当前位置: 首页>>代码示例>>Python>>正文


Python OLS.predict方法代码示例

本文整理汇总了Python中statsmodels.regression.linear_model.OLS.predict方法的典型用法代码示例。如果您正苦于以下问题:Python OLS.predict方法的具体用法?Python OLS.predict怎么用?Python OLS.predict使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在statsmodels.regression.linear_model.OLS的用法示例。


在下文中一共展示了OLS.predict方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: local_fdr

# 需要导入模块: from statsmodels.regression.linear_model import OLS [as 别名]
# 或者: from statsmodels.regression.linear_model.OLS import predict [as 别名]
def local_fdr(zscores, null_proportion=1.0, null_pdf=None, deg=7,
              nbins=30):
    """
    Calculate local FDR values for a list of Z-scores.

    Parameters
    ----------
    zscores : array-like
        A vector of Z-scores
    null_proportion : float
        The assumed proportion of true null hypotheses
    null_pdf : function mapping reals to positive reals
        The density of null Z-scores; if None, use standard normal
    deg : integer
        The maximum exponent in the polynomial expansion of the
        density of non-null Z-scores
    nbins : integer
        The number of bins for estimating the marginal density
        of Z-scores.

    Returns
    -------
    fdr : array-like
        A vector of FDR values

    References
    ----------
    B Efron (2008).  Microarrays, Empirical Bayes, and the Two-Groups
    Model.  Statistical Science 23:1, 1-22.

    Examples
    --------
    Basic use (the null Z-scores are taken to be standard normal):

    >>> fdr = local_fdr(zscores)

    Use a Gaussian null distribution estimated from the data:

    >>> null = EmpiricalNull(zscores)
    >>> fdr = local_fdr(zscores, null_pdf=null.pdf)
    """

    from statsmodels.genmod.generalized_linear_model import GLM
    from statsmodels.genmod.generalized_linear_model import families
    from statsmodels.regression.linear_model import OLS

    # Bins for Poisson modeling of the marginal Z-score density
    minz = min(zscores)
    maxz = max(zscores)
    bins = np.linspace(minz, maxz, nbins)

    # Bin counts
    zhist = np.histogram(zscores, bins)[0]

    # Bin centers
    zbins = (bins[:-1] + bins[1:]) / 2

    # The design matrix at bin centers
    dmat = np.vander(zbins, deg + 1)

    # Use this to get starting values for Poisson regression
    md = OLS(np.log(1 + zhist), dmat).fit()

    # Poisson regression
    md = GLM(zhist, dmat, family=families.Poisson()).fit(start_params=md.params)

    # The design matrix for all Z-scores
    dmat_full = np.vander(zscores, deg + 1)

    # The height of the estimated marginal density of Z-scores,
    # evaluated at every observed Z-score.
    fz = md.predict(dmat_full) / (len(zscores) * (bins[1] - bins[0]))

    # The null density.
    if null_pdf is None:
        f0 = np.exp(-0.5 * zscores**2) / np.sqrt(2 * np.pi)
    else:
        f0 = null_pdf(zscores)

    # The local FDR values
    fdr = null_proportion * f0 / fz

    fdr = np.clip(fdr, 0, 1)

    return fdr
开发者ID:CHEN-JIANGHANG,项目名称:statsmodels,代码行数:87,代码来源:multitest.py

示例2: OLS

# 需要导入模块: from statsmodels.regression.linear_model import OLS [as 别名]
# 或者: from statsmodels.regression.linear_model.OLS import predict [as 别名]
    y_true = np.dot(exog, beta)
    y = y_true + sig_e * np.random.normal(size=nobs)
    endog = y

    print "DGP"
    print "nobs=%d, beta=%r, sig_e=%3.1f" % (nobs, beta, sig_e)

    mod_ols = OLS(endog, exog[:, :2])
    res_ols = mod_ols.fit()
    #'cv_ls'[1000, 0.5][0.01, 0.45]
    tst = smke.TestFForm(
        endog,
        exog[:, :2],
        bw=[0.01, 0.45],
        var_type="cc",
        fform=lambda x, p: mod_ols.predict(p, x),
        estimator=lambda y, x: OLS(y, x).fit().params,
        nboot=1000,
    )

    print "bw", tst.bw
    print "tst.test_stat", tst.test_stat
    print tst.sig
    print "tst.boots_results mean, min, max", (
        tst.boots_results.mean(),
        tst.boots_results.min(),
        tst.boots_results.max(),
    )
    print "lower tail bootstrap p-value", (tst.boots_results < tst.test_stat).mean()
    print "upper tail bootstrap p-value", (tst.boots_results >= tst.test_stat).mean()
    from scipy import stats
开发者ID:lema655,项目名称:statsmodels,代码行数:33,代码来源:ex_kernel_test_functional.py


注:本文中的statsmodels.regression.linear_model.OLS.predict方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。