首页 > 解决方案 > 矩阵形式的标准化到非标准化之间的转换

问题描述

也许有人可以告诉我下面的代码哪里错了。我正在尝试标准化变量集,然后将其转换回原始状态。但是,似乎我每隔一行都有错误。

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

标签: rmatrixtransforminverse

解决方案


推荐阅读