CACO GH Data

Author

Emma Fetterly

Castilleja Greenhouse experiment

Setting up the workspace

Load necessary packages

library(tidyverse) #data wrangle
library(ggplot2) # plotting
library(lubridate) # change the date to a standard "Julian Data"
library(emmeans) # pairwise comparisons
library(car) #stats
library(multcomp)
library(bbmle)
library (dlookr) # creating plots to visualize normality
library(ggpubr) # plotting
library(broom) # make tidy tibbles out of summary stat operations
library(lme4) # creating GLMMs
library(redres) # plotting residuals
library(jtools)
library(Matrix)
library(interactions)
library(ggeffects)
library(DHARMa)

Set working directory and read in data from CSV as a data frame called “gh”

#set working directory
setwd(("/Users/emmafetterly/Library/Mobile Documents/com~apple~CloudDocs/Documents/Grad School/Thesis/GH_data/Data_csv"))

#read in the spreadsheet, your file name might be different 
gh <- read.csv("GH_data6.csv", header=TRUE)

First, let’s check our data types

str(gh)
'data.frame':   1440 obs. of  11 variables:
 $ Plant_ID             : chr  "R1_49" "Y1_37" "R1_1" "Y2_13" ...
 $ Block                : int  1 1 1 1 1 1 1 1 1 1 ...
 $ Position             : chr  "A1" "A2" "A3" "A4" ...
 $ Date                 : chr  "7/6/23" "7/6/23" "7/6/23" "7/6/23" ...
 $ Survivval            : chr  "Y" "Y" "Y" "Y" ...
 $ Rosette.Diameter..cm.: chr  "4.01" "5.92" "6.82" "8.64" ...
 $ Number.of.leaves..cm.: chr  "10" "12" "15" "11" ...
 $ LL..cm.              : chr  "2.76" "30" "4.06" "4.73" ...
 $ Soil.Moisture....    : num  NA NA NA NA NA NA NA NA NA NA ...
 $ Week                 : int  1 1 1 1 1 1 1 1 1 1 ...
 $ Notes                : chr  "Very worn" "" "" "" ...

Data wrangle process:

  1. Make new columns for “population” “plant_number_pop” “color” and “block” “tub” and “treatment” based on existing columns

    # Split the "plant_ID" column into "population" and "plant_number_pop" columns
    gh <- separate(gh, Plant_ID, into = c("population", "plant_number_pop"), sep = "_", remove = FALSE)
    
    #make a column that just has "red" and "yellow" labels
    gh <- gh %>%
      mutate(color = case_when(
        substr(population, 1, 1) == "R" ~ "red",
        substr(population, 1, 1) == "Y" ~ "yellow",
        TRUE ~ NA_character_
      ))
    
    #combine "small blocks" into experimental block units
    gh <- gh %>%
      mutate(Combined_Block = ifelse(Block %in% c(1, 2), 1,
                                     ifelse(Block %in% c(3, 4), 2,
                                            ifelse(Block %in% c(5, 6), 3,
                                                   ifelse(Block %in% c(7, 8), 4,
                                                          ifelse(Block %in% c(9, 10), 5,
                                                                 ifelse(Block %in% c(11, 12), 6,
                                                                        NA)))))))
    
    # rename the existing Block column to tub and rename the newly created Combined_Block column to Block
    gh <- gh %>%
      rename(tub = Block, Block = Combined_Block)
    
    # Create a new column "treatment" based on even/odd status of the "block" column
    gh <- gh %>%
      mutate(treatment = ifelse(Block %% 2 == 0, "D", "C"))
  2. Clean up variable names

    gh <-  gh %>%  
      rename(alive = Survivval, 
             size = Rosette.Diameter..cm.,  
             leaves = Number.of.leaves..cm.,
             LL  = LL..cm.,
             VWC = Soil.Moisture....)
  3. Ensure variable types are correct

    gh$Plant_ID<- as.factor(gh$Plant_ID)
    gh$population <- as.factor(gh$population)
    gh$plant_number_pop <- as.integer(gh$plant_number_pop)
    gh$size <- as.numeric(gh$size)
    gh$leaves <- as.numeric(gh$leaves)
    gh$LL <- as.numeric(gh$LL)
    gh$alive <- factor(gh$alive, levels = c("N", "Y"))
    gh$Date<- as.Date(gh$Date, "%m/%d/%y")
    
    #it would be good to create a column with a standard measure of days using the yday function from lubridate
    gh$julian <- yday(gh$Date)
  4. Remove “dummy plants” R31-60

    gh <- subset(gh, !(population == 'R1' & plant_number_pop > 30))
  5. Make appropriate subsets of data for analysis

    #data frame where there are no dead plants
    gh.alive <- subset(gh, alive != "N")
    
    # for the "end of experiment results" we'll want a week 5 data frame to see the most extreme effect of the drought
    
    # we will do this by creating a subset of the data called wk5
    wk5 <- gh.alive[gh.alive$Week == 5, ]
    
    # make subset data frames for easy plotting/sum stats 
    r1_subset_week5 <- gh.alive %>%
      filter(Week == 5)%>%
      filter(population == "R1")
    
    r2_subset_week5 <- gh.alive %>%
      filter(Week == 5)%>%
      filter(population == "R2")
    
    y1_subset_week5 <- gh.alive %>%
      filter(Week == 5)%>%
      filter(population == "Y1")
    
    y2_subset_week5 <- gh.alive %>%
      filter(Week == 5)%>%
      filter(population == "Y2")

