PIC_IA_DataAnalysis

Quarto

Quarto enables you to weave together content and executable code into a finished document. To learn more about Quarto see https://quarto.org.

Running Code

When you click the Render button a document will be generated that includes both content and the output of embedded code. You can embed code like this:

library(lme4)
Loading required package: Matrix
library(lmerTest)

Attaching package: 'lmerTest'
The following object is masked from 'package:lme4':

    lmer
The following object is masked from 'package:stats':

    step
library(emmeans)
library(car)
Loading required package: carData
library(RVAideMemoire)
*** Package RVAideMemoire v 0.9-81 ***

Attaching package: 'RVAideMemoire'
The following object is masked from 'package:lme4':

    dummy
library(DHARMa)
This is DHARMa 0.4.4. For overview type '?DHARMa'. For recent changes, type news(package = 'DHARMa')
library(MuMIn)
library(tidyverse)
Warning: package 'tidyverse' was built under R version 4.1.3
Warning: package 'ggplot2' was built under R version 4.1.3
Warning: package 'tibble' was built under R version 4.1.3
Warning: package 'tidyr' was built under R version 4.1.3
Warning: package 'readr' was built under R version 4.1.3
Warning: package 'purrr' was built under R version 4.1.3
Warning: package 'dplyr' was built under R version 4.1.3
Warning: package 'stringr' was built under R version 4.1.3
Warning: package 'forcats' was built under R version 4.1.3
Warning: package 'lubridate' was built under R version 4.1.3
-- Attaching core tidyverse packages ------------------------ tidyverse 2.0.0 --
v dplyr     1.1.2     v readr     2.1.4
v forcats   1.0.0     v stringr   1.5.0
v ggplot2   3.4.2     v tibble    3.2.1
v lubridate 1.9.2     v tidyr     1.3.0
v purrr     1.0.1     
-- Conflicts ------------------------------------------ tidyverse_conflicts() --
x tidyr::expand() masks Matrix::expand()
x dplyr::filter() masks stats::filter()
x dplyr::lag()    masks stats::lag()
x tidyr::pack()   masks Matrix::pack()
x dplyr::recode() masks car::recode()
x purrr::some()   masks car::some()
x tidyr::unpack() masks Matrix::unpack()
i Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
library(glmmTMB)
Warning in checkMatrixPackageVersion(): Package version inconsistency detected.
TMB was built with Matrix version 1.4.0
Current Matrix version is 1.3.4
Please re-install 'TMB' from source using install.packages('TMB', type = 'source') or ask CRAN for a binary version of 'TMB' matching CRAN's 'Matrix' package
library(corrplot)
corrplot 0.92 loaded
library(RColorBrewer)
library(ggplot2)
library(MASS)

Attaching package: 'MASS'

The following object is masked from 'package:dplyr':

    select
library(agricolae)
Warning: package 'agricolae' was built under R version 4.1.3
library(vegan)
Warning: package 'vegan' was built under R version 4.1.3
Loading required package: permute
Loading required package: lattice
Warning: package 'lattice' was built under R version 4.1.3
Registered S3 methods overwritten by 'vegan':
  method      from
  plot.rda    klaR
  predict.rda klaR
  print.rda   klaR
This is vegan 2.6-4
data <- read.csv("PIC_65_FIRE.AN.csv", header = T, na.strings = "N/A")
head(data)
        ID LINE     SIRE      DAM   LITTER   PEN FARM       ENTRY_TIME
1 96251326   65 91032775 92185339 78043216 B0113  774 10/27/2022 12:51
2 96251327   65 91032775 92185339 78043216 B0113  774 10/27/2022 12:00
3 96251327   65 91032775 92185339 78043216 B0113  774 10/27/2022 13:03
4 96284921   65 90218081 90208620 78064883 B0113  774  10/27/2022 7:27
5 96284921   65 90218081 90208620 78064883 B0113  774  10/27/2022 8:04
6 96284921   65 90218081 90208620 78064883 B0113  774  10/27/2022 8:41
         EXIT_TIME STAY_IN FEED_INTK ENTRY_WT EXIT_WT FEEDER_NO START_DAY
