StellathePug
2011-Jun-28 15:05 UTC
[R] How do I output all the R-squares of an SUR? summary(fitSUR$eq[[1:4]])$r.squared does not work
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
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.
Achim Zeileis
2011-Jun-28 16:20 UTC
[R] How do I output all the R-squares of an SUR? summary(fitSUR$eq[[1:4]])$r.squared does not work
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.squaredYou 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. >
StellathePug
2011-Jun-28 17:09 UTC
[R] How do I output all the R-squares of an SUR? summary(fitSUR$eq[[1:4]])$r.squared does not work
> sapply(fitSUR$eq, function(x) summary(x)$r.squared) > You can abbreviate that to: > sapply(summary(fitSUR)$eq, "[[", "r.squared")This is fantastic! Thanks so much. I had a hunch that it would be something related to the apply family but I am still not very good at using it. Thank you immensely for the two examples, they made my day!!! Rita -- 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-tp3630601p3630900.html Sent from the R help mailing list archive at Nabble.com.