Exploratory Data Analysis

Descriptive statistics

Start by looking at descriptive stats of our response variables (size, LL, leaves) by each week

sum_stat_allwks <- gh.alive %>%
  group_by(Week, treatment, population) %>% 
  describe(size, LL, leaves)

sum_stat_allwks
# A tibble: 144 × 29
   described_variables  Week treatment population     n    na  mean    sd
   <chr>               <int> <chr>     <fct>      <int> <int> <dbl> <dbl>
 1 LL                      1 C         R1            16     0  4.03 0.873
 2 LL                      1 C         R2            30     0  4.07 0.817
 3 LL                      1 C         Y1            30     0  5.67 4.80 
 4 LL                      1 C         Y2            30     0  6.34 1.17 
 5 LL                      1 D         R1            13     0  4.37 0.803
 6 LL                      1 D         R2            30     0  3.95 0.711
 7 LL                      1 D         Y1            30     0  4.76 1.09 
 8 LL                      1 D         Y2            30     0  5.93 1.41 
 9 LL                      2 C         R1            16     0  4.35 0.714
10 LL                      2 C         R2            30     0  4.22 0.785
# ℹ 134 more rows
# ℹ 21 more variables: se_mean <dbl>, IQR <dbl>, skewness <dbl>,
#   kurtosis <dbl>, p00 <dbl>, p01 <dbl>, p05 <dbl>, p10 <dbl>, p20 <dbl>,
#   p25 <dbl>, p30 <dbl>, p40 <dbl>, p50 <dbl>, p60 <dbl>, p70 <dbl>,
#   p75 <dbl>, p80 <dbl>, p90 <dbl>, p95 <dbl>, p99 <dbl>, p100 <dbl>

That’s a lot of information, what about just the last week (to look at the major effects of the drought)

sum_stat_wk5 <- wk5 %>%
  group_by(Week, treatment, population) %>% 
  describe(size, LL, leaves)

sum_stat_wk5
# A tibble: 24 × 29
   described_variables  Week treatment population     n    na  mean    sd
   <chr>               <int> <chr>     <fct>      <int> <int> <dbl> <dbl>
 1 LL                      5 C         R1            16     0  4.80 1.20 
 2 LL                      5 C         R2            22     0  4.85 1.10 
 3 LL                      5 C         Y1            27     0  5.38 1.23 
 4 LL                      5 C         Y2            27     0  6.54 1.36 
 5 LL                      5 D         R1            13     1  5.01 1.10 
 6 LL                      5 D         R2            25     0  4.80 0.957
 7 LL                      5 D         Y1            25     0  5.46 1.17 
 8 LL                      5 D         Y2            26     0  6.74 1.53 
 9 leaves                  5 C         R1            16     0 21.2  8.08 
10 leaves                  5 C         R2            22     0 19.8  7.35 
# ℹ 14 more rows
# ℹ 21 more variables: se_mean <dbl>, IQR <dbl>, skewness <dbl>,
#   kurtosis <dbl>, p00 <dbl>, p01 <dbl>, p05 <dbl>, p10 <dbl>, p20 <dbl>,
#   p25 <dbl>, p30 <dbl>, p40 <dbl>, p50 <dbl>, p60 <dbl>, p70 <dbl>,
#   p75 <dbl>, p80 <dbl>, p90 <dbl>, p95 <dbl>, p99 <dbl>, p100 <dbl>

Response variables graphed over time

By population:

By color:

Assumption checking for parametric statistical tests

  1. Normality - Visual checks

Rosette size

R1_normplots_size <- wk5 %>% 
  filter(population == "R1") %>%
  group_by(treatment) %>% 
  plot_normality(size)

R2_normplots_size <- wk5 %>% 
  filter(population == "R2") %>%
  group_by(treatment) %>% 
  plot_normality(size)

Y1_normplots_size <- wk5 %>% 
  filter(population == "Y2") %>%
  group_by(treatment) %>% 
  plot_normality(size)

Y2_normplots_size <- wk5 %>% 
  filter(population == "Y2") %>%
  group_by(treatment) %>% 
  plot_normality(size)

Longest leaf length

R1_normplots_LL <- wk5 %>% 
  filter(population == "R1") %>%
  group_by(treatment) %>% 
  plot_normality(LL)

R2_normplots_LL <- wk5 %>% 
  filter(population == "R2") %>%
  group_by(treatment) %>% 
  plot_normality(LL)

Y1_normplots_LL <- wk5 %>% 
  filter(population == "Y1") %>%
  group_by(treatment) %>% 
  plot_normality(LL)

Y2_normplots_LL <- wk5 %>% 
  filter(population == "Y2") %>%
  group_by(treatment) %>% 
  plot_normality(LL)

Number of leaves

R1_normplots_leaves <- wk5 %>% 
  filter(population == "R1") %>%
  group_by(treatment) %>% 
  plot_normality(leaves)

R2_normplots_leaves <- wk5 %>% 
  filter(population == "R2") %>%
  group_by(treatment) %>% 
  plot_normality(leaves)

