E_Hj=E.Hj*z.mult^3,
E_Hp=E.Hp*z.mult^3,
E_He=E.He*z.mult^3,
h_a=h.a/(24^2),
s_G=s.G,
T_REF=T.ref,
T_A=T.A,
T_AL=T.AL,
T_AH=T.AH,
T_L=T.L,
T_H=T.H,
E_0=E.0*z.mult^4,
f=f,
d_V=d.V,
d_E=d.E,
d_Egg=d.E,
mu_X=mu.X,
mu_E=mu.E,
mu_V=mu.V,
mu_P=mu.P,
kap_X_P=kap.P,
n_X=c(n.CX,n.HX,n.OX,n.ON),
n_E=c(n.CE,n.HE,n.OE,n.OE),
n_V=c(n.CV,n.HV,n.OV,n.OV),
n_P=c(n.CP,n.HP,n.OP,n.OP),
n_M_nitro=c(n.NC,n.NH,n.NO,n.NN),
L_b=L.b,
V_init=V_init,
E_init=E_init,
E_H_init=E_H_init,
stage=stage,
photostart = photostart,
photofinish = photofinish,
daylengthstart = daylengthstart,
daylengthfinish = daylengthfinish,
photodirs=photodirs,
photodirf=photodirf,
soilnode = 3)
yearout<-as.data.frame(ecto$yearout)
yearsout<-as.data.frame(ecto$yearsout)
environ<-as.data.frame(ecto$environ)
debout<-as.data.frame(ecto$debout)
metout<-as.data.frame(ecto$metout)
#taking only snow days, omitting egg stage
metout_snow <- metout[debout$STAGE != 0,]
results_all[results_all$Species == j & results_all$Locality == loc[s], "devtime" ] <- yearout$DEVTIME
results_all[results_all$Species == j & results_all$Locality == loc[s], "birthday" ] <- yearout$BIRTHDAY
results_all[results_all$Species == j & results_all$Locality == loc[s], "MonMature" ] <- yearout$MONMATURE
results_all[results_all$Species == j & results_all$Locality == loc[s], "MonRepro" ] <- yearout$MONREPRO
results_all[results_all$Species == j & results_all$Locality == loc[s], "Fecundity" ] <- max(yearsout$Fec)
results_all[results_all$Species == j & results_all$Locality == loc[s], "Clutches" ] <- max(yearsout$Clutch)
results_all[results_all$Species == j & results_all$Locality == loc[s], "AnnualAct" ] <- yearout$ANNUALACT
results_all[results_all$Species == j & results_all$Locality == loc[s], "LifeSpan" ] <- max(yearsout$YEAR)
#add maxwgt and maxlen
results_all[results_all$Species == j & results_all$Locality == loc[s], "MaxWgt" ] <- max(yearsout$MaxWgt)
results_all[results_all$Species == j & results_all$Locality == loc[s], "MaxLen" ] <- max(yearsout$MaxLen)
#add egg_dev time
results_all[results_all$Species == j & results_all$Locality == loc[s], "egg_dev" ] <- max(yearsout$tStg1) - max(yearsout$tEgg)
#number of snow days
results_all[results_all$Species == j & results_all$Locality == loc[s], "NO_Snow" ] <- sum(metout_snow$SNOWDEP==0)/24
#solar radiation - mean of daily maximum radiation during periods without snow
results_all[results_all$Species == j & results_all$Locality == loc[s], "mean_MAX_SOLR" ] <- mean(with(metout_snow, tapply(SOLR, DOY, max)))
results_all[results_all$Species == j & results_all$Locality == loc[s], "Rel_hum" ] <- mean(environ$RELHUM)
results_all[results_all$Species == j & results_all$Locality == loc[s], "Solar" ] <- mean(environ$SOLAR)
results_all[results_all$Species == j & results_all$Locality == loc[s], "MinTB" ] <- min((environ$TC))
results_all[results_all$Species == j & results_all$Locality == loc[s], "MaxTB" ] <- max((environ$TC))
results_all[results_all$Species == j & results_all$Locality == loc[s], "MeanTB" ] <- mean(environ$TC)
results_all[results_all$Species == j & results_all$Locality == loc[s], "Forage" ] <- yearsout$Forage[length(which(yearsout$Forage != 0))]
results_all[results_all$Species == j & results_all$Locality == loc[s], "Bask" ] <- yearsout$Bsk[length(which(yearsout$Bsk != 0))]
results_all[results_all$Species == j & results_all$Locality == loc[s], "Year" ] <- yearsout$YEAR[length(which(yearsout$YEAR != 0))]
results_all[results_all$Species == j & results_all$Locality == loc[s], "Years_repro" ] <- length(which(yearsout$Clutch != 0))
results_all[results_all$Species == j & results_all$Locality == loc[s], "MeanTALOC" ] <- mean(metout$TALOC)
results_all[results_all$Species == j & results_all$Locality == loc[s], "MeanVLOC" ] <- mean(metout$VLOC)
results_all[results_all$Species == j & results_all$Locality == loc[s], "MeanRHLOC" ] <- mean(metout$RHLOC)
#yearsout$YEAR[length(which(yearsout$Clutch != 0))]  add to get number of years after having first clutch
save(ecto, file=paste0("../../Results/ecto_files/ecto_spring", j, "_", loc[s], ".Rda"))
}
}
results_all
yearsout
environ
save(results_all, file="../../Results/ECTOTHERM_results/results_all_ecto_springTP.Rda")
library(xlsx)
write.xlsx(results_all, file="../../Results/ECTOTHERM_results/results_all_ecto_springTP.xlsx", sheetName = "Ecto_rez")
knitr::opts_chunk$set(echo = TRUE)
knitr::opts_chunk$set(message=FALSE)
knitr::opts_chunk$set(warning=FALSE)
knitr::opts_chunk$set(tidy=TRUE)
using<-function(...) {
libs<-unlist(list(...))
req<-unlist(lapply(libs,require,character.only=TRUE))
need<-libs[req==FALSE]
if(length(need)>0){
install.packages(need)
lapply(need,require,character.only=TRUE)
}
}
using("dplyr", "ggplot2", "ggpubr", "rstatix", "NCmisc", "car", "lme4", "DHARMa", "emmeans", "performance", "sjPlot", "rphylopic", "jpeg", "flexplot", "report", "broom", "ggfortify", "MASS", "jtools", "svglite",  "multcomp", "vegan", "showtext", "formatR", "AICcmodavg")
rm(list = ls())
getwd()
load("../../Results/ECTOTHERM_results/results_all_ecto_summerTP.Rda")
res_ecto_stats <- results_all
load("../../Results/ECTOTHERM_results/results_all_ecto_springTP.Rda")
res_ecto_stats_spring <- results_all
res_ecto_stats
res_ecto_stats_spring
rm(list = ls())
getwd()
load("../../Results/ECTOTHERM_results/results_all_ecto_summerTP.Rda")
res_ecto_stats <- results_all
load("../../Results/ECTOTHERM_results/results_all_ecto_springTP.Rda")
res_ecto_stats_spring <- results_all
res_ecto_stats$Season <- "SummerTP"
res_ecto_stats_spring$Season <- "SpringTP"
res_ecto_stats
res_ecto_stats_spring
res_both_seasons <- bind_rows(res_ecto_stats, res_ecto_stats_spring)
res_both_seasons
comparison_df <- res_both_seasons %>%
group_by(Sintopy, Species, Season) %>%
summarise(avg_value = mean(value_column, na.rm = TRUE))
res_both_seasons
comparison_df <- res_both_seasons %>%
group_by(Sintopy, Species, Season) %>%
summarise(avg_value = mean(Fecundity, na.rm = TRUE))
comparison_df
res_both_seasons
#Get yearly values
res_both_seasons$Forage_year <- res_ecto_stats$Forage/res_ecto_stats$Year
res_both_seasons$Bask_year <- res_ecto_stats$Bask/res_ecto_stats$Year
res_both_seasons$Fecundity_year <- res_ecto_stats$Fecundity/res_ecto_stats$Year
res_both_seasons$Clutches_year <- res_ecto_stats$Clutches/res_ecto_stats$Year
res_both_seasons
comparison_df <- res_both_seasons %>%
group_by(Species, Season) %>%
summarise(across(c(egg_dev, LifeSpan, Years_repro, Bask_year, Forage_year, Fecundity_year),
list(mean = mean, min = min, max = max),
na.rm = TRUE,
.names = "{col}_{fn}"))
comparison_df
comparison_df <- res_both_seasons %>%
group_by(Species, Sintopy, Season) %>%
summarise(across(c(egg_dev, LifeSpan, Years_repro, Bask_year, Forage_year, Fecundity_year),
list(mean = mean, min = min, max = max),
na.rm = TRUE,
.names = "{col}_{fn}"))
comparison_df
#Get yearly values
res_ecto_stats$Forage_year <- res_ecto_stats$Forage/res_ecto_stats$Year
res_ecto_stats$Bask_year <- res_ecto_stats$Bask/res_ecto_stats$Year
res_ecto_stats$Fecundity_year <- res_ecto_stats$Fecundity/res_ecto_stats$Year
res_ecto_stats$Clutches_year <- res_ecto_stats$Clutches/res_ecto_stats$Year
#Rename values
res_ecto_stats$Species[res_ecto_stats$Species == "Ihor"] <- "I. horvathi"
res_ecto_stats$Species[res_ecto_stats$Species == "Pmur"] <- "P. muralis"
res_ecto_stats$Sintopy[res_ecto_stats$Sintopy == "sint"] <- "Sintopy"
res_ecto_stats$Sintopy[res_ecto_stats$Sintopy == "aloPmur"] <- "Muralis allotopy"
res_ecto_stats$Sintopy[res_ecto_stats$Sintopy == "aloIhor"] <- "Horvathi allotopy"
#Turn to factor
res_ecto_stats$Locality <- as.factor(res_ecto_stats$Locality)
res_ecto_stats$Sintopy <- as.factor(res_ecto_stats$Sintopy)
res_ecto_stats$Species <- as.factor(res_ecto_stats$Species)
str(res_ecto_stats)
res_ecto_stats <- res_ecto_stats %>%
rename(Loc_type = Sintopy)
res_ecto_stats <- res_ecto_stats[, c( "Elevation", "Loc_type", "Species", "MeanTALOC", "MeanRHLOC", "Solar", "NO_Snow", "egg_dev", "LifeSpan", "Years_repro", "Bask_year", "Forage_year", "Fecundity_year")]
head(res_ecto_stats)
str(res_ecto_stats)
## Microclimate analysis table
loc_stats <- res_ecto_stats %>% distinct(MeanTALOC, .keep_all = TRUE)
#check data distribution
gghistogram(loc_stats$MeanTALOC, bins = 15)
ggboxplot(loc_stats$MeanTALOC)
#Check lm model
lm_MeanTALOC <- lm(MeanTALOC ~Elevation+Loc_type, data = loc_stats)
# Get summary and p values
summary(lm_MeanTALOC)
# Plot
lm_Plot_eTemp <- lm(MeanTALOC ~Elevation, data = loc_stats)
MeanTemp_plot <- visualize(lm_Plot_eTemp,  MeanTALOC ~Elevation, plot="model")+
scale_color_manual(values = c("black"))+
theme_classic()+
labs_pubr()+
labs(title = NULL, y=expression(paste("Mean temperature (°C)")), x=NULL)+
theme(legend.position="null")
MeanTemp_plot
#Check model fit, residuals etc.
autoplot(lm_MeanTALOC)+
theme_classic()
shapiro.test(residuals(lm_MeanTALOC))
#check data distribution
gghistogram(loc_stats$MeanTALOC, bins = 15)
ggboxplot(loc_stats$MeanTALOC)
#Check lm model
lm_MeanTALOC <- lm(MeanTALOC ~Elevation+Loc_type, data = loc_stats)
# Get summary and p values
summary(lm_MeanTALOC)
# Plot
lm_Plot_eTemp <- lm(MeanTALOC ~Elevation, data = loc_stats)
MeanTemp_plot <- visualize(lm_Plot_eTemp,  MeanTALOC ~Elevation, plot="model")+
scale_color_manual(values = c("black"))+
theme_classic()+
labs_pubr()+
labs(title = NULL, y=expression(paste("Mean temperature (°C)")), x=NULL)+
theme(legend.position="null")
MeanTemp_plot
#Check model fit, residuals etc.
autoplot(lm_MeanTALOC)+
theme_classic()
shapiro.test(residuals(lm_MeanTALOC))
#check data distribution
gghistogram(loc_stats$MeanRHLOC, bins = 15)
ggboxplot(loc_stats$MeanRHLOC)
#Check lm model first
lm_MeanRHLOC <- lm(MeanRHLOC ~Elevation+Loc_type, data = loc_stats)
# Get summary and p values
summary(lm_MeanRHLOC)
# Plot
lm_plot_eHum <- lm(MeanRHLOC ~Elevation, data = loc_stats)
Mean_humid <- visualize(lm_plot_eHum, MeanRHLOC ~ Elevation, plot="model")+
scale_color_manual(values = c("black"))+
theme_classic()+
labs_pubr()+
labs(title = NULL, y=expression(paste("Mean relative humidity (%)")), x=NULL)+
theme(legend.position="null")
Mean_humid
#Check model fit, residuals etc.
autoplot(lm_MeanRHLOC)+
theme_classic()
shapiro.test(residuals(lm_MeanRHLOC))
#check data distribution
gghistogram(loc_stats$Solar, bins = 5)
ggboxplot(loc_stats$Solar)
#Check lm model first
lm_Solar <- lm(Solar ~Elevation+Loc_type, data = loc_stats)
# Get summary and p values
summary(lm_Solar) #AIC delta <4, include interaction
# Plot
lm_solar_plot <- lm(Solar ~Elevation, data = loc_stats)
Mean_solar <- visualize(lm_solar_plot,  Solar ~ Elevation, plot="model")+
scale_color_manual(values = c("black"))+
theme_classic()+
#labs(title = NULL, y="Mean solar radiation (W/m2)", x=NULL)+
labs(title = NULL, y=expression(paste('Mean solar radiation' ~ " " ~ (W/m^{2}))), x=NULL)+
labs_pubr()+
theme(legend.position="null")
Mean_solar
#Check model fit, residuals etc.
autoplot(lm_Solar)+
theme_classic()
shapiro.test(residuals(lm_Solar))
#Check comparisons
summary(glht(lm_Solar, linfct = mcp(Loc_type = 'Tukey')))
#check data distribution
gghistogram(loc_stats$NO_Snow, bins = 50)
ggboxplot(loc_stats$NO_Snow)
#Check lm model first
lm_NO_Snow <- lm(NO_Snow ~ Elevation+Loc_type, data = loc_stats)
# Get summary and p values
summary(lm_NO_Snow)
# Plot
lm_plot_eSnow <- lm(NO_Snow ~ Elevation, data = loc_stats)
SnowDays_plot<- visualize(lm_plot_eSnow, NO_Snow ~ Elevation, plot="model")+
scale_color_manual(values = c("black"))+
theme_classic()+
labs_pubr()+
labs(title = NULL, y=expression(paste("Days without snow (n. days)")), x=NULL)+
theme(legend.position="null")
SnowDays_plot
#Check model fit, residuals etc.
autoplot(lm_NO_Snow)+
theme_classic()
shapiro.test(residuals(lm_NO_Snow))
plot_micro <- ggarrange(MeanTemp_plot, SnowDays_plot, Mean_solar, Mean_humid, nrow = 2, ncol = 2, labels = NULL,
common.legend = TRUE, legend = "none", font.label = list(size=13))
plot_micro
#ggsave("plot_micro_final.pdf", plot=plot_micro, path = "../../Figures/Ectotherm_plots/", units="cm", width=20, height=20, dpi=300)
#ggsave("plot_microfinal.svg", plot=plot_micro, path = "../../Figures/Ectotherm_plots/", units="cm", width=20, height=20, dpi=300)
#ggsave("plot_micro_final.png", plot=plot_micro, path = "../../Figures/Ectotherm_plots/", units="cm", width=20, height=20, dpi=300, bg="white")
ggsave("plot_micro_final_udpated.pdf", plot=plot_micro, path = "../../Figures/Ectotherm_plots/", units="cm", width=20, height=20, dpi=300)
ggsave("plot_microfinal_updated.svg", plot=plot_micro, path = "../../Figures/Ectotherm_plots/", units="cm", width=20, height=20, dpi=300)
ggsave("plot_micro_final_updated.png", plot=plot_micro, path = "../../Figures/Ectotherm_plots/", units="cm", width=20, height=20, dpi=300, bg="white")
summary(glht(lm_Solar, linfct = mcp(Loc_type = 'Tukey')))
# Get summary and p values
summary(lm_Solar) #AIC delta <4, include interaction
res_ecto_stats
rm(list = ls())
getwd()
load("../../Results/ECTOTHERM_results/results_all_ecto_summerTP.Rda")
res_ecto_stats <- results_all
load("../../Results/ECTOTHERM_results/results_all_ecto_springTP.Rda")
res_ecto_stats_spring <- results_all
res_ecto_stats$Season <- "SummerTP"
res_ecto_stats_spring$Season <- "SpringTP"
res_ecto_stats
res_ecto_stats
res_ecto_stats_spring
res_both_seasons <- bind_rows(res_ecto_stats, res_ecto_stats_spring)
res_both_seasons
#Get yearly values
res_both_seasons$Forage_year <- res_ecto_stats$Forage/res_ecto_stats$Year
res_both_seasons$Bask_year <- res_ecto_stats$Bask/res_ecto_stats$Year
res_both_seasons$Fecundity_year <- res_ecto_stats$Fecundity/res_ecto_stats$Year
res_both_seasons
comparison_df <- res_both_seasons %>%
group_by(Species, Sintopy, Season) %>%
summarise(across(c(egg_dev, LifeSpan, Years_repro, Bask_year, Forage_year, Fecundity_year),
list(mean = mean, min = min, max = max),
na.rm = TRUE,
.names = "{col}_{fn}"))
comparison_df
comparison_df
getwd()
load("../../Results/ECTOTHERM_results/results_all_ecto_summerTP.Rda")
res_ecto_stats <- results_all
#load("../../Results/ECTOTHERM_results/results_all_ecto_springTP.Rda")
#res_ecto_stats_spring <- results_all
#Get yearly values
res_ecto_stats$Forage_year <- res_ecto_stats$Forage/res_ecto_stats$Year
res_ecto_stats$Bask_year <- res_ecto_stats$Bask/res_ecto_stats$Year
res_ecto_stats$Fecundity_year <- res_ecto_stats$Fecundity/res_ecto_stats$Year
res_ecto_stats$Clutches_year <- res_ecto_stats$Clutches/res_ecto_stats$Year
#Rename values
res_ecto_stats$Species[res_ecto_stats$Species == "Ihor"] <- "I. horvathi"
res_ecto_stats$Species[res_ecto_stats$Species == "Pmur"] <- "P. muralis"
res_ecto_stats$Sintopy[res_ecto_stats$Sintopy == "sint"] <- "Sintopy"
res_ecto_stats$Sintopy[res_ecto_stats$Sintopy == "aloPmur"] <- "Muralis allotopy"
res_ecto_stats$Sintopy[res_ecto_stats$Sintopy == "aloIhor"] <- "Horvathi allotopy"
#Turn to factor
res_ecto_stats$Locality <- as.factor(res_ecto_stats$Locality)
res_ecto_stats$Sintopy <- as.factor(res_ecto_stats$Sintopy)
res_ecto_stats$Species <- as.factor(res_ecto_stats$Species)
str(res_ecto_stats)
res_ecto_stats <- res_ecto_stats %>%
rename(Loc_type = Sintopy)
res_ecto_stats <- res_ecto_stats[, c( "Elevation", "Loc_type", "Species", "MeanTALOC", "MeanRHLOC", "Solar", "NO_Snow", "egg_dev", "LifeSpan", "Years_repro", "Bask_year", "Forage_year", "Fecundity_year", "Season")]
res_ecto_stats <- res_ecto_stats[, c( "Elevation", "Loc_type", "Species", "MeanTALOC", "MeanRHLOC", "Solar", "NO_Snow", "egg_dev", "LifeSpan", "Years_repro", "Bask_year", "Forage_year", "Fecundity_year")]
head(res_ecto_stats)
str(res_ecto_stats)
loc_stats <- res_ecto_stats %>% distinct(MeanTALOC, .keep_all = TRUE)
#check data distribution
gghistogram(loc_stats$Solar, bins = 5)
ggboxplot(loc_stats$Solar)
#Check lm model first
lm_Solar <- lm(Solar ~Elevation+Loc_type, data = loc_stats)
# Get summary and p values
summary(lm_Solar) #AIC delta <4, include interaction
# Plot
lm_solar_plot <- lm(Solar ~Elevation, data = loc_stats)
Mean_solar <- visualize(lm_solar_plot,  Solar ~ Elevation, plot="model")+
scale_color_manual(values = c("black"))+
theme_classic()+
#labs(title = NULL, y="Mean solar radiation (W/m2)", x=NULL)+
labs(title = NULL, y=expression(paste('Mean solar radiation' ~ " " ~ (W/m^{2}))), x=NULL)+
labs_pubr()+
theme(legend.position="null")
Mean_solar
#Check model fit, residuals etc.
autoplot(lm_Solar)+
theme_classic()
shapiro.test(residuals(lm_Solar))
#Check comparisons
summary(glht(lm_Solar, linfct = mcp(Loc_type = 'Tukey')))
getwd()
load("../../Results/ECTOTHERM_results/results_all_ecto_summerTP.Rda")
res_ecto_stats <- results_all
rm(list = ls())
getwd()
load("../../Results/ECTOTHERM_results/results_all_ecto_summerTP.Rda")
res_ecto_stats <- results_all
load("../../Results/ECTOTHERM_results/results_all_ecto_springTP.Rda")
res_ecto_stats_spring <- results_all
res_ecto_stats$Season <- "SummerTP"
res_ecto_stats_spring$Season <- "SpringTP"
res_ecto_stats
res_ecto_stats_spring
res_both_seasons <- bind_rows(res_ecto_stats, res_ecto_stats_spring)
res_both_seasons
#Get yearly values
res_both_seasons$Forage_year <- res_ecto_stats$Forage/res_ecto_stats$Year
res_both_seasons$Bask_year <- res_ecto_stats$Bask/res_ecto_stats$Year
res_both_seasons$Fecundity_year <- res_ecto_stats$Fecundity/res_ecto_stats$Year
res_both_seasons
# Calculate average to compare seasons
comparison_df <- res_both_seasons %>%
group_by(Species, Sintopy, Season) %>%
summarise(across(c(egg_dev, LifeSpan, Years_repro, Bask_year, Forage_year, Fecundity_year),
list(mean = mean, min = min, max = max),
na.rm = TRUE,
.names = "{col}_{fn}"))
comparison_df
#Get yearly values
res_ecto_stats$Forage_year <- res_ecto_stats$Forage/res_ecto_stats$Year
res_ecto_stats$Bask_year <- res_ecto_stats$Bask/res_ecto_stats$Year
res_ecto_stats$Fecundity_year <- res_ecto_stats$Fecundity/res_ecto_stats$Year
res_ecto_stats$Clutches_year <- res_ecto_stats$Clutches/res_ecto_stats$Year
#Rename values
res_ecto_stats$Species[res_ecto_stats$Species == "Ihor"] <- "I. horvathi"
res_ecto_stats$Species[res_ecto_stats$Species == "Pmur"] <- "P. muralis"
res_ecto_stats$Sintopy[res_ecto_stats$Sintopy == "sint"] <- "Sintopy"
res_ecto_stats$Sintopy[res_ecto_stats$Sintopy == "aloPmur"] <- "Muralis allotopy"
res_ecto_stats$Sintopy[res_ecto_stats$Sintopy == "aloIhor"] <- "Horvathi allotopy"
#Turn to factor
res_ecto_stats$Locality <- as.factor(res_ecto_stats$Locality)
res_ecto_stats$Sintopy <- as.factor(res_ecto_stats$Sintopy)
res_ecto_stats$Species <- as.factor(res_ecto_stats$Species)
str(res_ecto_stats)
res_ecto_stats <- res_ecto_stats %>%
rename(Loc_type = Sintopy)
res_ecto_stats <- res_ecto_stats[, c( "Elevation", "Loc_type", "Species", "MeanTALOC", "MeanRHLOC", "Solar", "NO_Snow", "egg_dev", "LifeSpan", "Years_repro", "Bask_year", "Forage_year", "Fecundity_year", "Season")]
head(res_ecto_stats)
str(res_ecto_stats)
## Microclimate analysis table
loc_stats <- res_ecto_stats %>% distinct(MeanTALOC, .keep_all = TRUE)
res_ecto_stats
#check data distribution
gghistogram(res_ecto_stats$egg_dev, bins = 15)+
theme_pubclean()
gghistogram(res_ecto_stats$egg_dev, bins = 15)+
theme_pubclean()
ggboxplot(res_ecto_stats$egg_dev)+
theme_pubclean()+
labs(y=NULL, x=NULL)
#Check lm model first
lm_eggDev <- lm(egg_dev ~ Elevation+Species+Loc_type, data = res_ecto_stats)
lm_eggDev_int <- lm(egg_dev ~ Elevation*Species+Loc_type, data = res_ecto_stats)
lm_eggDev_int2<- lm(egg_dev ~ Elevation*Loc_type+Species, data = res_ecto_stats)
lm_eggDev_int3<- lm(egg_dev ~ Elevation+Loc_type*Species, data = res_ecto_stats)
# Compare models using AICc explicitly
model_list_egg <- list(lm_eggDev, lm_eggDev_int, lm_eggDev_int2, lm_eggDev_int3)
model_names_egg <- c("lm_eggDev", "lm_eggDev_int", "lm_eggDev_int2", "lm_eggDev_int3")
# Use second.ord = TRUE to ensure AICc is used
aictab(cand.set = model_list_egg, modnames = model_names_egg, second.ord = TRUE)
anova(lm_eggDev, lm_eggDev_int, lm_eggDev_int2, lm_eggDev_int3)
summary(lm_eggDev) ## NO SIGNIFICANT INTERACTIONS
visualize(lm_eggDev)
EggDev_plot <- visualize(lm_eggDev, egg_dev~Elevation+Loc_type |Species, plot="model")+
scale_color_manual(values = c("firebrick", "gold", "navyblue"))+
scale_shape_manual(values =c(19, 19, 19))+
scale_linetype_manual(values =c(1, 1, 1))+
theme_classic()+
labs_pubr()+
labs(title = NULL, y=expression(paste("Egg development time (days)")), x=NULL)+
theme(
strip.text = element_text(face = "italic"),
axis.text=element_text(size=11),
axis.title=element_text(size=12,face="bold"))+
facet_wrap(~Species)
EggDev_plot
lmm_eggDev <- lmer(egg_dev ~ Elevation+Loc_type+Species+(1|Locality), data = res_ecto_stats)
res_ecto_stats
getwd()
load("../../Results/ECTOTHERM_results/results_all_ecto_summerTP.Rda")
res_ecto_stats <- results_all
load("../../Results/ECTOTHERM_results/results_all_ecto_springTP.Rda")
res_ecto_stats_spring <- results_all
res_ecto_stats$Season <- "SummerTP"
res_ecto_stats_spring$Season <- "SpringTP"
res_ecto_stats
res_ecto_stats_spring
res_both_seasons <- bind_rows(res_ecto_stats, res_ecto_stats_spring)
res_both_seasons
#Get yearly values
res_both_seasons$Forage_year <- res_ecto_stats$Forage/res_ecto_stats$Year
res_both_seasons$Bask_year <- res_ecto_stats$Bask/res_ecto_stats$Year
res_both_seasons$Fecundity_year <- res_ecto_stats$Fecundity/res_ecto_stats$Year
res_both_seasons
# Calculate average to compare seasons
comparison_df <- res_both_seasons %>%
group_by(Species, Sintopy, Season) %>%
summarise(across(c(egg_dev, LifeSpan, Years_repro, Bask_year, Forage_year, Fecundity_year),
list(mean = mean, min = min, max = max),
na.rm = TRUE,
.names = "{col}_{fn}"))
comparison_df
#Get yearly values
res_ecto_stats$Forage_year <- res_ecto_stats$Forage/res_ecto_stats$Year
res_ecto_stats$Bask_year <- res_ecto_stats$Bask/res_ecto_stats$Year
res_ecto_stats$Fecundity_year <- res_ecto_stats$Fecundity/res_ecto_stats$Year
res_ecto_stats$Clutches_year <- res_ecto_stats$Clutches/res_ecto_stats$Year
#Rename values
res_ecto_stats$Species[res_ecto_stats$Species == "Ihor"] <- "I. horvathi"
res_ecto_stats$Species[res_ecto_stats$Species == "Pmur"] <- "P. muralis"
res_ecto_stats$Sintopy[res_ecto_stats$Sintopy == "sint"] <- "Sintopy"
res_ecto_stats$Sintopy[res_ecto_stats$Sintopy == "aloPmur"] <- "Muralis allotopy"
res_ecto_stats$Sintopy[res_ecto_stats$Sintopy == "aloIhor"] <- "Horvathi allotopy"
#Turn to factor
res_ecto_stats$Locality <- as.factor(res_ecto_stats$Locality)
res_ecto_stats$Sintopy <- as.factor(res_ecto_stats$Sintopy)
res_ecto_stats$Species <- as.factor(res_ecto_stats$Species)
str(res_ecto_stats)
res_ecto_stats <- res_ecto_stats %>%
rename(Loc_type = Sintopy)
res_ecto_stats <- res_ecto_stats[, c("Locality", "Elevation", "Loc_type", "Species", "MeanTALOC", "MeanRHLOC", "Solar", "NO_Snow", "egg_dev", "LifeSpan", "Years_repro", "Bask_year", "Forage_year", "Fecundity_year", "Season")]
head(res_ecto_stats)
str(res_ecto_stats)
## Microclimate analysis table
loc_stats <- res_ecto_stats %>% distinct(MeanTALOC, .keep_all = TRUE)
res_ecto_stats
lm_eggDev <- lm(egg_dev ~ Elevation+Species+Loc_type, data = res_ecto_stats)
lm_eggDev_int <- lm(egg_dev ~ Elevation*Species+Loc_type, data = res_ecto_stats)
lm_eggDev_int2<- lm(egg_dev ~ Elevation*Loc_type+Species, data = res_ecto_stats)
lm_eggDev_int3<- lm(egg_dev ~ Elevation+Loc_type*Species, data = res_ecto_stats)
model_list_egg <- list(lm_eggDev, lm_eggDev_int, lm_eggDev_int2, lm_eggDev_int3)
model_names_egg <- c("lm_eggDev", "lm_eggDev_int", "lm_eggDev_int2", "lm_eggDev_int3")
# Use second.ord = TRUE to ensure AICc is used
aictab(cand.set = model_list_egg, modnames = model_names_egg, second.ord = TRUE)
lmm_eggDev <- lmer(egg_dev ~ Elevation+Loc_type+Species+(1|Locality), data = res_ecto_stats)
library(lme4)
lmm_eggDev <- lmer(egg_dev ~ Elevation+Loc_type+Species+(1|Locality), data = res_ecto_stats)
install.packages("lme4")
install.packages("lme4")
