get linfct from model

linfct_from_model(m, as_list = TRUE)

Arguments

m

linear model

Examples


m <- sim_make_model_lm("factors")
#> creating sampleName from fileName column
#> completing cases
#> Joining with `by = join_by(protein_Id)`
linfct <- linfct_from_model(m, as_list = TRUE)

linfct$linfct_factors
#>             (Intercept) TreatmentB BackgroundZ
#> BackgroundX           1        0.5         0.0
#> BackgroundZ           1        0.5         1.0
#> TreatmentA            1        0.0         0.5
#> TreatmentB            1        1.0         0.5
linfct$linfct_interactions
#>                        (Intercept) TreatmentB BackgroundZ
#> TreatmentA:BackgroundX           1          0           0
#> TreatmentA:BackgroundZ           1          0           1
#> TreatmentB:BackgroundX           1          1           0
#> TreatmentB:BackgroundZ           1          1           1
lf <- matrix(
c(1, 1, 1, 1, 0.5, 0.5, 0, 1, 0, 1, 0.5, 0.5),
nrow = 4,
byrow = FALSE,
dimnames = list(c("BackgroundX", "BackgroundZ", "TreatmentA", "TreatmentB"),
                c("(Intercept)", "TreatmentB", "BackgroundZ"))
)
stopifnot(lf == linfct$linfct_factors)
m <- sim_make_model_lm("interaction")
#> creating sampleName from fileName column
#> completing cases
#> Joining with `by = join_by(protein_Id)`
linfct <- linfct_from_model(m)

m <- lm(Petal.Width ~ Species, data = iris)
linfct_from_model(m)
#> $linfct_factors
#>                   (Intercept) Speciesversicolor Speciesvirginica
#> Speciessetosa               1                 0                0
#> Speciesversicolor           1                 1                0
#> Speciesvirginica            1                 0                1
#> 
#> $linfct_interactions
#>                   (Intercept) Speciesversicolor Speciesvirginica
#> Speciessetosa               1                 0                0
#> Speciesversicolor           1                 1                0
#> Speciesvirginica            1                 0                1
#> 
xx <- data.frame( Y = 1:10 , Condition = c(rep("a",5), rep("b",5)) )
m <- lm(Y ~ Condition, data = xx)
linfct_from_model(m)
#> $linfct_factors
#>            (Intercept) Conditionb
#> Conditiona           1          0
#> Conditionb           1          1
#> 
#> $linfct_interactions
#>            (Intercept) Conditionb
#> Conditiona           1          0
#> Conditionb           1          1
#> 
xx <- data.frame( Y = 1:10 , Condition = c(rep("a",5), rep("b.b",5)) )
m <- lm(Y ~ Condition, data = xx)
linfct_from_model(m)
#> $linfct_factors
#>              (Intercept) Conditionb.b
#> Conditiona             1            0
#> Conditionb.b           1            1
#> 
#> $linfct_interactions
#>              (Intercept) Conditionb.b
#> Conditiona             1            0
#> Conditionb.b           1            1
#> 
xx <- data.frame( Y = 1:10 , Condition = c(rep("a",5), rep("ab",5)) )
m <- lm(Y ~ Condition, data = xx)
linfct_from_model(m)
#> $linfct_factors
#>             (Intercept) Conditionab
#> Conditiona            1           0
#> Conditionab           1           1
#> 
#> $linfct_interactions
#>             (Intercept) Conditionab
#> Conditiona            1           0
#> Conditionab           1           1
#>