Title: Semiparametric Spatiotemporal Model with Mixed Frequencies
Version: 1.0.0
Description: Fits a semiparametric spatiotemporal model for data with mixed frequencies, specifically where the response variable is observed at a lower frequency than some covariates. The estimation uses an iterative backfitting algorithm that combines a non-parametric smoothing spline for high-frequency data, parametric estimation for low-frequency and spatial neighborhood effects, and an autoregressive error structure. Methodology based on Malabanan, Lansangan, and Barrios (2022) https://scienggj.org/2022/SciEnggJ%202022-vol15-no02-p90-107-Malabanan%20et%20al.pdf.
License: MIT + file LICENSE
Encoding: UTF-8
RoxygenNote: 7.3.3
Imports: graphics, sf, spdep, stats, utils
Suggests: testthat (≥ 3.0.0)
Config/testthat/edition: 3
URL: https://github.com/jzeuzs/SemiparMF, https://semiparmf.j3z.dev
BugReports: https://github.com/jzeuzs/SemiparMF/issues
NeedsCompilation: no
Packaged: 2026-01-30 10:27:55 UTC; jez
Author: Jezzu Morrisen Quimosing ORCID iD [aut, cre, cph]
Maintainer: Jezzu Morrisen Quimosing <mail@j3z.dev>
Repository: CRAN
Date/Publication: 2026-02-03 13:20:06 UTC

Internal Computational Function for SemiparMF

Description

Implements the iterative backfitting algorithm with Cochrane-Orcutt updates as described in Malabanan et al. (2022). This function handles the core estimation loop, separating the non-parametric spline component from the parametric and temporal components.

Usage

.semipar_internal(y, x_high, z_low, w_mat, max_iter = 50, tol = 1e-04, ...)

Arguments

y

Numeric matrix (N x T). The response variable in wide format (rows=locations, cols=time).

x_high

Numeric array (N x T x K). The high-frequency covariate.

  • N: Number of spatial locations.

  • T: Number of low-frequency time points (matching y).

  • K: Frequency ratio (e.g., 3 for monthly data predicting quarterly response).

z_low

Numeric matrix (N x T). The parametric covariate (same frequency as y).

w_mat

Numeric matrix (N x T). The spatial neighborhood covariate (e.g., spatial lag of Z).

max_iter

Integer. Maximum number of backfitting iterations. Default is 50.

tol

Numeric. Convergence tolerance based on percentage change in Mean Squared Prediction Error (MSPE). Default is 1e-4.

...

Additional arguments passed to smooth.spline (e.g., spar).

Value

A list containing:

coefficients

List of scalar estimates: beta (covariate effect), gamma (spatial effect), and rho (temporal autocorrelation).

nonparam

List containing the spline object and f_hat (estimated non-parametric component).

residuals

Matrix (N x T) of pure structural residuals (Y - \hat{Y}).

fitted.values

Matrix (N x T) of fitted values.

history

Vector of MSPE values per iteration.

iters

Number of iterations performed.

References

Malabanan, V. A., Lansangan, J. R. G., & Barrios, E. B. (2022). Semiparametric Spatiotemporal Model with Mixed Frequencies: With Application in Crop Forecasting. Science & Engineering Journal, 15(2), 90-107.


Plot Convergence History

Description

Plots the Mean Squared Prediction Error (MSPE) across iterations.

Usage

## S3 method for class 'semiparMF'
plot(x, ...)

Arguments

x

An object of class semiparMF.

...

Additional graphical parameters.

Value

No return value, called for side effects (plotting).


Predict Method for SemiparMF

Description

Generates predictions for new data. Reference: "Predicted values are calculated by simply adding up the scores... and the linear combination".

Usage

## S3 method for class 'semiparMF'
predict(object, new_high_freq, new_z, new_w, ...)

Arguments

object

An object of class semiparMF.

new_high_freq

Numeric array (N x T_new x K) for the high-frequency covariate.

new_z

Numeric matrix (N x T_new) for the parametric covariate.

new_w

Numeric matrix (N x T_new) for the neighborhood covariate.

...

Additional arguments.

Value

A matrix (N x T_new) of predicted values.


Print Method for SemiparMF

Description

Print Method for SemiparMF

Usage

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

Arguments

x

An object of class semiparMF.

...

Additional arguments.

Value

The input object x is returned invisibly.


Print Summary for SemiparMF

Description

Print Summary for SemiparMF

Usage

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

Arguments

x

An object of class summary.semiparMF.

...

Additional arguments.

