Skip to main content

Nonlinear Least Squares: How Fast Did Greece Go Online?

Nonlinear least squares in R with nls(), on the World Bank’s share of people in Greece who use the internet (1990-2024): logistic and Gompertz growth curves, Gauss-Newton by hand, starting values and what happens when they are bad, self-starting models, profile against Wald confidence intervals, the delta method, AIC for curves that are not nested, a forecast test from 2008, a comparison of three countries and APA reporting.

The question: a curve with a meaning

In 1995 fewer than one in a hundred people in Greece used the internet. Today nearly nine in ten do. New things usually spread like this: slowly at first, when few people have them and others hardly hear of them; then fast; then slowly again, when only a few people are left. The curve looks like an S.

This page fits S-curves to the data, to answer three questions:

  1. What is the ceiling, the share at which the curve will stop?
  2. When was the growth fastest?
  3. How fast was it?

A polynomial could follow the points (see polynomial regression), but it has no ceiling, and its coefficients answer none of the three questions. An S-curve has exactly three parameters, and they are the three answers. The price is that the curve is nonlinear in its parameters, so the formulas of linear regression do not apply, and the computer must search. Nonlinear least squares is that search.

Code
library(jsonlite)   # fromJSON(): the World Bank answers in JSON
library(ggplot2)

curve_colours <- c("Logistic" = "#eb6834", "Gompertz" = "#2a78d6")

# number formats for the text
f1   <- function(x) formatC(x, format = "f", digits = 1, big.mark = ",")
f2   <- function(x) formatC(x, format = "f", digits = 2, big.mark = ",")
f3   <- function(x) formatC(x, format = "f", digits = 3, big.mark = ",")
num  <- function(x) trimws(format(x, big.mark = ","))

1. The data

The World Bank publishes, for every country and year, the individuals using the internet (% of population), collected by the International Telecommunication Union. It is free and needs no login:

Code
internet <- function(country) {
  url <- paste0("https://api.worldbank.org/v2/country/", country,
                "/indicator/IT.NET.USER.ZS?format=json&per_page=200")
  d <- fromJSON(url)[[2]][, c("date", "value")]
  d <- data.frame(year = as.integer(d$date), share = d$value)
  d <- subset(d, !is.na(share) & year <= 2024)
  d$t <- d$year - 2000                     # years since 2000
  d[order(d$year), ]
}
greece <- internet("GRC")
nrow(greece)
[1] 35
Code
greece[greece$year %in% c(1990, 1995, 2000, 2005, 2010, 2015, 2020, 2024), ]
   year     share   t
36 1990  0.000000 -10
31 1995  0.750000  -5
26 2000  9.138837   0
21 2005 24.000000   5
16 2010 44.400000  10
11 2015 66.834959  15
6  2020 78.115845  20
2  2024 86.269689  24

There are 35 years, 1990 to 2024. The share is the percentage of people who used the internet in the last three months. The early years are estimates of the ITU from subscriptions and connected computers, and the later ones come mostly from household surveys, so the series is not measured in the same way from end to end.


2. Look at the data

Code
ggplot(greece, aes(year, share)) +
  geom_line(colour = "grey70") +
  geom_point(size = 2, colour = "grey25") +
  scale_y_continuous(limits = c(0, 100)) +
  labs(title = "People in Greece who use the internet", x = NULL, y = "% of the population") +
  theme_bw()

Plot: 2. Look at the data

Code
rise <- data.frame(year = greece$year[-1], rise = diff(greece$share))
fastest <- rise[order(-rise$rise), ][1:3, ]
fastest
   year     rise
16 2006 8.250000
21 2011 7.249995
23 2013 4.796307

A slow start, a fast middle, and a slow approach to a ceiling. The yearly rise was largest in 2006 (8.2 points), and it is now 1.3.


3. The model step by step, with formulas

Step 1: what “nonlinear” means

\[y_i = f(t_i; \theta) + \varepsilon_i\]

