我試圖瞭解如何使用PROC HPGENSELECT
中的RESTRICT
語句擬合多項式邏輯模型。HPGENSELECT限制條款
我有一個分類變量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;
但是, t似乎限制了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/1('x1 1,x1 0 = 0'),您將看到另一個參數不會設置爲0. – DomPazz
我嘗試對數據集進行排序,並且它也以同樣的方式進行排序。不知道這個問題可能是...可能是一個錯誤? 4級會發生什麼? –
與第4級相同的行爲。可能只是提交給TS。 – DomPazz