Value

The input object x is returned invisibly.


Fit Semiparametric Spatiotemporal Model with Mixed Frequencies

Description

Fits a spatiotemporal model where the response variable is observed at a lower frequency (e.g., quarterly) than a non-parametric covariate (e.g., monthly). The model combines a non-parametric component for the high-frequency predictor, parametric components for low-frequency predictors and spatial neighborhood effects, and an autoregressive error structure.

Usage

semiparMF(
  formula,
  data_sf,
  high_freq_data,
  time_col,
  id_col,
  w_matrix = NULL,
  ...
)

Arguments

formula

A formula object (e.g., Y ~ Z). The left-hand side is the response variable (low frequency). The first predictor on the right-hand side is the parametric covariate ($Z$) measured at the same frequency.

data_sf

An sf object containing the panel data in long format. Must contain columns for the response, the parametric covariate, the time index, and the location ID.

high_freq_data

A numeric array of dimensions (N x T x K), where:

  • N: Number of unique spatial locations (must match data_sf).

  • T: Number of time points (must match data_sf).

  • K: The frequency ratio (e.g., 3 if predictor is monthly and response is quarterly).

time_col

Character string. The name of the column in data_sf representing the time index.

id_col

Character string. The name of the column in data_sf representing the location ID.

w_matrix

Optional numeric matrix (N x T). A pre-calculated spatial weight or neighborhood variable. If NULL (default), a spatial lag of the variable $Z$ is calculated using Queen Contiguity weights.

...

Additional arguments passed to the internal backfitting function (e.g., max_iter, tol, spar).

Value

An object of class semiparMF containing:

coefficients

A list of estimated parameters: beta (parametric covariate effect), gamma (neighborhood effect), and rho (autoregressive parameter).

nonparam

A list containing the fitted smoothing spline and the aggregated non-parametric component f_hat.

residuals

Matrix (N x T) of model residuals.

fitted.values

Matrix (N x T) of the fitted values (structural part only).

dims

Dimensions of the data (N, T).

meta

Metadata containing location IDs and time indices.

history

Convergence history (MSPE per iteration).

call

The function call.

References

Malabanan, V. A., Lansangan, J. R. G., & Barrios, E. B. (2022). Semiparametric Spatiotemporal Model with Mixed Frequencies: With Application in Crop Forecasting. Science & Engineering Journal, 15(2), 90-107.

Examples

# Simulate data using the package's included simulation function
sim <- simulate_semipar_data(n_side = 4, t_len = 20, k = 3, rho_error = 0.5)

# Fit the model
fit <- semiparMF(
  formula = Y ~ Z, 
  data_sf = sim$data, 
  high_freq_data = sim$X_high,
  time_col = "time_id", 
  id_col = "location_id"
)

# Inspect results
summary(fit)


Simulate Spatiotemporal Mixed Frequency Data

Description

Generates a synthetic dataset for testing the SemiparMF model. Structure follows Equation (7) in Malabanan et al. (2022).

Usage

simulate_semipar_data(
  n_side = 6,
  t_len = 50,
  k = 3,
  rho_error = 0.5,
  beta = 0.5,
  gamma = 0.3
)

Arguments

n_side

Integer. Grid side length. Total locations N = n_side^2.

t_len

Integer. Length of the time series (T).

k

Integer. Frequency ratio (e.g., 3 months per quarter).

rho_error

Numeric. Autocorrelation coefficient for the error term (default 0.5).

beta

True coefficient for covariate Z (default 0.5).

gamma

True coefficient for neighborhood variable W (default 0.3).

Value

A list containing:

data

An sf object containing Y, Z, W, and geometry.

X_high

An array (N x T x K) of high-frequency covariates.

true_params

List of true parameters used for generation.

Examples

# Generate a small dataset
sim <- simulate_semipar_data(n_side = 4, t_len = 10, k = 3)

# Check dimensions
dim(sim$data) # 160 x 5 (16 locations * 10 time points)
dim(sim$X_high) # 16 x 10 x 3


Summary Method for SemiparMF

Description

Summary Method for SemiparMF

Usage

## S3 method for class 'semiparMF'
summary(object, ...)

Arguments

object

An object of class semiparMF.

...

Additional arguments.

Value

A list of class summary.semiparMF containing:

coefficients

A list of estimated parameters (beta, gamma, rho).

last_mspe

The Mean Squared Prediction Error from the final iteration.

residuals_summary

Summary statistics of the residuals.

iterations

Total number of iterations performed.

call

The function call.