A model is linear when its parameters only multiply things that are known and are added up: \(\beta_0 + \beta_1 t + \beta_2 t^2\) is linear, although it is a curve in \(t\). It is nonlinear when a parameter sits inside a function, in a denominator or an exponent.

Step 2: the logistic curve

\[y = \frac{A}{1 + e^{-(t - m)/s}}\]

  • \(A\) is the ceiling (the asymptote), in % of the population;
  • \(m\) is the midpoint, the time at which the curve is at \(A/2\) and grows fastest;
  • \(s\) is the scale, how stretched the S is: in \(s\) years the curve goes from 50% to 73% of the ceiling. The growth at the midpoint is \(A/(4s)\) points per year.

The story behind it: the growth is proportional to those who have it already (they spread it) and to those who do not have it yet (Geroski, 2000).

Step 3: the Gompertz curve

\[y = A\, e^{-e^{-(t - m)/s}}\]

The same three parameters, but the S is not symmetric. The growth is fastest at \(t = m\), when the curve has reached only \(A/e\) = 37% of the ceiling, and it is \(A/(e\,s)\) points per year there. The rest of the way is slow: a long tail of late adopters. (Winsor, 1932, compares the two curves.)

Code
shape <- data.frame(t = seq(-15, 30, by = 0.1))
shape <- rbind(data.frame(shape, y = 100 / (1 + exp(-(shape$t - 5) / 3)), curve = "Logistic"),
               data.frame(shape, y = 100 * exp(-exp(-(shape$t - 3) / 5)), curve = "Gompertz"))
top   <- data.frame(t = c(5, 3), y = c(50, 100 / exp(1)), curve = c("Logistic", "Gompertz"))

ggplot(shape, aes(t, y, colour = curve)) +
  geom_line(linewidth = 1) +
  geom_point(data = top, size = 3) +
  scale_colour_manual(values = curve_colours, name = NULL) +
  labs(title = "Two S-curves with a ceiling of 100",
       subtitle = "Points: the fastest growth, half-way up (logistic) or at 37% (Gompertz)",
       x = "time", y = "y") +
  theme_bw() + theme(legend.position = "bottom")

Curves – Step 3: the Gompertz curve

Step 4: least squares again, but without a formula

We still want the parameters with the smallest sum of squared residuals,

\[S(\theta) = \sum_i \left[ y_i - f(t_i; \theta) \right]^2\]

In linear regression, setting the derivatives to zero gives equations that can be solved. Here the equations cannot be solved, so we walk downhill from a starting guess.

Step 5: the Gauss–Newton method

Near the current guess, replace the curve by its tangent, which is linear in the parameters (Bates & Watts, 1988). With \(J\) the table of derivatives of the curve (one row per year, one column per parameter) and \(e\) the current residuals, the best step is an ordinary regression of \(e\) on \(J\):

\[\theta_{\text{new}} = \theta_{\text{old}} + (J^\top J)^{-1} J^\top e\]

Repeat until the step is tiny. For the logistic curve, with \(p = 1/(1 + e^{-(t-m)/s})\), the derivatives are

\[\frac{\partial f}{\partial A} = p, \qquad \frac{\partial f}{\partial m} = -\frac{A}{s}\, p(1-p), \qquad \frac{\partial f}{\partial s} = -\frac{A}{s}\cdot\frac{t - m}{s}\, p(1-p)\]

Code
t_ <- greece$t
y_ <- greece$share
theta <- c(A = 90, m = 8, s = 4)            # the starting guess, read off the chart
walk  <- NULL
for (iteration in 0:8) {
  p <- 1 / (1 + exp(-(t_ - theta["m"]) / theta["s"]))
  e <- y_ - theta["A"] * p
  walk <- rbind(walk, c(iteration = iteration, theta, RSS = sum(e^2)))
  k <- theta["A"] / theta["s"] * p * (1 - p)
  J <- cbind(A = p, m = -k, s = -k * (t_ - theta["m"]) / theta["s"])
  theta <- theta + drop(solve(crossprod(J), crossprod(J, e)))
}
round(walk, 4)
      iteration       A      m      s       RSS
 [1,]         0 90.0000 8.0000 4.0000 1470.6033
 [2,]         1 84.6013 8.9270 4.3857  152.3089
 [3,]         2 85.6086 9.2095 4.4662  144.3244
 [4,]         3 85.7797 9.2399 4.4810  144.2446
 [5,]         4 85.7926 9.2426 4.4819  144.2439
 [6,]         5 85.7939 9.2429 4.4820  144.2439
 [7,]         6 85.7940 9.2429 4.4820  144.2439
 [8,]         7 85.7940 9.2429 4.4820  144.2439
 [9,]         8 85.7940 9.2429 4.4820  144.2439

