Coding workshop: Week 8

Multiple linear regression

tidyverse
readxl
here
janitor
MuMIn
ggeffects
scales
scale_x_discrete
AICc
read_csv
pipe operators
|>
mutate
select
as_factor
fct_relevel
case_match
str
slice_sample
expression
ggpredict
lm
summary
facet_wrap
scale_color_manual
geom_jitter
geom_pointrange
github
forking
Author
Affiliation
Modified

May 24, 2025

1. Summary

Packages

  • tidyverse
  • readxl
  • here
  • janitor
  • MuMIn
  • ggeffects
  • scales

Operations

New functions

  • using scale_x_discrete() with label_wrap() to wrap axis label text
  • using AICc() for model selection

Review

  • read in data using read_csv()
  • chain functions together using |>
  • modify columns using mutate()
  • select columns using select()
  • set factors using as_factor()
  • reorder levels in factors using fct_relevel()
  • recoding variables using case_match() within mutate()
  • looking at data structure using str()
  • displaying data using slice_sample()
  • using expression() to make complex plot labels
  • using ggpredict() to get model predictions
  • fitting linear models using lm()
  • looking at model summaries using summary()
  • using facet_wrap() to create panels based on a categorical variable
  • using scale_color_manual() to manually assign colors
  • using geom_jitter() and geom_pointrange() to represent data and model predictions

Data sources

The dataset is from Valliere, Justin; Zhang, Jacqueline; Sharifi, M.; Rundel, Philip (2019). Data from: Can we condition native plants to increase drought tolerance and improve restoration success? [Dataset]. Dryad. https://doi.org/10.5061/dryad.v0861f7.

The associated paper is Valliere J. M., J. Zhang, M. R. Sharifi, and P. W. Rundel. 2019. Can we condition native plants to increase drought tolerance and improve restoration success? Ecological Applications 29(3):e01863. 10.1002/eap.1863.

2. Code

All code is in the rendered .html file in this repository.