R: MICをためしてみる [統計]
"相関"の話&そのついでに"21世紀の相関(MIC)"の話(ややマニア向け) - Take a Risk: 林岳彦の研究メモ
ということで、MICをためしてみた。
Rでは、minervaパッケージをつかえばよいとのことだったので、さっそくインストールした。
ためしてみる。
> library(minerva)
まずはこういうデータでやってみる。
> n <- 100 > x <- runif(n, min = -1, max = 1) > y <- sqrt(1 - x^2) + rnorm(n, 0, 0.05) > > plot(x, y)
Pearsonの相関係数だとこうなる。
> cor.test(x, y, method = "pearson") Pearson's product-moment correlation data: x and y t = 0.4569, df = 98, p-value = 0.6488 alternative hypothesis: true correlation is not equal to 0 95 percent confidence interval: -0.1516910 0.2403425 sample estimates: cor 0.04610066
MICを計算してみる。ほかにもいくつか指標がでているが、おいおいしらべるとしよう。MIC-R2はMICとR2との差とのことである。
> mine(x, y) $MIC [1] 0.8291383 $MAS [1] 0.5163733 $MEV [1] 0.8291383 $MCN [1] 3.807355 $`MIC-R2` [1] 0.8270131
いろいろやってみる。
> n <- 100 > x <- runif(n, min = -2 * pi, max = 2 * pi) > y <- sin(x) + rnorm(n, 0, 0.05) > > plot(x, y)
> cor.test(x, y, method = "pearson") Pearson's product-moment correlation data: x and y t = -5.9331, df = 98, p-value = 4.486e-08 alternative hypothesis: true correlation is not equal to 0 95 percent confidence interval: -0.6453338 -0.3533375 sample estimates: cor -0.5140777 > mine(x, y) $MIC [1] 1 $MAS [1] 0.6046217 $MEV [1] 1 $MCN [1] 3.807355 $`MIC-R2` [1] 0.7357241
こういうデータでも。
> n <- 100 > x <- runif(n, min = 0, max = 4) > y <- x - floor(x) + rnorm(n, 0, 0.05) > > plot(x, y)
> cor.test(x, y, method = "pearson") Pearson's product-moment correlation data: x and y t = 3.4003, df = 98, p-value = 0.0009751 alternative hypothesis: true correlation is not equal to 0 95 percent confidence interval: 0.1371888 0.4900056 sample estimates: cor 0.3248533 > mine(x, y) $MIC [1] 0.6891383 $MAS [1] 0.4679093 $MEV [1] 0.6891383 $MCN [1] 3.807355 $`MIC-R2` [1] 0.5836087
ばらつきをちいさくしてみる。
> n <- 100 > x <- runif(n, min = 0, max = 4) > y <- x - floor(x) + rnorm(n, 0, 0.01) > > plot(x, y)
> cor.test(x, y, method = "pearson") Pearson's product-moment correlation data: x and y t = 1.9391, df = 98, p-value = 0.05537 alternative hypothesis: true correlation is not equal to 0 95 percent confidence interval: -0.004356778 0.374503945 sample estimates: cor 0.1922258 > mine(x, y) $MIC [1] 0.7538374 $MAS [1] 0.469407 $MEV [1] 0.7538374 $MCN [1] 3.807355 $`MIC-R2` [1] 0.7168866
ばらつきをおおきくしてみる。
> n <- 100 > x <- runif(n, min = 0, max = 4) > y <- x - floor(x) + rnorm(n, 0, 0.1) > > plot(x, y)
> cor.test(x, y, method = "pearson") Pearson's product-moment correlation data: x and y t = 2.6096, df = 98, p-value = 0.01049 alternative hypothesis: true correlation is not equal to 0 95 percent confidence interval: 0.06156619 0.42980098 sample estimates: cor 0.2549019 > mine(x, y) $MIC [1] 0.7009625 $MAS [1] 0.4471932 $MEV [1] 0.7009625 $MCN [1] 3.807355 $`MIC-R2` [1] 0.6359876
2つ前よりMICがおおきくなってしまったが、こういうこともあるのかも。
タグ:R
2013-04-30 16:53
nice!(0)
コメント(0)
トラックバック(1)
コメント 0