Nothing
condistribution <-
function(bws, xeval, yeval, condist, conderr = NA,
congrad = NA, congerr = NA,
ntrain, trainiseval = FALSE, gradients = FALSE,
gradient.order = NULL,
proper.requested = FALSE,
proper.applied = FALSE,
proper.method = NULL,
condist.raw = NULL,
proper.info = NULL,
rows.omit = NA,
train.rows.omit = NULL,
eval.rows.omit = NULL,
timing = NA, total.time = NA,
optim.time = NA, fit.time = NA, se = TRUE){
if (missing(bws) || missing(xeval) || missing(yeval) || missing(condist) || missing(ntrain))
stop("improper invocation of condistribution constructor")
if (length(rows.omit) == 0)
rows.omit <- NA
if (is.null(train.rows.omit) || length(train.rows.omit) == 0)
train.rows.omit <- NA
if (is.null(eval.rows.omit) || length(eval.rows.omit) == 0)
eval.rows.omit <- NA
d <- list(
xbw = bws$xbw,
ybw = bws$ybw,
bws = bws,
xnames = bws$xnames,
ynames = bws$ynames,
nobs = dim(xeval)[1],
xndim = bws$xndim,
yndim = bws$yndim,
xnord = bws$xnord,
xnuno = bws$xnuno,
xncon = bws$xncon,
ynord = bws$ynord,
ynuno = bws$ynuno,
yncon = bws$yncon,
pscaling = bws$pscaling,
ptype = bws$ptype,
pcxkertype = bws$pcxkertype,
puxkertype = bws$puxkertype,
poxkertype = bws$poxkertype,
pcykertype = bws$pcykertype,
puykertype = bws$puykertype,
poykertype = bws$poykertype,
xeval = xeval,
yeval = yeval,
condist = condist,
conderr = conderr,
congrad = congrad,
congerr = congerr,
ntrain = ntrain,
trainiseval = trainiseval,
gradients = gradients,
se = se,
gradient.order = gradient.order,
proper.requested = proper.requested,
proper.applied = proper.applied,
proper.method = proper.method,
condist.raw = condist.raw,
proper.info = proper.info,
rows.omit = rows.omit,
nobs.omit = if (identical(rows.omit, NA)) 0 else length(rows.omit),
train.rows.omit = train.rows.omit,
train.nobs.omit = if (identical(train.rows.omit, NA)) 0 else length(train.rows.omit),
eval.rows.omit = eval.rows.omit,
eval.nobs.omit = if (identical(eval.rows.omit, NA)) 0 else length(eval.rows.omit),
timing = timing, total.time = total.time,
optim.time = optim.time, fit.time = fit.time)
class(d) <- "condistribution"
return(d)
}
print.condistribution <- function(x, digits=NULL, ...){
cat("\nConditional distribution data: ", x$ntrain, " training points,",
if (x$trainiseval) "" else paste(" and ", x$nobs, " evaluation points,\n", sep=""),
" in ", x$xndim + x$yndim, " variable(s)",
"\n(", x$yndim, " dependent variable(s), and ", x$xndim, " explanatory variable(s))\n\n",
sep="")
printSearchParameterSummary(x$ybw, x$ynames, x$bws, vari = "y",
role = "Dependent",
fallback.label = paste("Dep. Var. ", x$pscaling, ":", sep = ""),
digits = digits)
printSearchParameterSummary(x$xbw, x$xnames, x$bws, vari = "x",
role = "Explanatory",
fallback.label = paste("Exp. Var. ", x$pscaling, ":", sep = ""),
digits = digits)
cat(genDenEstStr(x))
cat(genBwKerStrs(x$bws))
if (!is.null(x$proper.requested) && !is.null(x$proper.applied)) {
proper.state <- if (isTRUE(x$proper.applied)) {
sprintf("requested and applied (%s)", x$proper.method)
} else if (isTRUE(x$proper.requested)) {
"requested but not applied"
} else {
"not requested"
}
cat("\nProper distribution repair:", proper.state)
}
cat("\n\n")
if(!missing(...))
print(...,digits=digits)
invisible(x)
}
fitted.condistribution <- function(object, ...){
object$condist
}
se.condistribution <- function(x){
if (isTRUE(x$proper.applied)) {
stop("standard errors are unavailable for repaired conditional distributions in tranche 1")
}
.np_require_stored_se(x, x[["conderr", exact = TRUE]], "npcdist",
expr = substitute(x))
}
gradients.condistribution <- function(x, se = FALSE, gradient.order = NULL, ...) {
.np_reject_gradient_order_alias(substitute(list(...))[-1L],
"gradients.condistribution", suggest = TRUE)
npRejectLegacyBooleanErrors(list(...), "gradients.condistribution")
se <- npValidateScalarLogical(se, "se")
gout <- if (!se) x$congrad else .np_require_stored_se(
x, if (identical(x[["congerr", exact = TRUE]], NA)) NULL else
x[["congerr", exact = TRUE]], "npcdist",
what = "gradient standard errors", expr = substitute(x),
switches = "gradients = TRUE, se = TRUE")
if (is.null(gout) || (length(gout) == 1L && is.logical(gout) && is.na(gout)))
.np_stop_missing_output(
substitute(x), "npcdist",
message = if (!se) "gradients are not available." else
"gradient standard errors were not computed.",
switches = if (!se) "gradients = TRUE" else "gradients = TRUE, se = TRUE")
reg.spec <- npConditionalRegEngineSpec(x$bws, where = "gradients.condistribution")
if (isTRUE(x$bws$xncon == 0L)) {
if (!is.null(gradient.order)) {
npValidateCategoricalFirstDifferenceGradientOrder(
gradient.order = gradient.order,
where = "gradients.condistribution"
)
}
return(gout)
}
if (!identical(reg.spec$reg.engine, "lp") && !is.null(gradient.order))
npConditionalGradientOrder(x$bws, reg.spec$reg.engine, gradient.order,
where = "gradients.condistribution")
if (!identical(reg.spec$reg.engine, "lp") || is.null(gradient.order))
return(gout)
if (!is.matrix(gout))
return(gout)
gorder <- npValidateGlpGradientOrder(regtype = "lp",
gradient.order = gradient.order,
ncon = x$bws$xncon)
stored.order <- x$gradient.order
if (is.null(stored.order) && x$bws$xncon > 0L)
stored.order <- rep.int(1L, x$bws$xncon)
stored.order <- npValidateGlpGradientOrder(regtype = "lp",
gradient.order = stored.order,
ncon = x$bws$xncon)
available <- npGlpGradientAvailability(
regtype.engine = reg.spec$reg.engine,
degree.engine = reg.spec$degree.engine,
gradient.order = gorder,
ncon = x$bws$xncon,
where = "gradients.condistribution"
)
if (!any(available) && (x$bws$xnuno + x$bws$xnord == 0L)) {
npStopGlpGradientNoneAvailable(
where = "gradients.condistribution",
action = "return",
degree.engine = reg.spec$degree.engine,
gradient.order = gorder,
available = available,
con.names = x$xnames[x$bws$ixcon]
)
}
if (any(!available)) {
npWarnGlpGradientPartialAvailability(
where = "gradients.condistribution",
degree.engine = reg.spec$degree.engine,
gradient.order = gorder,
available = available,
con.names = x$xnames[x$bws$ixcon]
)
}
if (length(gorder)) {
defined.request <- available
if (any(defined.request & (gorder != stored.order))) {
stop("requested gradient.order differs from the derivative order stored in this condistribution object; refit or predict/evaluate with gradients=TRUE and the desired gradient.order",
call. = FALSE)
}
}
gout.masked <- gout
cont.idx <- which(x$bws$ixcon)
if (length(cont.idx)) {
drop.idx <- cont.idx[!available]
if (length(drop.idx))
gout.masked[, drop.idx] <- NA_real_
}
gout.masked
}
predict.condistribution <- function(object, se.fit = FALSE, ...) {
se.fit <- npValidateScalarLogical(se.fit, "se.fit")
dots <- list(...)
if ("se" %in% names(dots)) {
supplied.se <- npValidateScalarLogical(dots[["se", exact = TRUE]], "se")
if (!identical(supplied.se, se.fit))
stop("conflicting 'se' and 'se.fit' requests; use se.fit to request prediction standard errors",
call. = FALSE)
}
dots[["se"]] <- se.fit
has.formula.route <- !is.null(object$bws$formula)
if (!has.formula.route)
dots <- .np_match_native_args(dots, npcdist.condbandwidth,
c("txdat", "tydat"))
if ((!is.null(dots$exdat) || !is.null(dots$eydat)) && !is.null(dots$newdata))
dots$newdata <- NULL
if (!has.formula.route &&
is.null(dots$exdat) &&
is.null(dots$eydat) &&
!is.null(dots$newdata)) {
parts <- .np_native_newdata_parts(dots$newdata,
list(exdat = object$xnames, eydat = object$ynames), "predict")
dots$eydat <- parts$eydat
dots$exdat <- parts$exdat
dots$newdata <- NULL
}
dots <- .np_conditional_replay_proper(object, dots, prediction = TRUE)
dots[[".np_lp_first_se_demand"]] <- FALSE
dots[[".np_conditional_cat_se_demand"]] <- FALSE
tr <- do.call(npcdist, c(list(bws = object$bws), dots))
if(se.fit)
return(list(fit = fitted(tr), se.fit = se(tr),
df = tr$nobs))
else
return(fitted(tr))
}
summary.condistribution <- function(object, ...){
cat("\nConditional Distribution Data: ", object$ntrain, " training points,",
if (object$trainiseval) "" else paste(" and ", object$nobs, " evaluation points,\n", sep=""),
" in ", object$xndim + object$yndim, " variable(s)",
"\n(", object$yndim, " dependent variable(s), and ", object$xndim, " explanatory variable(s))\n\n",
sep="")
cat(genOmitStr(object))
printSearchParameterSummary(object$ybw, object$ynames, object$bws, vari = "y",
role = "Dependent",
fallback.label = paste("Dep. Var. ", object$pscaling, ":", sep = ""))
printSearchParameterSummary(object$xbw, object$xnames, object$bws, vari = "x",
role = "Explanatory",
fallback.label = paste("Exp. Var. ", object$pscaling, ":", sep = ""))
cat(genDenEstStr(object))
cat(genBwKerStrs(object$bws))
if (!is.null(object$proper.requested) && !is.null(object$proper.applied)) {
proper.state <- if (isTRUE(object$proper.applied)) {
sprintf("requested and applied (%s)", object$proper.method)
} else if (isTRUE(object$proper.requested)) {
"requested but not applied"
} else {
"not requested"
}
cat("\nProper distribution repair:", proper.state)
}
cat(genTimingStr(object))
cat('\n\n')
}
Any scripts or data that you put into this service are public.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.