Calcite | Level 5

## How can I apply my nonlinear mixed-effects model to testdata?

Hi,

I developed a nonlinear mixed-effects model using nlmixed procedure. But, I do not know how to apply this model to test data (unseen data in modeling). I tried OUTmodel and INmodel options, but I failed to run the model. Could you help me please?

data capboy;
input boy dbh N G hmak dmak plot;
datalines;
10.1 35 725 23.50 11.2 35 1
10.6 21 725 23.50 11.2 35 1

... more lines

;

data testdata;
input boy dbh N G hmak dmak plot;
datalines;
19 28 450 24.25 20 53 5
16.3 32 450 24.25 20 53 5

... more lines

;

proc nlmixed data=capboy ;
parms b1=54.021 b2=-12.521 b3=5.445 b4=1.911 b5=0.0699 s2u=0 s2e=1;
mdl=1.3 + (((b1 + b2*(dbh/hmak)))/(1 + (((b3 + b4*dmak/hmak))*exp( - (b5+u)*dbh))));
model boy ~ normal(mdl,s2e) OUTmodel=deneme;
random u ~ normal(0,s2u) subject=plot out=rp;
predict mdl out=tahmin;
run;

proc nlmixed INmodel=deneme;
score data=testdata fitstat;
run;

1 ACCEPTED SOLUTION

Accepted Solutions
SAS Super FREQ

## Re: How can I apply my nonlinear mixed-effects model to testdata?

The PREDICT statement predicts any expression. Currently, you are predicting mdl, which does not include any random effects.  Add a new PREDICT statement such as

predict mdl+u  out=tahminRand;

Or, for more complicated expressions, define a temporary variable in the program that incorporates the random effects. For example:

Pred = mdl + u;
predict Pred out=tahminRand;

4 REPLIES 4
SAS Super FREQ

## Re: How can I apply my nonlinear mixed-effects model to testdata?

The NLMIXED procedure does not support a SCORE statement, nor a STORE statement that would create a model that PROC PLM could score. Therefore, you have to use the "missing value trick" to score data sets. For a discussion of the missing value trick and a complete example, see the following articles:

Neither of the examples use PROC NLMIXED, but I can see from the code you've posted that you have experience with PROC NLMIXED syntax, so I think you'll be able to adapt the ideas to your problem.

Calcite | Level 5

## Re: How can I apply my nonlinear mixed-effects model to testdata?

Thank you Rick,

I used "the missing value trick" and predicted the missing values. However, this method gave the predictions of fixed-effects. I need the predictions of random-effects.

data score;
boy=.;
do plot=143 to 178;
output;
run;
data Combined;
set capboy
Score(in=ScoreData);
run;
proc nlmixed data=Combined;
parms b1=54.021 b2=-12.521 b3=5.445 b4=1.911 b5=0.0699 s2u=0.3 s2e=0.5;
mdl=1.3 + ((((b1+u) + b2*(dbh/hmak)))/(1 + (((b3 + b4*dmak/hmak))*exp( - b5*dbh))));
model boy ~ normal(mdl,s2e);
random u ~ normal(0,s2u) subject=plot out=rp;
predict mdl out=tahmin;
run;
proc print data=tahmin(Where= (plot=143));
run;

SAS Super FREQ

## Re: How can I apply my nonlinear mixed-effects model to testdata?

The PREDICT statement predicts any expression. Currently, you are predicting mdl, which does not include any random effects.  Add a new PREDICT statement such as

predict mdl+u  out=tahminRand;

Or, for more complicated expressions, define a temporary variable in the program that incorporates the random effects. For example:

Pred = mdl + u;
predict Pred out=tahminRand;

Calcite | Level 5

## Re: How can I apply my nonlinear mixed-effects model to testdata?

Thank you very much Rick for your helps.

I predicted fixed and random effects.

Discussion stats
• 4 replies
• 437 views
• 3 likes
• 2 in conversation