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")
> I am aware this has been asked before but I could not find a resolution.
> I am doing a logit
> lg <- glm(y[1:200] ~ x[1:200,1],family=binomial)
> Then I want to predict a new set
> pred <- predict(lg,x[201:250,1],type="response")
> But I get varying error messages or warnings about the different number of
> rows. I have tried data/newdata and also to wrap in data.frame() but
> get to work.
> Help would be appreciated.
> View this message in context:
> Sent from the R help mailing list archive at Nabble.com.
> R-help_at_r-project.org mailing list
> PLEASE do read the posting guide
> and provide commented, minimal, self-contained, reproducible code.
Archive maintained by Robert King, hosted by
the discipline of
statistics at the
University of Newcastle,
Archive generated by hypermail 2.2.0, at Wed 06 Apr 2011 - 22:40:27 GMT.
Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.
list of date sections of archive