Re: [R] predict.glm & newdata

From: Daniel Malter <daniel_at_umd.edu>
Date: Fri, 04 Apr 2008 15:02:24 -0400


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.

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. Received on Fri 04 Apr 2008 - 19:07:59 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Wed 30 Apr 2008 - 18:30:35 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