4
4
rm(list = ls())
5
5
# Read in dataset
6
6
# raw.data<-read.csv(file.choose())
7
- # raw<-read.csv("~/Google Drive/AMWO IPM/Datasets/M array table AMWO CSV.csv")
8
7
raw <- read.csv(" AMWO recoveries.csv" ) # reading in CSV from GitHub-linked timberdoodle folder
9
8
10
9
# #######################################################################
@@ -21,16 +20,22 @@ raw<-subset(raw,How.Obt==1)
21
20
# only use B.Year from 1963 onwards
22
21
raw <- subset(raw ,B.Year > = 1963 )
23
22
23
+ # subset B.Month between 4 and 9 to cover our 2 seasons
24
+ raw <- subset(raw ,B.Month > = 4 & B.Month < = 9 )
25
+
26
+ # take out recoveries in March
27
+ raw <- subset(raw ,R.Month != 3 )
28
+
24
29
# bring in B.month, convert to season
25
30
clean <- matrix (NA ,nrow = length(raw $ B.Month ),ncol = 1 )
26
31
clean <- data.frame (clean )
27
- clean [raw $ B.Month < = 6 ,]<- 1 # shouldn't we change this to between 4 and 6?
28
- clean [raw $ B.Month > 6 ,]<- 2 # shouldn't we change this to between 7 and 9?
32
+ clean [raw $ B.Month > = 4 & raw $ B.Month < = 6 ,]<- 1
33
+ clean [raw $ B.Month > = 7 & raw $ B.Month < = 9 ,]<- 2
29
34
30
35
# Bring in B.year
31
36
clean [,2 ]<- raw $ B.Year
32
37
33
- # bring in recovery year and account for recoveries occurring in Jan-March
38
+ # bring in recovery year and account for recoveries occurring in Jan-Feb
34
39
clean [,3 ]<- NA
35
40
clean [raw $ R.Month > = 4 ,3 ]<- raw [raw $ R.Month > = 4 ," R.Year" ]
36
41
# adjust if you don't want to include birds recovered in March
@@ -45,14 +50,17 @@ clean[raw$B.Flyway==6&raw$BRegion..STA%in%c("ONT"),4]<-2
45
50
46
51
# bring in R region, this is only to exlude region crossers
47
52
clean [,5 ]<- 0 # specify different number from previous step to flag it in the next step
48
- clean [raw $ B .Flyway== 1 ,5 ]<- 1
49
- clean [raw $ B .Flyway%in% 2 : 3 ,5 ]<- 2
50
- clean [raw $ B .Flyway== 6 & raw $ BRegion ..STA%in% c(" QC" ," NS" ," NB" ," PE" ," NF" ," PQ" ),5 ]<- 1
51
- clean [raw $ B .Flyway== 6 & raw $ BRegion ..STA%in% c(" ONT" ),5 ]<- 2
53
+ clean [raw $ R .Flyway== 1 ,5 ]<- 1
54
+ clean [raw $ R .Flyway%in% 2 : 3 ,5 ]<- 2
55
+ clean [raw $ R .Flyway== 6 & raw $ RRegion ..STA%in% c(" QC" ," NS" ," NB" ," PE" ," NF" ," PQ" ),5 ]<- 1
56
+ clean [raw $ R .Flyway== 6 & raw $ RRegion ..STA%in% c(" ONT" ),5 ]<- 2
52
57
53
58
# pull out places you don't care about
54
- raw <- raw [clean $ V4 != 0 | clean $ V5 != 0 ,]
55
- clean <- clean [clean $ V4 != 0 | clean $ V5 != 0 ,]
59
+ # raw<-raw[clean$V4!=0|clean$V5!=0,]
60
+ # test<-clean[clean$V4==0|clean$V5==0,]
61
+ # removes lines of region crossers
62
+ raw <- raw [clean $ V4 == clean $ V5 ,]
63
+ clean <- clean [clean $ V4 == clean $ V5 ,]
56
64
clean <- clean [,1 : 4 ] # remove R.state becuase it is redundant
57
65
58
66
# bring in age
@@ -69,38 +77,35 @@ clean[raw$Age..VAGE=="Local",5]<-1
69
77
raw <- raw [! is.na(clean [,5 ]),]
70
78
clean <- clean [! is.na(clean [,5 ]),]
71
79
72
- # get rid of hatch years in months 5 and 6
73
- clean <- clean [! (raw $ Age..VAGE == " Hatch Year" & raw $ B.Month %in% c(5 : 6 )),]
74
- raw <- raw [! (raw $ Age..VAGE == " Hatch Year" & raw $ B.Month %in% c(5 : 6 )),]
80
+ # get rid of hatch years in months 4, 5 and 6
81
+ clean <- clean [! (raw $ Age..VAGE == " Hatch Year" & raw $ B.Month %in% c(4 : 6 )),]
82
+ raw <- raw [! (raw $ Age..VAGE == " Hatch Year" & raw $ B.Month %in% c(4 : 6 )),]
75
83
76
- # bring in sex and convert to age class
84
+ # bring in sex and convert to age class so this is more like a sex-ageclass column
77
85
# 1=local, 2=juv, 3=male, 4=female
78
86
clean [,6 ]<- NA
79
- clean [clean [,5 ]%in% 1 : 2 ,6 ]<- clean [clean [,5 ]%in% 1 : 2 ,5 ] # is this line right? should second 5 be 6?
87
+ clean [clean [,5 ]%in% 1 : 2 ,6 ]<- clean [clean [,5 ]%in% 1 : 2 ,5 ]
80
88
clean [raw $ Sex..VSEX %in% c(" Male" ," Male; from subsequent encounter" )& clean [,5 ]== 3 ,6 ]<- 3
81
89
clean [raw $ Sex..VSEX %in% c(" Female" ," Female; from subsequent encounter" )& clean [,5 ]== 3 ,6 ]<- 4
82
90
83
- # remove unknown adults for now? Can treat unknowns via mixtures acc. to Todd
91
+ # remove unknown adults for now--only losing 20 individuals if we don't include them
84
92
raw <- raw [! (is.na(clean [,6 ])& clean [,5 ]== 3 ),]
85
93
clean <- clean [! (is.na(clean [,6 ])& clean [,5 ]== 3 ),]
86
94
87
- # remove unwanted banding periods (Oct-Dec) for now
88
- clean <- clean [! raw $ B.Month %in% c(10 : 12 ,1 : 3 ),]
89
- raw <- raw [! raw $ B.Month %in% c(10 : 12 ,1 : 3 ),]
90
-
91
-
95
+ # adding dummy column to use sum function below for marray
92
96
clean [,7 ]<- 1
93
97
colnames(clean )<- c(" bSeason" ," bYear" ," rYear" ," region" ," age" ," class" ," dummy" )
98
+
94
99
# #######################################################################
95
100
# create the marray
96
101
# #######################################################################
97
102
Year <- unique(clean $ bYear )
98
- Year <- sort(Year ) # SS added because needs to be chronological or else will have values below diagonal right?
103
+ Year <- sort(Year ) # SS sorted
99
104
NYear <- length(Year )
100
105
Season <- unique(clean $ bSeason )
101
106
NSeason <- length(Season )
102
107
Class <- unique(clean $ class )
103
- Class <- sort(Class ) # SS sorted
108
+ Class <- sort(Class ) # SS sorted
104
109
NClass <- length(Class )
105
110
Region <- unique(clean $ region )
106
111
Region <- sort(Region ) # SS sorted
@@ -118,16 +123,30 @@ for (s in 1:NSeason){
118
123
awc [b ,r ,s ,cc ,i ]<- sum(clean [clean $ bYear == Year [b ]& clean $ rYear == Year [r ]& clean $ class == Class [cc ]& clean $ region == Region [i ],7 ])
119
124
}}}}}
120
125
121
- # take a look at subset of giant marray
122
- awc [1 : 20 ,1 : 20 ,1 ,1 ,1 ]
123
-
124
- # are these the correct dimensions that we want?? or do we want to merge all age classes together into same marray? 2 separate
125
- # marrays for the 2 seasons, right? and regions, right?
126
+ # take a look at subset of giant marray--basically this is 16 marrays
127
+ awc [1 : 20 ,1 : 20 ,1 ,3 ,1 ]
126
128
127
129
save(awc , file = " AMWO_Marray.rda" )
128
130
131
+ # Creating separate M-Array that is more compatible with Todd's example
132
+ # Will need to be finished at a later date
133
+ awc.todd <- array (NA , dim = c(2 * NYear , NYear , NClass , NRegion ),
134
+ dimnames = list (Year , Year ,
135
+ c(" local" ," Hatch_Year" ," Adult_Male" ," Adult_Female" ),
136
+ c(" Eastern" ," Central" )))
137
+
138
+ for (cc in 1 : NClass ){
139
+ for (i in 1 : NRegion ){
140
+ for (b in 1 : NYear ){
141
+ for (r in 1 : NYear ){
142
+ awc.todd [b ,r ,cc ,i ]<- sum(clean [clean $ bYear == Year [b ]& clean $ rYear == Year [r ]& clean $ class == Class [cc ]& clean $ region == Region [i ],7 ])
143
+ }}}}
144
+
145
+ save(awc.todd , file = " AMWO_Todd_Marray.rda" )
146
+
129
147
# ---------------------------------------------------------------------------
130
148
# need to add last column of unrecovered individuals to marray
149
+ # THIS IS NOT FINISHED YET EITHER
131
150
# ---------------------------------------------------------------------------
132
151
# bring in bandings file
133
152
bands <- read.csv(" AMWO bandings.csv" )
0 commit comments