::p_load(tidyverse, readxl, parameters,
pacman
effectsize, magrittr, multcomp,
multcompView, rcompanion, rstatix,
emmeans, see, performance, fs,
janitor, broom,
conflicted)## resolve some conflicts with same function naming
conflicts_prefer(dplyr::select)
conflicts_prefer(dplyr::filter)
conflicts_prefer(effectsize::eta_squared)
conflicts_prefer(magrittr::set_names)
6 Laser auf Erdbeeren
Letzte Änderung am 13. January 2024 um 17:53:03
Genutzte R Pakete
<- list.files("data/strawberry",
berry_files pattern = "^E", full.names = TRUE)
<- map(berry_files, read_table,
berry_lst skip = 2, col_names = FALSE, col_types = cols())
<- map(berry_files, function(x){
berry_lst <- read_table(x,
tmp_tbl skip = 2, col_names = FALSE, col_types = cols())
<- basename(x) %>%
file_name path_ext_remove() %>%
str_replace_all("\\s", "_")
<- tmp_tbl %>%
tmp_tbl set_names(c("wave", file_name))
return(tmp_tbl)
})
<- berry_lst %>%
berry_tbl reduce(left_join, by = "wave") %>%
pivot_longer(cols = E_1.1._w1:last_col(),
names_sep = "\\._",
values_to = "values",
names_to = c("E", "rep")) %>%
group_by(wave, E) %>%
summarise(mean = mean(values))
ggplot(berry_tbl, aes(wave, mean, color = E)) +
theme_bw() +
geom_line() +
theme(legend.position = "none")
<- read_excel("data/strawberry_sugar.xlsx") %>%
sugar_tbl clean_names() %>%
select(-brixwert, -brix_mittel_note, -messwiederholung,
-g_zucker_l_saft_mittel_note, -oe_einzelfrucht) %>%
filter(!is.na(brix_einzelfrucht)) %>%
mutate(E = str_c("E_", boniturnote, ".", fruchtnummer))
<- left_join(berry_tbl, sugar_tbl,
berry_sugar_tbl by = c("E" = "E")) %>%
filter(boniturnote %in% c(1, 2, 3, 4, 5)) %>%
mutate(boniturnote = as_factor(boniturnote))
<- berry_sugar_tbl %>% pull(wave) %>% unique() wave_vec
Wir haben insgesamt 1740 Wellenlängen.
<- wave_vec[1:20] wave_vec
%>%
berry_sugar_tbl filter(wave == 231) %>%
ggplot(aes(x = brix_einzelfrucht, y = mean,
color = boniturnote)) +
theme_bw() +
geom_point() +
stat_smooth(method = "lm", se = FALSE) +
facet_wrap(~ wave) +
scale_color_okabeito()
%>%
berry_sugar_tbl filter(wave == 231) %$%
lm(mean ~ brix_einzelfrucht) %>%
glance() %>%
pull(r.squared)
[1] 0.01267805
<- map_dbl(wave_vec, function(x){
rsquare_vec <- berry_sugar_tbl %>%
rsquare filter(wave == x) %$%
lm(brix_einzelfrucht ~ mean + boniturnote) %>%
glance() %>%
pull(adj.r.squared)
return(rsquare)
.progress = TRUE) %>%
}, set_names(wave_vec)
which.max(rsquare_vec)
238
15
15] rsquare_vec[
238
0.6111646
%>%
berry_sugar_tbl filter(wave == wave_vec[15]) %>%
ggplot(aes(x = mean, y = brix_einzelfrucht,
color = boniturnote)) +
theme_bw() +
geom_text(aes(label = E)) +
stat_smooth(method = "lm", se = FALSE) +
facet_wrap(~ wave) +
scale_color_okabeito()