Description Usage Arguments Value Examples
Build and fit a neural network with random effects
1 2 3 | mistnet(x, y, n_z, layers, error_distribution,
z_prior = make_distribution("NO", mu = 0, sigma = 1), fit = TRUE,
mistnet_optimizer = mistnet_fit_optimx, ...)
|
x |
A numeric matrix of predictor variables |
y |
A numeric or integer matrix of response variables |
n_z, |
The number of latent random variables to include as predictors alongside x |
layers |
A list of |
error_distribution |
An |
z_prior |
A |
fit |
Logical. Should the model be fitted or should an untrained model
be returned? Defaults to |
mistnet_optimizer |
passed to |
... |
Additional arguments to |
An object of class network
and subclass mistnet_network
.
This object will contain the original x
and y
matrices,
a list of adjustable parameters (par_list
), [[etc.]]
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 | set.seed(1)
# Load data from the `vegan` package
data(mite, mite.env, package = "vegan")
# x is a matrix of environmental predictors
x = scale(model.matrix(~., data = mite.env)[, -1])
# y is a matrix of abundances (counts) for 35 species of mites
y = as.matrix(mite)
# Fit a neural network with one hidden layer of 10 nodes and an elu
# activation function. The response variable has a Poisson distribution
# with a log link (exp_activator). The prior distributions for each layer
# are each standard normal distributions, and two latent variables are used.
net = mistnet(
x = x,
y = y,
n_z = 2,
layers = list(
layer(
activator = elu_activator,
n_nodes = 10,
weight_prior = make_distribution("NO", mu = 0, sigma = 1)
),
layer(
activator = exp_activator,
n_nodes = ncol(y),
weight_prior = make_distribution("NO", mu = 0, sigma = 1)
)
),
error_distribution = make_distribution("PO")
)
print(net)
# show the model's predictions for each layer
str(feedforward(net, par = unlist(net$par_list)))
# Calculate the log-likelihood for each observation under the fitted model
log_prob(net, par = unlist(net$par_list), include_penalties = FALSE)
# Include penalty terms from the prior to calculate the log-posterior instead
log_prob(net, par = unlist(net$par_list), include_penalties = TRUE)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.