[R] predict.glm & newdata
Daniel Malter
daniel at umd.edu
Fri Apr 4 21:02:24 CEST 2008
Hi,
could it be the "newdata" argument? When I run predict with the newdata
argument, I get an error message - a different one though. The second reason
might be that your dataset is named df, which is defined as a function an
may produce problems. Try renaming the dataset.
yhat=predict(reg1,newdata=x2)
x1=seq(1:100)
r.norm1=rnorm(100,0,20)
x1=r.norm1+x1
x2=x1*2
r.norm2=rnorm(200,0,20)
x2=r.norm2+x2
reg1=glm(y1~x1,binomial)
yhat=predict(reg1) ##prediction works fine
yhat=predict(reg1,newdata=x2) ##gives error message because of "newdata"
>Error in eval(predvars, data, env) :
numeric 'envir' arg not of length one
yhat=predict(reg1,data=x2) ##works fine
##using offset
ofst=rep(0.5,100)
reg1=glm(y1~x1,binomial,offset=ofst)
yhat=predict(reg1)
yhat1=predict(reg1,newdata=x2) ##gives error message
yhat2=predict(reg1,data=x2) ##works fine
-------------------------
cuncta stricte discussurus
-------------------------
-----Ursprüngliche Nachricht-----
Von: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] Im
Auftrag von Tom Guston
Gesendet: Friday, April 04, 2008 1:29 PM
An: r-help at r-project.org
Betreff: [R] predict.glm & newdata
Hi all -
I'm stumped by the following
mdl <- glm(resp ~ . , data = df, family=binomial, offset = ofst) WORKS yhat
<- predict(mdl) WORKS yhat <- predict(mdl,newdata = df) FAILS
Error in drop(X[, piv, drop = FALSE] %*% beta[piv]) :
subscript out of bounds
I've tried without offset, quoting binomial. The offset variable ofst IS in
df.
Previous postings indicate possible names(df) problems (renaming factor
levels?) but I'm using the same data.frame for the newdata option.
Thank you in advance for any pointers.
Tom.
_________________________________________________________________
Going green? See the top 12 foods to eat organic.
1N1653A
[[alternative HTML version deleted]]
______________________________________________
R-help at r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
More information about the R-help
mailing list