I have a built some models using lm()
. The response variable is the abundance of a species at one of two locations each month. It is given as a percentage to 6 decimal place. Percentages have to be used as the data was collected via citizen science where the actual monthly total recorded each month is not reliable but the overall proportion (%) at each of the two locations is.
The best fit model has two explanatory variables which are wind speed and wind direction, both numerical. I would like to apply the predict()
function. So far, I have been able to do this by following the instructions from the post here as shown below.
model <- lm(y~ x1, data=df)
new.df <- data.frame(x1=c(0, 10, 20))
predict(model, new.df)
This seems to work well for models with just a single exploratory variable but I am having trouble adding a second so it works on my best fit model.
So far, this is what I have come up with, however, the results do not make sense as two are negative numbers.
model2 <- lm(y ~ x1+x2, data=df)
new.df <- data.frame(x1=c(1, 6, 12), (x2=c(1, 10, 20)))
predict(model2, new.df)
1 2 3
0.4123114 -0.3975497 -1.3014379
I would be grateful if anyone could offer any suggestions.