impKNN: KNN Imputation

imputeKNNR Documentation

KNN Imputation

Description

imputeKNN uses k-nearest neighbors (kNN) method to fill missing values.

Usage

imputeKNN(labData, idColName, k)

Arguments

labData

a file or dataframe of laboratory test data with at least 4 columns about patient ID, lab item, test value and test date, respectively.

idColName

the column name that records patient ID in labData.

k

the numbers of selected nearestZneighbors.

Details

Given wide format data, data can conduct KNN imputation. If lab item code are composed by multiple columns, it will automatically combined as one. All other columns will all be seen as value columns.

Value

A new, wide-formatted imputed data.table.

Examples


timeSeriesData <- getTimeSeriesLab(labData = labSample,
                                   idColName = SUBJECT_ID,
                                   labItemColName = ITEMID,
                                   dateColName = CHARTTIME,
                                   valueColName = VALUENUM,
                                   indexDate = first,
                                   gapDate = 360,
                                   completeWindows = TRUE)
wideData <- wideTimeSeriesLab(labData = timeSeriesData,
                  idColName = ID,
                  labItemColName = ITEMID,
                  windowColName = Window,
                  valueColName = Max)

imputeKNN(labData = wideData,
          idColName = ID + Window,
          k = 2)


DHLab-TSENG/lab documentation built on Sept. 1, 2023, 9:03 p.m.