Sas 过程中的平方误差之和
我正在尝试创建一个运行Newton Raphson优化的代码。我使用的是proc iml,但是当我需要计算误差e时,我需要将所有的平方差相加,并且不知道如何告诉SAS,在这种情况下,我需要的是向量分量的和,而不是向量分量的和。 代码如下:Sas 过程中的平方误差之和,sas,newtons-method,sas-iml,Sas,Newtons Method,Sas Iml,我正在尝试创建一个运行Newton Raphson优化的代码。我使用的是proc iml,但是当我需要计算误差e时,我需要将所有的平方差相加,并且不知道如何告诉SAS,在这种情况下,我需要的是向量分量的和,而不是向量分量的和。 代码如下: proc iml; use chap0; read all var{X} into X; read all var{t} into t; W=1; s= exp(X*w)/(1+ exp(X*w)); pr
proc iml; use chap0; read all var{X} into X;
read all var{t} into t;
W=1;
s= exp(X*w)/(1+ exp(X*w)); print s;
e = (s - t) ** 2; /*here I need the result of the sum for that and not the matrix*/
g=2*(s-t)*s*(1-s);
h=2 * s * (1 - s) * (s * (1 - s) + (s - t) * (1 - 2 * s));
count=0;/*init count number*/
do until (e<1e-8);
count=count+1;
w=w0-g/h; /*here I also need the sum of g and h*/
s= exp(X*w)/(1+ exp(X*w));
e = (s - t) ** 2;
wo=w;
end;
谢谢 您应该使用该函数计算IML中的平方和
e=ssq(s-t);
这里有其他几种方法可以做到这一点。注意,第一种方法给出了一个不同的结果,因为它是s和-t的平方和,只是一个传递参数的不同示例
proc iml;
x = 1:5;
y = j(1,5,2);
e1=ssq(x,-y); *sum of the squares, not actually subtracting note, so it is not the same answer;
e2=ssq(x-y); *sum of squares of the differences;
e3=(x-y)*(x-y)`; *multiplying a vector by its transpose sums it;
e4=(x-y)[##]; *summation subscript operator, see note;
print e1 e2 e3 e4;
quit;
Rick Wicklin对操作员有一个非常有用的建议