Type: Package
Title: Universal Turning Point and Inflection Point Tests
Version: 1.0.3
Date: 2026-03-07
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-04-02 15:26:14 UTC; SYSTEM
Author: Muhammad Alkhalaf ORCID iD [aut, cre, cph]
Maintainer: Muhammad Alkhalaf <muhammedalkhalaf@gmail.com>
Repository: CRAN
Date/Publication: 2026-04-09 08:20:02 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:

Value

A data frame containing Environmental Kuznets Curve data with columns for income and emissions.

Source

Simulated data for demonstration purposes.

References

Grossman, G. M., & 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 Interval for Ratio of Coefficients

Description

Computes the Fieller (1954) confidence interval for the turning point, which is more appropriate when the denominator coefficient has high uncertainty.

Usage

fieller_ci(b1, b2, s11, s12, s22, level = 0.95, form = "quadratic")

Arguments

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")

Value

A list with elements lo, hi, and type.

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


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, cubic, log-quadratic, and inverse functional forms.

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
)

Arguments

model

A fitted model object (e.g., from lm, glm). Alternatively, coefficients can be provided directly via coefs.

vars

Character vector of length 2 or 3 specifying the variable names: c("x", "x_sq") for quadratic, c("x", "x_sq", "x_cu") for cubic.

coefs

Named numeric vector of coefficients. If provided, model is not required. Must include names matching vars.

vcov_mat

Variance-covariance matrix for the coefficients. Required when coefs is provided.

min

Lower bound of the data interval. If NULL, extracted from the model data.

max

Upper bound of the data interval. If NULL, extracted from the model data.

form

Functional form: "auto" (default), "quadratic", "cubic", "inverse", or "logquadratic".

level

Confidence level for intervals (default 0.95).

delta

Logical; compute delta-method SE and CI (default TRUE).

fieller

Logical; compute Fieller confidence interval (default FALSE).

twolines

Logical; perform Simonsohn (2018) two-lines test (default FALSE).

bootstrap

Logical; compute parametric bootstrap CI (default FALSE).

breps

Number of bootstrap replications (default 1000).

data

Optional data frame for two-lines test.

depvar

Name of dependent variable for two-lines test.

Details

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:

Value

An object of class "tptest" containing:

tp

Turning point estimate

tp_se

Delta-method standard error

tp_ci

Confidence interval for turning point

shape

Detected shape ("U shape" or "Inverse U shape")

model_form

Functional form used

sasabuchi

List with Sasabuchi test results

fieller

Fieller interval (if requested)

twolines

Two-lines test results (if requested)

bootstrap

Bootstrap results (if requested)

coefficients

Named vector of relevant coefficients

vcov

Variance-covariance matrix

bounds

Data interval bounds

References

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.

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
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)



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 = "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, ...)

Arguments

x

A tptest object

...

Additional arguments (currently ignored)

object

A tptest object

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)

Value

For print and summary: the input object, returned invisibly. For plot: no return value, called for side effects (generates plots).


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)

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)

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.