以下の問題を計算した際に作成したもの
問題
変数x 、yの間にy=x2なる関係が成立している場合に、z=2x2+3として求めた変数yとzの相関係数
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
Sub 相関係数2() Const StartPos As Long = 1 Const Count As Long = 3000 Const EndPos As Long = StartPos + Count Dim ws As Worksheet Set ws = ThisWorkbook.Sheets("sheet1") ws.Cells.ClearContents Dim i As Long, j As Long '公式 Dim X As Long, Y As Long, Z As Long ws.Cells(1, "A") = "X" ws.Cells(1, "B") = "Y=X^2" ws.Cells(1, "C") = "z=2x^2+3" ws.Cells(1, "D") = "相関係数" For i = StartPos To EndPos '計算 X = i Y = X ^ 2 ' Xの2条 Z = 2 * Y + 3 ws.Cells(i + 1, "A") = X ws.Cells(i + 1, "B") = Y ws.Cells(i + 1, "C") = Z DoEvents Next i ws.Range("D2") = "=CORREL(B:B,C:C)" End Sub |
実行結果は1
コメント