#AnĂ¡lises----- library(tidyverse) library(performance) library(corrplot) library(lme4) library(DHARMa) library(MuMIn) library(ggplot2) library(car) library(dplyr) library(mgcv) library(car) #data preparation---- data<-read.csv("data.csv", header = T, sep=";") data_scale <- data %>% mutate(across(14:22, scale)) #gains due to growth of survivors---- data_scale_outlier <- data_scale[-70, ]#outlier removed from the sample car_gro<-uGamm(incr.surv ~ Age + Temperature_seasonality_min + VPD_max_tc + Annual_Precipitation_max + Temperature_Annual_Range_Max+area_basal_m2_ha+ Large_fustes, random = list(Forest type = ~1, plotcode = ~1), na.action = "na.fail", data = data_scale_outlier) AIC(car_gro) resid <- residuals(car_gro$lme, type = "normalized") ajust <- fitted(car_gro$lme) par(mfrow = c(2, 2)) plot(ajust, resid, xlab = "Adjusted Values", ylab = "Standardized residuals", main = "Residuals vs. Adjusted") abline(h = 0, col = "red", lty = 2) qqnorm(resid, main = "Normal Q-Q Plot") qqline(resid, col = "red") hist(resid, main = "Residual Histogram", xlab = "Residuals", col = "lightblue") plot(resid, type = "b", main = "Independence (Data Order)", ylab = "Residuals") par(mfrow = c(1, 1)) (msAICccres<- dredge(car_gro)) res_gro<-summary(model.avg(msAICccres, subset = delta <= 2.001)) res_gro importance_allcresc=sw(res_gro) importance_allcresc=data.frame(importance_allcresc) importance_allcresc$Var <- rownames(importance_allcresc) coef_datagr <- as.data.frame(coefTable(res_gro)) coef_datagr <- coef_datagr[-1,] coef_datagr$Var <- rownames(coef_datagr) coef_datagr=merge(coef_datagr, importance_allcresc, by="Var") coef_datagr <- coef_datagr[order((coef_datagr$importance_allcresc)),] var_DAP4<-coef_datagr rel_impcre<-data.frame(coef_datagr$importance, coef_datagr$Var);rel_impcre rel_impcre<-cbind(rel_impcre,rownames(rel_impcre)) colnames(rel_impcre)<-c("rel_imp","Var") colnames(coef_datagr) <- c("Var","Estim", "SE", "DF", "importance") coef_datagr$SE <- coef_datagr$SE * 1.96 coef_datagr=data.frame(coef_datagr) ###net carbon change----- data_scale_outlier$delta<-sqrt(data_scale_outlier$net.carbon.change^2) cardel <- uGamm( log(delta) ~ Age + Temperature_seasonality_min + VPD_max_tc + Annual_Precipitation_max + area_basal_m2_ha + Large_fustes, random = list(Tipologia = ~1, plotcode = ~1), na.action = "na.fail", data = data_scale_outlier ) resid <- residuals(cardel$lme, type = "normalized") ajust <- fitted(cardel$lme) par(mfrow = c(2, 2)) plot(ajust, resid, xlab = "Adjusted Values", ylab = "Standardized residuals", main = "Residuals vs. Adjusted") abline(h = 0, col = "red", lty = 2) qqnorm(resid, main = "Normal Q-Q Plot") qqline(resid, col = "red") hist(resid, main = "Residual Histogram", xlab = "Residuals", col = "lightblue") plot(resid, type = "b", main = "Independence (Data Order)", ylab = "Residuals") par(mfrow = c(1, 1)) (msAICcdelta <- dredge(cardel)) resdelta<-summary(model.avg(msAICcdelta,subset = delta <= 2))# resdelta importance_alldel=sw(resdelta) importance_alldel=data.frame(importance_alldel) importance_alldel$Var <- rownames(importance_alldel) coef_datadel <- as.data.frame(coefTable(resdelta)) coef_datadel <- coef_datadel[-1,] coef_datadel$Var <- rownames(coef_datadel) coef_datadel=merge(coef_datadel, importance_alldel, by="Var") coef_datadel <- coef_datadel %>% arrange(importance_alldel) var_DAP4<-coef_datadel rel_impcre<-data.frame(coef_datadel$importance, coef_datadel$Var);rel_impcre rel_impcre<-cbind(rel_impcre,rownames(rel_impcre)) colnames(rel_impcre)<-c("rel_imp","Var") colnames(coef_datadel) <- c("Var","Estim", "SE", "DF", "importance") coef_datadel$SE <- coef_datadel$SE * 1.96 coef_datadel=data.frame(coef_datadel) #Annual carbon losses---- data_scale$logLann <- log1p(selecionadas2$Lann) data_scale2 <- data_scale[-10, ]#outlier removed from the sample carloss_log<-uGamm(logLann ~ Age + Temperature_seasonality_min+ VPD_max_tc+ Annual_Precipitation_max + Temperature_Annual_Range_Max+ area_basal_m2_ha + Large_fustes, random = list(Tipologia = ~1, plotcode = ~1), na.action = "na.fail", data = data_scale2) resid <- residuals(carloss_log$lme, type = "normalized") ajust <- fitted(carloss_log$lme) par(mfrow = c(2, 2)) plot(ajust, resid, xlab = "Adjusted Values", ylab = "Standardized residuals", main = "Residuals vs. Adjusted") abline(h = 0, col = "red", lty = 2) qqnorm(resid, main = "Normal Q-Q Plot") qqline(resid, col = "red") hist(resid, main = "Residual Histogram", xlab = "Residuals", col = "lightblue") plot(resid, type = "b", main = "Independence (Data Order)", ylab = "Residuals") par(mfrow = c(1, 1)) (msAICc4 <- dredge(carloss_log)) res4<-summary(model.avg(msAICc4, subset = delta <= 2))# res4 importance_alllo=sw(res4) importance_alllo=data.frame(importance_alllo) importance_alllo$Var <- rownames(importance_alllo) coef_datalos <- as.data.frame(coefTable(res4)) coef_datalos <- coef_datalos[-1,] coef_datalos$Var <- rownames(coef_datalos) coef_datalos=merge(coef_datalos, importance_alllo, by="Var") coef_datadel <- coef_datadel %>% arrange(importance_alldel) var_DAP4<-coef_datalos rel_impcre<-data.frame(coef_datalos$importance, coef_datalos$Var);rel_impcre rel_impcre<-cbind(rel_impcre,rownames(rel_impcre)) colnames(rel_impcre)<-c("rel_imp","Var") colnames(coef_datalos) <- c("Var","Estim", "SE", "DF", "importance") coef_datalos$SE <- coef_datalos$SE * 1.96 coef_datalos=data.frame(coef_datalos) ####gains due to recrtuitment------ data_scale$logrecr <- log1p(data_scale$recruit.incr.ha.yr) linhas_outliers <- c(10, 49, 70)#outliers data_scale3 <- data_scale[-linhas_outliers, ] carrec_lognormal <- uGamm(log(recruit.incr.ha.yr) ~ Age + Temperature_seasonality_min+ VPD_max_tc+ Annual_Precipitation_max + Temperature_Annual_Range_Max+ area_basal_m2_ha + Large_fustes, random = list(Tipologia = ~1, plotcode = ~1), na.action = "na.fail", data = data_scale3) resid <- residuals(carrec_lognormal$lme, type = "normalized") ajust <- fitted(carrec_lognormal$lme) par(mfrow = c(2, 2)) plot(ajust, resid, xlab = "Adjusted Values", ylab = "Standardized residuals", main = "Residuals vs. Adjusted") abline(h = 0, col = "red", lty = 2) qqnorm(resid, main = "Normal Q-Q Plot") qqline(resid, col = "red") hist(resid, main = "Residual Histogram", xlab = "Residuals", col = "lightblue") plot(resid, type = "b", main = "Independence (Data Order)", ylab = "Residuals") par(mfrow = c(1, 1)) (msAICcrec <- dredge(carrec_lognormal)) resrec<-summary(model.avg(msAICcrec, subset = delta <= 2)) resrec importance_rec=sw(resrec) importance_rec=data.frame(importance_rec) importance_rec$Var <- rownames(importance_rec) coef_datacor<- as.data.frame(coefTable(resrec)) coef_datacor <- coef_datacor[-1,] coef_datacor$Var <- rownames(coef_datacor) coef_datacor=merge(coef_datacor, importance_rec, by="Var") coef_datacor <- coef_datacor %>% arrange(importance_rec) var_DAPrec<-coef_datacor rel_imprec<-data.frame(coef_datacor$importance, coef_datacor$Var);rel_imprec rel_imprec<-cbind(rel_imprec,rownames(rel_imprec)) colnames(rel_imprec)<-c("rel_imp","Var") colnames(coef_datacor) <- c("Var","Estim", "SE", "DF", "importance") coef_datacor$SE <- coef_datacor$SE * 1.96 coef_datacor=data.frame(coef_datacor) ##Aboveground carbon stock#### data_scale$stock2<-sqrt(data_scale$AGC.ha.census2^2) lines_outliers <- c(47, 51, 69, 73)#outlier removed data_scale4 <- selecionadas2[-lines_outliers, ] estque_lmer_clean <- lmer( AGC.ha.census2 ~ Age + I(Age^2) + area_basal_m2_ha + I(area_basal_m2_ha^2) + Temperature_seasonality_min + VPD_max_tc + Annual_Precipitation_max + Temperature_Annual_Range_Max + Large_fustes + (1 | Tipologia/plotcode), data = data_scale4, na.action = "na.fail", REML = FALSE ) residuos_dharma <- simulateResiduals(fittedModel = estque_lmer_clean, plot = FALSE) plot(residuos_dharma) (msAICc4 <- dredge(estque_lmer_clean)) resesto<-summary(model.avg(msAICc4, subset = delta <= 2))#, resesto importance_allest=sw(resesto) importance_allest=data.frame(importance_allest) importance_allest$Var <- rownames(importance_allest) coef_dataest <- as.data.frame(coefTable(resesto)) coef_dataest <- coef_dataest[-1,] coef_dataest$Var <- rownames(coef_dataest) coef_dataest=merge(coef_dataest, importance_allest, by="Var") coef_dataest <- coef_dataest %>% arrange(coef_dataest) var_DAP4<-coef_dataest rel_impcre<-data.frame(coef_dataest$importance, coef_dataest$Var);rel_impcre rel_impcre<-rel_impcre[-2,] rel_impcre<-cbind(rel_impcre,rownames(rel_impcre)) colnames(rel_impcre)<-c("rel_imp","Var") colnames(coef_dataest) <- c("Var","Estim", "SE", "DF", "importance") coef_dataest$SE <- coef_dataest$SE * 1.96 coef_dataest=data.frame(coef_dataest)