Skip to content

Commit c79348a

Browse files
committed
working on last column of m-array
1 parent 33847c5 commit c79348a

File tree

1 file changed

+68
-37
lines changed

1 file changed

+68
-37
lines changed

Code/AMWO_submodels/Data manip AMWO marray SR.R

+68-37
Original file line numberDiff line numberDiff line change
@@ -187,67 +187,98 @@ save(awc, file="AMWO_Marray.rda")
187187

188188
#---------------------------------------------------------------------------
189189
#need to add last column of unrecovered individuals to marray
190-
#THIS IS NOT FINISHED YET!! (ignore)
191190
#---------------------------------------------------------------------------
192191
#bring in bandings file
193-
bands<-read.csv("AMWO bandings.csv")
192+
bands<-read.csv("AMWO bandings.csv") #43,914 records
194193

195194
#need to summarize bandings according to: banding year, region, class, season
196195

197196
#only use status 3 birds
198-
bands<-subset(bands,Status==3)
197+
bands<-subset(bands,Status==3) #43,351 records (563 excluded)
199198

200199
#only use B.Year from 1963 onwards
201-
bands<-subset(bands,B.Year>=1963)
200+
bands<-subset(bands,B.Year>=1963) #40,734 (2617 excluded)
201+
202+
#subset B.Month between 4 and 9 to cover our 2 seasons
203+
bands<-subset(bands,B.Month>=4&B.Month<=9) #34,251 records (6483 excluded)
204+
205+
## TA added
206+
# remove radio transmitters (meta-analyses suggest survival and harvest effects)
207+
bands<-subset(bands,Add.Info!=89)
208+
bands<-subset(bands,Add.Info!=81) #32,827 records (1424 excluded)
202209

203210
#bring in B.month, convert to season
204-
clean<-matrix(NA,nrow=length(bands$B.Month),ncol=1)
205-
clean<-data.frame(clean)
206-
clean[bands$B.Month<=6,]<-1 #shouldn't we change this to between 4 and 6?
207-
clean[bands$B.Month>6,]<-2 #shouldn't we change this to between 7 and 9?
211+
clean.bands<-matrix(NA,nrow=length(bands$B.Month),ncol=1)
212+
clean.bands<-data.frame(clean.bands)
213+
clean.bands[bands$B.Month>=4&bands$B.Month<=6,]<-1
214+
clean.bands[bands$B.Month>=7&bands$B.Month<=9,]<-2 # 19,589 spring (Apr-Jun), 13,238 summer (Jul-Sep)
208215

209216
#Bring in B.year
210-
clean[,2]<-bands$B.Year
217+
clean.bands[,2]<-bands$B.Year
211218

212219
#bring in B region
213-
clean[,3]<-0
214-
clean[bands$B.Flyway==1,3]<-1
215-
clean[bands$B.Flyway%in%2:3,3]<-2
216-
clean[bands$B.Flyway==6&bands$BRegion..STA%in%c("QC","NS","NB","PE","NF","PQ"),3]<-1
217-
clean[bands$B.Flyway==6&bands$BRegion..STA%in%c("ONT"),3]<-2
220+
clean.bands[,3]<-0
221+
clean.bands[bands$B.Flyway==1,4]<-1 ## Eastern region, U.S
222+
clean.bands[bands$B.Flyway%in%2:3,4]<-2 ## Central region, U.S
223+
clean.bands[bands$B.Flyway==6&bands$BRegion..STA%in%c("QC","NS","NB","PE","NF","PQ"),4]<-1 ## Add eastern Canada (165)
224+
clean.bands[bands$B.Flyway==6&bands$BRegion..STA%in%c("ONT","MB"),4]<-2 ## 19 from ONT, added Manitoba to code (no recoveries, but some bandings)
225+
# 1,663 eastern recoveries, 2,618 central recoveries
226+
227+
#bring in R region, this is only to exlude region crossers
228+
clean[,5]<-0 #specify different number from previous step to flag it in the next step
229+
clean[raw$R.Flyway==1,5]<-1
230+
clean[raw$R.Flyway%in%2:3,5]<-2
231+
clean[raw$R.Flyway==6&raw$RRegion..STA%in%c("QC","NS","NB","PE","NF","PQ"),5]<-1
232+
clean[raw$R.Flyway==6&raw$RRegion..STA%in%c("ONT", "MB"),5]<-2
218233

