Skip to content

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 first group_sizes[0] observations correspond to the first group, the next group_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 a list with length equal to the number of parameters and covs[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 valuelen(link_fun)is equal to the number of parameters andlink_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 valuelen(var_link_fun)is equal to the number of fixed effects andlink_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 firstlen(covs[0])fixed effects correspond to the first parameter, the nextlen(covs[1])` fixed effects correspond to the second parameter and so on.
  • expand (bool): If expand is True (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 function var_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 value params is a two dimensional numpy array with params.shape[0] equal to the number of parameters and params.shape[1] equal to the number of observations, if expand is true, number of groups, if expand is false. The value params[k][i] is where is the function link_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.