diff --git a/NAMESPACE b/NAMESPACE index 75e76312e..32cfe9170 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -76,6 +76,7 @@ export(linfct_from_model) export(linfct_matrix_contrasts) export(make_benchmark) export(make_interaction_column) +export(make_model) export(make_reduced_hierarchy_config) export(matrix_to_tibble) export(medpolish_estimate) diff --git a/R/tidyMS_R6_Modelling.R b/R/tidyMS_R6_Modelling.R index 9c537315b..88dd0dea6 100644 --- a/R/tidyMS_R6_Modelling.R +++ b/R/tidyMS_R6_Modelling.R @@ -556,6 +556,21 @@ linfct_from_model <- function(m, as_list = TRUE){ } } +#' make interaction model for examples +#' @export +#' @example path.R +make_model <- function(model = " ~ Treatment * Background"){ + istar <- prolfqua::sim_lfq_data_protein_2Factor_config(Nprot = 1,with_missing = FALSE) + istar <- prolfqua::LFQData$new(istar$data,istar$config) + modelFunction <- strategy_lm(paste0(istar$response(), model)) + mod <- build_model( + istar, + modelFunction) + return(mod$modelDF$linear_model[[1]]) +} + + + #' linfct_matrix_contrasts #' @export #' @param linfct linear functions as created by linfct_from_model @@ -565,14 +580,27 @@ linfct_from_model <- function(m, as_list = TRUE){ #' @family modelling #' @keywords internal #' @examples -#' m <- prolfqua_data('data_basicModel_p1807') -#' linfct <- linfct_from_model(m,as_list = FALSE) -#' linfct -#' -#' Contrasts <- c("CMPvsMEP - HSC" = "`CelltypeCMP/MEP` - `CelltypeHSC`", -#' "NOvsHU" = "`class_therapyc.NO:CelltypeCMP/MEP` - `class_therapyp.HU:CelltypeCMP/MEP`") -#' linfct_matrix_contrasts(linfct, Contrasts ) #' +#' m <- make_model( " ~ Treatment + Background") +#' Contr <- c("TreatmentA_vs_B" = "TreatmentA - TreatmentB", +#' "BackgroundX_vs_Z" = "BackgroundX - BackgroundZ", +#' "IntoflintoA" = "`TreatmentA:BackgroundX` - `TreatmentA:BackgroundZ`", +#' "IntoflintoB" = "`TreatmentB:BackgroundX` - `TreatmentB:BackgroundZ`", +#' "IntoflintoX" = "`TreatmentA:BackgroundX` - `TreatmentB:BackgroundX`", +#' "IntoflintoZ" = "`TreatmentA:BackgroundZ` - `TreatmentB:BackgroundZ`", +#' "interactXZ" = "IntoflintoX - IntoflintoZ", +#' "interactAB" = "IntoflintoA - IntoflintoB" +#' ) +#' linfct <- linfct_from_model(m, as_list = FALSE) +#' x<- linfct_matrix_contrasts(linfct, Contr ) +#' stopifnot(sum(x["interactXZ",]) ==0 ) +#' stopifnot(sum(x["interactAB",]) ==0 ) +#' +#' m <- make_model( " ~ Treatment * Background") +#' linfct <- linfct_from_model(m, as_list = FALSE) +#' x<- linfct_matrix_contrasts(linfct, Contr ) +#' stopifnot(sum(x["interactXZ",]) ==1 ) +#' stopifnot(sum(x["interactAB",]) ==1 ) linfct_matrix_contrasts <- function(linfct , contrasts, p.message = FALSE){ linfct <- t(linfct) df <- tibble::as_tibble(linfct, rownames = "interaction") @@ -606,10 +634,8 @@ linfct_matrix_contrasts <- function(linfct , contrasts, p.message = FALSE){ #' @keywords internal #' @family modelling #' @examples -#' m <- prolfqua_data('data_basicModel_p1807') -#' m +#' m <- make_model( " ~ Treatment * Background") #' linfct <- linfct_from_model(m) -#' #' xl <- prolfqua::linfct_all_possible_contrasts(linfct$linfct_factors) #' xx <- prolfqua::linfct_all_possible_contrasts(linfct$linfct_interactions) #' @@ -633,9 +659,8 @@ linfct_all_possible_contrasts <- function(lin_int ){ #' @keywords internal #' @examples #' -#' m <- prolfqua_data('data_basicModel_p1807') +#' m <- make_model( " ~ Treatment * Background") #' xl <- linfct_factors_contrasts(m) -#' xl #' m <- lm(Petal.Width ~ Species, data = iris) #' linfct_factors_contrasts(m) linfct_factors_contrasts <- function(m){ @@ -664,12 +689,12 @@ linfct_factors_contrasts <- function(m){ #' @keywords internal #' @examples #' -#' mb <- prolfqua_data('data_basicModel_p1807') +#' mb <- make_model( " ~ Treatment * Background") #' linfct <- linfct_from_model(mb) #' names(linfct) #' my_glht(mb, linfct$linfct_factors) #' -#' m <- prolfqua_data('data_modellingResult_A')$modelProtein$linear_model[[1]] +#' m <- make_model( " ~ Treatment + Background") #' linfct <- linfct_from_model(m)$linfct_factors #' my_glht(m, linfct) #' @@ -723,7 +748,7 @@ my_glht <- function(model, linfct , sep = TRUE ) { #' @keywords internal #' @examples #' -#' m <- prolfqua_data('data_modellingResult_A')$modelProtein$linear_model[[1]] +#' m <- make_model( " ~ Treatment + Background") #' linfct <- linfct_from_model(m)$linfct_factors #' my_glht(m, linfct) #' my_contrast(m, linfct, confint = 0.95) @@ -781,9 +806,8 @@ my_contrast <- function(m, #' @family modelling #' @keywords internal #' @examples -#' m <- prolfqua_data('data_modellingResult_A')$modelProtein$linear_model[[1]] +#' m <- make_model( " ~ Treatment + Background") #' linfct <- linfct_from_model(m)$linfct_factors -#' m #' my_contrast_V1(m, linfct, confint = 0.95) #' my_contrast_V1(m, linfct, confint = 0.99) my_contrast_V1 <- function(incomplete, linfct, confint = 0.95){ @@ -810,7 +834,7 @@ my_contrast_V1 <- function(incomplete, linfct, confint = 0.95){ #' @family modelling #' @keywords internal #' @examples -#' m <- prolfqua_data('data_modellingResult_A')$modelProtein$linear_model[[1]] +#' m <- make_model( " ~ Treatment + Background") #' linfct <- linfct_from_model(m)$linfct_factors #' my_contrast_V2(m, linfct, confint = 0.95) #' my_contrast_V2(m, linfct, confint = 0.99) diff --git a/man/linfct_all_possible_contrasts.Rd b/man/linfct_all_possible_contrasts.Rd index 23dc9c5be..1d8fc0ed0 100644 --- a/man/linfct_all_possible_contrasts.Rd +++ b/man/linfct_all_possible_contrasts.Rd @@ -10,10 +10,8 @@ linfct_all_possible_contrasts(lin_int) create all possible contrasts } \examples{ -m <- prolfqua_data('data_basicModel_p1807') -m +m <- make_model( " ~ Treatment * Background") linfct <- linfct_from_model(m) - xl <- prolfqua::linfct_all_possible_contrasts(linfct$linfct_factors) xx <- prolfqua::linfct_all_possible_contrasts(linfct$linfct_interactions) diff --git a/man/linfct_factors_contrasts.Rd b/man/linfct_factors_contrasts.Rd index 8bd14b796..6a2bcae62 100644 --- a/man/linfct_factors_contrasts.Rd +++ b/man/linfct_factors_contrasts.Rd @@ -11,9 +11,8 @@ create contrasts between factor levels } \examples{ -m <- prolfqua_data('data_basicModel_p1807') +m <- make_model( " ~ Treatment * Background") xl <- linfct_factors_contrasts(m) -xl m <- lm(Petal.Width ~ Species, data = iris) linfct_factors_contrasts(m) } diff --git a/man/linfct_matrix_contrasts.Rd b/man/linfct_matrix_contrasts.Rd index 98846e10c..602bcc3c4 100644 --- a/man/linfct_matrix_contrasts.Rd +++ b/man/linfct_matrix_contrasts.Rd @@ -17,14 +17,27 @@ linfct_matrix_contrasts(linfct, contrasts, p.message = FALSE) linfct_matrix_contrasts } \examples{ -m <- prolfqua_data('data_basicModel_p1807') -linfct <- linfct_from_model(m,as_list = FALSE) -linfct -Contrasts <- c("CMPvsMEP - HSC" = "`CelltypeCMP/MEP` - `CelltypeHSC`", -"NOvsHU" = "`class_therapyc.NO:CelltypeCMP/MEP` - `class_therapyp.HU:CelltypeCMP/MEP`") -linfct_matrix_contrasts(linfct, Contrasts ) +m <- make_model( " ~ Treatment + Background") +Contr <- c("TreatmentA_vs_B" = "TreatmentA - TreatmentB", + "BackgroundX_vs_Z" = "BackgroundX - BackgroundZ", + "IntoflintoA" = "`TreatmentA:BackgroundX` - `TreatmentA:BackgroundZ`", + "IntoflintoB" = "`TreatmentB:BackgroundX` - `TreatmentB:BackgroundZ`", + "IntoflintoX" = "`TreatmentA:BackgroundX` - `TreatmentB:BackgroundX`", + "IntoflintoZ" = "`TreatmentA:BackgroundZ` - `TreatmentB:BackgroundZ`", + "interactXZ" = "IntoflintoX - IntoflintoZ", + "interactAB" = "IntoflintoA - IntoflintoB" + ) +linfct <- linfct_from_model(m, as_list = FALSE) +x<- linfct_matrix_contrasts(linfct, Contr ) +stopifnot(sum(x["interactXZ",]) ==0 ) +stopifnot(sum(x["interactAB",]) ==0 ) +m <- make_model( " ~ Treatment * Background") +linfct <- linfct_from_model(m, as_list = FALSE) +x<- linfct_matrix_contrasts(linfct, Contr ) +stopifnot(sum(x["interactXZ",]) ==1 ) +stopifnot(sum(x["interactAB",]) ==1 ) } \seealso{ Other modelling: diff --git a/man/make_model.Rd b/man/make_model.Rd new file mode 100644 index 000000000..5aceb5705 --- /dev/null +++ b/man/make_model.Rd @@ -0,0 +1,11 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/tidyMS_R6_Modelling.R +\name{make_model} +\alias{make_model} +\title{make interaction model for examples} +\usage{ +make_model(model = " ~ Treatment * Background") +} +\description{ +make interaction model for examples +} diff --git a/man/my_contrast.Rd b/man/my_contrast.Rd index dcedfa6db..29e651ad3 100644 --- a/man/my_contrast.Rd +++ b/man/my_contrast.Rd @@ -28,7 +28,7 @@ compute contrasts for full models } \examples{ -m <- prolfqua_data('data_modellingResult_A')$modelProtein$linear_model[[1]] +m <- make_model( " ~ Treatment + Background") linfct <- linfct_from_model(m)$linfct_factors my_glht(m, linfct) my_contrast(m, linfct, confint = 0.95) diff --git a/man/my_contrast_V1.Rd b/man/my_contrast_V1.Rd index 2474f5f1f..6afc61fbb 100644 --- a/man/my_contrast_V1.Rd +++ b/man/my_contrast_V1.Rd @@ -17,9 +17,8 @@ my_contrast_V1(incomplete, linfct, confint = 0.95) handles incomplete models by setting coefficients to 0 } \examples{ -m <- prolfqua_data('data_modellingResult_A')$modelProtein$linear_model[[1]] +m <- make_model( " ~ Treatment + Background") linfct <- linfct_from_model(m)$linfct_factors -m my_contrast_V1(m, linfct, confint = 0.95) my_contrast_V1(m, linfct, confint = 0.99) } diff --git a/man/my_contrast_V2.Rd b/man/my_contrast_V2.Rd index 9aab56860..b67f48ff0 100644 --- a/man/my_contrast_V2.Rd +++ b/man/my_contrast_V2.Rd @@ -17,7 +17,7 @@ my_contrast_V2(m, linfct, confint = 0.95) only keeps non NA coefficients. } \examples{ -m <- prolfqua_data('data_modellingResult_A')$modelProtein$linear_model[[1]] +m <- make_model( " ~ Treatment + Background") linfct <- linfct_from_model(m)$linfct_factors my_contrast_V2(m, linfct, confint = 0.95) my_contrast_V2(m, linfct, confint = 0.99) diff --git a/man/my_glht.Rd b/man/my_glht.Rd index e4e4c5cb4..bfb192d7d 100644 --- a/man/my_glht.Rd +++ b/man/my_glht.Rd @@ -11,12 +11,12 @@ apply multcomp::glht method to linfct } \examples{ -mb <- prolfqua_data('data_basicModel_p1807') +mb <- make_model( " ~ Treatment * Background") linfct <- linfct_from_model(mb) names(linfct) my_glht(mb, linfct$linfct_factors) -m <- prolfqua_data('data_modellingResult_A')$modelProtein$linear_model[[1]] +m <- make_model( " ~ Treatment + Background") linfct <- linfct_from_model(m)$linfct_factors my_glht(m, linfct)