svc: Extract spatially-varying coefficients from a fitted model

View source: R/spatial_svc.R

svcR Documentation

Extract spatially-varying coefficients from a fitted model

Description

Extract posterior distributions of spatially-varying coefficients (SVCs) from a fitted tulpa model with SVC specification.

Usage

svc(object, terms = NULL, summary = FALSE, probs = c(0.025, 0.5, 0.975), ...)

## S3 method for class 'tulpa_fit'
svc(object, terms = NULL, summary = FALSE, probs = c(0.025, 0.5, 0.975), ...)

## S3 method for class 'tulpa_svc_posterior'
summary(object, probs = c(0.025, 0.5, 0.975), ...)

## S3 method for class 'tulpa_svc_posterior'
print(x, ...)

## S3 method for class 'tulpa_svc_summary'
print(x, ...)

Arguments

object

A tulpa_fit object fitted with svc argument

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 tulpa_svc_posterior or tulpa_svc_summary object.

Value

A tulpa_svc_posterior object containing:

  • draws: Array of posterior draws (draws x locations x terms)

  • coords: Coordinate matrix

  • term_names: Names of SVC terms

summary() on a tulpa_svc_posterior returns a tulpa_svc_summary data frame with one row per location and term, holding the observation index, term name, coordinates, and the posterior mean, SD and requested quantiles of each spatially varying coefficient.

See Also

spatial_svc(), plot.tulpa_svc_posterior()

Examples


set.seed(303)
n <- 25L
df <- data.frame(lon = runif(n), lat = runif(n), x = rnorm(n))
bsurf <- 0.9 * sin(2.8 * df$lon) + 0.7 * cos(2.2 * df$lat)
df$count <- rpois(n, exp(0.2 + (0.8 + bsurf) * df$x))

# The varying slope on `x` is a spatial field; SVC is exact-mode only.
fit <- tulpa(
  count ~ x,
  data = df,
  family = "poisson",
  spatial = spatial_svc(~ lon + lat, terms = ~ x - 1, nn = 5L),
  mode = "exact",
  control = list(n_iter = 80L, n_warmup = 40L, seed = 1L)
)

svc_post <- svc(fit)
summary(svc_post)



tulpa documentation built on Oct. 19, 2026, 5:09 p.m.