MeanFunction | R Documentation |
For the generalised linear mixed model
For the generalised linear mixed model
Y \sim F(\mu,\sigma)
\mu = h^-1(X\beta + Z\gamma)
\gamma \sim MVN(0,D)
this class defines the fixed effects design matrix X. The mean function is defined by a model formula, data, and parameters. A new instance can be generated with $new(). The class will generate the relevant matrix X automatically. See glmmrBase for a detailed guide on model specification.
Specification of the mean function follows standard model formulae in R.
For example for a stepped-wedge cluster trial model, a typical mean model is
E(y_{ijt}|\delta)=\beta_0 + \tau_t + \beta_1 d_{jt} + z_{ijt}\delta
where \tau_t
are fixed effects for each time period. The formula specification for this would be '~ factor(t) + int'
where 'int' is the name of the variable indicating the treatment.
One can also include non-linear functions of variables in the mean function, and name the parameters. The resulting X matrix is then a matrix of first-order partial derivatives. For example, one can specify '~ int + b_1*exp(b_2*x)'.
Using 'update_parameters()' is the preferred way of updating the parameters of the mean or covariance objects as opposed to direct assignment, e.g. 'self$parameters <- c(...)'. The function calls check functions to automatically update linked matrices with the new parameters.
formula
model formula for the fixed effects
data
Data frame with data required to build X
parameters
A vector of parameter values for \beta
used for simulating data and calculating
covariance matrix of observations for non-linear models.
offset
An optional vector specifying the offset values
X
the fixed effects design matrix
n()
Returns the number of observations
MeanFunction$n()
...
ignored
The number of observations in the model
\dontshow{ setParallel(FALSE) # for the CRAN check } df <- nelder(~(cl(4)*t(5)) > ind(5)) df$int <- 0 df[df$cl <= 2, 'int'] <- 1 mf1 <- MeanFunction$new(formula = ~ int , data=df, parameters = c(-1,1) ) mf1$n()
new()
Create a new MeanFunction object
MeanFunction$new( formula, data, parameters = NULL, offset = NULL, verbose = FALSE )
formula
A formula object that describes the mean function, see Details
data
(Optional) A data frame containing the covariates in the model, named in the model formula
parameters
(Optional) A vector with the values of the parameters \beta
to use in data simulation and covariance calculations.
If the parameters are not specified then they are initialised to 0.
offset
A vector of offset values (optional)
verbose
Logical indicating whether to report detailed output
A MeanFunction object
\dontshow{ setParallel(FALSE) # for the CRAN check } df <- nelder(~(cl(4)*t(5)) > ind(5)) df$int <- 0 df[df$cl <= 2, 'int'] <- 1 mf1 <- MeanFunction$new(formula = ~ int , data=df, parameters = c(-1,1), )
print()
Prints details about the object
MeanFunction$print()
...
ignored
update_parameters()
Updates the model parameters
MeanFunction$update_parameters(parameters)
parameters
A vector of parameters for the mean function.
verbose
Logical indicating whether to provide more detailed feedback
colnames()
Returns or replaces the column names of the data in the object
MeanFunction$colnames(names = NULL)
names
If NULL then the function prints the column names, if a vector of names, then it attempts to replace the current column names of the data
\dontshow{ setParallel(FALSE) # for the CRAN check } df <- nelder(~(cl(4)*t(5)) > ind(5)) df$int <- 0 df[df$cl <= 5, 'int'] <- 1 mf1 <- MeanFunction$new(formula = ~ int , data=df, parameters = c(-1,1) ) mf1$colnames(c("cluster","time","individual","treatment")) mf1$colnames()
subset_rows()
Keeps a subset of the data and removes the rest
All indices not in the provided vector of row numbers will be removed from both the data and fixed effects design matrix X.
MeanFunction$subset_rows(index)
index
Rows of the data to keep
NULL
\dontshow{ setParallel(FALSE) # for the CRAN check } df <- nelder(~(cl(4)*t(5)) > ind(5)) df$int <- 0 df[df$cl <= 5, 'int'] <- 1 mf1 <- MeanFunction$new(formula = ~ int , data=df, parameters = c(-1,1) ) mf1$subset_rows(1:20)
linear_predictor()
Returns the linear predictor
Returns the linear predictor, X * beta
MeanFunction$linear_predictor()
A vector
any_nonlinear()
Returns a logical indicating whether the mean function contains non-linear functions of model parameters. Mainly used internally.
MeanFunction$any_nonlinear()
None. Called for effects
clone()
The objects of this class are cloneable with this method.
MeanFunction$clone(deep = FALSE)
deep
Whether to make a deep clone.
## ------------------------------------------------
## Method `MeanFunction$n`
## ------------------------------------------------
df <- nelder(~(cl(4)*t(5)) > ind(5))
df$int <- 0
df[df$cl <= 2, 'int'] <- 1
mf1 <- MeanFunction$new(formula = ~ int ,
data=df,
parameters = c(-1,1)
)
mf1$n()
## ------------------------------------------------
## Method `MeanFunction$new`
## ------------------------------------------------
df <- nelder(~(cl(4)*t(5)) > ind(5))
df$int <- 0
df[df$cl <= 2, 'int'] <- 1
mf1 <- MeanFunction$new(formula = ~ int ,
data=df,
parameters = c(-1,1),
)
## ------------------------------------------------
## Method `MeanFunction$colnames`
## ------------------------------------------------
df <- nelder(~(cl(4)*t(5)) > ind(5))
df$int <- 0
df[df$cl <= 5, 'int'] <- 1
mf1 <- MeanFunction$new(formula = ~ int ,
data=df,
parameters = c(-1,1)
)
mf1$colnames(c("cluster","time","individual","treatment"))
mf1$colnames()
## ------------------------------------------------
## Method `MeanFunction$subset_rows`
## ------------------------------------------------
df <- nelder(~(cl(4)*t(5)) > ind(5))
df$int <- 0
df[df$cl <= 5, 'int'] <- 1
mf1 <- MeanFunction$new(formula = ~ int ,
data=df,
parameters = c(-1,1)
)
mf1$subset_rows(1:20)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.