# set up model and fit linear model linear_model = LinearRegression(fit_intercept=False) linear_model.fit(design, Y) # extract the coefficients for linear model estimator betas = get_coef(linear_model, 'coef_') # calculate coefficient of determination (r-squared) r_squared = r2_score(Y, linear_model.predict(design), multioutput='raw_values') # project r-squared back to channels by times space r_squared = r_squared.reshape((n_channels, n_times)) r_squared = EvokedArray(r_squared, epochs_info, tmin) ############################################################################### # plot model r-squared # only show -250 to 500 ms ts_args = dict(xlim=(-.25, 0.5), unit=False, ylim=dict(eeg=[0, 0.8])) topomap_args = dict(cmap='Reds', scalings=dict(eeg=1), vmin=0, vmax=0.8, average=0.05) # create plot fig = r_squared.plot_joint(ts_args=ts_args, topomap_args=topomap_args, title='Proportion of variance explained by ' 'predictors', times=[.13, .23]) fig.axes[0].set_ylabel('R-squared')
# arguments fot the topographical maps topomap_args = dict(cmap='magma_r', scalings=dict(eeg=1), sensors=False, time_unit='ms', vmin=0.0, vmax=F.max(), average=0.05, extrapolate='head', outlines='head') title = 'Main effect incong. vs cong.' fig = F_evoked.plot_joint(ttp, ts_args=ts_args, topomap_args=topomap_args, title=title, show=False) fig.axes[-1].texts[0]._fontproperties._size = 12.0 # noqa fig.axes[-1].texts[0]._fontproperties._weight = 'bold' # noqa fig.axes[0].set_xticks(list(np.arange(-0.25, 1.05, 0.25)), minor=False) fig.axes[0].set_xticklabels(list(np.arange(-250, 1005, 250))) fig.axes[0].set_xlabel('Time (ms)') fig.axes[0].set_yticks(list(np.arange(0.0, F.max() + 2, 4)), minor=False) fig.axes[0].axvline(x=0.0, ymin=0.0, ymax=F.max() + 2, color='black', linestyle='dashed', linewidth=.8) fig.axes[0].spines['top'].set_visible(False)