| fill_missing | R Documentation |
The fillmissing() function replaces missing measurements in single-case
data. It linearly interpolates missing data points between two existing
measurements for all variables except the measurement time and phase. The
measurement time variable is filled with the missing time points. The phase
variable is copied from the previous measurement time point. If mt values are
missing (NA), they are also interpolated if interpolate_na = TRUE.
fill_missing(data, dvar, mvar, pvar, interpolate_na = TRUE)
data |
A single-case data frame. See |
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. |
pvar |
Character string with the name of the phase variable. Defaults to the attributes in the scdf file. |
interpolate_na |
If set |
The fill_missing() function is designed to handle single-case data
with missing measurement points. It performs linear interpolation to estimate
the missing values based on the existing data points. The function iterates
through each single-case in the provided single-case data frame (scdf) and
identifies gaps in the measurement time variable. For each gap, it calculates
the step size for linear interpolation and fills in the missing values for
all target variables (i.e., all variables except the measurement time and
phase). The interpolated data points are then added to the single-case data
frame, and the final result is sorted by measurement time. This function is
particularly useful for preparing single-case data for further analysis, such
as calculating overlap indices or conducting randomization tests, where
continuous measurement times are required. It ensures that the data is
complete by filling in the missing measurement points in a systematic manner.
A single-case data frame with interpolated missing data points.
Juergen Wilbert
Other data manipulation functions:
add_l2(),
as.data.frame.scdf(),
as_scdf(),
batch_apply(),
moving_median(),
print.sc_outlier(),
ranks(),
rescale(),
scdf(),
select_cases(),
set_vars(),
shift(),
smooth_cases(),
standardize(),
truncate_phase()
## 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
## An example with multiple interpolated variables
rolf_n <- exampleAB_add
rolf_n[[1]] <- rolf_n[[1]][-c(3,7,8),]
rolf_f <- fill_missing(rolf_n)
study1 <- c("original" = exampleAB_add, "interpolated" = rolf_f)
study1
## Example with missing NAs in measurement time
Maggie2 <- random_scdf(design(level = list(0,1)), seed = 123)
Maggie2_n <- Maggie2
Maggie2_n[[1]][c(5,12:14,20), "mt"] <- NA
Maggie2_f <- fill_missing(Maggie2_n)
study2 <- c("original" = Maggie2, "interpolated" = Maggie2_f)
study2
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.