[R] How do I output all the R-squares of an SUR? summary(fitSUR$eq[[1:4]])$r.squared does not work

Achim Zeileis Achim.Zeileis at uibk.ac.at
Tue Jun 28 18:20:53 CEST 2011


On Tue, 28 Jun 2011, StellathePug wrote:

> Greetings R Users,
> I have a system of equations for which I would like to output all the
> R-squares. Assume there are four equations in my system, the only way I
> found to output all the R-squares is by calling them out one by one as this:
>
> summary(fitSUR$eq[[1]])$r.squared
> summary(fitSUR$eq[[2]])$r.squared
> summary(fitSUR$eq[[3]])$r.squared
> summary(fitSUR$eq[[4]])$r.squared

You can abbreviate that to:

   sapply(fitSUR$eq, function(x) summary(x)$r.squared)

Instead of calling summary(fitSUR$eq[[1]]), you can also look at 
summary(fitSUR)$eq[[1]] which leads to identical output. Hence you could 
also do

   sapply(summary(fitSUR)$eq, "[[", "r.squared")

depending on which you find more intuitive.

hth,
Z

> But isn't there a way of making this automatic, for example, something more
> along the way of
>
> summary(fitSUR$eq[[1:4]])$r.squared ?
>
> The above does not work, by the way.
>
> I have attached below my sample program. Thanks!
> Rita
>
>
> ############ SAMPLE PROGRAM ################
>
> YX<-as.data.frame(matrix(rnorm(280),ncol=14, nrow=20))               ##
> generate variables
> names(YX) <-c(paste("Y", 1:4, sep=""), paste("X", 1:10, sep=""))     ##
> assign variables' names
>
> library(systemfit)
>
> ## EQUATIONS:
> EQ1 <- Y1 ~ X1 + X2 + X4 + X7 + X10      ## equation 1 formula
> EQ2 <- Y2 ~ X2 + X3 + X5 + X8 + X10      ## equation 2 formula
> EQ3 <- Y3 ~ X5 + X6 + X7 + X9            ## equation 3 formula
> EQ4 <- Y4 ~ X1 + X3 + X4 + X6 + X9       ## equation 4 formula
>
> eqSystem <-list(form1 = EQ1, form2 = EQ2, form3 = EQ3, form4 = EQ4)
>
> fitSUR <- systemfit(eqSystem, method ="SUR", data=YX)
>
>
> ## How do I out put all the R-squares of the system without having to type a
> single line for each?
>
> summary(fitSUR$eq[[1]])$r.squared
> summary(fitSUR$eq[[2]])$r.squared
> summary(fitSUR$eq[[3]])$r.squared
> summary(fitSUR$eq[[4]])$r.squared
>
> summary(fitSUR$eq[[1]])$adj.r.squared
> summary(fitSUR$eq[[2]])$adj.r.squared
> summary(fitSUR$eq[[3]])$adj.r.squared
> summary(fitSUR$eq[[4]])$adj.r.squared
>
> --
> View this message in context: http://r.789695.n4.nabble.com/How-do-I-output-all-the-R-squares-of-an-SUR-summary-fitSUR-eq-1-4-r-squared-does-not-work-tp3630601p3630601.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



More information about the R-help mailing list