multipleOutcomes {multipleOutcomes} | R Documentation |
Fitting Regression Models for Multiple Outcomes and Returning the Matrix of Covariance
Description
multipleOutcomes
can fit different types of models for multiple outcomes
simultaneously and return model parameters and variance-covariance matrix
for further analysis.
Usage
multipleOutcomes(..., family, data, data_index = NULL, score_epsilon = 1e-06)
Arguments
... |
formulas of models to be fitted, or moment functions for gmm. |
family |
a character vector of families to be used in the models.
Currently only |
data |
a data frame if all models are fitted on the same dataset;
otherwise a list of data frames for fitting models in |
data_index |
|
score_epsilon |
whatever. |
Value
It returns an object of class "multipleOutcomes", which is a list containing the following components:
coefficients | an unnamed vector of coefficients of all fitted models.
Use id_map for variable mapping. |
mcov | a unnamed matrix of covariance of coefficients . Use id_map
for variable mapping. |
id_map | a list mapping the elements in coefficients and mcov to
variable names. |
n_shared_sample_sizes | a matrix of shared sample sizes between datasets being used to fit the models. |
call | the matched call. |
Examples
## More examples can be found in the vignettes.
library(mvtnorm)
genData <- function(seed = NULL){
set.seed(seed)
n <- 400
sigma <- matrix(c(1, .6, .6, 1), 2)
x <- rmvnorm(n, sigma = sigma)
gam <- c(.1, -.2)
z <- rbinom(n, 1, plogis(1-1/(1+exp(-.5+x%*%gam+.1*rnorm(n)))))
bet <- c(-.2,.2)
#y <- rbinom(n, 1, plogis(1-1/(1+exp(-.5+x%*%bet + .2*z-.3*rnorm(n)))))
y <- -.5+x%*%bet + .2*z-.3*rnorm(n)
data.frame(y = y, z = z, x1 = x[, 1], x2 = x[, 2])
}
dat <- genData(123456)
dat1 <- head(dat,200)
dat2 <- tail(dat,200)
## fitting four models simultaneously.
fit <-
multipleOutcomes(
y ~ z + x1 - 1,
z ~ x1 + x2,
z ~ x1 - 1,
y ~ x2,
## z can be fitted with a linear or logistic regression
family = c('gaussian', 'binomial', 'gaussian','gaussian'),
data = list(dat1, dat2),
## each dataset is used to fit two models
data_index = c(1, 1, 2, 2)
)
## unnamed coefficients of all model parameters
coef(fit)
## named coefficients of a specific model
coef(fit, 2)
## unnamed covariance matrix of all model parameters
vcov(fit)
## named covariance matrix of a specific model
vcov(fit, 1)
## summary of all parameter estimates
summary(fit)
## summary of parameters in a specific model
summary(fit, 4)