Package {tptest}


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 ORCID iD [aut, cre, cph]
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:

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 (\beta_1)

b2

Second coefficient (\beta_2)

s11

Variance of b1

s12

Covariance of b1 and b2

s22

Variance of b2

level

Confidence level (two-sided). Lind and Mehlum (2010) note that the test of a U shape at level \alpha corresponds to checking whether the 1 - 2\alpha interval lies inside the data range.

form

Functional form: "quadratic" (x^* = -b_1/(2 b_2)), "inverse" (x^* = \sqrt{b_2/b_1}), or "logquadratic" (x^* = \exp(-b_1/(2 b_2))).

df

Degrees of freedom for the critical value: NULL (default) uses the normal distribution, a finite number uses t(df).

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

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 lm, glm, plm::plm). Alternatively, coefficients can be provided directly via coefs.

vars

Character vector of length 2 or 3 giving the names of the coefficients of the regressors that carry the curvature, in this order: c("x", "x_sq") for the quadratic form, c("x", "x_inv") (the regressors x and 1/x) for the inverse form, c("lnx", "lnx_sq") (the regressors \ln x and (\ln x)^2) for the log-quadratic form, and c("x", "x_sq", "x_cu") for the cubic form. The first name is also used to look up the regressor column when the data range is determined automatically.

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 interval [x_l, x_h] on which the test is carried out. If NULL, the minimum of the regressor named in vars[1] over the estimation sample is used. See bounds_scale for the scale of this argument.

max

Upper bound of the interval; see min.

form

Functional form: "auto" (default), "quadratic", "cubic", "inverse", or "logquadratic". With "auto", two names in vars select the quadratic form and three names select the cubic form.

level

Confidence level for intervals (default 0.95). The Sasabuchi test itself does not depend on level.

delta

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

fieller

Logical; compute Fieller confidence set (default FALSE). Available for the quadratic, inverse and log-quadratic forms.

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: the data used to fit model. It is required for the two-lines test and is used as a fallback to determine the data range when the regressor cannot be recovered from the model frame (rows dropped by the model's na.action are then excluded).

depvar

Name of dependent variable for two-lines test.

bounds_scale

Scale on which user-supplied min and max are given. "regressor" (default): the scale of the regressor named in vars[1], that is x for the quadratic, inverse and cubic forms and \ln x for the log-quadratic form. "levels": only meaningful for the log-quadratic form, min and max are given in levels of x and are log-transformed internally. The automatic range is always taken on the regressor scale.

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. NULL (default) selects automatically: the residual degrees of freedom of the model for lm-type models (including plm), and the normal distribution for glm objects, for models without df.residual, and for the coefs path. Inf forces the normal distribution; a finite number forces t(df).

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:

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 x scale and exponentiated.

tp_log, tp_log_se

Log-quadratic form only: turning point and its delta-method SE on the \ln x scale.

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 contains segments.

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 (NULL when 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 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)


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 \ln x column, the regressor used in the model.

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 x, as returned by tptest, and the split is made at log(split_point) on the \ln x column.

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.