Skip to contents

Linear mixed-effects model strategy (R6 class)

Linear mixed-effects model strategy (R6 class)

Details

Encapsulates everything needed to fit per-protein linear mixed-effects models via lmer and extract contrasts.

Public fields

formula

model formula

model_name

name of model

report_columns

columns to report

is_mixed

always TRUE for lmer

anova_df

list with anova function and column names

Methods


Method new()

Create a new StrategyLmer

Usage

StrategyLmer$new(
  modelstr,
  model_name = "Model",
  report_columns = c("statistic", "p.value", "p.value.adjusted", "moderated.p.value",
    "moderated.p.value.adjusted")
)

Arguments

modelstr

model formula string

model_name

name of model

report_columns

columns to report


Method model_fun()

Fit lmer to one protein's data

Usage

StrategyLmer$model_fun(x, pb, get_formula = FALSE)

Arguments

x

data.frame for one protein

pb

optional progress bar

get_formula

if TRUE, return formula instead of fitting


Method isSingular()

Check if model is singular

Usage

StrategyLmer$isSingular(model)

Arguments

model

fitted model


Method contrast_fun()

Compute contrasts from fitted model

Usage

StrategyLmer$contrast_fun(...)

Arguments

...

passed to my_contest


Method df_residual()

Get residual degrees of freedom

Usage

StrategyLmer$df_residual(model)

Arguments

model

fitted model


Method sigma()

Get residual standard error

Usage

StrategyLmer$sigma(model)

Arguments

model

fitted model


Method clone()

The objects of this class are cloneable with this method.

Usage

StrategyLmer$clone(deep = FALSE)

Arguments

deep

Whether to make a deep clone.

Examples

istar <- prolfqua::sim_lfq_data_peptide_config(Nprot = 10, with_missing = FALSE)
#> creating sampleName from fileName column
#> completing cases
#> completing cases done
#> setup done
istar <- prolfqua::LFQData$new(istar$data, istar$config)
istar$data <- istar$data |> dplyr::group_by(protein_Id) |>
  dplyr::mutate(abundanceC = abundance - mean(abundance)) |> dplyr::ungroup()
strat <- StrategyLmer$new("abundanceC ~ group_ + (1|peptide_Id)",
  model_name = "random_example")
mod <- build_model(istar, strat)
#> Warning: There were 4 warnings in `dplyr::mutate()`.
#> The first warning was:
#>  In argument: `linear_model = purrr::map(data, model_strategy$model_fun, pb =
#>   pb)`.
#>  In group 2: `protein_Id = "7cbcrd~5725"`.
#> Caused by warning in `value[[3L]]()`:
#> ! WARN :Error: grouping factors must have > 1 sampled level
#>  Run `dplyr::last_dplyr_warnings()` to see the 3 remaining warnings.
#> Joining with `by = join_by(protein_Id)`
sum(mod$modelDF$exists_lmer)
#> [1] 6