aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKen Kellner <ken.kellner@gmail.com>2014-08-13 19:52:25 (GMT)
committerKen Kellner <ken.kellner@gmail.com>2014-08-13 19:52:25 (GMT)
commita1b693eec491782c771cf2b5b7ef372272b82db7 (patch)
tree50e1946119cec7d5802d1fbf6094c6713f402def
parent550b14d1cac104d5bc5dcc3034fed0f3d6733053 (diff)
Calculate some minor additional statistics for the second version of the publication.
-rw-r--r--analysis_id_logistic.R22
-rw-r--r--models/model_id_logistic.R3
2 files changed, 19 insertions, 6 deletions
diff --git a/analysis_id_logistic.R b/analysis_id_logistic.R
index 6a84e70..9222cb9 100644
--- a/analysis_id_logistic.R
+++ b/analysis_id_logistic.R
@@ -1,7 +1,7 @@
##Work in progress model for imperfect detection
#Get dataset
-data.raw = read.csv('imperfect_detection_master.csv',header=TRUE)
+data.raw = read.csv('data/imperfect_detection_master.csv',header=TRUE)
#Get only important columns and convert some to factors
data = data.raw[,c(2,4,5,7:12,14:20,22,24:25,27:33)]
@@ -45,13 +45,23 @@ for (i in 1:npapers){
#Dependent variable
id = cbind(data$KenID,data$RobID)
+cucount = matrix(NA,nrow=npapers,ncol=2)
+index = 1
+for (i in 1:dim(id)[1]){
+ for (j in 1:nobs[i]){
+ cucount[i,j] <- index
+ index = index+1
+ }
+}
+
#Bundle
jags.data = list(#'njournals',
'journal','jsingletaxa','yrindex'
,'npapers','nobs','year','obs','id'
,'bi','fi','ma','hr','ins','pl'
,'cm','land',
- 'ab','oc','ri','su','ra'
+ 'ab','oc','ri','su','ra',
+ 'cucount'
)
#Parameters to save
@@ -67,9 +77,9 @@ params = c( 'alpha','p_alpha'
#,'p_beta_ab','p_beta_oc','p_beta_ri','p_beta_su','p_beta_ra'
,'bi_fi','bi_ma','bi_hr','bi_ins','bi_pl','fi_ma','fi_hr','fi_ins','fi_pl'
,'ma_hr','ma_ins','ma_pl','hr_ins','hr_pl','ins_pl'
- ,'birdmean','fishmean','mammean','herpmean','insmean','plantmean'
+ ,'birdmean','fishmean','mammean','herpmean','insmean','plantmean','pmean'
)
-modelFilename = "model_id_logistic.R"
+modelFilename = "models/model_id_logistic.R"
#Inits
#Inits for jags
@@ -84,7 +94,7 @@ inits <- function(){
z = zinit)}
#Analysis
-id.out = jags(data=jags.data, inits=inits,parameters.to.save=params, model.file=modelFilename,
- n.chains=3, n.iter=10000, n.burnin=1000, n.thin=50)
+id.out.new = jags(data=jags.data, inits=inits,parameters.to.save=params, model.file=modelFilename,
+ n.chains=3, n.iter=2000, n.burnin=1000, n.thin=2)
save(id.out,file="output_id_logistic.Rdata")
diff --git a/models/model_id_logistic.R b/models/model_id_logistic.R
index 8ce5277..f6a9165 100644
--- a/models/model_id_logistic.R
+++ b/models/model_id_logistic.R
@@ -81,10 +81,13 @@ model {
#+ p_beta_ab*ab[i] + p_beta_oc*oc[i] + p_beta_ri*ri[i] + p_beta_su*su[i]+ p_beta_ra*ra[i]
p_eff[i,j] <- z[i]*p[i,j]
id[i,j] ~ dbern(p_eff[i,j])
+ pmean_hold[cucount[i,j]] <- p[i,j]
}
}
#Derived parameters
+ pmean <- mean(pmean_hold[])
+
bi_fi <- beta_bi - beta_fi
bi_ma <- beta_bi - beta_ma
bi_hr <- beta_bi - beta_hr