Beispiel #1
0
def test_resid_rename_warnings_ar():
    model = ARModel(design=X, rho=0.4)
    results_ar = model.fit(Y)
    with pytest.warns(FutureWarning, match="'resid'"):
        assert_array_equal(results_ar.resid, results_ar.residuals)
    with pytest.warns(FutureWarning, match="'wresid"):
        assert_array_equal(results_ar.wresid, results_ar.whitened_residuals)
Beispiel #2
0
def ts_glm(pupilts,
           con_onsets,
           incon_onsets,
           neut_onsets,
           blinks,
           sampling_rate=30.):
    """
    Currently runs the following contrasts:
        Incongruent: [0,1,0,0,0]
        Congruent:   [0,0,1,0,0]
        Neutral:     [0,0,0,1,0]  
        Incon-Neut:  [0,1,0,-1,0]
        Con-Neut:    [0,0,1,-1,0]
        Incon-Con:   [0,1,-1,0,0]
    """
    signal_filt = ts.TimeSeries(pupilts, sampling_rate=sampling_rate)
    con_ts = get_event_ts(pupilts, con_onsets)
    incon_ts = get_event_ts(pupilts, incon_onsets)
    neut_ts = get_event_ts(pupilts, neut_onsets)
    kernel_end_sec = 3.
    kernel_length = kernel_end_sec / (1 / sampling_rate)
    kernel_x = np.linspace(0, kernel_end_sec, int(kernel_length))
    con_reg, con_td_reg = pupil_utils.regressor_tempderiv(con_ts,
                                                          kernel_x,
                                                          s1=1000.,
                                                          tmax=1.30)
    incon_reg, incon_td_reg = pupil_utils.regressor_tempderiv(incon_ts,
                                                              kernel_x,
                                                              s1=1000.,
                                                              tmax=1.30)
    neut_reg, neut_td_reg = pupil_utils.regressor_tempderiv(neut_ts,
                                                            kernel_x,
                                                            s1=1000.,
                                                            tmax=1.30)
    #kernel = pupil_utils.pupil_irf(kernel_x, s1=1000., tmax=1.30)
    #plot_event(signal_filt, con_ts, incon_ts, neut_ts, kernel, pupil_fname)
    intercept = np.ones_like(signal_filt.data)
    X = np.array(
        np.vstack((intercept, incon_reg, con_reg, neut_reg, blinks.values)).T)
    Y = np.atleast_2d(signal_filt).T
    model = ARModel(X, rho=1.).fit(Y)
    tIncon = float(model.Tcontrast([0, 1, 0, 0, 0]).t)
    tCon = float(model.Tcontrast([0, 0, 1, 0, 0]).t)
    tNeut = float(model.Tcontrast([0, 0, 0, 1, 0]).t)
    tIncon_Neut = float(model.Tcontrast([0, 1, 0, -1, 0]).t)
    tCon_Neut = float(model.Tcontrast([0, 0, 1, -1, 0]).t)
    tIncon_Con = float(model.Tcontrast([0, 1, -1, 0, 0]).t)
    resultdict = {
        'Incon_t': tIncon,
        'Con_t': tCon,
        'Neut_t': tNeut,
        'InconNeut_t': tIncon_Neut,
        'ConNeut_t': tCon_Neut,
        'InconCon_t': tIncon_Con
    }
    return resultdict
Beispiel #3
0
def ts_glm(pupilts, trg_onsets, std_onsets, blinks, sampling_rate=30.):
    signal_filt = ts.TimeSeries(pupilts, sampling_rate=sampling_rate)
    trg_ts = get_event_ts(pupilts, trg_onsets)
    std_ts = get_event_ts(pupilts, std_onsets)
    kernel_end_sec = 2.5
    kernel_length = kernel_end_sec / (1 / sampling_rate)
    kernel_x = np.linspace(0, kernel_end_sec, int(kernel_length))
    trg_reg, trg_td_reg = pupil_utils.regressor_tempderiv(trg_ts, kernel_x)
    std_reg, std_td_reg = pupil_utils.regressor_tempderiv(std_ts, kernel_x)
    #kernel = pupil_irf(kernel_x)
    #plot_event(signal_filt, trg_ts, std_ts, kernel, fname)
    intercept = np.ones_like(signal_filt.data)
    X = np.array(np.vstack((intercept, trg_reg, std_reg, blinks.values)).T)
    Y = np.atleast_2d(signal_filt).T
    model = ARModel(X, rho=1.).fit(Y)
    tTrg = float(model.Tcontrast([0, 1, 0, 0]).t)
    tStd = float(model.Tcontrast([0, 0, 1, 0]).t)
    tTrgStd = float(model.Tcontrast([0, 1, -1, 0]).t)
    resultdict = {
        'Target_Beta': tTrg,
        'Standard_Beta': tStd,
        'ContrastT': tTrgStd
    }
    return resultdict
Beispiel #4
0
def test_AR_degenerate():
    Xd = X.copy()
    Xd[:, 0] = Xd[:, 1] + Xd[:, 2]
    model = ARModel(design=Xd, rho=0.9)
    results = model.fit(Y)
    assert results.df_residuals == 31
Beispiel #5
0
def test_AR():
    model = ARModel(design=X, rho=0.4)
    results = model.fit(Y)
    assert results.df_residuals == 30
    assert results.residuals.shape[0] == 40
    assert results.predicted.shape[0] == 40
Beispiel #6
0
def test_AR_degenerate():
    Xd = X.copy()
    Xd[:, 0] = Xd[:, 1] + Xd[:, 2]
    model = ARModel(design=Xd, rho=0.9)
    results = model.fit(Y)
    assert_equal(results.df_resid, 31)
Beispiel #7
0
def test_AR():
    model = ARModel(design=X, rho=0.4)
    results = model.fit(Y)
    assert_equal(results.df_resid, 30)