예제 #1
0
def test_dataset_init(variables):
    dataset = Dataset(*variables, X_names=["bork"])

    n = len(variables[0])
    assert dataset.X.shape == (n, 2)
    assert dataset.X_names == ["intercept", "bork"]

    dataset = Dataset(*variables, X_names=["bork"], add_intercept=False)
    assert dataset.X.shape == (n, 1)
    assert dataset.X_names == ["bork"]
예제 #2
0
def test_dataset_init(variables):
    """Test Dataset creation from numpy arrays."""
    dataset = Dataset(*variables, X_names=["bork"])

    n = len(variables[0])
    assert dataset.X.shape == (n, 2)
    assert dataset.X_names == ["intercept", "bork"]

    dataset = Dataset(*variables, X_names=["bork"], add_intercept=False)
    assert dataset.X.shape == (n, 1)
    assert dataset.X_names == ["bork"]
예제 #3
0
def test_combination_test_from_dataset(Cls, data, mode, expected):
    """Test CombinationTest Estimators with PyMARE Datasets."""
    dset = Dataset(y=data)
    est = Cls(mode).fit_dataset(dset)
    results = est.summary()
    z = ss.norm.isf(results.p)
    assert np.allclose(z, expected, atol=1e-5)
예제 #4
0
def dataset_2d(variables):
    y, v, X = variables
    y = np.repeat(y, 3, axis=1)
    y[:, 1] = np.random.randint(-10, 10, size=len(y))
    v = np.repeat(v, 3, axis=1)
    v[:, 1] = np.random.randint(2, 10, size=len(v))
    return Dataset(y, v, X)
예제 #5
0
def dataset_n():
    y = np.array(
        [[-3.0, -0.5, 0.0, -5.01, 0.35, -2.0, -6.0, -4.0, -4.3, -0.1, -1.0]]).T
    n = (np.array([[
        16, 16, 20.548, 32.597, 14.0, 11.118, 4.444, 12.414, 26.963, 130.556,
        126.76
    ]]).T / 2)
    return Dataset(y, n=n)
예제 #6
0
def dataset_n():
    y = np.array([[-3., -0.5, 0., -5.01, 0.35, -2., -6., -4., -4.3, -0.1,
                   -1.]]).T
    n = np.array([[
        16, 16, 20.548, 32.597, 14., 11.118, 4.444, 12.414, 26.963, 130.556,
        126.76
    ]]).T / 2
    return Dataset(y, sample_sizes=n)
예제 #7
0
def dataset_2d(variables):
    """Build a larger Dataset with 2D data."""
    y, v, X = variables
    y = np.repeat(y, 3, axis=1)
    y[:, 1] = np.random.randint(-10, 10, size=len(y))
    v = np.repeat(v, 3, axis=1)
    v[:, 1] = np.random.randint(2, 10, size=len(v))
    return Dataset(y, v, X)
예제 #8
0
파일: base.py 프로젝트: yifan0330/PyMARE
 def to_dataset(self, measure='g', **kwargs):
     y = self.get(measure)
     v = self.get('v_{}'.format(measure), error=False)
     try:
         n = self.get('n')
     except:
         n = None
     return Dataset(y=y, v=v, n=n, **kwargs)
예제 #9
0
 def to_dataset(self, measure, **kwargs):
     measure = measure.lower()
     y = self.get(measure)
     v = self.get("v_{}".format(measure), error=False)
     try:
         n = self.get("n")
     except:
         n = None
     return Dataset(y=y, v=v, n=n, **kwargs)
예제 #10
0
def dataset_n():
    """Build a Dataset with sample sizes, but no variances."""
    y = np.array(
        [[-3.0, -0.5, 0.0, -5.01, 0.35, -2.0, -6.0, -4.0, -4.3, -0.1, -1.0]]).T
    n = (np.array([[
        16, 16, 20.548, 32.597, 14.0, 11.118, 4.444, 12.414, 26.963, 130.556,
        126.76
    ]]).T / 2)
    return Dataset(y, n=n)
예제 #11
0
def test_exact_perm_test_1d_no_mods():
    dataset = Dataset([1, 1, 2, 1.3], [1.5, 1, 2, 4])
    results = DerSimonianLaird().fit(dataset).summary()
    pmr = permutation_test(results, 867)
    assert pmr.n_perm == 16
    assert pmr.exact
    assert isinstance(pmr.results, MetaRegressionResults)
    assert pmr.fe_p.shape == (1, 1)
    assert pmr.tau2_p.shape == (1, )
예제 #12
0
파일: base.py 프로젝트: neurostuff/PyMARE
 def to_dataset(self, measure, **kwargs):
     """Convert conversion results to a Dataset."""
     measure = measure.lower()
     y = self.get(measure)
     v = self.get("v_{}".format(measure), error=False)
     try:
         n = self.get("n")
     except:
         n = None
     return Dataset(y=y, v=v, n=n, **kwargs)
예제 #13
0
def test_2d_loop_warning(dataset_2d):
    est = VarianceBasedLikelihoodEstimator()
    y = np.random.normal(size=(10, 100))
    v = np.random.randint(1, 50, size=(10, 100))
    dataset = Dataset(y, v)
    # Warning is raised when 2nd dim is > 10
    with pytest.warns(UserWarning, match='Input contains'):
        est.fit(dataset)
    # But not when it's smaller
    est.fit(dataset_2d)