1 10/27/2022 13:02     649       265     1056     791         5 27-Oct-22
2 10/27/2022 12:32    1948       514     1086     572         5 27-Oct-22
3 10/27/2022 13:06     169        57      791     734         5 27-Oct-22
4  10/27/2022 7:37     627        85      473     388         5 27-Oct-22
5  10/27/2022 8:17     768       196      613     417         5 27-Oct-22
6  10/27/2022 8:48     413        88      691     603         5 27-Oct-22
  OFFTEST_DAY
1    2-Jan-23
2    2-Jan-23
3    2-Jan-23
4    2-Jan-23
5    2-Jan-23
6    2-Jan-23
summary(data)
       ID                LINE         SIRE               DAM          
 Min.   :96251326   Min.   :65   Min.   :87591163   Min.   :86315923  
 1st Qu.:96601065   1st Qu.:65   1st Qu.:89122431   1st Qu.:90888369  
 Median :97257792   Median :65   Median :90896190   Median :92297569  
 Mean   :97267678   Mean   :65   Mean   :90604058   Mean   :91786593  
 3rd Qu.:97887849   3rd Qu.:65   3rd Qu.:92013824   3rd Qu.:93218718  
 Max.   :98368540   Max.   :65   Max.   :93693188   Max.   :94232962  
     LITTER             PEN                 FARM      ENTRY_TIME       
 Min.   :78043165   Length:114263      Min.   :774   Length:114263     
 1st Qu.:78261882   Class :character   1st Qu.:774   Class :character  
 Median :78637026   Mode  :character   Median :774   Mode  :character  
 Mean   :78609475                      Mean   :774                     
 3rd Qu.:78945651                      3rd Qu.:774                     
 Max.   :79177365                      Max.   :774                     
  EXIT_TIME            STAY_IN        FEED_INTK          ENTRY_WT   
 Length:114263      Min.   :    5   Min.   :-3543.0   Min.   :-913  
 Class :character   1st Qu.:  576   1st Qu.:  245.0   1st Qu.: 817  
 Mode  :character   Median : 1315   Median :  593.0   Median :1117  
                    Mean   : 1402   Mean   :  638.9   Mean   :1167  
                    3rd Qu.: 2038   3rd Qu.:  947.0   3rd Qu.:1480  
                    Max.   :10169   Max.   : 9102.0   Max.   :9090  
    EXIT_WT         FEEDER_NO      START_DAY         OFFTEST_DAY       
 Min.   :-913.0   Min.   : 4.00   Length:114263      Length:114263     
 1st Qu.: 414.0   1st Qu.:13.00   Class :character   Class :character  
 Median : 516.0   Median :31.00   Mode  :character   Mode  :character  
 Mean   : 528.1   Mean   :28.65                                        
 3rd Qu.: 635.0   3rd Qu.:46.00                                        
 Max.   :3917.0   Max.   :64.00                                        
summary(data$PEN)
   Length     Class      Mode 
   114263 character character 
summary(data$FEED_INTK)
   Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
-3543.0   245.0   593.0   638.9   947.0  9102.0 
summary(data$STAY_IN)
   Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
      5     576    1315    1402    2038   10169 
summary(data$ENTRY_TIME)
   Length     Class      Mode 
   114263 character character 
summary(data$EXIT_TIME)
   Length     Class      Mode 
   114263 character character 
summary(data$ENTRY_WT)
   Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
   -913     817    1117    1167    1480    9090 
summary(data$EXIT_WT)
   Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
 -913.0   414.0   516.0   528.1   635.0  3917.0 

You can add options to executable code like this

library(ggplot2)

# Convert PEN column to numeric
#data$PEN <- as.numeric(data$PEN)

# Categorize PEN as a factor with 15 groups
data$PEN <- factor(data$PEN)

# Plotting boxplots
ggplot(data = data, aes(x= PEN, y= FEED_INTK))+
  geom_boxplot(outlier.shape = 1)+
  theme(axis.text.x = element_text(hjust = 1))+
  labs(title = "Boxplot of FEED_INTK by PEN")+
  labs(y= "FEED_INTAKE")+
  labs(x="PEN")+
  theme(legend.position = "none")

ggplot(data = data, aes(x= PEN, y= STAY_IN))+
  geom_boxplot(outlier.shape = 1)+
  theme(axis.text.x = element_text(hjust = 1))+
  labs(title = "Boxplot of STAY_IN by PEN")+
  labs(y= "STAY_IN")+
  labs(x="PEN")+
  theme(legend.position = "none")

The echo: false option disables the printing of code (only output is displayed).