-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
extract out some lower level code into functions from outstandR()
- Loading branch information
1 parent
8b87034
commit 90ca74a
Showing
3 changed files
with
60 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
|
||
# | ||
contrast_stats <- function(AC_stats, | ||
BC_stats, | ||
CI = 0.95) { | ||
upper <- 0.5 + CI/2 | ||
ci_range <- c(1-upper, upper) | ||
|
||
contrasts <- list( | ||
AB = AC_stats$mean - BC_stats$mean, | ||
AC = AC_stats$mean, | ||
BC = BC_stats$mean) | ||
|
||
contrast_variances <- list( | ||
AB = AC_stats$var + BC_stats$var, | ||
AC = AC_stats$var, | ||
BC = BC_stats$var) | ||
|
||
contrast_ci <- list( | ||
AB = contrasts$AB + qnorm(ci_range)*as.vector(sqrt(contrast_variances$AB)), | ||
AC = contrasts$AC + qnorm(ci_range)*as.vector(sqrt(contrast_variances$AC)), | ||
BC = contrasts$BC + qnorm(ci_range)*as.vector(sqrt(contrast_variances$BC))) | ||
|
||
list(contrasts = contrasts, | ||
variances = contrast_variances, | ||
CI = contrast_ci) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
# prepare data functions | ||
|
||
# | ||
prep_ipd <- function(form, data) { | ||
# select data according to formula | ||
model.frame(form, data = data) | ||
} | ||
|
||
# | ||
prep_ald <- function(form, data) { | ||
|
||
term.labels <- attr(terms(form), "term.labels") | ||
mean_names <- paste0("mean.", term.labels) | ||
sd_names <- paste0("sd.", term.labels) | ||
term_names <- c(mean_names, sd_names) | ||
|
||
# remove treatment labels | ||
term_names <- sort(term_names[!grepl(pattern = "trt", term_names)]) | ||
|
||
# replace outcome variable name | ||
response_var <- all.vars(form)[1] | ||
response_names <- gsub(pattern = "y", replacement = response_var, | ||
x = c("y.B.sum", "y.B.bar", "N.B", "y.C.sum", "y.C.bar", "N.C")) | ||
|
||
keep_names <- c(term_names, response_names) | ||
|
||
data[keep_names] | ||
} |