Y1_normplots_leaves <- wk5 %>% 
  filter(population == "Y2") %>%
  group_by(treatment) %>% 
  plot_normality(leaves)

Y2_normplots_leaves <- wk5 %>% 
  filter(population == "Y2") %>%
  group_by(treatment) %>% 
  plot_normality(leaves)

Shapiro-Wilks normality test

Tip

p-value above 0.05 indicates normality

Summary

Based on the Shapiro Wilks test, almost all traits have normal distributions except for Y2 D for longest leaf length and R1 D for number of leaves - (is this due to an extreme outlier? R1_12 had 52 leaves, average for group was 21 leaves with SD of 10 leaves)

# size
wk5 %>% 
  group_by(population, treatment) %>% 
  do(tidy(shapiro.test(.$size)))
# A tibble: 8 × 5
# Groups:   population, treatment [8]
  population treatment statistic p.value method                     
  <fct>      <chr>         <dbl>   <dbl> <chr>                      
1 R1         C             0.906  0.0992 Shapiro-Wilk normality test
2 R1         D             0.958  0.715  Shapiro-Wilk normality test
3 R2         C             0.970  0.701  Shapiro-Wilk normality test
4 R2         D             0.960  0.405  Shapiro-Wilk normality test
5 Y1         C             0.978  0.804  Shapiro-Wilk normality test
6 Y1         D             0.948  0.223  Shapiro-Wilk normality test
7 Y2         C             0.967  0.513  Shapiro-Wilk normality test
8 Y2         D             0.926  0.0632 Shapiro-Wilk normality test
#number of leaves
wk5 %>% 
  group_by(population, treatment) %>% 
  do(tidy(shapiro.test(.$leaves)))
# A tibble: 8 × 5
# Groups:   population, treatment [8]
  population treatment statistic p.value method                     
  <fct>      <chr>         <dbl>   <dbl> <chr>                      
1 R1         C             0.987 0.996   Shapiro-Wilk normality test
2 R1         D             0.756 0.00212 Shapiro-Wilk normality test
3 R2         C             0.965 0.586   Shapiro-Wilk normality test
4 R2         D             0.982 0.918   Shapiro-Wilk normality test
5 Y1         C             0.969 0.581   Shapiro-Wilk normality test
6 Y1         D             0.973 0.709   Shapiro-Wilk normality test
7 Y2         C             0.957 0.312   Shapiro-Wilk normality test
8 Y2         D             0.939 0.127   Shapiro-Wilk normality test
#longest leaf length
wk5 %>% 
  group_by(population, treatment) %>% 
  do(tidy(shapiro.test(.$LL)))
# A tibble: 8 × 5
# Groups:   population, treatment [8]
  population treatment statistic p.value method                     
  <fct>      <chr>         <dbl>   <dbl> <chr>                      
1 R1         C             0.965  0.753  Shapiro-Wilk normality test
2 R1         D             0.953  0.649  Shapiro-Wilk normality test
3 R2         C             0.951  0.334  Shapiro-Wilk normality test
4 R2         D             0.986  0.976  Shapiro-Wilk normality test
5 Y1         C             0.950  0.211  Shapiro-Wilk normality test
6 Y1         D             0.940  0.146  Shapiro-Wilk normality test
7 Y2         C             0.917  0.0338 Shapiro-Wilk normality test
8 Y2         D             0.969  0.591  Shapiro-Wilk normality test

Equality of variances

Tip

p-value above 0.05 indicates equal variance

Summary

Data look good for equality of variances

#size
leveneTest(data = wk5, size ~ population*treatment)
Levene's Test for Homogeneity of Variance (center = median)
       Df F value Pr(>F)
group   7  1.3321 0.2378
      173               
# data look good for equality of variances
#number of leaves
leveneTest(data = wk5, leaves ~ population*treatment)
Levene's Test for Homogeneity of Variance (center = median)
       Df F value Pr(>F)
group   7  0.9001 0.5077
      173               
#LL
leveneTest(data = wk5, LL ~ population*treatment)
Levene's Test for Homogeneity of Variance (center = median)
       Df F value Pr(>F)
group   7  0.9144 0.4967
      173               

Box plots of traits by population

theme_emma <- function () { 
  theme_bw() %+replace%
    theme(panel.grid.major = element_blank(), #remove grids
          panel.grid.minor = element_blank(),
          strip.background = element_blank(),
          axis.text.x= element_text(face = "bold", size = "12"),
          axis.text.y= element_text(face = "bold", size = "12"),
          axis.title = element_text(face = "bold", size = "15"),
          axis.ticks.x=element_blank())}

size.plot.box <- ggplot(wk5, aes(x = population, y = size, fill = treatment)) +
  geom_boxplot() +
  scale_fill_manual(values=c("azure3", "azure4")) +
  theme_emma() +
  theme(
    panel.background = element_rect(fill='transparent'),
    plot.background = element_rect(fill='transparent', color=NA),
    panel.grid.major = element_blank(),
    panel.grid.minor = element_blank(),
    legend.background = element_rect(fill='transparent'),
    legend.box.background = element_rect(fill='transparent')
  )+
  labs(y = 'Rosette size (cm)', x = 'Population', fill = 'Treatment')

