Usage

library(sclr)

Model

The model is of the form

\[ P(Y = 1) = \lambda(1 - logit^{-1}(\beta_0 + \beta_1X_1 + \beta_2X_2 + ... + \beta_kX_k)) \] Where

\(Y\) - binary outcome indicator, (eg. 1 - infected, 0 - not infected).
\(X\) - covariate.
\(k\) - number of covariates.

Model fitting

Model fitting is done with a function called sclr. It is used in the same way as other fitting functions like lm.

# One-titre fit to included simulated data
fit1 <- sclr(status ~ logHI, sclr_one_titre_data)
summary(fit1)
#> Call: status ~ logHI
#> 
#> Parameter estimates
#>     lambda     beta_0 beta_logHI 
#>   0.243828  -7.763952   2.088048 
#> 
#> 95% confidence intervals
#>                 2.5 %     97.5 %
#> lambda      0.2255282  0.2621277
#> beta_0     -9.6362901 -5.8916140
#> beta_logHI  1.6458693  2.5302271

# Two-titre fit to included simulated data
fit2 <- sclr(status ~ logHI + logNI, sclr_two_titre_data)
summary(fit2)
#> Call: status ~ logHI + logNI
#> 
#> Parameter estimates
#>     lambda     beta_0 beta_logHI beta_logNI 
#>  0.2407342 -8.4834480  2.3476149  2.1817105 
#> 
#> 95% confidence intervals
#>                  2.5 %     97.5 %
#> lambda       0.2043912  0.2770771
#> beta_0     -10.8482743 -6.1186216
#> beta_logHI   1.7954867  2.8997431
#> beta_logNI   1.6720872  2.6913338

Expected protection

The predict method will return the point estimate and a confidence interval of \(\beta_0 + \beta_1X_1 + ... + \beta_kX_k\) where \(k\) is the number of covariates. It will also apply the inverse logit transformation to these estimates and interval bounds to get the point estimate and the interval for the probability of protection on the original scale.

# One-titre fit
preddata1 <- data.frame(logHI = seq(0, 8, length.out = 101))
pred1 <- predict(fit1, preddata1)
head(pred1[, c("logHI", "prot_l", "prot_point", "prot_u")])
#> # A tibble: 6 x 4
#>   logHI    prot_l prot_point  prot_u
#>   <dbl>     <dbl>      <dbl>   <dbl>
#> 1  0    0.0000653   0.000425 0.00275
#> 2  0.08 0.0000799   0.000502 0.00314
#> 3  0.16 0.0000978   0.000593 0.00359
#> 4  0.24 0.000120    0.000701 0.00409
#> 5  0.32 0.000146    0.000828 0.00466
#> 6  0.4  0.000179    0.000978 0.00532

# Two-titre fit
preddata2 <- data.frame(logHI = seq(0, 8, length.out = 101), logNI = 1)
pred2 <- predict(fit2, preddata2)
head(pred2[, c("logHI", "logNI", "prot_l", "prot_point", "prot_u")])
#> # A tibble: 6 x 5
#>   logHI logNI   prot_l prot_point prot_u
#>   <dbl> <dbl>    <dbl>      <dbl>  <dbl>
#> 1  0        1 0.000280    0.00183 0.0119
#> 2  0.08     1 0.000353    0.00221 0.0137
#> 3  0.16     1 0.000444    0.00266 0.0158
#> 4  0.24     1 0.000559    0.00321 0.0182
#> 5  0.32     1 0.000703    0.00387 0.0210
#> 6  0.4      1 0.000885    0.00467 0.0242

Protective titres

To get the estimated titre (and the confidence interval) that corresponds to a particular protection level (eg. 50%), use the get_protection_level function. Its interface is similar to that of predict.

protHI1 <- get_protection_level(fit1, "logHI", lvl = 0.5)
print(protHI1)
#> # A tibble: 3 x 3
#>   logHI prot_prob est        
#>   <dbl>     <dbl> <chr>      
#> 1  3.52       0.5 low bound  
#> 2  3.72       0.5 point      
#> 3  3.87       0.5 upper bound

prot_lvls2 <- data.frame(logNI = log(c(0.1, 10, 40)))
protHI2 <- get_protection_level(fit2, "logHI", prot_lvls2)
print(protHI2)
#>       logNI      logHI prot_prob         est
#> 1 -2.302585  5.2554587       0.5   low bound
#> 2  2.302585  1.1845222       0.5   low bound
#> 3  3.688879 -0.1615616       0.5   low bound
#> 4 -2.302585  5.7535086       0.5       point
#> 5  2.302585  1.4737826       0.5       point
#> 6  3.688879  0.1854565       0.5       point
#> 7 -2.302585  6.2172859       0.5 upper bound
#> 8  2.302585  1.6786425       0.5 upper bound
#> 9  3.688879  0.4329846       0.5 upper bound