Skip to content

Commit f8ab055

Browse files
update buffalo recharge example in vignette
1 parent 5e86e80 commit f8ab055

File tree

64 files changed

+522
-158
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

64 files changed

+522
-158
lines changed

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ Package: momentuHMM
22
Type: Package
33
Title: Maximum Likelihood Analysis of Animal Movement Behavior Using Multivariate Hidden Markov Models
44
Version: 2.0.0
5-
Date: 2024-02-02
5+
Date: 2024-06-12
66
Depends:
77
R (>= 2.10)
88
Author: Brett McClintock, Theo Michelot

NEWS

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
momentuHMM 2.0.0 2024-02-02
1+
momentuHMM 2.0.0 2024-06-12
22
-----------------
33
NEW FEATURES
44

publications/momentuHMM.bib

Lines changed: 189 additions & 0 deletions
Large diffs are not rendered by default.

publications/publications.md

Lines changed: 261 additions & 105 deletions

vignettes/codDist.pdf

-1.08 KB
Binary file not shown.

vignettes/codStates.pdf

-966 Bytes
Binary file not shown.

vignettes/examples/buffaloExample.R

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
library(momentuHMM)
22
library(raster)
3-
library(ctmcmove)
43

54
## download buffalo data
65
load(url("https://github.com/henryrscharf/Hooten_et_al_EL_2018/raw/master/data/buffalo/buffalo_Cilla.RData"))

vignettes/garterSnakeDist.pdf

-788 Bytes
Binary file not shown.

vignettes/garterSnakeStates.pdf

-1.06 KB
Binary file not shown.

vignettes/harborPorpoiseDist.pdf

-1.07 KB
Binary file not shown.

vignettes/harborPorpoiseStates.pdf

-1.43 KB
Binary file not shown.

vignettes/momentuHMM.Rnw

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2783,7 +2783,7 @@ with recharge function
27832783
where $w_j$ is the distance to nearest water indicator covariate at location ${\boldsymbol \mu}_j$. Thus the probability of being in the ``discharged'' state decreases as the recharge function $(g_t)$ increases. Note that there are no t.p.m. working parameter coefficients in Eq. \ref{eq:rechargeTPM1} and, because $\gamma_{11}=\gamma_{21}$ and $\gamma_{12}=\gamma_{22}$, the state switching in this model is not Markov (i.e., the state at time $t$ does not depend on the state at time $t-1$).
27842784

