shiyc2010 发表于 2010-10-20 13:02
我进行逻辑回归时想分别加入三个虚拟变量,应该怎么加?谢谢指教
In many SAS procedures, you may define them as a class variables.
Here is an example.
data tmp;
do i=1 to 200;
if mod(i,3) =0 then cat='a';
else if mod(i,3) =1 then cat='b';
else cat='c';
x=rannor(99);
y=1+ ( cat='a' ) * 1 + ( cat='b' ) *-1+( cat='c' ) * 0 + 1*x > rannor(99);
output;
end;
run;
proc logistic data=tmp;
class cat /param=glm;
model y (event='1') = cat x/link=probit;
run;
*****************************
The SAS System 20:39 Wednesday, October 20, 2010 1
The LOGISTIC Procedure
Model Information
Data Set WORK.TMP
Response Variable y
Number of Response Levels 2
Model binary probit
Optimization Technique Fisher's scoring
Number of Observations Read 200
Number of Observations Used 200
Response Profile
Ordered Total
Value y Frequency
1 0 56
2 1 144
Probability modeled is y=1.
Class Level Information
Class Value Design Variables
cat a 1 0 0
b 0 1 0
c 0 0 1
Model Convergence Status
Convergence criterion (GCONV=1E-8) satisfied.
Model Fit Statistics
Intercept
Intercept and
Criterion Only Covariates
AIC 239.181 149.280
SC 242.480 162.474
-2 Log L 237.181 141.280
The SAS System 20:39 Wednesday, October 20, 2010 2
The LOGISTIC Procedure
Testing Global Null Hypothesis: BETA=0
Test Chi-Square DF Pr > ChiSq
Likelihood Ratio 95.9009 3 <.0001
Score 73.9988 3 <.0001
Wald 53.4961 3 <.0001
Type 3 Analysis of Effects
Wald
Effect DF Chi-Square Pr > ChiSq
cat 2 34.6958 <.0001
x 1 40.7798 <.0001
Analysis of Maximum Likelihood Estimates
Standard Wald
Parameter DF Estimate Error Chi-Square Pr > ChiSq
Intercept 1 1.0395 0.2123 23.9756 <.0001
cat a 1 0.9981 0.3593 7.7172 0.0055
cat b 1 -1.1190 0.2819 15.7598 <.0001
cat c 0 0 . . .
x 1 1.1290 0.1768 40.7798 <.0001
Association of Predicted Probabilities and Observed Responses
Percent Concordant 89.7 Somers' D 0.794
Percent Discordant 10.3 Gamma 0.795
Percent Tied 0.1 Tau-a 0.322
Pairs 8064 c 0.897