| 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.0.3 |
| Built: | 2026-05-28 07:21:59 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
A data frame containing Environmental Kuznets Curve data with columns for income and emissions.
Simulated data for demonstration purposes.
Grossman, G. M., & 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 interval for the turning point, which is more appropriate when the denominator coefficient has high uncertainty.
fieller_ci(b1, b2, s11, s12, s22, level = 0.95, form = "quadratic")fieller_ci(b1, b2, s11, s12, s22, level = 0.95, form = "quadratic")
b1 |
First coefficient |
b2 |
Second coefficient |
s11 |
Variance of b1 |
s12 |
Covariance of b1 and b2 |
s22 |
Variance of b2 |
level |
Confidence level |
form |
Functional form ("quadratic" or "inverse") |
A list with elements lo, hi, and type.
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
Tests for U-shaped or inverse U-shaped relationships using the Sasabuchi (1980) test as extended by Lind and Mehlum (2010). Supports quadratic, cubic, log-quadratic, and inverse functional forms.
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 )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 )
model |
A fitted model object (e.g., from |
vars |
Character vector of length 2 or 3 specifying the variable names:
|
coefs |
Named numeric vector of coefficients. If provided, |
vcov_mat |
Variance-covariance matrix for the coefficients. Required
when |
min |
Lower bound of the data interval. If |
max |
Upper bound of the data interval. If |
form |
Functional form: |
level |
Confidence level for intervals (default 0.95). |
delta |
Logical; compute delta-method SE and CI (default |
fieller |
Logical; compute Fieller confidence interval (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 for two-lines test. |
depvar |
Name of dependent variable for two-lines test. |
The function implements several approaches for testing non-monotonic relationships:
Sasabuchi (1980) / Lind-Mehlum (2010) Test: Tests whether the relationship is U-shaped (or inverse U-shaped) by examining slopes at the interval boundaries. The null hypothesis is monotonicity or opposite U-shape.
Functional Forms:
Quadratic: ; turning point at
Cubic: ; up to two turning points
Inverse: ; turning point at
Log-quadratic:
An object of class "tptest" containing:
Turning point estimate
Delta-method standard error
Confidence interval for turning point
Detected shape ("U shape" or "Inverse U shape")
Functional form used
List with Sasabuchi test results
Fieller interval (if requested)
Two-lines test results (if requested)
Bootstrap results (if requested)
Named vector of relevant coefficients
Variance-covariance matrix
Data interval bounds
Lind, J. T., & 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 result <- tptest(fit, vars = c("x", "x_sq"), data = dat) 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 result <- tptest(fit, vars = c("x", "x_sq"), data = dat) 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 = "x", 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 = "x", 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) |
For print and summary: the input object, returned invisibly. For plot: no return value, called for side effects (generates plots).
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) |
y_var |
Name of the y variable (character) |
split_point |
Point at which to split the data (usually the turning point) |
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.