sparse.model.matrix(Matrix)
sparse.model.matrix()所属R语言包:Matrix
Construct Sparse Design / Model Matrices
构建稀疏设计/模型矩阵
译者:生物统计家园网 机器人LoveR
描述----------Description----------
Construct a Model or “Design” Matrix
构建一个模型或“设计”矩阵
用法----------Usage----------
sparse.model.matrix(object, data = environment(object),
contrasts.arg = NULL, xlev = NULL, transpose = FALSE,
drop.unused.levels = FALSE, row.names=TRUE, ...)
参数----------Arguments----------
参数:object
an object of an appropriate class. For the default method, a model formula or terms object.
一个适当的类的对象。默认的方法,模型公式或计算对象。
参数:data
a data frame created with model.frame. If another sort of object, model.frame is called first.
model.frame创建一个数据框。如果另一个对象排序,model.frame被称为第一。
参数:contrasts.arg
A list, whose entries are contrasts suitable for input to the contrasts replacement function and whose names are the names of columns of data containing factors.
列表项对比适合输入contrasts替换功能,其名称是data含factor的列的名称。
参数:xlev
to be used as argument of model.frame if data has no "terms" attribute.
作为参数使用model.frame如果data有没有"terms"属性。
参数:transpose
logical indicating if the transpose should be returned; if the transposed is used anyway, setting transpose = TRUE is more efficient.
逻辑表示如果转应退还;如果换位反正设置transpose = TRUE是更有效。
参数:drop.unused.levels
should factors have unused levels dropped? (This used to be true, implicitly in versions of Matrix up to July 2010; the default has been changed for compatibility with R's standard (dense) model.matrix().
因素应该有未使用的水平下降? (这是真实的,隐含在版本Matrix2010年7月,默认已经改变R的标准(密集的兼容性)model.matrix()的。
参数:row.names
logical indicating if row names should be used.
逻辑表明,如果行的名称应当使用。
参数:...
further arguments passed to or from other methods.
通过进一步的论据或其他方法。
值----------Value----------
a sparse matrix extending CsparseMatrix.
一个稀疏矩阵延伸CsparseMatrix。
Note that model.Matrix(*, sparse=TRUE) from package MatrixModels may be often be preferable to sparse.model.matrix() nowadays, as model.Matrix() returns modelMatrix objects with additional slots assign and contrasts which relate back to the variables used.
请注意model.Matrix(*, sparse=TRUE)包MatrixModels可往往是最好sparse.model.matrix()现在model.Matrix()回报modelMatrix对象附加插槽assign和 contrasts这回使用的变量。
As model.Matrix() used to be part of the Matrix package for a few months in summer 2010, it is currently provided as a stub which loads the MatrixModels package and uses its model.Matrix.
model.Matrix()用于Matrix包在2010年夏季几个月的一部分,它正在提供这加载MatrixModels包,并使用其model.Matrix的存根 。
作者(S)----------Author(s)----------
Doug Bates and Martin Maechler, with initial suggestions from Tim
Hesterberg.
参见----------See Also----------
model.matrix in standard R's package stats.<br> model.Matrix which calls sparse.model.matrix or model.matrix depending on its sparse argument may be preferred to sparse.model.matrix.
model.matrixR的标准包stats。参考model.Matrix要求sparse.model.matrix或model.matrix取决于其sparse参数可能更喜欢 sparse.model.matrix。
as(f, "sparseMatrix") (see coerce(from = "factor", ..) in the class doc sparseMatrix) produces the transposed sparse model matrix for a single factor f (and no contrasts).
as(f, "sparseMatrix")(见coerce(from = "factor", ..)类文档sparseMatrix)生产的换位为一个单一的因素f(对比)稀疏模式矩阵。
举例----------Examples----------
dd <- data.frame(a = gl(3,4), b = gl(4,1,12))# balanced 2-way[均衡的2路]
options("contrasts") # the default: "contr.treatment"[默认:“contr.treatment”]
sparse.model.matrix(~ a + b, dd)
sparse.model.matrix(~ -1+ a + b, dd)# no intercept --> even sparser[没有拦截 - >甚至稀疏]
sparse.model.matrix(~ a + b, dd, contrasts = list(a="contr.sum"))
sparse.model.matrix(~ a + b, dd, contrasts = list(b="contr.SAS"))
## Sparse method is equivalent to the traditional one :[相当于传统的#稀疏的方法是:]
stopifnot(all(sparse.model.matrix(~ a + b, dd) ==
Matrix(model.matrix(~ a + b, dd), sparse=TRUE)),
all(sparse.model.matrix(~ 0+ a + b, dd) ==
Matrix(model.matrix(~ 0+ a + b, dd), sparse=TRUE)))
转载请注明:出自 生物统计家园网(http://www.biostatistic.net)。
注:
注1:为了方便大家学习,本文档为生物统计家园网机器人LoveR翻译而成,仅供个人R语言学习参考使用,生物统计家园保留版权。
注2:由于是机器人自动翻译,难免有不准确之处,使用时仔细对照中、英文内容进行反复理解,可以帮助R语言的学习。
注3:如遇到不准确之处,请在本贴的后面进行回帖,我们会逐渐进行修订。
|