Skip to content

Commit ad87e63

Browse files
committed
Debugged marray as group
1 parent 139069c commit ad87e63

File tree

2 files changed

+47
-28
lines changed

2 files changed

+47
-28
lines changed

AMWO_Marray.rda

3.89 KB
Binary file not shown.

Code/AMWO_submodels/Data manip AMWO marray SR.R

+47-28
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
rm(list=ls())
55
# Read in dataset
66
#raw.data<-read.csv(file.choose())
7-
#raw<-read.csv("~/Google Drive/AMWO IPM/Datasets/M array table AMWO CSV.csv")
87
raw<-read.csv("AMWO recoveries.csv") #reading in CSV from GitHub-linked timberdoodle folder
98

109
########################################################################
@@ -21,16 +20,22 @@ raw<-subset(raw,How.Obt==1)
2120
#only use B.Year from 1963 onwards
2221
raw<-subset(raw,B.Year>=1963)
2322

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+
2429
#bring in B.month, convert to season
2530
clean<-matrix(NA,nrow=length(raw$B.Month),ncol=1)
2631
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
2934

3035
#Bring in B.year
3136
clean[,2]<-raw$B.Year
3237

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
3439
clean[,3]<-NA
3540
clean[raw$R.Month>=4,3]<-raw[raw$R.Month>=4,"R.Year"]
3641
#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
4550

4651
#bring in R region, this is only to exlude region crossers
4752
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
5257

5358
# 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,]
5664
clean<-clean[,1:4] #remove R.state becuase it is redundant
5765

5866
#bring in age
@@ -69,38 +77,35 @@ clean[raw$Age..VAGE=="Local",5]<-1
6977
raw<-raw[!is.na(clean[,5]),]
7078
clean<-clean[!is.na(clean[,5]),]
7179

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)),]
7583

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
7785
# 1=local, 2=juv, 3=male, 4=female
7886
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]
8088
clean[raw$Sex..VSEX%in%c("Male","Male; from subsequent encounter")&clean[,5]==3,6]<-3
8189
clean[raw$Sex..VSEX%in%c("Female","Female; from subsequent encounter")&clean[,5]==3,6]<-4
8290

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
8492
raw<-raw[!(is.na(clean[,6])&clean[,5]==3),]
8593
clean<-clean[!(is.na(clean[,6])&clean[,5]==3),]
8694

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
9296
clean[,7]<-1
9397
colnames(clean)<-c("bSeason","bYear","rYear","region","age","class","dummy")
98+
9499
########################################################################
95100
#create the marray
96101
########################################################################
97102
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
99104
NYear<-length(Year)
100105
Season<-unique(clean$bSeason)
101106
NSeason<-length(Season)
102107
Class<-unique(clean$class)
103-
Class<-sort(Class) #SS sorted
108+
Class<-sort(Class) #SS sorted
104109
NClass<-length(Class)
105110
Region<-unique(clean$region)
106111
Region<-sort(Region) #SS sorted
@@ -118,16 +123,30 @@ for (s in 1:NSeason){
118123
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])
119124
}}}}}
120125

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]
126128

127129
save(awc, file="AMWO_Marray.rda")
128130

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+
129147
#---------------------------------------------------------------------------
130148
#need to add last column of unrecovered individuals to marray
149+
#THIS IS NOT FINISHED YET EITHER
131150
#---------------------------------------------------------------------------
132151
#bring in bandings file
133152
bands<-read.csv("AMWO bandings.csv")

0 commit comments

Comments
 (0)