219-
# pull out places you don't care about
220-
bands<-bands[clean$V3!=0,]
221-
clean<-clean[clean$V3!=0,]
222-
clean<-clean[,1:3] #remove R.state becuase it is redundant
234+
# removes lines of region crossers
235+
raw<-raw[clean$V4==clean$V5,]
236+
clean<-clean[clean$V4==clean$V5,]
237+
clean<-clean[,1:4] #remove R.state becuase it is redundant
238+
# 1,663 to 1595 eastern recoveries, 2,618 to 2604 central recoveries
239+
240+
## TA's independent tally, 68 Eastern pop harvested in Central, 14 Central harvested in Eastern (perfect match!)
223241

224242
#bring in age
225243
# local = 1, hatch year = 2, adult = 3
226-
clean[,4]<-NA
227-
clean[bands$Age..VAGE=="After Hatch Year",4]<-3
228-
clean[bands$Age..VAGE=="After Second Year",4]<-3
229-
clean[bands$Age..VAGE=="After Third Year",4]<-3
230-
clean[bands$Age..VAGE=="Second Year",4]<-3
231-
clean[bands$Age..VAGE=="Unknown",4]<-NA
232-
clean[bands$Age..VAGE=="Hatch Year",4]<-2
233-
clean[bands$Age..VAGE=="Local",4]<-1
244+
clean[,5]<-NA
245+
clean[raw$Age..VAGE=="After Hatch Year",5]<-3
246+
clean[raw$Age..VAGE=="After Second Year",5]<-3
247+
clean[raw$Age..VAGE=="After Third Year",5]<-3
248+
clean[raw$Age..VAGE=="Second Year",5]<-3
249+
clean[raw$Age..VAGE=="Unknown",5]<-NA ##delete 39 unknown age at banding
250+
clean[raw$Age..VAGE=="Hatch Year",5]<-2
251+
clean[raw$Age..VAGE=="Local",5]<-1
234252
#remove unknowns
235-
bands<-bands[!is.na(clean[,4]),]
236-
clean<-clean[!is.na(clean[,4]),]
237-
238-
# get rid of hatch years in months 5 and 6
239-
clean <- clean[!(bands$Age..VAGE=="Hatch Year"&bands$B.Month%in%c(5:6)),]
240-
bands <- bands[!(bands$Age..VAGE=="Hatch Year"&bands$B.Month%in%c(5:6)),]
241-
242-
#bring in sex and convert to age class
243-
# 1=local, 2=juv, 3=male, 4=female
253+
raw<-raw[!is.na(clean[,5]),]
254+
clean<-clean[!is.na(clean[,5]),] ## 1530 locals, 1504 HY, 1126 adults
244255

256+
# get rid of hatch years in months 4, 5 and 6
257+
clean <- clean[!(raw$Age..VAGE=="Hatch Year"&raw$B.Month%in%c(4:6)),]
258+
raw <- raw[!(raw$Age..VAGE=="Hatch Year"&raw$B.Month%in%c(4:6)),]
245259

260+
## there are also 2 locals banded in month 7
261+
clean <- clean[!(raw$Age..VAGE=="Local"&raw$B.Month%in%c(7:9)),]
262+
raw <- raw[!(raw$Age..VAGE=="Local"&raw$B.Month%in%c(7:9)),] ## 1528 locals, 1350 HY, 1126 adults
246263

264+
#bring in sex and convert to age class so this is more like a sex-age class column
265+
# 1=local, 2=juv, 3=male, 4=female
266+
clean[,6]<-NA
267+
clean[clean[,5]%in%1:2,6]<-clean[clean[,5]%in%1:2,5]
247268

248-
#remove unknown adults for now? Can treat unknowns via mixtures acc. to Todd
269+
#convert 2 juvenile ages to a single class ##(SS edit 13 Feb)
270+
#now: 1=juv (both local and HY), 2=male, 3=female ##SS edit
271+
clean[clean[,6]%in%1:2,6]<-1
249272

273+
### Sex from subsequent encounter means unknown at time of banding (== unknown if not recovered)
274+
### So treat these as unknown and if marked as unknown-sex adult they get deleted (but probably all marked as local or HY)
275+
clean[raw$Sex..VSEX%in%c("Male")&clean[,5]==3,6]<-2
276+
clean[raw$Sex..VSEX%in%c("Female")&clean[,5]==3,6]<-3
277+
# 465 males, 640 females, 2899 unknown
250278

251-
# remove unwanted banding periods (Oct-Dec) for now
279+
#remove unknown adults for now--only losing 21 individuals if we don't include them
280+
raw<-raw[!(is.na(clean[,6])&clean[,5]==3),]
281+
clean<-clean[!(is.na(clean[,6])&clean[,5]==3),]
282+
# 465 males, 640 females, 2878 unknown
252283

253284

0 commit comments

Comments
 (0)