-
Notifications
You must be signed in to change notification settings - Fork 0
/
Analysis_sup.Rmd
157 lines (94 loc) · 3.74 KB
/
Analysis_sup.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
---
title: "Supplementary analyses"
author: "Gordana Popovic"
date: "8 April 2019"
output: html_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(
echo = TRUE,
message = FALSE,
warning = FALSE
)
```
```{r}
rm(list=ls())
which_threshold=50
library(coxme)
source("soil_functions.R")
#define survival object for both full model and the sub models with just ref or undermined
if(which_threshold==50){
f_surv=Surv(soil_narrow$days.above.50pcSM+1, soil_narrow$da50C)
f_surv_Imp <- with(U_subdat,Surv(days.above.50pcSM+1, da50C))
f_surv_Ref<- with(R_subdat,Surv(days.above.50pcSM+1, da50C))
}else if(which_threshold==25){
f_surv=Surv(soil_narrow$days.above.25pcSM+1, soil_narrow$da25C)
f_surv_Imp <- with(U_subdat,Surv(days.above.25pcSM+1, da25C))
f_surv_Ref<- with(R_subdat,Surv(days.above.25pcSM+1, da25C))
}else if(which_threshold==75){
f_surv=Surv(soil_narrow$days.above.75pcSM+1, soil_narrow$da75C)
f_surv_Imp <- with(U_subdat,Surv(days.above.75pcSM+1, da75C))
f_surv_Ref<- with(R_subdat,Surv(days.above.75pcSM+1, da75C))
}
```
### Does soil moisture persistence change with impact and veg type?
```{r}
mod_cox <- coxme(f_surv ~ lsoil_moist_day_before+ltotal.rain.volume+laverage.days.no.rain+
scarpdist +temp+precip+area_ratio+Probe_depth+
veg_type*Impact + (1 | Swamp/Probe_no), soil_narrow)
anova(mod_cox)
```
## Cox model
### Do veg types differ for mined and unmined sites separately?
```{r}
mod_cox_Ref <- coxme(f_surv_Ref ~ lsoil_moist_day_before+ltotal.rain.volume+laverage.days.no.rain+
scarpdist +temp+precip+area_ratio+Probe_depth+
veg_type + (1 | Swamp/Probe_no), R_subdat)
anova(mod_cox_Ref)
```
```{r}
U_subdat$scarpdist=scale(U_subdat$scarpdist)
mod_cox_Imp <- coxme(f_surv_Imp ~ lsoil_moist_day_before+ltotal.rain.volume+laverage.days.no.rain+
scarpdist +temp+precip+area_ratio+Probe_depth+
veg_type + (1 | Swamp/Probe_no), U_subdat)
anova(mod_cox_Imp)
```
## AFT model with random effects for Swamp instead of probe.
### Does soil moisture persistence change with impact and veg type?
```{r}
mod_aft=survreg(f_surv~lsoil_moist_day_before+ltotal.rain.volume+laverage.days.no.rain+
scarpdist +temp+precip+area_ratio+Probe_depth+
veg_type_+Impact_+veg_type_Impact_+frailty(Swamp),
dist='weibull',data=soil_narrow)
anova(mod_aft)
```
### Do veg types differ for mined and unmined sites separately?
```{r}
mod_aft_Ref=survreg(f_surv_Ref~lsoil_moist_day_before+ltotal.rain.volume+laverage.days.no.rain+
scarpdist +temp+precip+area_ratio+Probe_depth+
veg_type+frailty(Swamp),
dist='weibull',data=R_subdat)
wr=confint(mod_aft_Ref,level = 0.9)[10,]
anova(mod_aft_Ref)
```
```{r}
mod_aft_Imp=survreg(f_surv_Imp~lsoil_moist_day_before+ltotal.rain.volume+laverage.days.no.rain+
scarpdist +temp+precip+area_ratio+Probe_depth+
veg_type+frailty(Swamp),
dist='weibull',data=U_subdat)
wi=confint(mod_aft_Imp,level = 0.9)[10,]
anova(mod_aft_Imp)
```
## frailtypack
```{r}
library(frailtypack)
modClu <- frailtyPenal(f_surv~
cluster(Swamp)+subcluster(re)+lsoil_moist_day_before+ltotal.rain.volume+laverage.days.no.rain+
scarpdist +temp+precip+area_ratio+Probe_depth+
veg_type + Impact,
data=soil_narrow,n.knots=8,kappa=c(50000),cross.validation = TRUE)
summary(modClu)
```
Attempt to use frailtypack resulted in results with confidence intervals that were much too narrow to be trusted.
## Different soil moisture cut-off (25% and 75%)
These can be recreated with the main analysis code by changing the cut-off value in the top of the code.