0

请我还是 R 的新手,不明白如何修复可重现数据中的一些错误消息。

我需要使用 Cox 脆弱生存模型对调查数据进行多层次分析(在两个层次上)。我的问题是如何使用所需的两个权重编写调查设计并将它们应用于分析。

我已经确定了调查设计所需的变量,它们是:初级抽样单位 (psu) =~v021, level-1 weight=~wt1_1, level-2 weight=~wt2_1 ,strata=~v022。

请有人可以帮助我了解 svydesign 代码以及如何在模型中包含它和权重。

我知道我应该在我的分析中使用 svycoxph 而不是 coxph,但是我不知道如何使用我需要的两个级别的权重来编写调查设计,并且实际上将它们包含在下面的脆弱模型中。

感谢您的预期帮助。

这是我的数据集的快照:

library(survival)
#> Warning: package 'survival' was built under R version 4.0.5
library(frailtypack)
#> Warning: package 'frailtypack' was built under R version 4.0.5
#> Loading required package: boot
#> 
#> Attaching package: 'boot'
#> The following object is masked from 'package:survival':
#> 
#>     aml
#> Loading required package: MASS
#> Loading required package: survC1
#> Warning: package 'survC1' was built under R version 4.0.5
#> Loading required package: doBy
#> Warning: package 'doBy' was built under R version 4.0.5
#> 
#> Attaching package: 'frailtypack'
#> The following object is masked from 'package:survival':
#> 
#>     cluster


