Package {regcorr}


Type: Package
Title: Regression Models of Pearson Correlation Coefficient
Version: 0.1.0
Description: Provides statistical tools for evaluating how covariates influence the strength of Pearson correlation coefficients between two response variables. Supports bivariate normal and bivariate binary responses, with likelihood-based inference and bootstrap-based significance testing. The methodology is based on Dufera, Liu and Xu (2023) "Regression models of Pearson correlation coefficient" <doi:10.1080/24754269.2023.2164970>.
License: MIT + file LICENSE
Encoding: UTF-8
Depends: R (≥ 4.1.0)
Imports: stats
Suggests: testthat (≥ 3.0.0)
Config/testthat/edition: 3
URL: https://github.com/lonze-nb/regcorr
BugReports: https://github.com/lonze-nb/regcorr/issues
Config/roxygen2/version: 8.0.0
NeedsCompilation: no
Packaged: 2026-05-30 13:32:53 UTC; 34351
Author: Ze Lin [aut, cre], Bo Li [aut], Jinyao Shen [aut]
Maintainer: Ze Lin <zlin5858@163.com>
Repository: CRAN
Date/Publication: 2026-06-03 13:50:02 UTC

Fit a Regression Model for Pearson Correlation Coefficient

Description

Estimate regression coefficients in a covariate-dependent Pearson correlation model for bivariate binary responses using the Newton-Raphson algorithm.

Usage

NRfitBivBernoulli(Y, X, beta0, link)

NRfitBivBernoulli(Y, X, beta0, link)

Arguments

Y

n by 2 matrix, paired responses.

X

n by p matrix, covariate matrix including first column of ones.

beta0

Initial estimate of beta.

link

Indicator of link function ("1" = logistic, "2" = tanh).

Value

A list containing:

betaCurrent

Estimated regression coefficients.

numIter

Number of iterations.

restart

Number of restarts.

A list containing betaCurrent, numIter, and restart.

Examples

set.seed(123)

dat <- genDataBB(
  numSample = 30,
  p = 1,
  betaTrue = c(0.3, 0.1),
  eta1True = c(0, 0),
  eta2True = c(0, 0),
  link = "1"
)

fit <- NRfitBivBernoulli(
  Y = dat$Y,
  X = dat$X,
  beta0 = c(0, 0),
  link = "1"
)

fit$numIter


Fit a Regression Model for Pearson Correlation Coefficient

Description

Estimate regression coefficients in a covariate-dependent Pearson correlation model for bivariate normal responses using the Newton-Raphson algorithm.

Usage

NRfitBivNormal(Y, X, betaIni, link)

NRfitBivNormal(Y, X, betaIni, link)

Arguments

Y

n by 2 matrix, paired responses.

X

n by p matrix, covariate matrix including first column of ones.

betaIni

Initial estimate of beta.

link

Indicator of link function ("1" = logistic, "2" = tanh).

Value

A list containing:

betaCurrent

Estimated regression coefficients.

numIter

Number of Newton-Raphson iterations.

restart

Number of restarts.

A list containing betaCurrent, numIter, and restart.

Examples

set.seed(123)

dat <- genDataBN(
  numSample = 30,
  p = 1,
  betaTrue = c(0.5, 0.2),
  eta1True = c(0, 0),
  eta2True = c(0, 0),
  link = "1"
)

fit <- NRfitBivNormal(
  Y = dat$Y,
  X = dat$X,
  betaIni = c(0, 0),
  link = "1"
)

fit$numIter


Generate data from bivariate Bernoulli

Description

Generate data from bivariate Bernoulli

Usage

genDataBB(numSample, p, betaTrue, eta1True, eta2True, link)

genDataBB(numSample, p, betaTrue, eta1True, eta2True, link)

Arguments

numSample

Sample size.

p

Number of covariates.

betaTrue

True beta vector.

eta1True

True eta1 vector.

eta2True

True eta2 vector.

link

Link function indicator ("1" = logistic; "2" = tanh).

Value

A list containing X, Y, and rho.

Examples

set.seed(123)
dat <- genDataBB(
  numSample = 20,
  p = 2,
  betaTrue = c(0.2, 0, 0),
  eta1True = c(0, 0, 0),
  eta2True = c(0, 0, 0),
  link = "1"
)
names(dat)

Generate data from bivariate normal

Description

Simulate bivariate normal responses with a covariate-dependent Pearson correlation coefficient.

Usage

genDataBN(numSample, p, betaTrue, eta1True, eta2True, link)

genDataBN(numSample, p, betaTrue, eta1True, eta2True, link)

Arguments

numSample

Number of observations.

p

Number of covariates.

betaTrue

True regression coefficients for the correlation model.

eta1True

Included for interface consistency.

eta2True

Included for interface consistency.

link

Correlation link function: "1" for logistic, "2" for tanh.

Value

A list containing X, Y, and rho.

A list containing:

X

Covariate matrix.

Y

Response matrix with two columns.

rho

True correlation coefficients.

Examples

set.seed(123)
dat <- genDataBN(
  numSample = 20,
  p = 2,
  betaTrue = c(0.2, 0, 0),
  eta1True = c(0, 0, 0),
  eta2True = c(0, 0, 0),
  link = "1"
)
names(dat)

dim(dat$X)
dim(dat$Y)


Logistic Function

Description

Compute the logistic transformation of a numeric input.

Usage

logistic(x)

logistic(x)

Arguments

x

A numeric vector.

Value

A numeric value or vector with elements in (0,1).

The calculated logistic probability.

Examples

logistic(0)
logistic(c(-1, 0, 1))


Generate Correlated Binary Data

Description

Generate bivariate binary random variables with specified marginal probabilities and correlation.

Usage

rbinary(n, p, rho)

rbinary(n, p, rho)

Arguments

n

Number of rows.

p

1 by 2 mean vector of bivariate variables.

rho

Correlation of bivariate variables.

Details

The implementation follows Qaqish (2003).

Value

An n x 2 matrix of binary random variables.

n by 2 matrix of generated binary variables.

References

Qaqish, B. F. (2003). A family of multivariate binary distributions for simulating correlated binary variables with specified marginal means and correlations. Biometrika, 90(2), 455–463.

Examples

set.seed(123)
y <- rbinary(
  n = 10,
  p = c(0.4, 0.5),
  rho = 0.2
)

dim(y)


Subroutine to Test the Significance of Individual Parameters

Description

Conduct simulation studies for testing regression coefficients in correlation regression models.

Usage

subRoutineTest(
  numSample,
  p,
  link,
  model,
  betaTrue,
  betaIni,
  eta1True,
  eta2True,
  numSimu,
  numBoot
)

Arguments

numSample

Sample size.

p

Number of covariates.

link

Link function. "1" for logistic and "2" for tanh.

model

Model type. "1" for bivariate normal and "2" for bivariate Bernoulli.

betaTrue

True beta coefficients.

betaIni

Initial beta coefficients.

eta1True

True eta1 coefficients.

eta2True

True eta2 coefficients.

numSimu

Number of simulation replications.

numBoot

Number of bootstrap iterations.

Value

A list containing:

RMSE

Root mean squared error of the estimated coefficients.

ConsistRate

Consistency rate of estimated correlations.

power

Estimated testing power.

Examples

set.seed(123)

res <- subRoutineTest(
  numSample = 20,
  p = 1,
  link = "1",
  model = "1",
  betaTrue = c(0.2, 0.1),
  betaIni = c(0, 0),
  eta1True = c(0, 0),
  eta2True = c(0, 0),
  numSimu = 1,
  numBoot = 5
)

names(res)