Hi,

See below I reply your message for <https://stat.ethz.ch/pipermail/r-help/2008-April/160966.html>[R] predict.glm & newdata posted on Fri Apr 4 21:02:24 CEST 2008 


You say  it ##works fine but it does not: if you look at the length of yhat2, you will find 100 and not 200 as expected. In fact predict(reg1, data=x2) gives the same results as predict(reg1).


So I am still looking for a solution of this problem.


best regards

Maurice 

===========

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  


% ================================================= 
% Maurice CHARBIT
% Ecole Nationale Supérieure des Télécommunications
% Département TSI 
% 37,39 rue Dareau, pièce A321
% 75634 - PARIS cedex 13 FRANCE
% email: maurice.charbit@telecom-paristech.fr    
% Fax:   (33) (0)1 45 81 71 44
% Phone: (33) (0)1 45 81 71 78
%==================================================| 
	[[alternative HTML version deleted]]

