| Title: | Regression with Skew-Normally Distributed Error Term |
|---|---|
| Description: | Models with a skew-normally distributed error term: Badunenko & Henderson (2023). Production analysis with asymmetric noise. Journal of Productivity Analysis, https://doi.org/10.1007/s11123-023-00680-5. |
| Authors: | Oleg Badunenko [aut, cre] (ORCID: <https://orcid.org/0000-0001-7216-0861>), John Burkardt [ctb, cph] (Author of C code for Owen T function) |
| Maintainer: | Oleg Badunenko <[email protected]> |
| License: | GPL-3 |
| Version: | 1.1.0 |
| Built: | 2026-06-07 09:27:48 UTC |
| Source: | https://github.com/olegbadunenko/snreg |
banks07 is a data frame containing selected variables for
500 U.S. commercial banks, randomly sampled from approximately 5000 banks,
based on the dataset of Koetter et al. (2012) for year 2007.
The dataset is provided solely for illustration and pedagogical purposes
and is not suitable for empirical research.
data(banks07)data(banks07)
A data frame with the following variables:
yearYear (2007).
idEntity (bank) identifier.
TAGross total assets.
LLPLoan loss provisions.
Y1Total securities (thousands of USD).
Y2Total loans and leases (thousands of USD).
W1Cost of fixed assets divided by the cost of borrowed funds.
W2Cost of labor (thousands of USD) divided by the cost of borrowed funds.
EREquity-to-assets ratio (gross).
TCTotal operating cost.
LARatio of total loans and leases to gross total assets.
U.S. Commercial Banks Data (2007)
The dataset was created by sampling and transforming variables as shown in the section Examples. It is intended to illustrate the usage of functions from this package (e.g. stochastic frontier models with skew-normal noise).
http://qed.econ.queensu.ca/jae/2014-v29.2/restrepo-tobon-kumbhakar/
Koetter, M., Kolari, J., & Spierdijk, L. (2012). Enjoying the quiet life under deregulation? Evidence from adjusted Lerner indices for U.S. banks. Review of Economics and Statistics, 94(2), 462–480.
Restrepo-Tobon, D. & Kumbhakar, S. (2014). Enjoying the quiet life under deregulation? Not Quite. Journal of Applied Econometrics, 29(2), 333–343.
## Not run: ## ------------------------------------------------------------------ ## Construct sample panel dataset (banks00_07) ## ------------------------------------------------------------------ # Download data from the link in "Source" banks00_07 <- read.delim("2b_QLH.txt") # rename 'entity' to 'id' colnames(banks00_07)[colnames(banks00_07) == "entity"] <- "id" # keep only years 2000–2007 banks00_07 <- banks00_07[ banks00_07$year >= 2000 & banks00_07$year <= 2007, ] # restrict sample to interquartile range of total assets q1q3 <- quantile(banks00_07$TA, probs = c(.25, .75)) banks00_07 <- banks00_07[ banks00_07$TA >= q1q3[1] & banks00_07$TA <= q1q3[2], ] # generate required variables banks00_07$TC <- banks00_07$TOC banks00_07$ER <- banks00_07$Z / banks00_07$TA # Equity ratio banks00_07$LA <- banks00_07$Y2 / banks00_07$TA # Loans-to-assets ratio # keep only needed variables keep.vars <- c("id", "year", "Ti", "TC", "Y1", "Y2", "W1","W2", "ER", "LA", "TA", "LLP") banks00_07 <- banks00_07[, colnames(banks00_07) %in% keep.vars] # number of periods per id t0 <- as.vector( by(banks00_07$id, banks00_07$id, FUN = function(qq) length(qq)) ) banks00_07$Ti <- rep(t0, times = t0) # keep if Ti > 4 banks00_07 <- banks00_07[banks00_07$Ti > 4, ] # complete observations only banks00_07 <- banks00_07[complete.cases(banks00_07), ] # sample 500 banks at random set.seed(816376586) id_names <- unique(banks00_07$id) ids2choose <- sample(id_names, 500) banks00_07 <- banks00_07[banks00_07$id %in% ids2choose, ] # recompute Ti t0 <- as.vector( by(banks00_07$id, banks00_07$id, FUN = function(qq) length(qq)) ) banks00_07$Ti <- rep(t0, times = t0) banks00_07 <- banks00_07[banks00_07$Ti > 4, ] # sort banks00_07 <- banks00_07[order(banks00_07$id, banks00_07$year), ] banks07 <- banks00_07[banks00_07$year == 2007, ] ## End(Not run)## Not run: ## ------------------------------------------------------------------ ## Construct sample panel dataset (banks00_07) ## ------------------------------------------------------------------ # Download data from the link in "Source" banks00_07 <- read.delim("2b_QLH.txt") # rename 'entity' to 'id' colnames(banks00_07)[colnames(banks00_07) == "entity"] <- "id" # keep only years 2000–2007 banks00_07 <- banks00_07[ banks00_07$year >= 2000 & banks00_07$year <= 2007, ] # restrict sample to interquartile range of total assets q1q3 <- quantile(banks00_07$TA, probs = c(.25, .75)) banks00_07 <- banks00_07[ banks00_07$TA >= q1q3[1] & banks00_07$TA <= q1q3[2], ] # generate required variables banks00_07$TC <- banks00_07$TOC banks00_07$ER <- banks00_07$Z / banks00_07$TA # Equity ratio banks00_07$LA <- banks00_07$Y2 / banks00_07$TA # Loans-to-assets ratio # keep only needed variables keep.vars <- c("id", "year", "Ti", "TC", "Y1", "Y2", "W1","W2", "ER", "LA", "TA", "LLP") banks00_07 <- banks00_07[, colnames(banks00_07) %in% keep.vars] # number of periods per id t0 <- as.vector( by(banks00_07$id, banks00_07$id, FUN = function(qq) length(qq)) ) banks00_07$Ti <- rep(t0, times = t0) # keep if Ti > 4 banks00_07 <- banks00_07[banks00_07$Ti > 4, ] # complete observations only banks00_07 <- banks00_07[complete.cases(banks00_07), ] # sample 500 banks at random set.seed(816376586) id_names <- unique(banks00_07$id) ids2choose <- sample(id_names, 500) banks00_07 <- banks00_07[banks00_07$id %in% ids2choose, ] # recompute Ti t0 <- as.vector( by(banks00_07$id, banks00_07$id, FUN = function(qq) length(qq)) ) banks00_07$Ti <- rep(t0, times = t0) banks00_07 <- banks00_07[banks00_07$Ti > 4, ] # sort banks00_07 <- banks00_07[order(banks00_07$id, banks00_07$year), ] banks07 <- banks00_07[banks00_07$year == 2007, ] ## End(Not run)
coef.snreg is the S3 method for extracting the estimated regression
coefficients from an object of class "snreg".
## S3 method for class 'snreg' coef(obj, ...)## S3 method for class 'snreg' coef(obj, ...)
obj |
an object of class |
... |
additional arguments (currently unused). |
Coefficients from an snreg Model
This method simply returns the coef component stored inside the fitted
"snreg" object. If the object does not contain coefficient estimates
(e.g., if estimation was not completed in a scaffold), an informative error
is raised.
A numeric vector containing the model coefficients.
## Not run: m <- snreg(y ~ x1 + x2, data = df) coef(m) ## End(Not run)## Not run: m <- snreg(y ~ x1 + x2, data = df) coef(m) ## End(Not run)
lm.mle fits a linear regression model by maximum likelihood, allowing
for optional multiplicative heteroskedasticity in the disturbance variance via
a log-linear specification provided through ln.var.v.
lm.mle( formula, data, subset, ln.var.v = NULL, technique = c("bfgs"), lmtol = 1e-05, reltol = 1e-12, maxit = 199, optim.report = 1, optim.trace = 10, print.level = 3, digits = 4, only.data = FALSE, ... )lm.mle( formula, data, subset, ln.var.v = NULL, technique = c("bfgs"), lmtol = 1e-05, reltol = 1e-12, maxit = 199, optim.report = 1, optim.trace = 10, print.level = 3, digits = 4, only.data = FALSE, ... )
formula |
an object of class |
data |
an optional |
subset |
an optional logical or numeric vector specifying the subset of observations to be used in estimation. |
ln.var.v |
optional one-sided formula; e.g. |
technique |
character vector specifying the preferred optimization routine(s) in order of
preference. Recognized keywords (for future implementation) include |
lmtol |
numeric. Convergence tolerance based on scaled gradient (when applicable).
Default |
reltol |
numeric. Relative convergence tolerance for likelihood maximization.
Default |
maxit |
integer. Maximum number of iterations for the optimizer. Default |
optim.report |
integer. Verbosity level for reporting progress (if implemented). Default |
optim.trace |
integer. Trace level for optimization (if implemented). Default |
print.level |
integer. Printing level for summaries. Default |
digits |
integer. Number of digits for printing. Default |
only.data |
logical. If |
... |
additional arguments reserved for future methods (e.g., bounds, penalties). |
Linear Model by Maximum Likelihood (with optional heteroskedasticity)
The model is
When ln.var.v is supplied, the variance follows
otherwise is constant (homoskedastic).
This function:
Builds the model frame and X, y.
Builds Zv for the log-variance index when ln.var.v is provided.
Returns a structured object with placeholders for coef, vcov, loglik.
Insert your MLE engine to estimate , and (optionally) or
; compute standard errors via AIM/OPG as required by vcetype.
A list of class "snreg" containing (and extending) the fields
returned by optim:
par — numeric vector of the MLE parameter estimates.
value — numeric scalar: maximized log-likelihood value.
ll — numeric scalar: maximized log-likelihood value.
counts, convergence, message — standard optim outputs.
hessian — the observed Hessian at the solution (as returned by optim(hessian=TRUE)).
coef — named numeric vector equal to par (estimates).
vcov — variance–covariance matrix, computed as solve(-hessian).
sds — standard errors, sqrt(diag(vcov)).
ctab — coefficient table with columns:
Estimate, Std.Err, Z value, Pr(>z).
esample — logical vector indicating the observations used in estimation.
n — scalar, number of observations in the estimation sample.
The object inherits the default
optim components and is assigned class "snreg".
## Not run: library(snreg) data("banks07") head(banks07) # Translog cost function specification spe.tl <- log(TC) ~ (log(Y1) + log(Y2) + log(W1) + log(W2))^2 + I(0.5 * log(Y1)^2) + I(0.5 * log(Y2)^2) + I(0.5 * log(W1)^2) + I(0.5 * log(W2)^2) # ------------------------------------------------------------- # Specification 1: homoskedastic noise (ln.var.v = NULL) # ------------------------------------------------------------- formSV <- NULL m1 <- lm.mle( formula = spe.tl, data = banks07, ln.var.v = formSV ) coef(m1) # ------------------------------------------------------------- # Specification 2: heteroskedastic noise (variance depends on TA) # ------------------------------------------------------------- formSV <- ~ log(TA) m2 <- lm.mle( formula = spe.tl, data = banks07, ln.var.v = formSV ) coef(m2) ## End(Not run)## Not run: library(snreg) data("banks07") head(banks07) # Translog cost function specification spe.tl <- log(TC) ~ (log(Y1) + log(Y2) + log(W1) + log(W2))^2 + I(0.5 * log(Y1)^2) + I(0.5 * log(Y2)^2) + I(0.5 * log(W1)^2) + I(0.5 * log(W2)^2) # ------------------------------------------------------------- # Specification 1: homoskedastic noise (ln.var.v = NULL) # ------------------------------------------------------------- formSV <- NULL m1 <- lm.mle( formula = spe.tl, data = banks07, ln.var.v = formSV ) coef(m1) # ------------------------------------------------------------- # Specification 2: heteroskedastic noise (variance depends on TA) # ------------------------------------------------------------- formSV <- ~ log(TA) m2 <- lm.mle( formula = spe.tl, data = banks07, ln.var.v = formSV ) coef(m2) ## End(Not run)
Prints the contents of a "summary.snreg" object in a structured
format. The method reports convergence status (based on gradient-Hessian
scaling), log-likelihood, estimation results, and—when present—summaries
for technical/cost efficiencies and marginal effects.
## S3 method for class 'summary.snreg' print(obj, digits = NULL, ...)## S3 method for class 'summary.snreg' print(obj, digits = NULL, ...)
obj |
an object of class |
digits |
integer indicating the number of digits to print; default |
... |
additional arguments (currently unused). |
Print Method for Summary of snreg Objects
This method expects a fitted "snreg" object.
The input obj is returned (invisibly) after printing.
residuals.snreg is the S3 method for extracting residuals from a fitted
snreg model. Residuals may be returned either for the full data or only
for the estimation sample.
## S3 method for class 'snreg' residuals(obj, esample = TRUE, ...)## S3 method for class 'snreg' residuals(obj, esample = TRUE, ...)
obj |
an object of class |
esample |
logical. If |
... |
additional arguments (currently unused). |
Extract Residuals from an snreg Model
This method simply accesses the obj$resid component of a fitted
"snreg" object. An informative error is produced if residuals are not
available.
A numeric vector of residuals.
If esample = TRUE, the vector matches the length of the original data
and contains NA for non-estimation observations.
If esample = FALSE, only the computed residuals are returned.
snreg, fitted.snreg, coef.snreg
## Not run: m <- snreg(y ~ x1 + x2, data = df) # Residuals for estimation sample only residuals(m) # Residuals for all observations residuals(m, esample = FALSE) ## End(Not run)## Not run: m <- snreg(y ~ x1 + x2, data = df) # Residuals for estimation sample only residuals(m) # Residuals for all observations residuals(m, esample = FALSE) ## End(Not run)
snreg fits a linear regression model where the disturbance term follows
a skew-normal distribution. The function supports multiplicative
heteroskedasticity of the noise variance via a log-linear specification
(ln.var.v) and allows the skewness parameter to vary linearly with
exogenous variables (skew.v).
snreg( formula, data, subset, init.sk = NULL, ln.var.v = NULL, skew.v = NULL, start.val = NULL, technique = c("nr"), vcetype = c("aim"), lmtol = 1e-05, reltol = 1e-12, maxit = 199, optim.report = 1, optim.trace = 1, print.level = 3, digits = 4, only.data = FALSE, ... )snreg( formula, data, subset, init.sk = NULL, ln.var.v = NULL, skew.v = NULL, start.val = NULL, technique = c("nr"), vcetype = c("aim"), lmtol = 1e-05, reltol = 1e-12, maxit = 199, optim.report = 1, optim.trace = 1, print.level = 3, digits = 4, only.data = FALSE, ... )
formula |
an object of class |
data |
an optional |
subset |
an optional logical or numeric vector specifying the subset of observations to be used in estimation. |
init.sk |
numeric. Initial value for the (global) skewness parameter of the noise;
can be |
ln.var.v |
optional one-sided formula; e.g. |
skew.v |
optional one-sided formula; e.g. |
start.val |
optional numeric vector of starting values for all free parameters (regression coefficients, variance/heteroskedasticity parameters, skewness parameters). |
technique |
character vector giving the preferred maximization routine(s) in order of
preference. Currently recognized keywords include |
vcetype |
character specifying the variance-covariance estimator type:
|
lmtol |
numeric. Convergence tolerance based on the scaled gradient (if applicable).
Default is |
reltol |
numeric. Relative convergence tolerance for likelihood maximization.
Default is |
maxit |
integer. Maximum number of iterations for the optimizer. Default is |
optim.report |
integer. Verbosity for reporting progress (if implemented). Default is |
optim.trace |
integer. If positive, tracing information is printed (if implemented).
Default is |
print.level |
integer. Printing level for summaries: |
digits |
integer. Number of digits for printing. Default |
only.data |
logical. If |
... |
additional arguments reserved for future methods (e.g., box constraints). |
Linear Regression with Skew-Normal Errors
The model is
where denotes the skew-normal distribution (Azzalini).
Heteroskedasticity in the noise variance (if specified via ln.var.v) is modeled as
and the (optional) covariate-driven skewness (if specified via skew.v) as
This function constructs the model frame and design matrices for
, , and , and is designed to be paired with
a maximum likelihood routine to estimate parameters and (optionally) their
asymptotic covariance via either AIM or OPG.
An object of class "snreg" containing the maximum-likelihood results and,
depending on the optimization routine, additional diagnostics:
parNumeric vector of parameter estimates at the optimum.
coefNamed numeric vector equal to par.
vcovVariance–covariance matrix of the estimates.
sdsStandard errors, computed as sqrt(diag(vcov)).
ctabCoefficient table with columns:
Estimate, Std.Err, Z value, Pr(>z).
RSSResidual sum of squares.
esampleLogical vector indicating which observations were used in estimation.
nNumber of observations used in the estimation sample.
skewnessVector of the fitted skewness index.
hessian(BFGS only) Observed Hessian at the optimum. If vcetype == "opg",
this is set to the negative outer product of the individual gradients;
otherwise a numerical Hessian is computed.
value(BFGS only) Objective value returned by optim. With
control$fnscale = -1, this equals the maximized log-likelihood.
counts(BFGS only) Number of iterations / function evaluations returned by optim.
convergence(BFGS only) Convergence code from optim.
message(BFGS only) Additional optim message, if any.
llMaximized log-likelihood value.
gradient(NR only) Gradient at the solution.
gg(NR only) Optional gradient-related diagnostic.
gHg(NR only) Optional Newton-step diagnostic.
theta_rel_ch(NR only) Relative parameter change metric across iterations.
The returned object has class "snreg".
Azzalini, A. (1985). A Class of Distributions Which Includes the Normal Ones. Scandinavian Journal of Statistics, 12(2), 171–178.
Azzalini, A., & Capitanio, A. (2014). The Skew-Normal and Related Families. Cambridge University Press.
## Not run: library(snreg) data("banks07") head(banks07) # Translog cost function spe.tl <- log(TC) ~ (log(Y1) + log(Y2) + log(W1) + log(W2))^2 + I(0.5 * log(Y1)^2) + I(0.5 * log(Y2)^2) + I(0.5 * log(W1)^2) + I(0.5 * log(W2)^2) # ------------------------------------------------------------- # Specification 1: homoskedastic & symmetric noise # ------------------------------------------------------------- formSV <- NULL # variance equation formSK <- NULL # skewness equation m1 <- snreg( formula = spe.tl, data = banks07, ln.var.v = formSV, skew.v = formSK ) coef(m1) # ------------------------------------------------------------- # Specification 2: heteroskedastic + skewed noise # ------------------------------------------------------------- formSV <- ~ log(TA) # heteroskedasticity in v formSK <- ~ ER # skewness driven by equity ratio m2 <- snreg( formula = spe.tl, data = banks07, ln.var.v = formSV, skew.v = formSK ) coef(m2) ## End(Not run)## Not run: library(snreg) data("banks07") head(banks07) # Translog cost function spe.tl <- log(TC) ~ (log(Y1) + log(Y2) + log(W1) + log(W2))^2 + I(0.5 * log(Y1)^2) + I(0.5 * log(Y2)^2) + I(0.5 * log(W1)^2) + I(0.5 * log(W2)^2) # ------------------------------------------------------------- # Specification 1: homoskedastic & symmetric noise # ------------------------------------------------------------- formSV <- NULL # variance equation formSK <- NULL # skewness equation m1 <- snreg( formula = spe.tl, data = banks07, ln.var.v = formSV, skew.v = formSK ) coef(m1) # ------------------------------------------------------------- # Specification 2: heteroskedastic + skewed noise # ------------------------------------------------------------- formSV <- ~ log(TA) # heteroskedasticity in v formSK <- ~ ER # skewness driven by equity ratio m2 <- snreg( formula = spe.tl, data = banks07, ln.var.v = formSV, skew.v = formSK ) coef(m2) ## End(Not run)
snsf performs maximum likelihood estimation of the parameters and
technical or cost efficiencies in a Stochastic Frontier Model with a
skew-normally distributed error term.
snsf( formula, data, subset, distribution = "e", prod = TRUE, start.val = NULL, init.sk = NULL, ln.var.u = NULL, ln.var.v = NULL, skew.v = NULL, mean.u = NULL, technique = c("nr"), vcetype = c("aim"), optim.report = 1, optim.trace = 1, reltol = 1e-12, lmtol = 1e-05, maxit = 199, print.level = 3, report = 1, trace = 1, threads = 1, only.data = FALSE, digits = 4, ... )snsf( formula, data, subset, distribution = "e", prod = TRUE, start.val = NULL, init.sk = NULL, ln.var.u = NULL, ln.var.v = NULL, skew.v = NULL, mean.u = NULL, technique = c("nr"), vcetype = c("aim"), optim.report = 1, optim.trace = 1, reltol = 1e-12, lmtol = 1e-05, maxit = 199, print.level = 3, report = 1, trace = 1, threads = 1, only.data = FALSE, digits = 4, ... )
formula |
an object of class |
data |
an optional |
subset |
an optional logical or numeric vector specifying a subset of observations for which the model is estimated and efficiencies are computed. |
distribution |
character scalar specifying the distribution of the inefficiency term: default |
prod |
logical. If |
start.val |
optional numeric vector of starting values for the optimizer. |
init.sk |
numeric. Initial value for the skewness parameter of the noise component;
default is |
ln.var.u |
optional one-sided formula; e.g. |
ln.var.v |
optional one-sided formula; e.g. |
skew.v |
optional one-sided formula; e.g. |
mean.u |
optional one-sided formula; e.g. |
optim.report |
integer. Verbosity level for reporting during optimization (if implemented).
Default is |
optim.trace |
integer. Trace level for optimization (if implemented). Default is |
reltol |
numeric. Relative convergence tolerance used when maximizing the log-likelihood
with |
lmtol |
numeric. Convergence tolerance based on the scaled gradient (when applicable).
Default is |
maxit |
numeric. Maximum number of iterations for the optimizer. Default is |
print.level |
integer. Printing level: |
digits |
integer. Number of digits for displaying estimates and efficiencies. Default is |
... |
additional arguments passed to internal methods or to |
optim |
logical. If |
optim.method |
character. Method passed to |
optim.reltol |
numeric. Relative tolerance specifically for |
Stochastic Frontier Model with a Skew-Normally Distributed Error Term
Models for snsf are specified symbolically. A typical model has the form
y ~ x1 + ..., where y represents the logarithm of outputs or total
costs and {x1, ...} is a set of inputs (for production) or outputs and
input prices (for cost), all typically in logs.
Options ln.var.u and ln.var.v allow for multiplicative
heteroskedasticity in the inefficiency and/or noise components; i.e., their
variances can be modeled as exponential functions of exogenous variables
(including an intercept), as in Caudill et al. (1995).
An object of class "snreg" with maximum-likelihood estimates and diagnostics:
parNumeric vector of ML parameter estimates at the optimum.
coefNamed numeric vector equal to par.
vcovVariance–covariance matrix of the estimates.
sdsStandard errors, sqrt(diag(vcov)).
ctabCoefficient table with columns
Coef., SE, z, P>|z|.
llMaximized log-likelihood value.
hessian(When computed) Observed Hessian or OPG used to form vcov.
value(Optim-only, before aliasing) Objective value from optim.
counts(Optim-only) Iteration and evaluation counts from optim.
convergenceConvergence code).
message(Optim-only) Message returned by optim, if any.
gradient(NR-only) Gradient at the solution.
gg(NR-only) Gradient-related diagnostic.
gHg(NR-only) Newton-step diagnostic.
theta_rel_ch(NR-only) Relative parameter change metric across iterations.
residRegression residuals.
RSSResidual sum of squares crossprod(resid).
shat2Residual variance estimate var(resid).
shatResidual standard deviation sqrt(shat2).
aicAkaike Information Criterion.
bicBayesian Information Criterion.
MallowsMallows' -like statistic.
uEstimated inefficiency term (vector). Returned for models with an inefficiency component (e.g., exponential).
effEfficiency scores exp(-u) (technical or cost, depending on prod).
svEstimated (possibly unit-specific) standard deviation of the noise term.
suEstimated (possibly unit-specific) standard deviation or scale of the inefficiency term. For exponential models.
skewnessEstimated skewness index (e.g., from the skewness equation).
esampleLogical vector marking observations used in estimation.
nNumber of observations used.
The returned object has class "snreg".
Oleg Badunenko <Oleg.Badunenko.brunel.ac.uk>
Badunenko, O., & Henderson, D. J. (2023). Production analysis with asymmetric noise. Journal of Productivity Analysis, 61(1), 1–18. https://doi.org/10.1007/s11123-023-00680-5
Caudill, S. B., Ford, J. M., & Gropper, D. M. (1995). Frontier estimation and firm-specific inefficiency measures in the presence of heteroskedasticity. Journal of Business & Economic Statistics, 13(1), 105–111.
## Not run: library(snreg) data("banks07") head(banks07) myprod <- FALSE # Translog cost function spe.tl <- log(TC) ~ (log(Y1) + log(Y2) + log(W1) + log(W2))^2 + I(0.5 * log(Y1)^2) + I(0.5 * log(Y2)^2) + I(0.5 * log(W1)^2) + I(0.5 * log(W2)^2) # ------------------------------------------------------------- # Specification 1: homoskedastic & symmetric # ------------------------------------------------------------- formSV <- NULL # variance equation formSK <- NULL # skewness equation formSU <- NULL # inefficiency equation (unused here) m1 <- snsf( formula = spe.tl, data = banks07, prod = myprod, ln.var.v = formSV, skew.v = formSK ) coef(m1) # ------------------------------------------------------------- # Specification 2: heteroskedastic + skewed noise # ------------------------------------------------------------- formSV <- ~ log(TA) # heteroskedastic variance formSK <- ~ ER # skewness driver formSU <- ~ LA + ER # inefficiency m2 <- snsf( formula = spe.tl, data = banks07, prod = myprod, ln.var.v = formSV, skew.v = formSK ) coef(m2) ## End(Not run)## Not run: library(snreg) data("banks07") head(banks07) myprod <- FALSE # Translog cost function spe.tl <- log(TC) ~ (log(Y1) + log(Y2) + log(W1) + log(W2))^2 + I(0.5 * log(Y1)^2) + I(0.5 * log(Y2)^2) + I(0.5 * log(W1)^2) + I(0.5 * log(W2)^2) # ------------------------------------------------------------- # Specification 1: homoskedastic & symmetric # ------------------------------------------------------------- formSV <- NULL # variance equation formSK <- NULL # skewness equation formSU <- NULL # inefficiency equation (unused here) m1 <- snsf( formula = spe.tl, data = banks07, prod = myprod, ln.var.v = formSV, skew.v = formSK ) coef(m1) # ------------------------------------------------------------- # Specification 2: heteroskedastic + skewed noise # ------------------------------------------------------------- formSV <- ~ log(TA) # heteroskedastic variance formSK <- ~ ER # skewness driver formSU <- ~ LA + ER # inefficiency m2 <- snsf( formula = spe.tl, data = banks07, prod = myprod, ln.var.v = formSV, skew.v = formSK ) coef(m2) ## End(Not run)
su)Computes a compact table of summary statistics for each variable in a vector,
matrix, or data frame. The following metrics are returned per variable:
number of observations (Obs), missing values (NAs), mean,
standard deviation (StDev), interquartile range (IQR),
minimum (Min), user-specified quantiles (probs), and maximum (Max).
su( x, mat.var.in.col = TRUE, digits = 4, probs = c(0.1, 0.25, 0.5, 0.75, 0.9), print = FALSE )su( x, mat.var.in.col = TRUE, digits = 4, probs = c(0.1, 0.25, 0.5, 0.75, 0.9), print = FALSE )
x |
a numeric vector, matrix, or data frame. For matrices, variables are assumed
to be in columns; set |
mat.var.in.col |
logical. If |
digits |
integer. Number of digits to use when printing (only affects printed output when
|
probs |
numeric vector of probabilities in |
print |
logical. If |
Compact Summary Statistics for Vectors, Matrices, and Data Frames
Input handling:
If x is a matrix with a single row or column, it is treated like a vector.
Column or row names are used (if available). Otherwise, a default name is created.
If x is a matrix with multiple variables, variables are taken as columns.
Use mat.var.in.col = FALSE to transpose and treat rows as variables.
If x is a vector, its deparsed symbol name is used as the variable name.
If x is a data frame, each column is summarized.
Missing values are excluded in all summary computations.
A matrix (coercible to data.frame) where each row corresponds to a variable
and columns contain the summary statistics:
Obs, NAs, Mean, StDev, IQR, Min,
the requested probs quantiles (named), and Max.
The returned object is given class "snreg" for compatibility with
package-specific print/summarization methods.
## Not run: # Vector set.seed(1) v <- rnorm(100) su(v, print = TRUE) # Matrix: variables in columns M <- cbind(x = rnorm(50), y = runif(50)) su(M) # Matrix: variables in rows Mr <- rbind(x = rnorm(50), y = runif(50)) su(Mr, mat.var.in.col = FALSE) # Data frame DF <- data.frame(a = rnorm(30), b = rexp(30), c = rbinom(30, 1, 0.3)) out <- su(DF) head(out) ## End(Not run)## Not run: # Vector set.seed(1) v <- rnorm(100) su(v, print = TRUE) # Matrix: variables in columns M <- cbind(x = rnorm(50), y = runif(50)) su(M) # Matrix: variables in rows Mr <- rbind(x = rnorm(50), y = runif(50)) su(Mr, mat.var.in.col = FALSE) # Data frame DF <- data.frame(a = rnorm(30), b = rexp(30), c = rbinom(30, 1, 0.3)) out <- su(DF) head(out) ## End(Not run)
Produces a summary object for objects of class "snreg".
The function assigns the class "summary.snreg" to the fitted model
object, enabling a dedicated print method (print.summary.snreg) to
display results in a structured format.
## S3 method for class 'snreg' summary(obj, ...)## S3 method for class 'snreg' summary(obj, ...)
obj |
an object of class |
... |
additional arguments (currently not used). |
Summary Method for snreg Objects
This method expects a fitted "snreg" object.
summary.snreg does not modify the contents of the object; it only
updates the class attribute to "summary.snreg". The corresponding
print method (print.summary.snreg) is responsible for
formatting and displaying estimation details, such as convergence criteria,
log-likelihood, coefficient tables, and (if present) heteroskedastic and
skewness components.
An object of class "summary.snreg", identical to the input obj
except for its class attribute.
## Not run: # m <- snreg(TC ~ Y1 + Y2, data = banks07) # s <- summary(m) # print(s) ## End(Not run)## Not run: # m <- snreg(TC ~ Y1 + Y2, data = banks07) # s <- summary(m) # print(s) ## End(Not run)
T(h, a)
TOwen1 computes an Owen's -function variant (or a related
special function) for vectors h and a based on the t function in https://people.sc.fsu.edu/~jburkardt/c_src/owen/owen.html. Non-finite inputs (in h or a) produce NA
at corresponding positions, while finite pairs are computed in C in a
vectorized fashion.
TOwen(h, a, threads = 1)TOwen(h, a, threads = 1)
h |
numeric vector of |
a |
numeric vector of |
threads |
integer. Number of threads to request from the C implementation (if supported).
Default is |
Owen's T Function via C Backend
Owen's function is commonly defined as
for real and .
The function accepts vector inputs and:
Computes results only for entries where both h and a are finite.
Returns NA where either h or a is non-finite.
Optionally passes a threads hint to the C backend (ignored if not supported).
A numeric vector of length length(h) containing .
Elements where either h_i or a_i is not finite are NA.
The returned object is given class "snreg" for downstream compatibility
with your package’s print/summary helpers.
## Not run: # Basic usage. Vectorized 'a' h <- c(-1, 0, 1, 2) a <- 0.5 TOwen(h, a) # Vectorized 'a' with non-finite entries; non-finite entries yield NA a2 <- c(0.2, NA, 1, Inf) TOwen(h, a2) ## End(Not run)## Not run: # Basic usage. Vectorized 'a' h <- c(-1, 0, 1, 2) a <- 0.5 TOwen(h, a) # Vectorized 'a' with non-finite entries; non-finite entries yield NA a2 <- c(0.2, NA, 1, Inf) TOwen(h, a2) ## End(Not run)
TOwen1(h, a)
TOwen1 computes an Owen's -function variant (or a related
special function) for vectors h and a based on the tha function in https://people.sc.fsu.edu/~jburkardt/c_src/owen/owen.html. Non-finite inputs in h or a
yield NA at the corresponding positions.
TOwen1(h, a, threads = 1)TOwen1(h, a, threads = 1)
threads |
integer. Number of threads to request from the C implementation (if supported).
Default is |
Owen's T Function Variant via C Backend
This is a thin R wrapper around a native routine with signature:
void TOwen1(int *n, double *h, double *a, double *out, int *threads)
A numeric vector of length length(h) with the computed values. Elements
where either h or a is non-finite are NA. The returned
vector is given class "snreg" for downstream compatibility.
## Not run: library(snreg) # Basic usage. Vectorized 'a': h <- c(-1, 0, 1, 2) a <- 0.3 TOwen1(h, a) # Vectorized 'a' with non-finite entries: a2 <- c(0.2, NA, 1, Inf) TOwen1(h, a2) ## End(Not run)## Not run: library(snreg) # Basic usage. Vectorized 'a': h <- c(-1, 0, 1, 2) a <- 0.3 TOwen1(h, a) # Vectorized 'a' with non-finite entries: a2 <- c(0.2, NA, 1, Inf) TOwen1(h, a2) ## End(Not run)
vcov.snreg is the vcov S3 method for objects of class "snreg".
It returns the model-based variance–covariance matrix stored in the fitted object.
## S3 method for class 'snreg' vcov(obj, ...)## S3 method for class 'snreg' vcov(obj, ...)
obj |
an object of class |
... |
additional arguments (currently unused). |
Variance–Covariance Matrix for snreg Objects
This method expects a fitted "snreg" object.
This method simply returns the vcov component stored in obj.
If your estimator did not compute standard errors (e.g., because estimation
hasn’t been run yet in a scaffold), this field may be NULL, and the
method will error accordingly.
A numeric matrix containing the variance–covariance of the estimated parameters.
## Not run: library(snsf) data("banks07") head(banks07) # V <- vcov(m) # diag(V) ## End(Not run)## Not run: library(snsf) data("banks07") head(banks07) # V <- vcov(m) # diag(V) ## End(Not run)