<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Implementation of Beta Regression in PROC GLIMMIX? in Statistical Procedures</title>
    <link>https://communities.sas.com/t5/Statistical-Procedures/Implementation-of-Beta-Regression-in-PROC-GLIMMIX/m-p/27659#M1047</link>
    <description>THANK YOU, Matt! That's exactly what I was looking for.&lt;BR /&gt;
&lt;BR /&gt;
Turns out that part of the problem was my dataset - I think one or two observations might have been off. Otherwise, the specific code, and the alternatives, work perfectly!&lt;BR /&gt;
&lt;BR /&gt;
Thanks again - the code you provided matches Cribari-Neto's and Ferrari's results exactly. : )</description>
    <pubDate>Tue, 08 Jun 2010 13:56:02 GMT</pubDate>
    <dc:creator>deleted_user</dc:creator>
    <dc:date>2010-06-08T13:56:02Z</dc:date>
    <item>
      <title>Implementation of Beta Regression in PROC GLIMMIX?</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/Implementation-of-Beta-Regression-in-PROC-GLIMMIX/m-p/27657#M1045</link>
      <description>Hello, everyone - &lt;BR /&gt;
&lt;BR /&gt;
I am trying to learn my way around PROC GLIMMIX specifically for the purposes of beta maximum-likelihood estimation. However, I have had some trouble refining my results, and I would be grateful if anyone on this board could help me out.&lt;BR /&gt;
&lt;BR /&gt;
Beta Regression in PROC GLIMMIX, as outlined in SAS's official procedure documentation &lt;A href="http://support.sas.com/rnd/app/papers/glimmix.pdf"&gt;here&lt;/A&gt;, is based on the seminal paper by Ferrari and Cribari-Neto (which can be accessed &lt;A href="http://www.ime.usp.br/~sferrari/beta.pdf"&gt;here&lt;/A&gt;). Refer to page 114 of the SAS document.&lt;BR /&gt;
&lt;BR /&gt;
In order to establish a rigorous foundation for application of the function, I am trying to reproduce Ferrari's and Cribari-Neto's results with the gasoline dataset (refer to page 12 of the authors' paper). Their results are as follows:&lt;BR /&gt;
&lt;BR /&gt;&lt;BR /&gt;
&lt;P&gt;&lt;BR /&gt;
proc glimmix data=db.prater order=formatted exphessian; &lt;BR /&gt;&lt;BR /&gt;
 class x3; &lt;BR /&gt;&lt;BR /&gt;
 model y = x3 x4 / dist=beta solution link=logit s; &lt;BR /&gt;&lt;BR /&gt;
 random _residual_; &lt;BR /&gt;&lt;BR /&gt;
 nloptions technique=quanew update=bfgs; &lt;BR /&gt;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;/P&gt;&lt;BR /&gt;
&lt;BR /&gt;&lt;BR /&gt;
I seem to have gotten similar parameter estimates as the authors, with very different standard errors. Also, the authors' scale parameter (phi) is VERY different (=440.27838, whereas the "scale" value given by GLIMMIX is equal to 164.66).&lt;BR /&gt;
&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;
Would anyone familiar with the implementation of beta regression in GLIMMIX and the Cribari/Ferrari framework be able to advise on whether the "scale" parameter is indeed equal to the authors' "phi"? I understand that this discrepancy might be attributable to other factors, but the model is supposed to be simple and the dataset small (32 observations). Therefore, I would expect that any discrepancies between my results and theirs shouldn't be that significant, especially considering that SAS asserts that PROC GLIMMIX's beta regression functionality is derived from the authors' methodology. I would be happy to share my dataset and SAS output with anyone that might be curious to help me with this.&lt;BR /&gt;
&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;
Thanks for taking the time to read my question!</description>
      <pubDate>Wed, 26 May 2010 15:28:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/Implementation-of-Beta-Regression-in-PROC-GLIMMIX/m-p/27657#M1045</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2010-05-26T15:28:33Z</dc:date>
    </item>
    <item>
      <title>Re: Implementation of Beta Regression in PROC GLIMMIX?</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/Implementation-of-Beta-Regression-in-PROC-GLIMMIX/m-p/27658#M1046</link>
      <description>Hi:&lt;BR /&gt;
&lt;BR /&gt;
Below are some of my code musing around Beta regression with Proc GLIMMIX and NLMIXED.  (Pls note I am passing along assistance getting started with this topic I got some time ago from the always helpful folk @ SAS tech support.)&lt;BR /&gt;
&lt;BR /&gt;
Best regards,&lt;BR /&gt;
-MattF&lt;BR /&gt;
&lt;BR /&gt;
/* prater.sas */&lt;BR /&gt;
&lt;BR /&gt;
/* Matt Flynn */&lt;BR /&gt;
/* adapted from: */                                        &lt;BR /&gt;
 /*-----------------------------------------------------------*/&lt;BR /&gt;
 /* Kathleen Kiernan                                          */&lt;BR /&gt;
 /* Technical Support Statistician                            */&lt;BR /&gt;
 /*---Prater's gasoline data. The data appear as data set    -*/&lt;BR /&gt;
 /*---number 135 in Hand, et al. (1994), "A Handbook of     --*/&lt;BR /&gt;
 /*---Small Data Sets", Chapman &amp;amp; Hall, New York.          ---*/&lt;BR /&gt;
 /*---                                                     ---*/&lt;BR /&gt;
 /*---The data are here arranged as in the paper by        ---*/&lt;BR /&gt;
 /*---Ferrari and Cribari-Neto (2004) to match the order    --*/&lt;BR /&gt;
 /*---of the parameter estimates in their Table 1.         ---*/&lt;BR /&gt;
 /*---The id variable groups the covariate patterns        ---*/&lt;BR /&gt;
 /*---with respect to x1-x3.                               ---*/&lt;BR /&gt;
 /*---                                                     ---*/&lt;BR /&gt;
 /*---The response is the gasoline yield percentage in     ---*/&lt;BR /&gt;
 /*---crude oil distillation. X1-X3 are properties of      ---*/&lt;BR /&gt;
 /*---the distillation.                                    ---*/&lt;BR /&gt;
 /*---The percentage is converted to a proportion in       ---*/&lt;BR /&gt;
 /*---the data step.                                       ---*/&lt;BR /&gt;
 /*---                                                     ---*/&lt;BR /&gt;
 /*---Reference:                                           ---*/&lt;BR /&gt;
 /*---Ferrari, S.L.P. and Cribari-Neto, F. (2004),         ---*/&lt;BR /&gt;
 /*--"Beta Regression for Modeling Rates and Proportions",    */&lt;BR /&gt;
 /*---Journal of Applied Statistics, 31:7:799--815         ---*/&lt;BR /&gt;
 /*-Prater, N.H., 1956. Estimate gasoline yields from crude. -*/&lt;BR /&gt;
 /*-Petroleum Refiner, 35, 236-238 										     ---*/&lt;BR /&gt;
 /*-----------------------------------------------------------*/&lt;BR /&gt;
ods pdf file='~/prater.pdf'  style=journal;&lt;BR /&gt;
&lt;BR /&gt;
data gas;&lt;BR /&gt;
  input id x1 x2 x3 x4 yieldpct;&lt;BR /&gt;
  x1a=(x1&amp;gt;=40);&lt;BR /&gt;
  prop = yieldpct/100;&lt;BR /&gt;
  prop2 = log(prop/(1 - prop));&lt;BR /&gt;
cards;&lt;BR /&gt;
 1     50.8     8.6  190  205    12.2 &lt;BR /&gt;
 1     50.8     8.6  190  275    22.3 &lt;BR /&gt;
 1     50.8     8.6  190  345    34.7 &lt;BR /&gt;
 1     50.8     8.6  190  407    45.7 &lt;BR /&gt;
 2     40.8     3.5  210  218     8.0 &lt;BR /&gt;
 2     40.8     3.5  210  273    13.1 &lt;BR /&gt;
 2     40.8     3.5  210  347    26.6 &lt;BR /&gt;
 3     40.0     6.1  217  212     7.4 &lt;BR /&gt;
 3     40.0     6.1  217  272    18.2 &lt;BR /&gt;
 3     40.0     6.1  217  340    30.4 &lt;BR /&gt;
 4     38.4     6.1  220  235     6.9 &lt;BR /&gt;
 4     38.4     6.1  220  300    15.2 &lt;BR /&gt;
 4     38.4     6.1  220  365    26.0 &lt;BR /&gt;
 4     38.4     6.1  220  410    33.6 &lt;BR /&gt;
 5     40.3     4.8  231  307    14.4 &lt;BR /&gt;
 5     40.3     4.8  231  367    26.8 &lt;BR /&gt;
 5     40.3     4.8  231  395    34.9 &lt;BR /&gt;
 6     32.2     5.2  236  267    10.0 &lt;BR /&gt;
 6     32.2     5.2  236  360    24.8 &lt;BR /&gt;
 6     32.2     5.2  236  402    31.7 &lt;BR /&gt;
 7     41.3     1.8  267  235     2.8 &lt;BR /&gt;
 7     41.3     1.8  267  275     6.4 &lt;BR /&gt;
 7     41.3     1.8  267  358    16.1 &lt;BR /&gt;
 7     41.3     1.8  267  416    27.8 &lt;BR /&gt;
 8     38.1     1.2  274  285     5.0 &lt;BR /&gt;
 8     38.1     1.2  274  365    17.6 &lt;BR /&gt;
 8     38.1     1.2  274  444    32.1 &lt;BR /&gt;
 9     32.2     2.4  284  351    14.0 &lt;BR /&gt;
 9     32.2     2.4  284  424    23.2 &lt;BR /&gt;
10     31.8     0.2  316  365     8.5 &lt;BR /&gt;
10     31.8     0.2  316  379    14.7 &lt;BR /&gt;
10     31.8     0.2  316  428    18.0 &lt;BR /&gt;
;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
proc print data=gas; &lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
proc means data=gas n min q1 mean median q3 max; &lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
proc means data=gas n mean var; &lt;BR /&gt;
	class x1;&lt;BR /&gt;
	var prop;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
/* get some stats, alpha, beta are method of moments estimates,&lt;BR /&gt;
 (:log_alpha, :log_beta can to be used for starting values for MLE )*/&lt;BR /&gt;
proc sql print; &lt;BR /&gt;
	select min(prop) as min,&lt;BR /&gt;
 	      mean(prop) as mean,&lt;BR /&gt;
		     var(prop) as var,&lt;BR /&gt;
	 	     max(prop) as max,&lt;BR /&gt;
		     min(prop) - 0.001*(calculated max - calculated min) as lower,&lt;BR /&gt;
		     max(prop) + 0.001*(calculated max - calculated min) as upper&lt;BR /&gt;
		                into :min, :mean, :var, :max, :lower, :upper&lt;BR /&gt;
					from gas;&lt;BR /&gt;
	select (mean(prop))*((mean(prop))*(1 - mean(prop))/ (var(prop)) - 1) as alpha,&lt;BR /&gt;
	   (1 - mean(prop))*((mean(prop))*(1 - mean(prop))/ (var(prop)) - 1) as beta,&lt;BR /&gt;
									     	       log(calculated alpha) as log_alpha,&lt;BR /&gt;
										           log(calculated beta) as log_beta&lt;BR /&gt;
				into :alpha, :beta, :log_alpha, :log_beta &lt;BR /&gt;
					from gas;&lt;BR /&gt;
quit;&lt;BR /&gt;
%put *** mean=&amp;amp;mean.;&lt;BR /&gt;
&lt;BR /&gt;
%let xvar=X1;&lt;BR /&gt;
proc sort data=gas;&lt;BR /&gt;
	by &amp;amp;xvar.;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
/* Levene's test for Homogeneity of variance */&lt;BR /&gt;
/* Proc GLIMMIX only models mean, mu of beta, check for does need sub-model for variance, */&lt;BR /&gt;
/* in this case, no, not needed. */&lt;BR /&gt;
&lt;BR /&gt;
ods graphics on;&lt;BR /&gt;
proc reg data=gas;&lt;BR /&gt;
	model prop = &amp;amp;xvar.; &lt;BR /&gt;
	model prop2 = &amp;amp;xvar.; &lt;BR /&gt;
	output out=out rstudent=rstudent predicted=predicted;&lt;BR /&gt;
run;&lt;BR /&gt;
quit;&lt;BR /&gt;
ods graphics off;&lt;BR /&gt;
&lt;BR /&gt;
goptions reset=all device=png;&lt;BR /&gt;
axis1 label=(angle=90 'Studentized Residual');&lt;BR /&gt;
symbol1 color=blue value=circle width=2;&lt;BR /&gt;
proc gplot data=out;&lt;BR /&gt;
	plot rstudent*predicted=1 / vaxis=axis1 vref=0 lvref=2;&lt;BR /&gt;
run;&lt;BR /&gt;
quit;&lt;BR /&gt;
&lt;BR /&gt;
ods select HOVFTest;&lt;BR /&gt;
ods output HOVFTest=hovftest;&lt;BR /&gt;
proc anova data=gas;&lt;BR /&gt;
	class &amp;amp;xvar.;&lt;BR /&gt;
	model prop = &amp;amp;xvar.;&lt;BR /&gt;
	means &amp;amp;xvar. / hovtest=Levene(type=square);  * also (type=abs);&lt;BR /&gt;
run;&lt;BR /&gt;
quit;&lt;BR /&gt;
&lt;BR /&gt;
symbol1 font=marker value=U color=salmon;&lt;BR /&gt;
proc boxplot data=gas;&lt;BR /&gt;
  plot prop*&amp;amp;xvar. /&lt;BR /&gt;
					boxstyle      = schematic&lt;BR /&gt;
				  	boxconnect    = mean&lt;BR /&gt;
					cboxes        = dagr&lt;BR /&gt;
					cboxfill      = ywh&lt;BR /&gt;
					cframe        = ligr   &lt;BR /&gt;
					idsymbol	  = star&lt;BR /&gt;
					lvref         = 3&lt;BR /&gt;
					nohlabel      &lt;BR /&gt;
					vref          = &amp;amp;mean.&lt;BR /&gt;
					symbollegend  = legend1&lt;BR /&gt;
					totpanels     = 1&lt;BR /&gt;
					vaxis         = 0 to 0.5 by 0.1;&lt;BR /&gt;
					legend1 &lt;BR /&gt;
					;&lt;BR /&gt;
  title font=simplex 'Prater Data';&lt;BR /&gt;
  title "Box-Plots of Prop by &amp;amp;xvar.";&lt;BR /&gt;
run;&lt;BR /&gt;
title; title2;&lt;BR /&gt;
&lt;BR /&gt;
ods output Moments=moments;&lt;BR /&gt;
ods output ParameterEstimates=parms_ab;&lt;BR /&gt;
ods output FitQuantiles=fitq;&lt;BR /&gt;
proc univariate data=gas;&lt;BR /&gt;
	var prop  ;&lt;BR /&gt;
	histogram   /&lt;BR /&gt;
			  		  beta(theta=0.0000001 scale=1.0000001 color=blue w=2)&lt;BR /&gt;
/*  		          beta(theta=0.002501 scale=0.535364 color=blue w=2)*/&lt;BR /&gt;
		   			  kernel(c=0.5 lower=0.0)&lt;BR /&gt;
                      cfill     = ywh&lt;BR /&gt;
	                  cframe    = ligr&lt;BR /&gt;
/*		              endpoints = &amp;amp;lower. to &amp;amp;upper. by 0.06 */&lt;BR /&gt;
/*		              endpoints = 0 to 0.5 by 0.075 */&lt;BR /&gt;
		              endpoints = 0 to 1 by 0.1 &lt;BR /&gt;
		              ;&lt;BR /&gt;
	inset Beta(alpha beta theta sigma) / position=ne;&lt;BR /&gt;
	qqplot  / beta(alpha=1.87 beta=3.2755 theta=.002501  sigma=.535364);&lt;BR /&gt;
title 'Prater Gas data';&lt;BR /&gt;
run;&lt;BR /&gt;
title;&lt;BR /&gt;
&lt;BR /&gt;
proc print data=moments;&lt;BR /&gt;
run;&lt;BR /&gt;
proc print data=parms_ab;&lt;BR /&gt;
run;&lt;BR /&gt;
data parms_ab(keep=Parameter Estimate);&lt;BR /&gt;
	set parms_ab;&lt;BR /&gt;
	if Symbol in ('Alpha','Beta') then Parameter=Symbol;&lt;BR /&gt;
	if Parameter in ('Alpha','Beta','Mean');&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
proc print data=parms_ab;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
*---------------------------------------------------;&lt;BR /&gt;
/* KDE - kernel density estimation                 */&lt;BR /&gt;
*---------------------------------------------------;&lt;BR /&gt;
ods graphics on;&lt;BR /&gt;
proc kde data=gas bwm=.45;&lt;BR /&gt;
  univar prop / plots=histdensity levels out=out;&lt;BR /&gt;
	title2 'Smooth Estimate using larger Bandwidth';&lt;BR /&gt;
run;&lt;BR /&gt;
ods graphics off;&lt;BR /&gt;
title2;&lt;BR /&gt;
&lt;BR /&gt;
/* Beta QQ Plot from Proc Univariate */&lt;BR /&gt;
proc print data=fitq;&lt;BR /&gt;
run;&lt;BR /&gt;
data fitq2;&lt;BR /&gt;
	set fitq(keep=ObsQuantile rename=ObsQuantile=Quantile);&lt;BR /&gt;
	dist='Observed';&lt;BR /&gt;
	n=_N_;&lt;BR /&gt;
	output;&lt;BR /&gt;
	set fitq(keep=EstQuantile rename=EstQuantile=Quantile);&lt;BR /&gt;
	dist='Beta';&lt;BR /&gt;
	n=_N_;&lt;BR /&gt;
	output;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
proc sort data=fitq2;&lt;BR /&gt;
	by descending dist;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
proc print data=fitq2;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
symbol1 l=1 value=square color=blue font=;&lt;BR /&gt;
symbol3 l=2 value=circle color=green font=;&lt;BR /&gt;
proc gplot data=fitq2;&lt;BR /&gt;
	plot n * Quantile = dist;&lt;BR /&gt;
run;&lt;BR /&gt;
quit;&lt;BR /&gt;
&lt;BR /&gt;
*---------------------------------------------------;&lt;BR /&gt;
/* KS - Kolmogorov-Smirnov - GOF test              */&lt;BR /&gt;
*---------------------------------------------------;&lt;BR /&gt;
ods output KolSmir2Stats=k;&lt;BR /&gt;
proc npar1way data=fitq2 wilcoxon median edf;&lt;BR /&gt;
	class dist;&lt;BR /&gt;
	var Quantile;&lt;BR /&gt;
run;&lt;BR /&gt;
proc print data=k;&lt;BR /&gt;
run;&lt;BR /&gt;
title;&lt;BR /&gt;
&lt;BR /&gt;
%put log_alpha=&amp;amp;log_alpha., log_beta=&amp;amp;log_beta.;&lt;BR /&gt;
&lt;BR /&gt;
/***************************************************************************/&lt;BR /&gt;
/* fit beta regression model via GLIMMIX                                    */&lt;BR /&gt;
/***************************************************************************/&lt;BR /&gt;
ods graphics on;&lt;BR /&gt;
*ods select LSMeans DiffPlot;&lt;BR /&gt;
ods output ParameterEstimates=parms;&lt;BR /&gt;
proc glimmix data=gas or plots=all;*noprofile plots=pearsonpanel;&lt;BR /&gt;
*	model prop =  / dist=beta s;&lt;BR /&gt;
	model prop = x1 x2 x3 x4 / dist=beta solution;&lt;BR /&gt;
	*output out=out predicted(ilink)=PredMu residual(ilink)=ResidMu;&lt;BR /&gt;
	output out=out / allstats;&lt;BR /&gt;
	*random _residual_;&lt;BR /&gt;
run;&lt;BR /&gt;
ods graphics off;&lt;BR /&gt;
&lt;BR /&gt;
data parms;&lt;BR /&gt;
	set parms;&lt;BR /&gt;
	if Effect='Intercept' then mu = 1/(1 + exp(-estimate));&lt;BR /&gt;
	if substr(Effect,1,1)='x' then odds_ratio=exp(estimate);&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
proc print data=parms;&lt;BR /&gt;
	format Estimate 10.6;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
/*proc print data=out;*/&lt;BR /&gt;
run;&lt;BR /&gt;
data parms;&lt;BR /&gt;
	set parms(keep=Effect Estimate);&lt;BR /&gt;
	if Effect='Intercept' then do;&lt;BR /&gt;
		mu = 1/(1 + exp(-estimate));	&lt;BR /&gt;
		Estimate1=Estimate;&lt;BR /&gt;
		retain Estimate1 mu;&lt;BR /&gt;
	end;&lt;BR /&gt;
	if effect='Scale' then do;&lt;BR /&gt;
		oneoverphi=1/estimate;&lt;BR /&gt;
		alpha=mu*estimate;&lt;BR /&gt;
		beta=(1 - mu)*estimate;&lt;BR /&gt;
		Estimate2=Estimate;&lt;BR /&gt;
	end;&lt;BR /&gt;
	rename Estimate=Scale;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
proc print data=parms(firstobs=2); &lt;BR /&gt;
	var Estimate1 Estimate2 mu Scale alpha beta one:;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
/***********************************************************************************************/&lt;BR /&gt;
/* fit beta model via NLMIXED                                                                  */&lt;BR /&gt;
/* &lt;A href="http://mathworld.wolfram.com/BetaDistribution.html" target="_blank"&gt;http://mathworld.wolfram.com/BetaDistribution.html&lt;/A&gt;                                          */&lt;BR /&gt;
/* &lt;A href="http://functions.wolfram.com/GammaBetaErf/" target="_blank"&gt;http://functions.wolfram.com/GammaBetaErf/&lt;/A&gt;                                                  */&lt;BR /&gt;
&lt;BR /&gt;
/* using starting values supplied from Proc UNIVARIATE; alpha, beta parameterization                                         &lt;BR /&gt;
 	f(y) = (gamma(alpha + beta)/((gamma(alpha)*gamma(beta)))*&lt;BR /&gt;
               ((y)**(alpha -  1))*((1 - y)**(beta - 1)))	  alpha&amp;gt;0, beta&amp;gt;0 for 0&lt;Y&gt;&amp;lt;1, Both&lt;BR /&gt;
   alpha and beta are shape parameters, alpha pulling density to zero, beta pulling towards 1  */ &lt;BR /&gt;
/* Smithson, Michael &amp;amp; Jay Verkuilen                                                           */&lt;BR /&gt;
/* Beta Regression: Practical Issues in Estimation, wp, Jan-05                                 */&lt;BR /&gt;
/* &lt;A href="http://www.anu.edu.au/psychology/people/smithson/details/betareg/Readme.pdf" target="_blank"&gt;http://www.anu.edu.au/psychology/people/smithson/details/betareg/Readme.pdf&lt;/A&gt;                 */&lt;BR /&gt;
/* recommends ...tech=quanew update=bfgs; with tech=truereg for hard problems                  */&lt;BR /&gt;
/***********************************************************************************************/&lt;BR /&gt;
proc nlmixed data=gas;* tech=quanew update=bfgs;&lt;BR /&gt;
*	parms / data=parms_ab(where=(Parameter in ('Alpha','Beta'))); 		* using starting values estimated above from Proc UNIVARIATE;&lt;BR /&gt;
	parms ba_0=&amp;amp;log_alpha. bb_0=&amp;amp;log_beta.; 		* using starting values estimated above from Proc SQL;&lt;BR /&gt;
	alpha = exp(ba_0);&lt;BR /&gt;
	beta = exp(bb_0);&lt;BR /&gt;
	y = prop;&lt;BR /&gt;
*	beta=1;															* power-function distribution;&lt;BR /&gt;
	     if alpha &amp;gt; 1  and beta &amp;gt; 1  then mode = (alpha - 1)/(alpha + beta - 2);&lt;BR /&gt;
	else if alpha &amp;lt; 1  and beta &amp;lt; 1  then mode = '0 and 1';&lt;BR /&gt;
	else if alpha &amp;lt; 1  and beta &amp;gt;= 1 then mode = 0;&lt;BR /&gt;
	else if alpha = 1  and beta &amp;gt; 1  then mode = 0;&lt;BR /&gt;
	else if alpha &amp;gt;= 1 and beta &amp;lt; 1  then mode = 1;&lt;BR /&gt;
	else if alpha &amp;gt; 1  and beta = 1  then mode = 1;&lt;BR /&gt;
	else if alpha = beta = 1         then mode = 'does not exist';&lt;BR /&gt;
					/* four ways - el mismo - all same */&lt;BR /&gt;
	prob = (gamma(alpha + beta)/((gamma(alpha)*gamma(beta)))*&lt;BR /&gt;
                  ((y)**(alpha -  1))*((1 - y)**(beta - 1)));	&lt;BR /&gt;
	loglike = log(prob);&lt;BR /&gt;
&lt;BR /&gt;
* 	loglike = lgamma(alpha + beta) - (lgamma(alpha) + lgamma(beta)) +&lt;BR /&gt;
               (alpha -  1)*log(y) + (beta - 1)*log(1 - y);&lt;BR /&gt;
&lt;BR /&gt;
*	loglike = log(pdf('BETA', y, alpha, beta));&lt;BR /&gt;
&lt;BR /&gt;
*	loglike = logpdf('BETA', y, alpha, beta); &lt;BR /&gt;
&lt;BR /&gt;
 	model y  ~ general(loglike);&lt;BR /&gt;
	estimate 'alpha'  exp(ba_0);&lt;BR /&gt;
	estimate 'beta'  exp(bb_0);&lt;BR /&gt;
	estimate 'E(prop)'   alpha/(alpha + beta);&lt;BR /&gt;
	estimate 'Var(prop)' alpha*beta/(((alpha + beta)**2)*(alpha + beta + 1));&lt;BR /&gt;
	estimate 'Var(prop)' alpha/(alpha + beta)*(1 - (alpha/(alpha + beta)))*(1/(alpha + beta + 1));&lt;BR /&gt;
	estimate 'Var(prop)' alpha*beta/((alpha + beta + 1)*(alpha + beta)**2);&lt;BR /&gt;
*	estimate 'Var(prop)' (1/((alpha + beta + 1))*mu*(1 - mu));&lt;BR /&gt;
	estimate 'Var(prop)' (1/((alpha + beta + 1))*(alpha/(alpha + beta))*(1-(alpha/(alpha + beta))));&lt;BR /&gt;
	estimate 'mode' mode;&lt;BR /&gt;
	estimate 'precision phi' 1/(alpha + beta + 1);&lt;BR /&gt;
	estimate 'dispersion 1/phi' (alpha + beta + 1);&lt;BR /&gt;
&lt;BR /&gt;
	title 'Beta model via Proc NLMIXED - Alpha,Beta Parameterization';&lt;BR /&gt;
run;&lt;BR /&gt;
title;&lt;BR /&gt;
&lt;BR /&gt;
/******************************************************************************/&lt;BR /&gt;
/* from betareg package in R                                                  */&lt;BR /&gt;
/* Alexandre de Bustamante Simas                                              */&lt;BR /&gt;
/* Version 1.1, June 27, 2005                                                 */&lt;BR /&gt;
/* Version 2.23, Apr 4, 2010                                                  */&lt;BR /&gt;
/* Achim Zeileis, Francisco Cribari-Neto                                      */&lt;BR /&gt;
/* &lt;A href="http://cran.r-project.org/" target="_blank"&gt;http://cran.r-project.org/&lt;/A&gt;                                                 */&lt;BR /&gt;
/*&lt;BR /&gt;
(Intercept)           V1           V2           V3           V4          phi  &lt;BR /&gt;
  -2.694897     0.004542     0.030415    -0.011044     0.010564   246.510503  &lt;BR /&gt;
*******************************************************************************/&lt;BR /&gt;
&lt;BR /&gt;
/******************************************************************************************/&lt;BR /&gt;
/* fit beta model via NLMIXED (mu, phi) parameterization                                  */&lt;BR /&gt;
/* Paolino, Phillip;	&lt;BR /&gt;
	 Maximum likelihood estimation of models with Beta-distributed dependent variables;&lt;BR /&gt;
	 Political Analysis,	2001,	v9,	n4,	p325-346,&lt;BR /&gt;
	 &lt;A href="http://polmeth.wustl.edu/polanalysis/vol9no4.html" target="_blank"&gt;http://polmeth.wustl.edu/polanalysis/vol9no4.html&lt;/A&gt;                                      */&lt;BR /&gt;
/******************************************************************************************/&lt;BR /&gt;
proc print data=gas(obs=5); run; &lt;BR /&gt;
ods output ParameterEstimates=parms;&lt;BR /&gt;
proc nlmixed data=gas;* cov ecov;		&lt;BR /&gt;
*		bounds 0 &amp;lt; mu &amp;lt; 1, phi &amp;gt; 0;&lt;BR /&gt;
  	mu = exp(eta)/(1 + exp(eta));			    	* logit inverse link function;	* logit link:  log(mu/(1 - mu);	&lt;BR /&gt;
 		* mu = 1/2 + atan(eta)/constant('pi');	* Cauchy cauchit link tan[constant('pi')*(mu – .5)];&lt;BR /&gt;
 		* mu = 1 - exp(-exp(1-eta));						* loglog link;&lt;BR /&gt;
 		*	mu = (1 - exp(-exp(eta)));						* cloglog link: log(-log(1 - mu));&lt;BR /&gt;
		*	mu = probnorm(eta);										* probit link: probit(mu);&lt;BR /&gt;
		y = prop;&lt;BR /&gt;
 	loglike = lgamma(phi) - (lgamma(mu*phi) + lgamma((1 - mu)*phi)) +&lt;BR /&gt;
                                 (mu*phi - 1)*log(y) + ((1 - mu)*phi - 1)*log(1 - y);&lt;BR /&gt;
	model y ~ general(loglike);&lt;BR /&gt;
	estimate 'mu' mu;&lt;BR /&gt;
	estimate 'precision phi' phi;&lt;BR /&gt;
	estimate 'dispersion 1/phi' 1/phi;&lt;BR /&gt;
	estimate 'var' mu*(1 - mu)/(1 + phi);&lt;BR /&gt;
	estimate 'alpha' mu*phi;&lt;BR /&gt;
	estimate 'beta' (1 - mu)*phi;&lt;BR /&gt;
/*	estimate 'var' alpha*beta/(((alpha + beta)**2)*(alpha + beta + 1));*/&lt;BR /&gt;
	estimate 'Var' (mu*phi)*((1 - mu)*phi)/((((mu*phi) + ((1 - mu)*phi))**2)*((mu*phi) + ((1 - mu)*phi) + 1));&lt;BR /&gt;
	estimate 'Var' (1/((mu*phi + (1 - mu)*phi + 1))*mu*(1 - mu));&lt;BR /&gt;
	estimate 'mode'   ((mu*phi)-1)/((mu*phi)+ ((1 - mu)*phi) - 2);&lt;BR /&gt;
	estimate 'p = mu*phi' mu*phi;			* mu = p/(p + q); &lt;BR /&gt;
	estimate 'q = phi - mu*phi' phi - mu*phi;	* phi =  p + q;&lt;BR /&gt;
	title 'Beta model via Proc NLMIXED (mu, phi) parameterization';&lt;BR /&gt;
run;&lt;BR /&gt;
title;&lt;BR /&gt;
&lt;BR /&gt;
proc nlmixed data=gas;* cov ecov;		&lt;BR /&gt;
	parms b0=-3 b1=0 b2=0. b3=0 b4=0 phi=246.51;&lt;BR /&gt;
	eta = b0 + b1*x1 + b2*x2 + b3*x3 + b4*x4;&lt;BR /&gt;
  	mu = exp(eta)/(1 + exp(eta));			    * logit inverse link function;		&lt;BR /&gt;
*	eta_phi = p0;* + p2*x2;						* can be gerneralized with parameters in the variance;&lt;BR /&gt;
												* see: Paolino (1999), also Smithson &amp;amp; Verkuilen (2005);&lt;BR /&gt;
 * 	phi = exp(eta_phi);							* log inverse link function;&lt;BR /&gt;
*	eta = b0;&lt;BR /&gt;
*  	mu = exp(eta);							* log inverse link function;&lt;BR /&gt;
	y = prop;&lt;BR /&gt;
* 	loglike = lgamma(phi) - (lgamma(mu*phi) + lgamma((1 - mu)*phi)) +&lt;BR /&gt;
                                 (mu*phi - 1)*log(y) + ((1 - mu)*phi - 1)*log(1 - y);&lt;BR /&gt;
&lt;BR /&gt;
	/* Smithson &amp;amp; Verkuilen (2005), "A Better Lemon Squeezer"*/&lt;BR /&gt;
	/* &lt;A href="http://www.anu.edu.au/psychology/people/smithson/details/betareg/SAS_beta_regression.sas" target="_blank"&gt;http://www.anu.edu.au/psychology/people/smithson/details/betareg/SAS_beta_regression.sas&lt;/A&gt; */&lt;BR /&gt;
	/*	 keep original alpha, beta formulation form of Beta density, tranlate mu, phi -&amp;gt; p &amp;amp; q */&lt;BR /&gt;
	p = mu*phi;			* mu = p/(p + q); &lt;BR /&gt;
	q = phi - mu*phi;	* phi =  p + q;&lt;BR /&gt;
	loglike = lgamma(p + q) - lgamma(p) - lgamma(q) + (p - 1)*log(y) + (q - 1)*log(1 - y);&lt;BR /&gt;
&lt;BR /&gt;
	model y ~ general(loglike);&lt;BR /&gt;
	estimate 'mu' mu;&lt;BR /&gt;
	estimate '1/phi' 1/phi;&lt;BR /&gt;
	estimate 'var' mu*(1 - mu)/(1 + phi);&lt;BR /&gt;
	estimate 'alpha' mu*phi;&lt;BR /&gt;
	estimate 'beta' (1 - mu)*phi;&lt;BR /&gt;
/*	estimate 'var' alpha*beta/(((alpha + beta)**2)*(alpha + beta + 1));*/&lt;BR /&gt;
	estimate 'Var' (mu*phi)*((1 - mu)*phi)/((((mu*phi) + ((1 - mu)*phi))**2)*((mu*phi) + ((1 - mu)*phi) + 1));&lt;BR /&gt;
	estimate 'Var' (1/((mu*phi + (1 - mu)*phi + 1))*mu*(1 - mu));&lt;BR /&gt;
	estimate 'mode'   ((mu*phi)-1)/((mu*phi)+ ((1 - mu)*phi) - 2);&lt;BR /&gt;
	estimate 'p' p;&lt;BR /&gt;
	estimate 'q' q;&lt;BR /&gt;
/*	estimate 'odds ratio - x1' exp(b1); */&lt;BR /&gt;
/*	estimate 'odds ratio - x2' exp(b2); */&lt;BR /&gt;
/*	estimate 'odds ratio - x3' exp(b3); */&lt;BR /&gt;
/*	estimate 'odds ratio - x4' exp(b4); */&lt;BR /&gt;
	title 'Beta model via Proc NLMIXED (mu, phi) parameterization';&lt;BR /&gt;
run;&lt;BR /&gt;
title;&lt;BR /&gt;
&lt;BR /&gt;
proc print data=parms double; &lt;BR /&gt;
	format estimate 12.6; &lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
data parms_ab;&lt;BR /&gt;
	set parms(keep=Parameter Estimate);&lt;BR /&gt;
	if Parameter='b0' then do;&lt;BR /&gt;
		mu = 1/(1 + exp(-Estimate));	&lt;BR /&gt;
		retain mu;&lt;BR /&gt;
	end;&lt;BR /&gt;
	if Parameter='phi' then do;&lt;BR /&gt;
		oneoverphi=1/Estimate;&lt;BR /&gt;
		alpha=mu*Estimate;&lt;BR /&gt;
		beta=(1 - mu)*Estimate;&lt;BR /&gt;
	end;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
proc print data=parms_ab(firstobs=2); &lt;BR /&gt;
	*&amp;amp;var mu estimate alpha beta one:;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
/* &lt;BR /&gt;
From Proc UNIVARIATE Online docs &lt;BR /&gt;
The beta distributions are also referred to as Pearson Type I or II distributions.&lt;BR /&gt;
These include the power-function distribution (\beta=1), the arc-sine distribution &lt;BR /&gt;
(\alpha =\beta =\frac{1}2), and the generalized arc-sine distributions (\alpha +\beta =1,&lt;BR /&gt;
\beta \neq \frac{1}2).&lt;BR /&gt;
*/&lt;BR /&gt;
&lt;BR /&gt;
ods pdf close;&lt;/Y&gt;</description>
      <pubDate>Wed, 26 May 2010 17:46:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/Implementation-of-Beta-Regression-in-PROC-GLIMMIX/m-p/27658#M1046</guid>
      <dc:creator>MattF</dc:creator>
      <dc:date>2010-05-26T17:46:50Z</dc:date>
    </item>
    <item>
      <title>Re: Implementation of Beta Regression in PROC GLIMMIX?</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/Implementation-of-Beta-Regression-in-PROC-GLIMMIX/m-p/27659#M1047</link>
      <description>THANK YOU, Matt! That's exactly what I was looking for.&lt;BR /&gt;
&lt;BR /&gt;
Turns out that part of the problem was my dataset - I think one or two observations might have been off. Otherwise, the specific code, and the alternatives, work perfectly!&lt;BR /&gt;
&lt;BR /&gt;
Thanks again - the code you provided matches Cribari-Neto's and Ferrari's results exactly. : )</description>
      <pubDate>Tue, 08 Jun 2010 13:56:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/Implementation-of-Beta-Regression-in-PROC-GLIMMIX/m-p/27659#M1047</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2010-06-08T13:56:02Z</dc:date>
    </item>
  </channel>
</rss>

