[R] Regressions with fixed-effect in R

Millo Giovanni Giovanni_Millo at Generali.com
Wed May 12 17:43:21 CEST 2010


Dear Liviu,

we're still working on measures of fit for panels. If I get you right,
what you mean is the R^2 of the demeaned, or "within", regression. A
quick and dirty function to do this is:

pmodel.response<-plm:::pmodel.response.plm # needs this to make the
method accessible

r2<-function(x, adj=TRUE) {
  ## fetch response and residuals
  y <- pmodel.response(x, model="within")
  myres <- resid(x)
  n <- length(myres)

  if(adj) {
    adjssr <- x$df.residual
    adjtss <- n-1
    } else {
    adjssr <- 1
    adjtss <- 1
    }

  ssr <- sum(myres^2)/adjssr
  tss <- sum(y^2)/adjtss
  return(1-ssr/tss)
  }

and then

> r2(yourmodel)

Hope this helps
Giovanni

------------------------------

Message: 13
Date: Tue, 11 May 2010 13:21:02 +0100
From: Liviu Andronic <landronimirc at gmail.com>
To: Daniel Malter <daniel at umd.edu>
Cc: r-help at r-project.org
Subject: Re: [R] Regressions with fixed-effect in R
Message-ID:
	<AANLkTikvI6_-QVH-Odr31EiipPuq1sRa0-qconQZHtAV at mail.gmail.com>
Content-Type: text/plain; charset=UTF-8

Dear Daniel

On 5/11/10, Daniel Malter <daniel at umd.edu> wrote:
>  R-squared of interest is typically the within R-squared, not the
overall or
>
Could you point to an example on how to compute the within R-squared
in R, either via lm() or plm()?
Thank you
Liviu

--------------------------------

Giovanni Millo
Research Dept.,
Assicurazioni Generali SpA
Via Machiavelli 4, 
34132 Trieste (Italy)
tel. +39 040 671184 
fax  +39 040 671160 



More information about the R-help mailing list