Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Direct Age Standardization fails for empty regions #824

Closed
ljwolf opened this issue Jun 25, 2016 · 1 comment
Closed

Direct Age Standardization fails for empty regions #824

ljwolf opened this issue Jun 25, 2016 · 1 comment

Comments

@ljwolf
Copy link
Member

ljwolf commented Jun 25, 2016

I think there's a minor bug in pysal.esda.smoothing.direct_age_standardization:

for i in range(len(adjusted_r)):
    if adjusted_r[i] == 0:
        upper = .5 * scipy.stats.chi2(1-0.5 * alpha)
        lower = 0
    else:
        lower = scipy.stats.gamma.ppf(.05 * alpha, g_a[i],. scale=g_b[i])
        upper = scipy.stats.gamma.ppf(1 - .05*alpha, g_a_[k], scale=g_b_k[i]

I think that should be scipy.stats.chi2.ppf, as is the case for the gamma function. As it stands, when adjusted_r[i] == 0, we get a TypeError, since calling chi2(parameters) directly creates a frozen random variable, which can't be multiplied.

The traceback that occurs is:

/home/ljw/dev/pysal/pysal/esda/smoothing.pyc in __init__(self, e, b, w, s, alpha)
    978         e_n = np.array(e_n).reshape((1, t), order='F')[0]
    979         b_n = np.array(b_n).reshape((1, t), order='F')[0]
--> 980         r = direct_age_standardization(e_n, b_n, s, w.n, alpha=alpha)
    981         self.r = np.array([i[0] for i in r])
    982         w.transform = 'o'

/home/ljw/dev/pysal/pysal/esda/smoothing.pyc in direct_age_standardization(e, b, s, n, alpha)
    283     for i in range(len(adjusted_r)):
    284         if adjusted_r[i] == 0:
--> 285             upper = 0.5 * chi2(1 - 0.5 * alpha)
    286             lower = 0.0
    287         else:

TypeError: unsupported operand type(s) for *: 'float' and 'rv_frozen'

Someone with a knowledge of smoothing should probably review.

@ljwolf
Copy link
Member Author

ljwolf commented Jul 16, 2016

should be resolved in #827

@ljwolf ljwolf closed this as completed Jul 16, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant