Title: | Sensitivity Analysis Using the Trimmed Means Estimator |
---|---|
Description: | Sensitivity analysis using the trimmed means estimator. |
Authors: | Audinga-Dea Hazewinkel [aut, cre] , Tom Palmer [aut] , Kate Tilling [aut] , Kaitlin Wade [aut] , Jack Bowden [aut] |
Maintainer: | Audinga-Dea Hazewinkel <[email protected]> |
License: | GPL (>= 3) |
Version: | 0.3.1 |
Built: | 2024-11-19 05:10:53 UTC |
Source: | https://github.com/dea-hazewinkel/tmsens |
This package implements sensitivity analysis using the trimmed mean estimator.
Maintainer: Audinga-Dea Hazewinkel [email protected] (ORCID)
Authors:
Tom Palmer [email protected] (ORCID)
Kate Tilling [email protected] (ORCID)
Kaitlin Wade [email protected] (ORCID)
Jack Bowden [email protected] (ORCID)
Useful links:
Report bugs at https://github.com/dea-hazewinkel/tmsens/issues
summary
method for class "tm
".
## S3 method for class 'tm' summary(object, ...)
## S3 method for class 'tm' summary(object, ...)
object |
an object of class " |
... |
user specified arguments |
summary.tm
returns an list of summary statistics of the fitted trimmed means linear
model in object
, with components
call |
the matched call |
n |
the number of observations per treatment group |
dropout |
the proportion of dropout per treatment group |
trimfrac |
the proportion of data that was trimmed away per treatment group |
trimside |
specifies if lower or higher value trimming was performed |
n_after_trimming |
the number of observations per treatment group after trimming |
coefficients |
an array of coefficients with corresponding p-values and 95% confidence intervals |
Analysis_details |
reiterates trimming fraction and side, and, for |
SD_outcome |
an array of the standard deviation per treatment group, for the observed outcomes and for the trimmed outcomes |
tm
. The function coef
extracts the array of regression coefficients with corresponding p-values and 95% confidence intervals.
set.seed(123456) test_dat <- as.data.frame(cbind(c(rep(0,500),rep(1,500)), c(sort(rnorm(500,0,1)),sort(rnorm(500,1,1.5))), rbinom(1000,2,0.4), rnorm(1000,0,1))) colnames(test_dat) <- c("TR", "Y", "U", "U2") test_dat$Y[1:200] <- NA tm_obj <- tm(formula= Y ~ TR + U + U2, GR = "TR", trF = 0.5, side = "LOW", n_perm = 1000, adj_est = TRUE, data = test_dat) summary(tm_obj) coef(tm_obj)
set.seed(123456) test_dat <- as.data.frame(cbind(c(rep(0,500),rep(1,500)), c(sort(rnorm(500,0,1)),sort(rnorm(500,1,1.5))), rbinom(1000,2,0.4), rnorm(1000,0,1))) colnames(test_dat) <- c("TR", "Y", "U", "U2") test_dat$Y[1:200] <- NA tm_obj <- tm(formula= Y ~ TR + U + U2, GR = "TR", trF = 0.5, side = "LOW", n_perm = 1000, adj_est = TRUE, data = test_dat) summary(tm_obj) coef(tm_obj)
tm
performs a trimmed means analysis for data with a continuous outcome/response and a binary
treatment/exposure variable. Outcomes are sorted and trimmed per treatment group, and a linear
regression is fitted using lm
.
tm( formula, GR, trF = NULL, side = c("LOW", "HIGH"), n_perm = 1000, adj_est = FALSE, data )
tm( formula, GR, trF = NULL, side = c("LOW", "HIGH"), n_perm = 1000, adj_est = FALSE, data )
formula |
an object of class |
GR |
a string denoting the name of the binary treatment variable. This function assumes the lowest value to be the comparator/reference group |
trF |
a number between 0 and 1, specifying the trimming fraction: the proportion of the data that is trimmed away
for each treatment group. |
side |
specifies if higher value trimming ( |
n_perm |
the number of permutations performed to obtain the p-value and 95% confidence intervals for the estimates. Default is 1000. |
adj_est |
logical. If |
data |
a data frame containing the variables in the model. |
tm
returns an object of class tm
.
The function summary
is used to obtain a summary of the results. The generic accessor function
coefficients
extracts the regression coefficients with corresponding p-values and 95% confidence intervals.
An object of class "tm
" is a list containing the following components:
call |
the matched call |
n |
the number of observations per treatment group |
dropout |
the proportion of dropout per treatment group |
trimfrac |
the proportion of data that was trimmed away per treatment group |
trimside |
specifies if lower or higher value trimming was performed |
n_after_trimming |
the number of observations per treatment group after trimming |
coefficients |
an array of coefficients with corresponding p-values and 95% confidence intervals |
Analysis_details |
reiterates trimming fraction and side, and, for adjest=TRUE specifies if the adjustment was performed on the comparator or treatment group. |
SD_outcome |
an array of the standard deviation per treatment group, for the observed outcomes and for the trimmed outcomes |
The trimmed means estimate is subject to two assumptions: the strong MNAR assumption requires that all dropouts (unobserved outcome values) are located in the fraction of the distribution that is trimmed away; the location shift assumption requires the group variances of the full sample to be equal. The adjusted trimmed means estimator relaxes the latter, but assumes normally distributed outcomes. The adjustment is performed on the group with the smallest dropout proportion.
The p-value and 95% confidence intervals for the trimmed means estimate and the adjusted trimmed means estimate are obtained in a permutation approach.
set.seed(123456) test_dat <- as.data.frame(cbind(c(rep(0, 500), rep(1, 500)), c(sort(rnorm(500, 0, 1)), sort(rnorm(500, 1, 1.5))), rbinom(1000, 2, 0.4), rnorm(1000, 0, 1))) colnames(test_dat) <- c("TR", "Y", "U", "U2") test_dat$Y[1:200] <- NA # Note that we usually recommend setting n_perm to a larger value, e.g., 1000 tm_obj <- tm(formula= Y ~ TR + U + U2, GR = "TR", trF = 0.5, side = "LOW", n_perm = 100, adj_est = TRUE, data = test_dat) print(tm_obj) summary(tm_obj)
set.seed(123456) test_dat <- as.data.frame(cbind(c(rep(0, 500), rep(1, 500)), c(sort(rnorm(500, 0, 1)), sort(rnorm(500, 1, 1.5))), rbinom(1000, 2, 0.4), rnorm(1000, 0, 1))) colnames(test_dat) <- c("TR", "Y", "U", "U2") test_dat$Y[1:200] <- NA # Note that we usually recommend setting n_perm to a larger value, e.g., 1000 tm_obj <- tm(formula= Y ~ TR + U + U2, GR = "TR", trF = 0.5, side = "LOW", n_perm = 100, adj_est = TRUE, data = test_dat) print(tm_obj) summary(tm_obj)
tm_bias
calculates the bias and the bias-adjusted estimate for a trimmed means analysis (tm
) of a given
dataset, for a user-specified trimming fraction and dropout spread. tm_bias
calculates, under assumption
of normally distributed outcomes, the bias components resulting from violation of the
location shift assumption and violation of the strong MNAR assumption.
tm_bias( formula, GR, trF, side = c("LOW", "HIGH"), spread_TG = "max_bias", spread_CG = "max_bias", data )
tm_bias( formula, GR, trF, side = c("LOW", "HIGH"), spread_TG = "max_bias", spread_CG = "max_bias", data )
formula |
an object of class |
GR |
a string denoting the name of the binary treatment variable. This function assumes the lowest value to be the comparator/reference group |
trF |
a number between 0 and 1, specifying the trimming fraction: the proportion of the data that is trimmed away
for each treatment group. |
side |
specifies if higher value trimming ( |
spread_TG |
a number between 0 and 1, specifying the dropout spread for the treatment group.
|
spread_CG |
a number between 0 and 1, specifying the dropout spread for the comparator group.
|
data |
a data frame containing the variables in the model. |
tm_bias
returns an object of class tm_bias
.
An object of class "tm_bias
" is a list containing the following components:
call |
the matched call |
bias_components |
an array of bias components, including location shift assumption bias (LS), Strong MNAR bias in the treatment group (TG) and the comparator group (CG) |
total_bias |
the sum of all bias components |
TM_estimate |
the trimmed means estimate of the treatment effect |
bias_adj_TM_estimate |
the bias adjusted trimmed means estimate |
analysis_details |
the user-specified trimming fraction, trimming side, and dropout spread in the treatment (TG) and comparator groups (CG) |
observed_TG_SD |
observed standard deviation of the treatment group (TG) outcome |
observed_CG_SD |
observed standard deviation of the comparator group (CG) outcome |
inferred_TG_SD |
inferred full sample standard deviation of the treatment group (TG) outcome |
max_bias_CG |
an array of bias components, total bias, the bias adjusted estimate, and inferred full sample group standard deviations, calculated under the assumption of worst-case scenario dropout, with dropout in the comparator group (CG) on the opposite side of the distribution from the one that is being trimmed |
max_bias_TG |
an array of bias components, total bias, the bias adjusted estimate, and inferred full sample group standard deviations, calculated under the assumption of worst-case scenario dropout, with dropout in the treatment group (TG) on the opposite side of the distribution from the one that is being trimmed |
The trimmed means estimate is subject to two assumptions: the strong MNAR assumption requires that all dropouts (unobserved outcome values) are located in the fraction of the distribution that is trimmed away; the location shift assumption requires the group variances of the full sample to be equal. The bias resulting from the violation of either assumption can be calculated under assumption of normally distributed outcomes.
Obtaining the strong MNAR assumption bias requires an additional assumption about
the distribution of the dropouts: it is assumed that the dropouts are spread homogeneously across the specified
dropout spread. For example, under lower value trimming (side="LOW"
), and a treatment group dropout
spread of 0.6 (spread_TG=0.6
), any value in the bottom 60% of the treatment group outcome distribution
is equally likely to be missing.
The specified dropout spread for a given treatment group has implications for the unobserved full sample variance that is inferred from the observed data. For example, for an observed dropout of 0.4 and an assumed dropout spread of 0.5, the inferred full sample variance will be larger than for an assumed dropout spread of e.g., 0.8.
In addition to calculating the bias for a user-specified dropout spread, tm_bias
also calculates
the maximal bias. For example, for lower value trimming (side="LOW"
), the worst-case scenario would
involve lower value dropout in the treatment group (TG) and higher value dropout in the comparator group (CG),
and vice versa. Bias components are calculated for both scenarios. If the dropout spread
(spread_TG
, spread_CG
) is left unspecified for either treatment group, the function will
return only these quantities.
test_dat <- as.data.frame(cbind(c(rep(0, 500), rep(1, 500)), c(sort(rnorm(500, 0, 1)), sort(rnorm(500, 1, 1.5))))) colnames(test_dat) <- c("TR", "Y") test_dat$Y[which(test_dat$TR == 0)[1:150]] <- NA test_dat$Y[which(test_dat$TR == 1)[sample(seq(1, 400), 200, replace = FALSE)]] <- NA tm_bias_obj <- tm_bias(formula = Y ~ TR, "TR", trF = 0.5, side = "LOW", spread_TG = 0.4, spread_CG = 0.6, data = test_dat) print(tm_bias_obj)
test_dat <- as.data.frame(cbind(c(rep(0, 500), rep(1, 500)), c(sort(rnorm(500, 0, 1)), sort(rnorm(500, 1, 1.5))))) colnames(test_dat) <- c("TR", "Y") test_dat$Y[which(test_dat$TR == 0)[1:150]] <- NA test_dat$Y[which(test_dat$TR == 1)[sample(seq(1, 400), 200, replace = FALSE)]] <- NA tm_bias_obj <- tm_bias(formula = Y ~ TR, "TR", trF = 0.5, side = "LOW", spread_TG = 0.4, spread_CG = 0.6, data = test_dat) print(tm_bias_obj)