I am using R with knittr and LaTeX. I have isolated some error that has been occuring the following block:
<<>>=
opt_vals <- data.frame(opt_length=numeric(2000),
opt_eggs=numeric(2000))
for (i in 1:2000){
sim_fit <- fitted(model2)+rnorm(18, 0, sd(stdres2))
sim_data <- data.frame(sim_fit,
length=data_set$length,
length2=data_set$length2 )
model4 <- lm(sim_fit ~ length + length2, data = sim_data)
#Optimale laengde
optimal_length <- -coef(model4)[2]/(2*coef(model4)[3])
opt_vals$opt_length[i] <- optimal_length
#Maximalt forventede aeg
max_expected_eggs <- coef(model4)[1]-
(coef(model4)
[2]^2/(4*coef(model4)[3]))
opt_vals$opt_eggs[i] <- max_expected_eggs
}
@
Whenever I include this code in my Knittr document, I get errors about a missing (or extra) $ or a forgotten }
Additional info: When I set <>= the error disappear so I think it's something in the typesetting, but I am not at all sure about how to fix it.
Edit: I am attaching an screenshot of the errors and code region.
Any help is appreciated!