Dear all,

I've been having problems running update() to re-fit a cpglm model inside a 
function (as in the code below). The solution is probably simple, but I'm 
stuck. If anyone could help, I'd greatly appreciate it.

Regards,
Rubem




## R code
library(cplm)

## Data simulation
period<-factor(1:4)                       
herd<-factor(1:50)  

dat<-expand.grid(period=period,herd=herd)                      

beta<-c(-.3,1.7,2.5,3.4)                 
X<-model.matrix(~period,dat)              

mu<-as.vector(exp(X%*%beta))        
phi<-1; p<-1.6               

dat$resp<-rtweedie(nrow(dat),p,mu,phi)


## cpglm model
modPC1<-cpglm(resp~period,data=dat)
head(modPC1@model.frame)


## Simulating new response vector and re-fitting the model
sim.hnp<-function(glmfit){
  dat.1<-glmfit@model.frame
  n<-nrow(dat.1)
  dat.1[,1]<-rtweedie(n,glmfit$p,fitted(glmfit),glmfit$phi)
  
  mfun<-update(object=glmfit,data=dat.1)

  # rp<-resid(mfun,type='pearson')
  # sort(abs(rp))
}

sim.hnp(modPC1) # Error in is.data.frame(data) : object 'dat.1' not found

        [[alternative HTML version deleted]]

______________________________________________
R-help@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.

Reply via email to