Example #1
0
def _compute_least_squares(ages, weights):
    """
    Computes least squares fit for ages and weights.

    Prints summary statistics.
    """
    # compute the correlation between age and weight
    print('Pearson correlation', correlation._corr(ages, weights))
    print('Spearman correlation', correlation._spearman_corr(ages, weights))

    # compute least squares fit
    inter, slope = correlation._least_squares(ages, weights)
    print('(inter, slope):', inter, slope)

    res = correlation._residuals(ages, weights, inter, slope)
    R2 = correlation._coef_determination(weights, res)

    print('R^2', R2)
    print
    return inter, slope, R2
Example #2
0
def _compute_correlations():
    resp = brfss_scatter.Respondents()
    resp._read_records()
    print('Number of records:', len(resp.records))

    heights, weights = resp._get_height_weight()
    pearson = correlation._corr(heights, weights)
    print('Pearson correlation (weights):', pearson)

    log_weights = _log(weights)
    pearson = correlation._corr(heights, log_weights)
    print('Pearson correlation (log weights):', pearson)

    spearman = correlation._spearman_corr(heights, weights)
    print('Spearman correlation (weights):', spearman)

    inter, slope = correlation._least_squares(heights, log_weights)
    print('Least squares inter, slope (log weights):', inter, slope)

    res = correlation._residuals(heights, log_weights, inter, slope)
    R2 = correlation._coef_determination(log_weights, res)
    print('Coefficient of determination:', R2)
    print('sqrt(R^2):', math.sqrt(R2))