This vignette explains basic and more advanced functions of the spict package. When loading the package you are notified which version of the package you have installed:

library(spict)
#> Loading required package: TMB
#> Welcome to spict_v1.0@fdf34a123d05f8b02e43c5fd04a173a8302e014c

The printed version follows the format ver@SHA, where ver is the manually defined version number and SHA refers to a unique commit on github. The content of this vignette pertains to the version printed above.

A simple example

The package contains the catch and index data analysed in Polacheck et al. (1993). This data can be loaded and plotted by typing

data(pol) 

Data on three stocks are contained in this dataset. Here focus will be on the South Atlantic albacore data. This dataset contains the following

pol$albacore
#> $obsC
#>  [1] 15.9 25.7 28.5 23.7 25.0 33.3 28.2 19.7 17.5 19.3 21.6 23.1 22.5 22.5
#> [15] 23.6 29.1 14.4 13.2 28.4 34.6 37.5 25.9 25.3
#> 
#> $timeC
#>  [1] 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980
#> [15] 1981 1982 1983 1984 1985 1986 1987 1988 1989
#> 
#> $obsI
#>  [1] 61.89 78.98 55.59 44.61 56.89 38.27 33.84 36.13 41.95 36.63 36.33
#> [12] 38.82 34.32 37.64 34.01 32.16 26.88 36.61 30.07 30.75 23.36 22.36
#> [23] 21.91
#> 
#> $timeI
#>  [1] 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980
#> [15] 1981 1982 1983 1984 1985 1986 1987 1988 1989

Note that data are structure in a list containing the entries obsC (catch observations), timeC (time of catch observations), obsI (index observations), and timeI (time of index observations). If times are not specified it is assumed that the first observation is observed at time 1 and then sequentially onward with a time step of one year. It is therefore recommended to always specify observation times.

The data can be plotted using the command

plotspict.data(pol$albacore, qlegend = TRUE)

Note that the number of catch and index observations are given in the respective plot headers. Furthermore, note colour legend in the top-right corner (shown because of the argument qlegend = TRUE), which explains at what time of the year an observation was observed based on the colour of the individual points. For illustrative purposes let’s try shifting the data a bit

inp <- pol$albacore
inp$timeC <- inp$timeC + 0.3
inp$timeI <- inp$timeI + 0.8
plotspict.data(inp, qlegend = TRUE)
Blah

Blah

Now the colours show that catches are observed in the spring and index in the autumn.

Let’s try to fit the model to the data

system.time(rep <- fit.spict(pol$albacore))
#>    user  system elapsed 
#>   2.793   0.012   2.808

The call to fit.spict is wrapped in the system.time command to check the time spent on the calculations. This is obviously not required, but done here to show that fitting the model only takes a few seconds. The result of the model fit is stored in rep, which can either be plotted using plot or summarised using summary.

Styles

The html_vignette template includes a basic CSS theme. To override this theme you can specify your own CSS in the document metadata as follows:

output: 
  rmarkdown::html_vignette:
    css: mystyles.css

Figures

The figure sizes have been customised so that you can easily put two images side-by-side.

plot(1:10)
plot(10:1)

You can enable figure captions by fig_caption: yes in YAML:

output:
  rmarkdown::html_vignette:
    fig_caption: yes

Then you can use the chunk option fig.cap = "Your figure caption." in knitr.

More Examples

You can write math expressions, e.g. \(Y = X\beta + \epsilon\), footnotes1, and tables, e.g. using knitr::kable().

mpg cyl disp hp drat wt qsec vs am gear carb
Mazda RX4 21.0 6 160.0 110 3.90 2.620 16.46 0 1 4 4
Mazda RX4 Wag 21.0 6 160.0 110 3.90 2.875 17.02 0 1 4 4
Datsun 710 22.8 4 108.0 93 3.85 2.320 18.61 1 1 4 1
Hornet 4 Drive 21.4 6 258.0 110 3.08 3.215 19.44 1 0 3 1
Hornet Sportabout 18.7 8 360.0 175 3.15 3.440 17.02 0 0 3 2
Valiant 18.1 6 225.0 105 2.76 3.460 20.22 1 0 3 1
Duster 360 14.3 8 360.0 245 3.21 3.570 15.84 0 0 3 4
Merc 240D 24.4 4 146.7 62 3.69 3.190 20.00 1 0 4 2
Merc 230 22.8 4 140.8 95 3.92 3.150 22.90 1 0 4 2
Merc 280 19.2 6 167.6 123 3.92 3.440 18.30 1 0 4 4

Also a quote using >:

“He who gives up [code] safety for [code] speed deserves neither.” (via)


  1. A footnote here.