Home > GIStemp, LSCF, Statistics > Lines, Sines, and Curve Fitting 10 – nls

Lines, Sines, and Curve Fitting 10 – nls

2011 January 18

The “nonlinear least squares” (nls) function is part of the core of R. John Fox wrote an introduction to it: Nonlinear Regression and Nonlinear Least Squares. This function will in a few dozen iterations return a better fit than my brain-dead looping around parameter space a few tens of thousands of times.

So we will take a quick look at 4 of the functions we looked at earlier, fit them, and graph them

1. Simple linear fit
2. Simple exponential fit
3. Linear + Sine fit
4. Exponential + Sine fit

Linear Fit

Formula: y ~ m1 * x + b1

Estimate (Std. Error)
m1 0.005862 (2.934e-04
b1 -11.42 (5.707e-01)

> cor(y1,y)
[1] 0.8693986

Exponential Fit

Formula: y ~ -a2/100 + b2/100 * exp((k2/10000) * (x – 1880))

Estimate (Std. Error)
a2 32.714 (4.033)
b2 5.939 (2.242)
k2 209.096 (27.864)

> cor(y2,y)
[1] 0.9103917

Line + Sine Fit

Formula: y ~ m3 * x + b3 + A3 * sin(((x – B3)/T3) * (2 * pi))

Estimate (Std. Error)
m3 .005806 (.0002419)
b3 -11.32 (.4707e-01)
A3 0.1066 (.01224)
B3 52.74 (63.97)
T3 58.64 (1.981)

> cor(y3,y)
[1] 0.9206986

Exponential + Sine Fit

Formula: y ~ -a4/100 + b4/100 * exp((k4/10000) * (x – 1880)) + A4 * sin(((x –
B4)/T4) * (2 * pi))

Estimate (Std. Error)
a4 37.64934 (6.29163)
b4 10.09052 (4.29724)
k4 167.14237 (30.15498)
A4 0.08134 (0.01212)
B4 -649.10177 (138.06890)
T4 67.71585 (3.61209)

> cor(y4,y)
[1] 0.9348314


So what do these look like extended into the 21st Century?

One interesting observation is that while there is more than 3C in the 21st Century, the sine wave suppresses the growth in the early decades and it doesn’t accelerate until after 2040 or so. But slow growth is still obviously different than the cooling that one expects with a line+sine construct.

  1. Girma
    2011 January 18 at 12:10 pm


    Sorry. I got it now.

    Yes. Yes. Yes.

    A very high correlation coefficient of 0.93.

    Prediction of only about 0.5 deg C further warming by 2100!

    Not 6 deg C of the IPCC!

    According to Ron’s model, the Skeptics WIN.

    According to Ron’s model, don’t waste resources in the mirage problem of “man-made global warming”!

    First wait and see whether we will have cooling or warming in the next 5 to 10 years. The cooling will disprove man made global warming and stop the associated waste and stupidity of solving an imaginary problem.

  2. Girma
    2011 January 18 at 12:18 pm


    Sorry. I read it wrong. It is the exponential that has the higher correlation coefficient of 0.93 . What a pity. We shall wait and see then.

  3. 2011 January 18 at 12:22 pm

    Girma, you seem quick to claim victory … slow to acknowledge a defeat. 😉

  4. Girma
    2011 January 18 at 12:24 pm


    Can you do the above for hadcrut?

  5. Girma
    2011 January 18 at 12:28 pm

    As a skeptic, I don’t trust the GISTEMP data especially after 2000 at ALL!

  6. Girma
    2011 January 18 at 12:32 pm


    Please do exactly the above for hadcrut.

    Thanks in advance!

    Kind Regards

  7. 2011 January 18 at 1:06 pm

    Girma, if you are willing, I will “teach a man to fish.”

    Go to this page

    and download this program
    “Download R 2.12.1 for Windows”

    After you install it, to run my script, you will need to install the Cairo package

    The Cairo package, for the curious, allows me to run my scripts on a web server without a display. You don’t need it per se, its just written into my scripts.

    Then you will need to get the file from here, and put it into your working directory

    After that, you should be able to run this script

    Now, that’s a bunch of stuff to learn about installing and running R, but the data is already formatted, and the script is already written. But if you wait or day or two, I’ll provide the runs in HadCRU and NCDC data as well.

  8. Girma
    2011 January 19 at 10:44 pm



    I will wait two days, as I want to see the results in your very nice looking blog.

    And it will be a reference for any one interested in the topic in our planet.


    The global mean temperature data for 2010 is out.

    It is 0.475 deg C.

    The previous maximum of 0.548 deg C for 1998, 13 years ago, has not been exceeded.


    Global warming has stopped for 13 years, and we continue to count the number of years that the previous maximum has not been exceeded.

    The number now is 13!

    How many more years is required to declare global warming has stopped?

    2? 5? 10?

  9. 2011 January 20 at 10:28 am

    Since it’s a mathematical discussion, how about formalizing what “global warming has stopped” mean?

    Quantifiers, predicates, perhaps types. Perhaps even probabilities or other kinds of uncertainty measures.

    Hell, even modalities would suit me for now.

    Meanwhile, Girma’s bragging is much ado about nothing.

  10. 2011 January 20 at 12:42 pm

    Willard, I am slowly working my way into deterministic trend tests as we speak. Formal statistics is a new subject for me; I am approaching this as a student., not making pronouncements.

    But since you ask, if temperature data corresponds to a model where

    yt = mu + beta*t + ut

    Global warming occurs when beta > 0 and t is a range from a test date to a future (or most current) date
    Global warming has stopped when beta <= 0

  11. Girma
    2011 January 20 at 4:47 pm

    “global warming has stopped” means the global mean temperature maximum record of 0.548 deg C for 1998 has not been exceeded for 13 years.

    “Global warming has stopped” means deceleration of decadal trends. For example, for 1990 to 2000 the trend is 0.25 deg C per decade warming, while for 2000 to 2010 the trend is only 0.03 deg C per decade warming, a deceleration by a factor of 0.25/0.03=8.3!

    “Global warming is happening” means acceleration of decadal trends. For example, for 1980 to 1990 the trend is 0.07 deg C per decade warming, while for 2000 to 2010 the trend is 0.25 deg C per decade, an acceleration by a factor of 0.25/0.07=3.6!

  12. 2011 January 21 at 7:35 am


    Thank you for your equation.

    I am not looking for a formal test, but for a formal expression of the claim.

    If AGW is a theory, I suspect it could be stated as a logico-mathematical claim.

    In my humble opinion, mixing graphics with unquantified and unqualified claims dillutes the strenght of the analysis and surreptitiously leads to public relations, politics, and marketing.



    Thank you for your answer.

    I fail to see how the first two definitions are equivalent. Can you explain the identity between “beating a maximum record” and “deceleration”?

    Saying “global warming has stopped” is not the same thing as “global warming has stopped since 1998”.

    I believe that you are acknowledging that something is missing in your inference when you say:

    > How many more years is required to declare global warming has stopped?

    There might be no answer to that question.

    The Humean predicament is the human predicament.

  13. 2011 January 21 at 12:11 pm

    I am not looking for a formal test, but for a formal expression of the claim

    Hm. How is this *not* a formal expression of the claim?

    yt = mu + beta*t + ut

    Global warming occurs when beta > 0 and t is a range from a test date to a future (or most current) date
    Global warming has stopped when beta <= 0

    Perhaps you can provide an example of that to which you refer?

  14. 2011 January 22 at 7:01 am

    I think you have simply stated the equation for a trend. On the face of it, it does not say anything about Girma’s claims that the world is not warming. How is it that this trend indicate anything about climate?

    We talk about acceleration, deceleration, stopping, trend, warming, global temperature, but everything that matters remains implicit. If decelerating was enough to stop, we’d have less car accidents.

    On the face of it, Girma’s analysis can only make her say that the warming trend reported in HASCRUT3 can be eyeballed as having decelerated between 1998 and 2010.


    I’ve never seen such a formal claim as the one I have in mind. If Girma or anyone else could provide an engineer-level derivation of claims like “Warming has stopped” or “AGW is refuted”, with all the relevant steps spelled out, we’d have much, much less discussion. At the very least, it might not be unreasonable to ask for a specific reference to an existing article.

    This lack of formal derivation might even be a major and regrettable shortcoming and might even be the largest single factor in Girma’s reasoning.

  15. 2011 January 22 at 7:52 am
  16. 2011 January 22 at 9:58 am

    A caveat for all.

    The problem with calling anthropogenic climate change “global warming” is that it tends to reduce the problem to predictions about a time series.

    If the sensitivity of the surface temperature to CO2 is high, we definitely have a problem.

    If it is low, we might still have a problem, if the way the system adjusts to the radiative imbalance is by drastically altering its behavior. Consider the bitter winter in western Europe combined with the extraordinary warmth in Baffin Island and Greenland that has been going on for several weeks now. On the average, the temperature has not changed. But lands unfamiliar with persistent snow are dealing with it, while at the same time the ice sheets remain softened up for big losses next summer.

    The issue is that we are demonstrably and substantially altering the radiative properties of the atmosphere. We expect the surface to warm up and the stratosphere to cool as a symptom of this change. But there are subtleties. The extent and timing of these changes,and of associated transients, are not known with precision.

    The massive El Nino of 1998 may or may not have a lot to do with this. But the year-to-year background temperature is already close to the 1998 spike. A comparably large El Nino now, on top of the raosed baseline, would set another record that would be maintained for a decade or two.

    I don’t discourage people playing with R, but everyone should realize that what we are talking about is a complex physical system, not a statistical abstraction. If we had enough planets to extract the true statistical distributions, they would be very complex even in the absence of a human perturbation.

  17. 2011 January 22 at 10:56 am

    Willard, is this more along the lines of what you are thinking?

    GC is the 30 year mean of GSTA
    GSTA is the annual global, area weighted, averaged surface temperature anomaly
    GC is increasing or warming if dGC/dt > 0
    GC is not increasing or warming if dGC/dt <= 0

  18. 2011 January 22 at 11:02 am

    MT, I’m keenly aware that “global” masks the regional and seasonal changes that are much more important to individuals and society than “the mean of climate”, that weather extremes have more impact than climate means, and that “warming” overlooks the changes in moisture (drought, flood, annual/seasonal precipitation, aridity) that are probably more important to those same individuals and societies than temperature. Just like we have global and regional temperature data sets to work with, we also have precipitation records that have been somewhat overlooked in the blog-o-sphere.

    And, for that matter, there is code available for some fully coupled AOGCMs out there. I’ve sort-of-run modelE before and poked around at CESM. But before I try to tackle those, I want to work with statistical, phenomenological and energy-balance models to get some insights into “the (imaginary?) baseline” before I worry about complex and lagged feedbacks.

  19. 2011 January 26 at 10:13 pm

    FWIW, the accuracy of the data early in the record is a lot more questionable than the data for today, equally weighting all the points is probably a mistake, but it would not be straightforward to figure out how to handle the situation.

    Somewhat related, if the fit goes to hell at the endpoints, you really have to wonder if there is any predictive power

  1. No trackbacks yet.
Comments are closed.