我试图了解如何在RESTRICT
中使用PROC HPGENSELECT
语句来拟合多项logit模型。
我有一个分类变量evt_type
,它取3个值(0,1,2)。我有2个连续的回归变量x1
和x2
。我想将x1
上evt_type=2
的参数限制为0。
没有约束的装配:
proc hpgenselect data=to_reg;
class evt_type;
model evt_type(ref='0') = x1 x2 / link=glogit;
run;
给我:
Parameter Estimates
Standard
Parameter evt_type DF Estimate Error Chi-Square Pr > ChiSq
Intercept 1 1 -0.092251 0.109479 0.7100 0.3994
Intercept 2 1 -0.181718 0.119293 2.3204 0.1277
x1 1 1 0.875623 0.097909 79.9807 <.0001
x1 2 1 -0.017942 0.110512 0.0264 0.8710
x2 1 1 -0.220358 0.113552 3.7659 0.0523
x2 2 1 2.902520 0.199583 211.4960 <.0001
尝试使用基于文档的限制,它似乎是:
proc hpgenselect data=to_reg;
class evt_type;
model evt_type(ref='0') = x1 x2 / link=glogit;
restrict x1 0, x1 1 = 0;
run;
然而,这似乎限制了evt_type=1
上的参数。我做错了什么:
Parameter Estimates
Standard
Parameter evt_type DF Estimate Error Chi-Square Pr > ChiSq
Intercept 1 1 0.028338 0.100646 0.0793 0.7783
Intercept 2 1 -0.202028 0.117543 2.9541 0.0857
x1 1 0 0 . . .
x1 2 1 -0.423127 0.099020 18.2597 <.0001
x2 1 1 -0.159225 0.104655 2.3147 0.1282
x2 2 1 2.914689 0.199375 213.7191 <.0001
使用以下内容生成样本数据
%macro generate_sample(seed);
proc iml;
n=1000;
call randseed(&seed);
cov = {1 .0, .0 1};
x = randnormal(n,{0,0},cov);
c0 = {0, 0};
c1 = {1, 0};
c2 = {0, 3};
vProb = exp(x*c0) || exp(x*c1) || exp(x*c2);
vProb = vProb/ vProb[,+];
NumTrials = 1;
events = J(n,3,0);
do i=1 to n;
prob = vProb[i,];
events[i,] = RandMultinomial(1,1,prob);
end;
out = events || x;
create events from out[colname={'e0','e1','e2','x1', 'x2'}];
append from out;
close events;
out = vProb || x;
create true_prob from out[colname={"P_0","P_1","P_2",'x1', 'x2'}];
append from out;
close true_prob;
quit;
data to_reg;
format evt_type $1.;
set events;
array e[3] e0-e2;
do i=0 to 2;
if e[i+1] then do;
evt_type = put(i,1.);
leave;
end;
end;
drop i e0-e2;
run;
%mend;
%generate_sample(2);
答案 0 :(得分:2)
与SAS技术支持部门合作。似乎问题出在ref='0'
声明中。将模型排序从ref='0'
更改为descending
似乎可以使事情有效。
这失败了:
proc hpgenselect data=to_reg ;
model evt_type(ref='0')= x1 x2 / link=glogit dist=multinomial;
restrict x1 1 , x1 0 =0;
restrict x2 0 , x2 1 =0;
run;
虽然这有效:
proc hpgenselect data=to_reg ;
model evt_type(descending)= x1 x2 / link=glogit dist=multinomial;
restrict x1 1 , x1 0 =0;
restrict x2 0 , x2 1 =0;
run;
答案 1 :(得分:0)
这似乎与SAS在使用class
语句时内部命令的方式有关。如果您设置了类选项order = data
,则会适当地应用限制。
proc hpgenselect data=to_reg;
class evt_type / order=data;
model evt_type(ref='0') = x1 x2 / link=glogit;
restrict x1 0, x1 1 = 0;
run;