Design.Misc {Design} | R Documentation

## Miscellaneous Design Attributes and Utility Functions

### Description

These functions are used internally to `anova.Design`, `fastbw`, etc., to retrieve various attributes of a design. These functions allow some fitting functions not in the `Design` series (e.g,, `lm`, `glm`) to be used with `anova.Design`, `fastbw`, and similar functions.

For `Varcov`, there are these functions: `Varcov.default`, `Varcov.lm`, `Varcov.glm`. The `oos.loglik` function for each type of model implemented computes the -2 log likelihood for out-of-sample data (i.e., data not necessarily used to fit the model) evaluated at the parameter estimates from a model fit. Vectors for the model's linear predictors and response variable must be given. `oos.loglik` is used primarily by `bootcov`.

The `Getlim` function retrieves distribution summaries from the fit or from a `datadist` object. It handles getting summaries from both sources to fill in characteristics for variables that were not defined during the model fit. `Getlimi` returns the summary for an individual model variable.

The `related.predictors` function returns a list containing variable numbers that are directly or indirectly related to each predictor. The `interactions.containing` function returns indexes of interaction effects containing a given predictor. The `param.order` function returns a vector of logical indicators for whether parameters are associated with certain types of effects (nonlinear, interaction, nonlinear interaction).

The `Penalty.matrix` function builds a default penalty matrix for non-intercept term(s) for use in penalized maximum likelihood estimation. The `Penalty.setup` function takes a constant or list describing penalty factors for each type of term in the model and generates the proper vector of penalty multipliers for the current model.

The `lrtest` function does likelihood ratio tests for two nested models, from fits that have `stats` components with `"Model L.R."` values. For models such as `psm, survreg, ols, lm` which have scale parameters, it is assumed that scale parameter for the smaller model is fixed at the estimate from the larger model (see the example).

`univarLR` takes a multivariable model fit object from `Design` and re-fits a sequence of models containing one predictor at a time. It prints a table of likelihood ratio chi^2 statistics from these fits.

The `Newlabels` function is used to override the variable labels in a fit object. Likewise, `Newlevels` can be used to create a new fit object with levels of categorical predictors changed. These two functions are especially useful when constructing nomograms.

`DesignFit` is used to convert a fit from non-Design functions (e.g., `glm`) that were invoked with Design in effect to Design functions so that `anova.Design` will be called by `anova()`, etc. So that the original fit's `residuals` and `print` methods, if they exist, will be called, there are functions `print.Design` and `residuals.Design` to dispatch them. These two functions are not needed in versions of S-Plus prior to 5.x (i.e., non-SV4).

### Usage

    ## S3 method for class 'cph':
    Varcov(object, regcoef.only=FALSE, ...)
    ## S3 method for class 'glmD':
    Varcov(object, regcoef.only=FALSE, ...)
    ## S3 method for class 'glsD':
    Varcov(object, regcoef.only=FALSE, ...)
    ## S3 method for class 'lrm':
    Varcov(object, regcoef.only=FALSE, ...)
    ## S3 method for class 'ols':
    Varcov(object, regcoef.only=FALSE, ...)
    ## S3 method for class 'psm':
    Varcov(object, regcoef.only=FALSE, ...)

    oos.loglik(fit, ...)

    ## S3 method for class 'ols':
    oos.loglik(fit, lp, y, ...)
    ## S3 method for class 'lrm':
    oos.loglik(fit, lp, y, ...)
    ## S3 method for class 'cph':
    oos.loglik(fit, lp, y, ...)
    ## S3 method for class 'psm':
    oos.loglik(fit, lp, y, ...)
    ## S3 method for class 'glmD':
    oos.loglik(fit, lp, y, ...)

    num.intercepts(fit)

    Getlim(at, allow.null=FALSE, need.all=TRUE)
    Getlimi(name, Limval, need.all=TRUE)

    related.predictors(at, type=c("all","direct"))
    interactions.containing(at, pred)
    param.order(at, term.order)

    Penalty.matrix(at, X)
    Penalty.setup(at, penalty)

    lrtest(fit1, fit2)
    ## S3 method for class 'lrtest':
    print(x, ...)

    univarLR(fit)

    Newlabels(fit, ...)
    Newlevels(fit, ...)
    ## S3 method for class 'Design':
    Newlabels(fit, labels, ...)
    ## S3 method for class 'Design':
    Newlevels(fit, levels, ...)

    DesignFit(fit)  # fit from glm, lm, etc.,then use anova etc. on result

