2009-11-16

先週のプログラムの修正

回帰を行うために、時間軸を標準化した行を付け加えました。

Sub 解析()
Dim 気温差の和(12), 年数(12), 気温差(12)

'一列に並べ替え
Sheets(2).Cells(1, 3) = "年"
Sheets(2).Cells(1, 4) = "月"
Sheets(2).Cells(1, 5) = "気温"
pointer = 1
For i = 2 To 120
  For j = 2 To 13
    If i < 120 Or j < 12 Then
      pointer = pointer + 1
      Sheets(2).Cells(pointer, 3) = Sheets(1).Cells(i, 1)
      Sheets(2).Cells(pointer, 4) = Left(Sheets(1).Cells(1, j), Len(Sheets(1).Cells(1, j)) - 1)
      Sheets(2).Cells(pointer, 5) = Sheets(1).Cells(i, j)
      Sheets(2).Cells(pointer, 2) = Sheets(2).Cells(pointer, 3) & "/" & Sheets(2).Cells(pointer, 4)
    End If
  Next j
Next i

'行番号を標準化
For i = 2 To pointer
  Sheets(2).Cells(i, 1) = 2 * (i - 2) / (pointer - 2) - 1
Next i

'移動平均により季節成分を除去
Sheets(2).Cells(1, 6) = "移動平均"
For i = 8 To 1421
  wa = 0
  For j = -5 To 5
    wa = wa + Sheets(2).Cells(i + j, 5)
  Next j
  wa = wa + (Sheets(2).Cells(i - 6, 5) + Sheets(2).Cells(i + 6, 5)) / 2
  Sheets(2).Cells(i, 6) = wa / 12
Next i

'季節成分を推定
For i = 1 To 12
  気温差の和(i) = 0
  年数(i) = 0
Next i
For i = 8 To pointer - 6
  気温差の和(Sheets(2).Cells(i, 4)) = 気温差の和(Sheets(2).Cells(i, 4)) + (Sheets(2).Cells(i, 5) - Sheets(2).Cells(i, 6))
  年数(Sheets(2).Cells(i, 4)) = 年数(Sheets(2).Cells(i, 4)) + 1
Next i
For i = 1 To 12
  気温差(i) = 気温差の和(i) / 年数(i)
'  Sheets(2).Cells(i, 7) = 気温差(i)
Next i

'気温差の偏りを調整
気温の差の和 = 0
For i = 1 To 12
  気温の差の和 = 気温の差の和 + 気温差(i)
Next i
For i = 1 To 12
  気温差(i) = 気温差(i) - 気温の差の和 / 12
'  Sheets(2).Cells(i, 7) = 気温差(i)
Next i

Sheets(2).Cells(1, 7) = "季節調整済気温"
For i = 2 To pointer
  Sheets(2).Cells(i, 7) = Sheets(2).Cells(i, 5) - 気温差(Sheets(2).Cells(i, 4))
Next i

End Sub

0 件のコメント: