DPredict · Guide test 181
PE test for linear versus log linear models
Tests whether a linear or logarithmic regression specification adequately encompasses the alternative.
Do it in CodeSplash
In the app, set it up in Analyze with this method:
- Compare non-nested models (J, Cox, encompassing, PE, Vuong) — Which of two rival regression models explains the outcome better, when neither contains the other?
In Compare non-nested models (J, Cox, encompassing, PE, Vuong), choose Comparison = Linear (A) against log-linear (B).
Do it in CodeSplash Run this test on your own data, in Python or R.
Bench
Change the design, drag the data, move α. The statistic, its reference distribution and the verdict follow.
Bench · PE test for linear versus log linear models
0 makes log y linear in log x.
Your data
Simulated with a known ρIf H₀ were true
- The reference: how t varies across samples when H₀ is true.
- Your statistic, from the data above.
- The p-value: the area at least as extreme as yours (p = < .001).
- The hatched rejection region at α = .050: statistics landing here reject H₀.
The formula
With your numbers
- fitted values of the linear model y ~ x
- fitted values of the log-linear model
The verdict
t(57) = 4.55, p < .001
p ≤ α = .050: reject H₀
Rejecting says the log-linear form misses curvature the linear fit captures; the reverse direction tests the linear model.
- Statistic
- 4.545
- p-value
- 0.0000
PE test for linear versus log linear models on 60 (x, y) pairs: t(57) = 4.55, p < .001. The p-value is below α = .050, so the data are hard to reconcile with H₀.
Question and hypotheses
H0: the chosen linear or log-linear functional form is adequate relative to its rival.
Assumptions
Positive response and, when taking log fitted values, positive predictions; regular auxiliary regressions on the same observations.
Formula
Parameters and notation
ŷ is the level-model fit and fitted log y comes from the log model. First test γ=0; reverse test δ=0.
Structure of the method
Fit a level-response regression and a log-response regression. Construct auxiliary differences between log fitted values for the level model and between level-scale fitted values for the log model, then test the corresponding added coefficient in each direction. The transformations are the defining PE construction.
Estimated and nuisance parameters
Both regression coefficient vectors, their fitted responses, auxiliary coefficients, and covariance matrices are estimated. Exponentiated log predictions are mathematical inputs to this test and are not automatically unbiased estimates of the conditional arithmetic mean.
Settings and design choices
Prespecify the level/log regressors, positive-domain restrictions, sample inclusion, comparison direction, and classical or robust covariance. Verify positivity of observed responses and of any level-model predictions whose logarithms are taken. Clipping negative predictions changes the procedure and should not be silent.
Fitting and adaptation
Fit the two specifications on identical usable observations, generate the documented auxiliary variable, and refit the augmented regression. Any transformation selected from many alternatives needs separate validation. When a log model is adopted for prediction, handle retransformation bias through a justified predictive method rather than assuming the PE test resolves it.
Sensitivity and robustness
Extreme scale differences, nonpositive fits, heteroskedasticity, influential points, and small samples can destabilize the auxiliary tests. Both level and log forms can be inadequate. The test does not identify the best transformation among all possibilities, and a favorable p-value is not evidence that the chosen model is calibrated out of sample.
How to use and calibrate
Use the documented PE auxiliary t/Wald tests, with suitable covariance estimates.
Example application
Assess whether a response relationship is better represented in levels or logs.
Interpretation and pitfalls
Watch out
Exponentiating predicted log outcomes is not generally an unbiased prediction of mean outcomes. Both forms can be inadequate.
What changed in edition 2
- New sections: structure of the method, estimated and nuisance parameters, settings and design choices, fitting and adaptation, sensitivity and robustness.
Python and R
Positive response and predictor. Compares linear and log-linear specifications with different dependent-variable transformations.
Not run — Executed end to end through Rscript · needs Python standard library + Rscript; R packages: lmtest
# Python launcher for the complete R implementation below.
# Requires Rscript on PATH and the listed R packages.
import shutil
import subprocess
rscript = shutil.which("Rscript")
if rscript is None:
raise RuntimeError("Install R and make Rscript available on PATH.")
r_code = r"""
set.seed(2026)
x<-exp(rnorm(100));y<-exp(.5+.3*log(x)+rnorm(100,.0,.2));d<-data.frame(x,y)
print(lmtest::petest(y~x,log(y)~log(x),data=d))
"""
# No shell interpolation. A failed R execution raises an error in Python.
result = subprocess.run([rscript, "--vanilla", "-"], input=r_code,
text=True, capture_output=True)
print(result.stdout)
if result.stderr:
print(result.stderr)
result.check_returncode()
Validated — Executed successfully in the validation environment · needs lmtest
set.seed(2026)
x<-exp(rnorm(100));y<-exp(.5+.3*log(x)+rnorm(100,.0,.2));d<-data.frame(x,y)
print(lmtest::petest(y~x,log(y)~log(x),data=d))
Output
PE test
Model 1: y ~ x
Model 2: log(y) ~ log(x)
Estimate Std. Error t value Pr(>|t|)
M1 + log(fit(M1))-fit(M2) -1.76775 0.26558 -6.6563 1.682e-09 ***
M2 + fit(M1)-exp(fit(M2)) -0.15766 0.13064 -1.2068 0.2304
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1Sources
- lmtest — lmtest · petestAuthor documentation/source reviewed: lmtest 0.9-40.search.r-project.org
- petestsearch.r-project.org
- Statistics guide v4 (historical):
- Python: Executed end to end through Rscript · R: Executed successfully in the validation environment
- Reference's record:
- Edition 2 review: Python: skip · R: not executed (Rscript unavailable); why not run: Python: Python-to-R bridge; Rscript is unavailable. R code was not executed. Python: Not run in the reference's review: Python-to-R bridge; Rscript is unavailable. R code was not executed. R: Reviewed but not run: R wasn't available to the reference's authors.
From the CodeSplash statistics guide (v4), entry 181, updated from the reference's edition 2 (reviewed 14 November 2026) as STAT181.