### Arguments

`fit` | result of a fitting function
`object` | result of a fitting function
`at` | `Design` element of a fit
`pred` | index of a predictor variable (main effect)
`fit1` |
`fit2` | fit objects from `lrm,ols,psm,cph` etc. It doesn't matter which fit object is the sub-model.
`regcoef.only` | for fits such as parametric survival models which have a final row and column of the covariance matrix for a non-regression parameter such as a log(scale) parameter, setting `regcoef.only=TRUE` causes only the first `p` rows and columns of the covariance matrix to be returned, where `p` is the length of `object$coef`.
`lp` | linear predictor vector for `oos.loglik`. For proportional odds ordinal logistic models, this should have used the first intercept only. If `lp` and `y` are omitted, the -2 log likelihood for the original fit are returned.
`y` | values of a new vector of responses passed to `oos.loglik`.
`name` | the name of a variable in the model
`Limval` | an object returned by `Getlim`
`allow.null` | prevents `Getlim` from issuing an error message if no limits are found in the fit or in the object pointed to by `options(datadist=)`
`need.all` | set to `FALSE` to prevent `Getlim` or `Getlimi` from issuing an error message if data for a variable are not found
`type` | set to `"direct"` to return lists of indexes of directly related factors only (those in interactions with the predictor)
`term.order` | 1 for all parameters, 2 for all parameters associated with either nonlinear or interaction effects, 3 for nonlinear effects (main or interaction), 4 for interaction effects, 5 for nonlinear interaction effects.
`X` | a design matrix, not including columns for intercepts
`penalty` | a vector or list specifying penalty multipliers for types of model terms
`x` | a result of `lrtest`
`labels` | a character vector specifying new labels for variables in a fit. To give new labels for all variables, you can specify `labels` of the form `labels=c("Age in Years","Cholesterol")`, where the list of new labels is assumed to be the length of all main effect-type variables in the fit and in their original order in the model formula. You may specify a named vector to give new labels in random order or for a subset of the variables, e.g., `labels=c(age="Age in Years",chol="Cholesterol")`.
`levels` | a list of named vectors specifying new level labels for categorical predictors. This will override `parms` as well as `datadist` information (if available) that were stored with the fit.
`...` | other arguments; for `Varcov` the first argument is the fit object

### Value

`Varcov` returns a variance-covariance matrix, and `num.intercepts` returns an integer with the number of intercepts in the model. `oos.loglik` returns a scalar -2 log likelihood value. `Getlim` returns a list with components `limits` and `values`, either stored in `fit` or retrieved from the object created by `datadist` and pointed to in `options(datadist=)`. `related.predictors` returns a list of vectors, and `interactions.containing` returns a vector. `param.order` returns a logical vector corresponding to non-strata terms in the model. `Penalty.matrix` returns a symmetric matrix with dimension equal to the number of slopes in the model. For all but categorical predictor main effect elements, the matrix is diagonal with values equal to the variances of the columns of `X`. For segments corresponding to `c-1` dummy variables for `c`-category predictors, puts a `c-1` x `c-1` sub-matrix in `Penalty.matrix` that is constructed so that a quadratic form with `Penalty.matrix` in the middle computes the sum of squared differences in parameter values about the mean, including a portion for the reference cell in which the parameter is by definition zero. `Newlabels` returns a new fit object with the labels adjusted. `DesignFit` returns the original object but with `oldClass` of `"Design"` and with a new attribute `"fitFunction"` containing the original vector of classes.

### See Also

`Design`, `fastbw`, `anova.Design`, `summary.lm`, `summary.glm`, `datadist`, `vif`, `bootcov`

### Examples

    ## Not run:
    f <- psm(S ~ x1 + x2 + sex + race, dist='gau')
    g <- psm(S ~ x1 + sex + race, dist='gau',
             fixed=list(scale=exp(f$parms)))
    lrtest(f, g)

    g <- Newlabels(f, c(x2='Label for x2'))
    g <- Newlevels(g, list(sex=c('Male','Female'),race=c('B','W')))
    nomogram(g)
    ## End(Not run)

[Package Contents]