imputation {longitudinalData} | R Documentation |
imputation
is a function that offer different methods to impute
missing value of a LongData
.
imputation(object, method, partition)
object |
[LongData] or [matrix] : longitudinal
data to impute |
method |
[character] : Name of the imputation method (see detail) |
partition |
[Partition] : for some imputation technique (like
"copyMean"), a specific partition is needed. See detail. |
imputation
is a function that impute
missing value of a LongData
.
Several imputation methods are available. For each method, the
imputation has to deal with three kind of missing value :
at start of the trajectorie (first
values are missing), at the end (last values are
missing) or in the middle (the missing value have surround by
non-missing value). Here is a description of each methods (for all of
them, an example is provided in the Examples
section):
linearInterpolation
, the value imediatly
surounding the missing are join by a line;linearInterpolation
, the value imediatly
surounding the missing are join by a line.LongData
relativly to
a Partition
. More precisely, each individual trajectorie is
imputed relatively to its clusters center. For all kind of missing
value, the shape of the clusters center is copied
and is level up (or down) to fit with the non missing value of
the imputed trajectorie.
A matrix
with no missing values.
LongData
, Partition
, criterion
################## ### Preparation of the data timeV <- 1:19 trajMissing <- longData( matrix(c(NA,NA,2,3,NA,5,5.5,5.8,6,NA,NA,6.5,7.5,NA,NA,NA,4,NA,NA),1), id=1,time=timeV,varName="Example" ) plot(timeV,trajMissing["traj"],col=2,type="o",lwd=3,ylim=c(-2,10), xlab="Trajectorie to impute",ylab="") par(ask=TRUE) ################## ### LOCF trajImp <- imputation(trajMissing,method="LOCF") plot(timeV,trajImp["traj"],type="o",ylim=c(-2,10),ylab="",xlab="LOCF") lines(timeV,trajMissing["traj"],col=2,type="o",lwd=3) ### LOCB trajImp <- imputation(trajMissing,method="LOCB") plot(timeV,trajImp["traj"],type="o",ylim=c(-2,10),ylab="",xlab="LOCB") lines(timeV,trajMissing["traj"],col=2,type="o",lwd=3) ### linearInterpolation trajImp <- imputation(trajMissing,method="linearInterpolation") plot(timeV,trajImp["traj"],type="o",ylim=c(-2,10),ylab="",xlab="linearInterpolation") lines(timeV,trajMissing["traj"],col=2,type="o",lwd=3) ### linearInterpolation2 trajImp <- imputation(trajMissing,method="linearInterpolation2") plot(timeV,trajImp["traj"],type="o",ylim=c(-2,10),ylab="",xlab="linearInterpolation2") lines(timeV,trajMissing["traj"],col=2,type="o",lwd=3) ### linearInterpolation3 trajImp <- imputation(trajMissing,method="linearInterpolation3") plot(timeV,trajImp["traj"],type="o",ylim=c(-2,10),ylab="",xlab="linearInterpolation3") lines(timeV,trajMissing["traj"],col=2,type="o",lwd=3) ################## ### copyMean (using the fonction "trajImput.copyMean" for the graphical representation) meanTraj <- c(2,0.5,0,0.2,2,3,3.5,2.9,2,1.2,1,1.5,1.3,0.7,1.2,2.5,1.5,-1,1) trajImp <- trajImput.copyMean(trajMissing["traj"],meanTraj) plot(timeV,trajMissing["traj"],type="o",ylim=c(-2,10),col=2,lwd=3,ylab="", xlab="LongData to impute and its model (in green)") lines(timeV,meanTraj,col=3,type="b",lwd=3) plot(timeV,trajImp,type="o",ylim=c(-2,10),ylab="",xlab="copyMean") lines(timeV,trajMissing["traj"],col=2,type="b",lwd=3) lines(timeV,meanTraj,col=3,type="b",lwd=3) ### copyMean (using the fonction "imputation") trajMiss <- longData( matrix(c(2,3,NA,0, NA,4,0,NA, 4,NA,-1,0),4), id=1:4,time=1:3 ) part <- partition(nbCluster=2,clusters=c(1,1,2,2)) imputation(trajMiss,method="copyMean",partition=part) par(ask=FALSE)