Skip to content
Back to formatted view

Raw Message

Message-ID: <20130312195523.91050@gmx.net>
Date: 2013-03-12T19:55:23Z
From: kolos.agoston at gmx.net
Subject: Cook's distance
In-Reply-To: <mailman.0.1363109856.6296.r-help@r-project.org>

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