Re: [R] Obtaining the adjusted r-square given the regression coefficients

From: Uwe Ligges <ligges_at_statistik.uni-dortmund.de>
Date: Wed 11 Jan 2006 - 19:08:21 EST

Alexandra R. M. de Almeida wrote:

> Dear list
>
> I want to obtain the adjusted r-square given a set of coefficients
> (without the intercept), and I don't know if there is a function that
> does it. Exist???????????????? I know that if you make a linear

You can read the code of summary.lm and adapt it.

Uwe Ligges

> regression, you enter the dataset and have in "summary" the adjusted
> r-square. But this is calculated using the coefficients that R
> obtained,and I want other coefficients that i calculated separately
> and differently (without the intercept term too). I have made a
> function based in the equations of the book "Linear Regression
> Analisys" (Wiley Series in probability and mathematical statistics),
> but it doesn't return values between 0 and 1. What is wrong???? The
> functions is given by:
>
>
> adjustedR2<-function(Y,X,saM) { if(is.matrix(Y)==F) (Y<-as.matrix(Y))
> if(is.matrix(X)==F) (X<-as.matrix(X)) if(is.matrix(saM)==F)
> (saM<-as.matrix(saM)) RX<-rent.matrix(X,1)$Rentabilidade.tipo
> RY<-rent.matrix(Y,1)$Rentabilidade.tipo
> r2m<-matrix(0,nrow=ncol(Y),ncol=1) RSS<-matrix(0,ncol=ncol(Y),nrow=1)
> SYY<-matrix(0,ncol=ncol(Y),nrow=1) for (i in 1:ncol(RY)) {
> RSS[,i]<-(t(RY[,i])%*%RY[,i])-(saM[i,]%*%(t(RX)%*%RX)%*%t(saM)[,i])
> SYY[,i]<-sum((RY[,i]-mean(RY[,i]))^2)
> r2m[i,]<-1-(RSS[,i]/SYY[,i])*((nrow(RY))/(nrow(RY)-ncol(saM)-1)) }
> dimnames(r2m)<-list(colnames(Y),c("Adjusted R-square")) return(r2m)
> }
>
>
>
> Thanks! Alexandra
>
>
>
> Alexandra R. Mendes de Almeida
>
>
>
>
> ---------------------------------
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help@stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the
> posting guide! http://www.R-project.org/posting-guide.html



R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html Received on Wed Jan 11 20:22:31 2006

This archive was generated by hypermail 2.1.8 : Wed 11 Jan 2006 - 22:03:45 EST