For some reason, when I specify glms (and lm is also obtained), R does not predict missing data values. Here is an example:
y = round(runif(50)) y = c(y,rep(NA,50)) x = rnorm(100) m = glm(y~x, family=binomial(link="logit")) p = predict(m,na.action=na.pass) length(p) y = round(runif(50)) y = c(y,rep(NA,50)) x = rnorm(100) m = lm(y~x) p = predict(m) length(p)
The length of p should be 100, but its 50. It is strange that I have other forecasts in the same script that predict the lack of data.
EDIT: It turns out these other predictions were completely wrong - I did imputed.value = rnorm(N,mean.from.predict,var.of.prediction.interval) . This recycle the middle and sd vectors from lm predict or glm predict functions when length(predict)<N , which is very different from what I was looking for.
So my question is: how does my code stop glm and lm from predicting missing values?
Thanks!
source share