Extract posterior distributions of spatially-varying coefficients (SVCs) from a fitted ratio model with SVC specification.
Usage
svc(object, terms = NULL, summary = FALSE, probs = c(0.025, 0.5, 0.975), ...)
# S3 method for class 'ratiod_fit'
svc(object, terms = NULL, summary = FALSE, probs = c(0.025, 0.5, 0.975), ...)
# S3 method for class 'ratiod_svc_posterior'
summary(object, probs = c(0.025, 0.5, 0.975), ...)
# S3 method for class 'ratiod_svc_posterior'
print(x, ...)
# S3 method for class 'ratiod_svc_posterior'
plot(x, term = 1, type = "mean", ...)Arguments
- object
A
ratiod_fitobject fitted withsvcargument- terms
Which SVC terms to extract. If NULL (default), extracts all.
- summary
Logical; if TRUE, return summary statistics instead of full posterior draws.
- probs
Quantiles to compute if
summary = TRUE.- ...
Ignored
- x
A ratiod_svc_posterior object
- term
Which term to plot (name or index). Default: first term.
- type
Plot type: "mean" (default), "sd", or quantile (e.g., "q50")
Value
A ratiod_svc_posterior object containing:
draws: Array of posterior draws (draws x locations x terms)coords: Coordinate matrixterm_names: Names of SVC terms
See also
spatial_svc(), plot.ratiod_svc_posterior()
Examples
# \donttest{
# Generate synthetic spatial data
set.seed(303)
n <- 30
lon <- runif(n, 0, 10)
lat <- runif(n, 0, 10)
depth <- rnorm(n)
# Spatially varying intercept w0 and depth slope w1, shared by count and
# effort
w0 <- 0.5 * sin(lon / 2) + 0.5 * cos(lat / 2)
w1 <- 0.4 * cos(lon / 3)
df <- data.frame(
lon = lon,
lat = lat,
depth = depth,
count = rpois(n, exp(3 + 0.3 * depth + w0 + w1 * depth)),
effort = rgamma(n, shape = 4, rate = exp(-(w0 + w1 * depth)))
)
# Fit model with SVC
fit <- tratio(
count | effort ~ depth,
data = df,
family = ratiod_poisson_gamma(),
spatial = spatial_svc(~ lon + lat, terms = c(1, 2)),
control = list(iter = 400, chains = 1, seed = 1)
)
# Extract SVC posteriors
svc_post <- svc(fit)
summary(svc_post)
#> obs term coord_1 coord_2 mean sd q2.5
#> 1 1 (Intercept) -0.74552727 -1.33110810 0.706963299 0.1803532 0.368401333
#> 2 2 (Intercept) 1.11548899 -1.79945079 0.181872495 0.2376416 -0.246919470
#> 3 3 (Intercept) 0.31870377 1.15449865 -0.204578110 0.1878435 -0.552253873
#> 4 4 (Intercept) 0.78013618 -0.86618279 -0.089321059 0.1731485 -0.435597246
#> 5 5 (Intercept) 0.46004102 -0.73533404 -0.008096389 0.1765033 -0.369391490
#> 6 6 (Intercept) 1.63314700 -0.88217002 -0.131280205 0.1964693 -0.524130443
#> 7 7 (Intercept) 0.02631757 -0.67483168 0.306085906 0.1656406 -0.003640973
#> 8 8 (Intercept) -0.18440112 -0.09713499 0.190008502 0.1539187 -0.073689201
#> 9 9 (Intercept) -0.84498390 0.87363901 0.013839286 0.1725905 -0.404553399
#> 10 10 (Intercept) -0.85490948 1.35179725 0.079674707 0.1726053 -0.252971314
#> 11 11 (Intercept) 1.36713729 0.88483913 -0.567987780 0.2829698 -1.163473420
#> 12 12 (Intercept) 1.25035126 -0.57822590 -0.316311766 0.1698703 -0.618581993
#> 13 13 (Intercept) -1.47554201 0.58851774 -0.076998633 0.1446808 -0.353690353
#> 14 14 (Intercept) -1.71414857 0.09547305 -0.113043274 0.2186220 -0.535756023
#> 15 15 (Intercept) -1.01481202 -1.33103631 0.599314911 0.1799707 0.266097760
#> 16 16 (Intercept) -1.08795887 1.14705436 0.068952453 0.1602203 -0.204467195
#> 17 17 (Intercept) -0.39488775 -0.98385533 0.705740961 0.1744793 0.332126505
#> 18 18 (Intercept) -1.01478960 -1.23666615 0.670317731 0.2030713 0.266822081
#> 19 19 (Intercept) 0.73911051 1.16041569 -0.420391218 0.2194370 -0.836061161
#> 20 20 (Intercept) 0.47796288 -0.43555562 -0.045352663 0.1808655 -0.412287947
#> 21 21 (Intercept) 1.15784651 0.26206234 -0.763192408 0.2554864 -1.293965686
#> 22 22 (Intercept) 0.48022845 0.53267351 -0.375225578 0.1764856 -0.715820383
#> 23 23 (Intercept) 1.08986309 -0.29670057 -0.411065740 0.2057112 -0.808188337
#> 24 24 (Intercept) -0.99063147 0.81581050 -0.016039681 0.1291870 -0.260711648
#> 25 25 (Intercept) 1.09103446 -1.44834953 0.222570648 0.2074537 -0.180436197
#> 26 26 (Intercept) 0.32262042 -0.29825692 -0.055259724 0.1970254 -0.477876076
#> 27 27 (Intercept) 1.00040116 1.99477614 -0.168324457 0.2190127 -0.602675683
#> 28 28 (Intercept) -1.43188575 0.58388189 -0.096812068 0.1707463 -0.474827388
#> 29 29 (Intercept) -1.01568370 1.02552039 0.025999379 0.1359188 -0.212927145
#> 30 30 (Intercept) -0.54022902 0.52389907 0.087940474 0.2047175 -0.254191224
#> 31 1 depth -0.74552727 -1.33110810 -0.096212416 0.1848808 -0.496478386
#> 32 2 depth 1.11548899 -1.79945079 -0.324552419 0.2288978 -0.790038414
#> 33 3 depth 0.31870377 1.15449865 0.112135029 0.2396282 -0.313869018
#> 34 4 depth 0.78013618 -0.86618279 -0.334219092 0.1869990 -0.679609674
#> 35 5 depth 0.46004102 -0.73533404 -0.215645884 0.1794248 -0.521280601
#> 36 6 depth 1.63314700 -0.88217002 -0.373983901 0.1783683 -0.751273924
#> 37 7 depth 0.02631757 -0.67483168 -0.035302551 0.1703434 -0.365409151
#> 38 8 depth -0.18440112 -0.09713499 0.148213953 0.1930364 -0.133652550
#> 39 9 depth -0.84498390 0.87363901 0.270554716 0.1440466 -0.001553916
#> 40 10 depth -0.85490948 1.35179725 0.168481176 0.2439020 -0.292150725
#> 41 11 depth 1.36713729 0.88483913 -0.095955466 0.1627938 -0.385212851
#> 42 12 depth 1.25035126 -0.57822590 -0.328853155 0.1937893 -0.763958265
#> 43 13 depth -1.47554201 0.58851774 0.433700223 0.1912434 0.099744375
#> 44 14 depth -1.71414857 0.09547305 0.354357025 0.2777545 -0.079614357
#> 45 15 depth -1.01481202 -1.33103631 -0.120806742 0.2220577 -0.585678096
#> 46 16 depth -1.08795887 1.14705436 0.208907804 0.1218608 -0.012916242
#> 47 17 depth -0.39488775 -0.98385533 0.097932555 0.1947330 -0.206937798
#> 48 18 depth -1.01478960 -1.23666615 -0.111664028 0.1779871 -0.487785167
#> 49 19 depth 0.73911051 1.16041569 -0.046781931 0.1583317 -0.356282208
#> 50 20 depth 0.47796288 -0.43555562 -0.203178628 0.1552866 -0.533379140
#> 51 21 depth 1.15784651 0.26206234 0.005153748 0.2349889 -0.448638924
#> 52 22 depth 0.48022845 0.53267351 0.039745711 0.1731353 -0.340259332
#> 53 23 depth 1.08986309 -0.29670057 -0.194998636 0.1194083 -0.428340128
#> 54 24 depth -0.99063147 0.81581050 0.297942501 0.1599364 -0.032035043
#> 55 25 depth 1.09103446 -1.44834953 -0.436633602 0.2379949 -0.921435155
#> 56 26 depth 0.32262042 -0.29825692 -0.077579457 0.1433945 -0.346381492
#> 57 27 depth 1.00040116 1.99477614 -0.117108063 0.3043200 -0.811687748
#> 58 28 depth -1.43188575 0.58388189 0.436530834 0.1941419 0.091441766
#> 59 29 depth -1.01568370 1.02552039 0.253899667 0.1044769 0.055372296
#> 60 30 depth -0.54022902 0.52389907 0.285921031 0.1533128 0.022601906
#> q50 q97.5
#> 1 0.70483682 1.103885966
#> 2 0.19242257 0.701755206
#> 3 -0.21086955 0.139889134
#> 4 -0.06933639 0.238908349
#> 5 -0.00861236 0.311793859
#> 6 -0.13046069 0.248979018
#> 7 0.30040045 0.637248759
#> 8 0.20294240 0.471073791
#> 9 0.01836104 0.343854572
#> 10 0.05322179 0.449228454
#> 11 -0.54719202 0.002991587
#> 12 -0.31969369 -0.016909143
#> 13 -0.07999497 0.205126370
#> 14 -0.12868296 0.253145219
#> 15 0.61300588 0.931267171
#> 16 0.07319716 0.383792718
#> 17 0.69040038 1.088436076
#> 18 0.68075231 1.124423609
#> 19 -0.43481042 0.062682985
#> 20 -0.05253699 0.321759915
#> 21 -0.75706811 -0.303203808
#> 22 -0.37034266 -0.044829664
#> 23 -0.39849581 -0.007657013
#> 24 -0.02062395 0.234954570
#> 25 0.23135675 0.708389090
#> 26 -0.06490811 0.319815030
#> 27 -0.15363854 0.251105227
#> 28 -0.07511114 0.164468005
#> 29 0.03471433 0.349832095
#> 30 0.07689897 0.475646104
#> 31 -0.08615237 0.255414588
#> 32 -0.31203130 0.125574171
#> 33 0.10811249 0.610014446
#> 34 -0.32795856 -0.005664490
#> 35 -0.22123324 0.160815122
#> 36 -0.35223987 -0.084612554
#> 37 -0.04281083 0.292386167
#> 38 0.11862500 0.573060246
#> 39 0.27423481 0.545650919
#> 40 0.16510722 0.652377865
#> 41 -0.09811787 0.197610633
#> 42 -0.30899897 -0.004679579
#> 43 0.44521095 0.791540573
#> 44 0.33246295 0.926193450
#> 45 -0.10770718 0.253733333
#> 46 0.20961521 0.481347033
#> 47 0.07106074 0.525481487
#> 48 -0.11381893 0.238930660
#> 49 -0.05101140 0.293546533
#> 50 -0.19170538 0.073724132
#> 51 -0.01339483 0.581441255
#> 52 0.04741741 0.362978987
#> 53 -0.18945369 0.039422226
#> 54 0.29808228 0.648200679
#> 55 -0.42372503 -0.001669192
#> 56 -0.08402612 0.215643613
#> 57 -0.08903803 0.429890910
#> 58 0.43925275 0.854412060
#> 59 0.25653403 0.463204912
#> 60 0.28481026 0.604788893
# }