r - 矩阵形式的标准化到非标准化之间的转换
问题描述
也许有人可以告诉我下面的代码哪里错了。我正在尝试标准化变量集,然后将其转换回原始状态。但是,似乎我每隔一行都有错误。
set.seed(1234)
trash = matrix(runif(10), ncol = 2)
trashc = apply(trash, 2, function(x) x - mean(x))
trashstd = diag(1/sqrt(diag(cov(trashc))))
trashstdr = as.matrix(trashc) %*% trashstd
tmptrash = trashstdr %*% solve(trashstd)
tmptrash = tmptrash + colMeans(trash)
Results from transformation:
tmptrash
# [,1] [,2]
#[1,] 0.1137034 0.6403106
#[2,] 0.4689233 0.1628719
#[3,] 0.6092747 0.2325505
#[4,] 0.4700033 0.8194599
#[5,] 0.8609154 0.5142511
Original set:
trash
# [,1] [,2]
#[1,] 0.1137034 0.640310605
#[2,] 0.6222994 0.009495756
#[3,] 0.6092747 0.232550506
#[4,] 0.6233794 0.666083758
#[5,] 0.8609154 0.514251141
解决方案
推荐阅读
- python - 通过保持最高峰作为参考,识别最高峰,并返回最高峰左右低的值
- html - HTML 视频上的半透明覆盖总是在视频后面
- c# - 在 ASP.Net CORE Web 请求上执行异步工作时将文件保存在磁盘上的最有效方法
- micronaut - 使用 Micronaut 验证 POJO 记录不起作用
- c - mmap 无效参数 - 从命令行读取多个文件并写入一个输出文件
- flutter - 自定义小部件以扩展小部件或使用小部件作为成员?
- c# - 如何优化表单重绘
- flutter - 小部件库捕获的异常═ Stack Overflow 为什么这仅在我初始化 bloc 时显示
- php - 选择高库存的随机产品
- python - 在 MacBook Air 和 catalina 的 anaconda 中安装 Caffe