size.plot.box
Warning: Removed 1 rows containing non-finite values (`stat_boxplot()`).

LL.plot.box <- ggplot(wk5, aes(x = population, y = LL, fill = treatment)) +
  geom_boxplot() +
  scale_fill_manual(values=c("azure3", "azure4")) +
  theme_emma() +
  theme(
    panel.background = element_rect(fill='transparent'),
    plot.background = element_rect(fill='transparent', color=NA),
    panel.grid.major = element_blank(),
    panel.grid.minor = element_blank(),
    legend.background = element_rect(fill='transparent'),
    legend.box.background = element_rect(fill='transparent')
  )+
  labs(y = 'Longest leaf length (cm)', x = 'Population', fill = 'Treatment')

LL.plot.box
Warning: Removed 1 rows containing non-finite values (`stat_boxplot()`).

leaves.plot.box <- ggplot(wk5, aes(x = population, y = leaves, fill = treatment)) +
  geom_boxplot() +
  scale_fill_manual(values=c("azure3", "azure4")) +
  theme_emma() +
  theme(
    panel.background = element_rect(fill='transparent'),
    plot.background = element_rect(fill='transparent', color=NA),
    panel.grid.major = element_blank(),
    panel.grid.minor = element_blank(),
    legend.background = element_rect(fill='transparent'),
    legend.box.background = element_rect(fill='transparent')
  )+
  labs(y = 'Number of leaves', x = 'Population', fill = 'Treatment')

leaves.plot.box
Warning: Removed 1 rows containing non-finite values (`stat_boxplot()`).

Box plots of traits by color

size.plot.box.color <- ggplot(wk5, aes(x = color, y = size, fill = treatment)) +
  geom_boxplot() +
  scale_fill_manual(values=c("azure3", "azure4")) +
  theme_emma() +
  theme(
    panel.background = element_rect(fill='transparent'),
    plot.background = element_rect(fill='transparent', color=NA),
    panel.grid.major = element_blank(),
    panel.grid.minor = element_blank(),
    legend.background = element_rect(fill='transparent'),
    legend.box.background = element_rect(fill='transparent')
  )+
  labs(y = 'Rosette size (cm)', x = 'Flower color', fill = 'Treatment')

size.plot.box.color
Warning: Removed 1 rows containing non-finite values (`stat_boxplot()`).

LL.plot.box.color <- ggplot(wk5, aes(x = color, y = LL, fill = treatment)) +
  geom_boxplot() +
  scale_fill_manual(values=c("azure3", "azure4")) +
  theme_emma() +
  theme(
    panel.background = element_rect(fill='transparent'),
    plot.background = element_rect(fill='transparent', color=NA),
    panel.grid.major = element_blank(),
    panel.grid.minor = element_blank(),
    legend.background = element_rect(fill='transparent'),
    legend.box.background = element_rect(fill='transparent')
  )+
  labs(y = 'Longest leaf length (cm)', x = 'Flower color', fill = 'Treatment')

LL.plot.box.color
Warning: Removed 1 rows containing non-finite values (`stat_boxplot()`).

leaves.plot.box.color <- ggplot(wk5, aes(x = color, y = leaves, fill = treatment)) +
  geom_boxplot() +
  scale_fill_manual(values=c("azure3", "azure4")) +
  theme_emma() +
  theme(
    panel.background = element_rect(fill='transparent'),
    plot.background = element_rect(fill='transparent', color=NA),
    panel.grid.major = element_blank(),
    panel.grid.minor = element_blank(),
    legend.background = element_rect(fill='transparent'),
    legend.box.background = element_rect(fill='transparent')
  )+
  labs(y = 'Number of leaves', x = 'Flower color', fill = 'Treatment')

leaves.plot.box.color
Warning: Removed 1 rows containing non-finite values (`stat_boxplot()`).

Modeling

Response variables

trait (size, LL, number of leaves) - continuous

Predictor variables
  1. treatment - categorical control (C) and drought (D)
  2. color - categorical red and yellow
  3. population - (nested within color?) - R1, R2, Y1, Y2

block (random effect) - 1-6

Unsure

Need to nest population within color? Repeat measures for time series data?

Trait and color GLM without accounting for block

#model with color + treatment interaction 

mod.size.color.norandom <- lm(size ~ color*treatment, data = wk5)

summ(mod.size.color.norandom)
Observations 181 (1 missing obs. deleted)
Dependent variable size
Type OLS linear regression
F(3,177) 11.71
R² 0.17
Adj. R² 0.15
Est. S.E. t val. p
(Intercept) 8.97 0.35 25.34 0.00
coloryellow 1.68 0.46 3.64 0.00
treatmentD -0.15 0.50 -0.29 0.77
coloryellow:treatmentD 0.50 0.66 0.76 0.45
Standard errors: OLS
color_size_intplot_norandom <- cat_plot(mod.size.color.norandom, pred = color , modx = treatment, plot.points = TRUE, point.shape = TRUE,
                                   vary.lty = TRUE, colors = "Dark2")

anova_size_color_norandom <- Anova(mod.size.color.norandom)

anova_size_color_norandom
Anova Table (Type II tests)

Response: size
                Sum Sq  Df F value    Pr(>F)    
