Skip to content

Commit

Permalink
review examples in tidyMS_R6_Modelling
Browse files Browse the repository at this point in the history
  • Loading branch information
wolski committed Apr 29, 2024
1 parent 16d97bb commit b2d4ec7
Show file tree
Hide file tree
Showing 10 changed files with 80 additions and 35 deletions.
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
60 changes: 42 additions & 18 deletions R/tidyMS_R6_Modelling.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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")
Expand Down Expand Up @@ -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)
#'
Expand All @@ -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){
Expand Down Expand Up @@ -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)
#'
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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){
Expand All @@ -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)
Expand Down
4 changes: 1 addition & 3 deletions man/linfct_all_possible_contrasts.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions man/linfct_factors_contrasts.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 19 additions & 6 deletions man/linfct_matrix_contrasts.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions man/make_model.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/my_contrast.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions man/my_contrast_V1.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/my_contrast_V2.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions man/my_glht.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit b2d4ec7

Please sign in to comment.