Dear Koilos, You've neglected to correct the MSE for df. Modifying your example, so that it actually runs (your original regression doesn't work -- the lengths of x and y differ):
> y <- (1:100)^2 > x <- 1:100 > lm(y~x) -> linmod # just for the sake of a simple example > linmod$residuals[1]^2/(2*sum(linmod$residuals^2)/98)*(hatvalues(linmod)[1]/( 1-hatvalues(linmod)[1])^2) 1 0.09853436 > cooks.distance(linmod)[1] 1 0.09853436 I hope this helps, John ----------------------------------------------- John Fox Senator McMaster Professor of Social Statistics Department of Sociology McMaster University Hamilton, Ontario, Canada > -----Original Message----- > From: r-help-boun...@r-project.org [mailto:r-help-bounces@r- > project.org] On Behalf Of kolos.agos...@gmx.net > Sent: Tuesday, March 12, 2013 3:55 PM > To: r-help@r-project.org > Subject: [R] Cook's distance > > Dear useRs, > > I have some trouble with the calculation of Cook's distance in R. > The formula for Cook's distance can be found for example here: > http://en.wikipedia.org/wiki/Cook%27s_distance > > I tried to apply it in R: > > > y <- (1:400)^2 > > x <- 1:100 > > lm(y~x) -> linmod # just for the sake of a simple example > > > linmod$residuals[1]^2/(2*mean(linmod$residuals^2))*(hatvalues(linmod)[1 > ]/(1-hatvalues(linmod)[1])^2) > 1 > 0.02503195 > > cooks.distance(linmod)[1] > 1 > 0.02490679 > > Why differ the two results? > > Thanks a lot if somebody have some instructions for me. > > Best wishes: > > Kolos > > ______________________________________________ > 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. ______________________________________________ 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.