color           163.90   1 34.4128 2.145e-08 ***
treatment         0.96   1  0.2010    0.6545    
color:treatment   2.78   1  0.5847    0.4455    
Residuals       843.00 177                      
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
color_size_intplot_norandom

# checking residuals 
resid_ouput_size_color.norandom <- simulateResiduals(fittedModel = mod.size.color.norandom, plot = F)

plot(resid_ouput_size_color.norandom)

#model with color + treatment interaction

mod.LL.color.norandom <- lm(LL ~ color*treatment, data = wk5)

summ(mod.LL.color.norandom)
Observations 181 (1 missing obs. deleted)
Dependent variable LL
Type OLS linear regression
F(3,177) 12.20
R² 0.17
Adj. R² 0.16
Est. S.E. t val. p
(Intercept) 4.83 0.21 22.77 0.00
coloryellow 1.13 0.28 4.09 0.00
treatmentD 0.05 0.30 0.16 0.87
coloryellow:treatmentD 0.11 0.39 0.27 0.79
Standard errors: OLS
anova_LL_color_norandom <- Anova(mod.LL.color.norandom)

anova_LL_color_norandom
Anova Table (Type II tests)

Response: LL
                 Sum Sq  Df F value    Pr(>F)    
color            61.967   1 36.3076 9.535e-09 ***
treatment         0.542   1  0.3176    0.5738    
color:treatment   0.126   1  0.0740    0.7859    
Residuals       302.088 177                      
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
color_LL_intplot_norandom <- cat_plot(mod.LL.color.norandom, pred = color , modx = treatment, plot.points = TRUE, point.shape = TRUE,
                                   vary.lty = TRUE, colors = "Dark2")

color_LL_intplot_norandom

#checking residuals
resid_ouput_LL_color.norandom <- simulateResiduals(fittedModel = mod.LL.color.norandom, plot = F)

plot(resid_ouput_LL_color.norandom)

#model with color + treatment interaction

mod.leaves.color.norandom <- lm(leaves ~ color*treatment, data = wk5)

summ(mod.leaves.color.norandom)
Observations 181 (1 missing obs. deleted)
Dependent variable leaves
Type OLS linear regression
F(3,177) 2.09
R² 0.03
Adj. R² 0.02
Est. S.E. t val. p
(Intercept) 20.42 1.29 15.79 0.00
coloryellow 2.28 1.69 1.35 0.18
treatmentD -1.29 1.83 -0.71 0.48
coloryellow:treatmentD 1.19 2.40 0.50 0.62
Standard errors: OLS
anova_leaves_color_norandom <- Anova(mod.leaves.color.norandom)

anova_leaves_color_norandom
Anova Table (Type II tests)

Response: leaves
                 Sum Sq  Df F value  Pr(>F)  
color             363.7   1  5.7231 0.01779 *
treatment          16.1   1  0.2539 0.61495  
color:treatment    15.7   1  0.2470 0.61978  
Residuals       11247.0 177                  
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
color_leaves_intplot_norandom <- cat_plot(mod.leaves.color.norandom, pred = color , modx = treatment, plot.points = TRUE, point.shape = TRUE,
                                   vary.lty = TRUE, colors = "Dark2")

color_leaves_intplot_norandom

# checking residuals
resid_ouput_leaves_color.norandom <- simulateResiduals(fittedModel = mod.leaves.color.norandom, plot = F)

plot(resid_ouput_leaves_color.norandom)

Mixed model with random effect of block

#model with color by treatment interaction and random effect of block

mod.size.color <- lmer(size ~ color*treatment + (1|Block), data = wk5)
boundary (singular) fit: see help('isSingular')
summ(mod.size.color)
Observations 181
Dependent variable size
Type Mixed effects linear regression
AIC 805.76
BIC 824.96
Pseudo-R² (fixed effects) 0.16
Pseudo-R² (total) 0.16
Fixed Effects
Est. S.E. t val. d.f. p
(Intercept) 8.97 0.36 25.22 20.77 0.00
coloryellow 1.68 0.46 3.63 174.01 0.00
treatmentD -0.15 0.50 -0.29 21.01 0.77
coloryellow:treatmentD 0.50 0.66 0.76 173.75 0.45
p values calculated using Kenward-Roger standard errors and d.f.
Random Effects
Group Parameter Std. Dev.
Block (Intercept) 0.00
Residual 2.18
Grouping Variables
Group # groups ICC
Block 6 0.00
anova_size_color <- Anova(mod.size.color, 3)

anova_size_color
Analysis of Deviance Table (Type III Wald chisquare tests)

Response: size
                   Chisq Df Pr(>Chisq)    
(Intercept)     642.0083  1  < 2.2e-16 ***
color            13.2164  1  0.0002775 ***
treatment         0.0851  1  0.7705041    
color:treatment   0.5847  1  0.4444765    
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
population_size_intplot <- cat_plot(mod.size.color, pred = color , modx = treatment, plot.points = TRUE, point.shape = TRUE,
                                   vary.lty = TRUE, colors = "Dark2")

population_size_intplot

# checking residuals 
resid_ouput_size_color <- simulateResiduals(fittedModel = mod.size.color, plot = F)

plot(resid_ouput_size_color)

