全部版块 我的主页
论坛 数据科学与人工智能 数据分析与数据科学 SAS专版
3895 2
2013-06-14
array x{1:2,1:3} x11 x12 x13 x21 x22 x23;
定义一个2X3数组
想求:
s1=sum(of x[1,*]);和 s_1=sum(of x[*,1]);
这个求和语句有错误,求正确写法.
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

全部回复
2013-6-14 16:03:00
不知道有没有表述清楚,如下为整段过程,目的是练习求卡方值和P值.

data _null_;
array x {1:2,1:3} x11 x12 x13 x21 x22 x23(934 113 20 1070 92 8);
array exp{1:2,1:3} e11 e12 e13 e21 e22 e23;
array s{1:2} s1_ s2_;
array s_{1:3} s_1 s_2 s_3;
sum=sum(of x{*});
do i=1 to 2;
s=sum(of x{i, });end;
do i=1 to 3;
s_=sum(of x{ ,i});
end;
do i=1 to 2 ;
do j=1 to 3;
exp[i,j]=s*s_[j]/sum;
chisq +(x[i,j]-exp[i,j])**2/exp[i,j];
end;
end;
put chisq=;
p=cdf('chisq',chisq,3);
put p=;
put _all_;
run;
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2013-6-15 08:57:15

/* it seems that * : -- does not work with sum() and 2d-array   */
/* but you can add another loop to sum the column or row        */


data _null_;
array x {2,3} x11 x12 x13 x21 x22 x23(934 113 20 1070 92 8);
array exp{2,3} e11 e12 e13 e21 e22 e23;
array s{2} s1_ s2_;
array s_{3} s_1 s_2 s_3;

sum=sum(of x{*});
   do i=1 to 2;
       s
=0;
       do j = 1 to 3;
       s[ i ] + x[i, j] ; end;
   end;

   do i=1 to 3;
       s_
= 0;
       do j = 1 to 2;
       s_[ i ]=s_
+ x[j ,i]; end;
   end;

   do i=1 to 2 ;
         do j=1 to 3;
            exp[i, j]=s[ i ]*s_[ j ]/sum;
            chisq +(x[i,j]-exp[i,j])**2/exp[i,j];
         end;
     end;
  put chisq=;
  p=cdf('chisq',chisq,3);
  put p=;
  put _all_;
run;
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

相关推荐
栏目导航
热门文章
推荐文章

说点什么

分享

扫码加好友,拉您进群
各岗位、行业、专业交流群