ImputeRandom: Impute missing values

View source: R/imputation.R

ImputeRandomR Documentation

Impute missing values

Description

ImputeRandom imputes missing values with the Q ancestry coeficient matrix and G ancestral frequencies estimates. Missing values are sampled with the estimated genotype frequencies (P = Q G^T).

ImputeRound imputes missing values with the Q ancestry coeficient matrix and G ancestral frequencies estimates. Missing values are computed as a round of estimated genotype frequencies (P = Q G^T).

Usage

ImputeRandom(tess3.res, masked.X)

ImputeRound(tess3.res, masked.X)

Arguments

tess3.res

tess3Main object with Q and G estimates.

masked.X

Genotype matrix with the missing values (NA values).

Value

the imputed genotype matrix.

Examples

library(tess3r)

n <- 100
K <- 3
ploidy <- 2
L <- 3001
data.list <- SampleGenoFromGenerativeModelTESS3(G = SampleUnifDirichletG(L, ploidy, K),
                                                Q = SampleUnifQ(n, K),
                                                coord = SampleNormalClusterCoord(n.by.pop = n, K = 1),
                                                ploidy = ploidy)
# mask data
set.seed(0)
masked.prop <- 0.1
masked.X <- data.list$X
masked.X[sample(1:(ncol(masked.X)*nrow(masked.X)), (ncol(masked.X)*nrow(masked.X)) * masked.prop)] <- NA


# run tess3
tess3.obj <- tess3(X = masked.X,
                   coord = data.list$coord,
                   K = 3,
                   ploidy = 2,
                   lambda = 1.0,
                   method = "projected.ls",
                   rep = 2)

imputed.X.random <- ImputeRandom(Gettess3res(tess3.obj,3), masked.X)
mean(data.list$X[is.na(masked.X)] != imputed.X.random[is.na(masked.X)]) # pourcentage of error

imputed.X.round <- ImputeRound(tess3.res = Gettess3res(tess3.obj,3), masked.X)
mean(data.list$X[is.na(masked.X)] != imputed.X.round[is.na(masked.X)]) # pourcentage of error



cayek/TESS3_encho_sen documentation built on July 4, 2023, 7:51 p.m.