楼主: webgu
2071 2

[问答] PROC IML 9.3 下运行出错,9.4 的大学版正常。 [推广有奖]

贵宾

学科带头人

95%

还不是VIP/贵宾

-

TA的文库  其他...

Python与统计

SAS与统计

威望
2
论坛币
102549 个
通用积分
3.4687
学术水平
475 点
热心指数
493 点
信用等级
434 点
经验
62369 点
帖子
1555
精华
4
在线时间
2201 小时
注册时间
2009-5-4
最后登录
2025-12-25

初级学术勋章 初级热心勋章 初级信用勋章 中级学术勋章 中级热心勋章 中级信用勋章

楼主
webgu 发表于 2015-3-7 16:40:01 |AI写论文

+2 论坛币
k人 参与回答

经管之家送您一份

应届毕业生专属福利!

求职就业群
赵安豆老师微信:zhaoandou666

经管之家联合CDA

送您一个全额奖学金名额~ !

感谢您参与论坛问题回答

经管之家送您两个论坛币!

+2 论坛币
各位, 以下CODE  9.3 出错, 9.4 正常, 求解?


  1. proc iml;
  2. /* Let X1, X2,...,Xd be binary variables, let
  3.    p = (p1,p2,...,pd) the their expected values and let
  4.    Delta be the d x d matrix of correlations.
  5.    This function returns 1 if p and Delta are feasible for binary
  6.    variables. The function also computes lower and upper bounds on the
  7.    correlations, and returns them in LBound and UBound, respectively  */

  8. start CheckMVBinaryParams(LBound, UBound, _p, Delta);
  9.     p = rowvec(_p); q = 1 - p;              /* make p a row vector */
  10.     d = ncol(p);                            /*number of variables */

  11.     /* 1. check range of Delta; make sure p and Delta are feasible */
  12.     PP = p`*p;  PQ = p`*q;
  13.     QP = q`*p; QQ = q`*q;

  14.     A = -sqrt(PP/QQ); B = -sqrt(QQ/PP);     /* matrices */
  15.     LBound = choose(A>B,A,B);               /* elementwise max(A or B) */
  16.     LBound[loc(I(d))] = 1;                  /* set diagonal to 1 */
  17.     A = sqrt(PQ/QP); B = sqrt(QP/PQ);
  18.     UBound = choose(A<B,A,B);               /*min(A or B)*/
  19.     UBound[loc(I(d))] = 1;                  /*set diagonal to 1*/
  20.     /*return 1 <==> specified means and correlations are feasible*/
  21.     return( all(Delta >= LBound) & all(Delta <= UBound) );
  22. finish;



  23. /*Objective: Find correlation, rho, that is zero of this function.
  24. Global variables:
  25. pj = prob of success for binary var Xj
  26. pk = prob of success for binary var Xk
  27. djk = target correlation between Xj and Xk */
  28. start MVBFunc(rho) global(pj, pk, djk);
  29. Phi = probbnrm(quantile("Normal",pj), quantile("Normal",pk), rho);
  30. qj = 1-pj; qk = 1-pk;
  31. return(Phi - pj*pk - djk*sqrt(pj*qj*pk*qk));
  32. finish;


  33. start bisection(a, b);
  34. dx = 1e-6; dy = 1e-4;
  35. do i = 1 to 100; /** max iterations **/
  36.    c = (a+b)/2;
  37.    if abs(MVBFunc(c)) < dy | (b-a)/2 < dx then
  38.       return(c);
  39.    if MVBFunc(a)#MVBFunc(c) > 0 then a = c;
  40.    else b = c;
  41. end;
  42. return (.); /** no convergence **/
  43. finish;


  44. start RandMVBinary(N, p, Delta) global(pj, pk, djk);

  45.     /*1. Check parameters. Compute lower/upper bounds for all (j,k)*/

  46.     if ^CheckMVBinaryParams(LBound, UBound, p, Delta) then do;
  47.         print "The specified correlation is invalid." LBound Delta UBound;
  48.         STOP;
  49.     end;
  50.     q = 1 - p;
  51.     d = ncol(Delta); /*number of variables*/

  52.     /*2. Construct intermediate correlation matrix by solving the
  53.     bivariate CDF (PROBBNRM) equation for each pair of vars */
  54.     R = I(d);
  55.     do j = 1 to d-1;
  56.     do k = j+1 to d;
  57.     pj=p[j]; pk=p[k]; djk = Delta[j,k]; /*set global vars*/
  58.     R[j,k] = bisection(LBound[j,k], UBound[j,k]);  /*pre-12.1, 9.3 SAS 需要运行这个*/
  59. /*    R[j,k] = froot("MVBFunc", LBound[j,k]||UBound[j,k]);*/
  60.     R[k,j] = R[j,k];
  61.     end;
  62.     end;

  63.     /*3: Generate MV normal with mean 0 and covariance R*/
  64.     X = RandNormal(N, j(1,d,0), R);                     

  65.     /*4: Obtain binary variable from normal quantile*/
  66.     do j = 1 to d;
  67.     X[,j] = (X[,j] <= quantile("Normal", p[j]));         /*convert to 0/1*/
  68.     end;
  69.     return (X);
  70. finish;


  71. call randseed(1234);
  72. p = {0.25 0.75 0.5};                     /*expected values of the X[j]*/
  73. Delta = {  1 -0.1 -0.25,
  74.                     -0.1 1 0.25,
  75.                     -0.25 0.25 1 };                /*correlations between the X[j]*/
  76. X = RandMVBinary(1000, p, Delta);        

  77. /*compare sample estimates to parameters*/
  78. mean = mean(X);
  79. corr = corr(X);
  80. print p, mean, Delta, corr[format=best6.];

  81. quit;
复制代码


二维码

扫码加我 拉你入群

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

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

关键词:运行出错 ROC correlations intermediate respectively 大学

SAS资源
1. SAS 微信:StatsThinking
2. SAS QQ群:348941365

沙发
wpfwxn 发表于 2015-3-8 13:27:58
我这里没有报错,64位

SAS (r) Proprietary Software 9.3 (TS1M2 DBCS3060)

藤椅
webgu 发表于 2015-3-8 15:07:26
SAS (r) Proprietary Software 9.3 (TS1M0 DBCS3060)

ERROR: (execution) Matrix has not been set to a value.

您需要登录后才可以回帖 登录 | 我要注册

本版微信群
加好友,备注cda
拉您进交流群
GMT+8, 2026-1-21 03:14