# Biostatistics III in R

#### Code by Bénédicte Delcoigne and Mark Clements

# Exercise 25. Localised melanoma : generating and analysing a nested case-control (NCC) study

    library(biostat3) # cox and conditional logistic analyses
    library(Epi)      # sample a nested case-control study from a cohort

    ## Get the data for exercise 25 and have a look at it
    data(melanoma)
    mel <- subset(melanoma, stage=="Localised")           # restrict the cohort to stage==1
    mel <- transform(mel,
                     dc = (mel$status=="Dead: cancer" & surv_mm<120)+0,
                     surv_10y = pmin(120, surv_mm))
    table(mel$dc , mel$status)                            # check

    str(mel$sex) ; str(mel$year8594) ; str(mel$agegrp)    #Check structure of risk factors/confounders

    ##  Factor w/ 2 levels "Male","Female": 2 2 2 2 2 2 2 1 2 2 ...

    ##  Factor w/ 2 levels "Diagnosed 75-84",..: 1 1 1 1 1 1 1 1 1 1 ...

    ##  Factor w/ 4 levels "0-44","45-59",..: 4 4 4 4 4 4 4 4 4 4 ...

    out_coh <- coxph(Surv(surv_10y,dc) ~ sex + year8594 + agegrp, data = mel)
    summary(out_coh)

    ## Call:
    ## coxph(formula = Surv(surv_10y, dc) ~ sex + year8594 + agegrp,
    ##     data = mel)
    ##
    ##   n= 5318, number of events= 960
    ##
    ##                             coef exp(coef) se(coef)      z Pr(>|z|)
    ## sexFemale               -0.53061   0.58825  0.06545 -8.107 5.19e-16 ***
    ## year8594Diagnosed 85-94 -0.33339   0.71649  0.06618 -5.037 4.72e-07 ***
    ## agegrp45-59              0.28283   1.32688  0.09417  3.003  0.00267 **
    ## agegrp60-74              0.62006   1.85904  0.09088  6.823 8.90e-12 ***
    ## agegrp75+                1.21801   3.38045  0.10443 11.663  < 2e-16 ***
    ## ---
    ## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
    ##
    ##                         exp(coef) exp(-coef) lower .95 upper .95
    ## sexFemale                  0.5882     1.7000    0.5174    0.6688
    ## year8594Diagnosed 85-94    0.7165     1.3957    0.6293    0.8157
    ## agegrp45-59                1.3269     0.7536    1.1032    1.5959
    ## agegrp60-74                1.8590     0.5379    1.5557    2.2215
    ## agegrp75+                  3.3804     0.2958    2.7547    4.1483
    ##
    ## Concordance= 0.646  (se = 0.009 )
    ## Rsquare= 0.039   (max possible= 0.949 )
    ## Likelihood ratio test= 212.7  on 5 df,   p=<2e-16
    ## Wald test            = 217.9  on 5 df,   p=<2e-16
    ## Score (logrank) test = 226.8  on 5 df,   p=<2e-16

## (a)

There are 5318 individuals in the study that we would need to collect data for if we were to use the complete cohort of patients.

    n_ind <- length(mel$id)
    n_ind

    ## [1] 5318

## (b)

960 cancer patients die from melanoma during the first 10 years of follow-up.

    table(mel$dc, useNA="always")

    ##
    ##    0    1 <NA>
    ## 4358  960    0

    ncase <-  table (mel$dc, useNA="always")[2]
    ncase

    ##   1
    ## 960

## (c1)

    nccdata <-ccwc( entry=0, exit=surv_10y , fail=dc, origin=0, controls=1, include=list(sex,year8594,agegrp,dc,id), data=mel )

    ##
    ## Sampling risk sets: .....................................................................................................................

    tail(nccdata, 8)

    ##      Set  Map  Time Fail    sex        year8594 agegrp dc   id
    ## 1913 114 2674  87.5    1 Female Diagnosed 85-94   0-44  1 3784
    ## 1914 114 2640  87.5    0 Female Diagnosed 85-94    75+  0 3728
    ## 1915 115 4275  98.5    1   Male Diagnosed 85-94  60-74  1 6168
    ## 1916 115 2729  98.5    0   Male Diagnosed 85-94  45-59  0 3871
    ## 1917 116 5287   2.5    1   Male Diagnosed 85-94  45-59  1 7713
    ## 1918 116 1591   2.5    0 Female Diagnosed 75-84  60-74  0 2234
    ## 1919 117 5314 119.5    1   Male Diagnosed 85-94  60-74  1 7753
    ## 1920 117   12 119.5    0 Female Diagnosed 75-84    75+  0   20

