x = Table[i, {i, 1, 1000}];
y = Table[2*i + RandomInteger[PoissonDistribution[Ceiling[i/100.0]]], {i, 1,1000}];
data = Transpose[{x, y}];
Clear[x];
lm = LinearModelFit[data, x, x]
cancha = lm["FitResiduals"];
p1 = ListPlot[cancha]
temp = {};
For[i = 1, i <= 10, i++,
temp = AppendTo[temp, cancha[[100*i - 99 ;; 100*i]]]
];
dataList =
Transpose[{Range @@ #[[1]], #[[2]]}] & /@
Transpose@{# + {1, 0} & /@
Partition[Accumulate[Length /@ Prepend[temp, {}]], 2, 1], temp};
p4 = ListPlot[dataList]
canchaTotal = Total[Abs[cancha]]/Length[cancha]
canchazu = Table[0, {i, 1, 10}];
For[i = 1, i <= 10, i++,
canchazu[[i]] = Total[Abs[cancha[[100*i - 99 ;; 100*i]]]]/99
]
xishu = canchazu/canchaTotal
weight = Table[xishu, {i, 1, 100}];
weight = Flatten@Transpose[weight];
6.对加权后的重新拟合
lmn = LinearModelFit[data/weight, x, x]
temp = {};
For[i = 1, i <= 10, i++,
temp = AppendTo[temp, canchan[[100*i - 99 ;; 100*i]]]
]
dataList =
Transpose[{Range @@ #[[1]], #[[2]]}] & /@
Transpose@{# + {1, 0} & /@
Partition[Accumulate[Length /@ Prepend[temp, {}]], 2, 1], temp};
p3 = ListPlot[dataList, ImageSize -> Medium]
可以看到残差比之前要好一点
Row[{p4, p3}]
有较为明显的区别。
所有评论(0)