Skip to content

Commit

Permalink
differences for PR #51
Browse files Browse the repository at this point in the history
  • Loading branch information
actions-user committed Dec 2, 2024
1 parent b0dc4a0 commit b58e076
Show file tree
Hide file tree
Showing 8 changed files with 245 additions and 183 deletions.
316 changes: 154 additions & 162 deletions branch.md

Large diffs are not rendered by default.

21 changes: 13 additions & 8 deletions files/plans/plan_5.R
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,21 @@ tar_plan(
bill_depth_mm ~ bill_length_mm,
data = penguins_data
),
species_model = lm(
bill_depth_mm ~ bill_length_mm + species,
data = penguins_data
adelie_model = lm(
bill_depth_mm ~ bill_length_mm,
data = filter(penguins_data, species == "Adelie")
),
interaction_model = lm(
bill_depth_mm ~ bill_length_mm * species,
data = penguins_data
chinstrap_model = lm(
bill_depth_mm ~ bill_length_mm,
data = filter(penguins_data, species == "Chinstrap")
),
gentoo_model = lm(
bill_depth_mm ~ bill_length_mm,
data = filter(penguins_data, species == "Gentoo")
),
# Get model summaries
combined_summary = glance(combined_model),
species_summary = glance(species_model),
interaction_summary = glance(interaction_model)
adelie_summary = glance(adelie_model),
chinstrap_summary = glance(chinstrap_model),
gentoo_summary = glance(gentoo_model)
)
23 changes: 11 additions & 12 deletions files/plans/plan_6.R
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,18 @@ tar_plan(
),
# Clean data
penguins_data = clean_penguin_data(penguins_data_raw),
# Build models
models = list(
combined_model = lm(
bill_depth_mm ~ bill_length_mm, data = penguins_data),
species_model = lm(
bill_depth_mm ~ bill_length_mm + species, data = penguins_data),
interaction_model = lm(
bill_depth_mm ~ bill_length_mm * species, data = penguins_data)
# Group data
tar_group_by(
penguins_data_grouped,
penguins_data,
species
),
# Get model summaries
# Build combined model with all species together
combined_summary = model_glance(penguins_data),
# Build one model per species
tar_target(
model_summaries,
glance(models[[1]]),
pattern = map(models)
species_summary,
model_glance(penguins_data_grouped),
pattern = map(penguins_data_grouped)
)
)
28 changes: 28 additions & 0 deletions files/plans/plan_6b.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
options(tidyverse.quiet = TRUE)
source("R/packages.R")
source("R/functions.R")

tar_plan(
# Load raw data
tar_file_read(
penguins_data_raw,
path_to_file("penguins_raw.csv"),
read_csv(!!.x, show_col_types = FALSE)
),
# Clean data
penguins_data = clean_penguin_data(penguins_data_raw),
# Group data
tar_group_by(
penguins_data_grouped,
penguins_data,
species
),
# Build combined model with all species together
combined_summary = model_glance_orig(penguins_data),
# Build one model per species
tar_target(
species_summary,
model_glance_orig(penguins_data_grouped),
pattern = map(penguins_data_grouped)
)
)
16 changes: 16 additions & 0 deletions files/tar_functions/model_augment.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
model_glance <- function(penguins_data) {
# Make model
model <- lm(
bill_depth_mm ~ bill_length_mm,
data = penguins_data)
# Get species name
species_name <- unique(penguins_data$species)
# If this is the combined dataset with multiple
# species, changed name to 'combined'
if (length(species_name) > 1) {
species_name <- "combined"
}
# Get model summary and add species name
augment(model) |>
mutate(species = species_name, .before = 1)
}
16 changes: 16 additions & 0 deletions files/tar_functions/model_glance.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
model_glance <- function(penguins_data) {
# Make model
model <- lm(
bill_depth_mm ~ bill_length_mm,
data = penguins_data)
# Get species name
species_name <- unique(penguins_data$species)
# If this is the combined dataset with multiple
# species, changed name to 'combined'
if (length(species_name) > 1) {
species_name <- "combined"
}
# Get model summary and add species name
glance(model) |>
mutate(species = species_name, .before = 1)
}
6 changes: 6 additions & 0 deletions files/tar_functions/model_glance_orig.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
model_glance_orig <- function(penguins_data) {
model <- lm(
bill_depth_mm ~ bill_length_mm,
data = penguins_data)
broom::glance(model)
}
2 changes: 1 addition & 1 deletion md5sum.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"episodes/organization.Rmd" "74df25779b74013eeb6a8ca7b8934efe" "site/built/organization.md" "2024-11-19"
"episodes/packages.Rmd" "2c0eb6138ea6685a0ee279c89b381bc4" "site/built/packages.md" "2024-11-19"
"episodes/files.Rmd" "b7f4ef83379a58d5c30d8e011e3b2c0d" "site/built/files.md" "2024-11-19"
"episodes/branch.Rmd" "6f1187d6df3310eb042aaae3a44328dc" "site/built/branch.md" "2024-11-19"
"episodes/branch.Rmd" "dc21a4964dece3a46bf50af1917249f8" "site/built/branch.md" "2024-12-02"
"episodes/parallel.Rmd" "3ec032e9a527138e70e2efb4e5a10410" "site/built/parallel.md" "2024-11-19"
"episodes/quarto.Rmd" "76b257de72894ab24e1d1852b6149bf9" "site/built/quarto.md" "2024-11-19"
"instructors/instructor-notes.md" "df3784ee5c0436a9e171071f7965d3fc" "site/built/instructor-notes.md" "2024-11-19"
Expand Down

0 comments on commit b58e076

Please sign in to comment.