Type: Package
Title: Panel Data Pre-Testing and Diagnostic Suite
Version: 1.0.5
Description: Pre-testing and diagnostic tools for panel data analysis. Researchers should run these tests before any panel regression to verify modelling assumptions. The package implements: (1) the Hsiao (2014, <ISBN:978-1-107-65763-2>) homogeneity F-tests (F1/F2/F3), Swamy (1970) <doi:10.2307/1913012> parameter heterogeneity test, and Pesaran (2004) <doi:10.2139/ssrn.572504> cross-sectional dependence test via xtpretest(); (2) missing-data detection, mechanism testing, and imputation for unbalanced panels via xtmispanel(); (3) quantile-regression cross-sectional dependence tests (T_tau and T-tilde_tau statistics) of Demetrescu, Hosseinkouchack and Rodrigues (2023) <doi:10.1016/j.jeconom.2022.09.001> via xtcsdq(); and (4) the panel quantile-regression slope homogeneity S-hat and D-hat statistics of Galvao, Juhl, Montes-Rojas and Olmo (2017) <doi:10.1080/07350015.2015.1054493> via xtqsh(). Together these tests address three fundamental pre-testing questions: (i) are slopes homogeneous? (ii) is there cross-sectional dependence? and (iii) is the panel balanced and is missingness ignorable?
License: GPL-3
Encoding: UTF-8
RoxygenNote: 7.3.3
Depends: R (≥ 3.5.0)
Imports: stats, utils
Suggests: testthat (≥ 3.0.0), plm, zoo, quantreg
Config/testthat/edition: 3
NeedsCompilation: no
Packaged: 2026-04-29 17:22:26 UTC; acad_
Author: Muhammad Abdullah Alkhalaf ORCID iD [aut, cre, cph]
Maintainer: Muhammad Abdullah Alkhalaf <muhammedalkhalaf@gmail.com>
Repository: CRAN
Date/Publication: 2026-05-04 11:30:03 UTC

Print method for xtcsdq objects

Description

Print method for xtcsdq objects

Usage

## S3 method for class 'xtcsdq'
print(x, ...)

Arguments

x

An object of class "xtcsdq".

...

Additional arguments (ignored).

Value

Invisibly returns x.


Print Method for xtqsh Objects

Description

Prints a formatted summary of an "xtqsh" test result.

Usage

## S3 method for class 'xtqsh'
print(x, ...)

Arguments

x

An object of class "xtqsh".

...

Additional arguments (ignored).

Value

Invisibly returns x.


Sample Panel Dataset for Quantile Slope Homogeneity Testing

Description

A simulated balanced panel dataset for demonstrating the quantile slope homogeneity test (xtqsh).

Usage

data(qsh_sample)

Format

A data frame with columns:

id

Cross-sectional unit identifier.

time

Time period identifier.

y

Dependent variable.

x1

First explanatory variable.

x2

Second explanatory variable.


Summary method for xtcsdq objects

Description

Summary method for xtcsdq objects

Usage

## S3 method for class 'xtcsdq'
summary(object, ...)

Arguments

object

An object of class "xtcsdq".

...

Additional arguments (ignored).

Value

Invisibly returns object.


Summary Method for xtqsh Objects

Description

Prints a summary of an "xtqsh" test result.

Usage

## S3 method for class 'xtqsh'
summary(object, ...)

Arguments

object

An object of class "xtqsh".

...

Additional arguments (ignored).

Value

Invisibly returns object.


Tests of No Cross-Sectional Dependence in Panel Quantile Regressions

Description

Tests the null hypothesis of no cross-sectional error dependence (CSD) in panel quantile regressions. Implements the T_tau and T-tilde_tau statistics of Demetrescu, Hosseinkouchack and Rodrigues (2023).

Usage

xtcsdq(
  formula = NULL,
  data = NULL,
  index = NULL,
  quantiles,
  mode = c("pooled", "individual", "residuals"),
  residuals = NULL,
  bandwidth = NULL,
  correction = TRUE
)

Arguments

formula

A formula of the form y ~ x1 + x2 + .... Required for mode = "pooled" (default) and mode = "individual". Not used when residuals is provided.

data

A data frame containing the panel data in long format. Required unless residuals is provided.

