Functional Imputation
impute.Rd
Several basic imputation methods for missing values in functional data formatted as dfts objects.
Usage
impute(
X,
method = c("zero", "mean_obs", "median_obs", "mean_data", "median_data", "linear",
"functional"),
obs_share_data = FALSE
)
Arguments
- X
A dfts object or data which can be automatically converted to that format. See
dfts()
.- method
String to indicate method of imputation.
zero: Fill missing values with 0.
mean_obs: Fill missing values with the mean of each observation.
median_obs: Fill missing values with the median of each observation.
mean_data: Fill missing values with the mean of the data at that particular fparam value.
median_data: Fill missing values with the median of the data at that particular fparam value.
linear: Fill missing values with linear interpolation.
functional: Fill missing values with functional interpolation. This is done by fitting the data to basis with the package 'fda'.
Boolean in linear interpolation that indicates if data should be shared across observations. For example, if the end of observation i related to the start of observation i+1. Default is FALSE, which suggests independence. If true, the distance between the end and start of observations is taken to be the mean average distance of points in fparam.
Examples
temp <- data.frame(
c(NA, NA, 3:9, NA),
c(NA, stats::rnorm(2), NA, stats::rnorm(6)),
stats::rnorm(10),
c(stats::rnorm(4), rep(NA, 3), stats::rnorm(3)),
rep(NA, 10),
c(stats::rnorm(1), rep(NA, 9)),
c(stats::rnorm(9), NA),
stats::rnorm(10),
stats::rnorm(10),
c(NA, NA, 3:9, NA)
)
impute(temp, method = "mean_obs")
#> X
#> dimension: 10 x 10
#> season: 1
#> fparam (10): 0 0.1111111 0.2222222 0.3333333 0.4444444 0.5555556 ...
#> labels (10): c.NA..NA..3.9..NA. c.NA..stats..rnorm.2...NA..stats..rnorm.6.. stats..rnorm.10. c.stats..rnorm.4...rep.NA..3...stats..rnorm.3.. rep.NA..10. c.stats..rnorm.1...rep.NA..9.. ...
#>
#> Example data
#> [,1] [,2] [,3] [,4] [,5] [,6]
#> [1,] 6 -0.0541986 0.7779787 -0.7922591 NA 2.053649
#> [2,] 6 -0.6796192 -0.2680903 -1.1136238 NA 2.053649
#> [3,] 3 -0.1617645 0.3205850 -1.5919281 NA 2.053649
#> [4,] 4 -0.0541986 -0.1249798 -1.1974301 NA 2.053649
#> [5,] 5 -0.4905572 1.3617403 -0.4252574 NA 2.053649
#> [6,] 6 1.6459217 0.4818533 -0.4252574 NA 2.053649
impute(temp, method = "linear", obs_share_data = TRUE)
#> X
#> dimension: 10 x 10
#> season: 1
#> fparam (10): 0 0.1111111 0.2222222 0.3333333 0.4444444 0.5555556 ...
#> labels (10): c.NA..NA..3.9..NA. c.NA..stats..rnorm.2...NA..stats..rnorm.6.. stats..rnorm.10. c.stats..rnorm.4...rep.NA..3...stats..rnorm.3.. rep.NA..10. c.stats..rnorm.1...rep.NA..9.. ...
#>
#> Example data
#> [,1] [,2] [,3] [,4] [,5] [,6]
#> [1,] 1 4.6601904 0.7779787 -0.7922591 0.891822 2.053649
#> [2,] 2 -0.6796192 -0.2680903 -1.1136238 1.008005 1.977912
#> [3,] 3 -0.1617645 0.3205850 -1.5919281 1.124187 1.902175
#> [4,] 4 -0.3261608 -0.1249798 -1.1974301 1.240370 1.826437
#> [5,] 5 -0.4905572 1.3617403 -0.9017269 1.356553 1.750700
#> [6,] 6 1.6459217 0.4818533 -0.6060237 1.472736 1.674963