R/Spatial_covariance_functions.R

par(mfrow=c(2,2))

etasq.prior <- rexp(100,2)
rhosq.prior <- rexp(100,0.5)

# curve( median(etasq.prior)*exp(-median(rhosq.prior)*x^2) , from=0 , to=10, col="red",
#        lwd=2 )
# for ( i in 1:100 )
#   curve( etasq.prior[i]*exp(-rhosq.prior[i]*x^2) , add=TRUE ,
#          col=col.alpha("red",0.2) )

post <- extract.samples(n.notes.gp.only.female.indiv)

# plot the posterior median Covariance function

# plot the posterior median Covariance function
plot( NULL , xlab="Distance ( km)" , ylab="Covariance" ,main="Female Number of Notes",
      xlim=c(0,250) , ylim=c(0,2.5) )
# compute posterior median Covariance
x_seq <- seq( from=0 , to=250 , length.out=250 )
pmcov <- sapply( x_seq , function(x) post$etasq*exp(-post$rhosq*x^2) )
pmcov_mu <- apply( pmcov , 2 , median )
lines( x_seq , pmcov_mu , lwd=2 )
# plot 60 functions sampled from posterior
for ( i in 1:50 )
  curve( post$etasq[i]*exp(-post$rhosq[i]*x^2) , add=TRUE ,
         col=col.alpha("grey",0.3) )
par(new=T)
curve( median(etasq.prior)*exp(-median(rhosq.prior)*x^2) , from=0 , to=250, col="red",
       lwd=2,xlim=c(0,250) , ylim=c(0,2.5), xlab="" , ylab="" )


post <- extract.samples(notefreq.gp.cov.female.indiv)

# plot the posterior median Covariance function
plot( NULL , xlab="Distance ( km)" , ylab="Covariance" ,main="Female Note 1 Max Frequency",
      xlim=c(0,250) , ylim=c(0,2.5) )
# compute posterior median Covariance
x_seq <- seq( from=0 , to=250 , length.out=250 )
pmcov <- sapply( x_seq , function(x) post$etasq*exp(-post$rhosq*x^2) )
pmcov_mu <- apply( pmcov , 2 , median )
lines( x_seq , pmcov_mu , lwd=2 )
# plot 60 functions sampled from posterior
for ( i in 1:50 )
  curve( post$etasq[i]*exp(-post$rhosq[i]*x^2) , add=TRUE ,
         col=col.alpha("grey",0.3) )
par(new=T)
curve( median(etasq.prior)*exp(-median(rhosq.prior)*x^2) , from=0 , to=250, col="red",
       lwd=2,xlim=c(0,250) , ylim=c(0,2.5), xlab="" , ylab="" )

post <- extract.samples(notedur.gp.only.female.indiv)
# plot the posterior median Covariance function
plot( NULL , xlab="Distance ( km)" , ylab="Covariance" ,main="Female Note 1 Duration",
      xlim=c(0,250) , ylim=c(0,2.5) )
# compute posterior median Covariance
x_seq <- seq( from=0 , to=250 , length.out=250 )
pmcov <- sapply( x_seq , function(x) post$etasq*exp(-post$rhosq*x^2) )
pmcov_mu <- apply( pmcov , 2 , median )
lines( x_seq , pmcov_mu , lwd=2 )
# plot 60 functions sampled from posterior
for ( i in 1:50 )
  curve( post$etasq[i]*exp(-post$rhosq[i]*x^2) , add=TRUE ,
         col=col.alpha("grey",0.3) )
par(new=T)
curve( median(etasq.prior)*exp(-median(rhosq.prior)*x^2) , from=0 , to=250, col="red",
       lwd=2,xlim=c(0,250) , ylim=c(0,2.5), xlab="" , ylab="" )



post <- extract.samples(noterate.gp.only.male.indiv)
# plot the posterior median Covariance function
# plot the posterior median Covariance function
plot( NULL , xlab="Distance ( km)" , ylab="Covariance" ,main="Male Note Rate",
      xlim=c(0,250) , ylim=c(0,2.5) )
# compute posterior median Covariance
x_seq <- seq( from=0 , to=250 , length.out=250 )
pmcov <- sapply( x_seq , function(x) post$etasq*exp(-post$rhosq*x^2) )
pmcov_mu <- apply( pmcov , 2 , median )
lines( x_seq , pmcov_mu , lwd=2 )
# plot 60 functions sampled from posterior
for ( i in 1:50 )
  curve( post$etasq[i]*exp(-post$rhosq[i]*x^2) , add=TRUE ,
         col=col.alpha("grey",0.3) )
par(new=T)
curve( median(etasq.prior)*exp(-median(rhosq.prior)*x^2) , from=0 , to=250, col="red",
       lwd=2,xlim=c(0,250) , ylim=c(0,2.5), xlab="" , ylab="" )
DenaJGibbon/geographic_tarsiers documentation built on May 23, 2019, 12:50 a.m.