This question is about the difference between the sum of lm.influence(model)$hat
and the trace of the Hat-Matrix $H := X (X' X)^{-1} X'$ calculated "by hand".
Let's take for example the cars data-set and the linear-model $dist = \beta \cdot speed + \varepsilon$
data(cars)
mod <- lm(dist ~ speed, cars)
Using lm.influence
to calculate the trace I get 2. lm.influence
is supposed to return the diagonal elements of $H$ (see ?lm.influence
).
sum(lm.influence(mod)$hat)
[1] 2
Calculating the trace of $H$ "by hand" I get 1:
X <- cars$speed
H <- X %*% solve(t(X) %*% X) %*% t(X)
sum(diag(H))
[1] 1
From my understanding it should be 1 as the Rank of a 1-column-vector $\equiv$ 1.
For linear models, the trace of the hat matrix is equal to the rank of X, which is the number of independent parameters of the linear model. Source: http://en.wikipedia.org/wiki/Hat_matrix