最小二乘法是加权最小二乘法的特例。使用最小二乘法需要一些前提,数据大多数时候是满足这些条件的。但有时候这些条件是不能满足的,这时需要对原始数据作适当
看看下面的样例:
** run the original regression to get the residuals**;
proc reg data=prob7870.blood_pr;
model y=x;
output out=work.pred r=residual;
run;
** compute the absolute and squared residuals**;
data work.resid;
set work.pred;
absresid=abs(residual);
sqresid=residual**2;
proc reg data=work.resid;
** run a regression with the absolute residuals vs. x to get the estimated standard deviation**;
model absresid=x;
output out=work.s_weights p=s_hat;
** run a regression with the squared residuals vs. x to get the estimated variance**;
model sqresid=x;
output out=work.v_weights p=v_hat;
run;
** compute the weights using the estimated standard deviations**;
data work.s_weights;
set work.s_weights;
s_weight=1/(s_hat**2);
label s_weight = "weights using absolute residuals";
** compute the weights using the estimated variances**;
data work.v_weights;
set work.v_weights;
v_weight=1/v_hat;
label v_weight = "weights using squared residuals";
** do the weighted least squares using the weights from the estimated standard deviation**;
proc reg data=work.s_weights;
weight s_weight;
model y = x;
run;
** do the weighted least squares using the weights from the estimated variances**;
proc reg data=work.v_weights;
weight v_weight;
model y = x;
run;
quit;
Hadoop|
Apache Pig|
Apache Kafka|
Apache Storm|
Impala|
Zookeeper|
SAS|
TensorFlow|
人工智能基础|
Apache Kylin|
Openstack|
Flink|
MapReduce|
大数据|
云计算|
用户登录
还没有账号?立即注册
用户注册
投稿取消
文章分类: |
|
还能输入300字
上传中....