I don't have a macro, but here is some code for the beta. The first program works with the mu/phi parameterization of the beta. It assumes the proportion data is in a variable x. The parameter estimates of mu and phi (if ep=0 and lam=1) are equivalent to the intercept and scale parameters obtained from GLIMMIX.
MY CODE GOT MESSED UP WHEN PASTING. DON'T USE THIS CODE. SEE MY SUBSEQUENT
MESSAGES...
proc nlmixed data=sbdata ;
title2 'MLE of beta (NLMIXED), MU version, epsilon=0, lambda=1 ';
parms mu = .3, phi = 15;
ep=0; lam=1 ; *<--ep is the lower bound parameter, and lam is upper bound param.;
bounds mu > 0; bounds phi > 0;
be=gamma(((mu-ep)/lam)*phi)*gamma(((lam+ep-mu)/lam)*phi)/gamma(phi);
be_dens=( ((x-ep)**(((mu-ep)/lam)*phi -1)) * ((lam+ep-x)**(((lam+ep-mu)/lam)*phi -1) )) /
(be*lam**(phi-1));
loglik=log(be_dens);
model x~general(loglik);
estimate 'alpha' (mu-ep)*phi/lam; *<--to get the conventional alpha/beta parameters;
estimate 'beta'(lam+ep-mu)*phi/lam;
estimate 'logit' log( (mu-ep)/(lam+ep - mu) ); *--Estimated logit assuming general ep & lam;
estimate 'variance' lam*(mu-ep)*(lam+ep-mu)/(lam*(1+phi));
estimate 'median' betainv(0.5,(mu-ep)*phi/lam, (lam+ep-mu)*phi/lam)*lam + ep;
run;
*--Use of GLIMMIX to fit. To have epsilon=0 and lambda=1, must use x variable (x);
proc glimmix data=sbdata;
title2 'Beta, using pseudo-likelihood(GLIMMIX), epsilon=0 & lambda=1, IDentity link';
model x = / dist=beta link=id solution;
run;
Now for a logit link and two predictor variables (x1 and x2).
proc nlmixed data=two ;
title2 'MLE of Beta, using NLMIXED, done in terms of logit link';
title3 'Used epsilon=0 and lambda=1. This is a regression-type problem';
parms a=-2.1 b1=.011 b2 = .1
phi = 2 to 60 by 2;
ep=0.0; lam=1.0 ; *<--For these data, use epsilon=0 and lambda=1;
bounds phi > 0;
m = a + b1*x1 + b2*x2; *<--This is logit;
mu=ep + lam*(1/(1+exp(-m))); *<--Inverse link to get expected (mu);
lbe=lgamma(((mu-ep)/lam)*phi) + lgamma(((lam+ep-mu)/lam)*phi) - lgamma(phi);
lbed1 = (((mu-ep)/lam)*phi -1) * log(x-ep) ;
lbed2 = (((lam+ep-mu)/lam)*phi -1) * log(lam+ep-x);
lbed3= (phi-1)*log(lam) + lbe;
*be_dens= ( ((x-ep)**(((mu-ep)/lam)*phi -1)) * ((lam+ep-x)**(((lam+ep-mu)/lam)*phi -1) )) / (be*lam**(phi-1));
loglik=lbed1 + lbed2 - lbed3;
model x~general(loglik);
predict m out=outp; *<--Put logits in a file;
run;
proc glimmix data=two;
title2 'GLMM fitting of beta to Griffiths data (GLIMMIX), logits';
model x = x1 x2 / dist=beta link=logit solution ; *<--Note the logit link here;
run;
MY CODE GOT MESSED UP WHEN PASTED. SEE MY SUBSEQUENT MESSAGES FOR PROPER CODE.
Message was edited by: lvm
Message was edited by: lvm
Message was edited by: lvm
... View more