A handful of steps is enough. The sum of squares falls from 1,470.6 to 144.2.

Step 6: the standard errors

At the minimum, the same tangent gives approximate standard errors, as if the model were the linear one:

\[\widehat{\text{Var}}(\hat\theta) \approx \hat\sigma^2 (J^\top J)^{-1}, \qquad \hat\sigma^2 = \frac{S(\hat\theta)}{n - p}\]

They are only as good as the tangent. Section 5 has a better interval.


4. Fitting the models and reading the output

The logistic curve

nls() takes the formula of the curve and a list of starting values:

Code
logistic <- nls(share ~ A / (1 + exp(-(t - m) / s)), data = greece,
                start = list(A = 90, m = 8, s = 4))
summary(logistic)

Formula: share ~ A/(1 + exp(-(t - m)/s))

Parameters:
  Estimate Std. Error t value Pr(>|t|)    
A  85.7940     1.4186   60.48   <2e-16 ***
m   9.2429     0.2464   37.51   <2e-16 ***
s   4.4820     0.1752   25.58   <2e-16 ***
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Residual standard error: 2.123 on 32 degrees of freedom

Number of iterations to convergence: 6 
Achieved convergence tolerance: 1.603e-06
Code
cL <- coef(logistic)
  • A = 85.8: the curve stops at 85.8% of the population. But in 2024 the share was 86.3%, above the ceiling, and still rising. Something is wrong with this curve.
  • m = 9.24: the midpoint is about 2009.
  • s = 4.48: at the midpoint the share grew by \(A/(4s)\) = 4.8 points a year.
  • Residual standard error: the curve misses the points by about 2.1 percentage points. There is no \(R^2\): in nonlinear models it does not split the variation into two parts, it can mislead, and R does not print it (Spiess & Neumeyer, 2010).
  • Number of iterations and convergence tolerance: how the search ended. Our own Gauss–Newton steps gave the same estimates.

Starting values

The search needs to start in the right area. Three ways to find it:

  1. Read them off the chart. The ceiling is a bit above the last points, the midpoint is where the curve is at half of it, the scale is the time from 50% to 73%.
  2. Use a self-starting model, which finds its own: SSlogis() and SSgompertz() come with R.
  3. Make the problem linear to get a rough first answer: for a fixed ceiling, the logit of \(y/A\) is a straight line in \(t\).
Code
self <- nls(share ~ SSlogis(t, A, m, s), data = greece)    # no starting values
rbind(own_start = cL, self_start = coef(self))
                  A        m        s
own_start  85.79398 9.242912 4.482017
self_start 85.79400 9.242914 4.482021

And what happens with bad starting values?

Code
starts <- list(good        = list(A = 90,  m = 8,  s = 4),
               steep       = list(A = 100, m = 0,  s = 0.1),
               wrong_year  = list(A = 90,  m = 50, s = 1),
               low_ceiling = list(A = 1,   m = 0,  s = 1))
outcome <- sapply(starts, function(st) {
  fit <- try(nls(share ~ A / (1 + exp(-(t - m) / s)), data = greece, start = st), silent = TRUE)
  if (inherits(fit, "try-error")) trimws(sub(".*:", "", sub("\n *$", "", as.character(fit))))
  else paste("converged: A =", f1(coef(fit)[["A"]]))
})
data.frame(start = names(starts), outcome = outcome, row.names = NULL)
        start                                                 outcome