#model with color by treatment interaction and random effect of block

mod.LL.color <- lmer(LL ~ color*treatment + (1|Block), data = wk5)

summ(mod.LL.color)
Observations 181
Dependent variable LL
Type Mixed effects linear regression
AIC 624.11
BIC 643.30
Pseudo-R² (fixed effects) 0.17
Pseudo-R² (total) 0.17
Fixed Effects
Est. S.E. t val. d.f. p
(Intercept) 4.83 0.22 22.38 19.44 0.00
coloryellow 1.13 0.28 4.09 173.96 0.00
treatmentD 0.05 0.30 0.15 19.63 0.88
coloryellow:treatmentD 0.11 0.39 0.27 173.71 0.78
p values calculated using Kenward-Roger standard errors and d.f.
Random Effects
Group Parameter Std. Dev.
Block (Intercept) 0.06
Residual 1.31
Grouping Variables
Group # groups ICC
Block 6 0.00
anova_LL_color <- Anova(mod.size.color, 3)

anova_LL_color
Analysis of Deviance Table (Type III Wald chisquare tests)

Response: size
                   Chisq Df Pr(>Chisq)    
(Intercept)     642.0083  1  < 2.2e-16 ***
color            13.2164  1  0.0002775 ***
treatment         0.0851  1  0.7705041    
color:treatment   0.5847  1  0.4444765    
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
population_LL_intplot <- cat_plot(mod.LL.color, pred = color , modx = treatment, plot.points = TRUE, point.shape = TRUE,
                                   vary.lty = TRUE, colors = "Dark2")

population_LL_intplot

# checking residuals
resid_ouput_LL_color <- simulateResiduals(fittedModel = mod.LL.color, plot = F)
residuals(resid_ouput_LL_color)
  [1] 0.084 0.692 0.448 0.824 0.584 0.568 0.536 0.652 0.060 0.064 0.028 0.868
 [13] 0.440 0.696 0.752 0.856 0.892 0.092 0.568 0.288 0.720 0.620 0.224 0.220
 [25] 0.948 0.816 0.264 0.540 0.132 0.008 0.904 0.480 0.312 0.560 0.236 0.496
 [37] 0.704 0.368 0.004 1.000 0.972 0.896 0.304 0.100 0.204 0.528 0.868 0.768
 [49] 0.060 0.304 0.196 0.244 0.552 0.012 0.276 0.624 0.272 0.508 0.744 0.332
 [61] 0.944 0.408 0.200 0.648 0.512 0.960 0.820 0.848 0.124 0.288 0.788 0.788
 [73] 0.816 0.180 0.820 0.480 0.252 0.316 0.384 0.128 0.060 0.116 0.564 0.044
 [85] 0.704 0.220 0.652 0.292 0.552 0.136 0.068 0.564 0.660 0.448 0.088 0.420
 [97] 0.696 0.496 0.660 0.380 0.808 0.940 0.320 0.572 0.988 0.768 0.852 0.808
[109] 0.284 0.496 0.556 0.052 0.600 0.300 0.808 0.772 0.300 0.076 0.792 0.044
[121] 0.536 0.140 0.588 0.512 0.344 0.768 0.592 0.328 0.552 0.864 0.868 0.084
[133] 0.696 0.468 0.112 0.232 0.168 0.984 0.992 0.516 0.400 0.892 0.924 0.968
[145] 0.836 0.608 0.256 0.944 0.160 0.548 0.812 0.720 0.928 0.668 0.564 0.972
[157] 0.892 0.440 0.684 0.492 0.136 0.468 0.372 0.156 0.504 0.004 0.192 0.688
[169] 0.956 0.452 0.500 0.516 0.180 0.780 0.792 0.508 0.204 0.560 0.812 0.308
[181] 0.048
plot(resid_ouput_LL_color)

#model with color by treatment interaction random effect of block

mod.leaves.color <- lmer(leaves ~ color*treatment + (1|Block), data = wk5)
boundary (singular) fit: see help('isSingular')
summ(mod.size.color)
Observations 181
Dependent variable size
Type Mixed effects linear regression
AIC 805.76
BIC 824.96
Pseudo-R² (fixed effects) 0.16
Pseudo-R² (total) 0.16
Fixed Effects
Est. S.E. t val. d.f. p
(Intercept) 8.97 0.36 25.22 20.77 0.00
coloryellow 1.68 0.46 3.63 174.01 0.00
treatmentD -0.15 0.50 -0.29 21.01 0.77
coloryellow:treatmentD 0.50 0.66 0.76 173.75 0.45
p values calculated using Kenward-Roger standard errors and d.f.
Random Effects
Group Parameter Std. Dev.
Block (Intercept) 0.00
Residual 2.18
Grouping Variables
Group # groups ICC
Block 6 0.00
anova_leaves_color <- Anova(mod.leaves.color, 3)

anova_leaves_color
Analysis of Deviance Table (Type III Wald chisquare tests)

Response: leaves
                   Chisq Df Pr(>Chisq)    
(Intercept)     249.3880  1     <2e-16 ***
color             1.8290  1     0.1763    
treatment         0.4972  1     0.4807    
color:treatment   0.2470  1     0.6192    
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
color_leaves_intplot <- cat_plot(mod.leaves.color, pred = color , modx = treatment, plot.points = TRUE, point.shape = TRUE,
                                   vary.lty = TRUE, colors = "Dark2")

