Compute actual interaction values for multiple interaction terms.
computeActualInteractionFixEff.Rd
This function calculates the actual interaction values for multiple interaction terms using the provided data.
Arguments
- l_interactionTerm
A list of interaction terms in the form of "term1:term2".
- categorical_vars
A character vector containing the names of categorical variables in the data.
- dataActual
The data frame containing the actual gene expression values and metadata.
Examples
N_GENES <- 4
MIN_REPLICATES <- 3
MAX_REPLICATES <- 3
init_var <- init_variable(name = "varA", mu = 8, sd = 0.1, level = 3) %>%
init_variable(name = "varB", mu = c(5,-5), NA , level = 2) %>%
init_variable(name = "varC", mu = 1, 3, 3) %>%
add_interaction(between_var = c("varA", "varC"), mu = 5, 0.1)
#> Variable name should not contain digits, spaces, or special characters.
#> If any of these are present, they will be removed from the variable name.
#> Variable name should not contain digits, spaces, or special characters.
#> If any of these are present, they will be removed from the variable name.
#> Variable name should not contain digits, spaces, or special characters.
#> If any of these are present, they will be removed from the variable name.
mock_data <- mock_rnaseq(init_var, N_GENES,
MIN_REPLICATES, MAX_REPLICATES )
#> Building mu_ij matrix
#> k_ij ~ Nbinom(mu_ij, dispersion)
#> Counts simulation: Done
data2fit <- prepareData2fit(countMatrix = mock_data$counts,
metadata = mock_data$metadata )
results_fit <- fitModelParallel(formula = kij ~ varA + varB + varC + varA:varC,
data = data2fit, group_by = "geneID",
family = glmmTMB::nbinom2(link = "log"), n.cores = 1)
#> Log file location: /tmp/RtmpS86cq0/htrfit.log
#> CPU(s) number : 1
#> Cluster type : PSOCK
tidy_tmb <- tidy_tmb(results_fit)
fixEff_dataInference <- subsetFixEffectInferred(tidy_tmb)
fixEff_dataActual <- getData2computeActualFixEffect(mock_data$groundTruth$effects)
interactionTerm <- fixEff_dataInference$fixed_term$interaction[[1]]
categorical_vars <- fixEff_dataActual$categorical_vars
dataActual <- fixEff_dataActual$data
l_labelsInCategoricalVars <- lapply(dataActual[, categorical_vars], levels)
l_interaction <- strsplit(interactionTerm, split = ":")[[1]]
l_categoricalVarsInInteraction <- lapply(l_interaction,
function(label) findAttribute(label,
l_labelsInCategoricalVars)) %>%
unlist()
data_prepared <- prepareData2computeInteraction(categorical_vars,
l_categoricalVarsInInteraction, dataActual)
# Compute actual interaction values for multiple interactions
actualInteraction <- computeActualInteractionFixEff(interactionTerm, categorical_vars, dataActual)