1        good                                     converged: A = 85.8
2       steep                                     converged: A = 85.8
3  wrong_year singular gradient matrix at initial parameter estimates
4 low_ceiling                                       singular gradient

singular gradient is the most common error of nls(). It means that, at the current guess, changing some parameter does not change the curve (or two parameters change it in the same way), so there is no direction to walk in. With a midpoint in 2050, for example, the curve is flat zero over all the data. The remedy is almost always a better starting value, sometimes fewer parameters. minpack.lm::nlsLM() is a more patient search.

The Gompertz curve

Code
gompertz <- nls(share ~ A * exp(-exp(-(t - m) / s)), data = greece,
                start = list(A = 95, m = 6, s = 6))
summary(gompertz)

Formula: share ~ A * exp(-exp(-(t - m)/s))

Parameters:
  Estimate Std. Error t value Pr(>|t|)    
A  97.4404     1.4664   66.45   <2e-16 ***
m   7.3725     0.1700   43.36   <2e-16 ***
s   8.2564     0.2301   35.89   <2e-16 ***
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Residual standard error: 1.112 on 32 degrees of freedom

Number of iterations to convergence: 4 
Achieved convergence tolerance: 9.872e-06
Code
cG <- coef(gompertz)
Code
grid <- data.frame(t = seq(-10, 40, by = 0.2))
grid$year <- 2000 + grid$t
paths <- rbind(data.frame(grid, share = predict(logistic, grid), curve = "Logistic"),
               data.frame(grid, share = predict(gompertz, grid), curve = "Gompertz"))

ggplot(greece, aes(year, share)) +
  geom_line(data = paths, aes(colour = curve), linewidth = 1) +
  geom_point(size = 1.8, colour = "grey25") +
  scale_colour_manual(values = curve_colours, name = NULL) +
  scale_y_continuous(limits = c(0, 100)) +
  labs(title = "Logistic and Gompertz curves for Greece", x = NULL, y = "% of the population") +
  theme_bw() + theme(legend.position = "bottom")

Fits chart – The Gompertz curve

The Gompertz curve follows the points all the way. The logistic is too low at the end, because it is symmetric: having risen fast, it must also stop fast.

Which curve is better?

The two curves are not nested: neither is a special case of the other, so no F test compares them. They have the same number of parameters, so we can compare the residual sums of squares, or the AIC:

Code
comparison <- data.frame(curve  = c("Logistic", "Gompertz"),
                         RSS    = c(deviance(logistic), deviance(gompertz)),
                         sigma  = c(sigma(logistic), sigma(gompertz)),
                         AIC    = AIC(logistic, gompertz)$AIC)
comparison
     curve       RSS    sigma      AIC
1 Logistic 144.24391 2.123116 156.8912
2 Gompertz  39.58569 1.112229 111.6349

The Gompertz misses by about 1.1 points, the logistic by about 2.1. The AIC difference is 45.3, and by the usual rule of thumb 10 is already decisive. The residuals say it best:

Code
res <- rbind(data.frame(year = greece$year, r = resid(logistic), curve = "Logistic"),
             data.frame(year = greece$year, r = resid(gompertz), curve = "Gompertz"))
res$curve <- factor(res$curve, levels = c("Logistic", "Gompertz"))

ggplot(res, aes(year, r, colour = curve)) +
  geom_hline(yintercept = 0, colour = "grey60") +
  geom_segment(aes(xend = year, yend = 0), linewidth = 0.5) +
  geom_point(size = 1.8) +
  facet_wrap(~ curve, ncol = 1) +
  scale_colour_manual(values = curve_colours, guide = "none") +
  labs(title = "Residuals: the logistic misses in long waves", x = NULL, y = "residual (points)") +
  theme_bw()

Residuals – Which curve is better?

Code
lag1 <- c(
  logistic = acf(resid(logistic), plot = FALSE)$acf[2],
  gompertz = acf(resid(gompertz), plot = FALSE)$acf[2]
)
lag1
 logistic  gompertz 
0.6799875 0.2068244 

