# st: Re: computation of R-squared with a non-linear model

 From Paul Seed To "statalist@hsphsun2.harvard.edu" Subject st: Re: computation of R-squared with a non-linear model Date Fri, 22 May 2009 09:25:00 +0100

There is a simple way to compute R-squared for any regression model, if you do not believe the value given by Stata: Calculate the predicted values and carry out your own correlation.
```
Using the auto data set:

**** Start Stata code *****
sysuse auto
regress weight price

predict pred_w
su weight pred_w
corr weight pred_w

di "R-squared = " r(rho)*r(rho)
**** End Stata code *****

Both ways giver a value of 0.2901023
```
In general, the use of weights and adjusted R-squared makes things more complicated, and the last two lines could be changed to allow for them;
```but neither will alter a correltion of 1.0.

```
If Marcel Spijkerman uses this approach, he may find a) Marcel is right - the second R-squared is different from the first. (He does not say, but I assume that both the adjusted and unadjusted R-squared are 1.0).
```
```
b) Martin Buis is right - the model has failed to converge, and the predicted values are mostly or completely undefined.
```
c) Stata is right - both methods give R-squared = 1.0

d) Something else I haven't though to.

I'd be interested to know which.

```
```> Date: Wed, 20 May 2009 08:27:31 +0000
> From: maartenbuis@yahoo.co.uk
> Subject: RE: st: Re: computation of R-squared with a non-linear model
> To: statalist@hsphsun2.harvard.edu
>
>
> --- "marcel spijkerman" wrote:
```
```>>>> I estimate a weighted non-linear model of the
>>>> following form:
>>>>
>>>> y0.5 = (a1 + a2*X)0.5 weighted by some other
>>>> variable z.
>>>>
>>>> Stata reports an adjusted R-squared of 1.000. I
>>>> suspect this is not correct. How can compute the
>>>> correct adjusted R-squared using untransformed
>>>> variables?
```
```>
> --- Martin Weiss wrote:
```
```>>> Which command did you use for your estimation? If it
>>> was non-linear, -nl-?
>>> Show us what you typed and what the reply was...
```
```>
> --- On Wed, 20/5/09, marcel spijkerman wrote:
```
```>> I indeed typed the command:
>>
>> nl (sqrt_y = (a1 + a2X)0.5) [aweight= hhd1564_06]
>>
```
>> And the answer is .... :-)
```>
> It is surprising that you got output at all, as you
> did not specify any parameters. Anyhow, it appears that
> you have a convergence problem. So the next step is
> not to try to come up with some correct R2, but to
> fix the model. You could try specifing starting
> values.
>
> -- Maarten
>
> Ps. -aweights- are very very very rarely the correct
> weight type.
>
```
```Paul T Seed MSc CStat CSci, Senior Lecturer in Medical Statistics,
tel  (+44) (0) 20 7188 3642, fax (+44) (0) 20 7620 1227
```
Wednesdays: (+44) (0) 20 7848 4208
```

*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/
```