Draw samples from the empirical Bayes posterior predictive distribution derived from unmarked models or ranef objects

# S4 method for class 'unmarkedRanef'
posteriorSamples(object, nsims=100, ...)
# S4 method for class 'unmarkedFit'
posteriorSamples(object, nsims=100, ...)

Arguments

object

An object inheriting class unmarkedRanef or unmarkedFit

nsims

Number of draws to make from the posterior predictive distribution

...

Other arguments

Value

unmarkedPostSamples object containing the draws from the posterior predictive distribution. The draws are in the @samples slot.

Author

Ken Kellner contact@kenkellner.com

See also

Examples


# Simulate data under N-mixture model
set.seed(4564)
R <- 20
J <- 5
N <- rpois(R, 10)
y <- matrix(NA, R, J)
y[] <- rbinom(R*J, N, 0.5)

# Fit model
umf <- unmarkedFramePCount(y=y)
fm <- pcount(~1 ~1, umf, K=50)

# Estimates of conditional abundance distribution at each site
(re <- ranef(fm))
#>            Mean Mode 2.5% 97.5%
#>  [1,]  5.456813    5    4     8
#>  [2,] 12.263316   12   10    15
#>  [3,] 11.974866   12   10    15
#>  [4,] 12.512518   12   10    15
#>  [5,]  7.515203    7    6    10
#>  [6,]  6.910344    7    5     9
#>  [7,] 11.772003   12   10    14
#>  [8,] 11.590102   11    9    14
#>  [9,] 11.957508   12   10    15
#> [10,]  5.239116    5    4     7
#> [11,] 12.811799   13   10    16
#> [12,]  6.871755    7    5     9
#>  [ reached getOption("max.print") -- omitted 8 rows ]

#Draw from the posterior predictive distribution
(ppd <- posteriorSamples(re, nsims=100))
#> , , 1
#> 
#>       [,1]
#>  [1,]    8
#>  [2,]   12
#>  [3,]   11
#>  [4,]   15
#>  [5,]    7
#>  [6,]    6
#>  [7,]   11
#>  [8,]   11
#>  [9,]   13
#> [10,]    5
#> [11,]   13
#> [12,]    7
#> [13,]   11
#> [14,]   13
#> [15,]    8
#> [16,]    9
#> [17,]    7
#> [18,]    7
#> [19,]   11
#> [20,]   12
#> 
#> , , 2
#> 
#>       [,1]
#>  [1,]    4
#>  [2,]   10
#>  [3,]   12
#>  [4,]   11
#>  [5,]    9
#>  [6,]    5
#>  [7,]   10
#>  [8,]   10
#>  [9,]   11
#> [10,]    6
#> [11,]   11
#> [12,]    7
#> [13,]   10
#> [14,]   14
#> [15,]    4
#> [16,]   10
#> [17,]    9
#> [18,]    7
#> [19,]   11
#> [20,]   12
#> 
#> , , 3
#> 
#>       [,1]
#>  [1,]    4
#>  [2,]   11
#>  [3,]   10
#>  [4,]   11
#>  [5,]    6
#>  [6,]    7
#>  [7,]   10
#>  [8,]   10
#>  [9,]   11
#> [10,]    5
#> 
#>  [ reached getOption("max.print") -- omitted 10 row(s) and 97 matrix slice(s) ]