gamlj_lm.Rd
General Linear Model. Estimates models using lm()
function and
provides options to facilitate estimation of
interactions, simple slopes, simple effects, post-hoc tests, contrast
analysis, effect size indexes and visualization of the results.
gamlj_lm(
formula = NULL,
data,
dep = NULL,
fixed_intercept = TRUE,
factors = NULL,
covs = NULL,
model_terms = NULL,
nested_terms = NULL,
nested_intercept = NULL,
omnibus = "F",
estimates_ci = TRUE,
betas_ci = FALSE,
ci_width = 95,
ci_method = "wald",
boot_r = 1000,
contrasts = NULL,
contrast_custom_values = NULL,
contrast_custom_focus = NULL,
show_contrastnames = TRUE,
show_contrastcodes = FALSE,
vcov = FALSE,
plot_x = NULL,
plot_z = NULL,
plot_by = NULL,
plot_raw = FALSE,
plot_yscale = FALSE,
plot_xoriginal = FALSE,
plot_black = FALSE,
plot_around = "ci",
plot_jn = FALSE,
emmeans = NULL,
posthoc = NULL,
simple_x = NULL,
simple_mods = NULL,
simple_interactions = FALSE,
covs_scale = NULL,
covs_conditioning = "mean_sd",
ccm_value = 1,
ccp_value = 25,
ccra_steps = 3,
covs_scale_labels = "labels",
adjust = list("bonf"),
posthoc_es = list("dm"),
d_ci = FALSE,
es = list("beta", "etap"),
homo_test = FALSE,
colli_test = FALSE,
qq_plot = FALSE,
norm_test = FALSE,
norm_plot = FALSE,
resid_plot = FALSE,
intercept_info = FALSE,
es_info = FALSE,
dep_scale = "none",
se_method = "standard"
)
(optional) the formula of the model, see the examples. If not passed
model terms should be defined as a list in model_terms
option.
the data as a data frame
a string naming the dependent variable from data
; the
variable must be numeric. Not needed if formula
is used.
TRUE
(default) or FALSE
, estimates
fixed intercept. Overridden if formula
is used and contains ~1
or ~0
.
a vector of strings naming the fixed factors from
data
. Not needed if formula
is used.
a vector of strings naming the covariates from data
. Not
needed if formula
is used.
a list of character vectors describing fixed effects
terms. Not needed if formula
is used.
A right-hand formula for the nested model. It can be passed as a list of character vectors describing effects terms for the nested model.
TRUE
(default) or FALSE
, estimates
fixed intercept. Overridden if model_ters
is a formula and contains ~1
or ~0
..
Omnibus tests are based on F-test F
(default) or
loglikelihood ration test LRT
.
TRUE
(default) or FALSE
, parameters CI
in table
TRUE
(default) or FALSE
, parameters CI in
table
a number between 50 and 99.9 (default: 95) specifying the confidence interval width for the plots.
the method to compute the confidence intervals. It can be `wald` (default) for large samples confidence intervals, `quantile` for percentile bootstrap method, or `bcai` for bias corrected accelarated method.
a number bootstrap repetitions.
a named vector of the form c(var1="type",
var2="type2")
specifying the type of contrast to use, one of
'deviation'
, 'simple'
, 'dummy'
, 'difference'
,
'helmert'
, 'repeated'
, 'polynomial'
'custom'
. If NULL,
simple
is used. Can also be passed as a list of list of the form
list(list(var="var1",type="type1")). If any factor contrast is defined as 'custom'
,
a named list of the form list(factorname=numeric vector)
, for instance list(factorname=c(1,1,-2))
should be passed
to the option contrast_custom_values
.
a named list with the custom contrast weights, of the form list(factorname=numeric vector)
, for instance list(factorname=c(1,1,-2))
.
only one constrast per variable is allowed.
if any factor is coded with 'custom'
, when TRUE
or NULL
(default) the coefficients, simple effects and simple interactions
are focused on the custom contrast. If FALSE
, variables are coded accordingly to the passed contrast, but
no special table or test is devoted to the contrast.
TRUE
or FALSE
(default), shows raw
names of the contrasts variables in tables
TRUE
or FALSE
(default), shows
contrast coefficients tables
TRUE
or FALSE
(default), shows coefficients
covariances
a string naming the variable placed on the horizontal axis of the plot
a string naming the variable represented as separate lines in the plot
a list of variables defining the levels at which a separate plot should be produced.
TRUE
or FALSE
(default), plot raw data along
the predicted values
TRUE
or FALSE
(default), set the Y-axis
range equal to the range of the observed values.
TRUE
or FALSE
(default), use original
scale for covariates.
TRUE
or FALSE
(default), use different
linetypes per levels.
'none'
(default), 'ci'
, or 'se'
.
Use no error bars, use confidence intervals, or use standard errors on the
plots, respectively.
'FALSE'
(default), 'TRUE'
.
produces Johnson-Neyman plots for the variables specified in the main plot.
a rhs formula with the terms specifying the marginal means
to estimate (of the form '~x+x:z'
)
a rhs formula with the terms specifying the table to apply
the comparisons (of the form '~x+x:z'
). The formula is not expanded,
so 'x*z'
becomes 'x+z'
and not 'x+z+x:z'
. It can be
passed also as a list of the form list("x","z",c("x","z")
The variable for which the simple effects (slopes) are computed
a character vector with the variable(s) providing the levels at which the simple effects are computed
should simple Interactions be computed
a named vector of the form c(var1='type',
var2='type2')
specifying the transformation to apply to covariates, one of
'centered'
to the mean, 'standardized'
or 'none'
.
'none'
leaves the variable as it is.
'mean_sd
' (default), or 'percent
'.
How to condition covariates in simple effects and plots. 'mean_sd
'
for mean +/- 'ccp_value
' * sd. 'percent
' for median
+/-'ccp_value
' for percentiles. range
conditions to min and max divided in ccra_steps
steps (aproximately).
how many st.deviations around the means used to condition
simple effects and plots. Used if covs_conditioning
='mean_sd'
offsett (number of percentiles) around the median used to
condition simple effects and plots. Used if
simpleScale
='percent'
Covariate condition steps from min to max:
At how many values between min and max should the covariate be conditioned simpleScale
='range'
how the levels of a continuous moderator should
appear in tables and plots: labels
, values
and
values_labels
, ovalues
, `ovalues_labels. The latter two refer
to the variable orginal levels, before scaling.
adjustment method for postho tests. One or more of
'none'
, 'bonf'
,'tukey'
'holm'
; provide no,
Bonferroni, Tukey and Holm Post Hoc corrections respectively.
effect size indices for mean comparisons. One or more of
'dm'
, 'ds'
,'g'
for Cohen's d (dm=model SD,ds=sample
SD ) or Hedge's g
TRUE
or FALSE
(default), d confidence intervals
a list of effect sizes to print out. They can be: "eta"
for eta-squared, 'etap'
for partial eta-squared, 'omega'
for
omega-squared, 'omegap'
for partial omega-squared, 'epsilon'
for epsilon-squared, 'epsilonp'
for partial epsilon-squared and
'beta'
for standardized coefficients (betas). Default is
"beta"
and "parEta"
.
TRUE
or FALSE
(default), performs homogeneity
tests
TRUE
or FALSE
(default), computes VIF and Tollerance
for the terms in the model
TRUE
or FALSE
(default), provide a Q-Q plot of
residuals
TRUE
or FALSE
(default), provide a test for
normality of residuals
TRUE
or FALSE
(default), provide a histogram
of residuals superimposed by a normal distribution
TRUE
or FALSE
(default), provide a
scatterplot of the residuals against predicted
TRUE
or FALSE
(default), provide
ìnformation about the intercept (F test, effect size indexes)
TRUE
or FALSE
(default), provide ìnformation
about the effect size indexes
Re-scale the dependent variable.
Method to compute the standard error.
Classical standard errors is the default standard
.
Four methods for heteroschedasticy-consistent
standard errors are available: HC0
,
HC1
,HC2
,HC3
, from package sandwich
.
See vcovHC
for details.
A results object containing:
results$model | a property | ||||
results$info | a table | ||||
results$main$r2 | a table of R | ||||
results$main$intercept | a table of information for the model intercept | ||||
results$main$anova | a table of ANOVA results | ||||
results$main$effectsizes | a table of effect size indeces | ||||
results$main$coefficients | a table | ||||
results$main$vcov | a table | ||||
results$main$contrastCodeTables | an array of contrast coefficients tables | ||||
results$posthoc | an array of post-hoc tables | ||||
results$posthocEffectSize | an array of post-hoc effect size | ||||
results$simpleEffects$anova | a table of ANOVA for simple effects | ||||
results$simpleEffects$coefficients | a table | ||||
results$simpleInteractions | an array of simple interactions tables | ||||
results$emmeans | an array of predicted means tables | ||||
results$mainPlots | an array of results plots | ||||
results$plotnotes | a html | ||||
results$assumptions$homotest | a table of homogeneity tests | ||||
results$assumptions$normtest | a table of normality tests | ||||
results$assumptions$qqplot | a q-q plot | ||||
results$assumptions$normPlot | Residual histogram | ||||
results$assumptions$residPlot | Residual Predicted plot | ||||
results$predicted | an output | ||||
results$residuals | an output |
Tables can be converted to data frames with asDF
or as.data.frame
. For example:
results$info$asDF
as.data.frame(results$info)
data('ToothGrowth')
GAMLj3::gamlj_lm(formula = len ~ supp, data = ToothGrowth)
#>
#> GENERAL LINEAR MODEL
#>
#> Model Info
#> ─────────────────────────────────────────────────────────────────────
#> Info
#> ─────────────────────────────────────────────────────────────────────
#> Model Type Linear Model OLS Model for continuous y
#> Model lm len ~ 1 + supp
#> Distribution Gaussian Normal distribution of residuals
#> Omnibus Tests F
#> Sample size 60
#> Converged yes
#> Y transform none
#> C.I. method Wald
#> ─────────────────────────────────────────────────────────────────────
#>
#>
#> MODEL RESULTS
#>
#> Model Fit
#> ─────────────────────────────────────────────────────────────────────
#> R² Adj. R² df df (res) F p
#> ─────────────────────────────────────────────────────────────────────
#> 0.0594836 0.0432678 1 58 3.668253 0.0603934
#> ─────────────────────────────────────────────────────────────────────
#>
#>
#> ANOVA Omnibus tests
#> ──────────────────────────────────────────────────────────────────────────
#> SS df F p η²p
#> ──────────────────────────────────────────────────────────────────────────
#> Model 205.3500000 1 3.6682525 0.0603934 0.0594836
#> supp 205.3500000 1 3.6682525 0.0603934 0.0594836
#> Residuals 3246.8593333 58
#> Total 3452.2093333 59
#> ──────────────────────────────────────────────────────────────────────────
#>
#>
#> Parameter Estimates (Coefficients)
#> ─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
#> Names Effect Estimate SE Lower Upper β df t p
#> ─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
#> (Intercept) (Intercept) 18.8133333 0.9659221 16.8798301 20.7468365 -0.0000000 58 19.4770705 < .0000001
#> supp1 VC - OJ -3.7000000 1.9318443 -7.5670064 0.1670064 -0.4837034 58 -1.9152683 0.0603934
#> ─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
#>