Anthony Howell
Anthony Howell

Reputation: 71

Error using stargazer and coxph - Survival Data

I get the following error when trying to use stargazer::stargazer with the 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

Variables in the model are firm-, industry-, and region-level, and there is one interaction term. I try running the model on only one variable (E.g. Innovation), and I get the same error message. Rownames are NULL.

Updated Question and Response:

Sorry about the confusion. I did not realize I could edit the original question. Below is the model run on one variable - innovation, with the same error produced).

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

Structure of the Cox Model

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"

Upvotes: 2

Views: 1404

Answers (1)

IRTFM
IRTFM

Reputation: 263362

The material posted in your comment (which I added to the question and applied the code block formatting function as you should have done) doesn't really make sense. The coefficients listed "Innovation" and "Prior_Experience:Age" do not match the formula in the call: "formula = Surv(Duration, Event, type = "right") ~ Innovation + Avg_Wage)". There seems to have been some mangling of the object along the way.

Upvotes: 1

Related Questions