Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error message from tidy(coxphFit) #48

Closed
ghost opened this issue Apr 27, 2015 · 4 comments
Closed

Error message from tidy(coxphFit) #48

ghost opened this issue Apr 27, 2015 · 4 comments

Comments

@ghost
Copy link

ghost commented Apr 27, 2015

I'm getting the following error message when I try to tidy a coxph fit from the survival package:

Error in seq_len(nrow(x)) : 
  argument must be coercible to non-negative integer
In addition: Warning message:
In seq_len(nrow(x)) : first element used of 'length.out' argument

Here is code to replicate the problem, note I first confirm that tidy works on a regression fit and they attempt it on a coxph fit

library(survival)
library(broom)

# Create data frame for the survival analysis
demoDat <- structure(list(daysFromInvestigation = c(1L, 6L, 7L, 5L, 5L, 
2L, 3L, 1L, 2L, 5L, 1L, 4L, 5L, 7L, 3L, 1L, 6L, 4L, 2L, 6L, 6L, 
7L, 7L, 6L, 4L, 2L, 2L, 4L, 0L, 5L, 5L, 4L, 4L, 1L, 7L, 7L, 1L, 
2L, 0L, 7L, 6L, 7L, 1L, 1L, 2L, 2L, 2L, 1L, 7L, 1L, 2L, 3L, 1L, 
1L, 2L), Sex = structure(c(2L, 2L, 2L, 2L, 2L, 2L, 2L, 1L, 2L, 
2L, 2L, 1L, 2L, 1L, 1L, 2L, 2L, 2L, 1L, 2L, 2L, 1L, 2L, 2L, 2L, 
2L, 2L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 1L, 2L, 2L, 2L, 
1L, 2L, 2L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 1L, 2L, 2L, 2L), .Label = c("F  ", 
"M  "), class = "factor"), dead = c(1, 1, 1, 1, 1, 1, 1, 1, 1, 
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 
1, 1, 1, 1)), row.names = c(NA, -55L), class = "data.frame", .Names = c("daysFromInvestigation", 
"Sex", "dead"))


# To be sure that I've got the packages loaded and things work, demonstrate with a glm regression
demoFit <- glm(daysFromInvestigation ~ Sex, data=demoDat)
print(demoFit)
tidy(demoFit)

# Works great

# Now do coxph 
demoCoxFit <- coxph(Surv(demoDat$daysFromInvestigation, demoDat$dead) ~ Sex, data = demoDat)

print(demoCoxFit)

Which produces the following:

Call:
coxph(formula = Surv(demoDat$daysFromInvestigation, demoDat$dead) ~ 
    Sex, data = demoDat)


       coef exp(coef) se(coef)     z    p
SexM    0.2      1.22     0.34 0.588 0.56

Likelihood ratio test=0.36  on 1 df, p=0.549  n= 55, number of events= 55 

But when I run tidy on the fit, I get the error message at the beginning of this issue report

tidy(demoCoxFit)
@dgrtwo
Copy link
Collaborator

dgrtwo commented Apr 27, 2015

Looks like this was fixed by #36 and #37. They haven't been added to CRAN yet, but for now please try the development version:

devtools::install_github("dgrtwo/broom")

I'm planning to upload broom 0.3.7 to CRAN sometime this week, which will fix this.

@ghost
Copy link
Author

ghost commented Apr 27, 2015

That worked, thanks!

@dgrtwo
Copy link
Collaborator

dgrtwo commented May 6, 2015

broom 0.3.7 now on CRAN, along with this fix!

@dgrtwo dgrtwo closed this as completed May 6, 2015
@github-actions
Copy link

This issue has been automatically locked. If you believe you have found a related problem, please file a new issue (with a reprex: https://reprex.tidyverse.org) and link to this issue.

@github-actions github-actions bot locked and limited conversation to collaborators Mar 15, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant