Skip to main content
added 335 characters in body
Source Link
Zen
  • 25.1k
  • 4
  • 87
  • 126

You can definitely use a Bayesian analysis to solve your problem. You have $k$ categories, the observed number of answers for each category are $(x_1,\dots,x_k)$, and your likelihood is proportional to $$ \theta_1^{x_1} \dots \theta_k^{x_k} \, , $$ where $\theta_i$ is the proportion of potential users of the library that belong to category $i$. You don't know the $\theta_i$'s (they are parameters), but if you suppose that a priori they are distributed uniformly on the $k$-simplex, then, given the $x_i$'s, the $\theta_i$'s are distributed a posteriori as $$ (\theta_1,\dots,\theta_k) \mid (x_1,\dots,x_k) \sim \textrm{Dirichlet}(x_1 + 1, \dots, x_k + 1) \, . $$ From this posterior distribution, you can compute virtually anything that interests you, like credible intervals for the $\theta_i$'s, the probability that you have more college students than grad students, etc. Just do a simple Monte Carlo of the posterior using R. If you need some sample code, please post a piece of your data, and we will help you.

rdirichlet <- function(a) {
    y <- rgamma(length(a), a, 1)
    return(y / sum(y))
}

x <- c(65, 71, 532, 307, 369, 234, 584)

SIMS <- 10000

t <- matrix(nrow = SIMS, ncol = length(x), data = 0)

for (i in 1:SIMS) t[i,] = rdirichlet(x + 1)

sum(t[,3]) / SIMS # estimate of "college or grad"

quantile(t[,3], probs = c(0.025, 0.975)) # credible interval for "college or grad"

# posterior probabilities
sum(t[,3] > t[,7]) / SIMS # more "college or grad" than "other"
sum(t[,1] > t[,2]) / SIMS # more "k-12 teacher or librarian" than "k-12 student"

You can definitely use a Bayesian analysis to solve your problem. You have $k$ categories, the observed number of answers for each category are $(x_1,\dots,x_k)$, and your likelihood is proportional to $$ \theta_1^{x_1} \dots \theta_k^{x_k} \, , $$ where $\theta_i$ is the proportion of potential users of the library that belong to category $i$. You don't know the $\theta_i$'s (they are parameters), but if you suppose that a priori they are distributed uniformly on the $k$-simplex, then, given the $x_i$'s, the $\theta_i$'s are distributed a posteriori as $$ (\theta_1,\dots,\theta_k) \mid (x_1,\dots,x_k) \sim \textrm{Dirichlet}(x_1 + 1, \dots, x_k + 1) \, . $$ From this posterior distribution, you can compute virtually anything that interests you, like credible intervals for the $\theta_i$'s, the probability that you have more college students than grad students, etc. Just do a simple Monte Carlo of the posterior using R. If you need some sample code, please post a piece of your data, and we will help you.

You can definitely use a Bayesian analysis to solve your problem. You have $k$ categories, the observed number of answers for each category are $(x_1,\dots,x_k)$, and your likelihood is proportional to $$ \theta_1^{x_1} \dots \theta_k^{x_k} \, , $$ where $\theta_i$ is the proportion of potential users of the library that belong to category $i$. You don't know the $\theta_i$'s (they are parameters), but if you suppose that a priori they are distributed uniformly on the $k$-simplex, then, given the $x_i$'s, the $\theta_i$'s are distributed a posteriori as $$ (\theta_1,\dots,\theta_k) \mid (x_1,\dots,x_k) \sim \textrm{Dirichlet}(x_1 + 1, \dots, x_k + 1) \, . $$ From this posterior distribution, you can compute virtually anything that interests you, like credible intervals for the $\theta_i$'s, the probability that you have more college students than grad students, etc.

rdirichlet <- function(a) {
    y <- rgamma(length(a), a, 1)
    return(y / sum(y))
}

x <- c(65, 71, 532, 307, 369, 234, 584)

SIMS <- 10000

t <- matrix(nrow = SIMS, ncol = length(x), data = 0)

for (i in 1:SIMS) t[i,] = rdirichlet(x + 1)

sum(t[,3]) / SIMS # estimate of "college or grad"

quantile(t[,3], probs = c(0.025, 0.975)) # credible interval for "college or grad"

# posterior probabilities
sum(t[,3] > t[,7]) / SIMS # more "college or grad" than "other"
sum(t[,1] > t[,2]) / SIMS # more "k-12 teacher or librarian" than "k-12 student"
added 10 characters in body
Source Link
Zen
  • 25.1k
  • 4
  • 87
  • 126

You can definitely use a Bayesian analysis to solve your problem. You have $k$ categories, the observed number of answers for each category are $(x_1,\dots,x_k)$, and your likelihood is proportional to $$ \theta_1^{x_1} \dots \theta_k^{x_k} \, , $$ where $\theta_i$ is the proportion of potential users of the library that belong to category $i$. You don't know the $\theta_i$'s (they are parameters), but if you suppose that a priori they are distributed uniformly on the $k$-simplex, then, given the $x_i$'s, the $\theta_i$'s are distributed a posteriori as $$ (\theta_1,\dots,\theta_k) \mid (x_1,\dots,x_k) \sim \textrm{Dirichlet}(x_1 + 1, \dots, x_k + 1) \, . $$ From this posterior distribution, you can compute virtually anything that interests you, like credible intervals for the $\theta_i$'s, the probability that you have more college students than grad students, etc. Just do a simple Monte Carlo of the posterior using R. If you need some sample code, please post a piece of your data, and we will help you.

You can definitely use a Bayesian analysis to solve your problem. You have $k$ categories, the observed number of answers for each category are $(x_1,\dots,x_k)$, and your likelihood is proportional to $$ \theta_1^{x_1} \dots \theta_k^{x_k} \, , $$ where $\theta_i$ is the proportion of users of the library that belong to category $i$. You don't know the $\theta_i$'s (they are parameters), but if you suppose that a priori they are distributed uniformly on the $k$-simplex, then, given the $x_i$'s, the $\theta_i$'s are distributed a posteriori as $$ (\theta_1,\dots,\theta_k) \mid (x_1,\dots,x_k) \sim \textrm{Dirichlet}(x_1 + 1, \dots, x_k + 1) \, . $$ From this posterior distribution, you can compute virtually anything that interests you, like credible intervals for the $\theta_i$'s, the probability that you have more college students than grad students, etc. Just do a simple Monte Carlo of the posterior using R. If you need some sample code, please post a piece of your data, and we will help you.

You can definitely use a Bayesian analysis to solve your problem. You have $k$ categories, the observed number of answers for each category are $(x_1,\dots,x_k)$, and your likelihood is proportional to $$ \theta_1^{x_1} \dots \theta_k^{x_k} \, , $$ where $\theta_i$ is the proportion of potential users of the library that belong to category $i$. You don't know the $\theta_i$'s (they are parameters), but if you suppose that a priori they are distributed uniformly on the $k$-simplex, then, given the $x_i$'s, the $\theta_i$'s are distributed a posteriori as $$ (\theta_1,\dots,\theta_k) \mid (x_1,\dots,x_k) \sim \textrm{Dirichlet}(x_1 + 1, \dots, x_k + 1) \, . $$ From this posterior distribution, you can compute virtually anything that interests you, like credible intervals for the $\theta_i$'s, the probability that you have more college students than grad students, etc. Just do a simple Monte Carlo of the posterior using R. If you need some sample code, please post a piece of your data, and we will help you.

Source Link
Zen
  • 25.1k
  • 4
  • 87
  • 126

You can definitely use a Bayesian analysis to solve your problem. You have $k$ categories, the observed number of answers for each category are $(x_1,\dots,x_k)$, and your likelihood is proportional to $$ \theta_1^{x_1} \dots \theta_k^{x_k} \, , $$ where $\theta_i$ is the proportion of users of the library that belong to category $i$. You don't know the $\theta_i$'s (they are parameters), but if you suppose that a priori they are distributed uniformly on the $k$-simplex, then, given the $x_i$'s, the $\theta_i$'s are distributed a posteriori as $$ (\theta_1,\dots,\theta_k) \mid (x_1,\dots,x_k) \sim \textrm{Dirichlet}(x_1 + 1, \dots, x_k + 1) \, . $$ From this posterior distribution, you can compute virtually anything that interests you, like credible intervals for the $\theta_i$'s, the probability that you have more college students than grad students, etc. Just do a simple Monte Carlo of the posterior using R. If you need some sample code, please post a piece of your data, and we will help you.