-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy path.Rhistory
More file actions
184 lines (184 loc) · 5.98 KB
/
.Rhistory
File metadata and controls
184 lines (184 loc) · 5.98 KB
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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
setwd(./RawData)
setwd("./RawData")
getwd()
setwd("~/RawData")
setwd("C:/Users/farrm/Documents/GitHub/HMSNO/RawData")
setwd("C:/Users/farrm/Documents/GitHub/HMSNO/DataFormat")
library(readxl)
library(readxl)
read_excel("RawData/Data_Bwindi_nig_sylv_Nov18.xlsx", sheet = 1)
Bwindi_nig <- read_excel("RawData/Data_Bwindi_nig_sylv_Nov18.xlsx", sheet = 1)
install.packages("reshape")
library(reshape)
View(Bwindi_nig)
Bwindi_nig <- Bwindi_nig[,c(1:7,9,18,19)]
View(Bwindi_nig)
tst <- melt(Bwindi_nig, id = c("deployment ID", "Year", "elevation", "Distance"))
Bwindi_nig <- read_excel("RawData/Data_Bwindi_nig_sylv_Nov18.xlsx", sheet = 1)
Bwindi_nig <- Bwindi_nig[,c(1:7,9)]
tst <- melt(Bwindi_nig, id = c("deployment ID", "Year"))
View(Bwindi_nig)
tst <- melt(Bwindi_nig, id = c(1,8))
library(reshape2)
library(readxl)
Bwindi_nig <- read_excel("RawData/Data_Bwindi_nig_sylv_Nov18.xlsx", sheet = 1)
Bwindi_nig <- Bwindi_nig[,c(1:7,9)]
tst <- melt(Bwindi_nig, id = c(1,8))
View(tst)
tst <- melt(Bwindi_nig, id = c(8,1))
tst <- melt(Bwindi_nig, id = c(1,8))
View(tst)
library(dplyr)
tst <- tst %>% arrange(deployment ID, Year)
tst <- tst %>% arrange(`deployment ID`, Year)
View(tst)
tst <- grep("-", tst, NA)
tst <- melt(Bwindi_nig, id = c(1,8))
tst <- tst %>% arrange(`deployment ID`, Year)
tst <- gsub("-", NA, tst)
tst <- melt(Bwindi_nig, id = c(1,8))
tst <- tst %>% arrange(`deployment ID`, Year)
View(tst)
tst$value <- gsub("-", NA, tst$value)
setwd("C:/Users/farrm/Documents/GitHub/HMSNO/DataFormat")
library(readxl)
library(dplyr)
library(reshape2)
library(jagsUI)
Data <- NULL
files <- list.files(path = "./EditedData", pattern = "Data", full.names = TRUE)
for(i in 1:length(files)){
sheets <- excel_sheets(files[i])
for(j in 1:length(sheets)){
Temp <- read_excel(files[i], sheet = sheets[j])
Temp <- Temp %>% mutate(species = as.character(sheets[j]), park = as.factor(i)) %>%
select(park, `deployment ID`, Year, species, ls(Temp, pattern = "R"), elevation, edge)
Data <- bind_rows(Data, Temp)
}
}
#Convert to NAs
Data[,5:10] <- apply(Data[,5:10], 2, function(y) as.numeric(gsub("-", NA, y)))
#Convert to single vector format
Data2 <- melt(Data, id = c("park", "deployment ID", "Year", "species", "elevation", "edge"))
#Occupancy data
y <- Data2$value
#Indices
nyrs <- as.numeric(Data %>% summarize(n_distinct(Year)))
nsites <- as.numeric(Data %>% summarize(n_distinct(`deployment ID`)))
nspec <- as.numeric(Data %>% summarize (n_distinct(species)))
nobs <- length(y)
#Nested indices
yr <- as.numeric(as.factor(Data2$Year))
site <- as.numeric(as.factor(Data2$`deployment ID`))
spec <- as.numeric(as.factor(Data2$species))
#Data
jags.data <- list(y = y, nobs = nobs, nyrs = nyrs, nsites = nsites, nspec = nspec, yr = yr, site = site, spec = spec)
#Initial values
Nst <- array(NA, dim = c(nyrs, nsites, nspec))
Nst[1,,] <- 10
Sst <- array(5, dim = c(nyrs-1, nsites, nspec))
Gst <- array(2, dim = c(nyrs-1, nsites, nspec))
inits <- function()list(N=Nst, S=Sst, G=Gst)
#Parameters to save
params <- c("mu.a0", "tau.a0", "mu.b0", "tau.b0", "mu.o0", "tau.o0",
"mu.g0", "tau.g0", "mu.g1", "tau.g1",
"alpha0", "beta0", "omega0", "gamma0")
#MCMC settings
ni <- 50000
na <- 1000
nb <- 41000
nc <- 3
nt <- 3
#Parameters to save
params <- c("mu.a0", "tau.a0", "mu.b0", "tau.b0", "mu.o0", "tau.o0",
"mu.g0", "tau.g0",
"alpha0", "beta0", "omega0", "gamma0")
#Run JAGS model
out <- jagsUI(jags.data, inits, params, model.file = "../MSdyn.txt",
n.adapt = na, n.chains = nc, n.iter = ni, n.burnin = nb, n.thin = nt,
parallel = TRUE)
out
traceplot
traceplot(out)
#Run JAGS model
out <- jagsUI(jags.data, inits, params, model.file = "../MSdyn.txt",
n.adapt = na, n.chains = nc, n.iter = ni, n.burnin = nb, n.thin = nt,
parallel = TRUE)
out
traceplot(out)
?update
out1 <- jagsUI::update(ou, params, n.adpat=na, n.iter = 9000, n.thin = 3)
out1 <- update(ou, params, n.adpat=na, n.iter = 9000, n.thin = 3)
library(jagsUI)
cor(Data2$elevation, Data2$edge)
plot(Data2$elevation, Data2$edge)
hist(Data2$elevation)
sd(Data2$elevation)
sd(Data2$edge)
hist(Data2$edge)
Data
#Covariates
elevation <- Data$elevation
edge <- Data$edge
length(elevation)
nsites
#Covariates
elevation <- Data %>% group_by(`deployment ID`) %>% select(elevation)
elevation
Data %>% filter(`deployment ID` == `CT-BIF-1-01`)
Data %>% filter(`deployment ID` == "CT-BIF-1-01")
#Covariates
elevation <- Data %>% group_by(`deployment ID`) %>% select(elevation, edge) %>% unique()
elevation
nsites
View(elevation)
View(elevation)
setwd("~/Users/farrm/Documents/GitHub/Monarchs/DataFormatting/MonarchData/eButterfly")
data <- read.csv("all_records_2019_02_26_10_00_11.csv", header = TRUE)
table(Genus)
table(data$Genus)
library(dplyr)
data %>% filter(Genus == "Danaus") %>% summarize(n_distinct(Species))
data %>% filter(Genus == "Danaus") %>% group_by(Species) %>% summarize(n())
data %>% filter(Genus == "Danaus" & Species == "plexippus") %>% summarize(n())
data2 <- data %>% filter(Genus == "Danaus" & Species == "plexippus")
View(data2)
write.csv(data2, file = "eButterfly_Monarch.csv")
library(lme4)
library(dplyr)
#data
wq<-read.csv("Probereading_all_1st.csv")
setwd("~/Users/farrm/Downloads")
#data
wq<-read.csv("Probereading_all_1st.csv")
setwd("C:/Users/farrm/Documents/GitHub/HMSNO/DataFormat")
library(readxl)
install.packages("tidyverse")
library(readxl)
library(dplyr)
library(reshape2)
install.packages("jagsUI")
library(jagsUI)
Data <- NULL
files <- list.files(path = "./EditedData", pattern = "Data", full.names = TRUE)
for(i in 1:length(files)){
sheets <- excel_sheets(files[i])
for(j in 1:length(sheets)){
Temp <- read_excel(files[i], sheet = sheets[j])
Temp <- Temp %>% mutate(species = as.character(sheets[j]), park = as.factor(i)) %>%
select(park, `deployment ID`, Year, species, ls(Temp, pattern = "R"), elevation, edge, density)
Data <- bind_rows(Data, Temp)
}
}
View(Data)
Data$elevation
mean(Data$elevation)
sd(Data$elevation)
scale(seq(1:10, by = 1))
scale(seq(1, 10, by = 1))
scale(seq(11, 20, by = 1))
spde <- inla.spde2.matern(mesh, constr=TRUE,
B.tau = cbind(0,1),
B.kappa = cbind(log(sqrt(8)/2000), 0),
theta.prior.mean = 0,
theta.prior.prec = 0.001)