BookmarkSubscribeRSS Feed
rizayuli
Calcite | Level 5

Hello Please, I simulated the data below, ran NLMIXED but had execution error. Any correction. 

 

/* Step 1: Generate a data set that contains many samples */
%let N = 500; /* sample size */
%let NumSamples = 3; /* number of samples */
data a;
call streaminit(1234);
do SampleID=1 to &NumSamples; /* ID variable for each sample */
do i = 1 to &N;
x1 = ranuni(1234);
x2 = ranuni(1234);
x3 = rannor(1234);
theta = 1;
mu = exp(1 + .3*x1 + .3*x2);
parm1 = 1/(1+mu/theta);
yneg = rand('NEGB',parm1,theta);
pzero = cdf('LOGISTIC',x3*2);
if ranuni(1234)>pzero then do;
ynegzim = yneg;
end;
else do;
ynegzim = 0;
end;
y=ynegzim;
output ;
end ;
end;
keep SampleID i y x1 x2;
run;
proc means data=a qntldef=3 q3;
by SampleID; var y;
output out=c;
run;
proc print data=a;
run;
/* Step 2: Compute the hurdle of each sample */
data a;
set a;
bound=c;
if y > bound then y=bound+1;
proc nlmixed data=a TECH=NEWRAP;
by SampleID;
parms a0=0 a1=0 a2=0 b0=0 b1=0 b2=0 alpha=0.5;
bounds alpha>0;
lin = a0 + a1*x1 + a2*x2;
w = exp(lin) / (1+exp(lin));
eta = b0 + b1*x1 + b2*x2;
mu = exp(eta);
phi = 1/alpha;
pdf = (gamma(y+phi)/(gamma(y+1)*gamma(phi)))
*((1/(1+alpha*mu))**phi*(alpha*mu/(1+alpha*mu))**y);
l_1 = w;
l_2 = (1-w)*pdf/ (1-(1+alpha*mu)**(-phi));
cdf=0;
do t=1 to c;
cdf=cdf+((1-w)*((gamma(t+phi)/(gamma(t+1)*gamma(phi)))
*((1/(1+alpha*mu))**phi*(alpha*mu/(1+alpha*mu))**t)/(1-(1+alpha*mu)**(-phi))));
end;
l_3= 1-cdf;
if y = 0 then ll = log(l_1);
if 0 < y <= bound then ll = log(l_2);
if y <= bound then d=0; else d=1;
ll=(1-d)*ll+d*log(l_3);
model y~general(ll);
ods output FitStatistics=OutStats;
run;
proc print data=OutStats;
run;

2 REPLIES 2
Rick_SAS
SAS Super FREQ

I think you made a mistake in Step 2.  You wrote:

 

/* Step 2: Compute the hurdle of each sample */
data a;
set a;
bound=c;
if y > bound then y=bound+1;
run;

 

However, there is no variable in data set A that is named c.  Therefore this DATA step results in assigning y=. (missing value) for all observations.

 

rizayuli
Calcite | Level 5
c as bound (censored point), c value is third quartile every number iD. can you help me to fix my syntax sas.

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

What is ANOVA?

ANOVA, or Analysis Of Variance, is used to compare the averages or means of two or more populations to better understand how they differ. Watch this tutorial for more.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 2 replies
  • 2731 views
  • 0 likes
  • 2 in conversation