-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathharmonia_example.R
44 lines (26 loc) · 1.11 KB
/
harmonia_example.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
################################################################
#bring in harmonia at KBS data
harmonia<-read.csv(file="casestudydata/kbs_harmonia94-17.csv", header=T)
#this is raw trap data, and will require manipulation
#first, handle the dates, which are horrible in the original data
library(lubridate)
harmonia$newdate<-mdy(harmonia$DATE)
#extract year
harmonia$year<-year(harmonia$newdate)
#extract day of year
harmonia$doy<-yday(harmonia$newdate)
#because sampling periods varied year to year, sometimes with long tails, let's cull the data at Aug 10
harmonia<-harmonia[which(harmonia$doy<222),]
#also get rid of nulls
harmonia<-harmonia[complete.cases(harmonia),]
#now, reshape and summarize. We want to get average counts per trap, by year- let's use plyr
library(plyr)
harmonia.year<-ddply(harmonia, "year", summarize,
avg=sum(ADULTS)/length(ADULTS))
#now, we run it through the RS detector
source("dynamic_shift_detector.R")
DSdetector(harmonia.year, "AIC")
DSdetector(harmonia.year, "AICc")
harmonia1<-addNt1(harmonia.year)
breakweights(harmonia1, "AIC")
breakweights(harmonia1, "AICc")