27852785
In order to fit this model, we must first load the data and format the covariate rasters:
2786-
<<recharge-1, echo=TRUE, eval=TRUE, cache=TRUE, message=FALSE>>=
2786+
<<recharge-1, echo=TRUE, eval=TRUE, cache=TRUE, message=FALSE, warning=FALSE>>=
27872787
library(raster)
27882788
27892789
## download buffalo data
@@ -2802,9 +2802,6 @@ dist2sabie_scaled <- dist2sabie / mean(values(terrain(dist2sabie,
28022802
opt = "slope")),
28032803
na.rm = T)
28042804
2805-
# calculate gradient
2806-
D_scaled <- ctmcmove::rast.grad(dist2sabie_scaled)
2807-
28082805
## W (recharge function covariates)
28092806
# near_sabie = indicator for <500m from water
28102807
intercept <- raster(dist2sabie)
@@ -2858,16 +2855,16 @@ crwOut <- crawlWrap(buffaloData,
28582855
@
28592856

28602857
Now we're ready to specify the recharge model. We'll first fit the model to the best predicted track from \verb|crawlWrap| and then use this model fit to specify starting values for a multiple imputation analysis:
2861-
<<recharge-3, echo=TRUE, eval=TRUE, cache=TRUE, message=FALSE>>=
2858+
<<recharge-3, echo=TRUE, eval=TRUE, cache=TRUE, message=FALSE, warning=FALSE>>=
28622859
spatialCovs <- list(W_intercept = W_ortho$svd1,
28632860
W_near_sabie = W_ortho$svd2,
28642861
dist2sabie = dist2sabie,
2865-
D.x = D_scaled$rast.grad.x,
2866-
D.y = D_scaled$rast.grad.y)
2862+
D = dist2sabie_scaled)
28672863
28682864
# best predicted track data
28692865
hmmData <- prepData(crwOut,
28702866
spatialCovs = spatialCovs,
2867+
gradient = TRUE,
28712868
altCoordNames = "mu")
28722869
head(hmmData[,c("ID","time", "mu.x", "mu.y",
28732870
"W_intercept","W_near_sabie","dist2sabie",
@@ -2968,7 +2965,7 @@ Now that we have our starting values (``bestPar''), let's fit $28$ imputations o
29682965
<<recharge-4, echo=-1, eval=FALSE>>=
29692966
set.seed(1,kind="Mersenne-Twister",normal.kind="Inversion")
29702967
buffaloFits <- MIfitHMM(crwOut, nSims=28,
2971-
spatialCovs = spatialCovs,
2968+
spatialCovs = spatialCovs, gradient = TRUE,
29722969
mvnCoords="mu", altCoordNames = "mu",
29732970
nbStates=nbStates, dist=dist, formula=formula,
29742971
Par0=bestPar$Par, beta0=bestPar$beta,
@@ -2987,7 +2984,7 @@ plotSpatialCov(buffaloFits,dist2sabie)
29872984
# plot estimates and CIs for Pr(discharged) at each time step
29882985
trProbs <- getTrProbs(buffaloFits, getCI=TRUE)
29892986
plot(trProbs$est[1,2,],type="l", ylim=c(0,1),
2990-
ylab="Pr(discharged)", xlab="t",
2987+
ylab="Pr(discharged)", xlab="time step",
29912988
col=c("#E69F00", "#56B4E9")[buffaloFits$miSum$Par$states])
29922989
arrows(1:dim(trProbs$est)[3],
29932990
trProbs$lower[1,2,],

vignettes/momentuHMM.pdf

17.5 KB
Binary file not shown.

vignettes/momentuHMM.tex

Lines changed: 20 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -4359,9 +4359,6 @@ \subsection{African buffalo recharge dynamics}
43594359
\hlkwc{opt} \hlstd{=} \hlstr{"slope"}\hlstd{)),}
43604360
\hlkwc{na.rm} \hlstd{= T)}
43614361
4362-
\hlcom{# calculate gradient}
4363-
\hlstd{D_scaled} \hlkwb{<-} \hlstd{ctmcmove}\hlopt{::}\hlkwd{rast.grad}\hlstd{(dist2sabie_scaled)}
4364-
43654362
\hlcom{## W (recharge function covariates)}
43664363
\hlcom{# near_sabie = indicator for <500m from water}
43674364
\hlstd{intercept} \hlkwb{<-} \hlkwd{raster}\hlstd{(dist2sabie)}
@@ -4427,32 +4424,32 @@ \subsection{African buffalo recharge dynamics}
44274424
\hlstd{spatialCovs} \hlkwb{<-} \hlkwd{list}\hlstd{(}\hlkwc{W_intercept} \hlstd{= W_ortho}\hlopt{$}\hlstd{svd1,}
44284425
\hlkwc{W_near_sabie} \hlstd{= W_ortho}\hlopt{$}\hlstd{svd2,}
44294426
\hlkwc{dist2sabie} \hlstd{= dist2sabie,}
4430-
\hlkwc{D.x} \hlstd{= D_scaled}\hlopt{$}\hlstd{rast.grad.x,}
4431-
\hlkwc{D.y} \hlstd{= D_scaled}\hlopt{$}\hlstd{rast.grad.y)}
4427+
\hlkwc{D} \hlstd{= dist2sabie_scaled)}
44324428
44334429
\hlcom{# best predicted track data}
44344430
\hlstd{hmmData} \hlkwb{<-} \hlkwd{prepData}\hlstd{(crwOut,}
44354431
\hlkwc{spatialCovs} \hlstd{= spatialCovs,}
4432+
\hlkwc{gradient} \hlstd{=} \hlnum{TRUE}\hlstd{,}
44364433
\hlkwc{altCoordNames} \hlstd{=} \hlstr{"mu"}\hlstd{)}
44374434
\hlkwd{head}\hlstd{(hmmData[,}\hlkwd{c}\hlstd{(}\hlstr{"ID"}\hlstd{,}\hlstr{"time"}\hlstd{,} \hlstr{"mu.x"}\hlstd{,} \hlstr{"mu.y"}\hlstd{,}
44384435
\hlstr{"W_intercept"}\hlstd{,}\hlstr{"W_near_sabie"}\hlstd{,}\hlstr{"dist2sabie"}\hlstd{,}
44394436
\hlstr{"D.x"}\hlstd{,}\hlstr{"D.y"}\hlstd{)])}
44404437
\end{alltt}
44414438
\begin{verbatim}
4442-
## ID time mu.x mu.y W_intercept W_near_sabie dist2sabie
4443-
## 1 1 313344.4 384560.8 -2770752 -0.0001873081 -0.003616337 1323.424
4444-
## 2 1 313344.7 384560.3 -2770751 -0.0001873081 -0.003616337 1323.424
4445-
## 3 1 313344.9 384559.8 -2770749 -0.0001873081 -0.003616337 1323.424
4446-
## 4 1 313345.2 384559.3 -2770747 -0.0001873081 -0.003616337 1323.424
4447-
## 5 1 313345.4 384559.1 -2770744 -0.0001873081 -0.003616337 1323.424
4448-
## 6 1 313345.7 384559.1 -2770742 -0.0001873081 -0.003616337 1323.424
4449-
## D.x D.y
4450-
## 1 -0.8709203 0.2576337
4451-
## 2 -0.8709203 0.2576337
4452-
## 3 -0.8709203 0.2576337
4453-
## 4 -0.8709203 0.2576337
4454-
## 5 -0.8709203 0.2576337
4455-
## 6 -0.8709203 0.2576337
4439+
## ID time mu.x mu.y W_intercept W_near_sabie dist2sabie D.x
4440+
## 1 1 313344.4 384560.8 -2770752 -0.0001873081 -0.003616337 1323.424 -1.228246
4441+
## 2 1 313344.7 384560.3 -2770751 -0.0001873081 -0.003616337 1323.424 -1.227881
4442+
## 3 1 313344.9 384559.8 -2770749 -0.0001873081 -0.003616337 1323.424 -1.227418
4443+
## 4 1 313345.2 384559.3 -2770747 -0.0001873081 -0.003616337 1323.424 -1.226851
4444+
## 5 1 313345.4 384559.1 -2770744 -0.0001873081 -0.003616337 1323.424 -1.226157
4445+
## 6 1 313345.7 384559.1 -2770742 -0.0001873081 -0.003616337 1323.424 -1.225450
4446+
## D.y
4447+
## 1 0.3505877
4448+
## 2 0.3779253
4449+
## 3 0.3777812
4450+
## 4 0.3776649
4451+
## 5 0.3776060
4452+
## 6 0.3775941
44564453
\end{verbatim}
44574454
\begin{alltt}
44584455
\hlstd{nbStates} \hlkwb{<-} \hlnum{2}
@@ -4582,7 +4579,7 @@ \subsection{African buffalo recharge dynamics}
45824579
\definecolor{shadecolor}{rgb}{0.969, 0.969, 0.969}\color{fgcolor}\begin{kframe}
45834580
\begin{alltt}
45844581
\hlstd{buffaloFits} \hlkwb{<-} \hlkwd{MIfitHMM}\hlstd{(crwOut,} \hlkwc{nSims}\hlstd{=}\hlnum{28}\hlstd{,}
4585-
\hlkwc{spatialCovs} \hlstd{= spatialCovs,}
4582+
\hlkwc{spatialCovs} \hlstd{= spatialCovs,} \hlkwc{gradient} \hlstd{=} \hlnum{TRUE}\hlstd{,}
45864583
\hlkwc{mvnCoords}\hlstd{=}\hlstr{"mu"}\hlstd{,} \hlkwc{altCoordNames} \hlstd{=} \hlstr{"mu"}\hlstd{,}
45874584
\hlkwc{nbStates}\hlstd{=nbStates,} \hlkwc{dist}\hlstd{=dist,} \hlkwc{formula}\hlstd{=formula,}
45884585
\hlkwc{Par0}\hlstd{=bestPar}\hlopt{$}\hlstd{Par,} \hlkwc{beta0}\hlstd{=bestPar}\hlopt{$}\hlstd{beta,}
@@ -4601,7 +4598,7 @@ \subsection{African buffalo recharge dynamics}
46014598
\hlcom{# plot estimates and CIs for Pr(discharged) at each time step}
46024599
\hlstd{trProbs} \hlkwb{<-} \hlkwd{getTrProbs}\hlstd{(buffaloFits,} \hlkwc{getCI}\hlstd{=}\hlnum{TRUE}\hlstd{)}
46034600
\hlkwd{plot}\hlstd{(trProbs}\hlopt{$}\hlstd{est[}\hlnum{1}\hlstd{,}\hlnum{2}\hlstd{,],}\hlkwc{type}\hlstd{=}\hlstr{"l"}\hlstd{,} \hlkwc{ylim}\hlstd{=}\hlkwd{c}\hlstd{(}\hlnum{0}\hlstd{,}\hlnum{1}\hlstd{),}
4604-
\hlkwc{ylab}\hlstd{=}\hlstr{"Pr(discharged)"}\hlstd{,} \hlkwc{xlab}\hlstd{=}\hlstr{"t"}\hlstd{,}
4601+
\hlkwc{ylab}\hlstd{=}\hlstr{"Pr(discharged)"}\hlstd{,} \hlkwc{xlab}\hlstd{=}\hlstr{"time step"}\hlstd{,}
46054602
\hlkwc{col}\hlstd{=}\hlkwd{c}\hlstd{(}\hlstr{"#E69F00"}\hlstd{,} \hlstr{"#56B4E9"}\hlstd{)[buffaloFits}\hlopt{$}\hlstd{miSum}\hlopt{$}\hlstd{Par}\hlopt{$}\hlstd{states])}
46064603
\hlkwd{arrows}\hlstd{(}\hlnum{1}\hlopt{:}\hlkwd{dim}\hlstd{(trProbs}\hlopt{$}\hlstd{est)[}\hlnum{3}\hlstd{],}
46074604
\hlstd{trProbs}\hlopt{$}\hlstd{lower[}\hlnum{1}\hlstd{,}\hlnum{2}\hlstd{,],}
@@ -4614,8 +4611,8 @@ \subsection{African buffalo recharge dynamics}
46144611
\end{alltt}
46154612
\end{kframe}
46164613
\end{knitrout}
4617-
\noindent As in \cite{HootenEtAl2019}, we found that the buffalo spent a majority of time steps in the discharged state ($73$\%, 95\% CI: $70-76\%$) and thus needed to recharge regularly near water resources. With estimated $g_0=-0.27$ (95\% CI: $-0.75-0.2$), $\theta_1=1.43$ (95\% CI: $-0.61-3.48$), and $\theta_2=2.52$ (95\% CI: $1.47-3.57$), the estimated recharge function and transition probabilities (Figure \ref{fig:recharge}) look very similar to those reported by \cite{HootenEtAl2019}. However, \cite{HootenEtAl2019} found some evidence that the buffalo orients
4618-
toward surface water when in the discharged state, but our discrete-time formulation did not find evidence of such biased movement ($\beta^\mu=0.88$, 95\% CI: $-3.2-4.96$). This difference could be attributable to several factors, including our formulation being in discrete time (instead of continuous time), our use of a 2-stage multiple imputation approach based on the CTCRW (instead of a single-stage model), and the absence of prior distributions in our non-Bayesian model. Nevertheless, inferences about recharge and state-switching dynamics are essentially the same between our discrete-time formulation and the continuous-time model of \cite{HootenEtAl2019}.
4614+
\noindent As in \cite{HootenEtAl2019}, we found that the buffalo spent a majority of time steps in the discharged state ($73$\%, 95\% CI: $70-76\%$) and thus needed to recharge regularly near water resources. With estimated $g_0=-0.27$ (95\% CI: $-0.75-0.2$), $\theta_1=1.43$ (95\% CI: $-0.62-3.47$), and $\theta_2=2.52$ (95\% CI: $1.46-3.57$), the estimated recharge function and transition probabilities (Figure \ref{fig:recharge}) look very similar to those reported by \cite{HootenEtAl2019}. However, \cite{HootenEtAl2019} found some evidence that the buffalo orients
4615+
toward surface water when in the discharged state, but our discrete-time formulation did not find evidence of such biased movement ($\beta^\mu=0.64$, 95\% CI: $-2.16-3.44$). This difference could be attributable to several factors, including our formulation being in discrete time (instead of continuous time), our use of a 2-stage multiple imputation approach based on the CTCRW (instead of a single-stage model), and the absence of prior distributions in our non-Bayesian model. Nevertheless, inferences about recharge and state-switching dynamics are essentially the same between our discrete-time formulation and the continuous-time model of \cite{HootenEtAl2019}.
46194616
\begin{figure}[htbp]
46204617
\centering
46214618
\includegraphics[width=0.9\textwidth]{plot_buffaloStates.pdf}\\

vignettes/plot_buffaloExample011.pdf

-5.21 KB
Binary file not shown.

vignettes/plot_buffaloResults.pdf

-2.57 KB
Binary file not shown.

vignettes/plot_buffaloStates.pdf

3.97 KB
Binary file not shown.

vignettes/plot_codExample001.pdf

-2.98 KB
Binary file not shown.

vignettes/plot_codExample002.pdf

-2.58 KB
Binary file not shown.

vignettes/plot_codStationary001.pdf

-2.43 KB
Binary file not shown.

vignettes/plot_codStationary002.pdf

-2.43 KB
Binary file not shown.

vignettes/plot_codStationary003.pdf

-2.3 KB
Binary file not shown.

vignettes/plot_elephantResults001.pdf

-120 Bytes
Binary file not shown.

vignettes/plot_elephantResults002.pdf

-477 Bytes
Binary file not shown.

vignettes/plot_elephantResults009.pdf

-2.45 KB
Binary file not shown.

vignettes/plot_elephantResults010.pdf

-225 Bytes
Binary file not shown.

vignettes/plot_elephantResults012.pdf

-2.95 KB
Binary file not shown.

vignettes/plot_elephantResults013.pdf

-1.05 KB
Binary file not shown.

vignettes/plot_elephantResults015.pdf

-3.45 KB
Binary file not shown.

vignettes/plot_elephantResults016.pdf

-439 Bytes
Binary file not shown.

vignettes/plot_elephantResults017.pdf

-218 Bytes
Binary file not shown.

vignettes/plot_garterSnakePR.pdf

-2.99 KB
Binary file not shown.

vignettes/plot_greySealResults002.pdf

-32 Bytes
Binary file not shown.

vignettes/plot_greySealResults006.pdf

31 Bytes
Binary file not shown.

vignettes/plot_greySealResults009.pdf

-63 Bytes
Binary file not shown.

vignettes/plot_greySealResults013.pdf

32 Bytes
Binary file not shown.

vignettes/plot_greySealResults1.png

134 Bytes

vignettes/plot_greySealResults2.png

82 Bytes

vignettes/plot_groupExample001.pdf

-8.68 KB
Binary file not shown.
92 Bytes
Binary file not shown.
-1.5 KB
Binary file not shown.
-2.05 KB
Binary file not shown.
-2.14 KB
Binary file not shown.
-892 Bytes
Binary file not shown.

vignettes/plot_harbourSeal.png

-183 Bytes
-839 Bytes
Binary file not shown.
-91 Bytes

vignettes/plot_langevinCovs.png

663 Bytes

vignettes/plot_langevinUD.png

805 Bytes

vignettes/plot_nfsResults.pdf

-10.9 KB
Binary file not shown.

vignettes/plot_sesResults001.pdf

537 Bytes
Binary file not shown.

vignettes/plot_sesResults003.pdf

631 Bytes
Binary file not shown.

vignettes/plot_sesResults007.pdf

343 Bytes
Binary file not shown.

vignettes/plot_sesResults009.pdf

432 Bytes
Binary file not shown.

vignettes/plot_sesResults2.png

105 Bytes

vignettes/plot_simLangevin.png

-835 Bytes

vignettes/plot_turtleResults001.pdf

565 Bytes
Binary file not shown.

vignettes/plot_turtleResults002.pdf

201 Bytes
Binary file not shown.

vignettes/plot_turtleResults004.pdf

462 Bytes
Binary file not shown.

vignettes/plot_turtleResults2.pdf

-2.7 KB
Binary file not shown.

vignettes/sharkDist.pdf

-938 Bytes
Binary file not shown.

vignettes/sharkStates.pdf

-927 Bytes
Binary file not shown.

vignettes/vignette_inputs.R

Lines changed: 44 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,9 @@ dev.off()
3535
for(plt in seq(1,17)[-c(1,2,9,10,12,13,15,16,17)])
3636
unlink(paste0("plot_elephantResults0",ifelse(plt>9,"","0"),plt,".pdf"))
3737

38-
png(filename="elephant_plotSat.png",width=5,height=5,units="in",res=80)
39-
plotSat(data.frame(x=rawData$lon,y=rawData$lat),zoom=8,location=c(median(rawData$lon),median(rawData$lat)),ask=FALSE)
40-
dev.off()
38+
#png(filename="elephant_plotSat.png",width=5,height=5,units="in",res=80)
39+
#plotSat(data.frame(x=rawData$lon,y=rawData$lat),zoom=8,location=c(median(rawData$lon),median(rawData$lat)),ask=FALSE)
40+
#dev.off()
4141

4242
rm(list=ls()[-which(ls()=="example_wd" | ls()=="append.RData")])
4343

@@ -240,15 +240,15 @@ tmpData<-spTransform(tmpData,CRS="+proj=longlat +ellps=WGS84")
240240
png(file=paste0(getwd(),"/plot_harbourSeal.png"),width=7.25,height=5,units="in",res=84)
241241
par(mfrow=c(1,2))
242242
for(id in c(8,1)){
243-
freqs<-miSum.ind$Par$states[hsData$ID==id]
244-
x<-tmpData$x[which(hsData$ID==id)]
245-
y<-tmpData$y[which(hsData$ID==id)]
243+
freqs<-miSum.ind$Par$states[which(hsData$ID==id)]
244+
x<-coordinates(tmpData)[which(hsData$ID==id),1]
245+
y<-coordinates(tmpData)[which(hsData$ID==id),2]
246246
errorEllipse<-miSum.ind$errorEllipse[which(hsData$ID==id)]
247247
errorEllipse<-lapply(errorEllipse,function(x){x<-as.data.frame(x);
248-
coordinates(x)<-c("x","y");
249-
proj4string(x)<-CRS("+init=epsg:27700 +units=m");
250-
x<-spTransform(x,CRS="+proj=longlat +ellps=WGS84");
251-
as.data.frame(x)})
248+
coordinates(x)<-c("x","y");
249+
proj4string(x)<-CRS("+init=epsg:27700 +units=m");
250+
x<-spTransform(x,CRS="+proj=longlat +ellps=WGS84");
251+
as.data.frame(x)})
252252

253253
#png(file=paste0(getwd(),"/plot_harbourSeal",id,".png"),width=5,height=7.25,units="in",res=90)
254254
plot(x,y,type="o",pch=20,cex=.5,xlab="longitude",ylab="latitude",cex.lab=0.8,cex.axis=.7)
@@ -287,9 +287,9 @@ append.RData(timeIn1,file=paste0(getwd(),"/vignette_inputs.RData"))
287287
append.RData(timeIn2,file=paste0(getwd(),"/vignette_inputs.RData"))
288288
#append.RData(m2,file=paste0(getwd(),"/vignette_inputs.RData"))
289289
#append.RData(newProj,file=paste0(getwd(),"/vignette_inputs.RData"))
290-
png(file=paste0(getwd(),"/plot_northernFulmarExample.png"),width=7.25,height=5,units="in",res=80)
291-
plotSat(m2,zoom=7,shape=c(17,1,17,1,17,1),size=2,col=rep(c("#E69F00", "#56B4E9", "#009E73"),each=2),stateNames=c("sea ARS","sea Transit","boat ARS","boat Transit","colony ARS","colony Transit"),projargs=newProj,ask=FALSE)
292-
dev.off()
290+
#png(file=paste0(getwd(),"/plot_northernFulmarExample.png"),width=7.25,height=5,units="in",res=80)
291+
#plotSat(m2,zoom=7,shape=c(17,1,17,1,17,1),size=2,col=rep(c("#E69F00", "#56B4E9", "#009E73"),each=2),stateNames=c("sea ARS","sea Transit","boat ARS","boat Transit","colony ARS","colony Transit"),projargs=newProj,ask=FALSE)
292+
#dev.off()
293293

294294
rm(list=ls()[-which(ls()=="example_wd" | ls()=="append.RData")])
295295

@@ -326,11 +326,11 @@ fitmix1_Par <- getPar(fitmix1)
326326
append.RData(fitmix1_Par,file=paste0(getwd(),"/vignette_inputs.RData"))
327327
Par0_mix2 <- getPar0(fitmix1,mixtures=2)
328328
Par0_mix2$beta$beta[1,] <- c(-2.26, -3.93, -0.58,
329-
0.03, -2.25, -0.26,
329+
0.03, -2.25, -0.26,
330330
-3.38, -4.79, -2.82,
331331
-1.06, -3.3, -3.43)
332332
Par0_mix2$beta$beta[2,] <- c(-2.51, -3.32, -2.63,
333-
0.03, -1.26, -0.12,
333+
0.03, -1.26, -0.12,
334334
-96.8, -3.62, -1.75,
335335
-1.76, -2.14, -1.38)
336336
Par0_mix2$beta$pi <- c(0.73, 0.27)
@@ -409,7 +409,7 @@ rm(list=ls()[-which(ls()=="example_wd" | ls()=="append.RData")])
409409
### buffalo recharge example
410410
###################################################
411411
#source(paste0(getwd(),"/examples/buffaloExample.R"))
412-
load(paste0(example_wd,"buffaloExample.RData"))
412+
load(paste0(example_wd,"buffaloExample_gradCT.RData"))
413413
bufPar <- buffaloFits$miSum$Par$beta[c("mu","g0","theta")]
414414
bufPar$timeInStates <- buffaloFits$miSum$Par$timeInStates
415415
append.RData(bufPar,file=paste0(getwd(),"/vignette_inputs.RData"))
@@ -430,14 +430,38 @@ for(plt in c(1:10,12))
430430
pdf(file=paste0(getwd(),"/plot_buffaloResults.pdf"),width=8,height=3)
431431
par(mar=c(5,4,4,2)-c(0,0,2,1)) # bottom, left, top, right
432432
plot(trProbs$est[1,2,],type="l",
433-
ylim=c(0,1), ylab="Pr(discharged)", xlab="t", col=c("#E69F00", "#56B4E9")[buffaloFits$miSum$Par$states])
433+
ylim=c(0,1), ylab="Pr(discharged)", xlab="time step", col=c("#E69F00", "#56B4E9")[buffaloFits$miSum$Par$states])
434434
arrows(1:dim(trProbs$est)[3],
435435
trProbs$lower[1,2,],
436436
1:dim(trProbs$est)[3],
437437
trProbs$upper[1,2,],
438438
length=0.025, angle=90, code=3, col=c("#E69F00", "#56B4E9")[buffaloFits$miSum$Par$states], lwd=1.3)
439439
abline(h=0.5,lty=2)
440440
dev.off()
441+
442+
#pdf(file=paste0(getwd(),"/plot_buffaloExampleCT%03d.pdf"),width=8,height=3,onefile = FALSE)
443+
#plot(buffaloFitsCT,plotCI=TRUE,legend.pos="bottom",ask=FALSE)
444+
#dev.off()
445+
446+
#pdf(file="plot_buffaloStatesCT.pdf",width=7.5,height=5)
447+
#plotSpatialCov(buffaloFitsCT,dist2sabie)
448+
#dev.off()
449+
450+
#for(plt in c(1:10,12))
451+
# unlink(paste0("plot_buffaloExampleCT0",ifelse(plt>9,"","0"),plt,".pdf"))
452+
453+
#pdf(file=paste0(getwd(),"/plot_buffaloResultsCT.pdf"),width=8,height=3)
454+
#par(mar=c(5,4,4,2)-c(0,0,2,1)) # bottom, left, top, right
455+
#plot(cumsum(diff(buffaloFitsCT$miSum$data$time)),trProbsCT$est[1,2,-1],type="l",
456+
# ylim=c(0,1), ylab="Pr(discharged)", xlab="t", col=c("#E69F00", "#56B4E9")[buffaloFitsCT$miSum$Par$states])
457+
#arrows(cumsum(diff(buffaloFitsCT$miSum$data$time)),
458+
# trProbsCT$lower[1,2,-1],
459+
# cumsum(diff(buffaloFitsCT$miSum$data$time)),
460+
# trProbsCT$upper[1,2,-1],
461+
# length=0.025, angle=90, code=3, col=c("#E69F00", "#56B4E9")[buffaloFitsCT$miSum$Par$states], lwd=1.3)
462+
#abline(h=0.5,lty=2)
463+
#dev.off()
464+
441465
rm(list=ls()[-which(ls()=="example_wd" | ls()=="append.RData")])
442466

443467
###################################################
@@ -455,8 +479,10 @@ rm(list=ls()[-which(ls()=="example_wd")])
455479
### Langevin example
456480
###################################################
457481
load(paste0(example_wd,"langevinExample.RData"))
458-
library(patchwork)
482+
library(raster)
483+
library(viridis)
459484
library(ggplot2)
485+
library(patchwork)
460486
covnames <- c("bathy", "slope", "d2site")
461487
covplot <- list()
462488
for(i in 1:3) {

vignettes/vignette_inputs.RData

-856 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)