Skip to content
Prev 256015 / 398506 Next

glm predict on new data

Dear Dirk,

You should avoid indexing in the glm call so that the name of the terms
will not contain the indexing part. (Check str(lg) in your example.)
A more preferred solution uses predefined data frames in the original calls:
n <- 250
x <- rnorm(n)
noise <- rnorm(n,0,0.3)
y <- round(exp(x+noise)/(1+exp(x+noise)),digits=0)
datfr <- data.frame(x=x,y=y)
lg <- glm(y~x,data=datfr[1:200,],family="binomial")
pred <- predict(lg,newdata=datfr[201:n,],type="response")

HTH,
  Denes