The residuals of the logistic come in long runs of the same sign, and each correlates with the next at 0.68: the sign of a wrong curve. For the Gompertz the correlation is 0.21.


5. Confidence intervals, and quantities made from the parameters

Wald or profile?

The quick interval is the estimate \(\pm\) 2 standard errors (Wald). It trusts the tangent of step 6, and it is symmetric. The profile interval does not: it fixes one parameter at a value, fits all the others again, and keeps the values for which the fit does not become significantly worse (with an F test). confint() does it for nls fits:

Code
wald <- coef(gompertz) +
  outer(summary(gompertz)$coefficients[, 2], c(-1, 1) * qt(0.975, df.residual(gompertz)))
profile_ci <- confint(gompertz)
cbind(estimate = cG, wald_low = wald[, 1], wald_high = wald[, 2],
      profile_low = profile_ci[, 1], profile_high = profile_ci[, 2])
   estimate  wald_low  wald_high profile_low profile_high
A 97.440435 94.453526 100.427344   94.601769   100.596375
m  7.372518  7.026204   7.718833    7.039667     7.737578
s  8.256362  7.787733   8.724991    7.806563     8.740581

Here they nearly agree, because the data cover the whole curve. When they do not agree, the profile is the one to trust. The next section shows such a case.

The year when half of the people were online

This is not a parameter, but it can be computed from them. Setting the Gompertz curve to 50 and solving for \(t\):

\[t_{50} = m - s \log\!\big({-\log(50/A)}\big)\]

Its standard error comes from the delta method: the derivatives of the formula with respect to the parameters, and the covariance matrix of the estimates \(V\), give \(\sqrt{g^\top V g}\).

Code
t50   <- function(th) th[["m"]] - th[["s"]] * log(-log(50 / th[["A"]]))
slope <- function(th) th[["A"]] / (exp(1) * th[["s"]])          # the growth at the fastest moment
delta_se <- function(fun, fit, h = 1e-5) {
  th <- coef(fit)
  g  <- sapply(names(th), function(p) { up <- th; up[p] <- up[p] + h; (fun(up) - fun(th)) / h })
  sqrt(drop(t(g) %*% vcov(fit) %*% g))
}
derived <- rbind(t50        = c(estimate = t50(cG),   SE = delta_se(t50, gompertz)),
                 max_growth = c(estimate = slope(cG), SE = delta_se(slope, gompertz)))
derived <- cbind(
  derived,
  lower = derived[, 1] - 2 * derived[, 2],
  upper = derived[, 1] + 2 * derived[, 2]
)
derived
            estimate         SE     lower    upper
t50        10.713357 0.08768262 10.537992 10.88872
max_growth  4.341662 0.06687416  4.207914  4.47541

Half of the population was online 10.7 years after the start of 2000, that is around 2011. The growth was fastest around 2007, 4.3 points a year, 95% CI [4.2, 4.5].

The parameters are not independent

Code
cov2cor(vcov(gompertz))
          A         m         s
A 1.0000000 0.9132803 0.9129696
m 0.9132803 1.0000000 0.7873121
s 0.9129696 0.7873121 1.0000000

A higher ceiling can be traded for a later midpoint and a slower curve, with almost the same fit: the correlation of A with the other two is 0.91 and 0.91. Near 1 in absolute value, the data cannot separate them, and the search fails.


6. The test: could we have known in 2008?

In 2008 the share was 38.2%. Fit both curves to the years until then, and let them say what comes next:

Code
past   <- subset(greece, year <= 2008)
future <- subset(greece, year > 2008)
past_logistic <- nls(
  share ~ A / (1 + exp(-(t - m) / s)),
  data = past,
  start = list(A = 60, m = 5, s = 3)
)
past_gompertz <- nls(
  share ~ A * exp(-exp(-(t - m) / s)),
  data = past,
  start = list(A = 90, m = 7, s = 7)
)
early <- rbind(Logistic = coef(past_logistic), Gompertz = coef(past_gompertz))
early
                A        m        s
Logistic 50.48755 4.721393 2.784284
Gompertz 89.07385 6.537333 7.527445
Code
rmse <- c(Logistic = sqrt(mean((future$share - predict(past_logistic, future))^2)),
          Gompertz = sqrt(mean((future$share - predict(past_gompertz, future))^2)))
rmse
 Logistic  Gompertz 
22.082513  2.779562 
Code
ceiling_ci <- rbind(Logistic = confint(past_logistic)["A", ],      # profile intervals
                    Gompertz = confint(past_gompertz)["A", ])
ceiling_ci
             2.5%     97.5%
Logistic 43.97991  61.38468
Gompertz 65.17712 146.45275
Code
early_paths <- rbind(data.frame(grid, share = predict(past_logistic, grid), curve = "Logistic"),
                     data.frame(grid, share = predict(past_gompertz, grid), curve = "Gompertz"))

ggplot(greece, aes(year, share)) +
  geom_vline(xintercept = 2008.5, linetype = "dashed", colour = "grey50") +
  geom_line(data = early_paths, aes(colour = curve), linewidth = 1) +
  geom_point(size = 1.8, colour = "grey25") +
  annotate("text", x = 2008, y = 97, label = "fitted", hjust = 1, size = 3.3, colour = "grey30") +
  annotate(
    "text",
    x = 2009,
    y = 97,
    label = "predicted",
    hjust = 0,
    size = 3.3,
    colour = "grey30"
  ) +
  scale_colour_manual(values = curve_colours, name = NULL) +
  scale_y_continuous(limits = c(0, 100)) +
  labs(title = "Curves fitted to 1990–2008, continued", x = NULL, y = "% of the population") +
  theme_bw() +
  theme(legend.position = "bottom")

Forecast chart – 6. The test: could we have known in 2008?

The logistic curve, fitted to 2008, announced a ceiling of 50.5%, with a 95% confidence interval from 44.0 to 61.4. In 2024 the share was 86.3%. The Gompertz said 89.1%, and predicted the next 16 years with an error of 2.8 points, against 22.1.

Two lessons. First, the confidence interval is conditional on the curve. The interval of the logistic ceiling was honest about the noise and said nothing about being the wrong curve. Second, the ceiling is the hardest thing to estimate from an S-curve that has not yet bent: until 2008 the two curves fitted almost equally well (residual standard errors 1.0 and 0.9), and differed by 38.6 points about the future. The Gompertz was the better guess here. Nobody could have proved it in 2008. Forecasts of technology from early data are known to be this fragile (Meade & Islam, 2006).

This is also the case where the two kinds of interval disagree:

Code
est_A  <- early["Gompertz", "A"]
se_A   <- summary(past_gompertz)$coefficients["A", "Std. Error"]
wald_A <- est_A + c(-1, 1) * qt(0.975, df.residual(past_gompertz)) * se_A
c(estimate = est_A, SE = se_A, wald_low = wald_A[1], wald_high = wald_A[2],
  profile_low = ceiling_ci["Gompertz", 1], profile_high = ceiling_ci["Gompertz", 2])
    estimate           SE     wald_low    wald_high  profile_low profile_high 
    89.07385     16.55530     53.97819    124.16952     65.17712    146.45275 

By the Wald interval, the Gompertz ceiling of 2008 was between 54.0 and 124.2; by the profile, between 65.2 and 146.5. The profile is not symmetric: the data could rule out a low ceiling, but not a high one. A ceiling above 100% is impossible, and the model does not know it. If a limit is known, fix it (\(A = 100\)), or use a curve that contains it.


7. Comparing countries

The parameters mean the same thing everywhere, so they can be compared:

Code
countries <- c(Greece = "GRC", Germany = "DEU", `South Korea` = "KOR")
sets <- lapply(countries, internet)
fits <- lapply(sets, function(d) nls(share ~ A * exp(-exp(-(t - m) / s)), data = d,
                                     start = list(A = 90, m = 3, s = 5)))
country_table <- data.frame(
  country = names(countries),
  ceiling = sapply(fits, function(f) coef(f)[["A"]]),
  fastest = 2000 + sapply(fits, function(f) coef(f)[["m"]]),
  scale   = sapply(fits, function(f) coef(f)[["s"]]),
  growth  = sapply(fits, function(f) slope(coef(f))),
  sigma   = sapply(fits, sigma), row.names = NULL)
country_table
      country  ceiling  fastest    scale    growth    sigma
1      Greece 97.44043 2007.373 8.256356  4.341665 1.112229
2     Germany 88.88958 2000.447 3.610255  9.057712 2.380681
3 South Korea 92.28225 1999.736 3.167926 10.716393 4.716474
Code
obs  <- do.call(rbind, Map(function(d, n) data.frame(d, country = n), sets, names(sets)))
pred <- do.call(
  rbind,
  Map(
    function(f, n) data.frame(year = grid$year, share = predict(f, grid), country = n),
    fits,
    names(fits)
  )
)

ggplot(obs, aes(year, share, colour = country)) +
  geom_line(data = subset(pred, year <= 2025), linewidth = 1) +
  geom_point(size = 1.6) +
  scale_colour_manual(
    values = c(Greece = "#2a78d6", Germany = "#eb6834", `South Korea` = "#1baf7a"),
    name = NULL
  ) +
  labs(title = "The same curve, three countries", x = NULL, y = "% of the population") +
  theme_bw() +
  theme(legend.position = "bottom")

7. Comparing countries

South Korea was fastest around 2000 with 10.7 points a year, Germany around 2000 with 9.1, Greece around 2007 with 4.3. The curve fits Greece best: the residual standard error is 1.1 points for Greece, 2.4 for Germany and 4.7 for South Korea, where the points leave the curve visibly. One curve does not fit everybody. (For many countries together, with parameters that vary between them, see nlme::nlme(), the nonlinear form of the multilevel model.)


8. Things to keep in mind

  • Choose the curve from what you know, not from a catalog. Ceiling or no ceiling? Symmetric? Does it start at zero? A different curve is a different claim about the future.
  • Do not linearize by taking logs just to use lm(). A log changes the errors: it makes the relative errors equal, and it lets the years with 0.1% count as much as the years with 80%. Use it for starting values.
  • Local minima. The search stops at the bottom of a valley, which may not be the deepest. Start from several places, and look at the fitted curve.
  • The errors. Here they cannot be equally large everywhere: near 0 and near 100 there is no room for them. Residuals close to 0 in the first years, as in the chart of section 4, are the sign. Weights, or a model for proportions (a logistic GLM with a ceiling), would be the next step.
  • Time series. Years that follow each other are not independent. The standard errors assume they are. nlme::gnls() allows autocorrelated errors (compare generalized least squares).
  • Too many parameters. Each one needs data in the part of the curve that it describes. A ceiling needs points near the ceiling.
  • The measure changed from estimates to surveys, and the question of who counts as a user changed with it.

9. Reporting the results in APA style

A report (APA 7th edition) needs the equation, the meaning of the parameters and their units, the starting values and the software, the estimates with their intervals, and how the curve was chosen. The numbers come from the R objects:

Code
sG <- summary(gompertz)$coefficients
ciL <- confint(logistic)
sL <- summary(logistic)$coefficients
apa_table <- data.frame(
  Parameter = c(
    "Ceiling *A* (%)",
    "Time of fastest growth *m* (years since 2000)",
    "Scale *s* (years)"
  ),
  gE = f2(sG[, 1]),
  gS = f2(sG[, 2]),
  gC = paste0("[", f2(profile_ci[, 1]), ", ", f2(profile_ci[, 2]), "]"),
  lE = f2(sL[, 1]),
  lS = f2(sL[, 2]),
  lC = paste0("[", f2(ciL[, 1]), ", ", f2(ciL[, 2]), "]")
)

Method (data analysis):