예제 #14
0
def test_stouffers_perm_test_exact():
    """Test the exact permutation test on Stouffers Estimator."""
    dataset = Dataset([1, 1, 2, 1.3], [1.5, 1, 2, 4])
    results = StoufferCombinationTest().fit_dataset(dataset).summary()
    pmr = results.permutation_test(2000)
    assert pmr.n_perm == 16
    assert pmr.exact
    assert isinstance(pmr.results, CombinationTestResults)
    assert pmr.perm_p["fe_p"].shape == (1, )
    assert "tau2_p" not in pmr.perm_p
예제 #15
0
def test_exact_perm_test_1d_no_mods():
    """Test the exact permutation test on 1D data."""
    dataset = Dataset([1, 1, 2, 1.3], [1.5, 1, 2, 4])
    results = DerSimonianLaird().fit_dataset(dataset).summary()
    pmr = results.permutation_test(867)
    assert pmr.n_perm == 16
    assert pmr.exact
    assert isinstance(pmr.results, MetaRegressionResults)
    assert pmr.perm_p["fe_p"].shape == (1, 1)
    assert pmr.perm_p["tau2_p"].shape == (1, )
예제 #16
0
def test_stouffers_perm_test_approx():
    """Test the approximate permutation test on Stouffers Estimator."""
    y = [2.8, -0.2, -1, 4.5, 1.9, 2.38, 0.6, 1.88, -0.4, 1.5, 3.163, 0.7]
    dataset = Dataset(y)
    results = StoufferCombinationTest().fit_dataset(dataset).summary()
    pmr = results.permutation_test(2000)
    assert not pmr.exact
    assert pmr.n_perm == 2000
    assert isinstance(pmr.results, CombinationTestResults)
    assert pmr.perm_p["fe_p"].shape == (1, )
    assert "tau2_p" not in pmr.perm_p
예제 #17
0
파일: test_core.py 프로젝트: koudyk/PyMARE
def test_dataset_init(variables):
    dataset = Dataset(*variables, names=['bork'])

    # Convenience accessors
    assert np.array_equal(dataset.X, dataset.predictors)
    assert np.array_equal(dataset.y, dataset.estimates)
    assert np.array_equal(dataset.v, dataset.variances)

    n = len(variables[0])
    assert dataset.X.shape == (n, 2)
    assert dataset.names == ['intercept', 'bork']

    dataset = Dataset(*variables,
                      names=['bork'],
                      add_intercept=False,
                      extra_arg=200)
    assert dataset.X.shape == (n, 1)
    assert dataset.names == ['bork']
    assert 'extra_arg' in dataset.kwargs
    assert dataset.extra_arg == 200
예제 #18
0
def test_dataset_init_from_df(variables):
    df = pd.DataFrame({
        'y': [2, 4, 6],
        'v_alt': [100, 100, 100],
        'X1': [5, 2, 1],
        'X7': [9, 8, 7]
    })
    dataset = Dataset(v='v_alt', X=['X1', 'X7'], data=df)
    assert dataset.X.shape == (3, 3)
    assert dataset.X_names == ['intercept', 'X1', 'X7']
    assert np.array_equal(dataset.y, np.array([[2, 4, 6]]).T)
    assert np.array_equal(dataset.v, np.array([[100, 100, 100]]).T)
예제 #19
0
def test_dataset_init_from_df(variables):
    df = pd.DataFrame({
        "y": [2, 4, 6],
        "v_alt": [100, 100, 100],
        "X1": [5, 2, 1],
        "X7": [9, 8, 7]
    })
    dataset = Dataset(v="v_alt", X=["X1", "X7"], data=df)
    assert dataset.X.shape == (3, 3)
    assert dataset.X_names == ["intercept", "X1", "X7"]
    assert np.array_equal(dataset.y, np.array([[2, 4, 6]]).T)
    assert np.array_equal(dataset.v, np.array([[100, 100, 100]]).T)
예제 #20
0
def test_combination_test_from_dataset(Cls, data, mode, expected):
    dset = Dataset(y=data)
    est = Cls(mode).fit_dataset(dset)
    results = est.summary()
    z = ss.norm.isf(results.p)
    assert np.allclose(z, expected, atol=1e-5)
예제 #21
0
def dataset(variables):
    return Dataset(*variables, names=['my_covariate'])
예제 #22
0
def small_dataset_2d(variables):
    """Build a small Dataset with 2D data."""
    y = np.array([[1.5, 1.9, 2.2], [4, 2, 1]]).T
    v = np.array([[1, 0.8, 3], [1, 1.5, 1]]).T
    return Dataset(y, v)
예제 #23
0
def dataset(variables):
    """Build a Dataset compiled from the variables fixture."""
    return Dataset(*variables, X_names=["my_covariate"])
예제 #24
0
def dataset(variables):
    return Dataset(*variables, X_names=["my_covariate"])
예제 #25
0
def small_dataset_2d(variables):
    y = np.array([[1.5, 1.9, 2.2], [4, 2, 1]]).T
    v = np.array([[1, 0.8, 3], [1, 1.5, 1]]).T
    return Dataset(y, v)