Solved
New Contributor
Posts: 2

# Proc nlin with weights and SSE

Hi

I have a problem estimating a nlin function on weighted data which basically comes down to the problem below:

Consider the following data where clearly y =x² and z aresome weights. Bij adapting the standard proc nlin to include the weights:

``````data STARTDATA;
input x  y z ;
datalines ;
1 2 0.1
2 4 0.2
3 9 0.2
4 16 0.5
;
PROC SQL;
CREATE VIEW WORK.SORTTempTableSorted AS
SELECT T.y, T.x, T.z
FROM WORK.STARTDATA as T;
PROC NLIN DATA=WORK.SORTTempTableSorted
MAXITER=100
CONVERGE=1E-05
SINGULAR=1E-08
MAXSUBIT=30;
_WEIGHT_ = z;
MODEL y = x ** b
;
PARMS
b=0.01;
RUN;``````

The parameter b is estimated correctly as 2. However the SSE is minimized to the first weight which is 0.1 and is not further decreased to  0.
This makes the R²  (here 1) wrongly estimated.

How can I correct my example such that the SSE can be smaller than the first weight?

Accepted Solutions
Solution
‎02-01-2016 10:45 AM
Valued Guide
Posts: 684

## Re: Proc nlin with weights and SSE

Forgot the mention above, your SS should not be 0 because your y values are not exactly equal to x**2 (the first y should be 1, not 2, if you want an exact match).

All Replies
Valued Guide
Posts: 684

## Re: Proc nlin with weights and SSE

Why do you think the results are wrong? I just ran your program with plots turned on, and everything looks fine for the fit. Taking out the weight statement gives a different confidence region, different SE, etc.,as expected. I think you just have a coincidence about the "0.1". For instance, I ran:

data b; set startdata;
pred = x**2;
SS = (y - pred)**2;
WSS = z*SS;
run;
proc means data=b  sum;
var SS WSS;
run;

To manually get the sum of squares, weighted and unweighted, based on your parameter estimate. Weighted SS = 0.1, just like the NLIN output. If you run NLIN without the weight, you get SS = 1.0. This is what you get manually (above). I think everything is fine. By the way, put a plots=all option in your NLIN statement for good graphs.

Solution
‎02-01-2016 10:45 AM
Valued Guide
Posts: 684

## Re: Proc nlin with weights and SSE

Forgot the mention above, your SS should not be 0 because your y values are not exactly equal to x**2 (the first y should be 1, not 2, if you want an exact match).

New Contributor
Posts: 2

## Re: Proc nlin with weights and SSE

Hi

There is an input error in my trial model: y1 should be 1 of course. However In my real problem this gives still some strange results. Thanks for the plots =all. It helps for my real problem
☑ This topic is solved.