We modeled the percentage of the population of Greece using the internet in 1990–2024 (N = 35 years; World Bank, 2026) with two three-parameter growth curves, the logistic, \(y = A/(1 + e^{-(t - m)/s})\), and the Gompertz, \(y = A\,e^{-e^{-(t - m)/s}}\), where t is the number of years since 2000, A the ceiling, m the time of fastest growth and s the scale. The curves were fitted by nonlinear least squares (Gauss–Newton), with starting values read from the chart, and compared with the AIC and with their forecasts for 2009–2024 when fitted to the years until 2008. Confidence intervals are profile intervals. Analyses were conducted in R (Version 4.6.2; R Core Team, 2026).

Results:

The Gompertz curve fitted better than the logistic (AIC = 111.6 against 156.9; residual SD = 1.1 against 2.1 percentage points; Table 1). By the Gompertz curve, the share approaches a ceiling of 97.4%, 95% CI [94.6, 100.6]. Growth was fastest in 2007, at 4.3 points per year, 95% CI [4.2, 4.5]. Fitted to the years until 2008 only, the Gompertz curve predicted 2009–2024 with a root mean squared error of 2.8 points, and the logistic with 22.1.

Table 1

Growth Curves for the Share of People Using the Internet in Greece

Parameter Gompertz SE 95% CI Logistic SE 95% CI
Ceiling A (%) 97.44 1.47 [94.60, 100.60] 85.79 1.42 [82.98, 88.96]
Time of fastest growth m (years since 2000) 7.37 0.17 [7.04, 7.74] 9.24 0.25 [8.74, 9.79]
Scale s (years) 8.26 0.23 [7.81, 8.74] 4.48 0.18 [4.14, 4.85]

Note. N = 35 years. Profile confidence intervals. Residual standard error: 1.11 (Gompertz) and 2.12 (logistic) percentage points, 32 degrees of freedom.

Points to remember:

  • Write the equation. “A logistic curve” has many forms, and the parameters depend on the form.
  • Give units for every parameter.
  • Say how you chose the starting values and that the search converged.
  • Do not report \(R^2\). Report the residual standard error, and show the curve with the points.
  • An interval for a ceiling that the data have not reached is a statement about the curve as much as about the data.

10. Summary

When Theory gives a curve whose parameters mean something: growth, decay, saturation, dose and response
Nonlinear A parameter sits inside a function; polynomials are linear
How (R) nls(y ~ A / (1 + exp(-(t - m)/s)), data, start = list(...)), or self-starting: nls(y ~ SSlogis(t, A, m, s), data)
The search Gauss–Newton: regress the residuals on the derivatives, step, repeat
If it fails singular gradient: better starting values, fewer parameters, minpack.lm::nlsLM()
Intervals confint() gives profile intervals; the delta method for quantities made from parameters
Comparing curves Nested: anova(). Not nested: AIC, residual plots, forecasts
Danger Extrapolation: the curve decides, not the data
Related pages Polynomial regression, generalized least squares

References

Bates, D. M., & Watts, D. G. (1988). Nonlinear regression analysis and its applications. Wiley. https://doi.org/10.1002/9780470316757

Geroski, P. A. (2000). Models of technology diffusion. Research Policy, 29(4–5), 603–625. https://doi.org/10.1016/S0048-7333(99)00092-X

Meade, N., & Islam, T. (2006). Modelling and forecasting the diffusion of innovation – A 25-year review. International Journal of Forecasting, 22(3), 519–545. https://doi.org/10.1016/j.ijforecast.2006.01.005

Spiess, A.-N., & Neumeyer, N. (2010). An evaluation of R² as an inadequate measure for nonlinear models in pharmacological and biochemical research: A Monte Carlo approach. BMC Pharmacology, 10, Article 6. https://doi.org/10.1186/1471-2210-10-6

Winsor, C. P. (1932). The Gompertz curve as a growth curve. Proceedings of the National Academy of Sciences, 18(1), 1–8. https://doi.org/10.1073/pnas.18.1.1

World Bank. (2026). Individuals using the Internet (% of population) [Data set]. World Development Indicators. https://data.worldbank.org/indicator/IT.NET.USER.ZS