Created
September 29, 2021 18:58
-
-
Save MJacobs1985/5c24ce6b80930bd51d63a59e2f056183 to your computer and use it in GitHub Desktop.
Simulations in SAS
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Tabulate counts and plot data */ | |
%let N=150; | |
data CountData; | |
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 , 0.5); | |
end; | |
/*Simulate POISSON Model */ | |
do i=1 to &N; | |
x1=xx1{i}; | |
x2=xx2{i}; | |
/*linear model with the following parameters --> intercept = 2 / x1 = -4 / x2 = 1 */ | |
eta=1-1*x1+1*x2; /* linear predictor */ | |
mu=exp(eta); /* link function used to connect eta (linear predictor) to the response variable via simulation*/ | |
count=rand("Poisson", mu); | |
output;end;run; | |
proc freq data=CountData noprint;tables count / out=CountMinMax;run; | |
data _null_;set CountMinMax end=eof; | |
if _N_=1 then call symputx('minCount', count); | |
if eof then call symputx('maxCount', count); | |
run; | |
%put min=&minCount max=&maxCount; | |
/* Visualize the data */ | |
title 'Frequency Plot of Count Dataset'; | |
proc sgplot data=CountData; | |
vbar count; | |
xaxis display=(nolabel); | |
yaxis display=(nolabel); | |
run; | |
title; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment