| Title: | Universal Turning Point and Inflection Point Tests |
|---|---|
| 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>. |
| Authors: | Muhammad Alkhalaf [aut, cre, cph] (ORCID: <https://orcid.org/0009-0002-2677-9246>) |
| Maintainer: | Muhammad Alkhalaf <[email protected]> |
| License: | GPL-3 |
| Version: | 1.1.0 |
| Built: | 2026-11-01 08:29:39 UTC |
| Source: | https://github.com/muhammedalkhalaf/tptest |
Simulated data representing the Environmental Kuznets Curve (EKC) hypothesis, which posits an inverse U-shaped relationship between environmental degradation and economic development.
ekcekc
A data frame with 500 observations and 6 variables:
Country identifier (1-50)
Year (2000-2009)
GDP per capita (thousands of dollars)
Squared GDP per capita
CO2 emissions (tons per capita)
Log of CO2 emissions
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
Simulated data for demonstration purposes.
Grossman, G. M. and Krueger, A. B. (1995). Economic growth and the environment. Quarterly Journal of Economics, 110(2), 353-377.
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)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)
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).
fieller_ci(b1, b2, s11, s12, s22, level = 0.95, form = "quadratic", df = NULL)fieller_ci(b1, b2, s11, s12, s22, level = 0.95, form = "quadratic", df = NULL)
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: |
The set for the ratio of two coefficients is
,
whose boundary points are
with
.
For the quadratic form and ; for the
inverse form and , restricted to
.
A list with elements lo, hi and type:
"bounded"the set is the interval [lo, hi]. For the
inverse and log-quadratic forms lo = 0 means 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 at
level but the discriminant is positive.
"ray"the set is a half-line; one of lo, hi
is infinite (or lo = 0 for 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"form is not supported.
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
# 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)# 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)
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.
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 )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 )
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. |
Sasabuchi (1980) / Lind and Mehlum (2010) test.
With and monotone on
, a U shape is implied by
. The null
hypothesis (monotone or inverse U) is rejected at level when
both one-sided t-tests reject at level ; the overall statistic
is for a U shape and 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: ; turning point at
Inverse: ; turning point at
(requires ; gives a U shape,
an inverse U shape)
Log-quadratic: .
The regressors named in vars are and
and all computations are those of the quadratic form in .
The turning point is reported in levels, ,
with intervals transformed by . The bounds are on the
scale unless bounds_scale = "levels".
Cubic: .
Here 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
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
in sasabuchi$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) with
, and t_overall and p_overall are reported;
otherwise they are NA.
An object of class "tptest" containing:
Turning point estimate. For the log-quadratic form it is
reported in levels of , .
Delta-method standard error of tp
Delta-method confidence interval for the turning point. For
the log-quadratic form the interval is computed on the
scale and exponentiated.
Log-quadratic form only: turning point and its
delta-method SE on the scale.
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)
The alternative hypothesis tested by the Sasabuchi statistic ("U shape" or "Inverse U shape")
Functional form used
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 contains segments.
Fieller confidence set (if requested); see
fieller_ci
Two-lines test results (if requested)
Bootstrap results (if requested)
Named vector of relevant coefficients
Variance-covariance matrix
Interval bounds on the regressor scale
Log-quadratic form only: the bounds in levels of
Degrees of freedom used (NULL when the normal
distribution is used)
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.
# 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)# 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)
Print, summary, plot, and accessor methods for tptest objects.
## 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, ...)## 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, ...)
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) |
Performs the two-lines test proposed by Simonsohn (2018) as an alternative to quadratic regression for testing U-shaped relationships.
twolines_test(data, x_var, y_var, split_point, form = "quadratic")twolines_test(data, x_var, y_var, split_point, form = "quadratic")
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) |
A list with test results including slopes, t-values, p-values, and whether the test confirms the U-shape.
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.