I made a fairly simple binomial regression model:
m_r <- mle2(ig$v ~ dbinom(size=ig$n, prob = 1/(1+exp(-(a + br * ig$river_dist)))),
start = list(a = 0, br = 0), data = ig)
based on this dataframe:
> ig
v n ig_dist river_dist tam_dist site
1 102 256 950 1040 1040 Boveda
2 1 11 4800 720 832 Cuchaconga
3 19 24 2000 475 475 Ishpingo
4 12 15 3400 611 800 La Joya
And now I'd like to graph predicted outcomes for a range of possible 'river_dist' values. To do that, I created a new dataframe:
newdat <- data.frame(river_dist=seq(min(ig$river_dist), max(ig$river_dist),len=100))
and tried to add predicted values based on the model:
newdat$v <- predict(m_r, newdata=newdat, type="response")
But it seems to be recycling the same four values over and over (short sample, but the numbers keep repeating):
> head(newdat)
river_dist v
1 475.0000 95.110424
2 480.7071 7.450936
3 486.4141 20.330167
4 492.1212 11.456229
5 497.8283 95.110424
6 503.5354 7.450936
What am I doing wrong?
Edit: By changing 'ig$river_dist' to 'river_dist' in my model, I'm able to produce what look like real predictions, but they're still following a four-value cycle (with slight variations each time), producing zigzags in my graph, rather than a slope or curve I was expecting. If someone could explain why, I'd appreciate it! My plotting:
plot(v~river_dist, data=ig, col="red4")
lines(v ~ river_dist, newdat, col="green4", lwd=2)