R语言 未将time_to_follow-up变量识别为dfmacox函数中的数值变量

wmtdaxz3  于 2023-03-15  发布在  Mac
关注(0)|答案(1)|浏览(141)

在R之下不能识别我的时间变量为数值变量。

dfmacox(time= "Days_FU", status = "Death_FU", nl.predictors= c ("BMI"), smoother= "ns", method= "AIC", data = mydata)

这将生成以下消息:
“监测错误(n时间,n状态):时间变量不是数字”
我已经把它转换成一个数值变量了。还有什么我可以做的吗?
我试着在time变量前后加上反勾号**'**,但是,这并没有解决问题。
数据输出(dta)

dat <- tibble(
    N = c(255, 1126, 724, 294),
    BMI_Cat = c("-1.0", "-1.0", "-1.0", "-1.0"),
    BMI = c("18.4", "16.9", "18.4", "16.9"),
    Death_FU = c(0, 0, 0, 0),
    Days_FU = c(1455, 707, 1077, 961),
    Hosp_AF_HF_Stroke = c(0, 1, 0, 0),
    Days_any_AF_HF_hospitalization_or_stroke = c(1455, 1207, 1077, 961),
    Age = c(62, 85, 76, 51),
    Gender = c(1, 0, 1, 1),
    Hx_Smoking = c(1, NA, 0, 1),
    Hx_HF = c(1, NA, 0, 1),
    Hx_CAD = c(0, 1, 0, 0),
    Hx_HTN = c(1, 1, 1, 0),
    Hx_DM = c(0, 1, 0, 0),
    CHA2DS2_VASC = c(3, 6, 6, 2),
    eGFR_Cockroft_adm = c(78, NA, NA, 60),
    LVEF = c("42.50", "45.00", "55.00", "99.00"),
    AF_type_simple = c(3, 2, 2, 3))
nbnkbykc

nbnkbykc1#

看起来您可能需要将tibble更改为data.frame

library(smoothHR)
#> Loading required package: survival
#> Loading required package: splines
library(tibble)

dat <- tibble(
  N = c(255, 1126, 724, 294),
  BMI_Cat = c("-1.0", "-1.0", "-1.0", "-1.0"),
  BMI = c("18.4", "16.9", "18.4", "16.9"),
  Death_FU = c(0, 0, 0, 0),
  Days_FU = c(1455, 707, 1077, 961),
  Hosp_AF_HF_Stroke = c(0, 1, 0, 0),
  Days_any_AF_HF_hospitalization_or_stroke = c(1455, 1207, 1077, 961),
  Age = c(62, 85, 76, 51),
  Gender = c(1, 0, 1, 1),
  Hx_Smoking = c(1, NA, 0, 1),
  Hx_HF = c(1, NA, 0, 1),
  Hx_CAD = c(0, 1, 0, 0),
  Hx_HTN = c(1, 1, 1, 0),
  Hx_DM = c(0, 1, 0, 0),
  CHA2DS2_VASC = c(3, 6, 6, 2),
  eGFR_Cockroft_adm = c(78, NA, NA, 60),
  LVEF = c("42.50", "45.00", "55.00", "99.00"),
  AF_type_simple = c(3, 2, 2, 3))

df <- data.frame(dat)

dfmacox(time= "Days_FU", status = "Death_FU", nl.predictors= c ("BMI"), smoother= "ns", method= "AIC", data = df)
#> $df
#> [1] 1
#> 
#> $AIC
#> [1] 2
#> 
#> $AICc
#> [1] 0
#> 
#> $BIC
#> [1] -Inf
#> 
#> $myfit
#> Call:
#> coxph(formula = covar, data = data, x = TRUE)
#> 
#>                 coef exp(coef) se(coef)  z  p
#> ns(BMI, df = 1)   NA        NA        0 NA NA
#> 
#> Likelihood ratio test=0  on 0 df, p=1
#> n= 4, number of events= 0 
#> 
#> $method
#> [1] "AIC"
#> 
#> $nl.predictors
#> [1] "BMI"

创建于2023年3月13日,使用reprex v2.0.2

相关问题