curvefit.core.effects2params
Map Vector of Fixed and Random Effects to Parameter Matrix
Extracts fixed and random effects and converts them to parameters.
Needs to use unzip_x
.
Syntax
params = curvefit.core.effects2params.effects2params(
x, group_sizes, covs, link_fun, var_link_fun, expand=True
)
Arguments
x (np.array)
: This is a one dimensional numpy array contain a value for the fixed effects followed by the random effects. The random effects are divided into sub-vectors with length equal to the number of fixed effects. The i-th sub-vector corresponds to the i-th group of observations.group_sizes (array-like)
: A vector of positive integers. The firstgroup_sizes[0]
observations correspond to the first group, the nextgroup_sizes[1]
corresponds to the section group, and so on. The total number of observations is the sum of the group sizes.covs (List[np.ndarray])
: Is alist
with length equal to the number of parameters andcovs[k]
is a two dimensional numpy array with the following contents: --covs[k].shape[0]
is the number of observations --covs[k].shape[1]
is the number of fixed effects corresponding to the k-th parameter. --covs[k][i, ell]
is the covariate value corresponding to the i-th observation and ell-th covariate for the k-th parameter.link_fun
(List[Callable]): The value
len(link_fun)is equal to the number of parameters and
link_fun[k]` is a function with one numpy array argument and result that acts element by element and transforms the k-th parameter.var_link_fun
(List[Callable]): The value
len(var_link_fun)is equal to the number of fixed effects and
link_fun[j]is a function with one numpy array argument and result that that acts element by element and transforms the j-th fixed effect. The first
len(covs[0])fixed effects correspond to the first parameter, the next
len(covs[1])` fixed effects correspond to the second parameter and so on.expand (bool)
: If expand isTrue
(False
), create parameters for each observation (for each group of observations).
Returns
params (array-like)
: Let be the vector of fixed effects and the matrix of random effects corresponding to x. We define the matrix, with row dimension equal the number of groups and column dimension equal the number of fixed effects where is the functionvar_link_fun[i]
. If expand is true (false) indexes observations (groups). (If expand is true the random effect for a group gets repeated for all the observations in the group.) The return valueparams
is a two dimensional numpy array withparams.shape[0]
equal to the number of parameters andparams.shape[1]
equal to the number of observations, if expand is true, number of groups, if expand is false. The valueparams[k][i]
is where is the functionlink_fun[k]
, is the set of fixed effects indices corresponding to the k-th parameter, is the covariate value corresponding to the j-th fixed effect and the i-th observation, if expand is true, or i-th group, if expand is false.
Example
See effects2params_xam.