createPrior | R Documentation |
createPrior
creates a Cyclops prior object for use with fitCyclopsModel
.
createPrior(
priorType,
variance = 1,
exclude = c(),
graph = NULL,
neighborhood = NULL,
useCrossValidation = FALSE,
forceIntercept = FALSE
)
priorType |
Character: specifies prior distribution. See below for options |
variance |
Numeric: prior distribution variance |
exclude |
A vector of numbers or covariateId names to exclude from prior |
graph |
Child-to-parent mapping for a hierarchical prior |
neighborhood |
A list of first-order neighborhoods for a partially fused prior |
useCrossValidation |
Logical: Perform cross-validation to determine prior |
forceIntercept |
Logical: Force intercept coefficient into prior |
A Cyclops prior object of class inheriting from "cyclopsPrior"
for use with fitCyclopsModel
.
We specify all priors in terms of their variance parameters.
Similar fitting tools for regularized regression often parameterize the Laplace distribution
in terms of a rate "lambda"
per observation.
See "glmnet"
, for example.
variance = 2 * / (nobs * lambda)^2 or lambda = sqrt(2 / variance) / nobs
#Generate some simulated data:
sim <- simulateCyclopsData(nstrata = 1, nrows = 1000, ncovars = 2, eCovarsPerRow = 0.5,
model = "poisson")
cyclopsData <- convertToCyclopsData(sim$outcomes, sim$covariates, modelType = "pr",
addIntercept = TRUE)
#Define the prior and control objects to use cross-validation for finding the
#optimal hyperparameter:
prior <- createPrior("laplace", exclude = 0, useCrossValidation = TRUE)
control <- createControl(cvType = "auto", noiseLevel = "quiet")
#Fit the model
fit <- fitCyclopsModel(cyclopsData,prior = prior, control = control)
#Find out what the optimal hyperparameter was:
getHyperParameter(fit)
#Extract the current log-likelihood, and coefficients
logLik(fit)
coef(fit)
#We can only retrieve the confidence interval for unregularized coefficients:
confint(fit, c(0))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.