Learn R Programming

fasster (version 0.2.0)

interpolate.FASSTER: Interpolate missing values in a FASSTER model

Description

Fills in missing values in the response variable using the model's fitted values. This method only works for interpolating data used to estimate the model and cannot be used for new data.

Usage

# S3 method for FASSTER
interpolate(object, new_data, specials, ...)

Value

A tsibble with missing values in the response variable replaced by fitted values.

Arguments

object

A fitted FASSTER model object.

new_data

A tsibble containing the data to interpolate. Must be the same data used to fit the model.

specials

A list of special terms (passed by fabletools).

...

Additional arguments (currently unused).

Details

This method identifies missing values (NAs) in the response variable and replaces them with the corresponding fitted values from the model. It only works when new_data has the same length as the data used to fit the model.

Examples

Run this code
library(tsibble)
library(dplyr)

# Create data with missing values
deaths_na <- as_tsibble(mdeaths) |>
  mutate(value = if_else(row_number() %in% c(10, 20, 30), NA_real_, value))

# Fit model
fit <- deaths_na |>
  model(FASSTER(value ~ trend(1) + fourier(12)))

# Interpolate missing values
interpolate(fit, deaths_na)

Run the code above in your browser using DataLab