index

A character vector of length 2: c("id_var", "time_var"). Required unless residuals is provided.

quantiles

A numeric vector of quantile levels, each strictly between 0 and 1.

mode

Estimation mode: "pooled" (default, pooled FE-QR), "individual" (per-unit QR), or "residuals" (provide pre-computed residuals via the residuals argument).

residuals

A list (or named list) of numeric vectors or a matrix with one column per quantile, containing pre-computed QR residuals. Only used when mode = "residuals".

bandwidth

Numeric. KDE bandwidth for sparsity estimation. If NULL (default), uses 0.35 (NT)^{-0.2}.

correction

Logical. If TRUE (default), reports the bias-corrected T-tilde statistic in addition to T_tau.

Details

The T_tau statistic (Equation 3 in Demetrescu et al., 2023) tests for CSD by examining pairwise correlations of demeaned QR residuals across units. Under the null of no CSD, T_tau is asymptotically standard normal.

The bias-corrected version T-tilde_tau (Equation 5) subtracts two correction terms that account for the estimation uncertainty in the QR slope and the sparsity at the quantile. Reject H0 for large positive values.

The portmanteau statistic M_K = K^{-1} \sum_{q=1}^K T_\tau^{(q)} aggregates across K quantile levels.

The KDE bandwidth defaults to h = 0.35 (NT)^{-0.2} as in the original paper.

Value

An object of class "xtcsdq" with components:

T_tau

Numeric vector of T_tau statistics (one per quantile).

Ttilde_tau

Numeric vector of bias-corrected T-tilde_tau statistics.

pval_T

p-values for T_tau.

pval_Ttilde

p-values for T-tilde_tau.

fhat

KDE density estimates at zero (one per quantile).

M_K

Portmanteau statistic (average of T_tau over quantiles).

Mtilde_K

Bias-corrected portmanteau statistic.

pval_M

p-value for M_K.

pval_Mc

p-value for Mtilde_K.

quantiles

Quantile levels used.

N

Number of cross-sectional units.

TT

Number of time periods.

bandwidth

KDE bandwidth used.

References

Demetrescu, M., Hosseinkouchack, M. and Rodrigues, P.M.M. (2023). Testing for No Cross-Sectional Error Dependence in Panel Quantile Regressions. Ruhr Economic Papers, No. 1041. doi:10.4419/96973002

Examples


set.seed(42)
n <- 8; tt <- 20
dat <- data.frame(
  id   = rep(1:n, each = tt),
  time = rep(1:tt, times = n),
  y    = rnorm(n * tt),
  x1   = rnorm(n * tt)
)
res <- xtcsdq(y ~ x1, data = dat, index = c("id", "time"),
              quantiles = c(0.25, 0.5, 0.75))
print(res)
summary(res)



Missing Data Detection and Imputation for Panel Data

Description

Detects, diagnoses, and imputes missing values in panel (longitudinal) data sets. The function can produce summary tables (Module 1), test the missingness mechanism (Module 2), impute a target variable (Module 3), and run a cross-method sensitivity analysis (Module 4).

Usage

xtmispanel(
  data,
  vars = NULL,
  index,
  detect = TRUE,
  test = FALSE,
  impute = NULL,
  target = NULL,
  new_var = NULL,
  sensitivity = FALSE,
  knn_k = 5L
)

Arguments

data

A data.frame in long format.

vars

Character vector of variable names to analyse. If NULL (default), all numeric columns except the index are used.

index

Character vector of length 2: c("panel_id", "time_id").

detect

Logical. Run Module 1 (detection tables, default TRUE).

test

Logical. Run Module 2 (MCAR/MAR mechanism tests, default FALSE).

impute

Character or NULL. If a method name is given, run Module 3 (imputation). Supported methods: "mean", "median", "locf", "nocb", "linear", "spline", "pmm", "hotdeck", "knn", "rf", "em".

target

Character. Name of the variable to impute (required when impute is not NULL).

new_var

Character. Name of the output imputed variable (default "\{target\}_imp").

sensitivity

Logical. Run Module 4 (sensitivity analysis across all imputation methods, default FALSE).

knn_k

Integer. Number of neighbours for KNN imputation (default 5).

