data(Prestige, package="carData")
type
is really an ordered factor. Make it so.
Prestige$type <- ordered(Prestige$type, levels=c("bc", "wc", "prof")) # reorder levels
Main effects model
mod0 <- lm(prestige ~ education + income + women + type,
data=Prestige)
Simply plot the model object
op <- par(mfrow = c(2,2), mar=c(4,4,3,1)+.1)
plot(mod0)
par(op)
performance::check_model()
plotsBelow, I use the check_model
function from the
performance
package. This is part of the
easystats
collection of packages. See: https://easystats.github.io/easystats/ for an
overview.
if(!require(easystats)) install.packages("easystats")
## Loading required package: easystats
## # Attaching packages: easystats 0.5.2
## v insight 0.18.2 v datawizard 0.5.1
## v bayestestR 0.12.1 v performance 0.9.2
## v parameters 0.18.2 v effectsize 0.7.0.5
## v modelbased 0.8.5 v correlation 0.8.2
## v see 0.7.2 v report 0.5.5
library(easystats)
if(!require(performance)) install.packages("performance") # also needs "see"
library(performance)
The default plot gives an array of six nicely done diagnostic plots
check_model(mod0)
# can specify `check="all"`, or a subset of these:
check <- c("vif", "qq", "normality", "linearity", "ncv", "homogeneity", "outliers")
check_model(mod0, check=c("normality", "linearity", "ncv", "homogeneity", "outliers"))
detrended QQ plots are often better
check_model(mod0, check="qq", detrend=TRUE)
if(!require(report)) install.packages("report")
library(report)
report(mod0)
## We fitted a linear model (estimated using OLS) to predict prestige with
## education (formula: prestige ~ education + income + women + type). The model
## explains a statistically significant and substantial proportion of variance (R2
## = 0.83, F(5, 92) = 93.07, p < .001, adj. R2 = 0.83). The model's intercept,
## corresponding to education = 0, is at 0.18 (95% CI [-13.81, 14.18], t(92) =
## 0.03, p = 0.979). Within this model:
##
## - The effect of education is statistically significant and positive (beta =
## 3.66, 95% CI [2.38, 4.95], t(92) = 5.67, p < .001; Std. beta = 0.59, 95% CI
## [0.38, 0.80])
## - The effect of income is statistically significant and positive (beta =
## 1.04e-03, 95% CI [5.22e-04, 1.56e-03], t(92) = 3.98, p < .001; Std. beta =
## 0.26, 95% CI [0.13, 0.39])
## - The effect of women is statistically non-significant and positive (beta =
## 6.44e-03, 95% CI [-0.05, 0.07], t(92) = 0.21, p = 0.832; Std. beta = 0.01, 95%
## CI [-0.10, 0.12])
## - The effect of type [linear] is statistically non-significant and positive
## (beta = 4.18, 95% CI [-1.35, 9.71], t(92) = 1.50, p = 0.137; Std. beta = 0.24,
## 95% CI [-0.08, 0.57])
## - The effect of type [quadratic] is statistically significant and positive
## (beta = 4.79, 95% CI [1.72, 7.86], t(92) = 3.10, p = 0.003; Std. beta = 0.28,
## 95% CI [0.10, 0.46])
##
## Standardized parameters were obtained by fitting the model on a standardized
## version of the dataset. 95% Confidence Intervals (CIs) and p-values were
## computed using a Wald t-distribution approximation., We fitted a linear model
## (estimated using OLS) to predict prestige with income (formula: prestige ~
## education + income + women + type). The model explains a statistically
## significant and substantial proportion of variance (R2 = 0.83, F(5, 92) =
## 93.07, p < .001, adj. R2 = 0.83). The model's intercept, corresponding to
## income = 0, is at 0.18 (95% CI [-13.81, 14.18], t(92) = 0.03, p = 0.979).
## Within this model:
##
## - The effect of education is statistically significant and positive (beta =
## 3.66, 95% CI [2.38, 4.95], t(92) = 5.67, p < .001; Std. beta = 0.59, 95% CI
## [0.38, 0.80])
## - The effect of income is statistically significant and positive (beta =
## 1.04e-03, 95% CI [5.22e-04, 1.56e-03], t(92) = 3.98, p < .001; Std. beta =
## 0.26, 95% CI [0.13, 0.39])
## - The effect of women is statistically non-significant and positive (beta =
## 6.44e-03, 95% CI [-0.05, 0.07], t(92) = 0.21, p = 0.832; Std. beta = 0.01, 95%
## CI [-0.10, 0.12])
## - The effect of type [linear] is statistically non-significant and positive
## (beta = 4.18, 95% CI [-1.35, 9.71], t(92) = 1.50, p = 0.137; Std. beta = 0.24,
## 95% CI [-0.08, 0.57])
## - The effect of type [quadratic] is statistically significant and positive
## (beta = 4.79, 95% CI [1.72, 7.86], t(92) = 3.10, p = 0.003; Std. beta = 0.28,
## 95% CI [0.10, 0.46])
##
## Standardized parameters were obtained by fitting the model on a standardized
## version of the dataset. 95% Confidence Intervals (CIs) and p-values were
## computed using a Wald t-distribution approximation., We fitted a linear model
## (estimated using OLS) to predict prestige with women (formula: prestige ~
## education + income + women + type). The model explains a statistically
## significant and substantial proportion of variance (R2 = 0.83, F(5, 92) =
## 93.07, p < .001, adj. R2 = 0.83). The model's intercept, corresponding to women
## = 0, is at 0.18 (95% CI [-13.81, 14.18], t(92) = 0.03, p = 0.979). Within this
## model:
##
## - The effect of education is statistically significant and positive (beta =
## 3.66, 95% CI [2.38, 4.95], t(92) = 5.67, p < .001; Std. beta = 0.59, 95% CI
## [0.38, 0.80])
## - The effect of income is statistically significant and positive (beta =
## 1.04e-03, 95% CI [5.22e-04, 1.56e-03], t(92) = 3.98, p < .001; Std. beta =
## 0.26, 95% CI [0.13, 0.39])
## - The effect of women is statistically non-significant and positive (beta =
## 6.44e-03, 95% CI [-0.05, 0.07], t(92) = 0.21, p = 0.832; Std. beta = 0.01, 95%
## CI [-0.10, 0.12])
## - The effect of type [linear] is statistically non-significant and positive
## (beta = 4.18, 95% CI [-1.35, 9.71], t(92) = 1.50, p = 0.137; Std. beta = 0.24,
## 95% CI [-0.08, 0.57])
## - The effect of type [quadratic] is statistically significant and positive
## (beta = 4.79, 95% CI [1.72, 7.86], t(92) = 3.10, p = 0.003; Std. beta = 0.28,
## 95% CI [0.10, 0.46])
##
## Standardized parameters were obtained by fitting the model on a standardized
## version of the dataset. 95% Confidence Intervals (CIs) and p-values were
## computed using a Wald t-distribution approximation. and We fitted a linear
## model (estimated using OLS) to predict prestige with type (formula: prestige ~
## education + income + women + type). The model explains a statistically
## significant and substantial proportion of variance (R2 = 0.83, F(5, 92) =
## 93.07, p < .001, adj. R2 = 0.83). The model's intercept, corresponding to type
## = , is at 0.18 (95% CI [-13.81, 14.18], t(92) = 0.03, p = 0.979). Within this
## model:
##
## - The effect of education is statistically significant and positive (beta =
## 3.66, 95% CI [2.38, 4.95], t(92) = 5.67, p < .001; Std. beta = 0.59, 95% CI
## [0.38, 0.80])
## - The effect of income is statistically significant and positive (beta =
## 1.04e-03, 95% CI [5.22e-04, 1.56e-03], t(92) = 3.98, p < .001; Std. beta =
## 0.26, 95% CI [0.13, 0.39])
## - The effect of women is statistically non-significant and positive (beta =
## 6.44e-03, 95% CI [-0.05, 0.07], t(92) = 0.21, p = 0.832; Std. beta = 0.01, 95%
## CI [-0.10, 0.12])
## - The effect of type [linear] is statistically non-significant and positive
## (beta = 4.18, 95% CI [-1.35, 9.71], t(92) = 1.50, p = 0.137; Std. beta = 0.24,
## 95% CI [-0.08, 0.57])
## - The effect of type [quadratic] is statistically significant and positive
## (beta = 4.79, 95% CI [1.72, 7.86], t(92) = 3.10, p = 0.003; Std. beta = 0.28,
## 95% CI [0.10, 0.46])
##
## Standardized parameters were obtained by fitting the model on a standardized
## version of the dataset. 95% Confidence Intervals (CIs) and p-values were
## computed using a Wald t-distribution approximation.
model_dashboard()
easystats::model_dashboard()
gives a comprehensive
report, constructed with the report
package Not run here
because it generates a separate HTML file.
# model_dashboard(mod0,
# output_file = "prestige-dashboard.html",
# output_dir = "examples")