## (c2)

    out_ncc <- clogit(Fail ~ sex + year8594 + agegrp + strata(Set), data=nccdata)
    summary(out_ncc)

    ## Call:
    ## coxph(formula = Surv(rep(1, 1920L), Fail) ~ sex + year8594 +
    ##     agegrp + strata(Set), data = nccdata, method = "exact")
    ##
    ##   n= 1920, number of events= 960
    ##
    ##                             coef exp(coef) se(coef)      z Pr(>|z|)
    ## sexFemale               -0.43567   0.64683  0.09579 -4.548 5.42e-06 ***
    ## year8594Diagnosed 85-94 -0.38566   0.68000  0.09659 -3.993 6.53e-05 ***
    ## agegrp45-59              0.33054   1.39172  0.12511  2.642  0.00824 **
    ## agegrp60-74              0.66741   1.94919  0.12527  5.328 9.93e-08 ***
    ## agegrp75+                1.43134   4.18431  0.16857  8.491  < 2e-16 ***
    ## ---
    ## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
    ##
    ##                         exp(coef) exp(-coef) lower .95 upper .95
    ## sexFemale                  0.6468     1.5460    0.5361    0.7804
    ## year8594Diagnosed 85-94    0.6800     1.4706    0.5627    0.8217
    ## agegrp45-59                1.3917     0.7185    1.0891    1.7785
    ## agegrp60-74                1.9492     0.5130    1.5249    2.4916
    ## agegrp75+                  4.1843     0.2390    3.0070    5.8225
    ##
    ## Concordance= 0.649  (se = 0.015 )
    ## Rsquare= 0.053   (max possible= 0.701 )
    ## Likelihood ratio test= 105.6  on 5 df,   p=<2e-16
    ## Wald test            = 97.43  on 5 df,   p=<2e-16
    ## Score (logrank) test = 102.8  on 5 df,   p=<2e-16

## (d)

    n_uni <- length(unique(nccdata$id))
    n_uni

    ## [1] 1715

## (e)

Note that, since every nested case-control study is different, the parameter estimates you obtain will not be identical to those above. However, the hazard ratios from the two models should be very similar. The standard errors are slightly larger for the nested case-control study since the estimates are based on a sample from the full cohort. Loss of precision is the trade-off we have to make when designing a nested case-control study. The precision can be improved by adding more controls to each case.

    comp <- exp(data.frame(coef(out_coh),coef(out_ncc)))
    colnames(comp) <- c("cohort HR", "NCC HR")
    comp                           # print the HR estimates from the cohort and the NCC

    ##                         cohort HR    NCC HR
    ## sexFemale               0.5882470 0.6468322
    ## year8594Diagnosed 85-94 0.7164882 0.6800017
    ## agegrp45-59             1.3268817 1.3917190
    ## agegrp60-74             1.8590433 1.9491877
    ## agegrp75+               3.3804475 4.1843054

    var <- data.frame(diag(vcov(out_coh)), diag(vcov(out_ncc)), diag(vcov(out_coh))/diag(vcov(out_ncc)))
    colnames(var) <- c("cohort var", "NCC var", "ratio coh/ncc" )
    var                            # print the variances of estimates from the cohort and the NCC and their ratio

    ##                          cohort var     NCC var ratio coh/ncc
    ## sexFemale               0.004283749 0.009176364     0.4668242
    ## year8594Diagnosed 85-94 0.004380163 0.009329206     0.4695108
    ## agegrp45-59             0.008868630 0.015653206     0.5665695
    ## agegrp60-74             0.008258394 0.015691548     0.5262957
    ## agegrp75+               0.010906329 0.028414965     0.3838234

## (f)

We see that there is sampling variation in the parameter estimates from the five nested case-control studies but they are centered on the full cohort estimate. We see that the standard errors of the estimates from the nested case-control studies are larger than for the full cohort but there is some sampling variation.

    M <- 20                   # Number of loops: change the M value to change the number of loops
    param   <- matrix(0,M,5)  # Define the matrice of the coefficients
    for (i in 1:M)  {         # Start of the loop, create NCC data and analyse it
        nccdata <-ccwc( entry=0, exit=surv_10y , fail=dc, origin=0, controls=1, include=list(sex,year8594,agegrp), data=mel )
        out_ncc <- clogit(Fail ~ sex + year8594 + agegrp + strata(Set), data=nccdata)
        param [ i , 1:5] <- coef(out_ncc)   # store the 5 coefficients M times
    }                  # End of the loop