I have seen different questions but my query is about their combination.
- How to calculate Hat matrix for Beta regression? My actual issue is about
W
. Is this a link function (Logit)? Then how to add in code? becausehatvalues()
and my manual code are not equal. - If its a ridge regression, will K will be added in Matrix too?
My try:
require(betareg)
df<-data("ReadingSkills")
y<-ReadingSkills$accuracy
n<-length(y)
x1<-rnorm(n,0,1)
x2<-rnorm(n,0,1)
X<-cbind(x1, x2)
bfit<-betareg(y ~ x1 + x2, link="logit")
bfit1<-betareg(y~ X, link="logit")
hatmatrix<- diag(X%*%(solve(t(X)%*%X)%*%t(X)))
##in case of ridge
hat<-solve(t(X) %*% X + 0.1 * diag(3)) %*% t(X) %*% y
hatv<-hatvalues(bfit)
hatmatrix
hatv