irwls.diag<-function(data,glmobj){ # # Function to create IRWLS-based diagnostics corresponding to glm object. # # Input: # data - data frame containing data used to create glm object # glmobj - glm object defining model # # Output: # stdres - standardized residuals # hat - leverage values # cook - Cook's distances # phi - index of overdispersion. If overdispersion-corrected version # of the model is desired, standardized residuals must be divided # by the square root of phi # summary - summary of overdispersion-corrected version of the model # attach(data) fit<-predict.gam(glmobj,type="response") u<-log(fit)+(glmobj$y-fit)/fit ll<-lm(update(formula(glmobj),u~.),weights=fit,qr=T) phi<-deviance(ll)/ll$df.residual hat<-hat(ll$qr) stdres<-residuals(ll,type="pearson")/sqrt(1-hat) cook<-((stdres^2)*hat)/(length(ll$coeff)*(1-hat)*phi) summary<-summary(ll) detach() return(list(stdres=stdres,hat=hat,cook=cook,phi=phi,summary=summary))}