我试图将带有一堆因子变量的大而密集的data.frame转换为sparse.model.matrix。我收到了大量错误消息,并决定复制文档中的示例。以下是输出。
我已尝试重新启动并重新安装Matrix
软件包。
对可能出错的任何建议?
代码:
library(Matrix)
dd <- data.frame(a = gl(3,4), b = gl(4,1,12))# balanced 2-way
options("contrasts") # the default: "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"))
输出:
> library(Matrix)
> dd <- data.frame(a = gl(3,4), b = gl(4,1,12))# balanced 2-way
> options("contrasts") # the default: "contr.treatment"
$contrasts
unordered ordered
"contr.ltfr" "contr.poly"
> sparse.model.matrix(~ a + b, dd)
Error in get(contrasts.arg) : object 'contr.ltfr' not found
> sparse.model.matrix(~ -1+ a + b, dd)# no intercept --> even sparser
Error in get(contrasts.arg) : object 'contr.ltfr' not found
> sparse.model.matrix(~ a + b, dd, contrasts = list(a="contr.sum"))
Error in get(contrasts.arg) : object 'contr.ltfr' not found
> sparse.model.matrix(~ a + b, dd, contrasts = list(b="contr.SAS"))
Error in get(contrasts.arg) : object 'contr.ltfr' not found
>
> library(caret)
Loading required package: lattice
Loading required package: ggplot2
> dd <- data.frame(a = gl(3,4), b = gl(4,1,12))# balanced 2-way
> options("contrasts") # the default: "contr.treatment"
$contrasts
unordered ordered
"contr.ltfr" "contr.poly"
> sparse.model.matrix(~ a + b, dd)
Error in model.spmatrix(t, data, transpose = transpose, drop.unused.levels = drop.unused.levels, :
no slot of name "i" for this object of class "dgeMatrix"
> sparse.model.matrix(~ -1+ a + b, dd)# no intercept --> even sparser
Error in model.spmatrix(t, data, transpose = transpose, drop.unused.levels = drop.unused.levels, :
no slot of name "i" for this object of class "dgeMatrix"
> sparse.model.matrix(~ a + b, dd, contrasts = list(a="contr.sum"))
Error in model.spmatrix(t, data, transpose = transpose, drop.unused.levels = drop.unused.levels, :
no slot of name "i" for this object of class "dgeMatrix"
> sparse.model.matrix(~ a + b, dd, contrasts = list(b="contr.SAS"))
Error in model.spmatrix(t, data, transpose = transpose, drop.unused.levels = drop.unused.levels, :
no slot of name "i" for this object of class "dgeMatrix"
SessionInfo():
> sessionInfo()
R version 3.4.1 (2017-06-30)
Platform: x86_64-redhat-linux-gnu (64-bit)
Running under: Red Hat Enterprise Linux Server 7.4 (Maipo)
Matrix products: default
BLAS/LAPACK: /usr/lib64/R/lib/libRblas.so
locale:
[1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C LC_TIME=en_US.UTF-8 LC_COLLATE=en_US.UTF-8
[5] LC_MONETARY=en_US.UTF-8 LC_MESSAGES=en_US.UTF-8 LC_PAPER=en_US.UTF-8 LC_NAME=C
[9] LC_ADDRESS=C LC_TELEPHONE=C LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C
attached base packages:
[1] parallel splines stats graphics grDevices utils datasets methods base
other attached packages:
[1] data.table_1.10.4 xgboost_0.6-4 sqldf_0.4-11 RSQLite_2.0 gsubfn_0.6-6 proto_1.0.0 Metrics_0.1.2
[8] gbm_2.1.3 survival_2.41-3 cluster_2.0.6 ade4_1.7-8 convPkg5_0.1 RODBC_1.3-14 caret_6.0-73
[15] ggplot2_2.2.1 lattice_0.20-35 Matrix_1.2-11
loaded via a namespace (and not attached):
[1] Rcpp_0.12.10 compiler_3.4.1 nloptr_1.0.4 plyr_1.8.4 iterators_1.0.8
[6] tools_3.4.1 digest_0.6.12 bit_1.1-12 lme4_1.1-12 memoise_1.0.0
[11] tibble_1.3.4 nlme_3.1-131 gtable_0.2.0 mgcv_1.8-17 rlang_0.1.2
[16] foreach_1.4.3 DBI_0.6-1 microbenchmark_1.4-2.1 SparseM_1.76 stringr_1.2.0
[21] MatrixModels_0.4-1 bit64_0.9-5 stats4_3.4.1 grid_3.4.1 nnet_7.3-12
[26] tcltk_3.4.1 minqa_1.2.4 blob_1.1.0 reshape2_1.4.2 car_2.1-4
[31] magrittr_1.5 scales_0.4.1 codetools_0.2-15 ModelMetrics_1.1.0 MASS_7.3-47
[36] pbkrtest_0.4-7 colorspace_1.3-2 quantreg_5.29 stringi_1.1.3 lazyeval_0.2.0
[41] munsell_0.4.3 chron_2.3-51