Skip to contents

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'.

obs_share_data

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.

Value

A dfts object of the data with missing values interpolated.

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
#> 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.04700834  1.4335584 -0.08626380   NA -1.016992
#> [2,]    6 -0.52772779 -0.1766458 -0.60914380   NA -1.016992
#> [3,]    3  0.57752931 -0.4965200  1.24876947   NA -1.016992
#> [4,]    4  0.04700834  0.8675189  0.07178065   NA -1.016992
#> [5,]    5  0.39563136  1.0526662  0.72521688   NA -1.016992
#> [6,]    6  0.52759328  1.9583707  0.72521688   NA -1.016992
impute(temp, method='linear', obs_share_data=TRUE)
#> X 
#> dimension: 10 x 10
#> 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.7361361  1.4335584 -0.08626380 1.8091812 -1.0169916
#> [2,]    2 -0.5277278 -0.1766458 -0.60914380 1.5265639 -0.8613395
#> [3,]    3  0.5775293 -0.4965200  1.24876947 1.2439466 -0.7056874
#> [4,]    4  0.4865803  0.8675189  0.07178065 0.9613294 -0.5500353
#> [5,]    5  0.3956314  1.0526662  0.54404725 0.6787121 -0.3943833
#> [6,]    6  0.5275933  1.9583707  1.01631385 0.3960948 -0.2387312