color_leaves_intplot

#residuals
resid_ouput_leaves_color <- simulateResiduals(fittedModel = mod.leaves.color, plot = F)
residuals(resid_ouput_leaves_color)
  [1] 0.180 0.888 0.624 0.888 0.296 0.480 0.420 0.592 0.084 0.872 0.572 0.916
 [13] 0.608 0.836 0.788 0.892 0.940 0.080 0.984 0.344 0.912 0.256 0.060 0.580
 [25] 0.420 0.396 0.572 0.592 0.352 0.036 0.428 0.796 0.632 0.824 0.476 0.284
 [37] 0.628 0.968 0.044 0.420 0.752 0.796 0.548 0.256 0.048 0.668 0.728 0.708
 [49] 0.124 0.316 0.420 0.084 0.480 0.160 0.724 0.624 0.484 0.624 0.472 0.380
 [61] 0.548 0.144 0.308 0.780 0.980 0.940 0.536 0.936 0.320 0.212 0.860 0.944
 [73] 0.400 0.220 0.592 0.748 0.276 0.388 0.832 0.164 0.092 0.064 0.548 0.036
 [85] 0.708 0.228 0.684 0.324 0.400 0.072 0.060 0.212 0.116 0.104 0.396 0.168
 [97] 0.672 0.696 0.400 0.420 0.960 0.580 0.912 0.352 0.804 0.820 0.788 0.868
[109] 0.764 0.584 0.372 0.100 0.440 0.416 0.760 0.168 0.212 0.068 0.396 0.252
[121] 0.488 0.092 0.292 0.620 0.744 0.392 0.136 0.600 0.948 0.720 0.336 0.268
[133] 0.660 0.804 0.180 0.384 0.168 1.000 0.916 0.880 0.528 0.268 0.744 0.784
[145] 0.340 0.240 0.064 0.572 0.140 0.076 0.752 0.452 0.944 0.076 0.256 0.920
[157] 1.000 0.604 0.596 0.944 0.160 0.440 0.328 0.188 0.512 0.028 0.400 1.000
[169] 0.812 0.536 0.152 0.272 0.316 0.416 0.712 0.516 0.152 0.388 0.384 0.412
[181] 0.336
plot(resid_ouput_leaves_color)

Mortality data

# Convert 'alive' column to binary (0 for 'N', 1 for 'Y')
gh$alive_binary <- as.integer(gh$alive == 'Y')

# Subset the data for a specific week 
# ( Week 6 - date of final mortality survey of experiment)
subset_week6.all <- gh %>%
  filter(Week == 6)

# Calculate percent mortality and count by population

population_summary <- subset_week6.all %>%
  group_by(population, treatment) %>%
  summarise(count = n(),
            percent_mortality = mean(alive_binary)*100)  # Percent mortality
`summarise()` has grouped output by 'population'. You can override using the
`.groups` argument.

% Survival by population

% Survival by color

`summarise()` has grouped output by 'color'. You can override using the
`.groups` argument.

logit.reg_color <- glm(alive_binary ~ VWC*color,
                       data = subset_week6.all,
                       family = binomial(link = "logit"))


summ(logit.reg_color)
Observations 210
Dependent variable alive_binary
Type Generalized linear model
Family binomial
Link logit
𝛘²(3) 12.67
Pseudo-R² (Cragg-Uhler) 0.08
Pseudo-R² (McFadden) 0.05
AIC 258.31
BIC 271.70
Est. S.E. z val. p
(Intercept) 0.04 0.47 0.09 0.93
VWC 0.03 0.02 1.53 0.13
coloryellow -0.30 0.61 -0.49 0.62
VWC:coloryellow 0.02 0.02 0.87 0.39
Standard errors: MLE
GLM_survival_facet_pop <- ggplot(subset_week6.all, aes(x = VWC, y = alive_binary, color = population)) + 
  geom_point() +
  stat_smooth(method = "glm", method.args = list(family=binomial), se = TRUE) + 
  xlab("VWC") +
  ylab("Probability of survival") +
  ggtitle("Probability of survival against the soil water content (VWC)") +
  theme_classic() +
  facet_wrap(~ population) +
  scale_color_manual(values = c("R1" = "red3", "R2" = "red3", "Y1" = "gold", "Y2" = "gold"))

GLM_survival_facet_pop
`geom_smooth()` using formula = 'y ~ x'

GLM_survival_facet_color <- ggplot(subset_week6.all, aes(x = VWC, y = alive_binary, color = color)) + 
  geom_point() +
  stat_smooth(method = "glm", method.args = list(family=binomial), se = TRUE) + 
  xlab("VWC") +
  ylab("Probability of survival") +
  ggtitle("Probability of survival against the soil water content (VWC)") +
  theme_classic() +
  facet_wrap(~ color) +
  scale_color_manual(values = c("red" = "red3", "yellow" =  "gold"))

GLM_survival_facet_color
`geom_smooth()` using formula = 'y ~ x'

Relative Growth Rate

#### RGR #### 
# Week 1 - Week 5

