This program illustrates the use of the GENMOD procedure to analyze data following a Tweedie distribution. First, it simulates a dataset of 250 observations via a DATA step, constructing the response variable as a Poisson sum of Gamma variables (mathematical representation of the Tweedie distribution). Then, it fits two models: the first estimates parameters with the default Tweedie distribution, and the second fixes the power parameter p to 1.5.
Data Analysis
Type : CREATION_INTERNE
Data is entirely generated in the 'tmp1' DATA step using random functions (ranuni, ranpoi, rangam) based on parameters defined by macro variables.
1 Code Block
DATA STEP Data
Explanation : Initialization of configuration macro-variables. Creation of the 'tmp1' table containing categorical (c1-c5) and continuous (d1, d2) explanatory variables, as well as a target variable 'yTweedie' simulated according to a compound Poisson-Gamma process.
Copied!
%let nObs = 250;
%let nClass = 5;
%let nLevs = 4;
%let seed = 100;
data tmp1;
array c{&nClass};
keep c1-c&nClass yTweedie d1 d2;
/* Tweedie parms */
phi=0.5;
p=1.5;
do i=1 to &nObs;
do j=1 to &nClass;
c{j} = int(ranuni(1)*&nLevs);
end;
d1 = ranuni(&seed);
d2 = ranuni(&seed);
xBeta = 0.5*((c2<2) - 2*(c1=1) + 0.5*c&nClass + 0.05*d1);
mu = exp(xBeta);
/* Poisson distributions parms */
lambda = mu**(2-p)/(phi*(2-p));
/* Gamma distribution parms */
alpha = (2-p)/(p-1);
gamma = phi*(p-1)*(mu**(p-1));
rpoi = ranpoi(&seed,lambda);
if rpoi=0 then yTweedie=0;
else do;
yTweedie=0;
do j=1 to rpoi;
yTweedie = yTweedie + rangam(&seed,alpha);
end;
yTweedie = yTweedie * gamma;
end;
output;
end;
run;
Explanation : Execution of the GENMOD procedure to fit a generalized linear model on the simulated data, specifying a Tweedie distribution. The type3 option requests type 3 statistics.
Copied!
proc genmod data=tmp1;
class C1-C5;
model yTweedie = C1-C5 D1 D2 / dist=Tweedie type3;
run;
1
PROC GENMODDATA=tmp1;
2
class C1-C5;
3
model yTweedie = C1-C5 D1 D2 / dist=Tweedie type3;
4
RUN;
3 Code Block
PROC GENMOD
Explanation : Second execution of PROC GENMOD with a simplified model (fewer explanatory variables) and explicitly setting the Tweedie distribution's power parameter to 1.5.
Copied!
proc genmod data=tmp1;
class C1 C2;
model yTweedie = C1 C2 D1 / dist=Tweedie(p=1.5) type3;
run;
1
PROC GENMODDATA=tmp1;
2
class C1 C2;
3
model yTweedie = C1 C2 D1 / dist=Tweedie(p=1.5) type3;
4
RUN;
This material is provided "as is" by We Are Cas. There are no warranties, expressed or implied, as to merchantability or fitness for a particular purpose regarding the materials or code contained herein. We Are Cas is not responsible for errors in this material as it now exists or will exist, nor does We Are Cas provide technical support for it.
SAS and all other SAS Institute Inc. product or service names are registered trademarks or trademarks of SAS Institute Inc. in the USA and other countries. ® indicates USA registration. WeAreCAS is an independent community site and is not affiliated with SAS Institute Inc.
This site uses technical and analytical cookies to improve your experience.
Read more.