jlaake wrote:I'm not sure why you thought that was going to work given that you showed the dataframe and it doesn't contain a variable (column) with the name repro.cov.
You didn't include all of the pertinent code. What is repro.cov? A factor variable used to define groups or an individual covariate. If it is an individual covariate you should be using covariate.predictions but given you defined it as Y/N then I assume it is a factor variable. When you use model.average without specifying a parameter it does not include the design data fields because the design data can vary across parameters so there is no way to create a single dataframe with variable columns. Now, this model is an exception with only one parameter but the code doesn't make an exception. If you want to include the design data use
- Code: Select all
S.avg<-model.average(repro.results,parameter="S",vcv=T)$estimates
See ?model.average.marklist where that is explained. You can help yourself work this out by stepping through the code and seeing what is going wrong.
I'm learning....the code previously provided was built by another individual for my data as I'm learning about R and RMark. Repro.cov is an individual-specific covariate. In the Excel data set, repro.cov was listed as Y=Yes or N=No but was converted to Y=1 and N=0 for the analysis (see below).
I've included an example of the code for the analysis in case I'm missing something pertinent:
*Note not all code is provided due to the lengthiness of the code.
breeding.3<-subset(breeding,yr==3)
#Define 7-day periods
first.date<-breeding.3$date.code[3]
first.day<-first.date$yday
day<-breeding.3$date.code$yday-first.day+1
breeding.3$per<-as.integer(day/7)+1
convert.animal.id<-function(x,data)
{
levels<-levels(factor(data$animal_id))
index<-match(x,levels)
return(index)
}
breeding.3$id.no<-convert.animal.id(breeding.3$animal_id,data=breeding.3)
n.animals<-max(breeding.3$id.no)
#n.occasions<-max(breeding.3$per)
n.occasions<-14
#Create empty capture histories
y<-array(0,dim=c(n.animals,2*n.occasions))
data.set<-subset(breeding.3,select=c(id.no,per,Status))
for(i in 1:nrow(data.set))
{
status<-data.set[i,3]
id<-data.set[i,1]
per<-data.set[i,2]
ind1<-(per-1)*2+1
ind2<-per*2
status<-substr(status,1,5) #because some of these had spaces at the end
if (status=="Alive") y[id,ind1]=1
if (status=="Dead") {y[id,ind1]=y[id,ind2]=1 }
}
pasty<-function(x)
{
k<-ncol(x)
n<-nrow(x)
out<-array(dim=n)
for (i in 1:n)
{
out[i]<-paste(x[i,],collapse="")
}
return(out)
}
capt.hist.3<-pasty(y)
#Covariate
breeding.3$repro.cov[substr(breeding.3$repro,1,1)=="N"]=0
breeding.3$repro.cov[substr(breeding.3$repro,1,1)=="Y"]=1
cov<-with(breeding.3,aggregate(repro.cov~id.no,FUN=mean,na.action=NULL))
mark.data.3<-data.frame(ch=capt.hist.3,yr="3",repro.cov=cov$repro.cov)
#Eliminate capture histories with missing values
mark.data.3<-subset(mark.data.3,!is.na(repro.cov))
mark.data.3
##Then combine the data and run through MARK with some models including year effect
mark.data.final<-rbind(mark.data.1,mark.data.2,mark.data.3)
#Process the data
turkey.processed = process.data(data=mark.data.final,model="Known",groups=c("yr"))
#Create default design data
turkey.ddl=make.design.data(turkey.processed)
#Run MARK Models
repro.models=function()
{
#Define range of models for S
S.dot=list(formula=~1)
S.repro=list(formula=~repro.cov)
S.yr<-list(formula=~yr)
S.time<-list(formula=~time)
#Create Model List
model.list=create.model.list("Known")
#Run MARK Wrapper
results=mark.wrapper(model.list,data=turkey.processed,ddl=turkey.ddl,invisible=FALSE,threads=2)
# Return model table and list of models
return(results)
}
repro.results=repro.models()
repro.results
#Model Averaging Estimates
S.avg<-model.average(repro.results,parameter="S",vcv=T)$estimates
S.avg
row.names par.index estimate se lcl ucl fixed note group age time Age Time yr
1 S g1 a1 t2 1 0.9778946 0.006371892 0.9612777 0.9874736 1 1 2 1 0 1
2 S g1 a2 t3 2 0.9778948 0.006371200 0.9612802 0.9874730 1 2 3 2 1 1
3 S g1 a3 t4 3 0.9778951 0.006370934 0.9612813 0.9874730 1 3 4 3 2 1
4 S g1 a4 t5 4 0.9778948 0.006371391 0.9612795 0.9874732 1 4 5 4 3 1
5 S g1 a5 t6 5 0.9778951 0.006370947 0.9612813 0.9874730 1 5 6 5 4 1
6 S g1 a6 t7 6 0.9778948 0.006371391 0.9612795 0.9874732 1 6 7 6 5 1
7 S g1 a7 t8 7 0.9778947 0.006371430 0.9612794 0.9874732 1 7 8 7 6 1
8 S g1 a8 t9 8 0.9778951 0.006370954 0.9612812 0.9874730 1 8 9 8 7 1
9 S g1 a9 t10 9 0.9778951 0.006370970 0.9612812 0.9874730 1 9 10 9 8 1
10 S g1 a10 t11 10 0.9778947 0.006371472 0.9612792 0.9874732 1 10 11 10 9 1
11 S g1 a11 t12 11 0.9778954 0.006371281 0.9612804 0.9874736 1 11 12 11 10 1
12 S g1 a12 t13 12 0.9778954 0.006371281 0.9612804 0.9874736 1 12 13 12 11 1
13 S g1 a13 t14 13 0.9778948 0.006371757 0.9612783 0.9874736 1 13 14 13 12 1
14 S g1 a14 t15 14 0.9778954 0.006371281 0.9612804 0.9874736 1 14 15 14 13 1
15 S g2 a1 t2 15 0.9784176 0.005350470 0.9650226 0.9867533 2 1 2 1 0 2
16 S g2 a2 t3 16 0.9784179 0.005349621 0.9650254 0.9867525 2 2 3 2 1 2
17 S g2 a3 t4 17 0.9784182 0.005349278 0.9650267 0.9867523 2 3 4 3 2 2
18 S g2 a4 t5 18 0.9784178 0.005349855 0.9650246 0.9867527 2 4 5 4 3 2
19 S g2 a5 t6 19 0.9784181 0.005349294 0.9650267 0.9867523 2 5 6 5 4 2
20 S g2 a6 t7 20 0.9784178 0.005349855 0.9650246 0.9867527 2 6 7 6 5 2
21 S g2 a7 t8 21 0.9784178 0.005349903 0.9650245 0.9867528 2 7 8 7 6 2
22 S g2 a8 t9 22 0.9784181 0.005349303 0.9650266 0.9867523 2 8 9 8 7 2
23 S g2 a9 t10 23 0.9784181 0.005349324 0.9650266 0.9867524 2 9 10 9 8 2
24 S g2 a10 t11 24 0.9784178 0.005349953 0.9650243 0.9867528 2 10 11 10 9 2
25 S g2 a11 t12 25 0.9784185 0.005349661 0.9650258 0.9867531 2 11 12 11 10 2
26 S g2 a12 t13 26 0.9784185 0.005349661 0.9650258 0.9867531 2 12 13 12 11 2
27 S g2 a13 t14 27 0.9784179 0.005350284 0.9650234 0.9867533 2 13 14 13 12 2
28 S g2 a14 t15 28 0.9784185 0.005349661 0.9650258 0.9867531 2 14 15 14 13 2
29 S g3 a1 t2 29 0.9785430 0.005542476 0.9645193 0.9870980 3 1 2 1 0 3
30 S g3 a2 t3 30 0.9785432 0.005541651 0.9645221 0.9870972 3 2 3 2 1 3
31 S g3 a3 t4 31 0.9785435 0.005541314 0.9645235 0.9870971 3 3 4 3 2 3
32 S g3 a4 t5 32 0.9785432 0.005541878 0.9645214 0.9870974 3 4 5 4 3 3
33 S g3 a5 t6 33 0.9785435 0.005541329 0.9645234 0.9870971 3 5 6 5 4 3
34 S g3 a6 t7 34 0.9785432 0.005541878 0.9645214 0.9870974 3 6 7 6 5 3
35 S g3 a7 t8 35 0.9785432 0.005541924 0.9645212 0.9870975 3 7 8 7 6 3
36 S g3 a8 t9 36 0.9785435 0.005541338 0.9645234 0.9870971 3 8 9 8 7 3
37 S g3 a9 t10 37 0.9785435 0.005541359 0.9645233 0.9870971 3 9 10 9 8 3
38 S g3 a10 t11 38 0.9785432 0.005541974 0.9645210 0.9870975 3 10 11 10 9 3
39 S g3 a11 t12 39 0.9785438 0.005541676 0.9645226 0.9870978 3 11 12 11 10 3
40 S g3 a12 t13 40 0.9785438 0.005541676 0.9645226 0.9870978 3 12 13 12 11 3
41 S g3 a13 t14 41 0.9785433 0.005542290 0.9645201 0.9870980 3 13 14 13 12 3
42 S g3 a14 t15 42 0.9785438 0.005541676 0.9645226 0.9870978 3 14 15 14 13 3
S.final<-subset(S.avg,select=c(repro.cov,estimate,lcl,ucl))
write.csv(S.final,file="estimates.w.repro.csv",row.names=F)
Using the code that you provided, it still doesn't contain a variable (column) with the name repro.cov. Am I missing something obvious?