fitgrid.models module¶
- fitgrid.models.lm(epochs, LHS=None, RHS=None, parallel=False, n_cores=4, quiet=False, eval_env=4)[source]¶
Run ordinary least squares linear regression on the epochs.
- Parameters
epochs (Epochs) – epochs object on which regression is to be run
LHS (list of str, optional, defaults to all channels) – list of channels for the left hand side of the regression formula
RHS (str) – right hand side of the regression formula
parallel (bool, defaults to False) – change to True to run in parallel
n_cores (int, defaults to 4) – number of processes to use for computation
quiet (bool, defaults to False) – set to True to disable fitting progress bar
eval_env (int or patsy.EvalEnvironment, defaults to 4) – environment to use for evaluating patsy formulas, see patsy docs
- Returns
grid – LMFitGrid object containing the results of the regression
- Return type
- fitgrid.models.lmer(epochs, LHS=None, RHS=None, family='gaussian', conf_int='Wald', factors=None, permute=None, ordered=False, REML=True, parallel=False, n_cores=4, quiet=False)[source]¶
Fit lme4 linear mixed model by interfacing with R.
- Parameters
epochs (Epochs) – epochs object on which lmer is to be run
LHS (list of str, optional, defaults to all channels) – list of channels for the left hand side of the lmer formula
RHS (str) – right hand side of the lmer formula
family (str, defaults to ‘gaussian’) – distribution link function to use
conf_int (str, defaults to ‘Wald’)
factors (dict, optional) – Keys should be column names in data to treat as factors. Values should either be a list containing unique variable levels if dummy-coding or polynomial coding is desired. Otherwise values should themselves be dictionaries with unique variable levels as keys and desired contrast values (as specified in R!) as keys.
permute (int, defaults to None) – if non-zero, computes parameter significance tests by permuting test stastics rather than parametrically. Permutation is done by shuffling observations within clusters to respect random effects structure of data.
ordered (bool, defaults to False) – whether factors should be treated as ordered polynomial contrasts; this will parameterize a model with K-1 orthogonal polynomial regressors beginning with a linear contrast based on the factor order provided
REML (bool, defaults to True) – change to False to use ML estimation
parallel (bool, defaults to False) – change to True to run in parallel
n_cores (int, defaults to 4) – number of processes to use for computation
quiet (bool, defaults to False) – set to True to disable fitting progress bar
- Returns
grid – LMERFitGrid object containing the results of lmer fitting
- Return type
- fitgrid.models.lmer_single(data, channel, RHS, family, conf_int, factors, permute, ordered, REML)[source]¶
- fitgrid.models.run_model(epochs, function, channels=None, parallel=False, n_cores=4, quiet=False)[source]¶
Run an arbitrary model on the epochs.
- Parameters
epochs (Epochs) – the epochs object on which the model is to be run
function (Python function) – function that runs a model, see Notes below for details
channels (list of str) – list of channels to serve as dependent variables
parallel (bool, defaults to False) – set to True in order to run in parallel
n_cores (int, defaults to 4) – number of processes to run in parallel
quiet (bool, defaults to False) – set to True to disable progress bar display
- Returns
grid – a FitGrid object containing the results
- Return type
Notes
The function should take two parameters,
data
andchannel
, run some model on the data, and return an object containing the results.data
will be a snapshot across epochs at a single timepoint, containing all channels of interest.channel
is the name of the target variable that the function runs the model against (uses it as the dependent variable).Examples
Here’s an example of a function that can be passed to
run_model
:def regression(data, channel): formula = channel + ' ~ continuous + categorical' return ols(formula, data).fit()