BookmarkSubscribeRSS Feed
rshaw1
Calcite | Level 5

I am trying to calculate confidence intervals for a parameter estimate generated by proc nlmixed using the likelihood profile method.  The CIs that are currently calculated do not appear to use the likelihood profile method.  Is there a way to get proc nlmixed to do this?

Here is my code:

/*create data table that includes Q*/

PROC SQL;

   CREATE TABLE WORK.SEIDMANETAL1986_Q AS

   SELECT t1.TSFE_yrs_Range,

          t1.TSFE_yrs_Avg,

          t1.duration,

          t1.conc,

          t1.PY,

          t1.'Obs'n,

          /* Q */

            (case

            when t1.TSFE_yrs_Avg=. then .

            when t1.TSFE_yrs_Avg<10 then 0

            when t1.TSFE_yrs_Avg>(10+t1.duration) then (t1.TSFE_yrs_Avg-10)**3-(t1.TSFE_yrs_Avg-10-t1.duration)**3

            else (t1.TSFE_yrs_Avg-10)**3

            end) AS Q

      FROM '\\Esc-server1\home\rshaw\EH027\seidmanetal1986.sas7bdat' t1;

run;

 

/*model*/

proc nlmixed data=WORK.SEIDMANETAL1986_Q;

parms KM 1e-08; /*starting value*/

pred = conc*KM*Q*PY;

ll=LogPDF("POISSON",Obs,Pred); /*LofPDF function Returns the logarithm of a probability density (mass) function. Poisson distribution is specified.*/

model Obs ~ general(ll);

predict pred out=model1; /*generates table with predicted values and CI’s titled “Model1”*/

run;

 

 

 

Here is what the parameter estimates table that proc nlmixed generates looks like:

Parameter EstimatesParameter Estimate StandardError DF t Value Pr > |t| 95% Confidence Limits Gradient
KM3.946E-807Infty<.0001-InftyInfty-10.3456
6 REPLIES 6
Rick_SAS
SAS Super FREQ

Check the log and your data.

  • It's hard to read your output, but is that StdErr = 0? If so, your data is constant.
  • Your output shows that the gradient is not zero at the solution that you post. Therefore either the algorithm did not converge or the procedure stopped for some other reason (bad data?)

 

It would be helpful if you could post a PROC PRINT of the first 10 observations we can see what the data look like.

 

 

rshaw1
Calcite | Level 5

Thank you.  I believe it did converge - the following note was included in the output:

NOTE: GCONV convergence criterion satisfied.

 

 It's a very small data set:

Obs TSFE_yrs_Range TSFE_yrs_Avg duration conc PY Obs
15-107.51.546.939520
210-1512.51.548.336280
315-1917.51.544.131980
420-2522.51.543.226562
525-3027.51.540.320945
630-3532.51.533.515768
735-4037.51.531.110862
Rick_SAS
SAS Super FREQ

Is that the data being sent to PROC NLMIXED? It doesn't contain Q.

 

Anyway, you might try rescaling these data. Intuitively, if you define x = conc*Q*PY, then x is large ... roughly 1E8. In order to model Obs (which is in the range 0-8), by the mean of a Poisson(KM*x) distribution, the product must be about 2, which means that KM is approx 1E-8. This estimate is so small that it is  the same order as the convergence criteria for the optimization.

 

Try dividing x by 1E6, such as follows:

 

data have;
length TSFE_yrs_Range $5;
input TSFE_yrs_Range TSFE_yrs_Avg duration conc PY Obs ;
if      TSFE_yrs_Avg=. then Q = .;
else if TSFE_yrs_Avg<10 then Q = 0;
else if TSFE_yrs_Avg>(10+duration) then 
   Q = (TSFE_yrs_Avg-10)**3-(TSFE_yrs_Avg-10-duration)**3;
else Q =(TSFE_yrs_Avg-10)**3;
x = conc*Q*PY / 1e6;
   datalines;
 5-10  7.5 1.5 46.9 3952 0
10-15 12.5 1.5 48.3 3628 0
15-19 17.5 1.5 44.1 3198 0
20-25 22.5 1.5 43.2 2656 2
25-30 27.5 1.5 40.3 2094 5
30-35 32.5 1.5 33.5 1576 8
35-40 37.5 1.5 31.1 1086 2
;

proc means data=Have; var x; run;

proc nlmixed data=have;
parms KM 1e-2; /*starting value*/
pred = KM*x;
ll=LogPDF("POISSON",Obs,Pred); /*LofPDF function Returns the logarithm of a probability density (mass) function. Poisson distribution is specified.*/
model Obs ~ general(ll);
predict pred out=model1; /*generates table with predicted values and CI’s titled “Model1”*/
run;

 

 

rshaw1
Calcite | Level 5

Thanks Rick. 

 

Q is generated before proc nlmixed, see below code.

 

My goal is to generate confidence bounds for the KM parameter using the likelihood profile method.  How does what you propose doing accomplish that?

 

Thank you,

Rebekha

 

/*calculate Q*/

proc print data='\\Esc-server1\home\rshaw\EH027\seidmanetal1986.sas7bdat';

run;

PROC SQL;

CREATE TABLE WORK.SEIDMANETAL1986_Q AS

SELECT t1.TSFE_yrs_Range,

 

t1.TSFE_yrs_Avg,

t1.duration,

t1.conc,

t1.PY,

t1.'Obs'n,

/* Q */

(case

when t1.TSFE_yrs_Avg=. then .

when t1.TSFE_yrs_Avg<10 then 0

when t1.TSFE_yrs_Avg>(10+t1.duration) then (t1.TSFE_yrs_Avg-10)**3-(t1.TSFE_yrs_Avg-10-t1.duration)**3

else (t1.TSFE_yrs_Avg-10)**3

end) AS Q

FROM '\\Esc-server1\home\rshaw\EH027\seidmanetal1986.sas7bdat' t1;

run;

 

 

proc nlmixed data=WORK.SEIDMANETAL1986_Q;

parms KM 1e-8;

 

pred = conc*KM*Q*PY;

ll=LogPDF("POISSON",Obs,Pred);

model Obs ~ general(ll);

predict pred out=model1 alpha=0.1 /*df=5*/;

 

Proc print data=model1;

run;

 

Rick_SAS
SAS Super FREQ

How does what you propose doing accomplish that?

 

If you scale the data, you can get estimates and CIs in the new scale.

 

I have to think about it a little more, but it looks like this problem is linear in the parameter, so you can then divide the estimate and CIs by 1E6 to obtain the estimates on the original scale.  In fact, now that I look at it, I don't think you need NLMIXED at all. I think you can use PROC GENMOD to perform the regression. It all looks linear in the parameter. Maybe someone else can verify.

rshaw1
Calcite | Level 5

I don't know much about Proc Genmod - how would I enter this into that procedure?  I'm looking to 1st estimate KM and calculate the expected cases for each group (C=KM*Q*PY) by maximizing the log likelihood.  Proc nlmixed is currently providing a value for KM and giving me the predicted values for each group.  I'll try scaling the data as you suggest, but I don't think proc nlmixed calculates CIs using the likelihood profile method.

 

Thank you.

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 6 replies
  • 652 views
  • 0 likes
  • 2 in conversation