Cecilia Carmo
2009-Jun-16 08:29 UTC
[R] save the output of summary(lmList(x)) into a dataframe
Hi r-helpers! I need to save the output of summary() function that I?ve runned like this: z<- lmList(y~x1+x2| x3, na.action=na.omit,data1,subset=year==1999) w<-summary(z) The output (w) is something like this: Call: Model: y ~ x1 + x2 | x3 Data: data1 Coefficients: (Intercept) Estimate Std. Error t value Pr(>|t|) 1 0.081110514 1.141352e-01 7.106531e-01 0.4774081 2 0.384008008 NaN NaN NaN 5 -0.127962259 NaN NaN NaN 14 0.828115409 6.888789e-01 5.427381e-02 0.9567241 x1 Estimate Std. Error t value Pr(>|t|) 1 58.06999452 137.263534154 4.230548e-01 0.6723151 2 -202.45105435 NaN NaN NaN 5 NaN NaN NaN NaN 14 0.12776835 0.047486161 1.262510e-02 0.9899286 x2 Estimate Std. Error t value Pr(>|t|) 1 -0.173986693 2.126186e-01 -8.183043e-01 4.133115e-01 2 -0.630343567 NaN NaN NaN 5 NaN NaN NaN NaN 14 0.737871169 -3.203230e+01 3.840265e+01 0.000000e+00 Residual standard error: 0.2261486 on 1522 degrees of freedom I would like to have this output in a dataframe like this: x3 intercept x1 x2 Std. Error t value Pr(>|t|) 1 2 5 14 Anyone knows if it is possible and how? Thanks in advance, Cec?lia Carmo (Universidade de Aveiro ? Portugal)
milton ruser
2009-Jun-16 13:56 UTC
[R] save the output of summary(lmList(x)) into a dataframe
Hi Cecilia, Could you send us a reproducible example? cheers milton On Tue, Jun 16, 2009 at 4:29 AM, Cecilia Carmo <cecilia.carmo@ua.pt> wrote:> Hi r-helpers! > > I need to save the output of summary() function that I’ve runned like this: > z<- lmList(y~x1+x2| x3, na.action=na.omit,data1,subset=year==1999) > w<-summary(z) > The output (w) is something like this: > Call: > Model: y ~ x1 + x2 | x3 > Data: data1 > Coefficients: > (Intercept) > Estimate Std. Error t value Pr(>|t|) > 1 0.081110514 1.141352e-01 7.106531e-01 0.4774081 > 2 0.384008008 NaN NaN NaN > 5 -0.127962259 NaN NaN NaN > 14 0.828115409 6.888789e-01 5.427381e-02 0.9567241 > … > x1 > Estimate Std. Error t value Pr(>|t|) > 1 58.06999452 137.263534154 4.230548e-01 0.6723151 > 2 -202.45105435 NaN NaN NaN > 5 NaN NaN NaN NaN > 14 0.12776835 0.047486161 1.262510e-02 0.9899286 > … > x2 > Estimate Std. Error t value Pr(>|t|) > 1 -0.173986693 2.126186e-01 -8.183043e-01 4.133115e-01 > 2 -0.630343567 NaN NaN NaN > 5 NaN NaN NaN NaN > 14 0.737871169 -3.203230e+01 3.840265e+01 0.000000e+00 > … > Residual standard error: 0.2261486 on 1522 degrees of freedom > > I would like to have this output in a dataframe like this: > x3 intercept x1 x2 Std. Error t value Pr(>|t|) > 1 … > 2 > 5 > 14 > … > > Anyone knows if it is possible and how? > > Thanks in advance, > > Cecília Carmo (Universidade de Aveiro – Portugal) > > ______________________________________________ > R-help@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<http://www.r-project.org/posting-guide.html> > and provide commented, minimal, self-contained, reproducible code. >[[alternative HTML version deleted]]
Paul Johnson
2009-Jun-16 21:40 UTC
[R] save the output of summary(lmList(x)) into a dataframe
On Tue, Jun 16, 2009 at 3:29 AM, Cecilia Carmo<cecilia.carmo at ua.pt> wrote:> Hi r-helpers! > > I need to save the output of summary() function that I?ve runned like this: > z<- lmList(y~x1+x2| x3, na.action=na.omit,data1,subset=year==1999) > w<-summary(z) > The output (w) is something like this: > Call: > ?Model: y ~ x1 + x2 | x3 > ? Data: data1Does this come close? I'm just using the lmList example from lme4 ### example(lmList) spawns an object "fm1" that I demonstrate with: library(lme4) example(lmList) varnames <- names(fm1[[1]]$coefficients) mylist <- lmlist(fm1, summary) varnames <- names(fm1[[1]]$coefficients) myCoefficients <- function(x, name) { x[name,] } theintercepts <- t( sapply(mylist, myCoefficients, varnames[1])) theSecondVar <- t( sapply(mylist, myCoefficients, varnames[2])) I know other r-help readers will know a better way to cycle through the variables rather than running once for each element of varnames... -- Paul E. Johnson Professor, Political Science 1541 Lilac Lane, Room 504 University of Kansas