Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Issue when using marginsplot with splines

    Hi,

    I'm plotting a survival function against BMI using cubic splines using the following code:

    Code:
    foreach num of numlist 3/7{
            preserve
            drop if glicopd_HUNT==.    & PartAg_gli>=40.0 & PartAg_gli!=.
            stset enddate, id(id) failure(RegisterStatus==5) origin(time PartDat_gli) scale(365.25)
            mkspline spl_bmi = BMI_gli, cubic nknots(`num') displayknots            
            stcox c.spl_bmi* i.Sex, vce(robust)
            estat ic
            levelsof BMI_gli, local(levels)
            xblc spl_bmi*, covname(BMI_gli) at(`levels') reference(25.0) eform gen(vbmi hr lb ub)
            keep if vbmi>14.9 & vbmi<40.1
            twoway rarea lb ub vbmi, lp(solid) lc(red) lw(medium) || line hr vbmi, lc(blue) lp(solid) lw(medium) ///
            legend(off) ylabel(, nogrid format(%3.2f)) yscale(log) yticks() xlabel(15(1)40, format(%3.0f)) xticks() xtitle("{bf:BMI             (kg/m{sup:2})}") ytitle("{bf:HR (95% CI) for all-cause mortality}") ///
            yline(1, lc(black) lp(dash) lw(medthin)) name(copd_death_spl_bmi_knot`num', replace) saving("M:\BMIsplines_COPD.gph",             replace)
            restore
    }
    I want to estimate the BMI value associated with the lowest HR. I tried using marginsplot, but got the error message spl2_bmi ambiguous abbreviation
    r(111);
    using the code below. What do I do wrong? And is there a way to estimate a 95% CI around the BMI associated with lowest mortality?

    Code:
    foreach num of numlist 3/7 {
        preserve
        drop if glicopd_HUNT == . & PartAg_gli >= 40.0 & PartAg_gli != .
        stset enddate, id(id) failure(RegisterStatus == 5) origin(time PartDat_gli) scale(365.25)
        mkspline spl_bmi = BMI_gli, cubic nknots(`num') displayknots
        stcox c.spl_bmi* i.Sex, vce(robust)
        margins, at("spl_bmi") post
        qui marginsplot
        // Extract the lowest point
        qui summarize spl_bmi if _bs_1 == min(_bs_1) & e(sample)
        di "Lowest BMI value: " r(mean)
        restore
    }
    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input float(glicopd_HUNT PartAg_gli enddate_bmi) double(RegisterStatus Sex) float(BMI_gli id)
    3 24.2 23481 1 1   30   1
    3 29.2 23481 1 0 32.3   2
    3 43.8 23481 1 0 32.3   3
    3 73.7 23481 1 0 24.4   4
    1 73.6 23481 5 0 23.1   5
    1 52.4 23481 1 1 27.3   6
    3 52.3 23481 1 1 21.8   7
    3 76.2 23481 1 0 24.1   8
    3 79.9 23481 1 0 24.3   9
    2 37.5 23481 1 0 22.6  10
    3 60.6 23481 1 0 23.4  11
    1 34.3 23481 1 1   28  12
    3 74.6 23481 1 1 26.1  13
    3 73.9 23481 1 0 34.4  14
    3 63.4 23481 1 0 30.1  15
    1 42.6 23481 1 1 27.2  16
    2 52.8 23481 1 1 30.2  17
    1 24.3 23481 1 1   25  18
    3 73.5 23481 1 0 25.1  19
    3 64.9 23481 1 0 34.9  20
    3 45.6 23481 1 0 22.3  21
    3 32.8 23481 1 0 22.4  22
    1 40.6 23481 1 0 24.8  23
    3 42.2 23481 1 0 21.2  24
    3 27.8 23481 1 0 26.3  25
    2 40.8 23481 1 1   26  26
    3 41.7 23481 1 1 25.8  27
    1 25.1 23481 1 1   24  28
    3 66.8 23481 1 0 28.7  29
    3 30.6 23481 1 0 24.1  30
    3 55.3 23481 1 0 24.6  31
    3 47.3 23481 1 1 26.2  32
    1 58.6 14440 5 1 23.6  33
    2 19.5 23481 1 0 27.7  34
    3 33.4 23481 1 1 23.4  35
    1 62.1 23481 5 0 29.5  36
    3 64.4 23481 1 0 24.2  37
    3 52.6 23481 1 1 34.9  38
    3 72.7 23481 1 0 20.5  39
    1 59.5 21015 5 1 31.4  40
    1 31.7 23481 1 1 22.6  41
    3   49 23481 1 1 23.3  42
    2 35.3 23481 1 0 28.7  43
    1   77 14898 5 0 26.1  44
    2 40.7 23481 1 0 21.9  45
    3 32.2 23481 1 1   28  46
    3 26.1 23481 1 0 33.6  47
    1 40.2 23481 1 1 22.3  48
    3 57.2 23481 1 0 33.9  49
    3 60.7 23481 1 0   29  50
    3   65 23481 1 0 28.6  51
    1 49.8 23481 5 1 27.4  52
    2 72.8 23481 5 0   25  53
    1 67.7 18489 5 1   27  54
    3 25.7 23481 1 0 24.2  55
    2   20 23481 1 0 20.7  56
    3 46.6 23481 1 1 25.3  57
    1   42 23481 1 1 23.7  58
    3 43.3 23481 1 1   28  59
    3 45.6 23481 1 0 22.3  60
    3 67.8 23481 1 1 26.3  61
    3 39.1 23481 1 1 24.9  62
    1 26.7 23481 1 1 23.9  63
    1 63.9 22415 5 0 23.5  64
    3 46.2 23481 1 0 22.5  65
    3 26.7 23481 1 0 24.1  66
    3 62.5 23481 1 1 21.9  67
    3 32.7 23481 1 0 23.3  68
    1 49.4 23481 1 1 26.6  69
    1 42.4 23481 1 1 29.1  70
    3 78.5 23481 1 1 26.6  71
    3 69.2 23481 1 1 32.1  72
    1 74.3 17454 5 1 27.6  73
    3 44.2 23481 1 0 27.7  74
    1 47.7 23481 1 0 24.2  75
    3 40.8 23481 1 0 30.2  76
    3 66.9 23481 1 0 23.8  77
    3 73.5 23481 1 1 31.4  78
    1 54.2 18611 5 0 25.6  79
    2 55.9 23481 1 1 21.9  80
    1 42.6 23481 1 0 24.3  81
    3 34.7 23481 1 0   32  82
    3 32.7 23481 1 0 29.3  83
    3 43.2 23481 1 1 25.5  84
    1   32 23481 1 0 19.9  85
    1 76.8 14075 5 0   24  86
    1 59.9 19342 5 1 26.6  87
    2 29.3 23481 1 1 20.5  88
    1 47.7 23481 1 1 24.2  89
    3 33.2 23481 1 0   30  90
    3 32.2 23481 1 1 25.5  91
    3 32.9 23481 1 0 27.5  92
    1 57.7 18732 5 1 32.1  93
    3 50.1 23481 1 0 27.3  94
    3 74.1 23481 1 0 20.4  95
    1 36.3 23481 1 1 24.7  96
    2 27.6 23481 1 0 21.3  97
    3 22.7 23481 1 0 19.7  98
    3 45.7 23481 1 1 28.5  99
    3 44.9 23481 1 1 28.5 100
    end
    format %td enddate_bmi
    label values RegisterStatus RegisterStatus
    label def RegisterStatus 1 "Bosatt", modify
    label def RegisterStatus 5 "Død", modify
    label values Sex Sex
    label def Sex 0 "Kvinne", modify
    label def Sex 1 "Mann", modify
    Last edited by Sigrid Vikjord; 25 Apr 2024, 03:54.
Working...
X