BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Squibbles
Fluorite | Level 6

Hi All,

i'm not sure if this is possible, i've been searching for a while...

 

i need to get the coefficients, standard errors and Wald's confidence intervals for a continuous variable in Proc genmod.

 

I can get the co-efficient estimate for Age (BetaA), and i know i can multiply the coefficient by each age to get the coefficient for each age (i.e 33 * BetaA), however, i'm unsure on how to get the corresponding  Std. Error and Wald's confidence interval. 

 

Also, it would be really handy if I can SAS to output the range of Ages used in ProcGenmod and output the values into ParameterEstimates (similar to the way it outputs them for categorical variables) - which is what  i really want!

Many thanks

 

PROC GENMOD DATA = GLMDataset ;
		WEIGHT Quote. ;
		CLASS 	Gender /MISSING ;
		MODEL  PRICE = Gender Age  
			/DIST = Gamma.
			 LINK = LOG
			 TYPE1
			 TYPE3

			 ;
		OUTPUT 			OUT = GLMDatasetScored (keep = REFNO AVGPRICE PREMIUM: EST:. Gender Age )						
						PREDICTED	=	EST_AVGPRICE 
						LOWER		=	EST_LOWER_CI 
						UPPER 		=	EST_UPPER_CI
						RESDEV 	=	EST_DEVRES
						STDRESDEV	=	EST_STDDEVRES
						RESLIK 		=	EST_LIKLRES
						
						XBETA		=   EST_LINEARPREDICTOR					
						 ;
		ods output 	parameterestimates =  _ParamEst 
					modelfit = _Modelfit
					Type1 =  _Type1
					Type3 = _Type3;								
	RUN;

 

1 ACCEPTED SOLUTION

Accepted Solutions
JacobSimonsen
Barite | Level 11

An other solution is to use proc plm for calculating predictions for any values in some dataset. In my little example I make a dataset "template" which contains the values of covariates. In your example this dataset should just have one observation with age=23.

 

The output data will contain the linear predictor. So if you want it on the original scale, you should add to this example a step where you calculate exp(pred). Confidence limit can be transformed with exp() also, and if you want the stderr on the original scale you should use the delta-rule.

 

 

*simulate som data;
data mydata;
  do i=1 to 1000;
    gender=(i<=500);
	age=mod(i,100);
	y=rand('gamma',exp(0.4*gender+0.01*age));
    output;
  end;
run;

*estimate the parameters and save the model;
proc genmod data=mydata;
  class gender;
  model y=gender age/dist=gamma link=log;
  store mymodel;
run;

*constructing values of covariates for which we want predictions;
data template;
  do gender=0,1;
    do age=20 to 30;
	output;
    end;
  end;
run;

*calculate confidence intervals with proc plm;
proc plm restore=mymodel;
  score data=template out=predict lclm=lclm uclm=uclm stderr=stderr pred=pred;
run;

 

View solution in original post

4 REPLIES 4
StatDave
SAS Super FREQ

If you want the predicted mean for any given age in a given gender, that is in your OUTPUT OUT= data set.  Just find the observation with the given age and gender.  If what you want is a predicted mean for age averaged over the genders, then this would be something the LSMEANS statement would do for you if age were a CLASS (categorical) variable in the model.  Since it's not, you can use the ESTIMATE statement to compute an estimate similar to an LS-mean.  For example, assuming there are two genders and you want to treat them as having equal proportions in the population, then this statement would estimate the mean for age=20:

 

estimate 'age=20' intercept 1 gender .5 .5 age 20;

JacobSimonsen
Barite | Level 11

An other solution is to use proc plm for calculating predictions for any values in some dataset. In my little example I make a dataset "template" which contains the values of covariates. In your example this dataset should just have one observation with age=23.

 

The output data will contain the linear predictor. So if you want it on the original scale, you should add to this example a step where you calculate exp(pred). Confidence limit can be transformed with exp() also, and if you want the stderr on the original scale you should use the delta-rule.

 

 

*simulate som data;
data mydata;
  do i=1 to 1000;
    gender=(i<=500);
	age=mod(i,100);
	y=rand('gamma',exp(0.4*gender+0.01*age));
    output;
  end;
run;

*estimate the parameters and save the model;
proc genmod data=mydata;
  class gender;
  model y=gender age/dist=gamma link=log;
  store mymodel;
run;

*constructing values of covariates for which we want predictions;
data template;
  do gender=0,1;
    do age=20 to 30;
	output;
    end;
  end;
run;

*calculate confidence intervals with proc plm;
proc plm restore=mymodel;
  score data=template out=predict lclm=lclm uclm=uclm stderr=stderr pred=pred;
run;

 

Squibbles
Fluorite | Level 6

great thanks, plm should get to what i want. i'll look into LSMeans and Estimate, that might help with communicating results to a non-technical audience.

 

Thank you both 

StatDave
SAS Super FREQ

Like the OUTPUT statement that I suggested earlier, PLM's SCORE statement will give you predictions for specified gender and age (note that you can use the ILINK option in PLM to get the predictions on the mean scale instead of on the linear predictor scale). But, as I mentioned, if you want predictions for specified levels of age without specifying gender (essentially averaging over genders as determined by the coefficients specified), then the ESTIMATE statement approach for doing an LS-mean-like calculation is helpful.

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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
  • 4 replies
  • 5321 views
  • 11 likes
  • 3 in conversation