Learn R Programming

apollo (version 0.0.8)

apollo_normalDensity: Calculates density from a Normal distribution

Description

Calculates density from a Normal distribution at a specific value with a specified mean and standard deviation.

Usage

apollo_normalDensity(normalDensity_settings, functionality)

Arguments

normalDensity_settings

List of arguments to the functions. It must contain the following.

  • outcomeNormal: Numeric vector. Dependant variable.

  • xNormal: Numeric vector. Single explanatory variable.

  • mu: Numeric scalar. Intercept of the linear model.

  • sigma: Numeric scalar. Variance of error component of linear model to be estimated.

  • rows: Boolean vector. Consideration of rows in the likelihood calculation, FALSE to exclude. Length equal to the number of observations (nObs). Default is "all", equivalent to rep(TRUE, nObs).

functionality

Character. Can take different values depending on desired output.

  • "estimate": Used for model estimation.

  • "prediction": Used for model predictions.

  • "validate": Used for validating input.

  • "zero_LL": Used for calculating null likelihood.

  • "conditionals": Used for calculating conditionals.

  • "output": Used for preparing output after model estimation.

  • "raw": Used for debugging.

Value

The returned object depends on the value of argument functionality as follows.

  • "estimate": vector/matrix/array. Returns the probabilities for the chosen value for each observation.

  • "prediction": Not applicable.

  • "validate": Boolean. Returns TRUE if all tests are passed.

  • "zero_LL": Not applicable.

  • "conditionals": Same as "estimate".

  • "output": Same as "estimate" but also writes summary of choices into temporary file (later read by apollo_modelOutput).

  • "raw": Same as "estimate".

Details

This function estimates the linear model outcomeNormal = mu + xNormal + epsilon, where epsilon is a random error distributed Normal(0,sigma). If using this function in the context of an Integrated Choice and Latent Variable (ICLV) model with continuous indicators, then outcomeNormal would be the value of the indicator, xNormal would be the value of the latent variable (possibly multiplied by a parameter to measure its correlation with the indicator, e.g. xNormal=lambda*LV), and mu would be an additional parameter to be estimated (the mean of the indicator, which should be fixed to zero if the indicator is centered around its mean beforehand).

Examples

Run this code
# NOT RUN {
### Load data
xNormal <- runif(100)
outcomeNormal <- 1 + 2*xNormal + rnorm(100, mean=0, sd=0.5)

### Parameters
b = list(a=1, m=2)

### normalDensity settings
normalDensity_settings <- list(
   outcomeNormal     = outcomeNormal,
   xNormal     = 2*xNormal,
   mu    = 1,
   sigma = 0.5
)

### Compute choice probabilities using MNL model
apollo_normalDensity(normalDensity_settings, functionality="estimate")
# }

Run the code above in your browser using DataLab