#-----------------------------------------------------------------------# # Comandos: # > fit.model <- ajuste # > attach(dados) # > source("diag_cook_nbin") #-----------------------------------------------------------------------# X <- model.matrix(fit.model) n <- nrow(X) p <- ncol(X) fi <- fit.model$theta w <- fi*fitted(fit.model)/(fi + fitted(fit.model)) W <- diag(w) H <- solve(t(X)%*%W%*%X) H <- sqrt(W)%*%X%*%H%*%t(X)%*%sqrt(W) h <- diag(H) ts <- resid(fit.model,type="pearson")/sqrt(1-h) td <- resid(fit.model,type="deviance")/sqrt(1-h) di <- (h/(1-h))*(ts^2) par(mfrow=c(1,1)) # plot(di,xlab="Índice", ylab="Distância de Cook", pch=16,cex=2,cex.axis=1.5,cex.lab=1.5) cut = mean(di) + 4*sd(di) abline(cut,0,lty=2,lwd=2) identify(di,n=3,cex=2) #-----------------------------------------------------------------------#