【问题标题】:Error using stargazer and coxph - Survival Data使用 stargazer 和 coxph 时出错 - 生存数据
【发布时间】:2013-02-07 23:44:48
【问题描述】:

尝试将stargazer::stargazer 与 coxph (Survival) 一起使用时出现以下错误:

> summary(firm.survcox)
> stargazer(firm.survcox) 
> firm.survcox #only partial results are included for brevity 
Call: coxph(formula = Surv(Duration, Event, type = "right") ~ Innovation + Avg_Wage) 
coef exp(coef) se(coef) z p 
Innovation -0.87680 0.4161 0.008040 -109.051 0.0e+00 
Prior_Experience:Age -0.01297 0.9871 0.004174 -3.107 1.9e-03 
Likelihood ratio test=131885 on 23 df, p=0 n= 535416, 
number of events= 203037 (1060020 observations deleted due to missingness) 

Error in .get.standard.errors.1(object.name, user.given) : 
  subscript out of bounds

模型中的变量是企业级、行业级和区域级的,并且存在一个交互项。我尝试仅在一个变量(例如创新)上运行模型,我得到相同的错误消息。行名为 NULL。

更新的问题和响应:

很抱歉造成混乱。我没有意识到我可以编辑原始问题。下面是在一个变量上运行的模型 - 创新,产生了相同的错误)。

Call: coxph(formula = Surv(Duration, Event, type = "right") ~ Innovation) 
coef exp(coef) se(coef) z p 
Innovation -0.87680 0.4161 0.008040 -109.051 0.0e+00 
Likelihood ratio test=131885 on 23 df, p=0 n= 535416, 
number of events= 203037 (1060020 observations deleted due to missingness) 

stargazer(firm.survcox)
Error in .get.standard.errors.1(object.name, user.given) : 
  subscript out of bounds

Cox 模型的结构

str(firm.survcox)

    List of 18
    $ coefficients     : Named num -0.772
    ..- attr(*, "names")= chr "Innovation"
    $ var              : num [1, 1] 3.91e-05
    $ loglik           : num [1:2] -5583174 -5573640
    $ score            : num 16015
    $ iter             : int 4
    $ linear.predictors: num [1:1595436] 0.0807 0.0807 0.0807 -0.6915 0.0807 ...
    $ residuals        : Named num [1:1595436] 0.925 0.976 -0.516 0.888 0.976 ...
     ..- attr(*, "names")= chr [1:1595436] "1" "2" "3" "4" ...
    $ means            : Named num 0.104
      ..- attr(*, "names")= chr "Innovation"
    $ concordance      : Named num [1:5] 5.20e+10 1.97e+10 3.67e+11 1.14e+10 2.49e+08
    ..- attr(*, "names")= chr [1:5] "concordant" "discordant" "tied.risk" "tied.time"..
   $ method           : chr "efron"
   $ n                : int 1595436
   $ nevent           : num 404033
   $ terms            :Classes 'terms', 'formula' length 3 Surv(Duration, Event, type =  
       "right") ~ Innovation
    .. ..- attr(*, "variables")= language list(Surv(Duration, Event, type = "right"),      
       Innovation)
     .. ..- attr(*, "factors")= int [1:2, 1] 0 1
     .. .. ..- attr(*, "dimnames")=List of 2
     .. .. .. ..$ : chr [1:2] "Surv(Duration, Event, type = \"right\")" "Innovation"
     .. .. .. ..$ : chr "Innovation"
     .. ..- attr(*, "term.labels")= chr "Innovation"
    .. ..- attr(*, "specials")=Dotted pair list of 3

    .. .. ..$ strata : NULL   .. .. ..$ cluster: NULL   .. .. ..$ tt     : NULL   ..-    
    attr(*, "order")= int 1   .. ..- attr(*, "intercept")= int 1   .. ..- attr(*, 
    "response")= int 1   .. ..- attr(*, ".Environment")=<environment: R_GlobalEnv>    .. ..- 

    attr(*, "predvars")= language list(Surv(Duration, Event, type = "right"), 
   Innovation)   .. ..- attr(*, "dataClasses")= Named chr [1:2] "nmatrix.2" "numeric"    
   .. .. ..- attr(*, "names")= chr [1:2] "Surv(Duration, Event, type = \"right\")" 
  "Innovation"  
   $ assign     :List of 1   ..$ Innovation: num 1  
   $ wald.test        : Named num 15249   ..- attr(*, "names")= chr "Innovation"  
   $ y                : Surv [1:1595436, 1:2]  2   1  10+  5   1  10+ 10+  6   8+  8+  
    ...   ..- attr(*, "dimnames")=List of 2   .. ..$ : chr [1:1595436] "1" "2" "3" "4"     
   $ : chr [1:2] "time" "status"   ..- attr(*, "type")= chr "right"  $ formula          
     :Class 'formula' length 3 Surv(Duration, Event, type = "right") ~ Innovation   ..    
   attr(*, ".Environment")=<environment: R_GlobalEnv>   $ call             : language 
   coxph(formula = Surv(Duration, Event, type = "right") ~ Innovation)

    - attr(*, "class")= chr "coxph"

【问题讨论】:

  • firm.survcox 来自哪里?
  • 您需要显示代码或对象的结构。 stargazer 应该接受模型对象。
  • 你用的是什么版本的stargazer?
  • 信息为:R包版本3.0.1。 CRAN.R-project.org/package=stargazer 并在 R 版本 2.15.2 下构建
  • firm.survcox 是分配给上面粘贴的模型的名称。顺便说一句..当我使用参数回归使用 survreg 指定相同的模型时,stargazer 工作得很好......

标签: r latex survival-analysis


【解决方案1】:

在您的评论中发布的材料(我将其添加到问题中并按照您应该做的那样应用了代码块格式化功能)并没有真正的意义。 “Innovation”和“Prior_Experience:Age”列出的系数与调用中的公式不匹配:“formula = Surv(Duration, Event, type = "right") ~ Innovation + Avg_Wage)”。沿途似乎有一些物体损坏。

【讨论】:

  • 请不要将这些详细信息放在 cmets 中。使用您的问题的编辑工具。
  • 感谢您的回复。我已经在适当的地方更新了我的回复并发布了模型的结构。当我使用 survreg 函数而不是 coxph 函数使用 stargazer 时,结果有效。不知道该怎么办。
猜你喜欢
  • 2022-10-24
  • 2013-02-10
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-04-10
  • 1970-01-01
  • 2020-07-08
  • 1970-01-01
相关资源
最近更新 更多