Value

A list (invisibly) with components:

detect

Summary statistics per variable/panel/period.

test

MCAR and MAR test results.

imputed

The data frame augmented with the imputed column (when imputation is requested).

impute_stats

Summary comparing original vs imputed.

sensitivity

Sensitivity analysis results.

References

Little, R. J. A. (1988). A test of missing completely at random for multivariate data with missing values. Journal of the American Statistical Association, 83(404), 1198-1202. doi:10.1080/01621459.1988.10478714

Examples

set.seed(1)
df <- data.frame(
  id   = rep(1:4, each = 8),
  time = rep(1:8, times = 4),
  y    = c(rnorm(32))
)
# introduce some NAs
df$y[c(3, 11, 20)] <- NA
res <- xtmispanel(df, vars = "y", index = c("id", "time"), detect = TRUE)

Comprehensive Panel Data Pre-Testing Suite

Description

Performs a full battery of panel data pre-tests: Hsiao (2014) homogeneity F-tests, robust (HC1) versions, Swamy (1970) parameter heterogeneity test, cross-sectional dependence (Pesaran 2004), and panel summary statistics.

Usage

xtpretest(
  data,
  formula,
  index,
  tests = "ALL",
  level = 0.05
)

Arguments

data

A data.frame in long format containing all variables.

formula

A two-sided formula of the form y ~ x1 + x2 + ... specifying the dependent and independent variables.

index

Character vector of length 2: c("panel_id", "time_id").

tests

Character vector. Which modules to run. Possible values: "summary", "hsiao", "robust", "heterogeneity", "csd". Default "ALL" runs everything.

level

Numeric. Significance level for decisions (default 0.05).

Value

A list (invisibly) with components:

summary

Panel summary statistics.

hsiao

Hsiao homogeneity F-test results.

robust

Robust HC1 F-test results.

swamy

Swamy heterogeneity test results.

csd

Cross-sectional dependence test results.

recommendation

Character. Suggested estimator.

References

Hsiao, C. (2014). Analysis of Panel Data (3rd ed.). Cambridge University Press. doi:10.1017/CBO9781139839327

Swamy, P. A. V. B. (1970). Efficient inference in a random coefficient regression model. Econometrica, 38(2), 311-323. doi:10.2307/1909405

Pesaran, M. H. (2004). General diagnostic tests for cross section dependence in panels. Cambridge Working Paper in Economics, No. 0435. doi:10.2139/ssrn.572504

Examples

set.seed(10)
n <- 5; t <- 10
df <- data.frame(
  id   = rep(1:n, each = t),
  time = rep(1:t, times = n),
  y    = rnorm(n * t),
  x1   = rnorm(n * t)
)
res <- xtpretest(df, y ~ x1, index = c("id", "time"),
                 tests = c("hsiao", "csd"))

Quantile Regression Slope Homogeneity Test for Panel Data

Description

Tests the null hypothesis of slope homogeneity in panel quantile regressions. Implements the S-hat and D-hat statistics of Galvao et al. (2017).

Usage

xtqsh(formula, data, index, tau, bw = "hallsheather", marginal = FALSE)

Arguments

formula

A formula of the form y ~ x1 + x2 + ....

data

A data frame containing the panel data in long format.

index

Character vector of length 2: c("id_var", "time_var").

tau

Numeric vector of quantile levels, each strictly between 0 and 1.

bw

Bandwidth method: "hallsheather" (default) or "bofinger".

marginal

Logical. If TRUE, compute per-variable marginal tests. Default FALSE.

Value

An object of class "xtqsh" containing test statistics and p-values.

References

Galvao, A.F., Juhl, T., Montes-Rojas, G. and Olmo, J. (2017). Testing Slope Homogeneity in Quantile Regression Panel Data. Journal of Financial Econometrics, 16(2), 211-243.

Examples


set.seed(42)
n <- 10; tt <- 20
dat <- data.frame(
  id   = rep(1:n, each = tt),
  time = rep(1:tt, times = n),
  y    = rnorm(n * tt),
  x1   = rnorm(n * tt)
)
res <- xtqsh(y ~ x1, data = dat, index = c("id", "time"), tau = 0.5)
print(res)