阅读权限 255 威望 3 级论坛币 10965 个 通用积分 5.0866 学术水平 452 点 热心指数 463 点 信用等级 347 点 经验 76409 点 帖子 1937 精华 1 在线时间 3428 小时 注册时间 2009-5-22 最后登录 2020-1-26
Referring to Wicklin's "simulating data with sas" and the Fleishman's paper about cubic transformation method in Psychometrika(1978), i am mainly programing in FCMP, with the help pf Macro facility.
The partial code in FCMP is as below.
In this case, my macro can be called as: Simu_Skew_Kurt(,2 3 4 5,,,100);
let me know if anything wrong.
More Details can be seen in my blog at
http://blog.sina.com.cn/s/blog_a3a926360101f6us.html
proc fcmp;
%* input coefficients and output targeted moments: variance, skewness, kurtosis;
subroutine Fleishman(c[*], x[*]) varargs; outargs x;
x[1] = (c[1]**2) + 6*(c[1]*c[3]) + 2*(c[2]**2) + 15*(c[3]**2); /* variance */
x[2] = 2*c[2]*((c[1]**2) + 24*(c[1]*c[3]) + 105*(c[3]**2) + 2); /* skewness */
x[3] = 24*((c[1]*c[3])+(c[2]**2)*(1+(c[1]**2)+28*(c[1]*c[3]))+(c[3]**2)*(12+48*(c[1]*c[3])+141*(c[2]**2)+225*(c[3]**2))); /* excess kurtosis */
endsub;
%* input coefficient and output J matrix of Jacobian;
subroutine FlDeriv(x[*],J[3,3]) varargs; outargs J;
J[1,1] = 2*x[1] + 6*x[3];
J[1,2] = 4*x[2];
J[1,3] = 6*x[1] + 30*x[3];
J[2,1] = 4*x[2]*(x[1] + 12*x[3]);
J[2,2] = 2*((x[1]**2) + 24*(x[1]*x[3]) + 105*(x[3]**2) + 2);
J[2,3] = 4*x[2]*(12*x[1] + 105*x[3]);
J[3,1] = 24*(x[3] + (x[2]**2)*(2*x[1] + 28*x[3]) + 48*x[3]**3);
J[3,2] = 48*x[2]*(1 + (x[1]**2) + 28*(x[1]*x[3]) + 141*(x[3]**2));
J[3,3] = 24*(x[1]+28*x[1]*(x[2]**2)+2*x[3]*(12+48*(x[1]*x[3])+141*(x[2]**2)+225*(x[3]**2))+(x[3]**2)*(48*x[1]+450*x[3]));
endsub;
%* Iterations of Newton algorithm to resolve cubic coefficients;
array cf[1,4]/nosymbols;
rc =read_array('work.moments4',cf);
array tr[3];
%* Assign Targeted moments parameters;
array ti[3] (1 . .); ti[2] =cf[1,3]; ti[3] =cf[1,4];
%* Fleishman coefficients with an initial guess by a polynomial regression;
array x[3];
x[1] = 0.95357 -0.05679*ti[3] +0.03520*ti[2]**2 +0.00133*ti[3]**2 ;
x[2] = 0.10007*ti[2] +0.00844*ti[2]**3 ;
x[3] = 0.30978 -0.31655*x[1] ;
array J[3,3] ; %*Jacobian matrix;
array re[3,3] ; %*Intermediate results;
array f[3] ; %*Objective function;
array ep[3] ; %*Error updates;
maxIter =&maxIter.; absConv =&absConv.;
%* Initialize f- objective function;
call Fleishman(x,tr);
call subtractMatrix(tr, ti, f);
mf =absConv +1;
do iter =1 to maxIter by 1 while(mf >absConv);
%* Solve error function;
call FlDeriv(x, J);
call inv(J, re);
call mult(re,f, ep);
call mult(ep, -1, ep);
%* Updating coefficients x;
call addMatrix(x, ep, x);
%* Updating objection fucntion f;
call Fleishman(x,tr);
call SubtractMatrix(tr,ti, f);
%* Check error in Error allowance;
mf =0;
do i =1 to 3;
if abs(f[i])>mf then mf =abs(f[i]);
end;
end;
%* Set status variable for if converging;
call symputx('status', catx(' ', 'Converge in iterations of', iter-1));
if mf > absConv then do;
put "!!!!NOT converge in maximum iterations of" maxIter;
call symputx('status', catx(' ', 'Not Coverge in iterations of', iter-1));
end;
%* output solved Fleiman coefficients;
rc =write_array('work.Fleishman_cubic_coeffs',x);
run; 复制代码 Jingju
已有 1 人评分 经验
论坛币
学术水平
热心指数
信用等级
收起
理由
webgu
+ 100
+ 100
+ 5
+ 5
+ 5
无以言加的佩服!!!!
总评分: 经验 + 100
论坛币 + 100
学术水平 + 5
热心指数 + 5
信用等级 + 5
查看全部评分