Code
<- penguins %>% lm(body_mass_g ~ sex + species, data = .)
pen_model1 <- penguins %>% lm(body_mass_g ~ bill_depth_mm + bill_length_mm + flipper_length_mm, data = .)
pen_model2 <- penguins %>% lm(body_mass_g ~ ., data = .) pen_model3
easystats
Steen Flammild Harsted
January 10, 2024
Install the easystats
package and add a library call to easystats
in the code chunk where you call your other libraries.
palmerpenguins
datasetInstall the palmerpenguins
package and add a library call to palmerpenguins
in the code chunk where you call your other libraries. Read the documentation for palmerpenguins
here
penguins
dataset. Let body_mass_g
be your dependent variable (y), and investigate how changes in the other variables in penguins
impact body_mass_g
Build at least two models
Consider making the formula for one of the models body_mass_g ~ .
- What does this do?
Store them as (pen_model1
, pen_model2
, etc.)
Remember that we are just practicing coding here. Today is about How do we code it. The purpose of this particular exercise is to introduce you to a few very useful functions from the easystats
package(s), and to get you started with using lm()
.
penguins
(summary(penguins)
)$
pen_model1$
and explore the drop down menucoefficients(pen_model1)
summary()
of one of your modelseasystats
check_model
)
model_parameters()
compare_models()
compare_performance()
compare_performance() %>% plot()
PhDPublications
datasetAER
and load the package (+add library call to your library code chunk)AER
contains >100 different datasets (to see a list: data(package = 'AER')
).PhDPublications
, by writing data(PhDPublications)
PhDPublications
PhDPublications
, investigate what influenced the number of articles
PhD students published during the last 3 years of their PhD.articles
what type of data is this?
articles
.
articles
variable (see plot below).
lm()
. Instead you should use glm(, family = poisson())
articles ~ .
- What does this do?phd_model1
, phd_model2
, etc.)easystats
functions to work with different model types. The output will automagically adjust. This is a big advantage to other packages and programs.PhDPublications
(summary(PhDPublications)
)$
phd_model1$
and explore the drop down menucoefficients(phd_model1)
summary()
of one of your modelseasystats
check_model
)
model_parameters()
compare_models()
compare_performance()
compare_performance() %>% plot()
For more information on easystats
read here.
gtsummary
can also be used to create regressiontables:tbl_regression()
add_n()
add_glance_source_note()
tbl_regression()
to a plot()
tbl_uvregression()
is great for a large number of univariable regressionsGGally
Install the GGally
package and add a library call to the code chunk where you call your libraries.
GGally
has many powerful functions for dataanalysis
ggpairs()
to investigate your data. Try:
ggpairs(PhDPublications)
ggpairs(PhDPublications, mapping = aes(color = gender, alpha = 0.2))
ggcoef_model()
to plot you coefficients. Try: