logpostNorm: Observed-data log-posterior density for incomplete...

Description Usage Arguments Details Value Author(s) References See Also Examples

View source: R/norm2.R

Description

Computes the observed-data log-posterior density function at given parameter values for an incomplete dataset under a normal model.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
logpostNorm(obj, ...)


## Default S3 method:
logpostNorm(obj, x = NULL, intercept = TRUE, param, 
   prior = "uniform", prior.df = NULL, prior.sscp = NULL, ...)


## S3 method for class 'formula'
logpostNorm(formula, data, param, 
   prior = "uniform", prior.df = NULL, prior.sscp = NULL, ...)


## S3 method for class 'norm'
logpostNorm(obj, param = obj$param, prior = obj$prior,
   prior.df = obj$prior.df, prior.sscp = obj$prior.sscp, ...)

Arguments

obj

an object used to select a method. It may be y, a numeric matrix, vector or data frame of responses to be modeled as normal. Missing values (NAs) are allowed. If y is a data frame, any factors or ordered factors will be replaced by their internal codes, and a warning will be given. Alternatively, this first argument may be a formula as described below, or an object of class "norm" resulting from a call to emNorm or mcmcNorm; see DETAILS.

x

a numeric matrix, vector or data frame of covariates to be used as predictors for y. Missing values (NA's) are not allowed. If x is a matrix, it must have the same number of rows as y. If x is a data frame, any factors or ordered factors are replaced by their internal codes, and a warning is given. If NULL, it defaults to x = rep(1,nrow(y)), an intercept-only model.

intercept

if TRUE, then a column of 1's is appended to x. Ignored if x = NULL.

formula

an object of class "formula" (or one that can be coerced to that class): a symbolic description of the model which is provided in lieu of y and x. The details of model specification are given under DETAILS.

data

an optional data frame, list or environment (or object coercible by as.data.frame to a data frame) containing the variables in the model. If not found in data, the variables are taken from environment(formula), typically the environment from which logpostNorm is called.

param

assumed values for the model parameters. This must be a list with two named components, beta and sigma, which are numeric matrices with correct dimensions. In most circumstances, the parameter values will be obtained from a run of emNorm or mcmcNorm; see DETAILS.

prior

should be "uniform", "jeffreys", "ridge" or "invwish". If "ridge" then prior.df must be supplied. If "invwish" then prior.df and prior.sscp must be supplied.

prior.df

prior degrees of freedom for a ridge (prior="ridge") or inverted Wishart (prior="invwish") prior.

prior.sscp

prior sums of squares and cross-products (SSCP) matrix for an inverted Wishart prior (prior="invwish").

...

values to be passed to the methods.

Details

The simplest way to call logpostNorm is to provide an object of class "norm" as its sole argument, where that object is the result of a call to emNorm or mcmcNorm. The parameter values stored in that object will then be passed to logpostNorm automatically.

Alternatively, one may call logpostNorm by providing as the first argument y, a vector or matrix of data to be modeled as normal, and an optional vector or matrix of predictors x. Missing values NA are allowed in y but not in x.

A third way to call logpostNorm is to provide formula, a formula for a (typically multivariate) linear regression model in the manner expected by lm. A formula is given as y ~ model, where y is either a single numeric variable or a matrix of numeric variables bound together with the function cbind. The right-hand side of the formula (everything to the right of ~) is a linear predictor, a series of terms separated by operators +, : or * to specify main effects and interactions. Factors are allowed on the right-hand side and will enter the model as contrasts among the levels. The intercept term 1 is included by default; to remove the intercept, use -1.

Value

a numeric value reporting the observed-data log-posterior density

Author(s)

Joe Schafer Joseph.L.Schafer@census.gov

References

Schafer, J.L. (1997) Analysis of Incomplete Multivariate Data. London: Chapman & Hall/CRC Press.

For more information about this function and other functions in the norm2 package, see User's Guide for norm2 in the library subdirectory doc.

See Also

emNorm, mcmcNorm, loglikNorm

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
## run EM for marijuana data with ridge prior and print the
## last value of the log-posterior density
data(marijuana)
emResult <- emNorm(marijuana, prior="ridge", prior.df=0.5)
print( emResult$logpost[ emResult$iter ] )

## compute the log-posterior density at the final estimate
## and compare it to the last value reported by emNorm
logpost.max <- logpostNorm(emResult)
print( logpost.max - emResult$logpost[ emResult$iter ] )

## The result from logpostNorm is slightly higher,
## because the last value reported by emNorm is the
## log-posterior at the BEGINNING of the last iteration

norm2 documentation built on Feb. 12, 2021, 5:10 p.m.