Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Extracting coefficients with all information from gls output in R

Tags:

r

modeling

I need to get the coefficients along with their SEs, t-values and p-values from gls output in R.

library(nlme)
fm1 <- gls(follicles ~ sin(2*pi*Time) + cos(2*pi*Time), Ovary,
       correlation = corAR1(form = ~ 1 | Mare))

summary(fm1)
Generalized least squares fit by REML
  Model: follicles ~ sin(2 * pi * Time) + cos(2 * pi * Time) 
  Data: Ovary 
   AIC      BIC    logLik
  1571.455 1590.056 -780.7273

Correlation Structure: AR(1)
 Formula: ~1 | Mare 
 Parameter estimate(s):
  Phi 
0.7532079 

Coefficients:
                   Value Std.Error   t-value p-value
(Intercept)        12.216398 0.6646437 18.380373  0.0000
sin(2 * pi * Time) -2.774712 0.6450478 -4.301561  0.0000
cos(2 * pi * Time) -0.899605 0.6975383 -1.289685  0.1981

 Correlation: 
               (Intr) s(*p*T
sin(2 * pi * Time)  0.000       
cos(2 * pi * Time) -0.294  0.000

Standardized residuals:
        Min          Q1         Med          Q3         Max 
-2.41180365 -0.75405234 -0.02923628  0.63156880  3.16247697 

Residual standard error: 4.616172 
Degrees of freedom: 308 total; 305 residual

I'd highly appreciate if someone help me to figure out this. Thanks in advance.

like image 642
MYaseen208 Avatar asked Dec 22 '22 12:12

MYaseen208


2 Answers

try this:

> cs <- as.data.frame(summary(fm1)$tTable)
> cs
                        Value Std.Error   t-value      p-value
(Intercept)        12.2163982 0.6646437 18.380373 2.618737e-51
sin(2 * pi * Time) -2.7747122 0.6450478 -4.301561 2.286284e-05
cos(2 * pi * Time) -0.8996047 0.6975383 -1.289685 1.981371e-01
> cs$t
[1] 18.380373 -4.301561 -1.289685
> cs$p
[1] 2.618737e-51 2.286284e-05 1.981371e-01
like image 88
kohske Avatar answered Dec 24 '22 01:12

kohske


Assuming that you want the values above for some kind of table, a solution is relatively simple.

sumfm1 <- summary(fm1)

sumfm1$tTable

                       Value Std.Error   t-value      p-value
(Intercept)        12.2163982 0.6646437 18.380373 2.618737e-51
sin(2 * pi * Time) -2.7747122 0.6450478 -4.301561 2.286284e-05
cos(2 * pi * Time) -0.8996047 0.6975383 -1.289685 1.981371e-01 

More generally, if you call the str() function on any R object, you can normally (with a bit of trial and error) figure out how to extract the results you need.

EDIT: if you need it to go into a sweave file, then call xtable on the object above, and all should be good.

like image 35
richiemorrisroe Avatar answered Dec 24 '22 01:12

richiemorrisroe