# make week 1 and week 5 data frames
week1_data <- gh %>% filter(Week == 1)
week5_data <- gh %>% filter(Week == 5)

# Merge the data based on Plant_ID
merged_data <- merge(week1_data, week5_data, by = "Plant_ID", suffixes = c("_week1", "_week5"))

# Calculate relative growth rate (RGR)
merged_data <- merged_data %>%
  mutate(
    RGR = (log(size_week5) - log(size_week1)) / (5 - 1)  # Assuming measurements are weekly
  )

#select certain columns to retain plant ID, popualtion, plant number, color, treatment and block info
selected_columns <- merged_data[, c("Plant_ID", "population_week1","plant_number_pop_week1","color_week1", "RGR", "treatment_week1", "Block_week1", "alive_week5", "alive_binary_week5")]

#get rid of negative RGR and dead plants
RGR_clean <- selected_columns %>% 
  filter(RGR >= 0) %>% 
  filter(alive_binary_week5 >= 0) %>% 
  rename(treatment = treatment_week1, 
         block = Block_week1,  
         alive = alive_week5,
         alive_binary = alive_binary_week5,
         color = color_week1,
         plant_number_pop = plant_number_pop_week1,
         population = population_week1)

str(RGR_clean)
'data.frame':   131 obs. of  9 variables:
 $ Plant_ID        : Factor w/ 240 levels "R1_1","R1_10",..: 1 2 3 4 5 6 7 8 9 12 ...
 $ population      : Factor w/ 4 levels "R1","R2","Y1",..: 1 1 1 1 1 1 1 1 1 1 ...
 $ plant_number_pop: int  1 10 11 12 13 14 15 16 17 2 ...
 $ color           : chr  "red" "red" "red" "red" ...
 $ RGR             : num  0.1156 0.038 0.0849 0.0825 0.0279 ...
 $ treatment       : chr  "C" "C" "D" "D" ...
 $ block           : num  1 5 6 6 1 1 2 2 3 1 ...
 $ alive           : Factor w/ 2 levels "N","Y": 2 2 2 2 2 2 2 2 2 2 ...
 $ alive_binary    : int  1 1 1 1 1 1 1 1 1 1 ...

#### Examining RGR with model - color and treatment ####

mod.RGR.color.norandom <- lm(RGR ~ color*treatment, data = RGR_clean)

summ(mod.RGR.color.norandom)
Observations 131
Dependent variable RGR
Type OLS linear regression
F(3,127) 1.15
R² 0.03
Adj. R² 0.00
Est. S.E. t val. p
(Intercept) 0.05 0.00 9.76 0.00
coloryellow -0.01 0.01 -1.02 0.31
treatmentD 0.00 0.01 0.44 0.66
coloryellow:treatmentD -0.00 0.01 -0.42 0.68
Standard errors: OLS
color_RGR_intplot_norandom <- cat_plot(mod.RGR.color.norandom, pred = color, modx = treatment, plot.points = TRUE, point.shape = TRUE,
                                        vary.lty = TRUE, colors = "Dark2")

color_RGR_intplot_norandom 

# ANOVA of model

anova_RGR_color_norandom <- Anova(mod.RGR.color.norandom)

anova_RGR_color_norandom
Anova Table (Type II tests)

Response: RGR
                  Sum Sq  Df F value  Pr(>F)  
color           0.002218   1  3.2073 0.07569 .
treatment       0.000025   1  0.0368 0.84825  
color:treatment 0.000121   1  0.1757 0.67581  
Residuals       0.087809 127                  
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
# Significant effect of color and treatment, but not a significant effect of color : treatment
#### Examining RGR with model - population and treatment ####

mod.RGR.pop.norandom <- lm(RGR ~ population*treatment, data = RGR_clean)

summ(mod.RGR.pop.norandom)
Observations 131
Dependent variable RGR
Type OLS linear regression
F(7,123) 1.55
R² 0.08
Adj. R² 0.03
Est. S.E. t val. p
(Intercept) 0.05 0.01 7.05 0.00
populationR2 -0.01 0.01 -0.97 0.34
populationY1 -0.01 0.01 -0.79 0.43
populationY2 -0.02 0.01 -1.88 0.06
treatmentD -0.00 0.01 -0.01 0.99
populationR2:treatmentD 0.01 0.01 0.41 0.68
populationY1:treatmentD 0.00 0.01 0.29 0.77
populationY2:treatmentD -0.00 0.01 -0.32 0.75
Standard errors: OLS
pop_RGR_intplot_norandom <- cat_plot(mod.RGR.pop.norandom, pred = population, modx = treatment, plot.points = TRUE, point.shape = TRUE,
                                       vary.lty = TRUE, colors = "Dark2")

pop_RGR_intplot_norandom 

# ANOVA of model

anova_RGR_pop_norandom <- Anova(mod.RGR.pop.norandom)

anova_RGR_pop_norandom
Anova Table (Type II tests)

Response: RGR
                       Sum Sq  Df F value  Pr(>F)  
population           0.006695   3  3.3114 0.02237 *
treatment            0.000104   1  0.1542 0.69525  
population:treatment 0.000565   3  0.2794 0.84019  
Residuals            0.082889 123                  
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
# Significant effect of population and treatment, but not a significant effect of population : treatment