The fillmissing() function replaces missing measurements in single-case
data.
Arguments
- data
 A single-case data frame. See
scdf()to learn about this format.- dvar
 Character string with the name of the dependent variable. Defaults to the attributes in the scdf file.
- mvar
 Character string with the name of the measurement time variable. Defaults to the attributes in the scdf file.
- na.rm
 If set
TRUE,NAvalues are also interpolated. Default isna.rm = TRUE.
Value
A single-case data frame with interpolated missing data points.  See
scdf() to learn about the SCDF Format.
Details
This procedure is recommended if there are gaps between measurement times
(e.g. MT: 1, 2, 3, 4, 5, ... 8, 9) or explicitly missing values in your
single-case data and you want to calculate overlap indices (overlap()) or a
randomization test (rand_test()).
See also
Other data manipulation functions:
add_l2(),
as.data.frame.scdf(),
as_scdf(),
moving_median(),
outlier(),
ranks(),
rescale(),
scdf(),
select_cases(),
set_vars(),
shift(),
smooth_cases(),
standardize(),
truncate_phase()
Examples
## In his study, Grosche (2011) could not realize measurements each
## single week for all participants. During the course of 100 weeks,
## about 20 measurements per person at different times were administered.
## Fill missing values in a single-case dataset with discontinuous
## measurement times
Grosche2011filled <- fill_missing(Grosche2011)
study <- c(Grosche2011[2], Grosche2011filled[2])
names(study) <- c("Original", "Filled")
study
#> #A single-case data frame with two cases
#> 
#>  Original: values mt phase │ Filled: values mt phase │
#>                13  0     A │             13  0     A │
#>              17.4  1     A │           17.4  1     A │
#>                13  6     A │          16.52  2     A │
#>              7.74 10     A │          15.64  3     A │
#>              8.82 13     A │          14.76  4     A │
#>               7.5 15     A │          13.88  5     A │
#>              5.82 36     A │             13  6     A │
#>              6.26 38     B │          11.69  7     A │
#>               5.6 41     B │          10.37  8     A │
#>             12.79 43     B │           9.05  9     A │
#>              9.17 48     B │           7.74 10     A │
#>             10.59 50     B │            8.1 11     A │
#>              9.23 55     B │           8.46 12     A │
#>             10.71 59     B │           8.82 13     A │
#>              7.61 62     B │           8.16 14     A │
#> # ... up to 87 more rows
## Fill missing values in a single-case dataset that are NA
Maggie <- random_scdf(design(level = list(0,1)), seed = 123)
Maggie_n <- Maggie
replace.positions <- c(10,16,18)
Maggie_n[[1]][replace.positions,"values"] <- NA
Maggie_f <- fill_missing(Maggie_n)
study <- c(Maggie, Maggie_n, Maggie_f)
names(study) <- c("original", "missing", "interpolated")
study
#> #A single-case data frame with three cases
#> 
#>  original: phase values mt │ missing: phase values mt │
#>                A   47.2  1 │              A   47.2  1 │
#>                A  48.85  2 │              A  48.85  2 │
#>                A  57.79  3 │              A  57.79  3 │
#>                A  50.35  4 │              A  50.35  4 │
#>                A  50.65  5 │              A  50.65  5 │
#>                B  68.58  6 │              B  68.58  6 │
#>                B   62.3  7 │              B   62.3  7 │
#>                B  53.67  8 │              B  53.67  8 │
#>                B  56.57  9 │              B  56.57  9 │
#>                B  57.77 10 │              B   <NA> 10 │
#>                B  66.12 11 │              B  66.12 11 │
#>                B   61.8 12 │              B   61.8 12 │
#>                B     62 13 │              B     62 13 │
#>                B  60.55 14 │              B  60.55 14 │
#>                B  57.22 15 │              B  57.22 15 │
#> # ... up to five more rows
#> # One more case
