Skip to content

Instantly share code, notes, and snippets.

@MJacobs1985
Created September 29, 2021 19:02
Show Gist options
  • Save MJacobs1985/b884450fe20f879f8324503879c28ef9 to your computer and use it in GitHub Desktop.
Save MJacobs1985/b884450fe20f879f8324503879c28ef9 to your computer and use it in GitHub Desktop.
Simulations in SAS
/** Simulate binomial data, then analyze it it with Logistic Regression **/
/* Simulate dataset */
%let N=150;
data LogisticData;
array xx1{&N} _temporary_;
array xx2{&N} _temporary_;
call streaminit(1);
/* simulate fixed effects */
do i=1 to &N;
xx1{i}=rand("Uniform");
xx2{i}=rand("Normal", 0 , 2);
end;
/*Simulate Logistic Model */
do i=1 to &N;
x1=xx1{i};
x2=xx2{i};
eta=2-4*x1+1*x2;
mu=exp(eta)/(1+exp(eta));
y=rand("Bernoulli", mu);
output;
end;
run;
/* median probability across probabilities */
proc means data=logisticdata median;
var mu;
run;
proc freq data=logisticdata;
table y / plots=FreqPlot(scale=percent);
run;
proc logistic data=logisticdata plots=all;
model y(Event='1')=x1 x2 / aggregate=x1 scale=none influence;
output out=logistic_out xbeta=xbeta;
ods output Influence=Logistic_Influence;
run;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment