View source: R/ordinal_reg-ordinalNet.R
| ordinalNet_wrapper | R Documentation |
ordinalNetThe fit wrapper restructures case weights and reorganizes arguments into a
call to ordinalNet::ordinalNet(). The prediction wrapper interpolates
between fitted penalties to enable submodel prediction at specified
penalties.
ordinalNet_wrapper(
x,
y,
weights = NULL,
family = "cumulative",
link = "logit",
parallel_reg = NULL,
parallelTerms = TRUE,
nonparallelTerms = FALSE,
parallelPenaltyFactor = 1,
...,
call = rlang::caller_env()
)
predict_ordinalNet_wrapper(
object,
newx,
type,
lambda,
criteria = c("aic", "bic")
)
## S3 method for class ''_ordinalNet''
predict(
object,
new_data,
type = NULL,
opts = list(),
penalty = NULL,
multi = FALSE,
...
)
## S3 method for class ''_ordinalNet''
multi_predict(
object,
new_data,
type = NULL,
opts = list(),
penalty = NULL,
...
)
## S3 method for class ''_ordinalNet''
predict_raw(object, new_data, opts = list(), ...)
## S3 method for class ''_ordinalNet''
predict_classprob(object, new_data, ...)
## S3 method for class ''_ordinalNet''
predict_class(object, new_data, ...)
x |
The predictor data. |
y |
The outcome vector. |
weights |
An optional numeric vector of case weights. When provided, the outcome is restructured into a multinomial matrix of weighted indicators. |
family |
The odds link function; either a standardized dial value
( |
link |
The ordinal link function; either a standardized dial value (e.g.
|
parallel_reg |
Logical; whether predictors share effects across
thresholds. When |
parallelTerms |
Logical; whether to use parallel terms. |
nonparallelTerms |
Logical; whether to use non-parallel terms. |
parallelPenaltyFactor |
Numeric; scale factor applied to the penalty on parallel terms. Errs when used without parallel terms. |
... |
Additional arguments to pass. |
penalty |
A numeric vector of penalty values. |
An object of S3 class ordinalNet as returned by
ordinalNet::ordinalNet(), or a vector or matrix of predictions as
returned by ordinalNet::predict.ordinalNet().
house_data <-
MASS::housing[rep(seq(nrow(MASS::housing)), MASS::housing$Freq), -5]
house_matrix <- model.matrix(
Sat ~ Type + Infl + Cont + 0,
data = house_data,
contrasts.arg = lapply(house_data[, 2:4], contrasts, contrasts = FALSE)
)
pen_vec <- 10 ^ seq(-2.5, -.5, 1)
# fit wrapper
( fit_orig <- ordinalNet::ordinalNet(
house_matrix, y = house_data$Sat,
family = "sratio", link = "logit",
lambdaVals = pen_vec
) )
( fit_wrap <- ordinalNet_wrapper(
house_matrix, y = house_data$Sat,
family = "sratio", link = "logit",
lambdaVals = pen_vec
) )
fit_tidy <-
ordinal_reg(ordinal_link = "logistic", odds_link = "stopping_ratio") %>%
set_engine("ordinalNet") %>%
set_args(path_values = pen_vec, penalty = 1) %>%
fit(formula = Sat ~ Type + Infl + Cont + 0, data = house_data)
fit_tidy$fit
# predict wrapper
predict(
fit_orig,
newx = head(house_matrix),
whichLambda = 2,
type = "response"
)
predict_ordinalNet_wrapper(
fit_tidy$fit,
newx = head(house_matrix),
type = "prob",
lambda = pen_vec[2]
)
predict_ordinalNet_wrapper(
fit_tidy$fit,
newx = head(house_matrix),
type = "prob",
lambda = .01
)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.