Learn R Programming

fdars (version 0.3.3)

sparsify: Convert Regular Functional Data to Irregular by Subsampling

Description

Creates an irregFdata object from regular fdata by randomly selecting a subset of observation points for each curve.

Usage

sparsify(fdataobj, minObs = 5, maxObs = NULL, prob = NULL, seed = NULL)

Value

An object of class irregFdata.

Arguments

fdataobj

An object of class fdata.

minObs

Minimum number of observations to keep per curve.

maxObs

Maximum number of observations to keep per curve. If NULL, uses the total number of points.

prob

Sampling probability function. If NULL, uniform sampling is used. Otherwise, a function that takes argvals and returns sampling weights (not necessarily normalized).

seed

Optional integer random seed for reproducibility.

Details

For each curve, the function:

  1. Draws a random number of points to keep between minObs and maxObs

  2. Samples that many points (without replacement) from the grid

  3. If prob is provided, sampling is weighted accordingly

Common probability functions:

  • Uniform: NULL (default)

  • More points in middle: function(t) dnorm(t, mean = 0.5, sd = 0.2)

  • More points at ends: function(t) 1 - dnorm(t, mean = 0.5, sd = 0.2)

See Also

irregFdata, as.fdata.irregFdata, addError

Examples

Run this code
# Create regular functional data
t <- seq(0, 1, length.out = 100)
fd <- simFunData(n = 20, argvals = t, M = 5, seed = 42)

# Uniform sparsification
ifd <- sparsify(fd, minObs = 10, maxObs = 30, seed = 123)
print(ifd)
plot(ifd)

# Non-uniform: more observations in the middle
prob_middle <- function(t) dnorm(t, mean = 0.5, sd = 0.2)
ifd_middle <- sparsify(fd, minObs = 15, maxObs = 25, prob = prob_middle, seed = 123)
plot(ifd_middle, main = "More Observations in Middle")

Run the code above in your browser using DataLab