Skip to content

strandardise() returns invalid data.frame #41

@entjos

Description

@entjos

Dear @mclements,

I recently tried to use the standardise function for obtaining standardised transition probabilities and length of stay estimates from a competing risk or multi-state model. However, when I tried to run the standardise function on a simple competing risk model with 3 covariates, I run into some problems with the data.frame object that is returned by standardise. I added a reproducible example below. Do you have any ideas what could cause this error and how it could be fixed?

Thank you for your work with this package! 🙂

Best regards,
Joshua

Reproducible example

library(rstpm2)
library(deSolve)

# Use the colon dataset from the survival package as example
colon_df <- survival::colon

# Model for recurrences
recurrence <- gsm(
    Surv(time, status) ~ factor(rx) + sex + age, 
    data = colon_df, 
    subset = (etype == 1), 
    df = 3
)

# Model for death
death <- gsm(
    Surv(time, status) ~ factor(rx) + sex + age, 
    data = colon_df, 
    subset = (etype == 2), 
    df = 3
)

# Competing risk model
cr <- markov_msm(
    list(
        Recurrence = recurrence,
        Death      = death
    ),
    trans = matrix(
        c(
          NA, 1 , 2 ,
          NA, NA, NA,
          NA, NA, NA
        ),
        nrow  = 3,
        ncol  = 3,
        byrow = TRUE
    ),
    # Only include each individual once
    newdata = unique(colon_df[, c("id", "rx", "sex", "age")]),
    t = seq(0, 2500, length = 10)
)

# Obtaine standardised estimates.
# This causes the error
standardise(cr)

Error

This throws the following error message

Error in `data.frame()`:
! arguments imply differing number of rows: 0, 30

Session info

R version 4.3.3 (2024-02-29)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 24.04.3 LTS

Matrix products: default
BLAS:   /usr/lib/x86_64-linux-gnu/blas/libblas.so.3.12.0 
LAPACK: /usr/lib/x86_64-linux-gnu/lapack/liblapack.so.3.12.0

locale:
 [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C               LC_TIME=en_US.UTF-8        LC_COLLATE=en_US.UTF-8    
 [5] LC_MONETARY=en_US.UTF-8    LC_MESSAGES=en_US.UTF-8    LC_PAPER=en_US.UTF-8       LC_NAME=C                 
 [9] LC_ADDRESS=C               LC_TELEPHONE=C             LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C       

time zone: Europe/Stockholm
tzcode source: system (glibc)

attached base packages:
[1] splines   stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] deSolve_1.40   rstpm2_1.7.0   survival_3.5-8

loaded via a namespace (and not attached):
 [1] numDeriv_2016.8-1.1 bbmle_1.0.25.1      mgcv_1.9-1          Matrix_1.6-5        lattice_0.22-5      glue_1.8.0         
 [7] parallel_4.3.3      lifecycle_1.0.4     stats4_4.3.3        mvtnorm_1.3-3       cli_3.6.5           sessioninfo_1.2.3  
[13] pak_0.9.0           vctrs_0.6.5         grid_4.3.3          compiler_4.3.3      tools_4.3.3         nlme_3.1-164       
[19] pillar_1.11.1       bdsmatrix_1.3-7     Rcpp_1.1.0          rlang_1.1.6         MASS_7.3-60.0.1    

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions