#-----------------------------------------------------------------------# # Comandos: # > fit.model <- ajuste # > attach(dados) # > source("diag_cook_gama") #-----------------------------------------------------------------------# X <- model.matrix(fit.model) n <- nrow(X) p <- ncol(X) w <- fit.model$weights W <- diag(w) H <- solve(t(X)%*%W%*%X) H <- sqrt(W)%*%X%*%H%*%t(X)%*%sqrt(W) h <- diag(H) library(MASS) fi <- gamma.shape(fit.model)$alpha ts <- resid(fit.model,type="pearson")*sqrt(fi/(1-h)) td <- resid(fit.model,type="deviance")*sqrt(fi/(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) #-----------------------------------------------------------------------#