| Type: | Package |
| Title: | Universal Turning Point and Inflection Point Tests |
| Version: | 1.1.0 |
| Date: | 2026-09-30 |
| Description: | Performs turning point and inflection point tests for U-shaped and inverse U-shaped relationships in regression models. Implements the Sasabuchi (1980) test as extended by Lind and Mehlum (2010) with support for quadratic, cubic, log-quadratic, and inverse functional forms. Features include delta-method standard errors, Fieller confidence intervals, Simonsohn (2018) two-lines test, and parametric bootstrap. Designed for post-estimation analysis of linear models, panel models, and quantile regression. References: Lind and Mehlum (2010) <doi:10.1111/j.1468-0084.2009.00569.x>; Sasabuchi (1980); Fieller (1954) <doi:10.1111/j.2517-6161.1954.tb00159.x>. |
| License: | GPL-3 |
| URL: | https://github.com/muhammedalkhalaf/tptest |
| BugReports: | https://github.com/muhammedalkhalaf/tptest/issues |
| Encoding: | UTF-8 |
| LazyData: | true |
| RoxygenNote: | 7.3.3 |
| Depends: | R (≥ 4.0.0) |
| Imports: | stats, graphics |
| Suggests: | testthat (≥ 3.0.0), knitr, rmarkdown, lmtest, sandwich, plm, quantreg |
| NeedsCompilation: | no |
| Packaged: | 2026-09-30 23:01:26 UTC; root |
| Author: | Muhammad Alkhalaf |
| Maintainer: | Muhammad Alkhalaf <muhammedalkhalaf@gmail.com> |
| Repository: | CRAN |
| Date/Publication: | 2026-10-01 08:30:15 UTC |
Environmental Kuznets Curve Data
Description
Simulated data representing the Environmental Kuznets Curve (EKC) hypothesis, which posits an inverse U-shaped relationship between environmental degradation and economic development.
Usage
ekc
Format
A data frame with 500 observations and 6 variables:
- country
Country identifier (1-50)
- year
Year (2000-2009)
- gdp
GDP per capita (thousands of dollars)
- gdp_sq
Squared GDP per capita
- emissions
CO2 emissions (tons per capita)
- emissions_log
Log of CO2 emissions
Details
This is simulated panel data designed to demonstrate the tptest package. The true data generating process follows an inverse U-shape with:
Turning point at GDP ~ 25,000 USD per capita
Country-specific fixed effects
Year-specific trends
Source
Simulated data for demonstration purposes.
References
Grossman, G. M. and Krueger, A. B. (1995). Economic growth and the environment. Quarterly Journal of Economics, 110(2), 353-377.
Examples
data(ekc)
head(ekc)
# Fit quadratic model
fit <- lm(emissions ~ gdp + gdp_sq, data = ekc)
summary(fit)
# Test for inverse U-shape
result <- tptest(fit, vars = c("gdp", "gdp_sq"), data = ekc)
print(result)
Fieller Confidence Set for the Turning Point
Description
Computes the Fieller (1954) confidence set for the turning point, which is exact for linear models and remains informative when the denominator coefficient is imprecisely estimated (Lind and Mehlum 2010, equation 8).
Usage
fieller_ci(b1, b2, s11, s12, s22, level = 0.95, form = "quadratic", df = NULL)
Arguments
b1 |
First coefficient ( |
b2 |
Second coefficient ( |
s11 |
Variance of |
s12 |
Covariance of |
s22 |
Variance of |
level |
Confidence level (two-sided). Lind and Mehlum (2010) note
that the test of a U shape at level |
form |
Functional form: |
df |
Degrees of freedom for the critical value: |
Details
The set for the ratio \rho = n/d of two coefficients is
\{\rho : (n - \rho d)^2 \le T^2 (s_{nn} - 2 \rho s_{nd} + \rho^2 s_{dd})\},
whose boundary points are
(n d - T^2 s_{nd} \pm T \sqrt{D}) / (d^2 - T^2 s_{dd}) with
D = (s_{nd}^2 - s_{nn} s_{dd}) T^2 + d^2 s_{nn} + n^2 s_{dd} - 2 n d s_{nd}.
For the quadratic form \rho = b_1/b_2 and x^* = -\rho/2; for the
inverse form \rho = b_2/b_1 and x^* = \sqrt{\rho}, restricted to
\rho > 0.
Value
A list with elements lo, hi and type:
"bounded"the set is the interval
[lo, hi]. For the inverse and log-quadratic formslo = 0means the set is(0, hi]."two_rays"the set is the union of two rays,
(-Inf, lo]and[hi, Inf)((0, lo]and[hi, Inf)for the inverse and log-quadratic forms). This happens when the denominator coefficient is not significant atlevelbut the discriminant is positive."ray"the set is a half-line; one of
lo,hiis infinite (orlo = 0for the positive forms)."unbounded"the set is the whole real line (whole positive line for the inverse and log-quadratic forms).
"empty"inverse form only: no positive turning point is compatible with the data at
level."not_applicable"formis not supported.
References
Fieller, E. C. (1954). Some problems in interval estimation. Journal of the Royal Statistical Society: Series B, 16(2), 175-185. doi:10.1111/j.2517-6161.1954.tb00159.x
Lind, J. T. and Mehlum, H. (2010). With or without U? The appropriate test for a U-shaped relationship. Oxford Bulletin of Economics and Statistics, 72(1), 109-118. doi:10.1111/j.1468-0084.2009.00569.x
Examples
# Quadratic: b1 = -6, b2 = 0.55 with a precise b2 gives a bounded interval
fieller_ci(-6, 0.55, s11 = 0.04, s12 = -0.003, s22 = 0.0004, level = 0.95)
# Same with t(120) critical value
fieller_ci(-6, 0.55, s11 = 0.04, s12 = -0.003, s22 = 0.0004, df = 120)
# b2 not significant at 5 percent: the set is the union of two rays
fieller_ci(-2, 0.15, s11 = 0.5, s12 = -0.05, s22 = 0.01)
Universal Turning Point and Inflection Point Test
Description
Tests for U-shaped or inverse U-shaped relationships using the Sasabuchi (1980) test as extended by Lind and Mehlum (2010). Supports quadratic, inverse and log-quadratic functional forms, and a cubic form with a segment-wise extension of the test.
Usage
tptest(
model = NULL,
vars,
coefs = NULL,
vcov_mat = NULL,
min = NULL,
max = NULL,
form = c("auto", "quadratic", "cubic", "inverse", "logquadratic"),
level = 0.95,
delta = TRUE,
fieller = FALSE,
twolines = FALSE,
bootstrap = FALSE,
breps = 1000,
data = NULL,
depvar = NULL,
bounds_scale = c("regressor", "levels"),
df = NULL
)
Arguments
model |
A fitted model object (e.g., from |
vars |
Character vector of length 2 or 3 giving the names of the
coefficients of the regressors that carry the curvature, in this order:
|
coefs |
Named numeric vector of coefficients. If provided, |
vcov_mat |
Variance-covariance matrix for the coefficients. Required
when |
min |
Lower bound of the interval |
max |
Upper bound of the interval; see |
form |
Functional form: |
level |
Confidence level for intervals (default 0.95). The
Sasabuchi test itself does not depend on |
delta |
Logical; compute delta-method SE and CI (default |
fieller |
Logical; compute Fieller confidence set (default |
twolines |
Logical; perform Simonsohn (2018) two-lines test (default |
bootstrap |
Logical; compute parametric bootstrap CI (default |
breps |
Number of bootstrap replications (default 1000). |
data |
Optional data frame: the data used to fit |
depvar |
Name of dependent variable for two-lines test. |
bounds_scale |
Scale on which user-supplied |
df |
Degrees of freedom for the t distribution used in the one-sided
tests and in the critical values of the delta-method and Fieller
intervals. |
Details
Sasabuchi (1980) / Lind and Mehlum (2010) test.
With y = \beta x + \gamma f(x) and f' monotone on
[x_l, x_h], a U shape is implied by
\beta + \gamma f'(x_l) < 0 < \beta + \gamma f'(x_h). The null
hypothesis (monotone or inverse U) is rejected at level \alpha when
both one-sided t-tests reject at level \alpha; the overall statistic
is \min(-t_l, t_h) for a U shape and \min(t_l, -t_h) for an
inverse U shape, and its p-value is the upper tail probability of that
minimum. The alternative (U or inverse U) is chosen from the sign of the
change of the slope across the interval. When the fitted extremum lies
outside the interval the statistic is negative and the null hypothesis
cannot be rejected; the statistic and its p-value are still reported.
The reported p_min and p_max are the one-sided p-values of
the two component tests under the tested alternative.
Distribution. The t distribution with the model's residual
degrees of freedom is used for lm-type models. For generalized
linear models the test is only asymptotically valid (Lind and Mehlum 2010,
Section 2), so the normal distribution is used; the same applies to the
coefs path. The same distribution is used for the delta-method and
Fieller critical values; see argument df.
Functional forms:
-
Quadratic:
y = \beta_1 x + \beta_2 x^2; turning point atx^* = -\beta_1 / (2\beta_2) -
Inverse:
y = \beta_1 x + \beta_2 / x; turning point atx^* = \sqrt{\beta_2 / \beta_1}(requires\beta_2/\beta_1 > 0;\beta_1 > 0gives a U shape,\beta_1 < 0an inverse U shape) -
Log-quadratic:
y = \beta_1 \ln x + \beta_2 (\ln x)^2. The regressors named invarsare\ln xand(\ln x)^2and all computations are those of the quadratic form in\ln x. The turning point is reported in levels,x^* = \exp(-\beta_1/(2\beta_2)), with intervals transformed by\exp. The bounds are on the\ln xscale unlessbounds_scale = "levels". -
Cubic:
y = \beta_1 x + \beta_2 x^2 + \beta_3 x^3. Heref'is not monotone on an interval containing the inflection point, so the two-endpoint test of Lind and Mehlum (2010) does not apply to the whole interval (their footnote 3). As a package extension, the interval is split at the inflection point-\beta_2/(3\beta_3)when it lies inside, and the two-endpoint test is applied on each sub-interval, on which the slope is monotone. The results are returned insasabuchi$segments. The split point is the estimated inflection point, treated as fixed, so the sub-interval tests do not have the exact size of the test in the paper; this extension is not part of Lind and Mehlum (2010). When the inflection point lies outside the interval the slope is monotone on the whole interval, the single segment is the test of equation (9) of Lind and Mehlum (2010) withH = 3, andt_overallandp_overallare reported; otherwise they areNA.
Value
An object of class "tptest" containing:
- tp
Turning point estimate. For the log-quadratic form it is reported in levels of
x,\exp(-b_1/(2 b_2)).- tp_se
Delta-method standard error of
tp- tp_ci
Delta-method confidence interval for the turning point. For the log-quadratic form the interval is computed on the
\ln xscale and exponentiated.- tp_log, tp_log_se
Log-quadratic form only: turning point and its delta-method SE on the
\ln xscale.- shape
Description of the fitted curve on the interval: "U shape", "Inverse U shape", or a monotone label when the extremum lies outside the interval (cubic form: see Details)
- alternative
The alternative hypothesis tested by the Sasabuchi statistic ("U shape" or "Inverse U shape")
- model_form
Functional form used
- sasabuchi
List with the Sasabuchi test results: slopes and t-statistics at the bounds, one-sided p-values, the overall statistic and its p-value, and a logical
outside(extremum outside the interval). For the cubic form it also containssegments.- fieller
Fieller confidence set (if requested); see
fieller_ci- twolines
Two-lines test results (if requested)
- bootstrap
Bootstrap results (if requested)
- coefficients
Named vector of relevant coefficients
- vcov
Variance-covariance matrix
- bounds
Interval bounds on the regressor scale
- bounds_levels
Log-quadratic form only: the bounds in levels of
x- df
Degrees of freedom used (
NULLwhen the normal distribution is used)
References
Lind, J. T. and Mehlum, H. (2010). With or without U? The appropriate test for a U-shaped relationship. Oxford Bulletin of Economics and Statistics, 72(1), 109-118. doi:10.1111/j.1468-0084.2009.00569.x
Sasabuchi, S. (1980). A test of a multivariate normal mean with composite hypotheses determined by linear inequalities. Biometrika, 67(2), 429-439.
Fieller, E. C. (1954). Some problems in interval estimation. Journal of the Royal Statistical Society: Series B, 16(2), 175-185. doi:10.1111/j.2517-6161.1954.tb00159.x
Simonsohn, U. (2018). Two lines: A valid alternative to the invalid testing of U-shaped relationships with quadratic regressions. Advances in Methods and Practices in Psychological Science, 1(4), 538-555.
Examples
# Simulate data with U-shaped relationship
set.seed(42)
n <- 200
x <- runif(n, 1, 10)
y <- 50 - 8*x + 0.5*x^2 + rnorm(n, sd = 5)
dat <- data.frame(y = y, x = x, x_sq = x^2)
# Fit quadratic model
fit <- lm(y ~ x + x_sq, data = dat)
# Test for U-shape (data range taken from the estimation sample)
result <- tptest(fit, vars = c("x", "x_sq"))
print(result)
# With Fieller interval and two-lines test
result2 <- tptest(fit, vars = c("x", "x_sq"),
fieller = TRUE, twolines = TRUE,
data = dat, depvar = "y")
summary(result2)
Methods for tptest Objects
Description
Print, summary, plot, and accessor methods for tptest objects.
Usage
## S3 method for class 'tptest'
print(x, ...)
## S3 method for class 'tptest'
summary(object, ...)
## S3 method for class 'tptest'
plot(
x,
main = NULL,
xlab = NULL,
ylab = "Marginal Effect",
col.line = "steelblue",
col.tp = "red",
col.ci = grDevices::rgb(0.2, 0.4, 0.8, 0.2),
lwd = 2,
n = 200,
...
)
## S3 method for class 'tptest'
coef(object, ...)
## S3 method for class 'tptest'
confint(object, parm = NULL, level = NULL, ...)
Arguments
x |
A |
... |
Additional arguments (currently ignored) |
object |
A |
main |
Plot title |
xlab |
X-axis label |
ylab |
Y-axis label |
col.line |
Color for the fitted curve |
col.tp |
Color for the turning point marker |
col.ci |
Color for confidence band |
lwd |
Line width |
n |
Number of points for plotting curve |
parm |
Parameter specification (currently ignored) |
level |
Confidence level (default uses level from tptest object) |
Simonsohn (2018) Two-Lines Test
Description
Performs the two-lines test proposed by Simonsohn (2018) as an alternative to quadratic regression for testing U-shaped relationships.
Usage
twolines_test(data, x_var, y_var, split_point, form = "quadratic")
Arguments
data |
Data frame containing the variables |
x_var |
Name of the x variable (character). For the log-quadratic
form this is the |
y_var |
Name of the y variable (character) |
split_point |
Point at which to split the data (usually the turning
point). For the log-quadratic form it is given in levels of |
form |
Functional form (for log-quadratic, split is in log-space) |
Value
A list with test results including slopes, t-values, p-values, and whether the test confirms the U-shape.
References
Simonsohn, U. (2018). Two lines: A valid alternative to the invalid testing of U-shaped relationships with quadratic regressions. Advances in Methods and Practices in Psychological Science, 1(4), 538-555.