[SciPy-User] SciPy-User Digest, Vol 82, Issue 45

Timothy Kinney timothyjkinney at gmail.com
Tue Jun 15 13:42:14 EDT 2010


Josef,

Thank you for showing me how to do the R-squared calculation.

Also, looking at your code I realized that had a typo in my python
data so I was actually analyzing two different data sets, which is why
I got different results. I get the same result in both when I use the
same data set.

Back to work. :)

-Tim


> I get the same results as your Excel results for the log transformed
> linear model
>
>
>>>> y=np.array([600., 50, 46, 43, 40, 39, 38, 37, 36, 35])
>>>> t = np.array([356, 1476, 1477, 1478, 1480, 1480, 1481, 1482, 1485, 1489])
>>>> from scipy import stats
>>>> res = stats.linregress(t, np.log(y))
>>>> np.exp(res[1]), res[0]
> (1416.9044014863491, -0.002405999077350617)
>>>> yhat = np.exp(res[1])*np.exp(res[0]*t)
>>>> y-yhat
> array([-1.6609619 ,  9.35096348,  5.44864747,  2.5460967 , -0.2597068 ,
>       -1.2597068 , -2.16295842, -3.06644253, -3.77828427, -4.39729448])
>
>
>>>> rss=((np.log(y)-np.log(yhat))**2).sum()
>>>> rss
> 0.096919787740057148
>>>> lny=np.log(y)
>>>> 1-rss/((lny-lny.mean())**2).sum()   #R-squared
> 0.98551323008032532
>
> Josef



More information about the SciPy-User mailing list