rcom1 <- data.frame(
  data.frame(
    pid = c(
      1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13,
      14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29,
      30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45,
      46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60,
      61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76,
      77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92,
      93, 94, 95, 96, 97, 98, 99, 100
    ),
    study_time = c(
      13, 9, 17, 31, 39, 22, 24, 0, 23, 12, 9, 35,
      18, 20, 60, 18, 5, 46, 26, 54, 37, 51, 31, 55, 27, 15, 39, 6,
      29, 0, 9, 40, 23, 12, 35, 56, 14, 40, 57, 42, 5, 42, 39, 39,
      54, 19, 52, 42, 7, 28, 53, 5, 28, 13, 37, 0, 23, 33, 27, 36, 20,
      24, 58, 34, 12, 44, 3, 34, 14, 5, 10, 40, 12, 36, 19, 58, 17,
      40, 39, 58, 53, 53, 1, 50, 2, 28, 24, 13, 13, 50, 46, 46, 19, 6,
      32, 59, 9, 30, 30, 43
    ),
    died = c(
      0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0,
      0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0,
      0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0,
      0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
      0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
      0
    ),
    v021 = c(
      1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
      2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3,
      3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4, 4,
      4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
      5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 6, 6,
      6
    ),
    v022 = 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", "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", "2", "2", "2", "2", "2", "2", "2",
      "2", "2", "2"
    ),
    v012 = c(
      40, 37, 27, 27, 24, 32, 35, 35, 34, 20, 28,
      28, 26, 24, 24, 25, 26, 26, 26, 26, 28, 27, 25, 25, 27, 26, 26,
      21, 21, 31, 36, 36, 27, 23, 32, 32, 33, 33, 33, 28, 25, 37,
      33, 34, 33, 28, 28, 29, 33, 33, 33, 39, 38, 38, 38, 38, 24, 27,
      35, 40, 22, 38, 38, 21, 30, 30, 30, 39, 43, 18, 23, 23, 25, 25,
      30, 45, 26, 26, 35, 35, 35, 35, 32, 32, 40, 25, 27, 30, 30, 30,
      28, 28, 18, 27, 30, 30, 27, 21, 21, 30
    ),
    wt2_1 = c(
      401.200012207031, 401.200012207031,
      401.200012207031, 401.200012207031, 401.200012207031, 401.200012207031,
      401.200012207031, 401.200012207031, 401.200012207031,
      401.200012207031, 401.200012207031, 401.200012207031, 401.200012207031,
      401.200012207031, 401.200012207031, 401.200012207031,
      401.200012207031, 401.200012207031, 401.200012207031, 401.200012207031,
      401.200012207031, 401.200012207031, 401.200012207031,
      401.200012207031, 401.200012207031, 401.200012207031, 401.200012207031,
      401.200012207031, 401.200012207031, 401.200012207031,
      401.200012207031, 401.200012207031, 401.200012207031, 401.200012207031,
      401.200012207031, 401.200012207031, 401.200012207031,
      401.200012207031, 401.200012207031, 401.200012207031, 401.200012207031,
      401.200012207031, 401.200012207031, 401.200012207031,
      401.200012207031, 401.200012207031, 401.200012207031, 401.200012207031,
      401.200012207031, 401.200012207031, 401.200012207031,
      401.200012207031, 401.200012207031, 401.200012207031, 401.200012207031,
      401.200012207031, 401.200012207031, 401.200012207031,
      401.200012207031, 401.200012207031, 401.200012207031, 401.200012207031,
      401.200012207031, 401.200012207031, 401.200012207031,
      401.200012207031, 401.200012207031, 401.200012207031, 401.200012207031,
      401.200012207031, 401.200012207031, 401.200012207031,
      401.200012207031, 401.200012207031, 401.200012207031, 401.200012207031,
      401.200012207031, 401.200012207031, 401.200012207031,
      401.200012207031, 401.200012207031, 401.200012207031, 401.200012207031,
      401.200012207031, 401.200012207031, 401.200012207031,
      401.200012207031, 401.200012207031, 401.200012207031, 401.200012207031,
      631.818176269531, 631.818176269531, 631.818176269531,
      631.818176269531, 631.818176269531, 631.818176269531, 631.818176269531,
      631.818176269531, 631.818176269531, 631.818176269531
    ),
    wt1_1 = c(
      2.5074667930603, 2.5074667930603,
      2.5074667930603, 2.5074667930603, 2.5074667930603, 2.5074667930603,
      2.5074667930603, 2.5074667930603, 2.5074667930603, 2.5074667930603,
      2.5074667930603, 2.5074667930603, 2.5074667930603,
      2.5074667930603, 2.5074667930603, 5.1194109916687, 5.1194109916687,
      5.1194109916687, 5.1194109916687, 5.1194109916687, 5.1194109916687,
      5.1194109916687, 5.1194109916687, 5.1194109916687,
      5.1194109916687, 5.1194109916687, 5.1194109916687, 5.1194109916687,
      5.1194109916687, 5.1194109916687, 5.1194109916687, 5.1194109916687,
      5.1194109916687, 5.1194109916687, 2.40910983085632,
      2.40910983085632, 2.40910983085632, 2.40910983085632, 2.40910983085632,
      2.40910983085632, 2.40910983085632, 2.40910983085632,
      2.40910983085632, 2.40910983085632, 2.40910983085632, 2.40910983085632,
      2.40910983085632, 2.40910983085632, 1.06203985214233,
      1.06203985214233, 1.06203985214233, 1.06203985214233, 1.06203985214233,
      1.06203985214233, 1.06203985214233, 1.06203985214233,
      1.06203985214233, 1.06203985214233, 1.06203985214233, 1.06203985214233,
      1.06203985214233, 1.06203985214233, 1.06203985214233,
      1.06203985214233, 1.06203985214233, 1.06203985214233, 1.06203985214233,
      2.80098295211792, 2.80098295211792, 2.80098295211792,
      2.80098295211792, 2.80098295211792, 2.80098295211792, 2.80098295211792,
      2.80098295211792, 2.80098295211792, 2.80098295211792,
      2.80098295211792, 2.80098295211792, 2.80098295211792, 2.80098295211792,
      2.80098295211792, 2.80098295211792, 2.80098295211792,
      2.80098295211792, 2.80098295211792, 2.80098295211792, 2.80098295211792,
      2.80098295211792, 2.80098295211792, 1.24210178852081,
      1.24210178852081, 1.24210178852081, 1.24210178852081, 1.24210178852081,
      1.24210178852081, 1.24210178852081, 1.24210178852081,
      1.24210178852081, 1.24210178852081
    ),
    v024 = 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", "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"
    ),
    v025 = 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", "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", "2", "2", "2", "2", "2", "2", "2",
      "2", "2", "2"
    ),
    mat_edu = c(
      "5", "5", "5", "4", "4", "5", "4", "4", "4",
      "4", "4", "4", "5", "5", "5", "5", "5", "5", "4", "4", "5",
      "4", "4", "4", "5", "3", "3", "4", "4", "5", "5", "5", "5", "4",
      "2", "2", "0", "0", "0", "5", "5", "0", "1", "5", "5", "3",
      "3", "5", "5", "5", "5", "5", "5", "5", "5", "5", "5", "4", "5",
      "5", "4", "5", "5", "3", "4", "4", "5", "3", "1", "3", "3", "3",
      "1", "3", "2", "1", "3", "3", "4", "4", "0", "0", "2", "2",
      "1", "0", "4", "4", "4", "4", "0", "0", "3", "4", "2", "2", "3",
      "3", "3", "0"
    )
  )
)

Frailty <- coxph(Surv(study_time, died) ~ factor(mat_edu) + v025 + frailty(v021, distribution = "gamma"), data = rcom1)
#> Warning in coxpenal.fit(X, Y, istrat, offset, init = init, control, weights =
#> weights, : Inner loop failed to coverge for iterations 2 3 4

reprex 包于 2022-01-20 创建(v2.0.1)

4

0 回答 0