R/make.Z.matrix.R

Defines functions make.Z.matrix

make.Z.matrix <- function(genotype) {
# genotype : a vector (character or factor) with genotype labels
    #if (class(genotype)=='character') {
    #  genotype <- factor(genotype)
    #}
    genotype <- factor(as.character(genotype), levels = as.character(unique(genotype)))


		xx <- data.frame(geno = genotype)
		mf <- model.frame(~ geno - 1, xx, drop.unused.levels = TRUE)
		mt <- terms(mf)
		f.terms <- attr(mt, "term.labels")[attr(mt,"dataClasses") == "factor"]
		Z.t <- Matrix(model.matrix(mt, data = mf,
                               contrasts.arg = lapply(mf[,f.terms, drop = FALSE],
                                                      contrasts, contrasts=FALSE)))
return(Z.t)
}

Try the pcgen package in your browser

Any scripts or data that you put into this service are public.

pcgen documentation built on May 2, 2019, 2:10 p.m.