ResponseFitter

class nideconv.ResponseFitter(input_signal, sample_rate, oversample_design_matrix=20, add_intercept=True, **kwargs)[source]

ResponseFitter takes an input signal and performs deconvolution on it. To do this, it requires event times, and possible covariates. ResponseFytter can, for each event_type, use different basis function sets, see Event.

Methods

add_confounds(name, confound) Add a timeseries or set of timeseries to the general design matrix as a confound
add_event(event_name[, onset_times, …]) create design matrix for a given event_type.
get_epochs(onsets, interval[, …]) Return a matrix corresponding to specific onsets, within a given interval.
get_rsq() calculate the rsq of a given fit.
predict_from_design_matrix([X]) predict a signal given a design matrix.
regress([type, cv, alphas, store_residuals]) Regress a created design matrix on the input_data.
ridge_regress([cv, alphas, store_residuals]) run CV ridge regression instead of ols fit.
add_intercept  
get_residuals  
get_time_to_peak  
get_timecourses  
plot_timecourses  
add_confounds(name, confound)[source]

Add a timeseries or set of timeseries to the general design matrix as a confound

Parameters:
confound : array

Confound of (n_timepoints) or (n_timepoints, n_confounds)

add_event(event_name, onset_times=None, basis_set='fir', interval=[0, 10], n_regressors=None, durations=None, covariates=None, **kwargs)[source]

create design matrix for a given event_type.

Parameters:
event_name : string

Name of the event_type, used as key to lookup this event_type’s characteristics

**kwargs : dict

keyward arguments to be internalized by the generated and internalized Event object. Needs to consist of the necessary arguments to create an Event object, see Event constructor method.

get_epochs(onsets, interval, remove_incomplete_epochs=True)[source]

Return a matrix corresponding to specific onsets, within a given interval. Matrix size is (n_onsets, n_timepoints_within_interval).

Note that any events that are in the ResponseFitter-object will be regressed out before calculating the epochs.

get_rsq()[source]

calculate the rsq of a given fit. calls predict_from_design_matrix to predict the signal that has been fit

predict_from_design_matrix(X=None)[source]

predict a signal given a design matrix. Requires regression to have been run.

Parameters:
X : np.array, (timepoints, n_regressors)

the design matrix for which to predict data.

regress(type='ols', cv=20, alphas=None, store_residuals=False)[source]

Regress a created design matrix on the input_data.

Creates internal variables betas, residuals, rank and s. The beta values are then injected into the event_type objects the ResponseFitter contains.

Parameters:
type : string, optional

the type of fit to be done. Options are ‘ols’ for np.linalg.lstsq, ‘ridge’ for CV ridge regression.

ridge_regress(cv=20, alphas=None, store_residuals=False)[source]

run CV ridge regression instead of ols fit. Uses sklearn’s RidgeCV class

Parameters:
cv : int

number of cross-validation folds

alphas : np.array

the alpha/lambda values to try out in the CV ridge regression