-
Notifications
You must be signed in to change notification settings - Fork 1
/
Pfreedom_calculations_Hvidda2019.R
153 lines (116 loc) · 6.17 KB
/
Pfreedom_calculations_Hvidda2019.R
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
147
148
149
150
151
################
#Hardangervidda#
################
#RR1 #c(1,2,6), vector with RR for yearlings, adult females and adult males relative to yearlings, or if stochasstic,
#a matrix with one row for each simulation
pintro1 #0.01 1%
pintro #0.001 0.1%
prior #0.5
nsim1 #1000
S16
S17
S18
S19
pRLN2016
pRLN2017
pRLN2018
pRLN2019
############################
############################
############################
#Design prevalence
pstar1 =1
pstar2 =2
pstar3 =3
pstar4 =4
pstar5 =5
pstar6 =6
pstar10 =10
#Design prevalence:
#2016 -> 4 individuals
rownames(Nmat) <-c("N15","N16","N17","N18","N19")
rownames(Nmat_sd) <-c("N15","N16","N17","N18","N19")
####################
#2016
####################
N16_yad2=c(Nmat["N16","N1f"]+Nmat["N16","N1m"],Nmat["N16","Nadf"],Nmat["N16","Nadm"])
Nmat_sdW16<-(Nmat_sd["N16","N1f"]*Nmat["N16","N1f"]+Nmat_sd["N16","N1m"]*Nmat["N16","N1m"])/(Nmat["N16","N1f"]+Nmat["N16","N1m"])
N16sd_yad2=c(Nmat_sdW16,Nmat_sd["N16","Nadf"],Nmat_sd["N16","Nadm"])
N=N16_yad2
N_sd=N16sd_yad2
PrRLN=pRLN2016
nn=S16
PopSe16_Rpstar4<-simSSe_variant(N=N,N_sd=N_sd,nn=nn,RR=RR1,pstarN=pstar4,PrRLN=PrRLN,dSE=dSeTab1,nsim=nsim1,x1Y=x1Y,x1A=x1A)
summary(PopSe16_Rpstar4)
PopSe16_Rpstar2<-simSSe_variant(N=N,N_sd=N_sd,nn=nn,RR=RR1,pstarN=pstar2,PrRLN=PrRLN,dSE=dSeTab1,nsim=nsim1,x1Y=x1Y,x1A=x1A)
PopSe16_Rpstar3<-simSSe_variant(N=N,N_sd=N_sd,nn=nn,RR=RR1,pstarN=pstar3,PrRLN=PrRLN,dSE=dSeTab1,nsim=nsim1,x1Y=x1Y,x1A=x1A)
PopSe16_Rpstar5<-simSSe_variant(N=N,N_sd=N_sd,nn=nn,RR=RR1,pstarN=pstar5,PrRLN=PrRLN,dSE=dSeTab1,nsim=nsim1,x1Y=x1Y,x1A=x1A)
PopSe16_Rpstar6<-simSSe_variant(N=N,N_sd=N_sd,nn=nn,RR=RR1,pstarN=pstar6,PrRLN=PrRLN,dSE=dSeTab1,nsim=nsim1,x1Y=x1Y,x1A=x1A)
PopSe16_Rpstar10<-simSSe_variant(N=N,N_sd=N_sd,nn=nn,RR=RR1,pstarN=pstar10,PrRLN=PrRLN,dSE=dSeTab1,nsim=nsim1,x1Y=x1Y,x1A=x1A)
#######################
#2017
#######################
N17_yad2=c(Nmat["N17","N1f"]+Nmat["N17","N1m"],Nmat["N17","Nadf"],Nmat["N17","Nadm"])
Nmat_sdC17<-(Nmat_sd["N17","N1f"]*Nmat["N17","N1f"]+Nmat_sd["N17","N1m"]*Nmat["N17","N1m"])/(Nmat["N17","N1f"]+Nmat["N17","N1m"])
N17sd_yad2=c(Nmat_sdC17,Nmat_sd["N17","Nadf"],Nmat_sd["N17","Nadm"])
N=N17_yad2
N_sd=N17sd_yad2
PrRLN=pRLN2017 #0.095
nn=S17
PopSe17_Rpstar4<-simSSe_variant(N=N,N_sd=N_sd,nn=nn,RR=RR1,pstarN=pstar4,PrRLN=PrRLN,dSE=dSeTab1,nsim=nsim1,x1Y=x1Y,x1A=x1A)
PopSe17_Rpstar2<-simSSe_variant(N=N,N_sd=N_sd,nn=nn,RR=RR1,pstarN=pstar2,PrRLN=PrRLN,dSE=dSeTab1,nsim=nsim1,x1Y=x1Y,x1A=x1A)
PopSe17_Rpstar3<-simSSe_variant(N=N,N_sd=N_sd,nn=nn,RR=RR1,pstarN=pstar3,PrRLN=PrRLN,dSE=dSeTab1,nsim=nsim1,x1Y=x1Y,x1A=x1A)
PopSe17_Rpstar5<-simSSe_variant(N=N,N_sd=N_sd,nn=nn,RR=RR1,pstarN=pstar5,PrRLN=PrRLN,dSE=dSeTab1,nsim=nsim1,x1Y=x1Y,x1A=x1A)
PopSe17_Rpstar6<-simSSe_variant(N=N,N_sd=N_sd,nn=nn,RR=RR1,pstarN=pstar6,PrRLN=PrRLN,dSE=dSeTab1,nsim=nsim1,x1Y=x1Y,x1A=x1A)
PopSe17_Rpstar10<-simSSe_variant(N=N,N_sd=N_sd,nn=nn,RR=RR1,pstarN=pstar10,PrRLN=PrRLN,dSE=dSeTab1,nsim=nsim1,x1Y=x1Y,x1A=x1A)
#######################
#2018
#######################
N18_yad2=c(Nmat["N18","N1f"]+Nmat["N18","N1m"],Nmat["N18","Nadf"],Nmat["N18","Nadm"])
Nmat_sdC18<-(Nmat_sd["N18","N1f"]*Nmat["N18","N1f"]+Nmat_sd["N18","N1m"]*Nmat["N18","N1m"])/(Nmat["N18","N1f"]+Nmat["N18","N1m"])
N18sd_yad2=c(Nmat_sdC18,Nmat_sd["N18","Nadf"],Nmat_sd["N18","Nadm"])
N=N18_yad2
N_sd=N18sd_yad2
PrRLN=pRLN2018 #0.74
nn=S18
PopSe18_Rpstar4<-simSSe_variant(N=N,N_sd=N_sd,nn=nn,RR=RR1,pstarN=pstar4,PrRLN=PrRLN,dSE=dSeTab1,nsim=nsim1,x1Y=x1Y,x1A=x1A)
PopSe18_Rpstar2<-simSSe_variant(N=N,N_sd=N_sd,nn=nn,RR=RR1,pstarN=pstar2,PrRLN=PrRLN,dSE=dSeTab1,nsim=nsim1,x1Y=x1Y,x1A=x1A)
PopSe18_Rpstar3<-simSSe_variant(N=N,N_sd=N_sd,nn=nn,RR=RR1,pstarN=pstar3,PrRLN=PrRLN,dSE=dSeTab1,nsim=nsim1,x1Y=x1Y,x1A=x1A)
PopSe18_Rpstar5<-simSSe_variant(N=N,N_sd=N_sd,nn=nn,RR=RR1,pstarN=pstar5,PrRLN=PrRLN,dSE=dSeTab1,nsim=nsim1,x1Y=x1Y,x1A=x1A)
PopSe18_Rpstar6<-simSSe_variant(N=N,N_sd=N_sd,nn=nn,RR=RR1,pstarN=pstar6,PrRLN=PrRLN,dSE=dSeTab1,nsim=nsim1,x1Y=x1Y,x1A=x1A)
PopSe18_Rpstar10<-simSSe_variant(N=N,N_sd=N_sd,nn=nn,RR=RR1,pstarN=pstar10,PrRLN=PrRLN,dSE=dSeTab1,nsim=nsim1,x1Y=x1Y,x1A=x1A)
#######################
#2019
#######################
N19_yad2=c((Nmat["N19","N1f"]+Nmat["N19","N1m"]),Nmat["N19","Nadf"],Nmat["N19","Nadm"])
Nmat_sdC19<-(Nmat_sd["N19","N1f"]*Nmat["N19","N1f"]+Nmat_sd["N19","N1m"]*Nmat["N19","N1m"])/(Nmat["N19","N1f"]+Nmat["N19","N1m"])
N19sd_yad2=c(Nmat_sdC19,Nmat_sd["N19","Nadf"],Nmat_sd["N19","Nadm"])
N=N19_yad2
N_sd=N19sd_yad2
PrRLN=pRLN2019 #0.76
nn=S19
PopSe19_Rpstar4<-simSSe_variant(N=N,N_sd=N_sd,nn=nn,RR=RR1,pstarN=pstar4,PrRLN=PrRLN,dSE=dSeTab1,nsim=nsim1,x1Y=x1Y,x1A=x1A)
summary(PopSe19_Rpstar4)
PopSe19_Rpstar2<-simSSe_variant(N=N,N_sd=N_sd,nn=nn,RR=RR1,pstarN=pstar2,PrRLN=PrRLN,dSE=dSeTab1,nsim=nsim1,x1Y=x1Y,x1A=x1A)
PopSe19_Rpstar3<-simSSe_variant(N=N,N_sd=N_sd,nn=nn,RR=RR1,pstarN=pstar3,PrRLN=PrRLN,dSE=dSeTab1,nsim=nsim1,x1Y=x1Y,x1A=x1A)
PopSe19_Rpstar5<-simSSe_variant(N=N,N_sd=N_sd,nn=nn,RR=RR1,pstarN=pstar5,PrRLN=PrRLN,dSE=dSeTab1,nsim=nsim1,x1Y=x1Y,x1A=x1A)
PopSe19_Rpstar6<-simSSe_variant(N=N,N_sd=N_sd,nn=nn,RR=RR1,pstarN=pstar6,PrRLN=PrRLN,dSE=dSeTab1,nsim=nsim1,x1Y=x1Y,x1A=x1A)
PopSe19_Rpstar10<-simSSe_variant(N=N,N_sd=N_sd,nn=nn,RR=RR1,pstarN=pstar10,PrRLN=PrRLN,dSE=dSeTab1,nsim=nsim1,x1Y=x1Y,x1A=x1A)
####################
#Combine years
####################
#Used for harvest scenario simulations
PrRLN=pRLN2018
pintro1 #0.01
pintro #0.001
pH16<-pfree.est(SSe=PopSe16_Rpstar4,p.intro=pintro1,priorPFree=0.5)
pH17<-pfree.est(SSe=PopSe17_Rpstar4,p.intro=pintro1,priorPFree=pH16$PFree)
pH18<-pfree.est(SSe=PopSe18_Rpstar4,p.intro=pintro,priorPFree=pH17$PFree)
pH19<-pfree.est(SSe=PopSe19_Rpstar4,p.intro=pintro,priorPFree=pH18$PFree)
########################################################################################
resultPFreeHV<-rbind(c(mean(pH16$PFree),quantile(pH16$PFree,prob=c(0.025,0.5,0.975))),
c(mean(pH17$PFree),quantile(pH17$PFree,prob=c(0.025,0.5,0.975))),
c(mean(pH18$PFree),quantile(pH18$PFree,prob=c(0.025,0.5,0.975))),
c(mean(pH19$PFree),quantile(pH19$PFree,prob=c(0.025,0.5,0.975))))
resultPFreeHV
########################################################################################