使用stargazer和coxph时出错 - 生存数据

时间:2013-02-22 11:09:48

标签: r latex survival-analysis

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

> 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

模型中的变量是公司,行业和地区级别,并且存在一个交互术语。我尝试只在一个变量(例如创新)上运行模型,我得到相同的错误消息。 Rownames为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"

1 个答案:

答案 0 :(得分:1)

您评论中发布的材料(我在问题中添加并应用了您应该完成的代码块格式化功能)并没有多大意义。列出的“Innovation”和“Prior_Experience:Age”系数与调用中的公式不匹配:“formula = Surv(Duration,Event,type =”right“)~Innovation + Avg_Wage)”。在此过程中,似乎有一些物体被破坏了。