【问题标题】:Extracting coefficients with all information from gls output in R从R中的gls输出中提取所有信息的系数
【发布时间】:2011-06-25 13:23:10
【问题描述】:

我需要从 R 中的 gls 输出中获取系数及其 SE、t 值和 p 值。

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

如果有人帮助我解决这个问题,我将不胜感激。提前致谢。

【问题讨论】:

  • 把它们放在哪里?它们出现在摘要中,您是要导出它,还是将它们用作另一个函数的输入?就目前而言,这个问题相当不清楚。
  • @richiemorrisroe:我只是希望他们从这个摘要中提取并希望在 sweave 文件中使用。

标签: r modeling


【解决方案1】:

试试这个:

> 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

【讨论】:

    【解决方案2】:

    假设您想要某种表格的上述值,解决方案相对简单。

    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 
    

    更一般地说,如果您在任何 R 对象上调用 str() 函数,您通常可以(通过一些试验和错误)弄清楚如何提取您需要的结果。

    编辑:如果你需要它进入一个 sweave 文件,然后在上面的对象上调用 xtable,一切都应该很好。

    【讨论】:

      猜你喜欢
      • 2021-12-07
      • 1970-01-01
      • 2012-01-26
      • 1970-01-01
      • 1970-01-01
      • 2022-12-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多