idx
int64 1
56k
| question
stringlengths 15
155
| answer
stringlengths 2
29.2k
⌀ | question_cut
stringlengths 15
100
| answer_cut
stringlengths 2
200
⌀ | conversation
stringlengths 47
29.3k
| conversation_cut
stringlengths 47
301
|
|---|---|---|---|---|---|---|
39,801
|
Choosing between best two attributes with the same information gain when building decision tree
|
The decision tree method is a step-wise approach to model building, so variables entered earlier have a direct impact on which variables are entered later. Can you try both trees, and see which creates a better separation at your terminal nodes and/or builds a tree that fits more closely with the theoretical understanding you have of your data?
You could also see what the validation testing shows after building both trees, and go with the tree that fits all the data best.
|
Choosing between best two attributes with the same information gain when building decision tree
|
The decision tree method is a step-wise approach to model building, so variables entered earlier have a direct impact on which variables are entered later. Can you try both trees, and see which create
|
Choosing between best two attributes with the same information gain when building decision tree
The decision tree method is a step-wise approach to model building, so variables entered earlier have a direct impact on which variables are entered later. Can you try both trees, and see which creates a better separation at your terminal nodes and/or builds a tree that fits more closely with the theoretical understanding you have of your data?
You could also see what the validation testing shows after building both trees, and go with the tree that fits all the data best.
|
Choosing between best two attributes with the same information gain when building decision tree
The decision tree method is a step-wise approach to model building, so variables entered earlier have a direct impact on which variables are entered later. Can you try both trees, and see which create
|
39,802
|
Choosing between best two attributes with the same information gain when building decision tree
|
I work with the text classification problem, and for the classification I am using decision tree classifiers(ID3, Random forests etc). So I can give you an example that is related to text classification. In classification we are going to deal with the different words as the attributes, and you can reduce the features using information gain threshold and once you have all the reduced features with you, it will follow the procedure that I have mentioned below.
While building the decision tree, it will start with the attribute having the highest information gain, and now there are more than one words/attributes with the same information gain value. So for text classification, it will check in the alphabetical order.
For example: for root node there are two words with highest information gain ("Good" with IG=0.5, and "Awesome" with IG=0.5), "Awesome" will be selected as the root node.
Hope this will help to solve the doubt.
It will be great if you can download the machine learning package called "Weka" and try out the decision tree classifier with your own dataset. As the beautiful thing is, after the classification process it will allow you to see the decision tree created. ID3, Random Tree and Random forest of Weka uses Information gain for splitting of nodes.
|
Choosing between best two attributes with the same information gain when building decision tree
|
I work with the text classification problem, and for the classification I am using decision tree classifiers(ID3, Random forests etc). So I can give you an example that is related to text classificati
|
Choosing between best two attributes with the same information gain when building decision tree
I work with the text classification problem, and for the classification I am using decision tree classifiers(ID3, Random forests etc). So I can give you an example that is related to text classification. In classification we are going to deal with the different words as the attributes, and you can reduce the features using information gain threshold and once you have all the reduced features with you, it will follow the procedure that I have mentioned below.
While building the decision tree, it will start with the attribute having the highest information gain, and now there are more than one words/attributes with the same information gain value. So for text classification, it will check in the alphabetical order.
For example: for root node there are two words with highest information gain ("Good" with IG=0.5, and "Awesome" with IG=0.5), "Awesome" will be selected as the root node.
Hope this will help to solve the doubt.
It will be great if you can download the machine learning package called "Weka" and try out the decision tree classifier with your own dataset. As the beautiful thing is, after the classification process it will allow you to see the decision tree created. ID3, Random Tree and Random forest of Weka uses Information gain for splitting of nodes.
|
Choosing between best two attributes with the same information gain when building decision tree
I work with the text classification problem, and for the classification I am using decision tree classifiers(ID3, Random forests etc). So I can give you an example that is related to text classificati
|
39,803
|
McKay's bivariate Gamma distribution
|
You can create whole families of joint distributions on $(X,Y)$ such that $X\sim \Gamma(a_1,\alpha)$ and $Y\sim \Gamma(a_2,\beta)$ by using copulas like
$$
F_{(X,Y)}(x,y) = \mathbb{P}(X\le x,Y\le y) =
\dfrac{F_X(x)F_Y(y)}{1+\varrho (1-F_X(x))(1-F_Y(y))}
$$
for $-1\le \varrho \le 1$. The joint distribution is continuous, which means the event $X=Y$ has probability zero.
Now, if you have a specific reason for using McKay's bivariate distribution, with pdf
$$
f_{(X,Y)}(x,y) = \alpha^{p+q} x^{p-1} (y-x)^{q-1} \exp\{-\alpha y\} / [\Gamma(p) \Gamma(q)]\,\mathbb{I}_{0\le x\le y} \,,
$$
which gives
$$
X\sim \Gamma(p,\alpha)\,,\quad Y\sim \Gamma(p+q,\alpha)
$$
as marginals,
you must compute $\mathbb{E}[G(X,Y)]$ as
$$
\int_0^\infty \int_0^y G(x,y)\,\alpha^{p+q} x^{p-1} (y-x)^{q-1} \exp\{-\alpha y\} / [\Gamma(p) \Gamma(q)]\,\text{d}x\,\text{d}y\,.
$$
|
McKay's bivariate Gamma distribution
|
You can create whole families of joint distributions on $(X,Y)$ such that $X\sim \Gamma(a_1,\alpha)$ and $Y\sim \Gamma(a_2,\beta)$ by using copulas like
$$
F_{(X,Y)}(x,y) = \mathbb{P}(X\le x,Y\le y) =
|
McKay's bivariate Gamma distribution
You can create whole families of joint distributions on $(X,Y)$ such that $X\sim \Gamma(a_1,\alpha)$ and $Y\sim \Gamma(a_2,\beta)$ by using copulas like
$$
F_{(X,Y)}(x,y) = \mathbb{P}(X\le x,Y\le y) =
\dfrac{F_X(x)F_Y(y)}{1+\varrho (1-F_X(x))(1-F_Y(y))}
$$
for $-1\le \varrho \le 1$. The joint distribution is continuous, which means the event $X=Y$ has probability zero.
Now, if you have a specific reason for using McKay's bivariate distribution, with pdf
$$
f_{(X,Y)}(x,y) = \alpha^{p+q} x^{p-1} (y-x)^{q-1} \exp\{-\alpha y\} / [\Gamma(p) \Gamma(q)]\,\mathbb{I}_{0\le x\le y} \,,
$$
which gives
$$
X\sim \Gamma(p,\alpha)\,,\quad Y\sim \Gamma(p+q,\alpha)
$$
as marginals,
you must compute $\mathbb{E}[G(X,Y)]$ as
$$
\int_0^\infty \int_0^y G(x,y)\,\alpha^{p+q} x^{p-1} (y-x)^{q-1} \exp\{-\alpha y\} / [\Gamma(p) \Gamma(q)]\,\text{d}x\,\text{d}y\,.
$$
|
McKay's bivariate Gamma distribution
You can create whole families of joint distributions on $(X,Y)$ such that $X\sim \Gamma(a_1,\alpha)$ and $Y\sim \Gamma(a_2,\beta)$ by using copulas like
$$
F_{(X,Y)}(x,y) = \mathbb{P}(X\le x,Y\le y) =
|
39,804
|
McKay's bivariate Gamma distribution
|
For McKay's distribution $X$ is a Gamma variate that is the sum of a subset of squares taken from the other, $Y$, which is the sum of a larger set of squares. Implying that $Y>X$ with probability $1$. See McKay's original paper:
McKay, A. T. (1934) Sampling from batches. Journal of the Royal Statistical Society—Supplement 1: 207–216.
|
McKay's bivariate Gamma distribution
|
For McKay's distribution $X$ is a Gamma variate that is the sum of a subset of squares taken from the other, $Y$, which is the sum of a larger set of squares. Implying that $Y>X$ with probability $1$.
|
McKay's bivariate Gamma distribution
For McKay's distribution $X$ is a Gamma variate that is the sum of a subset of squares taken from the other, $Y$, which is the sum of a larger set of squares. Implying that $Y>X$ with probability $1$. See McKay's original paper:
McKay, A. T. (1934) Sampling from batches. Journal of the Royal Statistical Society—Supplement 1: 207–216.
|
McKay's bivariate Gamma distribution
For McKay's distribution $X$ is a Gamma variate that is the sum of a subset of squares taken from the other, $Y$, which is the sum of a larger set of squares. Implying that $Y>X$ with probability $1$.
|
39,805
|
Detecting changes in distribution of multiple variables
|
This sounds like a job for the Mahalanobis Distance. You would apply this by estimating the population covariance and mean vector using the previous $(k-1)$ samples (assuming $k > N$, where $N$ is the dimension of your observed vectors), and then computing the Mahalanobis Distance. A google search reveals a lot of hits on this topic, Bartkowiak seems like a decent starting place.
|
Detecting changes in distribution of multiple variables
|
This sounds like a job for the Mahalanobis Distance. You would apply this by estimating the population covariance and mean vector using the previous $(k-1)$ samples (assuming $k > N$, where $N$ is the
|
Detecting changes in distribution of multiple variables
This sounds like a job for the Mahalanobis Distance. You would apply this by estimating the population covariance and mean vector using the previous $(k-1)$ samples (assuming $k > N$, where $N$ is the dimension of your observed vectors), and then computing the Mahalanobis Distance. A google search reveals a lot of hits on this topic, Bartkowiak seems like a decent starting place.
|
Detecting changes in distribution of multiple variables
This sounds like a job for the Mahalanobis Distance. You would apply this by estimating the population covariance and mean vector using the previous $(k-1)$ samples (assuming $k > N$, where $N$ is the
|
39,806
|
Detecting changes in distribution of multiple variables
|
This sounds to me more like a change point problem. You should investigate the bcp package, http://cran.r-project.org/web/packages/bcp/index.html, as well as strucchange, http://cran.r-project.org/web/packages/strucchange/index.html
John Emerson maintains the bcp package, and when I met him, he seemed very willing to engage the community and potential users: john.emerson at yale.edu
Alternatively, if your data are time series data, you may wish to investigate the qcc package, and read some of Douglas Montgomery's work on Statistical Quality Control.
|
Detecting changes in distribution of multiple variables
|
This sounds to me more like a change point problem. You should investigate the bcp package, http://cran.r-project.org/web/packages/bcp/index.html, as well as strucchange, http://cran.r-project.org/web
|
Detecting changes in distribution of multiple variables
This sounds to me more like a change point problem. You should investigate the bcp package, http://cran.r-project.org/web/packages/bcp/index.html, as well as strucchange, http://cran.r-project.org/web/packages/strucchange/index.html
John Emerson maintains the bcp package, and when I met him, he seemed very willing to engage the community and potential users: john.emerson at yale.edu
Alternatively, if your data are time series data, you may wish to investigate the qcc package, and read some of Douglas Montgomery's work on Statistical Quality Control.
|
Detecting changes in distribution of multiple variables
This sounds to me more like a change point problem. You should investigate the bcp package, http://cran.r-project.org/web/packages/bcp/index.html, as well as strucchange, http://cran.r-project.org/web
|
39,807
|
Chi square statistic and contingency coefficients
|
There are two standard accounts of $\chi^2$ as applied to a multinomial distribution, both of which show why the denominator should not be squared:
After expanding the logarithm through second order and doing some algebra, the likelihood ratio statistic for the multinomial distribution, $-2\log(l) = 2\sum_{i=1}^k n_i \log(n_i / e_i)$, equals $\chi^2(1 + O(n^{-1/2}))$, so at least asymptotically, $\chi^2$ gives a likelihood ratio test. (I have replaced the double indexing by a single index, without any loss of generality.)
Fisher showed that the multinomial distribution arises as the conditional distribution of $k$ independent Poisson variates of intensities $e_{i}$, conditioned on their sum, $n$. Because the variances are $e_{i}$, the standardized values $(n_i - e_i)/\sqrt{e_i}$ are asymptotically Normal for large $n$, whence $\chi^2$ approaches the sum of squares of $k$ independent Normals, subject to the single condition $n_1 + \cdots + n_k=n$, giving it $k-1$ degrees of freedom.
Both arguments clearly show the sense in which $\chi^2$ is valid only asymptotically.
Accounts of both these points of view are found in chapter 30 of Stuart & Ord, Kendall's Advanced Theory of Statistics, Fifth Edition (1987).
I do not know the historical answer to the second question--the contingency coefficient $C$ goes back to Pearson over 100 years ago--but clearly $C$ is an analog of an absolute correlation coefficient, computed as the root of (residual variance / total variance). Indeed,
$$\chi^2 + n = \sum\frac{(n_i-e_i)^2 + e_i^2}{e_i} = \sum\frac{n_i^2}{e_i},$$
which looks exactly like an inverse variance-weighted total sum of squares. In effect, $n$ is the variance "explained" by the fit and $\chi^2$ is the residual variance. Note that $\chi^2$ small implies the fit is good with $C \approx 0$, corresponding to almost no association in a contingency table, while $\chi^2$ large implies the fit is terrible, corresponding to almost perfect association with $C \approx 1$.
|
Chi square statistic and contingency coefficients
|
There are two standard accounts of $\chi^2$ as applied to a multinomial distribution, both of which show why the denominator should not be squared:
After expanding the logarithm through second order
|
Chi square statistic and contingency coefficients
There are two standard accounts of $\chi^2$ as applied to a multinomial distribution, both of which show why the denominator should not be squared:
After expanding the logarithm through second order and doing some algebra, the likelihood ratio statistic for the multinomial distribution, $-2\log(l) = 2\sum_{i=1}^k n_i \log(n_i / e_i)$, equals $\chi^2(1 + O(n^{-1/2}))$, so at least asymptotically, $\chi^2$ gives a likelihood ratio test. (I have replaced the double indexing by a single index, without any loss of generality.)
Fisher showed that the multinomial distribution arises as the conditional distribution of $k$ independent Poisson variates of intensities $e_{i}$, conditioned on their sum, $n$. Because the variances are $e_{i}$, the standardized values $(n_i - e_i)/\sqrt{e_i}$ are asymptotically Normal for large $n$, whence $\chi^2$ approaches the sum of squares of $k$ independent Normals, subject to the single condition $n_1 + \cdots + n_k=n$, giving it $k-1$ degrees of freedom.
Both arguments clearly show the sense in which $\chi^2$ is valid only asymptotically.
Accounts of both these points of view are found in chapter 30 of Stuart & Ord, Kendall's Advanced Theory of Statistics, Fifth Edition (1987).
I do not know the historical answer to the second question--the contingency coefficient $C$ goes back to Pearson over 100 years ago--but clearly $C$ is an analog of an absolute correlation coefficient, computed as the root of (residual variance / total variance). Indeed,
$$\chi^2 + n = \sum\frac{(n_i-e_i)^2 + e_i^2}{e_i} = \sum\frac{n_i^2}{e_i},$$
which looks exactly like an inverse variance-weighted total sum of squares. In effect, $n$ is the variance "explained" by the fit and $\chi^2$ is the residual variance. Note that $\chi^2$ small implies the fit is good with $C \approx 0$, corresponding to almost no association in a contingency table, while $\chi^2$ large implies the fit is terrible, corresponding to almost perfect association with $C \approx 1$.
|
Chi square statistic and contingency coefficients
There are two standard accounts of $\chi^2$ as applied to a multinomial distribution, both of which show why the denominator should not be squared:
After expanding the logarithm through second order
|
39,808
|
Chi square statistic and contingency coefficients
|
I don't know what is "more true" or "less true" form of normalization. Any normalization that makes a particular sense will do. The quantity $(n_{ij}-E_{ij})^2/E_{ij}$ is called squared standardized residual in a cell, and overall Chi-square of a table is the sum of those across all cells. Chi-square can be viewed therefore as the weighted euclidean distance (weight$=1/E_{ij}$) between observed and expected frequencies [this notion of chi-square as the distance is realized in correspondence analysis].
Also, standardized residual follows Poisson distribution, and with large $E_{ij}$ approaches normal distribution. This opens the possibility to infer whether the residual in a cell is significantly large.
Standardized residual is not the only way to normalize residual in a cell. Adjusted residual is another useful form.
|
Chi square statistic and contingency coefficients
|
I don't know what is "more true" or "less true" form of normalization. Any normalization that makes a particular sense will do. The quantity $(n_{ij}-E_{ij})^2/E_{ij}$ is called squared standardized r
|
Chi square statistic and contingency coefficients
I don't know what is "more true" or "less true" form of normalization. Any normalization that makes a particular sense will do. The quantity $(n_{ij}-E_{ij})^2/E_{ij}$ is called squared standardized residual in a cell, and overall Chi-square of a table is the sum of those across all cells. Chi-square can be viewed therefore as the weighted euclidean distance (weight$=1/E_{ij}$) between observed and expected frequencies [this notion of chi-square as the distance is realized in correspondence analysis].
Also, standardized residual follows Poisson distribution, and with large $E_{ij}$ approaches normal distribution. This opens the possibility to infer whether the residual in a cell is significantly large.
Standardized residual is not the only way to normalize residual in a cell. Adjusted residual is another useful form.
|
Chi square statistic and contingency coefficients
I don't know what is "more true" or "less true" form of normalization. Any normalization that makes a particular sense will do. The quantity $(n_{ij}-E_{ij})^2/E_{ij}$ is called squared standardized r
|
39,809
|
Chi square statistic and contingency coefficients
|
An intuitive explanation for why
$$
d_{ij}=(n_{ij}−E_{ij})^2/E_{ij}^2
$$
would not be a good test statistic is to notice that it doesn't scale with the size of the sample: Suppose we increase our sample by 10 fold. Then if the null-hypothesis is false, we should be much more likely to reject -- that is, the test statistic $d_{ij}$ should be much larger. Yet if we multiply $n_{ij}$ and $E_{ij}$ by 10 (to get an idea of the scale of the new $d_{ij}$), we see that the value of $d_{ij}$ doesn't change.
To summarize, even though $d_{ij}$ is a very fine and intuitive measure of the difference between two probability distributions, it doesn't reflect anything about how confident we are that the sample distribution is different from the null hypothesis.
|
Chi square statistic and contingency coefficients
|
An intuitive explanation for why
$$
d_{ij}=(n_{ij}−E_{ij})^2/E_{ij}^2
$$
would not be a good test statistic is to notice that it doesn't scale with the size of the sample: Suppose we increase our
|
Chi square statistic and contingency coefficients
An intuitive explanation for why
$$
d_{ij}=(n_{ij}−E_{ij})^2/E_{ij}^2
$$
would not be a good test statistic is to notice that it doesn't scale with the size of the sample: Suppose we increase our sample by 10 fold. Then if the null-hypothesis is false, we should be much more likely to reject -- that is, the test statistic $d_{ij}$ should be much larger. Yet if we multiply $n_{ij}$ and $E_{ij}$ by 10 (to get an idea of the scale of the new $d_{ij}$), we see that the value of $d_{ij}$ doesn't change.
To summarize, even though $d_{ij}$ is a very fine and intuitive measure of the difference between two probability distributions, it doesn't reflect anything about how confident we are that the sample distribution is different from the null hypothesis.
|
Chi square statistic and contingency coefficients
An intuitive explanation for why
$$
d_{ij}=(n_{ij}−E_{ij})^2/E_{ij}^2
$$
would not be a good test statistic is to notice that it doesn't scale with the size of the sample: Suppose we increase our
|
39,810
|
Chi square statistic and contingency coefficients
|
About the contingency coefficient, I want to take the opportunity to leave a remark.
Consider the "theoretical chi-square statistic"
$$
v= \sum_{i,j}\frac{(p_{i,j}-p_ip_j)^2}{p_ip_j}
$$
and the theoretical contigency coefficient
$$
C_0 = \sqrt{\frac{v}{v+n}}.
$$
It is called the effect size in power calculations. As far as I know, there is no general and precise definition of the effect size.
However, considering $C_0$ as the effect size yields something similar to the power of $F$-tests in linear models, which are exact (non-asymptotic) likelihood ratio tests up to an elementary transformation.
Indeed, denoting by $E$ the effect size for such a test (for example $E=\mu/\sigma$ in the case of a simple Gaussian ${\cal N}(\mu, \sigma^2)$ sample and $H_0\colon\{\mu=0\}$), the test statistic under $H_1$ is a non-central $F$-distribution with non-centrality parameter $\boxed{\lambda=nE^2}$. In this situation we do not perform an asymptotic test because it is possible to get the exact law of the test statistic $F$. Asymptotically, $F \approx df_1\times\chi^2$ where $\chi^2$ is the test statistic of the asymptotic likelihood-ratio test. If we used the asymptotic likelihood ratio instead of the exact $F$-test, we would get a non-central Chi-square under $H_1$ instead of a non-central $F$ distribution : $F_{df_1,df_2}(\lambda) \approx \frac{1}{df_1}\chi^2_{df_1}(\lambda)$ when $df_2$ is large.
Similarly, in the context of contingency tables, when $n$ is large, the $\chi^2$ test statistic under $H_1$ is approximated by a non-central $\chi^2$ distribution with non-centrality parameter $\boxed{\lambda=n C_0^2}$, as we can check by this example of power calculation:
C0 <- 0.3 # theoretical effect size
n <- 100 # total count
alpha <- 0.05 # type I error
#--- Power calculcation with the pwr package ---#
library(pwr); pwr.chisq.test(C0, N=n, df=1, sig.level=alpha)
##
## Chi squared power calculation
##
## w = 0.3
## N = 100
## df = 1
## sig.level = 0.05
## power = 0.8508388
#--- Direct power calculation ---#
threshold <- qchisq(1-alpha, df = 1) # the critical value of the test statistic
lambda <- n*C0^2 # non-centrality parameter
1 - pchisq(threshold, df = 1, ncp = lambda) # we get the same result
## [1] 0.8508388
Thus each of these examples ($F$-tests in Gaussian linear models and $\chi^2$ tests for contingency tables) asymptotically give a likelihood ratio test (see @whuber's answer about the Pearson $\chi^2$), and their test statistic under $H_1$ is approximated, for large $n$, by a non-central $\chi^2$ distribution with non-centrality parameter $\boxed{\lambda=n\times\text{effect size}^2}$.
|
Chi square statistic and contingency coefficients
|
About the contingency coefficient, I want to take the opportunity to leave a remark.
Consider the "theoretical chi-square statistic"
$$
v= \sum_{i,j}\frac{(p_{i,j}-p_ip_j)^2}{p_ip_j}
$$
and the theor
|
Chi square statistic and contingency coefficients
About the contingency coefficient, I want to take the opportunity to leave a remark.
Consider the "theoretical chi-square statistic"
$$
v= \sum_{i,j}\frac{(p_{i,j}-p_ip_j)^2}{p_ip_j}
$$
and the theoretical contigency coefficient
$$
C_0 = \sqrt{\frac{v}{v+n}}.
$$
It is called the effect size in power calculations. As far as I know, there is no general and precise definition of the effect size.
However, considering $C_0$ as the effect size yields something similar to the power of $F$-tests in linear models, which are exact (non-asymptotic) likelihood ratio tests up to an elementary transformation.
Indeed, denoting by $E$ the effect size for such a test (for example $E=\mu/\sigma$ in the case of a simple Gaussian ${\cal N}(\mu, \sigma^2)$ sample and $H_0\colon\{\mu=0\}$), the test statistic under $H_1$ is a non-central $F$-distribution with non-centrality parameter $\boxed{\lambda=nE^2}$. In this situation we do not perform an asymptotic test because it is possible to get the exact law of the test statistic $F$. Asymptotically, $F \approx df_1\times\chi^2$ where $\chi^2$ is the test statistic of the asymptotic likelihood-ratio test. If we used the asymptotic likelihood ratio instead of the exact $F$-test, we would get a non-central Chi-square under $H_1$ instead of a non-central $F$ distribution : $F_{df_1,df_2}(\lambda) \approx \frac{1}{df_1}\chi^2_{df_1}(\lambda)$ when $df_2$ is large.
Similarly, in the context of contingency tables, when $n$ is large, the $\chi^2$ test statistic under $H_1$ is approximated by a non-central $\chi^2$ distribution with non-centrality parameter $\boxed{\lambda=n C_0^2}$, as we can check by this example of power calculation:
C0 <- 0.3 # theoretical effect size
n <- 100 # total count
alpha <- 0.05 # type I error
#--- Power calculcation with the pwr package ---#
library(pwr); pwr.chisq.test(C0, N=n, df=1, sig.level=alpha)
##
## Chi squared power calculation
##
## w = 0.3
## N = 100
## df = 1
## sig.level = 0.05
## power = 0.8508388
#--- Direct power calculation ---#
threshold <- qchisq(1-alpha, df = 1) # the critical value of the test statistic
lambda <- n*C0^2 # non-centrality parameter
1 - pchisq(threshold, df = 1, ncp = lambda) # we get the same result
## [1] 0.8508388
Thus each of these examples ($F$-tests in Gaussian linear models and $\chi^2$ tests for contingency tables) asymptotically give a likelihood ratio test (see @whuber's answer about the Pearson $\chi^2$), and their test statistic under $H_1$ is approximated, for large $n$, by a non-central $\chi^2$ distribution with non-centrality parameter $\boxed{\lambda=n\times\text{effect size}^2}$.
|
Chi square statistic and contingency coefficients
About the contingency coefficient, I want to take the opportunity to leave a remark.
Consider the "theoretical chi-square statistic"
$$
v= \sum_{i,j}\frac{(p_{i,j}-p_ip_j)^2}{p_ip_j}
$$
and the theor
|
39,811
|
Average number of failures before success
|
I disagree with the answer given by @probabilityislogic. There is no geometric distribution here at all, truncated or otherwise.
One of 13 agents can answer the question. The worker calls the agents one by one until the worker reaches the agent who can answer the question. Let us number the agents as $1$, $2, \ldots, 13$ in the order in which they are called. Absent any other information, I presume that the agent who can answer the question is equally likely to be any of $1$, $2, \ldots, 13$, and so the average number of calls is
$7$. The next question may lead to the agents being called in a different order, but the identity of the agent may be different too, and so the same analysis applies.
Alternative scenario to be considered: all the questions are on the same topic and can be answered by just one agent but the worker, being a slow learner, does not figure this out, and calls the agents in random order every time a question comes in. So the go-to agent is reached on the first, second, ...., thirteenth call with equal probability, and again, $7$ calls are required on average.
Added note: The simulation by @thias (cf. comment on probabilityislogic's answer) confirms my analysis.
|
Average number of failures before success
|
I disagree with the answer given by @probabilityislogic. There is no geometric distribution here at all, truncated or otherwise.
One of 13 agents can answer the question. The worker calls the agents
|
Average number of failures before success
I disagree with the answer given by @probabilityislogic. There is no geometric distribution here at all, truncated or otherwise.
One of 13 agents can answer the question. The worker calls the agents one by one until the worker reaches the agent who can answer the question. Let us number the agents as $1$, $2, \ldots, 13$ in the order in which they are called. Absent any other information, I presume that the agent who can answer the question is equally likely to be any of $1$, $2, \ldots, 13$, and so the average number of calls is
$7$. The next question may lead to the agents being called in a different order, but the identity of the agent may be different too, and so the same analysis applies.
Alternative scenario to be considered: all the questions are on the same topic and can be answered by just one agent but the worker, being a slow learner, does not figure this out, and calls the agents in random order every time a question comes in. So the go-to agent is reached on the first, second, ...., thirteenth call with equal probability, and again, $7$ calls are required on average.
Added note: The simulation by @thias (cf. comment on probabilityislogic's answer) confirms my analysis.
|
Average number of failures before success
I disagree with the answer given by @probabilityislogic. There is no geometric distribution here at all, truncated or otherwise.
One of 13 agents can answer the question. The worker calls the agents
|
39,812
|
Average number of failures before success
|
What you require is a truncated geometric distribution. The usual geometric distribution has a support of $0,1,\dots$ (i.e. to infinity) whereas your one has support only up to $12$.
So you need to renormalise the pdf.
$$Pr(X=x|p)=Ap(1-p)^x\implies A^{-1}=\sum_{x=0}^{12}p(1-p)^x=1-(1-p)^{13}$$
$$\implies Pr(X=x|p)=\frac{p(1-p)^x}{1-(1-p)^{13}}$$
Now we take expectations over this pdf (letting $q=1-p=\frac{12}{13}$):
$$E(X|p)=\frac{p}{1-q^{13}}\sum_{x=0}^{12}xq^x$$
$$=\frac{pq}{1-q^{13}}\sum_{x=0}^{12}\frac{\partial}{\partial q}q^{x}
=\frac{pq}{1-q^{13}}\frac{\partial}{\partial q}\sum_{x=0}^{12}q^{x}=\frac{pq}{1-q^{13}}\frac{\partial}{\partial q}\frac{1-q^{x+1}}{1-q}$$
$$=\frac{pq}{1-q^{13}}\frac{1-q^{12}-12q^{12}(1-q)}{(1-q)^2}$$
$$=\frac{q}{1-q}\times\frac{1-q^{12}-12q^{12}(1-q)}{1-q^{13}}=12\times 0.43=5.13$$
That last factor represents a correction to the usual mean, due to the range restriction. For the more general case, we have (again letting $q=1-p$ be the chance for failure):
$$Pr(X=x|N,q)=\frac{(1-q)q^x}{1-q^{N+1}}\;\;\;\;\;\;\;\;x\in\{0,1,\dots,N\}$$
$$E(X|q,N)=\frac{q}{1-q}\times\frac{1-q^{N}-Nq^{N}(1-q)}{1-q^{N+1}}$$
Both of these contain the usual geometric distribution as appropriate limits as $N\to\infty$
UPDATE
This answer actually assumes that all $13$ operators could be called on any of the trials. Hence the $p$ remains constant. However, as Dilas correctly points out, the proper distribution is uniform. You can see this by "direct counting", the chance of correct on the first call is $\frac{1}{13}$, and the chance of correct on the second call is $(1-\frac{1}{13})\frac{1}{12}=\frac{1}{13}$ (the second prob is $\frac{1}{12}$ because the operator won't call the first caller again). For general case we have a "telescoping product":
$$Pr(X=x|N)=\frac{1}{N+1-x}\prod_{j=0}^{x-1}(1-\frac{1}{N+1-j})=\frac{1}{N+1-x}\prod_{j=0}^{x-1}\frac{N-j}{N+1-j}=\frac{1}{N+1}$$
This gives the expected value of $7$
|
Average number of failures before success
|
What you require is a truncated geometric distribution. The usual geometric distribution has a support of $0,1,\dots$ (i.e. to infinity) whereas your one has support only up to $12$.
So you need to r
|
Average number of failures before success
What you require is a truncated geometric distribution. The usual geometric distribution has a support of $0,1,\dots$ (i.e. to infinity) whereas your one has support only up to $12$.
So you need to renormalise the pdf.
$$Pr(X=x|p)=Ap(1-p)^x\implies A^{-1}=\sum_{x=0}^{12}p(1-p)^x=1-(1-p)^{13}$$
$$\implies Pr(X=x|p)=\frac{p(1-p)^x}{1-(1-p)^{13}}$$
Now we take expectations over this pdf (letting $q=1-p=\frac{12}{13}$):
$$E(X|p)=\frac{p}{1-q^{13}}\sum_{x=0}^{12}xq^x$$
$$=\frac{pq}{1-q^{13}}\sum_{x=0}^{12}\frac{\partial}{\partial q}q^{x}
=\frac{pq}{1-q^{13}}\frac{\partial}{\partial q}\sum_{x=0}^{12}q^{x}=\frac{pq}{1-q^{13}}\frac{\partial}{\partial q}\frac{1-q^{x+1}}{1-q}$$
$$=\frac{pq}{1-q^{13}}\frac{1-q^{12}-12q^{12}(1-q)}{(1-q)^2}$$
$$=\frac{q}{1-q}\times\frac{1-q^{12}-12q^{12}(1-q)}{1-q^{13}}=12\times 0.43=5.13$$
That last factor represents a correction to the usual mean, due to the range restriction. For the more general case, we have (again letting $q=1-p$ be the chance for failure):
$$Pr(X=x|N,q)=\frac{(1-q)q^x}{1-q^{N+1}}\;\;\;\;\;\;\;\;x\in\{0,1,\dots,N\}$$
$$E(X|q,N)=\frac{q}{1-q}\times\frac{1-q^{N}-Nq^{N}(1-q)}{1-q^{N+1}}$$
Both of these contain the usual geometric distribution as appropriate limits as $N\to\infty$
UPDATE
This answer actually assumes that all $13$ operators could be called on any of the trials. Hence the $p$ remains constant. However, as Dilas correctly points out, the proper distribution is uniform. You can see this by "direct counting", the chance of correct on the first call is $\frac{1}{13}$, and the chance of correct on the second call is $(1-\frac{1}{13})\frac{1}{12}=\frac{1}{13}$ (the second prob is $\frac{1}{12}$ because the operator won't call the first caller again). For general case we have a "telescoping product":
$$Pr(X=x|N)=\frac{1}{N+1-x}\prod_{j=0}^{x-1}(1-\frac{1}{N+1-j})=\frac{1}{N+1-x}\prod_{j=0}^{x-1}\frac{N-j}{N+1-j}=\frac{1}{N+1}$$
This gives the expected value of $7$
|
Average number of failures before success
What you require is a truncated geometric distribution. The usual geometric distribution has a support of $0,1,\dots$ (i.e. to infinity) whereas your one has support only up to $12$.
So you need to r
|
39,813
|
How to solve Chuck-a-Luck puzzle
|
All three methods should produce the same result for the house edge. To check yours, you should find
Number 1s Prob
0 125/216
1 75/216
2 15/216
3 1/216
which would make your expected winnings (for a stake of 1)
$$\frac{-1\times 125 + 1\times 75 + 2 \times 15 + 3 \times 1}{216} = - \frac{17}{216} \approx -0.0787.$$
You may need to check your calculations again.
|
How to solve Chuck-a-Luck puzzle
|
All three methods should produce the same result for the house edge. To check yours, you should find
Number 1s Prob
0 125/216
1 75/216
2 15/216
3 1/2
|
How to solve Chuck-a-Luck puzzle
All three methods should produce the same result for the house edge. To check yours, you should find
Number 1s Prob
0 125/216
1 75/216
2 15/216
3 1/216
which would make your expected winnings (for a stake of 1)
$$\frac{-1\times 125 + 1\times 75 + 2 \times 15 + 3 \times 1}{216} = - \frac{17}{216} \approx -0.0787.$$
You may need to check your calculations again.
|
How to solve Chuck-a-Luck puzzle
All three methods should produce the same result for the house edge. To check yours, you should find
Number 1s Prob
0 125/216
1 75/216
2 15/216
3 1/2
|
39,814
|
How to compare group means for two samples with t-test using R?
|
1) Yes, it looks to me like you used the t.test function correctly.
2) Since your p-value is 0.9998 all you can say is that you don't have enough evidence to reject your null hypothesis (that the means are equal). In other words, your evidence (the scores from both group) doesn't show that the mean of the first group is greater than the mean of the second.
Note that I was careful in answering your second question not to conclude that the means are equal. You can't conclude that from the test. Only that you don't have evidence that the first is greater than the second.
|
How to compare group means for two samples with t-test using R?
|
1) Yes, it looks to me like you used the t.test function correctly.
2) Since your p-value is 0.9998 all you can say is that you don't have enough evidence to reject your null hypothesis (that the mean
|
How to compare group means for two samples with t-test using R?
1) Yes, it looks to me like you used the t.test function correctly.
2) Since your p-value is 0.9998 all you can say is that you don't have enough evidence to reject your null hypothesis (that the means are equal). In other words, your evidence (the scores from both group) doesn't show that the mean of the first group is greater than the mean of the second.
Note that I was careful in answering your second question not to conclude that the means are equal. You can't conclude that from the test. Only that you don't have evidence that the first is greater than the second.
|
How to compare group means for two samples with t-test using R?
1) Yes, it looks to me like you used the t.test function correctly.
2) Since your p-value is 0.9998 all you can say is that you don't have enough evidence to reject your null hypothesis (that the mean
|
39,815
|
How to compare group means for two samples with t-test using R?
|
The hypothesis stated is clearly one-sided and the problem is set up in a Neyman-Pearsonian manner. Those features might be deliberate, or it might be an accidental consequence of the fact that N-P is the dominant paradigm in many introductory statistics texts. If it is deliberate then the results of the analysis should stand and the null hypothesis accepted. (Move on, nothing to see here...) However, there are alternative paradigms that are worthy of consideration.
If an effect in the observed direction is interesting (or, some might insist that I say 'would have been interesting before the experiment was done') then the one-sided test was ill-advised to begin with. If these data are part of a series of characterization experiments then the use of a decision-forcing N-P approach was inappropriate. Instead, use a Fisherian approach where the two-sided p value is as an index of the evidence against the null hypothesis (pointing to fairly strong evidence against the null in this case). Another evidence-yielding approach is to determine the likelihood function for the result which can then be updated with the evidence form subsequent tests of the same null hypothesis.
To some, these suggestions will sound outlandish and bordering on illegal. However I think that it is important to point out that many of the procedures and rules of statistical analysis come from schools of thought that are little more than expressions of opinion of strong-minded statisticians.
|
How to compare group means for two samples with t-test using R?
|
The hypothesis stated is clearly one-sided and the problem is set up in a Neyman-Pearsonian manner. Those features might be deliberate, or it might be an accidental consequence of the fact that N-P is
|
How to compare group means for two samples with t-test using R?
The hypothesis stated is clearly one-sided and the problem is set up in a Neyman-Pearsonian manner. Those features might be deliberate, or it might be an accidental consequence of the fact that N-P is the dominant paradigm in many introductory statistics texts. If it is deliberate then the results of the analysis should stand and the null hypothesis accepted. (Move on, nothing to see here...) However, there are alternative paradigms that are worthy of consideration.
If an effect in the observed direction is interesting (or, some might insist that I say 'would have been interesting before the experiment was done') then the one-sided test was ill-advised to begin with. If these data are part of a series of characterization experiments then the use of a decision-forcing N-P approach was inappropriate. Instead, use a Fisherian approach where the two-sided p value is as an index of the evidence against the null hypothesis (pointing to fairly strong evidence against the null in this case). Another evidence-yielding approach is to determine the likelihood function for the result which can then be updated with the evidence form subsequent tests of the same null hypothesis.
To some, these suggestions will sound outlandish and bordering on illegal. However I think that it is important to point out that many of the procedures and rules of statistical analysis come from schools of thought that are little more than expressions of opinion of strong-minded statisticians.
|
How to compare group means for two samples with t-test using R?
The hypothesis stated is clearly one-sided and the problem is set up in a Neyman-Pearsonian manner. Those features might be deliberate, or it might be an accidental consequence of the fact that N-P is
|
39,816
|
Presenting logistic model fit graphically
|
First I want to reiterate what others have said in the comments: this is in general a difficult problem with no easy solution.
With that in mind, one way of assessing model fit with logistic regression models when your primary interest is simply predictive power is to plot ROCs. Here's an example (with caveats) using the pROC package in R:
library(pROC)
#Fit three logistic models
m1 <- glm(case ~ age,data=infert,family=binomial())
m2 <- glm(case ~ age + parity + education + induced,
data=infert,family=binomial())
m3 <- glm(case ~ age+parity+education+spontaneous+induced,
data=infert,family=binomial())
#Plot the three ROCs, adding the AUC for each
plot.roc(infert$case,fitted(m1),print.auc = TRUE)
plot.roc(infert$case,fitted(m2),add=TRUE,col = "blue",
print.auc=TRUE,print.auc.y = 0.45)
plot.roc(infert$case,fitted(m3),add = TRUE,col = "red",
print.auc = TRUE,print.auc.y = 0.4)
The basic idea is that more area under the curve indicates a "better" model, from the perspective of prediction only.
Note that my example is meant only to illustrate how to make such a graph, as I've plotted these curves using the in-sample fitted values, rather than those obtained using cross validation, bootstrapping or a hold-out test set, which in general is preferable.
I'll end by repeating my warning that this is far from the way to assess model fit. It is just a way that is limited to assessing predictive accuracy.
|
Presenting logistic model fit graphically
|
First I want to reiterate what others have said in the comments: this is in general a difficult problem with no easy solution.
With that in mind, one way of assessing model fit with logistic regressio
|
Presenting logistic model fit graphically
First I want to reiterate what others have said in the comments: this is in general a difficult problem with no easy solution.
With that in mind, one way of assessing model fit with logistic regression models when your primary interest is simply predictive power is to plot ROCs. Here's an example (with caveats) using the pROC package in R:
library(pROC)
#Fit three logistic models
m1 <- glm(case ~ age,data=infert,family=binomial())
m2 <- glm(case ~ age + parity + education + induced,
data=infert,family=binomial())
m3 <- glm(case ~ age+parity+education+spontaneous+induced,
data=infert,family=binomial())
#Plot the three ROCs, adding the AUC for each
plot.roc(infert$case,fitted(m1),print.auc = TRUE)
plot.roc(infert$case,fitted(m2),add=TRUE,col = "blue",
print.auc=TRUE,print.auc.y = 0.45)
plot.roc(infert$case,fitted(m3),add = TRUE,col = "red",
print.auc = TRUE,print.auc.y = 0.4)
The basic idea is that more area under the curve indicates a "better" model, from the perspective of prediction only.
Note that my example is meant only to illustrate how to make such a graph, as I've plotted these curves using the in-sample fitted values, rather than those obtained using cross validation, bootstrapping or a hold-out test set, which in general is preferable.
I'll end by repeating my warning that this is far from the way to assess model fit. It is just a way that is limited to assessing predictive accuracy.
|
Presenting logistic model fit graphically
First I want to reiterate what others have said in the comments: this is in general a difficult problem with no easy solution.
With that in mind, one way of assessing model fit with logistic regressio
|
39,817
|
Presenting logistic model fit graphically
|
A good reference for the kind of graphs you seem to want is John Fox, "Effect Displays for Multinomial and Proportional-Odds Logit Models," in Sociological Methodology (2006). See the citations to his earlier work. He implements these techniques in R and S-Plus in his book that accompanies his text on linear regression.
|
Presenting logistic model fit graphically
|
A good reference for the kind of graphs you seem to want is John Fox, "Effect Displays for Multinomial and Proportional-Odds Logit Models," in Sociological Methodology (2006). See the citations to his
|
Presenting logistic model fit graphically
A good reference for the kind of graphs you seem to want is John Fox, "Effect Displays for Multinomial and Proportional-Odds Logit Models," in Sociological Methodology (2006). See the citations to his earlier work. He implements these techniques in R and S-Plus in his book that accompanies his text on linear regression.
|
Presenting logistic model fit graphically
A good reference for the kind of graphs you seem to want is John Fox, "Effect Displays for Multinomial and Proportional-Odds Logit Models," in Sociological Methodology (2006). See the citations to his
|
39,818
|
How to interpret KPSS results?
|
You specified a null hypothesis of trend stationarity. That is the data follow a straight line time trend with stationary errors. The p-value is 0.1, so the null hypothesis is not rejected at the usual 5% level.
|
How to interpret KPSS results?
|
You specified a null hypothesis of trend stationarity. That is the data follow a straight line time trend with stationary errors. The p-value is 0.1, so the null hypothesis is not rejected at the usua
|
How to interpret KPSS results?
You specified a null hypothesis of trend stationarity. That is the data follow a straight line time trend with stationary errors. The p-value is 0.1, so the null hypothesis is not rejected at the usual 5% level.
|
How to interpret KPSS results?
You specified a null hypothesis of trend stationarity. That is the data follow a straight line time trend with stationary errors. The p-value is 0.1, so the null hypothesis is not rejected at the usua
|
39,819
|
Testing normality
|
I would not rely on p-values for any test of normality (or for much else, frankly). Look at the graphs.
You can, a priori, say that EVERY distribution is non-normal. If you have a large dataset the nonnormality will be statistically significant. The questions are HOW non-normal? Non-normal in what ways? and What are the consequences?
None of these questions is answered by any test of normality or statistical significance.
Why are you testing normality? If it's a test of residuals for some linear model, there was a great quote from George Box ... something like this is "like sending out a rowboat to see if the water is calm enough for an ocean liner"
|
Testing normality
|
I would not rely on p-values for any test of normality (or for much else, frankly). Look at the graphs.
You can, a priori, say that EVERY distribution is non-normal. If you have a large dataset the no
|
Testing normality
I would not rely on p-values for any test of normality (or for much else, frankly). Look at the graphs.
You can, a priori, say that EVERY distribution is non-normal. If you have a large dataset the nonnormality will be statistically significant. The questions are HOW non-normal? Non-normal in what ways? and What are the consequences?
None of these questions is answered by any test of normality or statistical significance.
Why are you testing normality? If it's a test of residuals for some linear model, there was a great quote from George Box ... something like this is "like sending out a rowboat to see if the water is calm enough for an ocean liner"
|
Testing normality
I would not rely on p-values for any test of normality (or for much else, frankly). Look at the graphs.
You can, a priori, say that EVERY distribution is non-normal. If you have a large dataset the no
|
39,820
|
Testing normality
|
All I can say is that your eyes are one of your better EDA tools. If your data (with 500,000 observations) doesn't look normal, then there's no reason to even perform a statistical test for normality. Especially with that many data points, any slight deviation from normality should make you fail the test.
It looks like your data is actually discrete, too. You should consider fitting a Binomial or Poisson or some other discrete distribution to the data.
|
Testing normality
|
All I can say is that your eyes are one of your better EDA tools. If your data (with 500,000 observations) doesn't look normal, then there's no reason to even perform a statistical test for normality.
|
Testing normality
All I can say is that your eyes are one of your better EDA tools. If your data (with 500,000 observations) doesn't look normal, then there's no reason to even perform a statistical test for normality. Especially with that many data points, any slight deviation from normality should make you fail the test.
It looks like your data is actually discrete, too. You should consider fitting a Binomial or Poisson or some other discrete distribution to the data.
|
Testing normality
All I can say is that your eyes are one of your better EDA tools. If your data (with 500,000 observations) doesn't look normal, then there's no reason to even perform a statistical test for normality.
|
39,821
|
Appropriateness of calculating scale means based on available non-missing responses (i.e., person-mean imputation)
|
Some years ago, I thought it might be a good idea to apply person-mean imputation (person-mean substitution or case-mean imputation) in case of item non-response. Nowadays, however, it seems obvious to me that this approach assumes that all scale items share similar characteristics (similar variance, standard deviation, item difficulty, etc.). In other words, I would be concerned if some respondents do not answer difficult/sensitive/... items.
Bono et al (2007: 7) are less concerned about this approach:
"Person-mean imputation requires
substitution of the mean of all of an
individual’s completed items for those
items that were not completed on a
given scale. This differs from
item-mean where the mean response of
the whole sample that responded to the
item is substituted. Person-mean
imputation could result in different
substitutions for each person with
missing items. On the plus side,
because it does not substitute a
constant value, it does not
artificially reduce the measure’s
variability and is less likely to
attenuate the correlation. A
disadvantage is that it tends to
inflate the reliability estimates as
the number of missing items increases.
However, when the numbers of either
respondents with missing items or
items missing within scales are 20% or
less, both item-mean imputation and
person-mean imputation provide good
estimates of the reliability of
measures."
You also might want to check
Craig K. Enders (2010): Applied Missing Data Analysis. (Google books link)
Downey RG, King C. (1998): Missing data in Likert ratings: A comparison of replacement methods.
|
Appropriateness of calculating scale means based on available non-missing responses (i.e., person-me
|
Some years ago, I thought it might be a good idea to apply person-mean imputation (person-mean substitution or case-mean imputation) in case of item non-response. Nowadays, however, it seems obvious t
|
Appropriateness of calculating scale means based on available non-missing responses (i.e., person-mean imputation)
Some years ago, I thought it might be a good idea to apply person-mean imputation (person-mean substitution or case-mean imputation) in case of item non-response. Nowadays, however, it seems obvious to me that this approach assumes that all scale items share similar characteristics (similar variance, standard deviation, item difficulty, etc.). In other words, I would be concerned if some respondents do not answer difficult/sensitive/... items.
Bono et al (2007: 7) are less concerned about this approach:
"Person-mean imputation requires
substitution of the mean of all of an
individual’s completed items for those
items that were not completed on a
given scale. This differs from
item-mean where the mean response of
the whole sample that responded to the
item is substituted. Person-mean
imputation could result in different
substitutions for each person with
missing items. On the plus side,
because it does not substitute a
constant value, it does not
artificially reduce the measure’s
variability and is less likely to
attenuate the correlation. A
disadvantage is that it tends to
inflate the reliability estimates as
the number of missing items increases.
However, when the numbers of either
respondents with missing items or
items missing within scales are 20% or
less, both item-mean imputation and
person-mean imputation provide good
estimates of the reliability of
measures."
You also might want to check
Craig K. Enders (2010): Applied Missing Data Analysis. (Google books link)
Downey RG, King C. (1998): Missing data in Likert ratings: A comparison of replacement methods.
|
Appropriateness of calculating scale means based on available non-missing responses (i.e., person-me
Some years ago, I thought it might be a good idea to apply person-mean imputation (person-mean substitution or case-mean imputation) in case of item non-response. Nowadays, however, it seems obvious t
|
39,822
|
Appropriateness of calculating scale means based on available non-missing responses (i.e., person-mean imputation)
|
Person-mean imputation with an minimum-item threshold is a simple strategy for retaining scale scores where participants miss the occasional response.
Some general principles
If missing data is minimal (e.g., less than 5% of participants are missing 1 item on a 10 item scale), the method of dealing with missing data is unlikely to make a difference to substantive conclusions.
From a first principle perspective, imputation methods should provide more robust estimates of missing item responses as they incorporate both item and person characteristics into estimating the missing response.
Design studies to avoid sporadic item-missing data.
Conditions where person-mean imputation is more reasonable:
Item means are all about the same
The threshold number of missing items is low relative to the total number of items in the scale (e.g., a requirement for 19 out of 20 items is more appropriate than 10 out of 20 items)
There is generally very little missing data; at the extreme level, there is no missing data, and person-mean imputation does not change the data at all
the cause of missing data is due to random processes such as accidentally skipping items, not clearly indicating the response, and so on.
A simple and standardised rule for calculating scale means is desired (e.g., a rule might be required for a test manual that can be applied in a standardised way across studies and samples)
Avoiding sporadic missing data for items in scales
At a broader level, person-mean imputation of item responses is a response to a problem that can often be avoided using various study design strategies:
Computerised administration of questionnaires can prevent (where this is ethically permitted) participants skipping or missing items.
If questionnaires are administered on paper and in person, the experimenter can review the questionnaire booklet to check for missing data before the participant leaves the room.
|
Appropriateness of calculating scale means based on available non-missing responses (i.e., person-me
|
Person-mean imputation with an minimum-item threshold is a simple strategy for retaining scale scores where participants miss the occasional response.
Some general principles
If missing data is minim
|
Appropriateness of calculating scale means based on available non-missing responses (i.e., person-mean imputation)
Person-mean imputation with an minimum-item threshold is a simple strategy for retaining scale scores where participants miss the occasional response.
Some general principles
If missing data is minimal (e.g., less than 5% of participants are missing 1 item on a 10 item scale), the method of dealing with missing data is unlikely to make a difference to substantive conclusions.
From a first principle perspective, imputation methods should provide more robust estimates of missing item responses as they incorporate both item and person characteristics into estimating the missing response.
Design studies to avoid sporadic item-missing data.
Conditions where person-mean imputation is more reasonable:
Item means are all about the same
The threshold number of missing items is low relative to the total number of items in the scale (e.g., a requirement for 19 out of 20 items is more appropriate than 10 out of 20 items)
There is generally very little missing data; at the extreme level, there is no missing data, and person-mean imputation does not change the data at all
the cause of missing data is due to random processes such as accidentally skipping items, not clearly indicating the response, and so on.
A simple and standardised rule for calculating scale means is desired (e.g., a rule might be required for a test manual that can be applied in a standardised way across studies and samples)
Avoiding sporadic missing data for items in scales
At a broader level, person-mean imputation of item responses is a response to a problem that can often be avoided using various study design strategies:
Computerised administration of questionnaires can prevent (where this is ethically permitted) participants skipping or missing items.
If questionnaires are administered on paper and in person, the experimenter can review the questionnaire booklet to check for missing data before the participant leaves the room.
|
Appropriateness of calculating scale means based on available non-missing responses (i.e., person-me
Person-mean imputation with an minimum-item threshold is a simple strategy for retaining scale scores where participants miss the occasional response.
Some general principles
If missing data is minim
|
39,823
|
Appropriateness of calculating scale means based on available non-missing responses (i.e., person-mean imputation)
|
one more piece of advice: make sure the full 6-item composite scale is reliable & that none of the included items reduces scale reliability. If those conditions aren't satisfied, you shouldn't be averaging them even in cases where data are complete. If these conditions are satisfied, then using a subset of items for cases w/ missing data isn't going to bias your result (assuming you are averaging or adding z-score transformation of items, as you always should in forming aggregate likert scale); it is just going to make it noisier than it should be (b/c you are relying on fewer items & thus cancelling out less of the random measurement error associated with each individual item).
(Best solution, though, is multiple imputation, again assuming composite scale is reliable.)
|
Appropriateness of calculating scale means based on available non-missing responses (i.e., person-me
|
one more piece of advice: make sure the full 6-item composite scale is reliable & that none of the included items reduces scale reliability. If those conditions aren't satisfied, you shouldn't be aver
|
Appropriateness of calculating scale means based on available non-missing responses (i.e., person-mean imputation)
one more piece of advice: make sure the full 6-item composite scale is reliable & that none of the included items reduces scale reliability. If those conditions aren't satisfied, you shouldn't be averaging them even in cases where data are complete. If these conditions are satisfied, then using a subset of items for cases w/ missing data isn't going to bias your result (assuming you are averaging or adding z-score transformation of items, as you always should in forming aggregate likert scale); it is just going to make it noisier than it should be (b/c you are relying on fewer items & thus cancelling out less of the random measurement error associated with each individual item).
(Best solution, though, is multiple imputation, again assuming composite scale is reliable.)
|
Appropriateness of calculating scale means based on available non-missing responses (i.e., person-me
one more piece of advice: make sure the full 6-item composite scale is reliable & that none of the included items reduces scale reliability. If those conditions aren't satisfied, you shouldn't be aver
|
39,824
|
Rank transformed 2-way ANOVA
|
The proportional odds (PO) ordinal logistic model is a generalization of the Wilcoxon and Kruskal-Wallis tests, allowing for covariates, interactions, and anything else you can do in a regression model for a univariate response. A two-way ANOVA on ranks is not based on strong statistical principles.
One of many computational tools for the PO model is the lrm function in the R rms package. The rms package's contrast, anova, summary, plot, and nomogram functions can help.
|
Rank transformed 2-way ANOVA
|
The proportional odds (PO) ordinal logistic model is a generalization of the Wilcoxon and Kruskal-Wallis tests, allowing for covariates, interactions, and anything else you can do in a regression mode
|
Rank transformed 2-way ANOVA
The proportional odds (PO) ordinal logistic model is a generalization of the Wilcoxon and Kruskal-Wallis tests, allowing for covariates, interactions, and anything else you can do in a regression model for a univariate response. A two-way ANOVA on ranks is not based on strong statistical principles.
One of many computational tools for the PO model is the lrm function in the R rms package. The rms package's contrast, anova, summary, plot, and nomogram functions can help.
|
Rank transformed 2-way ANOVA
The proportional odds (PO) ordinal logistic model is a generalization of the Wilcoxon and Kruskal-Wallis tests, allowing for covariates, interactions, and anything else you can do in a regression mode
|
39,825
|
What's the minimum number of individuals in a group for repeated-measures ANOVA?
|
Performing the ANOVA assumes that the nature and amount of variation in the hypothetical population represented by the one patient are the same as the variation in the hypothetical population represented by the ten other patients, and that all were obtained randomly and independently from their populations.
Under these assumptions a standard approach is to use data from the ten patients to compute a prediction interval for a single additional patient. The significance test only has to check whether the lone patient falls within that interval.
The prediction interval is simple to justify and compute. It depends only on the estimated mean $\bar{m}$ from the ten patients and on their estimated variance $s^2$. Let $x$ be the value of the lone patient. Under the null hypothesis (that all patients are drawn independently from a single population), the variance of $x - \bar{m}$ equals $s^2 + s^2/10$. If you further assume all variation is Normal--that's critical here because it's hard to check with just ten patients in a group--then $\frac{x - \bar{m}}{\sqrt{s^2 + s^2/10}}$ has a Student's t distribution with 9 degrees of freedom (9 is the df used to estimate $s^2$), allowing you to erect a confidence interval in the standard way for $x$.
If this prediction interval test disagrees with SPSS's result, I would not trust the SPSS ANOVA in this case.
|
What's the minimum number of individuals in a group for repeated-measures ANOVA?
|
Performing the ANOVA assumes that the nature and amount of variation in the hypothetical population represented by the one patient are the same as the variation in the hypothetical population represen
|
What's the minimum number of individuals in a group for repeated-measures ANOVA?
Performing the ANOVA assumes that the nature and amount of variation in the hypothetical population represented by the one patient are the same as the variation in the hypothetical population represented by the ten other patients, and that all were obtained randomly and independently from their populations.
Under these assumptions a standard approach is to use data from the ten patients to compute a prediction interval for a single additional patient. The significance test only has to check whether the lone patient falls within that interval.
The prediction interval is simple to justify and compute. It depends only on the estimated mean $\bar{m}$ from the ten patients and on their estimated variance $s^2$. Let $x$ be the value of the lone patient. Under the null hypothesis (that all patients are drawn independently from a single population), the variance of $x - \bar{m}$ equals $s^2 + s^2/10$. If you further assume all variation is Normal--that's critical here because it's hard to check with just ten patients in a group--then $\frac{x - \bar{m}}{\sqrt{s^2 + s^2/10}}$ has a Student's t distribution with 9 degrees of freedom (9 is the df used to estimate $s^2$), allowing you to erect a confidence interval in the standard way for $x$.
If this prediction interval test disagrees with SPSS's result, I would not trust the SPSS ANOVA in this case.
|
What's the minimum number of individuals in a group for repeated-measures ANOVA?
Performing the ANOVA assumes that the nature and amount of variation in the hypothetical population represented by the one patient are the same as the variation in the hypothetical population represen
|
39,826
|
How do I generate a QQ-Plot for data fitted using fitdistr?
|
Try the following code:
simdata <- qexp(ppoints(length(data)), rate = params$estimate)
qqplot(data, simdata)
(Inspired by the base R implementation of qqnorm)
PS When using non-base R functions, you should state what library they come from. I had to Google to discover that fitdistr is from MASS.
|
How do I generate a QQ-Plot for data fitted using fitdistr?
|
Try the following code:
simdata <- qexp(ppoints(length(data)), rate = params$estimate)
qqplot(data, simdata)
(Inspired by the base R implementation of qqnorm)
PS When using non-base R functions, you
|
How do I generate a QQ-Plot for data fitted using fitdistr?
Try the following code:
simdata <- qexp(ppoints(length(data)), rate = params$estimate)
qqplot(data, simdata)
(Inspired by the base R implementation of qqnorm)
PS When using non-base R functions, you should state what library they come from. I had to Google to discover that fitdistr is from MASS.
|
How do I generate a QQ-Plot for data fitted using fitdistr?
Try the following code:
simdata <- qexp(ppoints(length(data)), rate = params$estimate)
qqplot(data, simdata)
(Inspired by the base R implementation of qqnorm)
PS When using non-base R functions, you
|
39,827
|
How do I generate a QQ-Plot for data fitted using fitdistr?
|
You could also look Wessa P., (2008), Maximum-likelihood Exponential Distribution Fitting which has a nice, documented online execution of the problem with the R source code attached to the actual plot.
|
How do I generate a QQ-Plot for data fitted using fitdistr?
|
You could also look Wessa P., (2008), Maximum-likelihood Exponential Distribution Fitting which has a nice, documented online execution of the problem with the R source code attached to the actual plo
|
How do I generate a QQ-Plot for data fitted using fitdistr?
You could also look Wessa P., (2008), Maximum-likelihood Exponential Distribution Fitting which has a nice, documented online execution of the problem with the R source code attached to the actual plot.
|
How do I generate a QQ-Plot for data fitted using fitdistr?
You could also look Wessa P., (2008), Maximum-likelihood Exponential Distribution Fitting which has a nice, documented online execution of the problem with the R source code attached to the actual plo
|
39,828
|
Annotating graphs in R [closed]
|
A quick and dirty way to paste some text and numerical results along the labels of your legend is to simply rename the factor levels. For instance,
df <- data.frame(x=rnorm(100), y=rnorm(100), f=gl(2,50))
df$f2 <- df$f
levels(df$f2) <- paste(levels(df$f), tapply(df$y, df$f, mean), sep=": ")
p <- ggplot(data=df) + geom_point(aes(x=x, y=y, color=f2))
p + opts(legend.position = 'bottom', legend.title=NULL)
You can add whatever you want into the new labels, such as mean, min, max, etc. (e.g., create a custom function, inspired from summary() that returns the values you want, and append them to c("In","Out")).
|
Annotating graphs in R [closed]
|
A quick and dirty way to paste some text and numerical results along the labels of your legend is to simply rename the factor levels. For instance,
df <- data.frame(x=rnorm(100), y=rnorm(100), f=gl(2,
|
Annotating graphs in R [closed]
A quick and dirty way to paste some text and numerical results along the labels of your legend is to simply rename the factor levels. For instance,
df <- data.frame(x=rnorm(100), y=rnorm(100), f=gl(2,50))
df$f2 <- df$f
levels(df$f2) <- paste(levels(df$f), tapply(df$y, df$f, mean), sep=": ")
p <- ggplot(data=df) + geom_point(aes(x=x, y=y, color=f2))
p + opts(legend.position = 'bottom', legend.title=NULL)
You can add whatever you want into the new labels, such as mean, min, max, etc. (e.g., create a custom function, inspired from summary() that returns the values you want, and append them to c("In","Out")).
|
Annotating graphs in R [closed]
A quick and dirty way to paste some text and numerical results along the labels of your legend is to simply rename the factor levels. For instance,
df <- data.frame(x=rnorm(100), y=rnorm(100), f=gl(2,
|
39,829
|
Annotating graphs in R [closed]
|
I'm sure that there's a more elegant way to do this but you can try this :
Data <- data.frame(serie1 = cumsum(rnorm(100)), serie2 = rnorm(100), temps = as.Date(1:100, origin = "2000-01-01"))
label <- c("In traffic [max 2.0G bps] [Avg 1.1G bps] [95% 1.8G bps] [Min 569.4M bps]", "Out traffic [max 2.0G bps] [Avg 672M bps] [95% 2.1G bps] [Min 154.3M bps]")
p <- ggplot(melt(Data, id = "temps"), aes(temps, value, group = variable, colour = variable))
p <- p + geom_line() +xlab("") + opts(legend.position = "bottom", legend.title = NULL)
p <- p + scale_colour_manual(values = c("red", "blue"), breaks = c("serie1", "serie2"), labels = label)
print(p)
|
Annotating graphs in R [closed]
|
I'm sure that there's a more elegant way to do this but you can try this :
Data <- data.frame(serie1 = cumsum(rnorm(100)), serie2 = rnorm(100), temps = as.Date(1:100, origin = "2000-01-01"))
label <
|
Annotating graphs in R [closed]
I'm sure that there's a more elegant way to do this but you can try this :
Data <- data.frame(serie1 = cumsum(rnorm(100)), serie2 = rnorm(100), temps = as.Date(1:100, origin = "2000-01-01"))
label <- c("In traffic [max 2.0G bps] [Avg 1.1G bps] [95% 1.8G bps] [Min 569.4M bps]", "Out traffic [max 2.0G bps] [Avg 672M bps] [95% 2.1G bps] [Min 154.3M bps]")
p <- ggplot(melt(Data, id = "temps"), aes(temps, value, group = variable, colour = variable))
p <- p + geom_line() +xlab("") + opts(legend.position = "bottom", legend.title = NULL)
p <- p + scale_colour_manual(values = c("red", "blue"), breaks = c("serie1", "serie2"), labels = label)
print(p)
|
Annotating graphs in R [closed]
I'm sure that there's a more elegant way to do this but you can try this :
Data <- data.frame(serie1 = cumsum(rnorm(100)), serie2 = rnorm(100), temps = as.Date(1:100, origin = "2000-01-01"))
label <
|
39,830
|
Annotating graphs in R [closed]
|
Try the directlabels package for some more control. As far as the caption goes, if you're automatically generating the graphs, you might simply use it as caption text (in LaTeX or HTML or what have you). Hope this helps.
|
Annotating graphs in R [closed]
|
Try the directlabels package for some more control. As far as the caption goes, if you're automatically generating the graphs, you might simply use it as caption text (in LaTeX or HTML or what have y
|
Annotating graphs in R [closed]
Try the directlabels package for some more control. As far as the caption goes, if you're automatically generating the graphs, you might simply use it as caption text (in LaTeX or HTML or what have you). Hope this helps.
|
Annotating graphs in R [closed]
Try the directlabels package for some more control. As far as the caption goes, if you're automatically generating the graphs, you might simply use it as caption text (in LaTeX or HTML or what have y
|
39,831
|
Checking factor / covariate independence in ANCOVA
|
One approach is to see if the covariate is correlated with the predictor variables. That is, if the ANCOVA is given by:
predicted ~ covariate + predictor1*predictor2*predictor3
Then first assess whether the covariate and the various predictor effects/interactions are correlated:
covariate ~ predictor1*predictor2*predictor3
If you find that the covariate is correlated with any of the predictor variables or their interaction, then you're violating the assumption you cite. If the covariate is categorical with more than 2 levels, you'll have to assess the correlations via multinomial regression.
|
Checking factor / covariate independence in ANCOVA
|
One approach is to see if the covariate is correlated with the predictor variables. That is, if the ANCOVA is given by:
predicted ~ covariate + predictor1*predictor2*predictor3
Then first assess whet
|
Checking factor / covariate independence in ANCOVA
One approach is to see if the covariate is correlated with the predictor variables. That is, if the ANCOVA is given by:
predicted ~ covariate + predictor1*predictor2*predictor3
Then first assess whether the covariate and the various predictor effects/interactions are correlated:
covariate ~ predictor1*predictor2*predictor3
If you find that the covariate is correlated with any of the predictor variables or their interaction, then you're violating the assumption you cite. If the covariate is categorical with more than 2 levels, you'll have to assess the correlations via multinomial regression.
|
Checking factor / covariate independence in ANCOVA
One approach is to see if the covariate is correlated with the predictor variables. That is, if the ANCOVA is given by:
predicted ~ covariate + predictor1*predictor2*predictor3
Then first assess whet
|
39,832
|
Checking factor / covariate independence in ANCOVA
|
EDIT As pointed out in the comments below, this is an answer to a different question, one about ensuring that the effect of the covariate is the same in all groups.
You have to check for interactions of the covariate and the factors. So if the ANCOVA model was
lm1 <- lm(outcome ~ covariate + factor1*factor2*factor3)
then the you can add all the interactions and look at
lm2 <- lm(outcome ~ covariate*factor1*factor2*factor3)
followed by an F-test:
anova(lm1, lm2)
It might also make sense to add fewer interactions (especially if you don't have a lot of data), so that the large number of high order interactions don't eat up the power.
|
Checking factor / covariate independence in ANCOVA
|
EDIT As pointed out in the comments below, this is an answer to a different question, one about ensuring that the effect of the covariate is the same in all groups.
You have to check for interactions
|
Checking factor / covariate independence in ANCOVA
EDIT As pointed out in the comments below, this is an answer to a different question, one about ensuring that the effect of the covariate is the same in all groups.
You have to check for interactions of the covariate and the factors. So if the ANCOVA model was
lm1 <- lm(outcome ~ covariate + factor1*factor2*factor3)
then the you can add all the interactions and look at
lm2 <- lm(outcome ~ covariate*factor1*factor2*factor3)
followed by an F-test:
anova(lm1, lm2)
It might also make sense to add fewer interactions (especially if you don't have a lot of data), so that the large number of high order interactions don't eat up the power.
|
Checking factor / covariate independence in ANCOVA
EDIT As pointed out in the comments below, this is an answer to a different question, one about ensuring that the effect of the covariate is the same in all groups.
You have to check for interactions
|
39,833
|
Mixed effects log-linear models
|
Log-linear or Poisson model are part of generalized linear models. Look at the lme4 package which allows for mixed-effects modeling, with family=poisson().
Here is an example of use:
> data(homerun, package="Zelig")
> with(homerun, table(homeruns, month))
month
homeruns April August July June March May September
0 36 36 40 26 1 33 30
1 13 17 11 21 1 14 14
2 0 3 3 3 0 3 6
3 1 0 0 1 0 1 0
> library(lme4)
> mod <- glmer(homeruns ~ player + (player - 1 | month), data=homerun, family=poisson())
> summary(mod)
Generalized linear mixed model fit by the Laplace approximation
Formula: homeruns ~ player + (player - 1 | month)
Data: homerun
AIC BIC logLik deviance
305.8 324.6 -147.9 295.8
Random effects:
Groups Name Variance Std.Dev. Corr
month playerMcGwire 7.9688e-10 2.8229e-05
playerSosa 6.6633e-02 2.5813e-01 0.000
Number of obs: 314, groups: month, 7
Fixed effects:
Estimate Std. Error z value Pr(>|z|)
(Intercept) -0.7949 0.1195 -6.651 2.91e-11 ***
playerSosa -0.1252 0.2020 -0.620 0.535
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
Correlation of Fixed Effects:
(Intr)
playerSosa -0.592
The scale parameter (useful to check for possible overdispersion) is available through the following slot:
summary(mod)@sigma
(The equivalent for usual GLM would be summary(glm(...))$dispersion).
More information about mixed-effects modeling as implemented in lme4 can be found on R-forge, in the Mixed-effects models project, or the GLMM FAQ, as suggested by @fabians.
The gamm4 package may also be of interest as it allows to fit generalized additive mixed models.
|
Mixed effects log-linear models
|
Log-linear or Poisson model are part of generalized linear models. Look at the lme4 package which allows for mixed-effects modeling, with family=poisson().
Here is an example of use:
> data(homerun, p
|
Mixed effects log-linear models
Log-linear or Poisson model are part of generalized linear models. Look at the lme4 package which allows for mixed-effects modeling, with family=poisson().
Here is an example of use:
> data(homerun, package="Zelig")
> with(homerun, table(homeruns, month))
month
homeruns April August July June March May September
0 36 36 40 26 1 33 30
1 13 17 11 21 1 14 14
2 0 3 3 3 0 3 6
3 1 0 0 1 0 1 0
> library(lme4)
> mod <- glmer(homeruns ~ player + (player - 1 | month), data=homerun, family=poisson())
> summary(mod)
Generalized linear mixed model fit by the Laplace approximation
Formula: homeruns ~ player + (player - 1 | month)
Data: homerun
AIC BIC logLik deviance
305.8 324.6 -147.9 295.8
Random effects:
Groups Name Variance Std.Dev. Corr
month playerMcGwire 7.9688e-10 2.8229e-05
playerSosa 6.6633e-02 2.5813e-01 0.000
Number of obs: 314, groups: month, 7
Fixed effects:
Estimate Std. Error z value Pr(>|z|)
(Intercept) -0.7949 0.1195 -6.651 2.91e-11 ***
playerSosa -0.1252 0.2020 -0.620 0.535
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
Correlation of Fixed Effects:
(Intr)
playerSosa -0.592
The scale parameter (useful to check for possible overdispersion) is available through the following slot:
summary(mod)@sigma
(The equivalent for usual GLM would be summary(glm(...))$dispersion).
More information about mixed-effects modeling as implemented in lme4 can be found on R-forge, in the Mixed-effects models project, or the GLMM FAQ, as suggested by @fabians.
The gamm4 package may also be of interest as it allows to fit generalized additive mixed models.
|
Mixed effects log-linear models
Log-linear or Poisson model are part of generalized linear models. Look at the lme4 package which allows for mixed-effects modeling, with family=poisson().
Here is an example of use:
> data(homerun, p
|
39,834
|
Log graph question
|
Yes. Quantiles can be transformed under any monotonically increasing transformation.
To see this, suppose $Y$ is the random variable and $q_{0.16}$ is the 16% quantile. Then
$$
\text{Pr}(Y\le q_{0.16}) = \text{Pr}(\log(Y)\le\log(q_{0.16})) = 0.16.
$$
Generally, if $f$ is monotonic and increasing then
$$
\text{Pr}(Y\le q_{\alpha}) = \text{Pr}(f(Y)\le f(q_{\alpha})) = \alpha.
$$
|
Log graph question
|
Yes. Quantiles can be transformed under any monotonically increasing transformation.
To see this, suppose $Y$ is the random variable and $q_{0.16}$ is the 16% quantile. Then
$$
\text{Pr}(Y\le q_{0.16
|
Log graph question
Yes. Quantiles can be transformed under any monotonically increasing transformation.
To see this, suppose $Y$ is the random variable and $q_{0.16}$ is the 16% quantile. Then
$$
\text{Pr}(Y\le q_{0.16}) = \text{Pr}(\log(Y)\le\log(q_{0.16})) = 0.16.
$$
Generally, if $f$ is monotonic and increasing then
$$
\text{Pr}(Y\le q_{\alpha}) = \text{Pr}(f(Y)\le f(q_{\alpha})) = \alpha.
$$
|
Log graph question
Yes. Quantiles can be transformed under any monotonically increasing transformation.
To see this, suppose $Y$ is the random variable and $q_{0.16}$ is the 16% quantile. Then
$$
\text{Pr}(Y\le q_{0.16
|
39,835
|
Log graph question
|
Yes.
When you say that "X is the 16% quantile", what it means is that 16% of the sample have a lower value than X. The log of any number smaller than X is smaller than log(X) and the log of any number greater than X is greater than log(X), so the ordering is not changed.
|
Log graph question
|
Yes.
When you say that "X is the 16% quantile", what it means is that 16% of the sample have a lower value than X. The log of any number smaller than X is smaller than log(X) and the log of any number
|
Log graph question
Yes.
When you say that "X is the 16% quantile", what it means is that 16% of the sample have a lower value than X. The log of any number smaller than X is smaller than log(X) and the log of any number greater than X is greater than log(X), so the ordering is not changed.
|
Log graph question
Yes.
When you say that "X is the 16% quantile", what it means is that 16% of the sample have a lower value than X. The log of any number smaller than X is smaller than log(X) and the log of any number
|
39,836
|
Difference between Norm of Residuals and what is a "good" Norm of Residual
|
So, I would recommend using standard method for comparing nested models. In your case, you consider two alternative models, the cubic fit being the more "complex" one. An F- or $\chi^2$-test tells you whether the residual sum of squares or deviance significantly decrease when you add further terms. It is very like comparing a model including only the intercept (in this case, you have residual variance only) vs. another one which include one meaningful predictor: does this added predictor account for a sufficient part of the variance in the response? In your case, it amounts to say: Modeling a cubic relationship between X and Y decreases the unexplained variance (equivalently, the $R^2$ will increase), and thus provide a better fit to the data compared to a linear fit.
It is often used as a test of linearity between the response variable and the predictor, and this is the reason why Frank Harrell advocates the use of restricted cubic spline instead of assuming a strict linear relationship between Y and the continuous Xs (e.g. age).
The following example comes from a book I was reading some months ago (High-dimensional data analysis in cancer research, Chap. 3, p. 45), but it may well serves as an illustration. The idea is just to fit different kind of models to a simulated data set, which clearly highlights a non-linear relationship between the response variable and the predictor. The true generative model is shown in black. The other colors are for different models (restricted cubic spline, B-spline close to yours, and CV smoothed spline).
library(rms)
library(splines)
set.seed(101)
f <- function(x) sin(sqrt(2*pi*x))
n <- 1000
x <- runif(n, 0, 2*pi)
sigma <- rnorm(n, 0, 0.25)
y <- f(x) + sigma
plot(x, y, cex=.4)
curve(f, 0, 6, lty=2, add=TRUE)
# linear fit
lm00 <- lm(y~x)
# restricted cubic spline, 3 knots (2 Df)
lm0 <- lm(y~rcs(x,3))
lines(seq(0,6,length=1000),
predict(lm0,data.frame(x=seq(0,6,length=1000))),
col="red")
# use B-spline and a single knot at x=1.13 (4 Df)
lm1 <- lm(y~bs(x, knots=1.13))
lines(seq(0,6,length=1000),
predict(lm1,data.frame(x=seq(0,6,length=1000))),
col="green")
# cross-validated smoothed spline (approx. 20 Df)
xy.spl <- smooth.spline(x, y, cv=TRUE)
lines(xy.spl, col="blue")
legend("bottomleft", c("f(x)","RCS {rms}","BS {splines}","SS {stats}"),
col=1:4, lty=c(2,rep(1,3)),bty="n", cex=.6)
Now, suppose you want to compare the linear fit (lm00) and model relying on B-spline (lm1), you just have to do an F-test to see that the latter provides a better fit:
> anova(lm00, lm1)
Analysis of Variance Table
Model 1: y ~ x
Model 2: y ~ bs(x, knots = 1.13)
Res.Df RSS Df Sum of Sq F Pr(>F)
1 998 309.248
2 995 63.926 3 245.32 1272.8 < 2.2e-16 ***
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
Likewise, it is quite usual to compare GLM with GAM based on the results of a $\chi^2$-test.
|
Difference between Norm of Residuals and what is a "good" Norm of Residual
|
So, I would recommend using standard method for comparing nested models. In your case, you consider two alternative models, the cubic fit being the more "complex" one. An F- or $\chi^2$-test tells you
|
Difference between Norm of Residuals and what is a "good" Norm of Residual
So, I would recommend using standard method for comparing nested models. In your case, you consider two alternative models, the cubic fit being the more "complex" one. An F- or $\chi^2$-test tells you whether the residual sum of squares or deviance significantly decrease when you add further terms. It is very like comparing a model including only the intercept (in this case, you have residual variance only) vs. another one which include one meaningful predictor: does this added predictor account for a sufficient part of the variance in the response? In your case, it amounts to say: Modeling a cubic relationship between X and Y decreases the unexplained variance (equivalently, the $R^2$ will increase), and thus provide a better fit to the data compared to a linear fit.
It is often used as a test of linearity between the response variable and the predictor, and this is the reason why Frank Harrell advocates the use of restricted cubic spline instead of assuming a strict linear relationship between Y and the continuous Xs (e.g. age).
The following example comes from a book I was reading some months ago (High-dimensional data analysis in cancer research, Chap. 3, p. 45), but it may well serves as an illustration. The idea is just to fit different kind of models to a simulated data set, which clearly highlights a non-linear relationship between the response variable and the predictor. The true generative model is shown in black. The other colors are for different models (restricted cubic spline, B-spline close to yours, and CV smoothed spline).
library(rms)
library(splines)
set.seed(101)
f <- function(x) sin(sqrt(2*pi*x))
n <- 1000
x <- runif(n, 0, 2*pi)
sigma <- rnorm(n, 0, 0.25)
y <- f(x) + sigma
plot(x, y, cex=.4)
curve(f, 0, 6, lty=2, add=TRUE)
# linear fit
lm00 <- lm(y~x)
# restricted cubic spline, 3 knots (2 Df)
lm0 <- lm(y~rcs(x,3))
lines(seq(0,6,length=1000),
predict(lm0,data.frame(x=seq(0,6,length=1000))),
col="red")
# use B-spline and a single knot at x=1.13 (4 Df)
lm1 <- lm(y~bs(x, knots=1.13))
lines(seq(0,6,length=1000),
predict(lm1,data.frame(x=seq(0,6,length=1000))),
col="green")
# cross-validated smoothed spline (approx. 20 Df)
xy.spl <- smooth.spline(x, y, cv=TRUE)
lines(xy.spl, col="blue")
legend("bottomleft", c("f(x)","RCS {rms}","BS {splines}","SS {stats}"),
col=1:4, lty=c(2,rep(1,3)),bty="n", cex=.6)
Now, suppose you want to compare the linear fit (lm00) and model relying on B-spline (lm1), you just have to do an F-test to see that the latter provides a better fit:
> anova(lm00, lm1)
Analysis of Variance Table
Model 1: y ~ x
Model 2: y ~ bs(x, knots = 1.13)
Res.Df RSS Df Sum of Sq F Pr(>F)
1 998 309.248
2 995 63.926 3 245.32 1272.8 < 2.2e-16 ***
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
Likewise, it is quite usual to compare GLM with GAM based on the results of a $\chi^2$-test.
|
Difference between Norm of Residuals and what is a "good" Norm of Residual
So, I would recommend using standard method for comparing nested models. In your case, you consider two alternative models, the cubic fit being the more "complex" one. An F- or $\chi^2$-test tells you
|
39,837
|
How to explain such a big difference between parametric and non parametric test (and other questions)?
|
Because the null hypothesis your McNemar test tests, is not the same as the one tested by the $\chi^2$ test. The McNemar test actually tests whether the probability of 1-2 equals that of 2-1 (say first number is the row and second the column). If you switch columns, then you get a completely different outcome. The $\chi^2$ test just tests whether the frequencies can be calculated from the marginal frequencies, which means both categorical variables are independent.
To illustrate in R :
> x <- matrix(c(39,49,9,19),ncol=2)
> y <-x[,2:1]
> x
[,1] [,2]
[1,] 39 9
[2,] 49 19
> y
[,1] [,2]
[1,] 9 39
[2,] 19 49
> mcnemar.test(x)
McNemar's Chi-squared test with continuity correction
data: x
McNemar's chi-squared = 26.2241, df = 1, p-value = 3.04e-07
> mcnemar.test(y)
McNemar's Chi-squared test with continuity correction
data: y
McNemar's chi-squared = 6.2241, df = 1, p-value = 0.01260
> chisq.test(x)
Pearson's Chi-squared test with Yates' continuity correction
data: x
X-squared = 0.8447, df = 1, p-value = 0.3581
> chisq.test(y)
Pearson's Chi-squared test with Yates' continuity correction
data: y
X-squared = 0.8447, df = 1, p-value = 0.3581
It is obvious the result of the McNemar test is completely different depending on which column comes first, whereas the $\chi^2$ test gives exactly the same outcome. Now why is this one non-significant? Well, take a look at the expected values :
> m1 <- margin.table(x,1)/116
> m2 <- margin.table(x,2)/116
> outer(m1,m2)*116
[,1] [,2]
[1,] 36.41379 11.58621
[2,] 51.58621 16.41379
Pretty close to the table you have.
So both tests are not disagreeing at all. The $\chi^2$ rightfully concludes that both variables are independent, i.e. the counts in one variable are not influenced by the other and vice versa, and the McNemar test rightfully concludes that the probability of being first row-second column (0.07) is not the same as being second row-first column (0.42).
|
How to explain such a big difference between parametric and non parametric test (and other questions
|
Because the null hypothesis your McNemar test tests, is not the same as the one tested by the $\chi^2$ test. The McNemar test actually tests whether the probability of 1-2 equals that of 2-1 (say firs
|
How to explain such a big difference between parametric and non parametric test (and other questions)?
Because the null hypothesis your McNemar test tests, is not the same as the one tested by the $\chi^2$ test. The McNemar test actually tests whether the probability of 1-2 equals that of 2-1 (say first number is the row and second the column). If you switch columns, then you get a completely different outcome. The $\chi^2$ test just tests whether the frequencies can be calculated from the marginal frequencies, which means both categorical variables are independent.
To illustrate in R :
> x <- matrix(c(39,49,9,19),ncol=2)
> y <-x[,2:1]
> x
[,1] [,2]
[1,] 39 9
[2,] 49 19
> y
[,1] [,2]
[1,] 9 39
[2,] 19 49
> mcnemar.test(x)
McNemar's Chi-squared test with continuity correction
data: x
McNemar's chi-squared = 26.2241, df = 1, p-value = 3.04e-07
> mcnemar.test(y)
McNemar's Chi-squared test with continuity correction
data: y
McNemar's chi-squared = 6.2241, df = 1, p-value = 0.01260
> chisq.test(x)
Pearson's Chi-squared test with Yates' continuity correction
data: x
X-squared = 0.8447, df = 1, p-value = 0.3581
> chisq.test(y)
Pearson's Chi-squared test with Yates' continuity correction
data: y
X-squared = 0.8447, df = 1, p-value = 0.3581
It is obvious the result of the McNemar test is completely different depending on which column comes first, whereas the $\chi^2$ test gives exactly the same outcome. Now why is this one non-significant? Well, take a look at the expected values :
> m1 <- margin.table(x,1)/116
> m2 <- margin.table(x,2)/116
> outer(m1,m2)*116
[,1] [,2]
[1,] 36.41379 11.58621
[2,] 51.58621 16.41379
Pretty close to the table you have.
So both tests are not disagreeing at all. The $\chi^2$ rightfully concludes that both variables are independent, i.e. the counts in one variable are not influenced by the other and vice versa, and the McNemar test rightfully concludes that the probability of being first row-second column (0.07) is not the same as being second row-first column (0.42).
|
How to explain such a big difference between parametric and non parametric test (and other questions
Because the null hypothesis your McNemar test tests, is not the same as the one tested by the $\chi^2$ test. The McNemar test actually tests whether the probability of 1-2 equals that of 2-1 (say firs
|
39,838
|
Asymptotic power
|
The definition above (a fixed alternative, sample size going to infinity) is more precisely related to the consistency (or not) of a hypothesis test. That is, a test is consistent against a fixed alternative if the power function approaches 1 at that alternative.
Asymptotic power is something different. As Joris remarked, with asymptotic power the alternatives $\theta_n$ are changing, are converging to the null value $\theta_0$ (on the order of $\sqrt n$, say) while the sample size marches to infinity.
Under some regularity conditions (for example, the test statistic has a monotone likelihood ratio, is asymptotically normal, has asymptotic variance $\tau$ continuous in $\theta$, yada yada yada) if $\sqrt n(\theta_n - \theta_0)$ goes to $\delta$ then the power function goes to $\Phi(\delta/\tau - z_\alpha)$, where $\Phi$ is the standard normal CDF. This last quantity is called the asymptotic power of just such a test.
See Lehmann's $\underline{\mbox{Elements of Large Sample Theory}}$ for discussion and worked out examples.
By the way, yes, the majority of classical tests are consistent.
|
Asymptotic power
|
The definition above (a fixed alternative, sample size going to infinity) is more precisely related to the consistency (or not) of a hypothesis test. That is, a test is consistent against a fixed alt
|
Asymptotic power
The definition above (a fixed alternative, sample size going to infinity) is more precisely related to the consistency (or not) of a hypothesis test. That is, a test is consistent against a fixed alternative if the power function approaches 1 at that alternative.
Asymptotic power is something different. As Joris remarked, with asymptotic power the alternatives $\theta_n$ are changing, are converging to the null value $\theta_0$ (on the order of $\sqrt n$, say) while the sample size marches to infinity.
Under some regularity conditions (for example, the test statistic has a monotone likelihood ratio, is asymptotically normal, has asymptotic variance $\tau$ continuous in $\theta$, yada yada yada) if $\sqrt n(\theta_n - \theta_0)$ goes to $\delta$ then the power function goes to $\Phi(\delta/\tau - z_\alpha)$, where $\Phi$ is the standard normal CDF. This last quantity is called the asymptotic power of just such a test.
See Lehmann's $\underline{\mbox{Elements of Large Sample Theory}}$ for discussion and worked out examples.
By the way, yes, the majority of classical tests are consistent.
|
Asymptotic power
The definition above (a fixed alternative, sample size going to infinity) is more precisely related to the consistency (or not) of a hypothesis test. That is, a test is consistent against a fixed alt
|
39,839
|
Asymptotic power
|
As I understood it, the asymptotic power is the hypothetical power when the effect size goes to zero and the sample size to infinity. Basically it should be 0 or 1, indicating whether the test cannot or can distinguish an arbitrary small deviation from the null hypothesis when the sample size is sufficiently large.
|
Asymptotic power
|
As I understood it, the asymptotic power is the hypothetical power when the effect size goes to zero and the sample size to infinity. Basically it should be 0 or 1, indicating whether the test cannot
|
Asymptotic power
As I understood it, the asymptotic power is the hypothetical power when the effect size goes to zero and the sample size to infinity. Basically it should be 0 or 1, indicating whether the test cannot or can distinguish an arbitrary small deviation from the null hypothesis when the sample size is sufficiently large.
|
Asymptotic power
As I understood it, the asymptotic power is the hypothetical power when the effect size goes to zero and the sample size to infinity. Basically it should be 0 or 1, indicating whether the test cannot
|
39,840
|
Asymptotic power
|
Yes, you are right. I would only replace "there exists a sample size n that the selected test would reject the null hypothesis" with "for every e>0 there exists a sample size n_0 such that the probability to reject the null hypothesis is greater than 1-e for all n>n_0".
|
Asymptotic power
|
Yes, you are right. I would only replace "there exists a sample size n that the selected test would reject the null hypothesis" with "for every e>0 there exists a sample size n_0 such that the probabi
|
Asymptotic power
Yes, you are right. I would only replace "there exists a sample size n that the selected test would reject the null hypothesis" with "for every e>0 there exists a sample size n_0 such that the probability to reject the null hypothesis is greater than 1-e for all n>n_0".
|
Asymptotic power
Yes, you are right. I would only replace "there exists a sample size n that the selected test would reject the null hypothesis" with "for every e>0 there exists a sample size n_0 such that the probabi
|
39,841
|
Why does AIC formula in R appear to use one extra parameter than expected?
|
> -2*logLik(fit)+2*(length(fit$coef)+1)
[1] 3332.282
(you forgot; you have 6 parameter because $\sigma_{\epsilon}$ also has to be estimated!
|
Why does AIC formula in R appear to use one extra parameter than expected?
|
> -2*logLik(fit)+2*(length(fit$coef)+1)
[1] 3332.282
(you forgot; you have 6 parameter because $\sigma_{\epsilon}$ also has to be estimated!
|
Why does AIC formula in R appear to use one extra parameter than expected?
> -2*logLik(fit)+2*(length(fit$coef)+1)
[1] 3332.282
(you forgot; you have 6 parameter because $\sigma_{\epsilon}$ also has to be estimated!
|
Why does AIC formula in R appear to use one extra parameter than expected?
> -2*logLik(fit)+2*(length(fit$coef)+1)
[1] 3332.282
(you forgot; you have 6 parameter because $\sigma_{\epsilon}$ also has to be estimated!
|
39,842
|
Working through a clustering problem
|
You can try Latent Semantic Analysis, which basically provides a way to represent in a reduced space your news feeds and any term (in your case, keyword appearing in the title). As it relies on Singular Value Decomposition, I suppose you may then be able to check if there exists a particular association between those two attributes. I know this is used to find documents matching a specific set of criteria, as in information retrieval, or to construct a tree reflecting terms similarity (like a dictionary) based on a large corpus (which here plays the role of the concept space).
See for a gentle introduction An Introduction to Latent Semantic Analysis, by Landauer et al.
Moreover, there is an R package that implements this technique, namely lsa.
|
Working through a clustering problem
|
You can try Latent Semantic Analysis, which basically provides a way to represent in a reduced space your news feeds and any term (in your case, keyword appearing in the title). As it relies on Singul
|
Working through a clustering problem
You can try Latent Semantic Analysis, which basically provides a way to represent in a reduced space your news feeds and any term (in your case, keyword appearing in the title). As it relies on Singular Value Decomposition, I suppose you may then be able to check if there exists a particular association between those two attributes. I know this is used to find documents matching a specific set of criteria, as in information retrieval, or to construct a tree reflecting terms similarity (like a dictionary) based on a large corpus (which here plays the role of the concept space).
See for a gentle introduction An Introduction to Latent Semantic Analysis, by Landauer et al.
Moreover, there is an R package that implements this technique, namely lsa.
|
Working through a clustering problem
You can try Latent Semantic Analysis, which basically provides a way to represent in a reduced space your news feeds and any term (in your case, keyword appearing in the title). As it relies on Singul
|
39,843
|
Working through a clustering problem
|
The traditional solution to this problem is to use the vector representation for the news stories and then cluster the vectors. The vectors are arrays where each entry represents a word or word class. The value associated to each word will be the tf-idf weight. This value goes up the more frequent the word in the document and down the more frequent the word is in the whole collection of documents.
You may think of the titles as the documents, but sticking to just the title for news stories may be a bit risky for clustering similar stories. The problem is that by using word counts you are discarding all information on the order of the words. Longer texts compensate for that loss information by distinguishing documents by the vocabulary used (articles mentioning finance, money, ... are closer to each other than those mentioning ergodic, Poincare).
If you want to stick to titles, one idea is to think of word pairs as the words you use in the vector representation. So for the title The eagle has landed, you would think of the eagle, eagle has, has landed. as the “words.”
To discover when a cluster has become much bigger or different from the others you will need to develop a decision procedure.
|
Working through a clustering problem
|
The traditional solution to this problem is to use the vector representation for the news stories and then cluster the vectors. The vectors are arrays where each entry represents a word or word class
|
Working through a clustering problem
The traditional solution to this problem is to use the vector representation for the news stories and then cluster the vectors. The vectors are arrays where each entry represents a word or word class. The value associated to each word will be the tf-idf weight. This value goes up the more frequent the word in the document and down the more frequent the word is in the whole collection of documents.
You may think of the titles as the documents, but sticking to just the title for news stories may be a bit risky for clustering similar stories. The problem is that by using word counts you are discarding all information on the order of the words. Longer texts compensate for that loss information by distinguishing documents by the vocabulary used (articles mentioning finance, money, ... are closer to each other than those mentioning ergodic, Poincare).
If you want to stick to titles, one idea is to think of word pairs as the words you use in the vector representation. So for the title The eagle has landed, you would think of the eagle, eagle has, has landed. as the “words.”
To discover when a cluster has become much bigger or different from the others you will need to develop a decision procedure.
|
Working through a clustering problem
The traditional solution to this problem is to use the vector representation for the news stories and then cluster the vectors. The vectors are arrays where each entry represents a word or word class
|
39,844
|
Working through a clustering problem
|
This problem you are asking about is known as text mining!
There are a few things you need to consider. For example in your question you mentioned using keywords in titles. One may ask "why not the text in the article rather than just the title?" which brings me to the first consideration: What data do you limit yourself to?
Secondly, as the previous answer suggests, using frequencies is a great start. To take the analysis further you may start looking at what words occur frequently together! For example, the word 'happy' may occur very frequently... however if always accompanied by a 'not' your conclusions would be very different!
There is a very nice Australian piece of software I have used in the past called Leximancer. I would advise anybody interested in text mining to have a look at their site and the examples they have... from memory one of which analysed speeches by 2 U.S. presidential candidates. It makes for some very interesting reading!
|
Working through a clustering problem
|
This problem you are asking about is known as text mining!
There are a few things you need to consider. For example in your question you mentioned using keywords in titles. One may ask "why not the te
|
Working through a clustering problem
This problem you are asking about is known as text mining!
There are a few things you need to consider. For example in your question you mentioned using keywords in titles. One may ask "why not the text in the article rather than just the title?" which brings me to the first consideration: What data do you limit yourself to?
Secondly, as the previous answer suggests, using frequencies is a great start. To take the analysis further you may start looking at what words occur frequently together! For example, the word 'happy' may occur very frequently... however if always accompanied by a 'not' your conclusions would be very different!
There is a very nice Australian piece of software I have used in the past called Leximancer. I would advise anybody interested in text mining to have a look at their site and the examples they have... from memory one of which analysed speeches by 2 U.S. presidential candidates. It makes for some very interesting reading!
|
Working through a clustering problem
This problem you are asking about is known as text mining!
There are a few things you need to consider. For example in your question you mentioned using keywords in titles. One may ask "why not the te
|
39,845
|
Working through a clustering problem
|
I would start with a frequency distribution. Collect for a big corpus the word-frequencies and select smartly the words that are keywords (not misspellings, with a very low frequency, and not stop words like "and", "or")
Then when you have a number of new feeds, compare their distribution with the distribution that you build from your training data. Look to the big differences in frequencies and select so the important keywords of that moment.
|
Working through a clustering problem
|
I would start with a frequency distribution. Collect for a big corpus the word-frequencies and select smartly the words that are keywords (not misspellings, with a very low frequency, and not stop wor
|
Working through a clustering problem
I would start with a frequency distribution. Collect for a big corpus the word-frequencies and select smartly the words that are keywords (not misspellings, with a very low frequency, and not stop words like "and", "or")
Then when you have a number of new feeds, compare their distribution with the distribution that you build from your training data. Look to the big differences in frequencies and select so the important keywords of that moment.
|
Working through a clustering problem
I would start with a frequency distribution. Collect for a big corpus the word-frequencies and select smartly the words that are keywords (not misspellings, with a very low frequency, and not stop wor
|
39,846
|
Let $X_1,\dots, X_n$ be random sample from $Bernoulli(p)$. Which estimator is better?
|
You have been given the MLE as well as the posterior mean under a Beta prior (see e.g. here).
As you write (in slightly different notation with $\theta=p$, $k=n\bar X$, $\alpha_0=\alpha$, $\hat \theta_1=\hat p_1$, $R=MSE$ etc.),
$$
\begin{align*}
R(\theta, \hat{\theta}_2) =& \, V_\theta (\hat{\theta}_2) + ({bias}_\theta (\hat{\theta}_2))^2 \\
=& \, V_\theta \left( \frac{k + \alpha_0}{\alpha_0 + \beta_0 + n} \right) + \left( E_\theta \left( \frac{k + \alpha_0}{\alpha_0 + \beta_0 + n} \right) - \theta \right)^2 \\
=& \, \frac{n\theta(1 - \theta)}{(\alpha_0 + \beta_0 + n)^2} + \left( \frac{n\theta + \alpha_0}{\alpha_0 + \beta_0 + n} - \theta \right)^2.
\end{align*}
$$
Which estimator then is "better" indeed depends on the prior parameters, sampls size as well as the true $\theta$. This is intuitive as a prior that puts lots of probability on regions of the parameter space where the true value happens to be can be expected to produce a good Bayesian estimator.
A well-known and interesting choice is to let $\alpha_0 = \beta_0 = \sqrt{0.25n}$. The resulting estimator is
$$
\hat{\theta}_2 = \, \frac{k + \sqrt{0.25n}}{n + \sqrt{n}}$$
Then, the risk function is independent of $\theta$:
$$
R(\theta,\hat{\theta}_2) = \, \frac{n}{4(n + \sqrt{n})^2},
$$
and you can easily find the region in which $\hat \theta_1$ is outperformed in terms of maximum risk, and that that region shrinks with $n$ (that it shrinks with $n$ is intuitive, the sample average being the asymptotically efficient MLE).
The prior is "well-known" because there is a theorem (which I think I have come across in a book by Wasserman, but surely is also available elsewhere) saying that if $\hat{\theta}$ is a Bayes rule (a decision rule that minimizes the Bayes risk, e.g. the integral over $\theta$ for the MSE for squared loss with respect to some prior) with respect to some prior $\pi$ and if $\hat{\theta}$ has a constant risk
\begin{align*}
R(\theta, \hat{\theta}) = c
\end{align*}
for some $c$, then $\hat{\theta}$ is minimax.
A rule is minimax if, in a class of estimators $\tilde{\theta}$, it minimizes the maximum risk.
Formally, $\hat{\theta}$ is minimax if
$$ \sup\limits_{\theta} R(\theta, \hat{\theta}) = \, \inf\limits_{\tilde{\theta}} \sup\limits_{\theta} R(\theta, \tilde{\theta}).$$
In this example,
$$
\begin{align*}
\sup\limits_{\theta} R(\theta, \hat{\theta}_1) =& \, \max\limits_{0 \leq \theta \leq 1} \frac{\theta(1-\theta)}{n} = \frac{1}{4n}
\end{align*}
$$
and
$$\begin{align*}
\sup\limits_{\theta} R(\theta, \hat{\theta}_2) =& \, \max\limits_{\theta} \frac{n}{4(n + \sqrt{n})^2} = \frac{n}{4(n + \sqrt{n})^2}
\end{align*}
$$
and we observe that
$$
\sup\limits_{\theta} R(\theta, \hat{\theta}_2)<\sup\limits_{\theta} R(\theta, \hat{\theta}_1)
$$
On the other hand, consider a uniform prior $\pi(\theta) = 1$. Then, the Bayes risks are
\begin{align*}
r(\pi, \hat{\theta}_1) =& \, \int R(\theta, \hat{\theta}_1) \, d\theta = \int \frac{\theta(1-\theta)}{n} \, d\theta = \frac{1}{6n}
\end{align*}
and
\begin{align*}
r(\pi, \hat{\theta}_2) =& \, \int R(\theta, \hat{\theta}_2) \, d\theta = \frac{n}{4(n + \sqrt{n})^2}.
\end{align*}
For $n \geq 20$, $r(\pi, \hat{\theta}_2) > r(\pi, \hat{\theta}_1)$ (in the figure below, only the red dots are above the red dahes, with the ranking reversed for the other $n$) which suggests that $\hat{\theta}_1$ is a better estimator according to this criterior and this prior.
Schematically:
n <- c(15, 25, 30, 100)
theta <- seq(0.001, 0.999, 0.001)
risk.MLE <- sapply(n, function(n) theta*(1-theta)/n)
risk.posteriormean <- n/(4*(n + sqrt(n))^2)
Bayesrisk.MLE. <- 1/(6*n)
matplot(theta, risk.MLE, type="l", col=c("red", "blue", "green", "orange"), lty=1, lwd=2)
abline(h=risk.posteriormean, lwd=2, col=c("red", "blue", "green", "orange"), lty=2) # long dashes for the (Bayes) risk of the posterior mean
abline(h=Bayesrisk.MLE., lwd=2, col=c("red", "blue", "green", "orange"), lty=3) # dots for Bayes risk of MLE
So to make a long answer short: it depends!
|
Let $X_1,\dots, X_n$ be random sample from $Bernoulli(p)$. Which estimator is better?
|
You have been given the MLE as well as the posterior mean under a Beta prior (see e.g. here).
As you write (in slightly different notation with $\theta=p$, $k=n\bar X$, $\alpha_0=\alpha$, $\hat \theta
|
Let $X_1,\dots, X_n$ be random sample from $Bernoulli(p)$. Which estimator is better?
You have been given the MLE as well as the posterior mean under a Beta prior (see e.g. here).
As you write (in slightly different notation with $\theta=p$, $k=n\bar X$, $\alpha_0=\alpha$, $\hat \theta_1=\hat p_1$, $R=MSE$ etc.),
$$
\begin{align*}
R(\theta, \hat{\theta}_2) =& \, V_\theta (\hat{\theta}_2) + ({bias}_\theta (\hat{\theta}_2))^2 \\
=& \, V_\theta \left( \frac{k + \alpha_0}{\alpha_0 + \beta_0 + n} \right) + \left( E_\theta \left( \frac{k + \alpha_0}{\alpha_0 + \beta_0 + n} \right) - \theta \right)^2 \\
=& \, \frac{n\theta(1 - \theta)}{(\alpha_0 + \beta_0 + n)^2} + \left( \frac{n\theta + \alpha_0}{\alpha_0 + \beta_0 + n} - \theta \right)^2.
\end{align*}
$$
Which estimator then is "better" indeed depends on the prior parameters, sampls size as well as the true $\theta$. This is intuitive as a prior that puts lots of probability on regions of the parameter space where the true value happens to be can be expected to produce a good Bayesian estimator.
A well-known and interesting choice is to let $\alpha_0 = \beta_0 = \sqrt{0.25n}$. The resulting estimator is
$$
\hat{\theta}_2 = \, \frac{k + \sqrt{0.25n}}{n + \sqrt{n}}$$
Then, the risk function is independent of $\theta$:
$$
R(\theta,\hat{\theta}_2) = \, \frac{n}{4(n + \sqrt{n})^2},
$$
and you can easily find the region in which $\hat \theta_1$ is outperformed in terms of maximum risk, and that that region shrinks with $n$ (that it shrinks with $n$ is intuitive, the sample average being the asymptotically efficient MLE).
The prior is "well-known" because there is a theorem (which I think I have come across in a book by Wasserman, but surely is also available elsewhere) saying that if $\hat{\theta}$ is a Bayes rule (a decision rule that minimizes the Bayes risk, e.g. the integral over $\theta$ for the MSE for squared loss with respect to some prior) with respect to some prior $\pi$ and if $\hat{\theta}$ has a constant risk
\begin{align*}
R(\theta, \hat{\theta}) = c
\end{align*}
for some $c$, then $\hat{\theta}$ is minimax.
A rule is minimax if, in a class of estimators $\tilde{\theta}$, it minimizes the maximum risk.
Formally, $\hat{\theta}$ is minimax if
$$ \sup\limits_{\theta} R(\theta, \hat{\theta}) = \, \inf\limits_{\tilde{\theta}} \sup\limits_{\theta} R(\theta, \tilde{\theta}).$$
In this example,
$$
\begin{align*}
\sup\limits_{\theta} R(\theta, \hat{\theta}_1) =& \, \max\limits_{0 \leq \theta \leq 1} \frac{\theta(1-\theta)}{n} = \frac{1}{4n}
\end{align*}
$$
and
$$\begin{align*}
\sup\limits_{\theta} R(\theta, \hat{\theta}_2) =& \, \max\limits_{\theta} \frac{n}{4(n + \sqrt{n})^2} = \frac{n}{4(n + \sqrt{n})^2}
\end{align*}
$$
and we observe that
$$
\sup\limits_{\theta} R(\theta, \hat{\theta}_2)<\sup\limits_{\theta} R(\theta, \hat{\theta}_1)
$$
On the other hand, consider a uniform prior $\pi(\theta) = 1$. Then, the Bayes risks are
\begin{align*}
r(\pi, \hat{\theta}_1) =& \, \int R(\theta, \hat{\theta}_1) \, d\theta = \int \frac{\theta(1-\theta)}{n} \, d\theta = \frac{1}{6n}
\end{align*}
and
\begin{align*}
r(\pi, \hat{\theta}_2) =& \, \int R(\theta, \hat{\theta}_2) \, d\theta = \frac{n}{4(n + \sqrt{n})^2}.
\end{align*}
For $n \geq 20$, $r(\pi, \hat{\theta}_2) > r(\pi, \hat{\theta}_1)$ (in the figure below, only the red dots are above the red dahes, with the ranking reversed for the other $n$) which suggests that $\hat{\theta}_1$ is a better estimator according to this criterior and this prior.
Schematically:
n <- c(15, 25, 30, 100)
theta <- seq(0.001, 0.999, 0.001)
risk.MLE <- sapply(n, function(n) theta*(1-theta)/n)
risk.posteriormean <- n/(4*(n + sqrt(n))^2)
Bayesrisk.MLE. <- 1/(6*n)
matplot(theta, risk.MLE, type="l", col=c("red", "blue", "green", "orange"), lty=1, lwd=2)
abline(h=risk.posteriormean, lwd=2, col=c("red", "blue", "green", "orange"), lty=2) # long dashes for the (Bayes) risk of the posterior mean
abline(h=Bayesrisk.MLE., lwd=2, col=c("red", "blue", "green", "orange"), lty=3) # dots for Bayes risk of MLE
So to make a long answer short: it depends!
|
Let $X_1,\dots, X_n$ be random sample from $Bernoulli(p)$. Which estimator is better?
You have been given the MLE as well as the posterior mean under a Beta prior (see e.g. here).
As you write (in slightly different notation with $\theta=p$, $k=n\bar X$, $\alpha_0=\alpha$, $\hat \theta
|
39,847
|
Interpreting zero odds ratio from Fisher's exact test
|
If in a 2-by-2 table, we let $n_{11}$ be the counts in (1,1) cell, $n_{12}$ the counts in the (1,2) cell, $n_{21}$ those of cell (2,1) cell and $n_{22}$ those of cell (2,2), then the sample odds ratio is defined by
$$
\hat\theta = \frac{n_{11}n_{22}}{n_{12}n_{21}}.
$$
If any of $n_{ij}$ is zero, then $\hat\theta$ equals 0 or $\infty$ (it is undefined if both entries in a row or in a column are zero). Because these outcomes have positive probability, then the expected value and variance of $\hat\theta$ are not defined. A better well-behaved estimator is
$$
\tilde\theta = \frac{(n_{11}+0.5)(n_{22}+0.5)}{(n_{12}+0.5)(n_{21}+0.5)}
$$
Both $\hat\theta$ and $\tilde\theta$ have the same asymptotic normal distribution around the true odds-ratio $\theta$. Unless the sample size is quite large, however, the distributions of both $\tilde\theta$ and $\hat\theta$ are highly skewed. The log transform, having an additive rather than multiplicative structure, converges more rapidly to normality. An estimated standard error for $\log\hat\theta$ is
$$
\hat{\rm{se}}(\log\hat\theta) = \left(\frac{1}{n_{11}}+\frac{1}{n_{12}}+\frac{1}{n_{21}}+\frac{1}{n_{22}}\right)^{1/2},
$$
and thus by the large sample normality of $\log\hat\theta$
$$
\log\hat\theta \pm z_{\alpha/2}\hat{\rm{se}}(\log\hat\theta).
$$
provides an approximate confidence interval for $\log\hat\theta$. The confidence interval for $\hat\theta$ can be obtained by exponentiating the limits of the above intervals. A similar interval can be obtained using $\tilde\theta$ in place of $\hat\theta$.
However, when $\hat\theta = 0$ or $\hat\theta = \infty$, this interval cannot be applied. When $\hat\theta = 0$, one should take 0 as the lower limit and when $\hat\theta = \infty$ one should take $\infty$ as the upper limit. For the other bound you can use the above formula following some adjustment, such as replacing $n_{ij}$ by $n_{ij}+0.5$ in the estimator and standard error. Other methods are also possible, such as methods based on score function or conditional maximum likelihood estimation.
As for the odd-ratio estimate provided by fisher.test, the help page (?fisher.test) says
estimate an estimate of the odds ratio. Note that the conditional
Maximum Likelihood Estimate (MLE) rather than the unconditional MLE
(the sample odds ratio) is used. Only present in the 2 x 2 case.
This means that the odd-ratio provided by fisher.test is derived through an alternative estimator (here conditional maximum likelihood, which is a kind of maximum likelihood estimator) which need not coincide with the sample odds ratio $\hat\theta$ or $\tilde\theta$.
Here is a simple example that supports this claim.
fisher.test(matrix(c(69,13,33,23), ncol=2))
Fisher's Exact Test for Count Data
data: matrix(c(69, 13, 33, 23), ncol = 2)
p-value = 0.001425
alternative hypothesis: true odds ratio is not equal to 1
95 percent confidence interval:
1.556881 8.947718
sample estimates:
odds ratio
3.66139
# sample odds-ratio estimate
> 69*23/(13*33)
[1] 3.699301
As you can see, the two estimates are not exactly the same although they are pretty close.
If you want to dive deeper into this subject I suggest having a look at Agresti's Categorical Data Analysis book.
|
Interpreting zero odds ratio from Fisher's exact test
|
If in a 2-by-2 table, we let $n_{11}$ be the counts in (1,1) cell, $n_{12}$ the counts in the (1,2) cell, $n_{21}$ those of cell (2,1) cell and $n_{22}$ those of cell (2,2), then the sample odds ratio
|
Interpreting zero odds ratio from Fisher's exact test
If in a 2-by-2 table, we let $n_{11}$ be the counts in (1,1) cell, $n_{12}$ the counts in the (1,2) cell, $n_{21}$ those of cell (2,1) cell and $n_{22}$ those of cell (2,2), then the sample odds ratio is defined by
$$
\hat\theta = \frac{n_{11}n_{22}}{n_{12}n_{21}}.
$$
If any of $n_{ij}$ is zero, then $\hat\theta$ equals 0 or $\infty$ (it is undefined if both entries in a row or in a column are zero). Because these outcomes have positive probability, then the expected value and variance of $\hat\theta$ are not defined. A better well-behaved estimator is
$$
\tilde\theta = \frac{(n_{11}+0.5)(n_{22}+0.5)}{(n_{12}+0.5)(n_{21}+0.5)}
$$
Both $\hat\theta$ and $\tilde\theta$ have the same asymptotic normal distribution around the true odds-ratio $\theta$. Unless the sample size is quite large, however, the distributions of both $\tilde\theta$ and $\hat\theta$ are highly skewed. The log transform, having an additive rather than multiplicative structure, converges more rapidly to normality. An estimated standard error for $\log\hat\theta$ is
$$
\hat{\rm{se}}(\log\hat\theta) = \left(\frac{1}{n_{11}}+\frac{1}{n_{12}}+\frac{1}{n_{21}}+\frac{1}{n_{22}}\right)^{1/2},
$$
and thus by the large sample normality of $\log\hat\theta$
$$
\log\hat\theta \pm z_{\alpha/2}\hat{\rm{se}}(\log\hat\theta).
$$
provides an approximate confidence interval for $\log\hat\theta$. The confidence interval for $\hat\theta$ can be obtained by exponentiating the limits of the above intervals. A similar interval can be obtained using $\tilde\theta$ in place of $\hat\theta$.
However, when $\hat\theta = 0$ or $\hat\theta = \infty$, this interval cannot be applied. When $\hat\theta = 0$, one should take 0 as the lower limit and when $\hat\theta = \infty$ one should take $\infty$ as the upper limit. For the other bound you can use the above formula following some adjustment, such as replacing $n_{ij}$ by $n_{ij}+0.5$ in the estimator and standard error. Other methods are also possible, such as methods based on score function or conditional maximum likelihood estimation.
As for the odd-ratio estimate provided by fisher.test, the help page (?fisher.test) says
estimate an estimate of the odds ratio. Note that the conditional
Maximum Likelihood Estimate (MLE) rather than the unconditional MLE
(the sample odds ratio) is used. Only present in the 2 x 2 case.
This means that the odd-ratio provided by fisher.test is derived through an alternative estimator (here conditional maximum likelihood, which is a kind of maximum likelihood estimator) which need not coincide with the sample odds ratio $\hat\theta$ or $\tilde\theta$.
Here is a simple example that supports this claim.
fisher.test(matrix(c(69,13,33,23), ncol=2))
Fisher's Exact Test for Count Data
data: matrix(c(69, 13, 33, 23), ncol = 2)
p-value = 0.001425
alternative hypothesis: true odds ratio is not equal to 1
95 percent confidence interval:
1.556881 8.947718
sample estimates:
odds ratio
3.66139
# sample odds-ratio estimate
> 69*23/(13*33)
[1] 3.699301
As you can see, the two estimates are not exactly the same although they are pretty close.
If you want to dive deeper into this subject I suggest having a look at Agresti's Categorical Data Analysis book.
|
Interpreting zero odds ratio from Fisher's exact test
If in a 2-by-2 table, we let $n_{11}$ be the counts in (1,1) cell, $n_{12}$ the counts in the (1,2) cell, $n_{21}$ those of cell (2,1) cell and $n_{22}$ those of cell (2,2), then the sample odds ratio
|
39,848
|
Why are generalized additive models (GAMs) so popular in ecology?
|
TL;DR: GAMs are useful models when specific functional relationships are not hypothesized.
Ecology as a science (and like many other sciences, particularly population sciences) often has hypotheses for its statistical models which do not take specific functional forms. For example, causal relationships may be specified qualitatively in terms of direction of effect (e.g., ‘species $A$ causes a decrease in species $B$ in some trophic system,’ but perhaps not ‘$A$ causes some specified $f(B,\Theta)$’ in the way that we often encounter in physics or chemistry). GAMs are an appealing kind of model in such circumstances, because they are agnostic to the functional form relating $A$ and $B$.
|
Why are generalized additive models (GAMs) so popular in ecology?
|
TL;DR: GAMs are useful models when specific functional relationships are not hypothesized.
Ecology as a science (and like many other sciences, particularly population sciences) often has hypotheses fo
|
Why are generalized additive models (GAMs) so popular in ecology?
TL;DR: GAMs are useful models when specific functional relationships are not hypothesized.
Ecology as a science (and like many other sciences, particularly population sciences) often has hypotheses for its statistical models which do not take specific functional forms. For example, causal relationships may be specified qualitatively in terms of direction of effect (e.g., ‘species $A$ causes a decrease in species $B$ in some trophic system,’ but perhaps not ‘$A$ causes some specified $f(B,\Theta)$’ in the way that we often encounter in physics or chemistry). GAMs are an appealing kind of model in such circumstances, because they are agnostic to the functional form relating $A$ and $B$.
|
Why are generalized additive models (GAMs) so popular in ecology?
TL;DR: GAMs are useful models when specific functional relationships are not hypothesized.
Ecology as a science (and like many other sciences, particularly population sciences) often has hypotheses fo
|
39,849
|
Pearl, Causal Inference in Statistics Q3.5.1 (Backdoor criterion)
|
No you were right to begin with, you can control for any variable along the back door path so long as it doesn’t open up new such paths.
You can try it for yourself for the specific diagram here (set Z to adjusted and some other one to see only the causal path remain colored): http://dagitty.net/dags.html?id=331
|
Pearl, Causal Inference in Statistics Q3.5.1 (Backdoor criterion)
|
No you were right to begin with, you can control for any variable along the back door path so long as it doesn’t open up new such paths.
You can try it for yourself for the specific diagram here (set
|
Pearl, Causal Inference in Statistics Q3.5.1 (Backdoor criterion)
No you were right to begin with, you can control for any variable along the back door path so long as it doesn’t open up new such paths.
You can try it for yourself for the specific diagram here (set Z to adjusted and some other one to see only the causal path remain colored): http://dagitty.net/dags.html?id=331
|
Pearl, Causal Inference in Statistics Q3.5.1 (Backdoor criterion)
No you were right to begin with, you can control for any variable along the back door path so long as it doesn’t open up new such paths.
You can try it for yourself for the specific diagram here (set
|
39,850
|
Sample size recommended for a chi-square test for the variance
|
If you are using a chi-squared test of $H_0: \sigma^2 = 64$ against
$H_a: \sigma^2 > 64,$ then the sample size required depends on how much
greater than $64$ is important to you. Let's say you want have
probability $.90$ of detecting if the actual variance is $\sigma^2 = 100$ or more.
That is, you want the 'power' of the test to be 90%. Is $n = 100$ observations enough?
Because $Q = \frac{(n-1)S^2}{\sigma^2} \sim \mathsf{Chisq}(\nu = n-1),$ we have
use reject $H_0$ at the 5% level if $\frac{(n-1)S^2}{64} > c = 123.23$, where the critical value $c = 123.23$ cuts probability $0.05$ from the upper tail of $\mathsf{Chisq}(99).$
qchisq(.95, 99)
[1] 123.2252
Let's try a couple of normal samples of size $n = 100$ from populations with
$\sigma^2 = 64$ to see what happens. [The value of the mean is irrelevant; I used 200.] Mostly, the values of the test statistic $Q$ are below $c=123,2252$ (as shown), but occasionally (not shown) the result exceeds $c,$ which should happen in 5% of the cases.
set.seed(1234)
x = rnorm(100, 200, sqrt(64))
99*var(x)/64
[1] 99.87417
x = rnorm(100, 200, sqrt(64))
99*var(x)/64
[1] 105.4757
By contrast, if $\sigma^2 = 100,$ then we should get $Q > c$ in most of the
cases:
set.seed(1235)
x = rnorm(100, 200, sqrt(100))
99*var(x)/64
[1] 170.5568
x = rnorm(100, 200, sqrt(100))
99*var(x)/64
[1] 185.5564
x = rnorm(100, 200, sqrt(100))
99*var(x)/64
[1] 155.7088
A simulation with a million samples of size $n=100$ shows that the power is
above 90% $(0.9327 \pm 0.0005).$ So $n=100$ is enough.
set.seed(2021)
q.a = replicate( 10^6, 99*var(rnorm(100,200,sqrt(100))) /64 )
mean(q.a > c)
[1] 0.93268
2*sd(q.a > c)/1000
[1] 0.000501151
Notes: (1) Many statistical software programs include a 'power and sample size' procedure for such tests. And there are some online calculators (which I have not vetted). (2) There is a standard formula for a 95% confidence interval for $\sigma^2;$ you might use that to make an initial guess what $n$ is needed. (3) Also, simulation is not really required for power. Maybe you can use what I have
shown to find a direct computation in R for the power.
|
Sample size recommended for a chi-square test for the variance
|
If you are using a chi-squared test of $H_0: \sigma^2 = 64$ against
$H_a: \sigma^2 > 64,$ then the sample size required depends on how much
greater than $64$ is important to you. Let's say you want ha
|
Sample size recommended for a chi-square test for the variance
If you are using a chi-squared test of $H_0: \sigma^2 = 64$ against
$H_a: \sigma^2 > 64,$ then the sample size required depends on how much
greater than $64$ is important to you. Let's say you want have
probability $.90$ of detecting if the actual variance is $\sigma^2 = 100$ or more.
That is, you want the 'power' of the test to be 90%. Is $n = 100$ observations enough?
Because $Q = \frac{(n-1)S^2}{\sigma^2} \sim \mathsf{Chisq}(\nu = n-1),$ we have
use reject $H_0$ at the 5% level if $\frac{(n-1)S^2}{64} > c = 123.23$, where the critical value $c = 123.23$ cuts probability $0.05$ from the upper tail of $\mathsf{Chisq}(99).$
qchisq(.95, 99)
[1] 123.2252
Let's try a couple of normal samples of size $n = 100$ from populations with
$\sigma^2 = 64$ to see what happens. [The value of the mean is irrelevant; I used 200.] Mostly, the values of the test statistic $Q$ are below $c=123,2252$ (as shown), but occasionally (not shown) the result exceeds $c,$ which should happen in 5% of the cases.
set.seed(1234)
x = rnorm(100, 200, sqrt(64))
99*var(x)/64
[1] 99.87417
x = rnorm(100, 200, sqrt(64))
99*var(x)/64
[1] 105.4757
By contrast, if $\sigma^2 = 100,$ then we should get $Q > c$ in most of the
cases:
set.seed(1235)
x = rnorm(100, 200, sqrt(100))
99*var(x)/64
[1] 170.5568
x = rnorm(100, 200, sqrt(100))
99*var(x)/64
[1] 185.5564
x = rnorm(100, 200, sqrt(100))
99*var(x)/64
[1] 155.7088
A simulation with a million samples of size $n=100$ shows that the power is
above 90% $(0.9327 \pm 0.0005).$ So $n=100$ is enough.
set.seed(2021)
q.a = replicate( 10^6, 99*var(rnorm(100,200,sqrt(100))) /64 )
mean(q.a > c)
[1] 0.93268
2*sd(q.a > c)/1000
[1] 0.000501151
Notes: (1) Many statistical software programs include a 'power and sample size' procedure for such tests. And there are some online calculators (which I have not vetted). (2) There is a standard formula for a 95% confidence interval for $\sigma^2;$ you might use that to make an initial guess what $n$ is needed. (3) Also, simulation is not really required for power. Maybe you can use what I have
shown to find a direct computation in R for the power.
|
Sample size recommended for a chi-square test for the variance
If you are using a chi-squared test of $H_0: \sigma^2 = 64$ against
$H_a: \sigma^2 > 64,$ then the sample size required depends on how much
greater than $64$ is important to you. Let's say you want ha
|
39,851
|
Sample size recommended for a chi-square test for the variance
|
The test "works as advertized" even for very small sample sizes but is pretty sensitive to the assumption of normality (e.g. it is generally sensitive to changes in kurtosis).
It is notably more level-sensitive than a t-test is to the assumption of normality, and in this case large samples will not tend to mitigate the problem.
As such, many people tend to avoid normal-based tests of variance (chi-squared and particularly F).
Even if you do have near normality, your big worry with small sample sizes (as always) will generally be with power (when the assumptions hold or nearly so, the test works in the sense that it does what it says on the box -- tests the hypothesis at the chosen significance level -- but may nevertheless still have poor power).
If you are confident that you will have a near-normal population distribution (don't use a test of your data to decide this), and you do have a specific effect size you want to detect, and a specific power you want at that effect size and a specific significance level, you can calculate sample size via a calculation involving the noncentral chi-squared distribution. Or simulation can be used (indeed, simulation has some advantages in that you can easily investigate the impact of different circumstances from the assumptions).
If your sample sizes were large (which it doesn't sound like), you might consider bootstrap testing, perhaps.
|
Sample size recommended for a chi-square test for the variance
|
The test "works as advertized" even for very small sample sizes but is pretty sensitive to the assumption of normality (e.g. it is generally sensitive to changes in kurtosis).
It is notably more level
|
Sample size recommended for a chi-square test for the variance
The test "works as advertized" even for very small sample sizes but is pretty sensitive to the assumption of normality (e.g. it is generally sensitive to changes in kurtosis).
It is notably more level-sensitive than a t-test is to the assumption of normality, and in this case large samples will not tend to mitigate the problem.
As such, many people tend to avoid normal-based tests of variance (chi-squared and particularly F).
Even if you do have near normality, your big worry with small sample sizes (as always) will generally be with power (when the assumptions hold or nearly so, the test works in the sense that it does what it says on the box -- tests the hypothesis at the chosen significance level -- but may nevertheless still have poor power).
If you are confident that you will have a near-normal population distribution (don't use a test of your data to decide this), and you do have a specific effect size you want to detect, and a specific power you want at that effect size and a specific significance level, you can calculate sample size via a calculation involving the noncentral chi-squared distribution. Or simulation can be used (indeed, simulation has some advantages in that you can easily investigate the impact of different circumstances from the assumptions).
If your sample sizes were large (which it doesn't sound like), you might consider bootstrap testing, perhaps.
|
Sample size recommended for a chi-square test for the variance
The test "works as advertized" even for very small sample sizes but is pretty sensitive to the assumption of normality (e.g. it is generally sensitive to changes in kurtosis).
It is notably more level
|
39,852
|
What is the meaning of isotropic gaussian blobs , which are generated by sklearn.datasets.makeblobs?
|
The make_blobs() function draws samples from a special Gaussian mixture model. A general Gaussian mixture model with $k$ clusters has a density of the form
$$
p(x) = \sum_{i=1}^k \pi_i \mathcal{N}(\mu_i, \Sigma_i)
$$
where $\pi_i \ge 0$ are the weights of each cluster with $\sum_{i=1}^k \pi_i = 1$, $\mu_i$ are the cluster centers, and $\Sigma_i$ are the cluster covariances. Here $\mathcal{N}(\mu_i, \Sigma_i)$ refers to the normal Gaussian density with mean $\mu_i$ and covariance $\Sigma_i$.
In particular, for the make_blobs() function, each cluster or component has equal probability of being sampled $\pi_i = 1/k$ and the cluster centers can be either specified or in the case of your code randomly generated by setting centers = 2. Isotropic refers to the fact that the covariance matrices will all be diagonal
$$
\Sigma_i = \begin{bmatrix}
\sigma_i^2 & 0 \\
0 & \sigma_i^2
\end{bmatrix}
$$
with $\sigma_i$ being the standard deviation that is passed in. By default, all clusters will have the same standard deviation. A Gaussian mixture model is not Gaussian unless there is only one cluster, which is why your plots don't look Gaussian, but rather a combination of Gaussians.
|
What is the meaning of isotropic gaussian blobs , which are generated by sklearn.datasets.makeblobs?
|
The make_blobs() function draws samples from a special Gaussian mixture model. A general Gaussian mixture model with $k$ clusters has a density of the form
$$
p(x) = \sum_{i=1}^k \pi_i \mathcal{N}(\m
|
What is the meaning of isotropic gaussian blobs , which are generated by sklearn.datasets.makeblobs?
The make_blobs() function draws samples from a special Gaussian mixture model. A general Gaussian mixture model with $k$ clusters has a density of the form
$$
p(x) = \sum_{i=1}^k \pi_i \mathcal{N}(\mu_i, \Sigma_i)
$$
where $\pi_i \ge 0$ are the weights of each cluster with $\sum_{i=1}^k \pi_i = 1$, $\mu_i$ are the cluster centers, and $\Sigma_i$ are the cluster covariances. Here $\mathcal{N}(\mu_i, \Sigma_i)$ refers to the normal Gaussian density with mean $\mu_i$ and covariance $\Sigma_i$.
In particular, for the make_blobs() function, each cluster or component has equal probability of being sampled $\pi_i = 1/k$ and the cluster centers can be either specified or in the case of your code randomly generated by setting centers = 2. Isotropic refers to the fact that the covariance matrices will all be diagonal
$$
\Sigma_i = \begin{bmatrix}
\sigma_i^2 & 0 \\
0 & \sigma_i^2
\end{bmatrix}
$$
with $\sigma_i$ being the standard deviation that is passed in. By default, all clusters will have the same standard deviation. A Gaussian mixture model is not Gaussian unless there is only one cluster, which is why your plots don't look Gaussian, but rather a combination of Gaussians.
|
What is the meaning of isotropic gaussian blobs , which are generated by sklearn.datasets.makeblobs?
The make_blobs() function draws samples from a special Gaussian mixture model. A general Gaussian mixture model with $k$ clusters has a density of the form
$$
p(x) = \sum_{i=1}^k \pi_i \mathcal{N}(\m
|
39,853
|
What is the meaning of isotropic gaussian blobs , which are generated by sklearn.datasets.makeblobs?
|
Thanks Talsup, for giving the nice explanation. I am sharing the things in the nutshell.
The code snippet for understanding the make_blobs() is here. make_blobs_notebook
|
What is the meaning of isotropic gaussian blobs , which are generated by sklearn.datasets.makeblobs?
|
Thanks Talsup, for giving the nice explanation. I am sharing the things in the nutshell.
The code snippet for understanding the make_blobs() is here. make_blobs_notebook
|
What is the meaning of isotropic gaussian blobs , which are generated by sklearn.datasets.makeblobs?
Thanks Talsup, for giving the nice explanation. I am sharing the things in the nutshell.
The code snippet for understanding the make_blobs() is here. make_blobs_notebook
|
What is the meaning of isotropic gaussian blobs , which are generated by sklearn.datasets.makeblobs?
Thanks Talsup, for giving the nice explanation. I am sharing the things in the nutshell.
The code snippet for understanding the make_blobs() is here. make_blobs_notebook
|
39,854
|
Negative Binomial as Gamma-Poisson Mixture or Compound Logarithmic Poisson: can this correspondence be generalized to other distributions?
|
Let
$$
M_\theta(z)=E e^{z\theta}
$$
denote the moment generating function of $\theta$. Since $X|\theta\sim \operatorname{Poisson}(\theta)$, the probability generating function (pgf) of $X|\theta$ is
$$
G_{X|\theta}(z)=Ez^X|\theta = e^{\theta(z-1)}.
$$
Hence, using the law of total expectation, the pgf of $X$ is
$$
G_X(z)=Ez^X=E(Ez^X|\theta)=Ee^{\theta(z-1)} =M_\theta(z-1). \tag{1}
$$
If, at the same time,
$$
X = \sum_{i=1}^N Y_i
$$
where the $Y_i$'s are iid with pgf $G_Y(z)$ and $N \sim \operatorname{Poisson}(\lambda)$ such that the pgf of $N$ is $
G_N(z)=e^{\lambda(t-1)}$,
then the pgf of $X$ must also be equal to
\begin{align}
G_X(z)
&=Ez^X
\\&=E E(z^X|N)
\\&=E E(z^{Y_1+Y_2+\dots+Y_N}|N)
\\&=E (G_Y(z)^N|N)
\\&=G_N(G_Y(z)). \tag{2}
\end{align}
Hence, the pgf of the iid $Y_i$'s given $M_\theta(z)$ is
$$
G_Y(z)=G_N^{-1}(G_X(z))=\frac1\lambda(\ln G_X(z) + 1)=\frac1\lambda(\ln M_\theta(z-1) + 1). \tag{3}
$$
from which the probability mass function $P(Y=k)=G_Y^{(k)}(0)/k!$, $k=0,1,2,\dots$ can be computed.
Of course, if any of the point masses are negative, $X$ can not be represented simultaneously both as a Poisson mixture and as a compound Poisson distribution.
Example 1: Suppose that $\theta \sim \operatorname{Bern}(1/2)$ such that $M_\theta(z)=\frac{1+e^z}2$. Note that this means that $X$ has a zero-inflated Poisson distribution. Using (3) and the fact that $G_Y(1^-)=\sum_{k=0}^\infty P(Y_i=k)=1$ we must have $\lambda=1$ and
\begin{align}
G_Y(z)&=\ln\frac{1+e^{z-1}}2+1
\\&=\ln\frac{1 + e}2 + \frac z{1 + e} + \frac{e z^2}{2 (1 + e)^2} + \frac{(e - 1) e z^3}{6 (1 + e)^3} + \frac{e (1 - 4 e + e^2) z^4}{24 (1 + e)^4} + ...
\end{align}
which would imply that $P(Y_i=4)=-0.00147<0$.
Example 2: There are other cases than the negative binomial case described in the original post, however. Suppose that the $Y_i$'s have pgf $G_Y(z)=e^{z-1}$, that is, each $Y_i \sim \operatorname{Poisson}(1)$.
Using (2), the pgf of $X$ is then
$$
G_X(z)=G_N(G_Y(z))=e^{\lambda(e^{z-1}-1)}
$$
and using (1), the mgf of $\theta$ would need to be
$$
M_{\theta}(z)=G_X(z+1)=e^{\lambda(e^z-1)}
$$
implying that $\theta\sim \operatorname{Poisson}(\lambda)$. So in this case $X$ can be seen both as a Poisson-Poisson mixture and as a sum of a Poisson distributed number of iid Poisson(1) random variables.
|
Negative Binomial as Gamma-Poisson Mixture or Compound Logarithmic Poisson: can this correspondence
|
Let
$$
M_\theta(z)=E e^{z\theta}
$$
denote the moment generating function of $\theta$. Since $X|\theta\sim \operatorname{Poisson}(\theta)$, the probability generating function (pgf) of $X|\theta$ is
|
Negative Binomial as Gamma-Poisson Mixture or Compound Logarithmic Poisson: can this correspondence be generalized to other distributions?
Let
$$
M_\theta(z)=E e^{z\theta}
$$
denote the moment generating function of $\theta$. Since $X|\theta\sim \operatorname{Poisson}(\theta)$, the probability generating function (pgf) of $X|\theta$ is
$$
G_{X|\theta}(z)=Ez^X|\theta = e^{\theta(z-1)}.
$$
Hence, using the law of total expectation, the pgf of $X$ is
$$
G_X(z)=Ez^X=E(Ez^X|\theta)=Ee^{\theta(z-1)} =M_\theta(z-1). \tag{1}
$$
If, at the same time,
$$
X = \sum_{i=1}^N Y_i
$$
where the $Y_i$'s are iid with pgf $G_Y(z)$ and $N \sim \operatorname{Poisson}(\lambda)$ such that the pgf of $N$ is $
G_N(z)=e^{\lambda(t-1)}$,
then the pgf of $X$ must also be equal to
\begin{align}
G_X(z)
&=Ez^X
\\&=E E(z^X|N)
\\&=E E(z^{Y_1+Y_2+\dots+Y_N}|N)
\\&=E (G_Y(z)^N|N)
\\&=G_N(G_Y(z)). \tag{2}
\end{align}
Hence, the pgf of the iid $Y_i$'s given $M_\theta(z)$ is
$$
G_Y(z)=G_N^{-1}(G_X(z))=\frac1\lambda(\ln G_X(z) + 1)=\frac1\lambda(\ln M_\theta(z-1) + 1). \tag{3}
$$
from which the probability mass function $P(Y=k)=G_Y^{(k)}(0)/k!$, $k=0,1,2,\dots$ can be computed.
Of course, if any of the point masses are negative, $X$ can not be represented simultaneously both as a Poisson mixture and as a compound Poisson distribution.
Example 1: Suppose that $\theta \sim \operatorname{Bern}(1/2)$ such that $M_\theta(z)=\frac{1+e^z}2$. Note that this means that $X$ has a zero-inflated Poisson distribution. Using (3) and the fact that $G_Y(1^-)=\sum_{k=0}^\infty P(Y_i=k)=1$ we must have $\lambda=1$ and
\begin{align}
G_Y(z)&=\ln\frac{1+e^{z-1}}2+1
\\&=\ln\frac{1 + e}2 + \frac z{1 + e} + \frac{e z^2}{2 (1 + e)^2} + \frac{(e - 1) e z^3}{6 (1 + e)^3} + \frac{e (1 - 4 e + e^2) z^4}{24 (1 + e)^4} + ...
\end{align}
which would imply that $P(Y_i=4)=-0.00147<0$.
Example 2: There are other cases than the negative binomial case described in the original post, however. Suppose that the $Y_i$'s have pgf $G_Y(z)=e^{z-1}$, that is, each $Y_i \sim \operatorname{Poisson}(1)$.
Using (2), the pgf of $X$ is then
$$
G_X(z)=G_N(G_Y(z))=e^{\lambda(e^{z-1}-1)}
$$
and using (1), the mgf of $\theta$ would need to be
$$
M_{\theta}(z)=G_X(z+1)=e^{\lambda(e^z-1)}
$$
implying that $\theta\sim \operatorname{Poisson}(\lambda)$. So in this case $X$ can be seen both as a Poisson-Poisson mixture and as a sum of a Poisson distributed number of iid Poisson(1) random variables.
|
Negative Binomial as Gamma-Poisson Mixture or Compound Logarithmic Poisson: can this correspondence
Let
$$
M_\theta(z)=E e^{z\theta}
$$
denote the moment generating function of $\theta$. Since $X|\theta\sim \operatorname{Poisson}(\theta)$, the probability generating function (pgf) of $X|\theta$ is
|
39,855
|
Negative Binomial as Gamma-Poisson Mixture or Compound Logarithmic Poisson: can this correspondence be generalized to other distributions?
|
At the moment this is just a partial answer. I'm going to start by deriving the requirement for these two mixture forms to be equal. This will get you some of the way by at least showing the equation that your functions must solve. At the moment I can't see a full solution.
We can see from the first mixture that the support of $X$ is the non-negative integers, so let's work in that space. Suppose we let $p_X$ be the mass function and $m_X$ be the moment-generating function for $X$. I will take $F$ and $G$ to be the density functions for the distributions of $\theta$ and $Y_i$. The first mixture form can be characterised by the requirement:
$$\text{Mixture 1}
\quad \quad \quad
p_X(x) = \int \limits_\Theta \text{Pois}(x|\theta) \cdot F(\theta) \ d\theta,$$
and the second mixture form can be characterised by the requirement:
$$\text{Mixture 2}
\quad \quad \quad
m_X(t) = \sum_{n=0}^\infty m_Y(t)^n \cdot \text{Pois}(n|\lambda).$$
Equating the mixture forms: To solve your problem, let's work in terms of moment-generating functions, and simplify things as far as we can. From the first mixture form we must have:
$$\begin{align}
m_X(t)
&= \mathbb{E}(e^{tX}) \\[12pt]
&= \sum_{x=0}^\infty e^{tx} p_X(x) \\[8pt]
&= \sum_{x=0}^\infty e^{tx} \int \limits_\Theta \text{Pois}(x|\theta) \cdot F(\theta) \ d\theta. \\[6pt]
\end{align}$$
Expanding the moment-generating function $m_Y$ in the second mixture form gives:
$$\begin{align}
m_X(t)
&= \sum_{n=0}^\infty m_Y(t)^n \cdot \text{Pois}(n|\lambda) \\[6pt]
&= \sum_{n=0}^\infty \mathbb{E}(e^{tY})^n \cdot \text{Pois}(n|\lambda) \\[6pt]
&= \sum_{n=0}^\infty \Bigg( \sum_{y=0}^\infty e^{ty} \cdot G(y) \Bigg)^n \cdot \text{Pois}(n|\lambda). \\[6pt]
\end{align}$$
Equating the two forms for the moment-generating function then gives the equivalence requirement:
$$\boxed{\quad \sum_{n=0}^\infty \Bigg( \sum_{y=0}^\infty e^{ty} \cdot G(y) \Bigg)^n \cdot \text{Pois}(n|\lambda) = \sum_{x=0}^\infty e^{tx} \int \limits_\Theta \text{Pois}(x|\theta) \cdot F(\theta) \ d\theta \quad}$$
Consequently, what we require to solve your mixture problem, is some forms for the densities $F$ and $G$ and the parameter $\lambda$ that satisfy the equivalence requirement. If you can obtain conditions on the densities that ensure that the above equation is satisfied then you will have established the equivalence of the two mixtures.
|
Negative Binomial as Gamma-Poisson Mixture or Compound Logarithmic Poisson: can this correspondence
|
At the moment this is just a partial answer. I'm going to start by deriving the requirement for these two mixture forms to be equal. This will get you some of the way by at least showing the equatio
|
Negative Binomial as Gamma-Poisson Mixture or Compound Logarithmic Poisson: can this correspondence be generalized to other distributions?
At the moment this is just a partial answer. I'm going to start by deriving the requirement for these two mixture forms to be equal. This will get you some of the way by at least showing the equation that your functions must solve. At the moment I can't see a full solution.
We can see from the first mixture that the support of $X$ is the non-negative integers, so let's work in that space. Suppose we let $p_X$ be the mass function and $m_X$ be the moment-generating function for $X$. I will take $F$ and $G$ to be the density functions for the distributions of $\theta$ and $Y_i$. The first mixture form can be characterised by the requirement:
$$\text{Mixture 1}
\quad \quad \quad
p_X(x) = \int \limits_\Theta \text{Pois}(x|\theta) \cdot F(\theta) \ d\theta,$$
and the second mixture form can be characterised by the requirement:
$$\text{Mixture 2}
\quad \quad \quad
m_X(t) = \sum_{n=0}^\infty m_Y(t)^n \cdot \text{Pois}(n|\lambda).$$
Equating the mixture forms: To solve your problem, let's work in terms of moment-generating functions, and simplify things as far as we can. From the first mixture form we must have:
$$\begin{align}
m_X(t)
&= \mathbb{E}(e^{tX}) \\[12pt]
&= \sum_{x=0}^\infty e^{tx} p_X(x) \\[8pt]
&= \sum_{x=0}^\infty e^{tx} \int \limits_\Theta \text{Pois}(x|\theta) \cdot F(\theta) \ d\theta. \\[6pt]
\end{align}$$
Expanding the moment-generating function $m_Y$ in the second mixture form gives:
$$\begin{align}
m_X(t)
&= \sum_{n=0}^\infty m_Y(t)^n \cdot \text{Pois}(n|\lambda) \\[6pt]
&= \sum_{n=0}^\infty \mathbb{E}(e^{tY})^n \cdot \text{Pois}(n|\lambda) \\[6pt]
&= \sum_{n=0}^\infty \Bigg( \sum_{y=0}^\infty e^{ty} \cdot G(y) \Bigg)^n \cdot \text{Pois}(n|\lambda). \\[6pt]
\end{align}$$
Equating the two forms for the moment-generating function then gives the equivalence requirement:
$$\boxed{\quad \sum_{n=0}^\infty \Bigg( \sum_{y=0}^\infty e^{ty} \cdot G(y) \Bigg)^n \cdot \text{Pois}(n|\lambda) = \sum_{x=0}^\infty e^{tx} \int \limits_\Theta \text{Pois}(x|\theta) \cdot F(\theta) \ d\theta \quad}$$
Consequently, what we require to solve your mixture problem, is some forms for the densities $F$ and $G$ and the parameter $\lambda$ that satisfy the equivalence requirement. If you can obtain conditions on the densities that ensure that the above equation is satisfied then you will have established the equivalence of the two mixtures.
|
Negative Binomial as Gamma-Poisson Mixture or Compound Logarithmic Poisson: can this correspondence
At the moment this is just a partial answer. I'm going to start by deriving the requirement for these two mixture forms to be equal. This will get you some of the way by at least showing the equatio
|
39,856
|
Why are the residuals in $\mathbb{R}^{n-p}$?
|
$\newcommand{\rank}{\mathrm{rank}}$
$\newcommand{\tr}{\mathrm{tr}}$
$\newcommand{\real}{\mathbb{R}}$
$\newcommand{\eps}{\epsilon}$
Write the linear model in the matrix form
\begin{align*}
y = X\beta + \epsilon
\end{align*}
where $y \in \mathbb{R}^n, X = \begin{pmatrix} x_1 & \cdots & x_{p}\end{pmatrix} \in \mathbb{R}^{n \times p}, \beta \in \mathbb{R}^p, \epsilon \in \mathbb{R}^n$. By convention, $x_1 \equiv e$, where $e \in \real^n$ is a column vector of all ones, and $\rank(X) = p$.
Recall that $H = X(X'X)^{-1}X'$ is the "hat matrix", and the residual vector can be written as $\hat{\epsilon} = (I_{(n)} - H)y$. First note that $y$ lies in $\mathbb{R}^n$, therefore $\hat{\epsilon}$ lies in the image space of the matrix $I_{(n)} - H$ (you can view the matrix $I_{(n)} - H$ as a linear operator on $\mathbb{R}^n$), say $U$. Linear algebra theory asserts that $\dim(U) = \rank(I_{(n)} - H)$. On the other hand, since $I_{(n)} - H$ is idempotent (i.e., $(I_{(n)} - H)^2 = I_{(n)} - H$), its rank is equal to its trace, i.e.,
\begin{align*}
& \rank(I_{(n)} - H) = \tr(I_{(n)} - H) = \tr(I_{(n)}) - \tr(H) \\
= & n - \tr(X(X'X)^{-1}X') = n -
\tr(X'X(X'X)^{-1}) = n - \tr(I_{(p)}) = n - p,
\end{align*}
where we used properties $\tr(A + B) = \tr(A) + \tr(B)$ and $\tr(AB) = \tr(BA)$ of trace.
There is another more geometric flavor argument to derive $\dim(U)$, as your textbook tries to convey. Denote the space spanned by columns of $X$ by $W$, then it is easy to see that
\begin{align*}
\real^n = W \oplus W^\bot, \tag{$*$}
\end{align*}
where $W^\bot$ stands for the orthogonal complement of $W$. For any $y \in \real^n$, the decomposition
$$y = Hy + (I_{(n)} - H)y = \hat{y} + \hat{\eps}. $$
and $\hat{\eps}'Xa = y'(I - H)Xa = 0$ for any $a \in \real^p$ show that $\hat{\eps} \in W^\bot$, hence $U = W^\bot$. By $(*)$, it follows that
\begin{align*}
\dim(U) = \dim(W^\bot) = \dim(\real^n) - \dim(W) = n - p,
\end{align*}
since obviously $\dim(W) = \rank(X) = p$.
|
Why are the residuals in $\mathbb{R}^{n-p}$?
|
$\newcommand{\rank}{\mathrm{rank}}$
$\newcommand{\tr}{\mathrm{tr}}$
$\newcommand{\real}{\mathbb{R}}$
$\newcommand{\eps}{\epsilon}$
Write the linear model in the matrix form
\begin{align*}
y = X\beta +
|
Why are the residuals in $\mathbb{R}^{n-p}$?
$\newcommand{\rank}{\mathrm{rank}}$
$\newcommand{\tr}{\mathrm{tr}}$
$\newcommand{\real}{\mathbb{R}}$
$\newcommand{\eps}{\epsilon}$
Write the linear model in the matrix form
\begin{align*}
y = X\beta + \epsilon
\end{align*}
where $y \in \mathbb{R}^n, X = \begin{pmatrix} x_1 & \cdots & x_{p}\end{pmatrix} \in \mathbb{R}^{n \times p}, \beta \in \mathbb{R}^p, \epsilon \in \mathbb{R}^n$. By convention, $x_1 \equiv e$, where $e \in \real^n$ is a column vector of all ones, and $\rank(X) = p$.
Recall that $H = X(X'X)^{-1}X'$ is the "hat matrix", and the residual vector can be written as $\hat{\epsilon} = (I_{(n)} - H)y$. First note that $y$ lies in $\mathbb{R}^n$, therefore $\hat{\epsilon}$ lies in the image space of the matrix $I_{(n)} - H$ (you can view the matrix $I_{(n)} - H$ as a linear operator on $\mathbb{R}^n$), say $U$. Linear algebra theory asserts that $\dim(U) = \rank(I_{(n)} - H)$. On the other hand, since $I_{(n)} - H$ is idempotent (i.e., $(I_{(n)} - H)^2 = I_{(n)} - H$), its rank is equal to its trace, i.e.,
\begin{align*}
& \rank(I_{(n)} - H) = \tr(I_{(n)} - H) = \tr(I_{(n)}) - \tr(H) \\
= & n - \tr(X(X'X)^{-1}X') = n -
\tr(X'X(X'X)^{-1}) = n - \tr(I_{(p)}) = n - p,
\end{align*}
where we used properties $\tr(A + B) = \tr(A) + \tr(B)$ and $\tr(AB) = \tr(BA)$ of trace.
There is another more geometric flavor argument to derive $\dim(U)$, as your textbook tries to convey. Denote the space spanned by columns of $X$ by $W$, then it is easy to see that
\begin{align*}
\real^n = W \oplus W^\bot, \tag{$*$}
\end{align*}
where $W^\bot$ stands for the orthogonal complement of $W$. For any $y \in \real^n$, the decomposition
$$y = Hy + (I_{(n)} - H)y = \hat{y} + \hat{\eps}. $$
and $\hat{\eps}'Xa = y'(I - H)Xa = 0$ for any $a \in \real^p$ show that $\hat{\eps} \in W^\bot$, hence $U = W^\bot$. By $(*)$, it follows that
\begin{align*}
\dim(U) = \dim(W^\bot) = \dim(\real^n) - \dim(W) = n - p,
\end{align*}
since obviously $\dim(W) = \rank(X) = p$.
|
Why are the residuals in $\mathbb{R}^{n-p}$?
$\newcommand{\rank}{\mathrm{rank}}$
$\newcommand{\tr}{\mathrm{tr}}$
$\newcommand{\real}{\mathbb{R}}$
$\newcommand{\eps}{\epsilon}$
Write the linear model in the matrix form
\begin{align*}
y = X\beta +
|
39,857
|
Why are the residuals in $\mathbb{R}^{n-p}$?
|
Orthogonal component
The space for the residuals is the orthogonal complement of the space spanned by $X$.
This is because the residual $\mathbf{y}-\mathbf{\hat{y}}$ is a vector that is perpendicular to the fit $\mathbf{\hat{y}}$. In the geometric representation it is a perpendicular projection of $y$ into the space spanned by the vectors in $X$ namely $\mathbf{\hat y} = X(X^TX)^{-1}X^T \mathbf{y}$.
This orthogonal component has dimension $n-p$
Intuitive illustration
The image in your book is abstract. It might maybe help to draw it for an actual example.
In the example below, you see an illustration for the fitting of $\mathbf{y} = a + b\mathbf{x}$ with only three points.
The error is a vector perpendicular to the surface spanned by $x_1$ and $x_2$. For any observation, the error will point in the same direction and can be seen to be a multiple of a line (a 1D space).
Linear algebra
You can describe any observation $\mathbf{y}$ (a sample of size $n$) in the space of potential observations as a sum of any $n$ orthogonal vectors. If $p$ of those form the vector $\mathbf{\hat{y}}$ then the remainder (the error $\mathbf{\epsilon}$) is a sum of the $n-p$ other ones.
$$\mathbf{y} = \overbrace{\underbrace{x_1 + x_2 + \dots + x_p}_{\substack{\mathbf{\hat{y}}\\\text{These $p$ vectors/regressors summed}\\\text{form the vector $\mathbf{\hat{y}}$}}} + \underbrace{ e_1 + e_2 + \dots + e_{n-p}}_{\substack{\mathbf{\epsilon}\\\text{The error $\mathbf{\epsilon}$ is a sum of}\\\text{the remaining $n-p$}}}}^{\text{$n$ orthogonal vectors of which $p$ are the regressors $x_i$}}$$
The $n-p$ stems from splitting the space into two orthogonal subspaces, one with dimension $p$, the other with dimension $n-p$.
|
Why are the residuals in $\mathbb{R}^{n-p}$?
|
Orthogonal component
The space for the residuals is the orthogonal complement of the space spanned by $X$.
This is because the residual $\mathbf{y}-\mathbf{\hat{y}}$ is a vector that is perpendicular
|
Why are the residuals in $\mathbb{R}^{n-p}$?
Orthogonal component
The space for the residuals is the orthogonal complement of the space spanned by $X$.
This is because the residual $\mathbf{y}-\mathbf{\hat{y}}$ is a vector that is perpendicular to the fit $\mathbf{\hat{y}}$. In the geometric representation it is a perpendicular projection of $y$ into the space spanned by the vectors in $X$ namely $\mathbf{\hat y} = X(X^TX)^{-1}X^T \mathbf{y}$.
This orthogonal component has dimension $n-p$
Intuitive illustration
The image in your book is abstract. It might maybe help to draw it for an actual example.
In the example below, you see an illustration for the fitting of $\mathbf{y} = a + b\mathbf{x}$ with only three points.
The error is a vector perpendicular to the surface spanned by $x_1$ and $x_2$. For any observation, the error will point in the same direction and can be seen to be a multiple of a line (a 1D space).
Linear algebra
You can describe any observation $\mathbf{y}$ (a sample of size $n$) in the space of potential observations as a sum of any $n$ orthogonal vectors. If $p$ of those form the vector $\mathbf{\hat{y}}$ then the remainder (the error $\mathbf{\epsilon}$) is a sum of the $n-p$ other ones.
$$\mathbf{y} = \overbrace{\underbrace{x_1 + x_2 + \dots + x_p}_{\substack{\mathbf{\hat{y}}\\\text{These $p$ vectors/regressors summed}\\\text{form the vector $\mathbf{\hat{y}}$}}} + \underbrace{ e_1 + e_2 + \dots + e_{n-p}}_{\substack{\mathbf{\epsilon}\\\text{The error $\mathbf{\epsilon}$ is a sum of}\\\text{the remaining $n-p$}}}}^{\text{$n$ orthogonal vectors of which $p$ are the regressors $x_i$}}$$
The $n-p$ stems from splitting the space into two orthogonal subspaces, one with dimension $p$, the other with dimension $n-p$.
|
Why are the residuals in $\mathbb{R}^{n-p}$?
Orthogonal component
The space for the residuals is the orthogonal complement of the space spanned by $X$.
This is because the residual $\mathbf{y}-\mathbf{\hat{y}}$ is a vector that is perpendicular
|
39,858
|
Why are the residuals in $\mathbb{R}^{n-p}$?
|
I think the constraints on the residuals mean that they can be represented by $n-p$ numbers. Take a trivial case,
$$
y = \bar{y} + \varepsilon
$$
Here, there will be n error terms, but they will sum to zero. So, if you tell me $n-1$ error terms, I can work out the other one.
I think there is something analogous for the full model, but I'm not sure how to explain it. I guess, if you told me $n-p$ error terms, as well as the $X$ matrix and $\beta$ vector, I would be able to work out the rest.
|
Why are the residuals in $\mathbb{R}^{n-p}$?
|
I think the constraints on the residuals mean that they can be represented by $n-p$ numbers. Take a trivial case,
$$
y = \bar{y} + \varepsilon
$$
Here, there will be n error terms, but they will sum t
|
Why are the residuals in $\mathbb{R}^{n-p}$?
I think the constraints on the residuals mean that they can be represented by $n-p$ numbers. Take a trivial case,
$$
y = \bar{y} + \varepsilon
$$
Here, there will be n error terms, but they will sum to zero. So, if you tell me $n-1$ error terms, I can work out the other one.
I think there is something analogous for the full model, but I'm not sure how to explain it. I guess, if you told me $n-p$ error terms, as well as the $X$ matrix and $\beta$ vector, I would be able to work out the rest.
|
Why are the residuals in $\mathbb{R}^{n-p}$?
I think the constraints on the residuals mean that they can be represented by $n-p$ numbers. Take a trivial case,
$$
y = \bar{y} + \varepsilon
$$
Here, there will be n error terms, but they will sum t
|
39,859
|
Is $\mathrm{binomial}(n, p)$ family both full and curved for $n$ fixed?
|
From Casella & Berger, p.137-38:
When $n$ is given, (1) is an exponential family. It is full as the parameter space $(0,1)$ is the largest possible. In the sense that
$$\log p - \log (1-p)$$
ranges $(-\infty,+\infty)$ when $p\in(0,1)$. Rewriting it as
$$ f(x|p)=\tbinom{n}{x}\exp \left[x\log p+(n-x)\log(1-p)\right]\tag{2}$$
is seemingly increasing the dimension of the natural statistic and hence gives the impression of a curved exponential family, but this is only an impression since $x$ and $(n-x)$ are linearly dependent:
$$ x+(n-x)=n$$
The representation (2) is thus not minimal. In other words, one can rewrite (2) as
$$\exp \left[x\log p+(n-x)\log(1-p)\right]=\exp \left[x\{\log p-\log(1-p)\}\underbrace{+n\log(1-p)}_{\substack{\text{normalising}\\ \text{constant}}}\right]$$
and deduce there is a dimension-one sufficient statistic.
|
Is $\mathrm{binomial}(n, p)$ family both full and curved for $n$ fixed?
|
From Casella & Berger, p.137-38:
When $n$ is given, (1) is an exponential family. It is full as the parameter space $(0,1)$ is the largest possible. In the sense that
$$\log p - \log (1-p)$$
ranges $
|
Is $\mathrm{binomial}(n, p)$ family both full and curved for $n$ fixed?
From Casella & Berger, p.137-38:
When $n$ is given, (1) is an exponential family. It is full as the parameter space $(0,1)$ is the largest possible. In the sense that
$$\log p - \log (1-p)$$
ranges $(-\infty,+\infty)$ when $p\in(0,1)$. Rewriting it as
$$ f(x|p)=\tbinom{n}{x}\exp \left[x\log p+(n-x)\log(1-p)\right]\tag{2}$$
is seemingly increasing the dimension of the natural statistic and hence gives the impression of a curved exponential family, but this is only an impression since $x$ and $(n-x)$ are linearly dependent:
$$ x+(n-x)=n$$
The representation (2) is thus not minimal. In other words, one can rewrite (2) as
$$\exp \left[x\log p+(n-x)\log(1-p)\right]=\exp \left[x\{\log p-\log(1-p)\}\underbrace{+n\log(1-p)}_{\substack{\text{normalising}\\ \text{constant}}}\right]$$
and deduce there is a dimension-one sufficient statistic.
|
Is $\mathrm{binomial}(n, p)$ family both full and curved for $n$ fixed?
From Casella & Berger, p.137-38:
When $n$ is given, (1) is an exponential family. It is full as the parameter space $(0,1)$ is the largest possible. In the sense that
$$\log p - \log (1-p)$$
ranges $
|
39,860
|
Rejection threshold of the Benjamini-Hochberg procedure
|
As you sense, there is no fixed p-value cutoff for the Benjamini-Hochberg control of false discovery rate. The cutoff depends on the specific distribution of p-values among the $m$ hypotheses that you are evaluating together. You put them in increasing order and count up in $k$ from the lowest p-value $(k=1)$. You agree to "reject the null hypothesis" for hypotheses up through this value of $k$:
For a given $\alpha$, find the largest $k$ such that $P_{(k)} \leq \frac{k}{m} \alpha.$
If the null hypotheses all hold so there is a uniform distribution of p-values in [0,1], the p-value cutoff will be close to $\alpha$. How much below that you go if some null hypotheses don't hold depends on how non-uniform the distribution of p-values is.
|
Rejection threshold of the Benjamini-Hochberg procedure
|
As you sense, there is no fixed p-value cutoff for the Benjamini-Hochberg control of false discovery rate. The cutoff depends on the specific distribution of p-values among the $m$ hypotheses that you
|
Rejection threshold of the Benjamini-Hochberg procedure
As you sense, there is no fixed p-value cutoff for the Benjamini-Hochberg control of false discovery rate. The cutoff depends on the specific distribution of p-values among the $m$ hypotheses that you are evaluating together. You put them in increasing order and count up in $k$ from the lowest p-value $(k=1)$. You agree to "reject the null hypothesis" for hypotheses up through this value of $k$:
For a given $\alpha$, find the largest $k$ such that $P_{(k)} \leq \frac{k}{m} \alpha.$
If the null hypotheses all hold so there is a uniform distribution of p-values in [0,1], the p-value cutoff will be close to $\alpha$. How much below that you go if some null hypotheses don't hold depends on how non-uniform the distribution of p-values is.
|
Rejection threshold of the Benjamini-Hochberg procedure
As you sense, there is no fixed p-value cutoff for the Benjamini-Hochberg control of false discovery rate. The cutoff depends on the specific distribution of p-values among the $m$ hypotheses that you
|
39,861
|
Rejection threshold of the Benjamini-Hochberg procedure
|
I'm not certain of the formal validity of this approach, but you could calculate the corresponding FWER as given by the Hochberg method.
The Benjamini-Hochberg procedure for controlling the False Discovery Rate is (I'm going to quote Wikipedia)
... we have $H_1 \ldots H_m$ null hypotheses tested and $P_1 \ldots P_m$ their corresponding p-values. We list these p-values in ascending order and denote them by $P_{(1)} \ldots P_{(m)}$.
...
For a given $\alpha$, find the largest $k$ such that $P_{(k)} \leq \frac{k}{m} \alpha.$
Reject the null hypothesis (i.e., declare discoveries) for all $H_{(i)}$ for $i = 1, \ldots, k$.
That method sets the FDR at $\alpha$, i.e., out of the rejected hypotheses, we expect the fraction of Type I Errors to be $\alpha$.
The Family-Wise Error Rate, on the other hand, is the probability of at least one Type I Error in the set of rejected hypotheses. The Hochberg method accomplishes this with a calculation similar to the BH FDR method (again, quoting Wikipedia),
Start by ordering the p-values (from lowest to highest) $P_{(1)} \ldots P_{(m)}$ and let the associated hypotheses be $H_{(1)} \ldots H_{(m)}$
For a given $\alpha$, let $R$ be the largest $k$ such that $P_{(k)} \leq \frac{\alpha}{m-k+1}$
Reject the null hypotheses $H_{(1)} \ldots H_{(R)}$
You could put these together to 1) define an FDR $\alpha$, 2) determine the largest rejected p-value $p^*$ and the number of rejected hypotheses $k$ out of total $m$, 3) calculate the corresponding Hochberg FWER $\tilde{\alpha}$ as
$$ \tilde{\alpha} = p^* \times(m-k+1) $$
|
Rejection threshold of the Benjamini-Hochberg procedure
|
I'm not certain of the formal validity of this approach, but you could calculate the corresponding FWER as given by the Hochberg method.
The Benjamini-Hochberg procedure for controlling the False Disc
|
Rejection threshold of the Benjamini-Hochberg procedure
I'm not certain of the formal validity of this approach, but you could calculate the corresponding FWER as given by the Hochberg method.
The Benjamini-Hochberg procedure for controlling the False Discovery Rate is (I'm going to quote Wikipedia)
... we have $H_1 \ldots H_m$ null hypotheses tested and $P_1 \ldots P_m$ their corresponding p-values. We list these p-values in ascending order and denote them by $P_{(1)} \ldots P_{(m)}$.
...
For a given $\alpha$, find the largest $k$ such that $P_{(k)} \leq \frac{k}{m} \alpha.$
Reject the null hypothesis (i.e., declare discoveries) for all $H_{(i)}$ for $i = 1, \ldots, k$.
That method sets the FDR at $\alpha$, i.e., out of the rejected hypotheses, we expect the fraction of Type I Errors to be $\alpha$.
The Family-Wise Error Rate, on the other hand, is the probability of at least one Type I Error in the set of rejected hypotheses. The Hochberg method accomplishes this with a calculation similar to the BH FDR method (again, quoting Wikipedia),
Start by ordering the p-values (from lowest to highest) $P_{(1)} \ldots P_{(m)}$ and let the associated hypotheses be $H_{(1)} \ldots H_{(m)}$
For a given $\alpha$, let $R$ be the largest $k$ such that $P_{(k)} \leq \frac{\alpha}{m-k+1}$
Reject the null hypotheses $H_{(1)} \ldots H_{(R)}$
You could put these together to 1) define an FDR $\alpha$, 2) determine the largest rejected p-value $p^*$ and the number of rejected hypotheses $k$ out of total $m$, 3) calculate the corresponding Hochberg FWER $\tilde{\alpha}$ as
$$ \tilde{\alpha} = p^* \times(m-k+1) $$
|
Rejection threshold of the Benjamini-Hochberg procedure
I'm not certain of the formal validity of this approach, but you could calculate the corresponding FWER as given by the Hochberg method.
The Benjamini-Hochberg procedure for controlling the False Disc
|
39,862
|
Rejection threshold of the Benjamini-Hochberg procedure
|
After some thought, I believe that the unadjusted p-value of the last (rank-wise) significant test after the BH-procedure comes closest to a significance threshold.
An example:
Do the BH-procedure:
Some p-values: $0.0001,0.0234,0.3354,0.0021,0.5211,0.9123,0.0008,0.0293,0.0500, 1.000$
Order them: $0.0001, 0.0008, 0.0021, 0.0234, 0.0293, 0.0500, 0.3354, 0.5211, 0.9123, 1.0000$
Compute q-values for all 10 ranks: $q_i = \frac{i}{m}\cdot \alpha$, for $i=1,2,..,m$.
Find the largest ranked p-value that is smaller than its corresponding q-value.
Results:
$$\begin{array}{}
\textbf{Rank} & \textbf{q-value} & \textbf{p-value} & \textbf{Significance (BH)} \\ \hline
1 & 0.005 & 0.0001 & True \\ \hline
2 & 0.01 & 0.0008 & True \\ \hline
3 & 0.015 & 0.0021 & True \\ \hline
4 & 0.02 & 0.0234 & False \\ \hline
5 & 0.025 & 0.0293 & False \\ \hline
6 & 0.03 & 0.05 & False \\ \hline
7 & 0.035 & 0.3354 & False \\ \hline
8 & 0.04 & 0.5211 & False \\ \hline
9 & 0.045 & 0.9123 & False \\ \hline
10 & 0.05 & 1 & False \\ \hline
\end{array}$$
On the table, we can see that all tests above Rank 3 are non-significant, thus we can conclude that 0.0021 acts as our significance threshold.
In comparison, the Bonferroni correction has a threshold of $\frac{\alpha}{m}=0.005$.
Here is the R-code I used for this example:
# generate p-values
pValues <- c(0.0001,0.0234,0.3354,0.0021,0.5211,0.9123,0.0008,0.0293,0.0500, 1)
# order the p-values
pValues <- sort(pValues)
# BH-procedure
alpha <- 0.05
m <- length(pValues)
qValues <- c()
for (i in 1:m){
qV <- (i/m)*alpha
qValues <- append(qValues, qV)
}
# find the largest p-value that satisfies p_i < q_i
BH_test <- qValues > pValues
# largest k is 3, thus threshold is 0.0021
threshold <- p[sum(BH_test)];threshold
|
Rejection threshold of the Benjamini-Hochberg procedure
|
After some thought, I believe that the unadjusted p-value of the last (rank-wise) significant test after the BH-procedure comes closest to a significance threshold.
An example:
Do the BH-procedure:
S
|
Rejection threshold of the Benjamini-Hochberg procedure
After some thought, I believe that the unadjusted p-value of the last (rank-wise) significant test after the BH-procedure comes closest to a significance threshold.
An example:
Do the BH-procedure:
Some p-values: $0.0001,0.0234,0.3354,0.0021,0.5211,0.9123,0.0008,0.0293,0.0500, 1.000$
Order them: $0.0001, 0.0008, 0.0021, 0.0234, 0.0293, 0.0500, 0.3354, 0.5211, 0.9123, 1.0000$
Compute q-values for all 10 ranks: $q_i = \frac{i}{m}\cdot \alpha$, for $i=1,2,..,m$.
Find the largest ranked p-value that is smaller than its corresponding q-value.
Results:
$$\begin{array}{}
\textbf{Rank} & \textbf{q-value} & \textbf{p-value} & \textbf{Significance (BH)} \\ \hline
1 & 0.005 & 0.0001 & True \\ \hline
2 & 0.01 & 0.0008 & True \\ \hline
3 & 0.015 & 0.0021 & True \\ \hline
4 & 0.02 & 0.0234 & False \\ \hline
5 & 0.025 & 0.0293 & False \\ \hline
6 & 0.03 & 0.05 & False \\ \hline
7 & 0.035 & 0.3354 & False \\ \hline
8 & 0.04 & 0.5211 & False \\ \hline
9 & 0.045 & 0.9123 & False \\ \hline
10 & 0.05 & 1 & False \\ \hline
\end{array}$$
On the table, we can see that all tests above Rank 3 are non-significant, thus we can conclude that 0.0021 acts as our significance threshold.
In comparison, the Bonferroni correction has a threshold of $\frac{\alpha}{m}=0.005$.
Here is the R-code I used for this example:
# generate p-values
pValues <- c(0.0001,0.0234,0.3354,0.0021,0.5211,0.9123,0.0008,0.0293,0.0500, 1)
# order the p-values
pValues <- sort(pValues)
# BH-procedure
alpha <- 0.05
m <- length(pValues)
qValues <- c()
for (i in 1:m){
qV <- (i/m)*alpha
qValues <- append(qValues, qV)
}
# find the largest p-value that satisfies p_i < q_i
BH_test <- qValues > pValues
# largest k is 3, thus threshold is 0.0021
threshold <- p[sum(BH_test)];threshold
|
Rejection threshold of the Benjamini-Hochberg procedure
After some thought, I believe that the unadjusted p-value of the last (rank-wise) significant test after the BH-procedure comes closest to a significance threshold.
An example:
Do the BH-procedure:
S
|
39,863
|
Obtaining the correct Log-likelihood function
|
The loglikelihood is correct. Your problem is the derivatives.
The loglikelihood is not differentiable with respect to $\mu$ where $\mu=x_i$ (and in particular, not at the MLE). The second derivative with respect to $\mu$ is zero everywhere that it is defined. So you can't just do calculus.
For any fixed $\lambda$, the loglikelihood is piecewise linear (and concave) in $\mu$ with corners at the observations, so there is a maximum (and no other stationary points) and the maximum must be at an observation. It's fairly easy to satisfy yourself that the maximum is at the median if $n$ is odd and on the whole median interval if $n$ is even. That's true for every fixed $\lambda$ so it must be true for varying $\lambda$ as well.
Now, fixing $\mu$ at the MLE you have a differentiable one-parameter problem in $\lambda$. Solving
$$\frac{\partial}{\partial \lambda} \ell(\hat\mu, \lambda ; \mathbf{x})=\frac{n}{\lambda}-\sum_{i=1}^{n}\left|x_{i}-\hat\mu\right|$$
gives you $\hat\lambda$ as the mean absolute deviation from the median as the only stationary point. You can then check the second derivative wrt $\theta$ to make sure it's a maximum. Or you can argue that the maximum must be there or at the endpoints $\lambda=0$ or $\lambda=\infty$, and it's not either of those.
|
Obtaining the correct Log-likelihood function
|
The loglikelihood is correct. Your problem is the derivatives.
The loglikelihood is not differentiable with respect to $\mu$ where $\mu=x_i$ (and in particular, not at the MLE). The second derivative
|
Obtaining the correct Log-likelihood function
The loglikelihood is correct. Your problem is the derivatives.
The loglikelihood is not differentiable with respect to $\mu$ where $\mu=x_i$ (and in particular, not at the MLE). The second derivative with respect to $\mu$ is zero everywhere that it is defined. So you can't just do calculus.
For any fixed $\lambda$, the loglikelihood is piecewise linear (and concave) in $\mu$ with corners at the observations, so there is a maximum (and no other stationary points) and the maximum must be at an observation. It's fairly easy to satisfy yourself that the maximum is at the median if $n$ is odd and on the whole median interval if $n$ is even. That's true for every fixed $\lambda$ so it must be true for varying $\lambda$ as well.
Now, fixing $\mu$ at the MLE you have a differentiable one-parameter problem in $\lambda$. Solving
$$\frac{\partial}{\partial \lambda} \ell(\hat\mu, \lambda ; \mathbf{x})=\frac{n}{\lambda}-\sum_{i=1}^{n}\left|x_{i}-\hat\mu\right|$$
gives you $\hat\lambda$ as the mean absolute deviation from the median as the only stationary point. You can then check the second derivative wrt $\theta$ to make sure it's a maximum. Or you can argue that the maximum must be there or at the endpoints $\lambda=0$ or $\lambda=\infty$, and it's not either of those.
|
Obtaining the correct Log-likelihood function
The loglikelihood is correct. Your problem is the derivatives.
The loglikelihood is not differentiable with respect to $\mu$ where $\mu=x_i$ (and in particular, not at the MLE). The second derivative
|
39,864
|
Which categorical variable encoding should I use if I want the model intercept to have the interpretation of the global mean?
|
If the data are balanced, then deviation coding should work.
Let's look at a simple example:
set.seed(13)
dt <- expand.grid(X1 = LETTERS[1:3], reps = 1:5)
X <- model.matrix(~ X1, dt)
betas <- c(3, 1, 2)
dt$Y <- X %*% betas + rnorm(nrow(dt))
mean(dt$Y)
[1] 4.11413
So we would like the intercept to be 4.11413
If we fit the model with default coding we get:
lm(Y ~ X1, dt) %>% coef() # default treatment coding
(Intercept) X1B X1C
3.3430627 0.2867999 2.0264018
But now if we use deviating coding we get
contrasts(dt$X1) <- contr.sum(3) # specify deviation coding
lm(Y ~ X1, dt) %>% coef()
(Intercept) X11 X12
4.1141299 -0.7710672 -0.4842673
If the data are unbalanced then you will need to do some post-hoc adjustement.
Edit: To address what to do when the data are unbalanced.
In this case, it is easier to work with default treatment coding rather than deviation coding:
> set.seed(1)
> dt1 <- expand.grid(X1 = LETTERS[1:1], reps = 1:5)
> dt2 <- expand.grid(X1 = LETTERS[2:2], reps = 1:3)
> dt3 <- expand.grid(X1 = LETTERS[3:3], reps = 1:2)
> dt <- rbind(dt1, dt2, dt3)
> table(dt$X1)
A B C
5 3 2
So the groups are unbalanced.
> X <- model.matrix(~ X1, dt)
> betas <- c(2, 3, 1)
> dt$Y <- 4 + X %*% betas + rnorm(nrow(dt), 0, 1)
> mean(dt$Y)
[1] 7.232203
So we would like to recove 7.23 with a post hoc calculation, which can be acheived fairly easily with
> coef(lm(Y ~ X1, dt))[1] + betas[2] * table(dt$X1)[2]/nrow(dt) + betas[3] * table(dt$X1)[3]/nrow(dt)
(Intercept)
7.22927
Note that the result is not exact due to the combination of imbalance in the groups and the random error. As the error approaches zero, the result becomes exact. Even with error, the result is also unbiased, as we can see from a monte carlo simulation:
n.sim <- 1000
vec.sim <- numeric(n.sim)
for (i in 1:n.sim) {
set.seed(i)
dt$Y <- 4 + X %*% betas + rnorm(nrow(dt), 0, 1)
vec.sim[i] <- mean(dt$Y) - (coef(lm(Y ~ X1, dt))[1] + betas[2] * table(dt$X1)[2]/nrow(dt) + betas[3] * table(dt$X1)[3]/nrow(dt))
}
hist(vec.sim)
mean(vec.sim)
[1] -0.003418483
Edit: As noted in the comments, we should really be using the coefficient estimates from the model, and doing so will then make the calculation exact:
> coef(lm(Y ~ X1, dt))[1] + coef(lm(Y ~ X1, dt))[2] * table(dt$X1)[2]/nrow(dt) + coef(lm(Y ~ X1, dt))[3] * table(dt$X1)[3]/nrow(dt)
(Intercept)
7.232203
|
Which categorical variable encoding should I use if I want the model intercept to have the interpret
|
If the data are balanced, then deviation coding should work.
Let's look at a simple example:
set.seed(13)
dt <- expand.grid(X1 = LETTERS[1:3], reps = 1:5)
X <- model.matrix(~ X1, dt)
betas <- c(3, 1,
|
Which categorical variable encoding should I use if I want the model intercept to have the interpretation of the global mean?
If the data are balanced, then deviation coding should work.
Let's look at a simple example:
set.seed(13)
dt <- expand.grid(X1 = LETTERS[1:3], reps = 1:5)
X <- model.matrix(~ X1, dt)
betas <- c(3, 1, 2)
dt$Y <- X %*% betas + rnorm(nrow(dt))
mean(dt$Y)
[1] 4.11413
So we would like the intercept to be 4.11413
If we fit the model with default coding we get:
lm(Y ~ X1, dt) %>% coef() # default treatment coding
(Intercept) X1B X1C
3.3430627 0.2867999 2.0264018
But now if we use deviating coding we get
contrasts(dt$X1) <- contr.sum(3) # specify deviation coding
lm(Y ~ X1, dt) %>% coef()
(Intercept) X11 X12
4.1141299 -0.7710672 -0.4842673
If the data are unbalanced then you will need to do some post-hoc adjustement.
Edit: To address what to do when the data are unbalanced.
In this case, it is easier to work with default treatment coding rather than deviation coding:
> set.seed(1)
> dt1 <- expand.grid(X1 = LETTERS[1:1], reps = 1:5)
> dt2 <- expand.grid(X1 = LETTERS[2:2], reps = 1:3)
> dt3 <- expand.grid(X1 = LETTERS[3:3], reps = 1:2)
> dt <- rbind(dt1, dt2, dt3)
> table(dt$X1)
A B C
5 3 2
So the groups are unbalanced.
> X <- model.matrix(~ X1, dt)
> betas <- c(2, 3, 1)
> dt$Y <- 4 + X %*% betas + rnorm(nrow(dt), 0, 1)
> mean(dt$Y)
[1] 7.232203
So we would like to recove 7.23 with a post hoc calculation, which can be acheived fairly easily with
> coef(lm(Y ~ X1, dt))[1] + betas[2] * table(dt$X1)[2]/nrow(dt) + betas[3] * table(dt$X1)[3]/nrow(dt)
(Intercept)
7.22927
Note that the result is not exact due to the combination of imbalance in the groups and the random error. As the error approaches zero, the result becomes exact. Even with error, the result is also unbiased, as we can see from a monte carlo simulation:
n.sim <- 1000
vec.sim <- numeric(n.sim)
for (i in 1:n.sim) {
set.seed(i)
dt$Y <- 4 + X %*% betas + rnorm(nrow(dt), 0, 1)
vec.sim[i] <- mean(dt$Y) - (coef(lm(Y ~ X1, dt))[1] + betas[2] * table(dt$X1)[2]/nrow(dt) + betas[3] * table(dt$X1)[3]/nrow(dt))
}
hist(vec.sim)
mean(vec.sim)
[1] -0.003418483
Edit: As noted in the comments, we should really be using the coefficient estimates from the model, and doing so will then make the calculation exact:
> coef(lm(Y ~ X1, dt))[1] + coef(lm(Y ~ X1, dt))[2] * table(dt$X1)[2]/nrow(dt) + coef(lm(Y ~ X1, dt))[3] * table(dt$X1)[3]/nrow(dt)
(Intercept)
7.232203
|
Which categorical variable encoding should I use if I want the model intercept to have the interpret
If the data are balanced, then deviation coding should work.
Let's look at a simple example:
set.seed(13)
dt <- expand.grid(X1 = LETTERS[1:3], reps = 1:5)
X <- model.matrix(~ X1, dt)
betas <- c(3, 1,
|
39,865
|
What are the steps to simulate data for a linear model with random slopes and random intercepts
|
The general approach to simulating data for a mixed model is as follows:
Create the variable(s) for the fixed effects
Create the variable(s) for the group(s)
The fixed effects coefficients will be supplied / given and these will be a column vector $\beta$
Create a model matrix, $X$, for the fixed effects
Simulate the random effects from the given variances and covariances. In mixed model theory these are typically multivariate normal, but there is no requirement for this when we are simulating the data.
Create a model matrix, $Z$, for the random effects
Simulate a residual error, $e$, from some distribution. This is typically a normally distributed variable with a given (constant) variance, but again, when we are simulating the data we could use any distribution we want, and the variance could be a function of the fixed effects, or they could be autocorrelated, or based on a more complex process.
Use the general mixed model formula: $y = X \beta + Zu + e$ to simulate the outcome $y$
This completes the necessary steps to simulate data for a mixed model.
The above steps are deliberately general. Unfortunately the devil is in the details. Step 6, in particular can be very tricky. The only way to properly understand it all, is to actually do it. I will go through an example from start to finish with a small dataset, without the need for any software or package. To start, let us have:
One grouping variable, $G$, with 3 levels A, B and C
A fixed effect for $a$, a continuous variable, taking the values from 1 to 4.
Random intercepts for $G$, and random slopes for $a$ with a correlation between them of $\rho$
A balanced design such that each group has every value of $a$ exactly once, so that we have 12 observations in total.
Following the steps above, step 1 and 2, the dataset will be:
G a
1 A 1
2 B 1
3 C 1
4 A 2
5 B 2
6 C 2
7 A 3
8 B 3
9 C 3
10 A 4
11 B 4
12 C 4
In step 3 we have the fixed effects coefficients. Here we will fit a fixed intercept as well as the fixed effect for $a$, so there will be two values, let us say they are 3.1 and 1.8. Thus
$$
\beta = \begin{bmatrix}
3.1 \\
1.8
\end{bmatrix}
$$
In step 4, we form the model matrix $X$ for the fixed effects. The purpose of this is to map the fixed effect coefficients to the outcome variable. Each row of $X$ will multiple $\beta$, to give a single contribution to the outcome $y$. So the first column of $X$ will be all 1s for the intercept, so that each row gets the same value (3.1) for the intercept and the 2nd column will contain the values of $a$ which will be multiplied by the fixed effect coefficient for $a$ (1.8). Thus we will have:
$$
X = \begin{bmatrix}
1 & 1 \\
1 & 1 \\
1 & 1 \\
1 & 2 \\
1 & 2 \\
1 & 2 \\
1 & 3 \\
1 & 3 \\
1 & 3 \\
1 & 4 \\
1 & 4 \\
1 & 4
\end{bmatrix}
$$
It is then easy to see that when we form the product $X\beta$, $X$ maps the correct values into the result. For example for row 1, we will have $1 \times 3.1 + 1 \times 1.8 = 4.9$ and for the last row we will have $1 \times 3.1 + 4 \times 1.8 = 10.3$
In step 5 we simulate the random effects. For simplicity, let us assume they will follow a multivariate normal distribution. Let us say that the random intercepts will have variance of 2.1 and the random slopes will have a variance of 1.8, with a correlation, $\rho$, of 0.5 between them and both will have a mean of zero. Then the random effects will be distributed:
$$
u \sim \mathcal{N}\left(0, \begin{bmatrix}
2.1 & 0.5\\
0.5 & 1.8
\end{bmatrix} \right)
$$
So we need to sample 3 times from this distribution (corresponding to the 3 levels in our grouping variable, $G$), and let us say that we obtain:
$$
u = \begin{bmatrix}
2.4 & 0.8 \\
-0.9 & 1.3 \\
-1.5 & -2.1
\end{bmatrix}
$$
where the first column will be the random intercepts, let's call it $u_1$ and the 2nd column will be the random slopes, let's call it $u_2$
Now for the tricky part. In step 6 we form the model matrix $Z$ for the random effects. As with $X$ the purpose of this matrix is to map the correct values of the random effects $u$ to the outcome for each row in the data. Since we have 1 grouping variable (random intercepts) and one random slopes variable it is convenient to split $Z$ into 2. First we consider the random intercepts. Each group has it's own intercept and these are in $u_1$:
$$
u_1 = \begin{bmatrix}
2.4 \\
-0.9 \\
-1.5
\end{bmatrix}
$$
So group A has an intercept of 2.4, group B has an intercept of -0.9 and group C has an intercept of -1.5. Now we need to bear in mind the structure of the dataset. It is reproduced again here:
G a
1 A 1
2 B 1
3 C 1
4 A 2
5 B 2
6 C 2
7 A 3
8 B 3
9 C 3
10 A 4
11 B 4
12 C 4
It should therefore be easy to see, that $Z_1$ has to have the following structure to match that of the dataset and map the correct values into the result:
$$
Z_1= \begin{bmatrix}
1 & 0 & 0 \\
0 & 1 & 0 \\
0 & 0 & 1 \\
1 & 0 & 0 \\
0 & 1 & 0 \\
0 & 0 & 1 \\
1 & 0 & 0 \\
0 & 1 & 0 \\
0 & 0 & 1 \\
1 & 0 & 0 \\
0 & 1 & 0 \\
0 & 0 & 1
\end{bmatrix}
$$
so that when we form the product $Z_1 u_1$, we get, for example, for the first row (group A) $(2.4 \times 1) + (-1.9 \times 0) + (-1.5 \times 0) = 2.4$ and likewise for rows 4, 7 and 10. Applying the same logic for groups B and C we can see that they always receive -0.9 and -1.5 respectively.
For the random slopes things get a little more tricky. We have
$$
u_2 = \begin{bmatrix}
0.8 \\
1.3 \\
-2.1
\end{bmatrix}
$$
So the random slope for group A for variable $a$ is 0.8. This is a linear slope so it means that the values of $a$ must be multiplied by 0.8. For group B the values of $a$ must be multipled by 1.3 and for group C they must be multiplied by -2.1. Again, noting the structure of the dataset above, $Z_2$ will accomplish this mapping with the following structure:
$$
Z_2 = \begin{bmatrix}
1 & 0 & 0 \\
0 & 1 & 0 \\
0 & 0 & 1 \\
2 & 0 & 0 \\
0 & 2 & 0 \\
0 & 0 & 2 \\
3 & 0 & 0 \\
0 & 3 & 0 \\
0 & 0 & 3 \\
4 & 0 & 0 \\
0 & 4 & 0 \\
0 & 0 & 4
\end{bmatrix}
$$
If we again consider group A which has a random slope of 0.8, the first row, when $a=1$, contributes $0.8 \times 1 + 1.3 \times 0 + (-2.1 \times 0) = 0.8 $, the 4th row, when $a=2$, contributes $0.8 \times 2 + 1.3 \times 0 + (-2.1 \times 0) = 1.6 $, the 7th row, when $a=3$, contributes $0.8 \times 3 + 1.3 \times 0 + (-2.1 \times 0) = 2.4 $ and the 10th row, when $a=4$, contributes $0.8 \times 4 + 1.3 \times 0 + (-2.1 \times 0) = 3.2 $ . Again the same logic applies for groups B and C.
If we wish we could combine $Z_1$ and $Z_2$ to form $Z$ and $u_1$ and $u_2$ to form $u$, and this could be done in many ways. But all we really have to do to complete the simulation is to sample from some distribution to obtain $e$ and then compute $y = X\beta + Z_1u_1 + Z_2u_2 + e$
Edit: to address Erik's request for R code to demonstrate the above.
I would never suggest to form $Z$ by hand / from scratch in all but the simplest of models. But here I will do so, and also check that the resulting data are constent with using software to create $Z$
set.seed(15)
n.group <- 3 #number of groups
dt <- expand.grid(G = LETTERS[1:n.group], a = 1:4)
X <- model.matrix(~ a, dt) # model matrix for fixed effects
betas <- c(3.1, 1.8) # fixed effects coefficient vector
Z1 <- model.matrix(~ 0 + G, dt) # model matrix for random intercepts
Z2 <- model.matrix(~ 0 + G, dt) * dt$a # model matrix for random slopes
Here I have created $Z_1$ and $Z_2$, "manually" as per the main part of my answer.
s1 <- 2.1 # SD of random intercepts
s2 <- 1.8 # SD of random slopes
rho <- 0.5 # correlation between intercepts and slopes
cormat <- matrix(c(s1, rho, rho, s2), 2, 2) # correlation matrix
covmat <- lme4::sdcor2cov(cormat) # covariance matrix (needed for mvrnorm)
umat <- MASS::mvrnorm(n.group, c(0, 0), covmat, empirical = TRUE) # simulate the random effects
u1 <- umat[, 1]
u2 <- umat[, 2]
e <- rnorm(nrow(dt), 0, 2) # residual error
dt$Y_manual <- X %*% betas + Z1 %*% u1 + Z2 %*% u2 + e
So we have simulated Y from manually created $Z$ matrices
Now let's use lme4 to create $Z$
library(lme4)
lForm <- lFormula(Y_manual ~ a + (a|G), dt) # lme4's function to process a model formula
Z <- t(as.matrix(lForm$reTrms$Zt)) # extract the Z matrix
u <- c(rbind(umat[, 1], umat[, 2])) # lme4 needs the random effects in this order: interleaved)
dt$Y <- X %*% betas + Z %*% u + e
dt
G a Y Y_manual
1 A 1 4.347903 4.347903
2 B 1 4.039412 4.039412
3 C 1 8.275563 8.275563
4 A 2 4.788965 4.788965
5 B 2 3.301834 3.301834
6 C 2 10.839260 10.839260
7 A 3 9.906717 9.906717
8 B 3 -1.159811 -1.159811
9 C 3 17.517209 17.517209
10 A 4 12.205023 12.205023
11 B 4 1.017939 1.017939
12 C 4 17.692258 17.692258
So as we can see, we obtain exactly the same simulated values for the outcome with the manual method and by using lme4's lFormula function
Now let's try actually fitting the model:
m0 <- lmer(Y ~ a + (a|G), dt)
summary(m0)
Random effects:
Groups Name Variance Std.Dev. Corr
G (Intercept) 1.852 1.361
a 6.338 2.518 -0.44
Residual 3.038 1.743
Number of obs: 12, groups: G, 3
Fixed effects:
Estimate Std. Error t value
(Intercept) 3.557 1.462 2.433
a 1.670 1.522 1.097
Surprisingly it converges without warning and the estimates are not too bad considering the sample size !
|
What are the steps to simulate data for a linear model with random slopes and random intercepts
|
The general approach to simulating data for a mixed model is as follows:
Create the variable(s) for the fixed effects
Create the variable(s) for the group(s)
The fixed effects coefficients will be su
|
What are the steps to simulate data for a linear model with random slopes and random intercepts
The general approach to simulating data for a mixed model is as follows:
Create the variable(s) for the fixed effects
Create the variable(s) for the group(s)
The fixed effects coefficients will be supplied / given and these will be a column vector $\beta$
Create a model matrix, $X$, for the fixed effects
Simulate the random effects from the given variances and covariances. In mixed model theory these are typically multivariate normal, but there is no requirement for this when we are simulating the data.
Create a model matrix, $Z$, for the random effects
Simulate a residual error, $e$, from some distribution. This is typically a normally distributed variable with a given (constant) variance, but again, when we are simulating the data we could use any distribution we want, and the variance could be a function of the fixed effects, or they could be autocorrelated, or based on a more complex process.
Use the general mixed model formula: $y = X \beta + Zu + e$ to simulate the outcome $y$
This completes the necessary steps to simulate data for a mixed model.
The above steps are deliberately general. Unfortunately the devil is in the details. Step 6, in particular can be very tricky. The only way to properly understand it all, is to actually do it. I will go through an example from start to finish with a small dataset, without the need for any software or package. To start, let us have:
One grouping variable, $G$, with 3 levels A, B and C
A fixed effect for $a$, a continuous variable, taking the values from 1 to 4.
Random intercepts for $G$, and random slopes for $a$ with a correlation between them of $\rho$
A balanced design such that each group has every value of $a$ exactly once, so that we have 12 observations in total.
Following the steps above, step 1 and 2, the dataset will be:
G a
1 A 1
2 B 1
3 C 1
4 A 2
5 B 2
6 C 2
7 A 3
8 B 3
9 C 3
10 A 4
11 B 4
12 C 4
In step 3 we have the fixed effects coefficients. Here we will fit a fixed intercept as well as the fixed effect for $a$, so there will be two values, let us say they are 3.1 and 1.8. Thus
$$
\beta = \begin{bmatrix}
3.1 \\
1.8
\end{bmatrix}
$$
In step 4, we form the model matrix $X$ for the fixed effects. The purpose of this is to map the fixed effect coefficients to the outcome variable. Each row of $X$ will multiple $\beta$, to give a single contribution to the outcome $y$. So the first column of $X$ will be all 1s for the intercept, so that each row gets the same value (3.1) for the intercept and the 2nd column will contain the values of $a$ which will be multiplied by the fixed effect coefficient for $a$ (1.8). Thus we will have:
$$
X = \begin{bmatrix}
1 & 1 \\
1 & 1 \\
1 & 1 \\
1 & 2 \\
1 & 2 \\
1 & 2 \\
1 & 3 \\
1 & 3 \\
1 & 3 \\
1 & 4 \\
1 & 4 \\
1 & 4
\end{bmatrix}
$$
It is then easy to see that when we form the product $X\beta$, $X$ maps the correct values into the result. For example for row 1, we will have $1 \times 3.1 + 1 \times 1.8 = 4.9$ and for the last row we will have $1 \times 3.1 + 4 \times 1.8 = 10.3$
In step 5 we simulate the random effects. For simplicity, let us assume they will follow a multivariate normal distribution. Let us say that the random intercepts will have variance of 2.1 and the random slopes will have a variance of 1.8, with a correlation, $\rho$, of 0.5 between them and both will have a mean of zero. Then the random effects will be distributed:
$$
u \sim \mathcal{N}\left(0, \begin{bmatrix}
2.1 & 0.5\\
0.5 & 1.8
\end{bmatrix} \right)
$$
So we need to sample 3 times from this distribution (corresponding to the 3 levels in our grouping variable, $G$), and let us say that we obtain:
$$
u = \begin{bmatrix}
2.4 & 0.8 \\
-0.9 & 1.3 \\
-1.5 & -2.1
\end{bmatrix}
$$
where the first column will be the random intercepts, let's call it $u_1$ and the 2nd column will be the random slopes, let's call it $u_2$
Now for the tricky part. In step 6 we form the model matrix $Z$ for the random effects. As with $X$ the purpose of this matrix is to map the correct values of the random effects $u$ to the outcome for each row in the data. Since we have 1 grouping variable (random intercepts) and one random slopes variable it is convenient to split $Z$ into 2. First we consider the random intercepts. Each group has it's own intercept and these are in $u_1$:
$$
u_1 = \begin{bmatrix}
2.4 \\
-0.9 \\
-1.5
\end{bmatrix}
$$
So group A has an intercept of 2.4, group B has an intercept of -0.9 and group C has an intercept of -1.5. Now we need to bear in mind the structure of the dataset. It is reproduced again here:
G a
1 A 1
2 B 1
3 C 1
4 A 2
5 B 2
6 C 2
7 A 3
8 B 3
9 C 3
10 A 4
11 B 4
12 C 4
It should therefore be easy to see, that $Z_1$ has to have the following structure to match that of the dataset and map the correct values into the result:
$$
Z_1= \begin{bmatrix}
1 & 0 & 0 \\
0 & 1 & 0 \\
0 & 0 & 1 \\
1 & 0 & 0 \\
0 & 1 & 0 \\
0 & 0 & 1 \\
1 & 0 & 0 \\
0 & 1 & 0 \\
0 & 0 & 1 \\
1 & 0 & 0 \\
0 & 1 & 0 \\
0 & 0 & 1
\end{bmatrix}
$$
so that when we form the product $Z_1 u_1$, we get, for example, for the first row (group A) $(2.4 \times 1) + (-1.9 \times 0) + (-1.5 \times 0) = 2.4$ and likewise for rows 4, 7 and 10. Applying the same logic for groups B and C we can see that they always receive -0.9 and -1.5 respectively.
For the random slopes things get a little more tricky. We have
$$
u_2 = \begin{bmatrix}
0.8 \\
1.3 \\
-2.1
\end{bmatrix}
$$
So the random slope for group A for variable $a$ is 0.8. This is a linear slope so it means that the values of $a$ must be multiplied by 0.8. For group B the values of $a$ must be multipled by 1.3 and for group C they must be multiplied by -2.1. Again, noting the structure of the dataset above, $Z_2$ will accomplish this mapping with the following structure:
$$
Z_2 = \begin{bmatrix}
1 & 0 & 0 \\
0 & 1 & 0 \\
0 & 0 & 1 \\
2 & 0 & 0 \\
0 & 2 & 0 \\
0 & 0 & 2 \\
3 & 0 & 0 \\
0 & 3 & 0 \\
0 & 0 & 3 \\
4 & 0 & 0 \\
0 & 4 & 0 \\
0 & 0 & 4
\end{bmatrix}
$$
If we again consider group A which has a random slope of 0.8, the first row, when $a=1$, contributes $0.8 \times 1 + 1.3 \times 0 + (-2.1 \times 0) = 0.8 $, the 4th row, when $a=2$, contributes $0.8 \times 2 + 1.3 \times 0 + (-2.1 \times 0) = 1.6 $, the 7th row, when $a=3$, contributes $0.8 \times 3 + 1.3 \times 0 + (-2.1 \times 0) = 2.4 $ and the 10th row, when $a=4$, contributes $0.8 \times 4 + 1.3 \times 0 + (-2.1 \times 0) = 3.2 $ . Again the same logic applies for groups B and C.
If we wish we could combine $Z_1$ and $Z_2$ to form $Z$ and $u_1$ and $u_2$ to form $u$, and this could be done in many ways. But all we really have to do to complete the simulation is to sample from some distribution to obtain $e$ and then compute $y = X\beta + Z_1u_1 + Z_2u_2 + e$
Edit: to address Erik's request for R code to demonstrate the above.
I would never suggest to form $Z$ by hand / from scratch in all but the simplest of models. But here I will do so, and also check that the resulting data are constent with using software to create $Z$
set.seed(15)
n.group <- 3 #number of groups
dt <- expand.grid(G = LETTERS[1:n.group], a = 1:4)
X <- model.matrix(~ a, dt) # model matrix for fixed effects
betas <- c(3.1, 1.8) # fixed effects coefficient vector
Z1 <- model.matrix(~ 0 + G, dt) # model matrix for random intercepts
Z2 <- model.matrix(~ 0 + G, dt) * dt$a # model matrix for random slopes
Here I have created $Z_1$ and $Z_2$, "manually" as per the main part of my answer.
s1 <- 2.1 # SD of random intercepts
s2 <- 1.8 # SD of random slopes
rho <- 0.5 # correlation between intercepts and slopes
cormat <- matrix(c(s1, rho, rho, s2), 2, 2) # correlation matrix
covmat <- lme4::sdcor2cov(cormat) # covariance matrix (needed for mvrnorm)
umat <- MASS::mvrnorm(n.group, c(0, 0), covmat, empirical = TRUE) # simulate the random effects
u1 <- umat[, 1]
u2 <- umat[, 2]
e <- rnorm(nrow(dt), 0, 2) # residual error
dt$Y_manual <- X %*% betas + Z1 %*% u1 + Z2 %*% u2 + e
So we have simulated Y from manually created $Z$ matrices
Now let's use lme4 to create $Z$
library(lme4)
lForm <- lFormula(Y_manual ~ a + (a|G), dt) # lme4's function to process a model formula
Z <- t(as.matrix(lForm$reTrms$Zt)) # extract the Z matrix
u <- c(rbind(umat[, 1], umat[, 2])) # lme4 needs the random effects in this order: interleaved)
dt$Y <- X %*% betas + Z %*% u + e
dt
G a Y Y_manual
1 A 1 4.347903 4.347903
2 B 1 4.039412 4.039412
3 C 1 8.275563 8.275563
4 A 2 4.788965 4.788965
5 B 2 3.301834 3.301834
6 C 2 10.839260 10.839260
7 A 3 9.906717 9.906717
8 B 3 -1.159811 -1.159811
9 C 3 17.517209 17.517209
10 A 4 12.205023 12.205023
11 B 4 1.017939 1.017939
12 C 4 17.692258 17.692258
So as we can see, we obtain exactly the same simulated values for the outcome with the manual method and by using lme4's lFormula function
Now let's try actually fitting the model:
m0 <- lmer(Y ~ a + (a|G), dt)
summary(m0)
Random effects:
Groups Name Variance Std.Dev. Corr
G (Intercept) 1.852 1.361
a 6.338 2.518 -0.44
Residual 3.038 1.743
Number of obs: 12, groups: G, 3
Fixed effects:
Estimate Std. Error t value
(Intercept) 3.557 1.462 2.433
a 1.670 1.522 1.097
Surprisingly it converges without warning and the estimates are not too bad considering the sample size !
|
What are the steps to simulate data for a linear model with random slopes and random intercepts
The general approach to simulating data for a mixed model is as follows:
Create the variable(s) for the fixed effects
Create the variable(s) for the group(s)
The fixed effects coefficients will be su
|
39,866
|
Probability that linear combination of normal random variables exceeds a value
|
If you're looking for an analytic solution, this is what you should do. Start by defining a new variable
$$ X = 2Y_1 + 4Y_2 - 3Y_3$$
A sum of jointly normal random variables is also normal, even if the variables are not independent (see Wikipedia article here). All that remains is to compute the mean and variance.
The mean of $X$ can be determined as
\begin{align*}
E[X] &= 2 E[Y_1] + 4 E[Y_2] - 3 E[Y_3] \\
&= (2 \times 10) + (4 \times 12)-(3 \times 14) \\
&= 26
\end{align*}
The variance of $X$ is slightly easier to write in matrix form. Let $Y \equiv (Y_1,Y_2,Y_3)$ and $\omega \equiv (2,4,-3)$ be vectors of random variables and weights, respectively. The variance is given by
$$ Var(X) = Var(\omega'Y) = \omega'Var(Y)\omega$$
Numerically this is equal to
$$ Var(X) = \begin{bmatrix} 2 & 4 & -3 \end{bmatrix} \begin{bmatrix} 2& .5 & -.75 \\ .5 & 2 & 0 \\ -.75 & 0 & 8 \end{bmatrix} \begin{bmatrix} 2 \\ 4 \\ -3 \end{bmatrix}= 129$$
If $\Phi$ is the CDF of a standard normal,
\begin{align*}
P(X > 40) &= 1-P\left( X \le 40 \right) \\
&= 1-P\left( \frac{X - E[X]}{\sqrt{Var(X)}} \le \frac{40 - E[X]}{\sqrt{Var(X)}} \right) \\
&= 1-P\left( Z \le \frac{40 - E[X]}{\sqrt{Var(X)}} \right) \\
&= 1-\Phi\left( \frac{40 - E[X]}{\sqrt{Var(X)}} \right) \\
&= 0.108867
\end{align*}
|
Probability that linear combination of normal random variables exceeds a value
|
If you're looking for an analytic solution, this is what you should do. Start by defining a new variable
$$ X = 2Y_1 + 4Y_2 - 3Y_3$$
A sum of jointly normal random variables is also normal, even if th
|
Probability that linear combination of normal random variables exceeds a value
If you're looking for an analytic solution, this is what you should do. Start by defining a new variable
$$ X = 2Y_1 + 4Y_2 - 3Y_3$$
A sum of jointly normal random variables is also normal, even if the variables are not independent (see Wikipedia article here). All that remains is to compute the mean and variance.
The mean of $X$ can be determined as
\begin{align*}
E[X] &= 2 E[Y_1] + 4 E[Y_2] - 3 E[Y_3] \\
&= (2 \times 10) + (4 \times 12)-(3 \times 14) \\
&= 26
\end{align*}
The variance of $X$ is slightly easier to write in matrix form. Let $Y \equiv (Y_1,Y_2,Y_3)$ and $\omega \equiv (2,4,-3)$ be vectors of random variables and weights, respectively. The variance is given by
$$ Var(X) = Var(\omega'Y) = \omega'Var(Y)\omega$$
Numerically this is equal to
$$ Var(X) = \begin{bmatrix} 2 & 4 & -3 \end{bmatrix} \begin{bmatrix} 2& .5 & -.75 \\ .5 & 2 & 0 \\ -.75 & 0 & 8 \end{bmatrix} \begin{bmatrix} 2 \\ 4 \\ -3 \end{bmatrix}= 129$$
If $\Phi$ is the CDF of a standard normal,
\begin{align*}
P(X > 40) &= 1-P\left( X \le 40 \right) \\
&= 1-P\left( \frac{X - E[X]}{\sqrt{Var(X)}} \le \frac{40 - E[X]}{\sqrt{Var(X)}} \right) \\
&= 1-P\left( Z \le \frac{40 - E[X]}{\sqrt{Var(X)}} \right) \\
&= 1-\Phi\left( \frac{40 - E[X]}{\sqrt{Var(X)}} \right) \\
&= 0.108867
\end{align*}
|
Probability that linear combination of normal random variables exceeds a value
If you're looking for an analytic solution, this is what you should do. Start by defining a new variable
$$ X = 2Y_1 + 4Y_2 - 3Y_3$$
A sum of jointly normal random variables is also normal, even if th
|
39,867
|
Probability that linear combination of normal random variables exceeds a value
|
You can obtain the mean and variance of the resulting linear combination or you can also do a simulation and obtain the results.
Via simulation.
> covmat=matrix(c(2,0.5,-0.75,0.5,2,0,-0.75,0,8),nrow=3)
> is.positive.definite(x, tol=1e-8)
[1] TRUE
> means=c(10,12,14)
> weights=c(2,4,-3)
> mat=mvrnorm(10^7,means,covmat)
> mat=mat %*% weights
> result=sum(mat>40)/10^7
> result
[1] 0.1088587
Non simulated
The mean is a linear combination of means
> new_mean= means %*% weights
> new_mean
[1] 26
The variance is obtained multiplying
> weights %*% covmat %*% weights
[,1]
[1,] 129
So your result is
> 1-pnorm(40,26,sqrt(129))
[1] 0.1088567
|
Probability that linear combination of normal random variables exceeds a value
|
You can obtain the mean and variance of the resulting linear combination or you can also do a simulation and obtain the results.
Via simulation.
> covmat=matrix(c(2,0.5,-0.75,0.5,2,0,-0.75,0,8),nrow=3
|
Probability that linear combination of normal random variables exceeds a value
You can obtain the mean and variance of the resulting linear combination or you can also do a simulation and obtain the results.
Via simulation.
> covmat=matrix(c(2,0.5,-0.75,0.5,2,0,-0.75,0,8),nrow=3)
> is.positive.definite(x, tol=1e-8)
[1] TRUE
> means=c(10,12,14)
> weights=c(2,4,-3)
> mat=mvrnorm(10^7,means,covmat)
> mat=mat %*% weights
> result=sum(mat>40)/10^7
> result
[1] 0.1088587
Non simulated
The mean is a linear combination of means
> new_mean= means %*% weights
> new_mean
[1] 26
The variance is obtained multiplying
> weights %*% covmat %*% weights
[,1]
[1,] 129
So your result is
> 1-pnorm(40,26,sqrt(129))
[1] 0.1088567
|
Probability that linear combination of normal random variables exceeds a value
You can obtain the mean and variance of the resulting linear combination or you can also do a simulation and obtain the results.
Via simulation.
> covmat=matrix(c(2,0.5,-0.75,0.5,2,0,-0.75,0,8),nrow=3
|
39,868
|
reparameterization trick in VAEs, How should we do this?
|
We do this simply because the variance of a random variable is constrained to be positive (i.e. $\sigma^2 \in \mathbb{R}^+$) and so if we were to try to learn the variance we would have to constrain somehow the output of a neural network to be positive. A simple way around this is to learn the logarithm instead since $\log(\sigma^2) \in \mathbb{R}$ ensures that $\exp(\log(\sigma^2)) \in \mathbb{R}^+$.
The $\sigma$ in the first equation is the standard deviation which as you know is the square root of the variance. Then you can see that the multiplication of 0.5 outside the log equates to raising the variance inside of the log to the power of 0.5:
$$
e^{0.5\log(var)} = e^{\log(var^{0.5})} = var^{0.5} = \sigma
$$
Given the answer to (2) it should be clear they are the same.
|
reparameterization trick in VAEs, How should we do this?
|
We do this simply because the variance of a random variable is constrained to be positive (i.e. $\sigma^2 \in \mathbb{R}^+$) and so if we were to try to learn the variance we would have to constrain s
|
reparameterization trick in VAEs, How should we do this?
We do this simply because the variance of a random variable is constrained to be positive (i.e. $\sigma^2 \in \mathbb{R}^+$) and so if we were to try to learn the variance we would have to constrain somehow the output of a neural network to be positive. A simple way around this is to learn the logarithm instead since $\log(\sigma^2) \in \mathbb{R}$ ensures that $\exp(\log(\sigma^2)) \in \mathbb{R}^+$.
The $\sigma$ in the first equation is the standard deviation which as you know is the square root of the variance. Then you can see that the multiplication of 0.5 outside the log equates to raising the variance inside of the log to the power of 0.5:
$$
e^{0.5\log(var)} = e^{\log(var^{0.5})} = var^{0.5} = \sigma
$$
Given the answer to (2) it should be clear they are the same.
|
reparameterization trick in VAEs, How should we do this?
We do this simply because the variance of a random variable is constrained to be positive (i.e. $\sigma^2 \in \mathbb{R}^+$) and so if we were to try to learn the variance we would have to constrain s
|
39,869
|
power analysis for binomial test
|
In order to find 'power', you need to have a specific alternative in mind.
Suppose your null hypothesis is $H_0: p = 0.5$ vs. $H_a: p > 0.5,$ where
$p = P(\mathrm{Female}).$ Also suppose you have $n = 64$ and you want the power
of a test at level $\alpha = 0.05$ against the specific alternative $p = 0.6.$
For an exact binomial test, you need to find the critical value $c$ such
that $P(X \ge c\,|\,n=64, p=.5)$ is maximized, but still below $0.05.$ In R,
where dbinom, pbinom, and qbinom denote binomial PDF, CDF, and quantile function (inverse CDF), respectively, we see that the critical value is $c = 40.$ Notice that, because of
the discreteness of binomial distributions, the so-called `5% level' actually rejects with probability
$P(\mathrm{Rej}\, H_0 | H_0\, \mathrm{True}) \approx 3\%.$
qbinom(.95, 64, .5)
[1] 39
sum(dbinom(39:64, 64, .5))
[1] 0.05171094
sum(dbinom(40:64, 64, .5))
[1] 0.02997059
1 - pbinom(39, 64, .5)
[1] 0.02997059
Then the power of this test against alternative value $p = 0.6$ is given by
$P(X \ge 40\,|\,n=64, p=0.6) = 0.3927.$
1 - pbinom(39, 64, .6)
[1] 0.392654
We can make a 'power curve' for this test by looking at a sequence of
alternative values p.a between $0.5$ and $.75.$ The first block of
R code below makes the solid black line in the plot below.
p.a = seq(.50, .75, by=.01)
p.rej = 1 - pbinom(39, 64, p.a)
plot(p.a, p.rej, type="l", main="Power Curve")
abline(h=c(.03,1), col="green2")
If we look at a level $\alpha = 0.05$ test of $H_0: p = 0.5$ vs $H_a: p > 0.5$ with $n = 256$ subjects, then the critical value is $c = 141,$ the rejection probability when $H_0$ is true is $0.046,$ and the power against various
alternative values of $p$ is greater, as shown by the dotted blue line
in the figure.
c.256 = qbinom(.95, 256, .5); c.256
[1] 141
1 - pbinom(c.256, 256, .5)
[1] 0.04565604
p.rej.256 = 1 - pbinom(c.256, 256, p.a)
lines(p.a, p.rej.256, col="blue", lty="dotted")
Notes: Because $n = 64$ is sufficiently large to use normal approximations, you might want to try using normal approximations. A disadvantage is that this
ignores the issue of discreteness, so it may appear that your test rejects exactly 5% of the time when $H_0$ is true. Also, you'd need to use a continuity correction for
best results.
One relevant computation for the significance level in R is:
1 - pnorm(39.5, 32, 4)
[1] 0.03039636
(Approximate) power is $0.3895:$
mu.a = 64*.6; sg.a = sqrt(64*.6*.4)
mu.a; sg.a
[1] 38.4
[1] 3.919184
1 - pnorm(39.5, mu.a, sg.a) # Using NORM(mu.a, sg.a)
[1] 0.3894815
1 - pnorm((39.5 - mu.a)/sg.a) # Standardizing and using NORM(0,1).
[1] 0.3894815
|
power analysis for binomial test
|
In order to find 'power', you need to have a specific alternative in mind.
Suppose your null hypothesis is $H_0: p = 0.5$ vs. $H_a: p > 0.5,$ where
$p = P(\mathrm{Female}).$ Also suppose you have $n =
|
power analysis for binomial test
In order to find 'power', you need to have a specific alternative in mind.
Suppose your null hypothesis is $H_0: p = 0.5$ vs. $H_a: p > 0.5,$ where
$p = P(\mathrm{Female}).$ Also suppose you have $n = 64$ and you want the power
of a test at level $\alpha = 0.05$ against the specific alternative $p = 0.6.$
For an exact binomial test, you need to find the critical value $c$ such
that $P(X \ge c\,|\,n=64, p=.5)$ is maximized, but still below $0.05.$ In R,
where dbinom, pbinom, and qbinom denote binomial PDF, CDF, and quantile function (inverse CDF), respectively, we see that the critical value is $c = 40.$ Notice that, because of
the discreteness of binomial distributions, the so-called `5% level' actually rejects with probability
$P(\mathrm{Rej}\, H_0 | H_0\, \mathrm{True}) \approx 3\%.$
qbinom(.95, 64, .5)
[1] 39
sum(dbinom(39:64, 64, .5))
[1] 0.05171094
sum(dbinom(40:64, 64, .5))
[1] 0.02997059
1 - pbinom(39, 64, .5)
[1] 0.02997059
Then the power of this test against alternative value $p = 0.6$ is given by
$P(X \ge 40\,|\,n=64, p=0.6) = 0.3927.$
1 - pbinom(39, 64, .6)
[1] 0.392654
We can make a 'power curve' for this test by looking at a sequence of
alternative values p.a between $0.5$ and $.75.$ The first block of
R code below makes the solid black line in the plot below.
p.a = seq(.50, .75, by=.01)
p.rej = 1 - pbinom(39, 64, p.a)
plot(p.a, p.rej, type="l", main="Power Curve")
abline(h=c(.03,1), col="green2")
If we look at a level $\alpha = 0.05$ test of $H_0: p = 0.5$ vs $H_a: p > 0.5$ with $n = 256$ subjects, then the critical value is $c = 141,$ the rejection probability when $H_0$ is true is $0.046,$ and the power against various
alternative values of $p$ is greater, as shown by the dotted blue line
in the figure.
c.256 = qbinom(.95, 256, .5); c.256
[1] 141
1 - pbinom(c.256, 256, .5)
[1] 0.04565604
p.rej.256 = 1 - pbinom(c.256, 256, p.a)
lines(p.a, p.rej.256, col="blue", lty="dotted")
Notes: Because $n = 64$ is sufficiently large to use normal approximations, you might want to try using normal approximations. A disadvantage is that this
ignores the issue of discreteness, so it may appear that your test rejects exactly 5% of the time when $H_0$ is true. Also, you'd need to use a continuity correction for
best results.
One relevant computation for the significance level in R is:
1 - pnorm(39.5, 32, 4)
[1] 0.03039636
(Approximate) power is $0.3895:$
mu.a = 64*.6; sg.a = sqrt(64*.6*.4)
mu.a; sg.a
[1] 38.4
[1] 3.919184
1 - pnorm(39.5, mu.a, sg.a) # Using NORM(mu.a, sg.a)
[1] 0.3894815
1 - pnorm((39.5 - mu.a)/sg.a) # Standardizing and using NORM(0,1).
[1] 0.3894815
|
power analysis for binomial test
In order to find 'power', you need to have a specific alternative in mind.
Suppose your null hypothesis is $H_0: p = 0.5$ vs. $H_a: p > 0.5,$ where
$p = P(\mathrm{Female}).$ Also suppose you have $n =
|
39,870
|
power analysis for binomial test
|
It's also important to ask yourself why you are calculating the power. Since you already have the data, you are calculating a 'post-hoc' power statistic (as opposed to a pre-hoc power statistic). It's worth nothing that a number of authors have criticised the use of post-hoc power statistics from a Frequentist point of view - see, for example, https://gpsych.bmj.com/content/32/4/e100069
|
power analysis for binomial test
|
It's also important to ask yourself why you are calculating the power. Since you already have the data, you are calculating a 'post-hoc' power statistic (as opposed to a pre-hoc power statistic). It
|
power analysis for binomial test
It's also important to ask yourself why you are calculating the power. Since you already have the data, you are calculating a 'post-hoc' power statistic (as opposed to a pre-hoc power statistic). It's worth nothing that a number of authors have criticised the use of post-hoc power statistics from a Frequentist point of view - see, for example, https://gpsych.bmj.com/content/32/4/e100069
|
power analysis for binomial test
It's also important to ask yourself why you are calculating the power. Since you already have the data, you are calculating a 'post-hoc' power statistic (as opposed to a pre-hoc power statistic). It
|
39,871
|
Can adding a random intercept change the fixed effect estimates in a regression model?
|
Yes.
This is an example of Simpson's paradox. There are already plenty of resources online explaining Simpson's paradox, so I won't go into it here.
To see this in action, let's look at simulated behavioural data where
Participants produce a response, $y$, in response to varying stimuli, $x$.
Participants' intercepts are normally distributed, $\alpha_p \sim N(0, 1)$;
Participants with higher intercepts are exposed to higher average values of $x$,
$\bar x_p = 2\times \alpha_p$.
Responses $y$ are drawn from the distribution $y \sim N(\alpha_p - .5\times(x - \bar x_p), 1)$
library(tidyverse)
library(lme4)
n_subj = 5
n_trials = 20
subj_intercepts = rnorm(n_subj, 0, 1) # Varying intercepts
subj_slopes = rep(-.5, n_subj) # Everyone has same slope
subj_mx = subj_intercepts*2 # Mean stimulus depends on intercept
# Simulate data
data = data.frame(subject = rep(1:n_subj, each=n_trials),
intercept = rep(subj_intercepts, each=n_trials),
slope = rep(subj_slopes, each=n_trials),
mx = rep(subj_mx, each=n_trials)) %>%
mutate(
x = rnorm(n(), mx, 1),
y = intercept + (x-mx)*slope + rnorm(n(), 0, 1))
# subject_means = data %>%
# group_by(subject) %>%
# summarise_if(is.numeric, mean)
# subject_means %>% select(intercept, slope, x, y) %>% plot()
# Plot
ggplot(data, aes(x, y, color=factor(subject))) +
geom_point() +
stat_smooth(method='lm', se=F) +
stat_smooth(group=1, method='lm', color='black') +
labs(x='Stimulus', y='Response', color='Subject') +
theme_bw(base_size = 18)
Black line shows regression line collapsing across subjects.
Coloured lines show individual subjects' regression lines.
Note that slope is the same for all subjects ---
apparent differences in the plot are due to noise.
# Model without random intercept
lm(y ~ x, data=data) %>% summary() %>% coef()
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) -0.1851366 0.16722764 -1.107093 2.709636e-01
## x 0.2952649 0.05825209 5.068743 1.890403e-06
# With random intercept
lmer(y ~ x + (1|subject), data=data) %>% summary() %>% coef()
## Estimate Std. Error t value
## (Intercept) -1.4682938 1.20586337 -1.217629
## x -0.5740137 0.09277143 -6.187397
|
Can adding a random intercept change the fixed effect estimates in a regression model?
|
Yes.
This is an example of Simpson's paradox. There are already plenty of resources online explaining Simpson's paradox, so I won't go into it here.
To see this in action, let's look at simulated beha
|
Can adding a random intercept change the fixed effect estimates in a regression model?
Yes.
This is an example of Simpson's paradox. There are already plenty of resources online explaining Simpson's paradox, so I won't go into it here.
To see this in action, let's look at simulated behavioural data where
Participants produce a response, $y$, in response to varying stimuli, $x$.
Participants' intercepts are normally distributed, $\alpha_p \sim N(0, 1)$;
Participants with higher intercepts are exposed to higher average values of $x$,
$\bar x_p = 2\times \alpha_p$.
Responses $y$ are drawn from the distribution $y \sim N(\alpha_p - .5\times(x - \bar x_p), 1)$
library(tidyverse)
library(lme4)
n_subj = 5
n_trials = 20
subj_intercepts = rnorm(n_subj, 0, 1) # Varying intercepts
subj_slopes = rep(-.5, n_subj) # Everyone has same slope
subj_mx = subj_intercepts*2 # Mean stimulus depends on intercept
# Simulate data
data = data.frame(subject = rep(1:n_subj, each=n_trials),
intercept = rep(subj_intercepts, each=n_trials),
slope = rep(subj_slopes, each=n_trials),
mx = rep(subj_mx, each=n_trials)) %>%
mutate(
x = rnorm(n(), mx, 1),
y = intercept + (x-mx)*slope + rnorm(n(), 0, 1))
# subject_means = data %>%
# group_by(subject) %>%
# summarise_if(is.numeric, mean)
# subject_means %>% select(intercept, slope, x, y) %>% plot()
# Plot
ggplot(data, aes(x, y, color=factor(subject))) +
geom_point() +
stat_smooth(method='lm', se=F) +
stat_smooth(group=1, method='lm', color='black') +
labs(x='Stimulus', y='Response', color='Subject') +
theme_bw(base_size = 18)
Black line shows regression line collapsing across subjects.
Coloured lines show individual subjects' regression lines.
Note that slope is the same for all subjects ---
apparent differences in the plot are due to noise.
# Model without random intercept
lm(y ~ x, data=data) %>% summary() %>% coef()
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) -0.1851366 0.16722764 -1.107093 2.709636e-01
## x 0.2952649 0.05825209 5.068743 1.890403e-06
# With random intercept
lmer(y ~ x + (1|subject), data=data) %>% summary() %>% coef()
## Estimate Std. Error t value
## (Intercept) -1.4682938 1.20586337 -1.217629
## x -0.5740137 0.09277143 -6.187397
|
Can adding a random intercept change the fixed effect estimates in a regression model?
Yes.
This is an example of Simpson's paradox. There are already plenty of resources online explaining Simpson's paradox, so I won't go into it here.
To see this in action, let's look at simulated beha
|
39,872
|
Can adding a random intercept change the fixed effect estimates in a regression model?
|
The accepted answer is absolutely correct but the degree of change in the fixed effect with the inclusion of the random effect can be very sensitive to the number of repeated measurements per subject. For instance, in my own analysis (data plotted below), the inclusion of a random intercept does not change the slope of the fixed effect (2 trials per subject). But by artificially enlarging the number of trial per subject by binding a clone of the observed data to itself (4 trials per subject), the effect described above is observed.
|
Can adding a random intercept change the fixed effect estimates in a regression model?
|
The accepted answer is absolutely correct but the degree of change in the fixed effect with the inclusion of the random effect can be very sensitive to the number of repeated measurements per subject.
|
Can adding a random intercept change the fixed effect estimates in a regression model?
The accepted answer is absolutely correct but the degree of change in the fixed effect with the inclusion of the random effect can be very sensitive to the number of repeated measurements per subject. For instance, in my own analysis (data plotted below), the inclusion of a random intercept does not change the slope of the fixed effect (2 trials per subject). But by artificially enlarging the number of trial per subject by binding a clone of the observed data to itself (4 trials per subject), the effect described above is observed.
|
Can adding a random intercept change the fixed effect estimates in a regression model?
The accepted answer is absolutely correct but the degree of change in the fixed effect with the inclusion of the random effect can be very sensitive to the number of repeated measurements per subject.
|
39,873
|
Cross entropy vs KL divergence: What's minimized directly in practice?
|
Let $q$ be the density of your true data-generating process and $f_\theta$ be your model-density.
Then $$KL(q||f_\theta) = \int q(x) log\left(\frac{q(x)}{f_\theta(x)}\right)dx = -\int q(x) \log(f_\theta(x))dx + \int q(x) \log(q(x)) dx$$
The first term is the Cross Entropy $H(q, f_\theta)$ and the second term is the (differential) entropy $H(q)$. Note that the second term does NOT depend on $\theta$ and therefore you cannot influence it anyway. Therfore minimizing either Cross-Entropy or KL-divergence is equivalent.
Without looking at the formula you can understand it the following informal way (if you assume a discrete distribution). The entropy $H(q)$ encodes how many bits you need if you encode the signal that comes from the distribution $q$ in an optimal way. The Cross-Entropy $H(q, f_\theta)$ encodes how many bits on average you would need when you encoded the singal that comes from a distribution $q$ using the optimal coding scheme for $f_\theta$. This decomposes into the Entropy $H(q)$ + $KL(q||f_\theta)$. The KL-divergence therefore measures how many additional bits you need if you use an optimal coding scheme for distribution $f_\theta$ (i.e. you assume your data comes from $f_\theta$ while it is actually generated from $q$). This also explains why it has to be positive. You cannot be better than the optimal coding scheme that yields the average bit-length $H(q)$.
This illustrates in an informal way why minimizing KL-divergence is equivalent to minimizing CE: By minimzing how many more bits you need than the optimal coding scheme (on average) you of course also minimize the total amount of bits you need (on average)
The following post illustrates the idea with the optimal coding scheme: Qualitively what is Cross Entropy
|
Cross entropy vs KL divergence: What's minimized directly in practice?
|
Let $q$ be the density of your true data-generating process and $f_\theta$ be your model-density.
Then $$KL(q||f_\theta) = \int q(x) log\left(\frac{q(x)}{f_\theta(x)}\right)dx = -\int q(x) \log(f_\the
|
Cross entropy vs KL divergence: What's minimized directly in practice?
Let $q$ be the density of your true data-generating process and $f_\theta$ be your model-density.
Then $$KL(q||f_\theta) = \int q(x) log\left(\frac{q(x)}{f_\theta(x)}\right)dx = -\int q(x) \log(f_\theta(x))dx + \int q(x) \log(q(x)) dx$$
The first term is the Cross Entropy $H(q, f_\theta)$ and the second term is the (differential) entropy $H(q)$. Note that the second term does NOT depend on $\theta$ and therefore you cannot influence it anyway. Therfore minimizing either Cross-Entropy or KL-divergence is equivalent.
Without looking at the formula you can understand it the following informal way (if you assume a discrete distribution). The entropy $H(q)$ encodes how many bits you need if you encode the signal that comes from the distribution $q$ in an optimal way. The Cross-Entropy $H(q, f_\theta)$ encodes how many bits on average you would need when you encoded the singal that comes from a distribution $q$ using the optimal coding scheme for $f_\theta$. This decomposes into the Entropy $H(q)$ + $KL(q||f_\theta)$. The KL-divergence therefore measures how many additional bits you need if you use an optimal coding scheme for distribution $f_\theta$ (i.e. you assume your data comes from $f_\theta$ while it is actually generated from $q$). This also explains why it has to be positive. You cannot be better than the optimal coding scheme that yields the average bit-length $H(q)$.
This illustrates in an informal way why minimizing KL-divergence is equivalent to minimizing CE: By minimzing how many more bits you need than the optimal coding scheme (on average) you of course also minimize the total amount of bits you need (on average)
The following post illustrates the idea with the optimal coding scheme: Qualitively what is Cross Entropy
|
Cross entropy vs KL divergence: What's minimized directly in practice?
Let $q$ be the density of your true data-generating process and $f_\theta$ be your model-density.
Then $$KL(q||f_\theta) = \int q(x) log\left(\frac{q(x)}{f_\theta(x)}\right)dx = -\int q(x) \log(f_\the
|
39,874
|
Deviance for Gamma GLM
|
The general derivation of the deviance for a GLM family is given in Section 5.4 of Dunn and Smyth (2018) (the book that you mentioned in a previous post).
You can insert the form of the gamma density to get the result, but the density has to parametrized in the right way.
A common way to write the gamma density is as
$$f(y;\alpha,\beta)=\frac{y^{\alpha-1}e^{-y/\beta}}{\beta^\alpha\Gamma(\alpha)}$$
with $E(y)=\alpha\beta=\mu$ and var$(y)=\alpha\beta^2=V(\mu)\phi$ with $V(\mu)=\mu^2$ and $\phi=1/\alpha$.
Converting to the log-scale gives
$$\log f(y;\alpha,\beta)= -y/\beta-\alpha\log\beta+(\alpha-1)\log y-\log\Gamma(\alpha)$$
Reparametrizing to $\mu$ and $\phi$ gives
$$\log f(y;\mu,\phi)= t(y,\mu)/\phi+a(y,\phi)$$
with
$$t(y,\mu)=-y/\mu-\log\mu$$
and
$$a(y,\phi)=(\log\phi)/\phi+(1/\phi-1)\log y -\log\Gamma(1/\phi).$$
The unit deviance is defined as
$$d(y,\mu)=2\left\{t(y,y)-t(y,\mu)\right\}$$
with in this case
$$t(y,y)-t(y,\mu)=-1-\log y+ y/\mu+\log\mu=(y-\mu)/\mu-\log(y/\mu).$$
Finally, the total deviance is
$$D=\sum_{i=1}^n w_i d(y_i,\mu_i)$$
where the $w_i$ are the prior weights.
If the prior weights are all 1, then this agrees with the deviance formula in your question.
It is true that the $(y-\mu)/\mu$ terms often do sum to zero when evaluated at the fitted values, $\mu_i=\hat\mu_i$, but not always.
The GLM maximum likelihood equations solve
$$\sum_{i=1}^n w_i x_{ij} \frac{y_i-\mu_i}{g'(\mu_i) V(\mu_i)}=0$$
where the $x_{ij}$ are covariate values, $g'$ is the derivative of the link function and $V(\mu)$ is the variance function.
For the gamma distribution, $V(\mu)=\mu^2$.
If a log-link is used, then $g'(\mu) = 1/\mu$.
If a log-link is used and the covariates include an intercept term, then the likelihood equations imply
$$\sum_{i=1}^n w_i \frac{y_i-\mu_i}{\mu_i}=0$$
In this case, the $(y-\mu)/\mu$ terms will not contribute to the total deviance.
Nevertheless, the terms can't be ignored entirely because they are part of the unit deviances and will still contribute to the deviance residuals.
Reference
Dunn, PK, and Smyth, GK (2018). Generalized linear models with examples in R. Springer, New York, NY.
https://www.amazon.com/Generalized-Linear-Examples-Springer-Statistics/dp/1441901175
|
Deviance for Gamma GLM
|
The general derivation of the deviance for a GLM family is given in Section 5.4 of Dunn and Smyth (2018) (the book that you mentioned in a previous post).
You can insert the form of the gamma density
|
Deviance for Gamma GLM
The general derivation of the deviance for a GLM family is given in Section 5.4 of Dunn and Smyth (2018) (the book that you mentioned in a previous post).
You can insert the form of the gamma density to get the result, but the density has to parametrized in the right way.
A common way to write the gamma density is as
$$f(y;\alpha,\beta)=\frac{y^{\alpha-1}e^{-y/\beta}}{\beta^\alpha\Gamma(\alpha)}$$
with $E(y)=\alpha\beta=\mu$ and var$(y)=\alpha\beta^2=V(\mu)\phi$ with $V(\mu)=\mu^2$ and $\phi=1/\alpha$.
Converting to the log-scale gives
$$\log f(y;\alpha,\beta)= -y/\beta-\alpha\log\beta+(\alpha-1)\log y-\log\Gamma(\alpha)$$
Reparametrizing to $\mu$ and $\phi$ gives
$$\log f(y;\mu,\phi)= t(y,\mu)/\phi+a(y,\phi)$$
with
$$t(y,\mu)=-y/\mu-\log\mu$$
and
$$a(y,\phi)=(\log\phi)/\phi+(1/\phi-1)\log y -\log\Gamma(1/\phi).$$
The unit deviance is defined as
$$d(y,\mu)=2\left\{t(y,y)-t(y,\mu)\right\}$$
with in this case
$$t(y,y)-t(y,\mu)=-1-\log y+ y/\mu+\log\mu=(y-\mu)/\mu-\log(y/\mu).$$
Finally, the total deviance is
$$D=\sum_{i=1}^n w_i d(y_i,\mu_i)$$
where the $w_i$ are the prior weights.
If the prior weights are all 1, then this agrees with the deviance formula in your question.
It is true that the $(y-\mu)/\mu$ terms often do sum to zero when evaluated at the fitted values, $\mu_i=\hat\mu_i$, but not always.
The GLM maximum likelihood equations solve
$$\sum_{i=1}^n w_i x_{ij} \frac{y_i-\mu_i}{g'(\mu_i) V(\mu_i)}=0$$
where the $x_{ij}$ are covariate values, $g'$ is the derivative of the link function and $V(\mu)$ is the variance function.
For the gamma distribution, $V(\mu)=\mu^2$.
If a log-link is used, then $g'(\mu) = 1/\mu$.
If a log-link is used and the covariates include an intercept term, then the likelihood equations imply
$$\sum_{i=1}^n w_i \frac{y_i-\mu_i}{\mu_i}=0$$
In this case, the $(y-\mu)/\mu$ terms will not contribute to the total deviance.
Nevertheless, the terms can't be ignored entirely because they are part of the unit deviances and will still contribute to the deviance residuals.
Reference
Dunn, PK, and Smyth, GK (2018). Generalized linear models with examples in R. Springer, New York, NY.
https://www.amazon.com/Generalized-Linear-Examples-Springer-Statistics/dp/1441901175
|
Deviance for Gamma GLM
The general derivation of the deviance for a GLM family is given in Section 5.4 of Dunn and Smyth (2018) (the book that you mentioned in a previous post).
You can insert the form of the gamma density
|
39,875
|
What is the expected value of x log(x) of the gamma distribution?
|
$$\begin{align}E[X\log X]&=\int_0^\infty \log x \frac{\lambda^\alpha}{\Gamma(\alpha)}x^\alpha e^{-\lambda x}dx\\&=\frac{\Gamma(\alpha+1)}{\Gamma(\alpha)\lambda}\int_0^\infty\log x\frac{\lambda^{\alpha+1}}{\Gamma(\alpha+1)}x^{(\alpha+1)-1}e^{-\lambda x}dx\\&=\frac{\Gamma(\alpha+1)}{\Gamma(\alpha)\lambda}E[\log Y]\end{align}$$
where $Y\sim \text{Gamma}(\alpha_y=\alpha+1, \lambda_y=\lambda)$. From here, the expected value of the logarithm of a gamma RV is: $$E[\log Y]=-\log\lambda+\psi(\alpha+1)$$
where $\psi$ stands for polygamma function.
So, the overall result is (put $\alpha=3.7, \lambda=1$):
$$E[X\log X]=\underbrace{\frac{\Gamma(4.7)}{1\times\Gamma(3.7)}}_{3.7}(-\log 1 +\psi(4.7))\approx5.32$$
I've used Matlab's psi function to calculate the polygamma function.
|
What is the expected value of x log(x) of the gamma distribution?
|
$$\begin{align}E[X\log X]&=\int_0^\infty \log x \frac{\lambda^\alpha}{\Gamma(\alpha)}x^\alpha e^{-\lambda x}dx\\&=\frac{\Gamma(\alpha+1)}{\Gamma(\alpha)\lambda}\int_0^\infty\log x\frac{\lambda^{\alpha
|
What is the expected value of x log(x) of the gamma distribution?
$$\begin{align}E[X\log X]&=\int_0^\infty \log x \frac{\lambda^\alpha}{\Gamma(\alpha)}x^\alpha e^{-\lambda x}dx\\&=\frac{\Gamma(\alpha+1)}{\Gamma(\alpha)\lambda}\int_0^\infty\log x\frac{\lambda^{\alpha+1}}{\Gamma(\alpha+1)}x^{(\alpha+1)-1}e^{-\lambda x}dx\\&=\frac{\Gamma(\alpha+1)}{\Gamma(\alpha)\lambda}E[\log Y]\end{align}$$
where $Y\sim \text{Gamma}(\alpha_y=\alpha+1, \lambda_y=\lambda)$. From here, the expected value of the logarithm of a gamma RV is: $$E[\log Y]=-\log\lambda+\psi(\alpha+1)$$
where $\psi$ stands for polygamma function.
So, the overall result is (put $\alpha=3.7, \lambda=1$):
$$E[X\log X]=\underbrace{\frac{\Gamma(4.7)}{1\times\Gamma(3.7)}}_{3.7}(-\log 1 +\psi(4.7))\approx5.32$$
I've used Matlab's psi function to calculate the polygamma function.
|
What is the expected value of x log(x) of the gamma distribution?
$$\begin{align}E[X\log X]&=\int_0^\infty \log x \frac{\lambda^\alpha}{\Gamma(\alpha)}x^\alpha e^{-\lambda x}dx\\&=\frac{\Gamma(\alpha+1)}{\Gamma(\alpha)\lambda}\int_0^\infty\log x\frac{\lambda^{\alpha
|
39,876
|
How could one (tentatively) estimate the actual number of COVID-19 infections in an area, using hard data like age-adjusted death rate?
|
Death rate
Using death rate may work when people that die have most likely acquired the virus locally.
However, for the moment, many people die because they acquired the virus during a visit to another area, or because they got it from another person that acquired the virus abroad.
Thus this death-rate based number is not very accurate unless the virus has fully spread out (in which case it will be more likely to get infected from a local source).
For the cases of Wuhan, Italy and other epi-centers, which have more spread due to local infections rather than foreign infections, death rate might be a good probe (although you still have to deal with the delay).
In addition, while death rate might be more trustworthy than total cases of infection (just think about the Germans, with lots of supplies, are testing with a lot of thousands of people, while neighboring countries, with limited supplies, are trying to limit the use of testing as much as possible), it is still a biased number. It is not easy to determine/pinpoint the cause of death. Often a multitude of diseases are present. If a person with cancer or aids gets a pneumonia from nCoV-19, then what is the cause? The sampling of 'cause of death' is not very clear and becomes part of the analysis.
Statistics are only usefull for a comparison when they have a similar underlying basis.
Edit 1 (these numbers where not available before): I know about the case of the Netherlands, they compared the number of reported covid deaths and the number of total deaths. They found an increase in death rate with about 2000 people per week, but the number of reported covid-19 death cases is only about 1000 per week. So there might be a lot of people that are missed in the statistics about covid-19 (another explanation could be that those half those 2000 people are covid-19 and the other half are something else, but that is unlikely). A lot of people are not appearing in the statistics because they do not die in a hospital (but instead in their own house or in a care home).
My view of these numbers is that the ubiquitous corona-case-dashboards and counters are flimsy and weak and are presenting dubious (biased) numbers. The underlying basis is doubtful when the numbers of different sources do not match.
If you do want to use death rate numbers than the more rigid total death rate seems to be the better numbers (that means death due to all causes and not just the reports about covid-19). But these numbers are often not easily obtained/present (at least not publicly and stratified on a local scale) like the picture of the distribution of the cases in the Netherlands
source: Centraal Bureau voor Statistiek
I have been trying to source this kind of stuff for multiple countries, but it is not easy. I imagine (hope) that this might be done behind the scenes on an international level. E.g. the euromomo project. But I do not know much about it and suspect that the data is mostly aggregrated at a national level (making it useless or at least not possible to make images like above) But I also imagine that governments are not spending time on getting these numbers accurate and instead waste their time on corona-apps.
Edit 2: I know of a research by the University of Oxford that has used exactly your approach of using the death rate in order to estimate the prevalence.
The problem is that they introduce a parameter $\rho$, the proportion of the population at risk, which is a very uncertain parameter. This parameter $\rho$ is together with the time between the introduction of the index case(s) and the first reported death a relatively simple transformation between the current number of deaths and the total infected population. A similar calculation, but more simple without the Bayesian stuff around, is done in this blog post.
Personally I am very skeptical about these calculations. There are some computations involved which make the appearance of a rigorous method. But effectively it is just scaling the current number of deaths with a factor in order to guestimate the current number of infected/immune people. The numbers involved in the determination of the scaling factor are very uncertain and biased. The posterior estimate of the number infected people is just as uncertain as the prior estimate of the factor $\rho$ and the time between first index case and first death (as well as other factors like estimates of growth rate and estimates of incubation time, and bias in reports about the number of deaths.... it is a big mess)
Travel data
The virus is mostly spreading out irregularly over a network. It spreads out differently at different scales, within the household, neighborhood, workplaces/schools, villages, agglomerations, countries, continents. You can sort of see the virus spread around with sudden jumps from large node/community to large node/community.
You can use occurrence of the virus in those nodes/communities as the variable (so you do not count individuals, since we do not know the presence in all individuals, but instead count the much better known presence of the virus in communities), and then use a model for the dynamics of the virus spreading between this different nodes in the network.
For instance. E.g. in region A you encounter x cases of disease among people that came from region B and y cases of disease among people that came from region C, while the travel to those regions is $r$ and $q$, then an estimate of the relative presence of the virus in regions B:C can be approximated by (x/r):(y/q).
I remember there was an early article on the spread of COVID-19 (I believe it was by Chinese scholars) that tried to estimate $R_0$ and included information about the frequency of travel between different regions.
Random tests
You can perform test on a sample from the population that does not show any symptoms and use the prevalence of the virus among this sample to make an estimate about the prevalence in the entire population.
If the prevalence is very small then this requires a very large sample which might be difficult. In that case one may perform the test among a sample where the suspicion of the prevalence is higher and gain some information about how many people have the virus in that group. Such a measure can be used to calibrate the estimates based on incomplete information (ie. along with other information, such as the rate at which people with the virus have the particular mild or severe symptoms, you get an idea about how much the current estimates are underestimating the true number of cases).
Edit 3 By now there have been a few of these type of screenings. For instance:
in a small screening among two Dutch hospitals, researchers have found that 86 out of 1353 health care workers (6.4%) tested positive for covid-19 with a PCR test, and most had only mild symptoms.
In a screening in the community Gangelt in Germany, in which thousand people partaked, preliminary results showed that 15% of the people were infected. The related death rate is 0.37%, which is much less than the other reported numbers (but still more than an ordinary flu).
Preliminary results of research on blood donors in all of the Netherlands show that 3% of the donors have antibodies against covid-19.
When more of these results come in we are able to make a much more rigid estimate about the spatial distribution and prevalence of the disease.
|
How could one (tentatively) estimate the actual number of COVID-19 infections in an area, using hard
|
Death rate
Using death rate may work when people that die have most likely acquired the virus locally.
However, for the moment, many people die because they acquired the virus during a visit to anoth
|
How could one (tentatively) estimate the actual number of COVID-19 infections in an area, using hard data like age-adjusted death rate?
Death rate
Using death rate may work when people that die have most likely acquired the virus locally.
However, for the moment, many people die because they acquired the virus during a visit to another area, or because they got it from another person that acquired the virus abroad.
Thus this death-rate based number is not very accurate unless the virus has fully spread out (in which case it will be more likely to get infected from a local source).
For the cases of Wuhan, Italy and other epi-centers, which have more spread due to local infections rather than foreign infections, death rate might be a good probe (although you still have to deal with the delay).
In addition, while death rate might be more trustworthy than total cases of infection (just think about the Germans, with lots of supplies, are testing with a lot of thousands of people, while neighboring countries, with limited supplies, are trying to limit the use of testing as much as possible), it is still a biased number. It is not easy to determine/pinpoint the cause of death. Often a multitude of diseases are present. If a person with cancer or aids gets a pneumonia from nCoV-19, then what is the cause? The sampling of 'cause of death' is not very clear and becomes part of the analysis.
Statistics are only usefull for a comparison when they have a similar underlying basis.
Edit 1 (these numbers where not available before): I know about the case of the Netherlands, they compared the number of reported covid deaths and the number of total deaths. They found an increase in death rate with about 2000 people per week, but the number of reported covid-19 death cases is only about 1000 per week. So there might be a lot of people that are missed in the statistics about covid-19 (another explanation could be that those half those 2000 people are covid-19 and the other half are something else, but that is unlikely). A lot of people are not appearing in the statistics because they do not die in a hospital (but instead in their own house or in a care home).
My view of these numbers is that the ubiquitous corona-case-dashboards and counters are flimsy and weak and are presenting dubious (biased) numbers. The underlying basis is doubtful when the numbers of different sources do not match.
If you do want to use death rate numbers than the more rigid total death rate seems to be the better numbers (that means death due to all causes and not just the reports about covid-19). But these numbers are often not easily obtained/present (at least not publicly and stratified on a local scale) like the picture of the distribution of the cases in the Netherlands
source: Centraal Bureau voor Statistiek
I have been trying to source this kind of stuff for multiple countries, but it is not easy. I imagine (hope) that this might be done behind the scenes on an international level. E.g. the euromomo project. But I do not know much about it and suspect that the data is mostly aggregrated at a national level (making it useless or at least not possible to make images like above) But I also imagine that governments are not spending time on getting these numbers accurate and instead waste their time on corona-apps.
Edit 2: I know of a research by the University of Oxford that has used exactly your approach of using the death rate in order to estimate the prevalence.
The problem is that they introduce a parameter $\rho$, the proportion of the population at risk, which is a very uncertain parameter. This parameter $\rho$ is together with the time between the introduction of the index case(s) and the first reported death a relatively simple transformation between the current number of deaths and the total infected population. A similar calculation, but more simple without the Bayesian stuff around, is done in this blog post.
Personally I am very skeptical about these calculations. There are some computations involved which make the appearance of a rigorous method. But effectively it is just scaling the current number of deaths with a factor in order to guestimate the current number of infected/immune people. The numbers involved in the determination of the scaling factor are very uncertain and biased. The posterior estimate of the number infected people is just as uncertain as the prior estimate of the factor $\rho$ and the time between first index case and first death (as well as other factors like estimates of growth rate and estimates of incubation time, and bias in reports about the number of deaths.... it is a big mess)
Travel data
The virus is mostly spreading out irregularly over a network. It spreads out differently at different scales, within the household, neighborhood, workplaces/schools, villages, agglomerations, countries, continents. You can sort of see the virus spread around with sudden jumps from large node/community to large node/community.
You can use occurrence of the virus in those nodes/communities as the variable (so you do not count individuals, since we do not know the presence in all individuals, but instead count the much better known presence of the virus in communities), and then use a model for the dynamics of the virus spreading between this different nodes in the network.
For instance. E.g. in region A you encounter x cases of disease among people that came from region B and y cases of disease among people that came from region C, while the travel to those regions is $r$ and $q$, then an estimate of the relative presence of the virus in regions B:C can be approximated by (x/r):(y/q).
I remember there was an early article on the spread of COVID-19 (I believe it was by Chinese scholars) that tried to estimate $R_0$ and included information about the frequency of travel between different regions.
Random tests
You can perform test on a sample from the population that does not show any symptoms and use the prevalence of the virus among this sample to make an estimate about the prevalence in the entire population.
If the prevalence is very small then this requires a very large sample which might be difficult. In that case one may perform the test among a sample where the suspicion of the prevalence is higher and gain some information about how many people have the virus in that group. Such a measure can be used to calibrate the estimates based on incomplete information (ie. along with other information, such as the rate at which people with the virus have the particular mild or severe symptoms, you get an idea about how much the current estimates are underestimating the true number of cases).
Edit 3 By now there have been a few of these type of screenings. For instance:
in a small screening among two Dutch hospitals, researchers have found that 86 out of 1353 health care workers (6.4%) tested positive for covid-19 with a PCR test, and most had only mild symptoms.
In a screening in the community Gangelt in Germany, in which thousand people partaked, preliminary results showed that 15% of the people were infected. The related death rate is 0.37%, which is much less than the other reported numbers (but still more than an ordinary flu).
Preliminary results of research on blood donors in all of the Netherlands show that 3% of the donors have antibodies against covid-19.
When more of these results come in we are able to make a much more rigid estimate about the spatial distribution and prevalence of the disease.
|
How could one (tentatively) estimate the actual number of COVID-19 infections in an area, using hard
Death rate
Using death rate may work when people that die have most likely acquired the virus locally.
However, for the moment, many people die because they acquired the virus during a visit to anoth
|
39,877
|
How could one (tentatively) estimate the actual number of COVID-19 infections in an area, using hard data like age-adjusted death rate?
|
It seems that there is a blog post that also deals with this question.
If you have deaths in your region, you can use that to guess the number of true current cases. We know approximately how long it takes for that person to go from catching the virus to dying on average (17.3 days). That means the person who died on 2/29 in Washington State probably got infected around 2/12.
Then, you know the mortality rate. For this scenario, I’m using 1% (we’ll discuss later the details). That means that, around 2/12, there were already around ~100 cases in the area (of which only one ended up in death 17.3 days later).
Now, use the average doubling time for the coronavirus (time it takes to double cases, on average). It’s 6.2. That means that, in the 17 days it took this person to die, the cases had to multiply by ~8 (=2^(17/6)). That means that, if you are not diagnosing all cases, one death today means 800 true cases today.
Here is another dashboard with a similar estimation methodology:
Estimating The Infected Population From Deaths
|
How could one (tentatively) estimate the actual number of COVID-19 infections in an area, using hard
|
It seems that there is a blog post that also deals with this question.
If you have deaths in your region, you can use that to guess the number of true current cases. We know approximately how long i
|
How could one (tentatively) estimate the actual number of COVID-19 infections in an area, using hard data like age-adjusted death rate?
It seems that there is a blog post that also deals with this question.
If you have deaths in your region, you can use that to guess the number of true current cases. We know approximately how long it takes for that person to go from catching the virus to dying on average (17.3 days). That means the person who died on 2/29 in Washington State probably got infected around 2/12.
Then, you know the mortality rate. For this scenario, I’m using 1% (we’ll discuss later the details). That means that, around 2/12, there were already around ~100 cases in the area (of which only one ended up in death 17.3 days later).
Now, use the average doubling time for the coronavirus (time it takes to double cases, on average). It’s 6.2. That means that, in the 17 days it took this person to die, the cases had to multiply by ~8 (=2^(17/6)). That means that, if you are not diagnosing all cases, one death today means 800 true cases today.
Here is another dashboard with a similar estimation methodology:
Estimating The Infected Population From Deaths
|
How could one (tentatively) estimate the actual number of COVID-19 infections in an area, using hard
It seems that there is a blog post that also deals with this question.
If you have deaths in your region, you can use that to guess the number of true current cases. We know approximately how long i
|
39,878
|
Is there any difference between hypothesis testing $A\beta = a$ and $\beta = A^{-1}a$?
|
If you wish to perform a constrained linear regression with linear equality constraints of the form $A\beta = a$, then tests such as the likelihood ratio test are more naturally formulated in this way. This is because the constrained OLS estimator $\beta^*$ can be written in terms of the unconstrained estimator $\hat{\beta}$, $A$, and $a$:
$$\beta^* = \hat{\beta} + (X'X)^{-1}A'(A(X'X)^{-1}A')^{-1}(a-A\hat{\beta})$$
$\beta^*$ is best linear unbiased, given the constraints. Our test is then easily seen to be that $a-A\beta=0$, or, slightly rearranged, that $A\beta = a$, whereas the use of the inverse does not jump so readily to the eye.
Also note that it may be that $A$ is not square, and therefore not invertible, for example, if you are constraining $\hat{\beta}_1 + \hat{\beta}_2 = 0$ in your regression and want to test the corresponding hypothesis about $\beta_1$ and $\beta_2$, $A$ would be $1 \times k$, where $k$ is the length of $\beta$. This may not apply to your case, judging from the first line of the question, but in the more general case it is definitely an issue.
|
Is there any difference between hypothesis testing $A\beta = a$ and $\beta = A^{-1}a$?
|
If you wish to perform a constrained linear regression with linear equality constraints of the form $A\beta = a$, then tests such as the likelihood ratio test are more naturally formulated in this way
|
Is there any difference between hypothesis testing $A\beta = a$ and $\beta = A^{-1}a$?
If you wish to perform a constrained linear regression with linear equality constraints of the form $A\beta = a$, then tests such as the likelihood ratio test are more naturally formulated in this way. This is because the constrained OLS estimator $\beta^*$ can be written in terms of the unconstrained estimator $\hat{\beta}$, $A$, and $a$:
$$\beta^* = \hat{\beta} + (X'X)^{-1}A'(A(X'X)^{-1}A')^{-1}(a-A\hat{\beta})$$
$\beta^*$ is best linear unbiased, given the constraints. Our test is then easily seen to be that $a-A\beta=0$, or, slightly rearranged, that $A\beta = a$, whereas the use of the inverse does not jump so readily to the eye.
Also note that it may be that $A$ is not square, and therefore not invertible, for example, if you are constraining $\hat{\beta}_1 + \hat{\beta}_2 = 0$ in your regression and want to test the corresponding hypothesis about $\beta_1$ and $\beta_2$, $A$ would be $1 \times k$, where $k$ is the length of $\beta$. This may not apply to your case, judging from the first line of the question, but in the more general case it is definitely an issue.
|
Is there any difference between hypothesis testing $A\beta = a$ and $\beta = A^{-1}a$?
If you wish to perform a constrained linear regression with linear equality constraints of the form $A\beta = a$, then tests such as the likelihood ratio test are more naturally formulated in this way
|
39,879
|
Is there any difference between hypothesis testing $A\beta = a$ and $\beta = A^{-1}a$?
|
It is often the case that $A$ is not a square matrix, and so not invertible. However, assuming that $A$ is actually invertible, the statement $A \beta = a$ is equivalent to $\beta = A^{-1} a$, and so your formulation of the test is legitimate (though unusual). Regardless of which form you use to state the hypotheses, the actual content of the test is determined by finding an appropriate test statistic and using it to compute the p-value. This exercise is not affected by which of the two equivalent forms you use to state the hypotheses.
|
Is there any difference between hypothesis testing $A\beta = a$ and $\beta = A^{-1}a$?
|
It is often the case that $A$ is not a square matrix, and so not invertible. However, assuming that $A$ is actually invertible, the statement $A \beta = a$ is equivalent to $\beta = A^{-1} a$, and so
|
Is there any difference between hypothesis testing $A\beta = a$ and $\beta = A^{-1}a$?
It is often the case that $A$ is not a square matrix, and so not invertible. However, assuming that $A$ is actually invertible, the statement $A \beta = a$ is equivalent to $\beta = A^{-1} a$, and so your formulation of the test is legitimate (though unusual). Regardless of which form you use to state the hypotheses, the actual content of the test is determined by finding an appropriate test statistic and using it to compute the p-value. This exercise is not affected by which of the two equivalent forms you use to state the hypotheses.
|
Is there any difference between hypothesis testing $A\beta = a$ and $\beta = A^{-1}a$?
It is often the case that $A$ is not a square matrix, and so not invertible. However, assuming that $A$ is actually invertible, the statement $A \beta = a$ is equivalent to $\beta = A^{-1} a$, and so
|
39,880
|
Is independence subjective?
|
I'm a bit late and good things have already been written, however I didn't see the following mentioned:
For person A coin tosses are independent and identically distributed, hence they are exchangeable.
For person B coin tosses are neither independent nor identically distributed but they are exchangeable."
This doesn't depend on the information that A or B have, but rather on whether they view probability as epistemic (i.e., referring to knowledge/uncertainty of an agent, like most Bayesians) or as aleatory (referring to data generating processes out there in the world, like most frequentists). One can even be pluralist and accept both views as advantageous in different situations.
In any case, person B can, even with the given information, talk about aleatory probabilities and would then normally model the coin tosses as i.i.d. with unknown probability. It is inappropriate to say that "for person B coin tosses are neither independent nor identically distributed", because the epistemic model in which they are exchangeable but not i.i.d. does not refer to the physical process but rather to the state of knowledge.
What's strange for me at this point is that for the same physical process of tossing fair coins in a row, one person thinks that the tosses are independent and the other doesn't, while I know that they are all IID.
But this is not the case. Person A apparently models what the physical process is, but person B is going on about modelling their own state of knowledge, and does not make statements about the underlying physical process.
Should we assess independence based on an idealized true data generating process or based on what we currently know about the process?
From a pluralist point of view that's your choice and there are pros and cons of both. However once you made your choice, be consistent with it!
Does this make independence subjective? Or is my understanding incorrect?
There are always subjective elements in probability modeling that you cannot get rid of. This is obvious in subjective Bayes, however also frequentists need to make model decisions that are subjective. Probability models are always underdetermined by the data. A frequentist could try to test independence (which doesn't happen very often), but this comes with its own problems and can certainly not detect all conceivable alternative possibilities.
Nevertheless it is quite perplexing that if question was posed as randomly picking a coin from an urn containing one biased and one fair coin (not knowing which one you picked) and then tossing the same coin N times, both the frequentist and the bayesian would probably agree that the tosses are not unconditionally independent, which means they both now assess independence based on what they know about the situation instead of the ground truth that the tosses actually don't affect each other.
If you'd phrase this in terms how they model the situation like this and for what reasons, this would seem far less perplexing than writing about what people think the coin tosses really are. Probability in my view is a tool for modelling the world, not a description of how the world really is.
|
Is independence subjective?
|
I'm a bit late and good things have already been written, however I didn't see the following mentioned:
For person A coin tosses are independent and identically distributed, hence they are exchangeab
|
Is independence subjective?
I'm a bit late and good things have already been written, however I didn't see the following mentioned:
For person A coin tosses are independent and identically distributed, hence they are exchangeable.
For person B coin tosses are neither independent nor identically distributed but they are exchangeable."
This doesn't depend on the information that A or B have, but rather on whether they view probability as epistemic (i.e., referring to knowledge/uncertainty of an agent, like most Bayesians) or as aleatory (referring to data generating processes out there in the world, like most frequentists). One can even be pluralist and accept both views as advantageous in different situations.
In any case, person B can, even with the given information, talk about aleatory probabilities and would then normally model the coin tosses as i.i.d. with unknown probability. It is inappropriate to say that "for person B coin tosses are neither independent nor identically distributed", because the epistemic model in which they are exchangeable but not i.i.d. does not refer to the physical process but rather to the state of knowledge.
What's strange for me at this point is that for the same physical process of tossing fair coins in a row, one person thinks that the tosses are independent and the other doesn't, while I know that they are all IID.
But this is not the case. Person A apparently models what the physical process is, but person B is going on about modelling their own state of knowledge, and does not make statements about the underlying physical process.
Should we assess independence based on an idealized true data generating process or based on what we currently know about the process?
From a pluralist point of view that's your choice and there are pros and cons of both. However once you made your choice, be consistent with it!
Does this make independence subjective? Or is my understanding incorrect?
There are always subjective elements in probability modeling that you cannot get rid of. This is obvious in subjective Bayes, however also frequentists need to make model decisions that are subjective. Probability models are always underdetermined by the data. A frequentist could try to test independence (which doesn't happen very often), but this comes with its own problems and can certainly not detect all conceivable alternative possibilities.
Nevertheless it is quite perplexing that if question was posed as randomly picking a coin from an urn containing one biased and one fair coin (not knowing which one you picked) and then tossing the same coin N times, both the frequentist and the bayesian would probably agree that the tosses are not unconditionally independent, which means they both now assess independence based on what they know about the situation instead of the ground truth that the tosses actually don't affect each other.
If you'd phrase this in terms how they model the situation like this and for what reasons, this would seem far less perplexing than writing about what people think the coin tosses really are. Probability in my view is a tool for modelling the world, not a description of how the world really is.
|
Is independence subjective?
I'm a bit late and good things have already been written, however I didn't see the following mentioned:
For person A coin tosses are independent and identically distributed, hence they are exchangeab
|
39,881
|
Is independence subjective?
|
It seems me that ultimately the answer to your question boil down in the concept of probability that you accept.
Let me recover the Tim answer’s
In probability theory, independence of two events is defined as
$P(A∩B)=P(A)P(B)$
There is nothing subjective about the definition, it is a possible property of random variables.
The last sentences is strongly questionable in Bruno de Finetti point of view about probability. In the radical interpretation that he suggest, the probabilities themselves are completely subjective, even in case where classical definition is almost always applied (like coin tossing). So independence are subjective judgement also. Note that for exchangeability the same is true.
The experiment that you have in mind is a stylized case for more general question like this:
two person face the same probabilistic problem, but one have more information then the other about that.
Therefore the probabilistic model that them keep in mind are almost surely different, and then the conclusions that them achieve.
Let that the conclusions are probability themselves; which is the right one?
In de Finetti point of view the last question are nonsense one. No probability are right because ultimately probability do not exist (in absolutely objective sense). Probabilities (conclusions) can (must) be coherent, no more.
In de Finetti interpretation the conclusions in example can be both right or both wrong or one right and one wrong, regardless of individual knowledge. It depend only from possible logical mistake (inconsistency) in reasoning of both guys.
However is true that in our example the guy B, that have less information, can learn something from the data and if the coin are “truly” interpretable as iid random variables, before or after, should be converge to the conclusion of guy A. Come in place the endless debate between reality/data and probability.
Coming back to your sentence
What's strange for me at this point is that for the same physical process of tossing fair coins in a row, one person thinks that the tosses are independent and the other doesn't, while I know that they are all IID.
Does this make independence subjective?
In de Finetti point of view, the answer is yes and nothing is strange.
N.B: in terminological sense if you "know" that "they are all IID" no other opinion are admissible, then guy B almost surely going to wrong conclusions. However if your "know" is a theoretical assumption the answer to your question ... is in the question (events are independent)... no room for subjective opinions. However note that ask to solve any mathematical problem giving correct terms to some guys and incorrect or incomplete terms to the others is exactly the same.
At the other side if your "knowledge" is about reality ... it can be an illusion ... subjective interpretation come back to be admissible.
For full understanding of de Finetti point of view you can read https://www.amazon.com/Theory-Probability-introductory-treatment-Statistics/dp/1119286379
|
Is independence subjective?
|
It seems me that ultimately the answer to your question boil down in the concept of probability that you accept.
Let me recover the Tim answer’s
In probability theory, independence of two events is d
|
Is independence subjective?
It seems me that ultimately the answer to your question boil down in the concept of probability that you accept.
Let me recover the Tim answer’s
In probability theory, independence of two events is defined as
$P(A∩B)=P(A)P(B)$
There is nothing subjective about the definition, it is a possible property of random variables.
The last sentences is strongly questionable in Bruno de Finetti point of view about probability. In the radical interpretation that he suggest, the probabilities themselves are completely subjective, even in case where classical definition is almost always applied (like coin tossing). So independence are subjective judgement also. Note that for exchangeability the same is true.
The experiment that you have in mind is a stylized case for more general question like this:
two person face the same probabilistic problem, but one have more information then the other about that.
Therefore the probabilistic model that them keep in mind are almost surely different, and then the conclusions that them achieve.
Let that the conclusions are probability themselves; which is the right one?
In de Finetti point of view the last question are nonsense one. No probability are right because ultimately probability do not exist (in absolutely objective sense). Probabilities (conclusions) can (must) be coherent, no more.
In de Finetti interpretation the conclusions in example can be both right or both wrong or one right and one wrong, regardless of individual knowledge. It depend only from possible logical mistake (inconsistency) in reasoning of both guys.
However is true that in our example the guy B, that have less information, can learn something from the data and if the coin are “truly” interpretable as iid random variables, before or after, should be converge to the conclusion of guy A. Come in place the endless debate between reality/data and probability.
Coming back to your sentence
What's strange for me at this point is that for the same physical process of tossing fair coins in a row, one person thinks that the tosses are independent and the other doesn't, while I know that they are all IID.
Does this make independence subjective?
In de Finetti point of view, the answer is yes and nothing is strange.
N.B: in terminological sense if you "know" that "they are all IID" no other opinion are admissible, then guy B almost surely going to wrong conclusions. However if your "know" is a theoretical assumption the answer to your question ... is in the question (events are independent)... no room for subjective opinions. However note that ask to solve any mathematical problem giving correct terms to some guys and incorrect or incomplete terms to the others is exactly the same.
At the other side if your "knowledge" is about reality ... it can be an illusion ... subjective interpretation come back to be admissible.
For full understanding of de Finetti point of view you can read https://www.amazon.com/Theory-Probability-introductory-treatment-Statistics/dp/1119286379
|
Is independence subjective?
It seems me that ultimately the answer to your question boil down in the concept of probability that you accept.
Let me recover the Tim answer’s
In probability theory, independence of two events is d
|
39,882
|
Is independence subjective?
|
In probability theory, independence of two events is defined as
$$
P(A \cap B) = P(A)\,P(B)
$$
There is nothing subjective about the definition, it is a possible property of random variables. For real life data, because of things like sampling bias, measurement error, insufficient sample size, numerical precision etc., we would be talking about degree to which the assumption of independence was violated. This is one of the reasons why we look at the residual plots of the model.
On one extreme, you can consider if "butterfly’s wings in Brazil set off a tornado in Texas", i.e. say that independence does not exist. Even simple "physical" problems like throwing a coin can possibly be influenced by some external factors (unless it is thrown by a robot at vacuum), yet most people would agree that is is "random" and "independent" enough to not consider such nuances.
On another extreme, you could boldly assume independence, e.g. when building a spam classifier you use Naive Bayes classifier that assumes that all the variables are independent. This would be obviously wrong, as people do not combine words in sentences by pairing them at random. Yet, Naive Bayes classifier can give pretty decent results for many similar problems and is commonly used.
Yes, no matter what assessments people make, they may be influenced by external factors, there is a huge body of research in psychology on this. Independence is one of them, a handy one, that simplifies a lot of maths for solving statistical problems. Usually the problem is not if the assumption is correct or wrong, but on how much would making the wrong assumption influence the results. Moreover, in many cases for computational reason you simply need to make such assumptions, as you wouldn't be able to model every possible interaction of anything with anything in the world.
|
Is independence subjective?
|
In probability theory, independence of two events is defined as
$$
P(A \cap B) = P(A)\,P(B)
$$
There is nothing subjective about the definition, it is a possible property of random variables. For real
|
Is independence subjective?
In probability theory, independence of two events is defined as
$$
P(A \cap B) = P(A)\,P(B)
$$
There is nothing subjective about the definition, it is a possible property of random variables. For real life data, because of things like sampling bias, measurement error, insufficient sample size, numerical precision etc., we would be talking about degree to which the assumption of independence was violated. This is one of the reasons why we look at the residual plots of the model.
On one extreme, you can consider if "butterfly’s wings in Brazil set off a tornado in Texas", i.e. say that independence does not exist. Even simple "physical" problems like throwing a coin can possibly be influenced by some external factors (unless it is thrown by a robot at vacuum), yet most people would agree that is is "random" and "independent" enough to not consider such nuances.
On another extreme, you could boldly assume independence, e.g. when building a spam classifier you use Naive Bayes classifier that assumes that all the variables are independent. This would be obviously wrong, as people do not combine words in sentences by pairing them at random. Yet, Naive Bayes classifier can give pretty decent results for many similar problems and is commonly used.
Yes, no matter what assessments people make, they may be influenced by external factors, there is a huge body of research in psychology on this. Independence is one of them, a handy one, that simplifies a lot of maths for solving statistical problems. Usually the problem is not if the assumption is correct or wrong, but on how much would making the wrong assumption influence the results. Moreover, in many cases for computational reason you simply need to make such assumptions, as you wouldn't be able to model every possible interaction of anything with anything in the world.
|
Is independence subjective?
In probability theory, independence of two events is defined as
$$
P(A \cap B) = P(A)\,P(B)
$$
There is nothing subjective about the definition, it is a possible property of random variables. For real
|
39,883
|
Is independence subjective?
|
Up to the last paragraph, the setting appears to be entirely Bayesian. I will first respond to the questions raised up to (but excluding) the last paragraph from a Bayesian perspective.
...for the same physical process of tossing fair coins in a row, one person thinks that the tosses are independent and the other doesn't, while I know that they are all IID. Does this make independence subjective?
In your example, the difference between persons arises not because they treat the same information differently, but because of the different (amount of) information they have. The first one is conditioning on $p=0.5$ (using $p$ to denote the probability of heads), while the second one is not. Another, perhaps more relevant question is: Were the two persons given the same information, would they necessarily arrive at the same conclusion regarding independence? If having the same information implies having the same priors and likelihoods (does it? I do not have an answer right now), then the answer is in the affirmative.
Should we assess independence based on an idealized true data generating process or based on what we currently know about the process?
As Bayesians, we should assess independence based on what we currently know about the process. According to Lindley "Understanding Uncertainty" (2006) p. 37-38, Probability describes a relationship between you and the world, or that part of the world involved in the event. <...> It is not solely a feature of your mind, it is not a value possessed by an event but expresses a relationship between you and the event and is a basic tool in your understanding of the world (emphasis is mine). Since independence is defined by probabilities, I think the same logic and interpretation extends to independence.
(It is also not entirely clear to me how to express the statement assess independence based on an idealized true data generating process rigorously in statistical terms.)
Regarding the last paragraph and the treatment of independence from a frequentist perspective, there are two steps to the process:
How real world events/phehomena are modeled probabilistically
How independence is defined and understood within the models (regardless of their connection to the real world).
In step 1, questions can be raised regarding some simplifying assumptions taken when moving from the real world to models. A relevant one for us is about the plausibility of an assumption that the outcome of the first toss does not affect the physical properties of the second toss; this can form a basis for a formal assumption of independence defined on the model level (step 2). In step 2, independence can be assessed formally using laws of probability, and that is relatively easy, I believe (given a complete job in step 1).
Regarding
...it is quite perplexing that if question was posed as randomly picking a coin from an urn containing one biased and one fair coin (not knowing which one you picked) and then tossing the same coin N times, <...> the frequentist <...> would probably agree that the tosses are not unconditionally independent, which means <...> independence [is assessed] based on what they know about the situation instead of the ground truth that the tosses actually don't affect each other,
the problem is with step (1). The real world phenomena are more complicated than just throwing the same coin several times; there is also the action of picking one of two coins in the beginning. Taking proper account of the latter yields (after being formalized in step 2) unconditional dependence. After some thought, one will probably not find it counterintuitive. Now, if we are only looking at tosses of a single coin, then we have independence, whether we define it conditionally on having selected a concrete coin in the experiment you describe or we define it unconditionally in an experiment where only one coin exists (so not your experiment). So in my understanding, there is actually no clash with the ground truth -- as long as we are identifying the phenomena we are modelling / taking into account correctly.
|
Is independence subjective?
|
Up to the last paragraph, the setting appears to be entirely Bayesian. I will first respond to the questions raised up to (but excluding) the last paragraph from a Bayesian perspective.
...for the sa
|
Is independence subjective?
Up to the last paragraph, the setting appears to be entirely Bayesian. I will first respond to the questions raised up to (but excluding) the last paragraph from a Bayesian perspective.
...for the same physical process of tossing fair coins in a row, one person thinks that the tosses are independent and the other doesn't, while I know that they are all IID. Does this make independence subjective?
In your example, the difference between persons arises not because they treat the same information differently, but because of the different (amount of) information they have. The first one is conditioning on $p=0.5$ (using $p$ to denote the probability of heads), while the second one is not. Another, perhaps more relevant question is: Were the two persons given the same information, would they necessarily arrive at the same conclusion regarding independence? If having the same information implies having the same priors and likelihoods (does it? I do not have an answer right now), then the answer is in the affirmative.
Should we assess independence based on an idealized true data generating process or based on what we currently know about the process?
As Bayesians, we should assess independence based on what we currently know about the process. According to Lindley "Understanding Uncertainty" (2006) p. 37-38, Probability describes a relationship between you and the world, or that part of the world involved in the event. <...> It is not solely a feature of your mind, it is not a value possessed by an event but expresses a relationship between you and the event and is a basic tool in your understanding of the world (emphasis is mine). Since independence is defined by probabilities, I think the same logic and interpretation extends to independence.
(It is also not entirely clear to me how to express the statement assess independence based on an idealized true data generating process rigorously in statistical terms.)
Regarding the last paragraph and the treatment of independence from a frequentist perspective, there are two steps to the process:
How real world events/phehomena are modeled probabilistically
How independence is defined and understood within the models (regardless of their connection to the real world).
In step 1, questions can be raised regarding some simplifying assumptions taken when moving from the real world to models. A relevant one for us is about the plausibility of an assumption that the outcome of the first toss does not affect the physical properties of the second toss; this can form a basis for a formal assumption of independence defined on the model level (step 2). In step 2, independence can be assessed formally using laws of probability, and that is relatively easy, I believe (given a complete job in step 1).
Regarding
...it is quite perplexing that if question was posed as randomly picking a coin from an urn containing one biased and one fair coin (not knowing which one you picked) and then tossing the same coin N times, <...> the frequentist <...> would probably agree that the tosses are not unconditionally independent, which means <...> independence [is assessed] based on what they know about the situation instead of the ground truth that the tosses actually don't affect each other,
the problem is with step (1). The real world phenomena are more complicated than just throwing the same coin several times; there is also the action of picking one of two coins in the beginning. Taking proper account of the latter yields (after being formalized in step 2) unconditional dependence. After some thought, one will probably not find it counterintuitive. Now, if we are only looking at tosses of a single coin, then we have independence, whether we define it conditionally on having selected a concrete coin in the experiment you describe or we define it unconditionally in an experiment where only one coin exists (so not your experiment). So in my understanding, there is actually no clash with the ground truth -- as long as we are identifying the phenomena we are modelling / taking into account correctly.
|
Is independence subjective?
Up to the last paragraph, the setting appears to be entirely Bayesian. I will first respond to the questions raised up to (but excluding) the last paragraph from a Bayesian perspective.
...for the sa
|
39,884
|
Is independence subjective?
|
The coin tosses that each of the two subjects will conduct will always be independent and identically distributed random variables (and thus exchangeable) no matter what they think. The underlying properties and distributions are not subject to our beliefs about them.
For instance, if you fill up a room with 1 million people and you give a fair coin to each one and ask them to flip it 20 times chances are that there will be a couple that will get the same side all 20 times. If you go and ask these two specific people what they think about the coin, they will most likely say that they have strong evidence that the coin is biased. However, if you reveal what happened to the rest 999998 people they will take back their previous statements. This example has nothing to do with iid or exchangeability, I just wanted to demonstrate an example when subjective beliefs can be very well structured and scientific and sensible but incorrect compared to what is the "ground truth".
That said, allow me to help you understand the above definitions and concepts through some examples:
Independence: If you flip two coins (don't care if they are fair or biassed) the outcome of the "system" only depends on each of the coin's manufacturing properties and there is no magic wire connecting them and affecting the outcome of one given to what has happened to the other. These two variables are independent. The length of someone's legs and his height are not independent as the outcome "1m tall" has different probabilities if this person's legs are 1.1 meters and 0.5 meters, in the first case the outcome has 0 probability to occur as we are talking about the same person.
Identically distributed: If you have a coin (don't care if its' fair or biased) and you flip it two times the probability of getting heads is the same in the first and in the second flip again because the fact the coin is exactly the same and the first outcome didn't magically destroy any of the coin's underlying properties so that in the second flip one is more likely than the other. If you have two football games: Barcelona vs Real Madrid and Barcelona vs random team in the 3rd league, the probability distributions of the two results are not the same because although the first team is the same in both cases, in the second one is not.
Exchangeable: If you have one coin (don't care if it's fair or biased) and you flip it two times and you write down one outcome in blue and the other outcome in red, then, the probability of the event (blue = heads and red = tails) is the same if the blue is the first flip's outcome and red is the second flip's or the other way round. In other words, the outcome of the coin can give you no clue at all about if it's the first or the second coin flip. The probability of the event (Final score: 7-1) is different if the game is Barcelona vs Random 3rd division team OR if the game is Random 3rd division team vs Barcelona.
|
Is independence subjective?
|
The coin tosses that each of the two subjects will conduct will always be independent and identically distributed random variables (and thus exchangeable) no matter what they think. The underlying pro
|
Is independence subjective?
The coin tosses that each of the two subjects will conduct will always be independent and identically distributed random variables (and thus exchangeable) no matter what they think. The underlying properties and distributions are not subject to our beliefs about them.
For instance, if you fill up a room with 1 million people and you give a fair coin to each one and ask them to flip it 20 times chances are that there will be a couple that will get the same side all 20 times. If you go and ask these two specific people what they think about the coin, they will most likely say that they have strong evidence that the coin is biased. However, if you reveal what happened to the rest 999998 people they will take back their previous statements. This example has nothing to do with iid or exchangeability, I just wanted to demonstrate an example when subjective beliefs can be very well structured and scientific and sensible but incorrect compared to what is the "ground truth".
That said, allow me to help you understand the above definitions and concepts through some examples:
Independence: If you flip two coins (don't care if they are fair or biassed) the outcome of the "system" only depends on each of the coin's manufacturing properties and there is no magic wire connecting them and affecting the outcome of one given to what has happened to the other. These two variables are independent. The length of someone's legs and his height are not independent as the outcome "1m tall" has different probabilities if this person's legs are 1.1 meters and 0.5 meters, in the first case the outcome has 0 probability to occur as we are talking about the same person.
Identically distributed: If you have a coin (don't care if its' fair or biased) and you flip it two times the probability of getting heads is the same in the first and in the second flip again because the fact the coin is exactly the same and the first outcome didn't magically destroy any of the coin's underlying properties so that in the second flip one is more likely than the other. If you have two football games: Barcelona vs Real Madrid and Barcelona vs random team in the 3rd league, the probability distributions of the two results are not the same because although the first team is the same in both cases, in the second one is not.
Exchangeable: If you have one coin (don't care if it's fair or biased) and you flip it two times and you write down one outcome in blue and the other outcome in red, then, the probability of the event (blue = heads and red = tails) is the same if the blue is the first flip's outcome and red is the second flip's or the other way round. In other words, the outcome of the coin can give you no clue at all about if it's the first or the second coin flip. The probability of the event (Final score: 7-1) is different if the game is Barcelona vs Random 3rd division team OR if the game is Random 3rd division team vs Barcelona.
|
Is independence subjective?
The coin tosses that each of the two subjects will conduct will always be independent and identically distributed random variables (and thus exchangeable) no matter what they think. The underlying pro
|
39,885
|
Does $X\stackrel{d}\to X_1$ and $Y\stackrel{d}\to Y_1$ imply $X+Y\stackrel{d}\to X_1+Y_1$?
|
What $X+Y$ and $X_1+Y_1$ converge to depends upon the joint distributions of $(X,Y)$ and $(X_1,Y_1)$; what $X, X_1, Y, Y_1$ converge to individually depends upon the marginal distributions. You can have the same marginal distributions with different joint distributions. Because the joint distributions may be different, functions of both variables may have different distributions as well. As convergence of the marginal distributions to the same distribution does not imply convergence of the joint distributions to the same distribution, the answer to your question is "no".
For a simple example using equality of distributions rather than convergence, let $X, X_1$ be i.i.d. $\text{Normal}(0,1)$, with $Y = X$ and $Y_1 = -X_1$. Then $X = X_1$ in distribution and $Y = Y_1$ in distribution, all four being $\text{Normal}(0,1)$. However, $X+Y \neq X_1+Y_1$ in distribution, the former being distributed $\text{Normal}(0,2)$ and the latter being identically equal to $0$.
Edit:
As @GordonSmyth observes in comments, if the limiting dependence between $X$ and $Y$ is the same as that between $X_1$ and $Y_1$, then the conjecture in the question holds, but not necessarily otherwise. This holds for the case where $X$ and $Y$ are independent and so are $X_1$ and $Y_1$, among others.
|
Does $X\stackrel{d}\to X_1$ and $Y\stackrel{d}\to Y_1$ imply $X+Y\stackrel{d}\to X_1+Y_1$?
|
What $X+Y$ and $X_1+Y_1$ converge to depends upon the joint distributions of $(X,Y)$ and $(X_1,Y_1)$; what $X, X_1, Y, Y_1$ converge to individually depends upon the marginal distributions. You can h
|
Does $X\stackrel{d}\to X_1$ and $Y\stackrel{d}\to Y_1$ imply $X+Y\stackrel{d}\to X_1+Y_1$?
What $X+Y$ and $X_1+Y_1$ converge to depends upon the joint distributions of $(X,Y)$ and $(X_1,Y_1)$; what $X, X_1, Y, Y_1$ converge to individually depends upon the marginal distributions. You can have the same marginal distributions with different joint distributions. Because the joint distributions may be different, functions of both variables may have different distributions as well. As convergence of the marginal distributions to the same distribution does not imply convergence of the joint distributions to the same distribution, the answer to your question is "no".
For a simple example using equality of distributions rather than convergence, let $X, X_1$ be i.i.d. $\text{Normal}(0,1)$, with $Y = X$ and $Y_1 = -X_1$. Then $X = X_1$ in distribution and $Y = Y_1$ in distribution, all four being $\text{Normal}(0,1)$. However, $X+Y \neq X_1+Y_1$ in distribution, the former being distributed $\text{Normal}(0,2)$ and the latter being identically equal to $0$.
Edit:
As @GordonSmyth observes in comments, if the limiting dependence between $X$ and $Y$ is the same as that between $X_1$ and $Y_1$, then the conjecture in the question holds, but not necessarily otherwise. This holds for the case where $X$ and $Y$ are independent and so are $X_1$ and $Y_1$, among others.
|
Does $X\stackrel{d}\to X_1$ and $Y\stackrel{d}\to Y_1$ imply $X+Y\stackrel{d}\to X_1+Y_1$?
What $X+Y$ and $X_1+Y_1$ converge to depends upon the joint distributions of $(X,Y)$ and $(X_1,Y_1)$; what $X, X_1, Y, Y_1$ converge to individually depends upon the marginal distributions. You can h
|
39,886
|
Approximating the median of a $\Gamma(\alpha,1)$ distribution with $0<\alpha<1$
|
Let $\mu_\alpha$ be the median of a $\Gamma(\alpha)$ distribution. This means the area under the density $$f_{\Gamma(\alpha)}(x) = \frac{x^{\alpha-1}}{\Gamma(\alpha)} \,e^{-x}$$ between $x=0$ and $x=\mu_\alpha$ equals $1/2.$ A graph of $f_{\Gamma(\alpha)}$ is sketched here in black (for $\alpha=0.3$), understanding the graph extends infinitely upwards as $x$ approaches $0$ and flattens down to $0$ as $x$ grows large:
The median $\mu_\alpha$ separates the left half of the area (darkened) from the right half. The dotted red curve is an upper bound for the Gamma density, enabling a lower bound for the median to be found by using the area under the red curve instead of the gray area.
$1 - x \le e^{-x} \le 1$ for $x \ge 0$ implies
$$\frac{x^{\alpha-1}}{\Gamma(\alpha)} \,(1-x) \le f_{\Gamma(\alpha)}(x) \le \frac{x^{\alpha-1}}{\Gamma(\alpha)}$$
which in turn gives
$$ \int_0^{\mu_\alpha}\frac{x^{\alpha-1}}{\Gamma(\alpha)} \,(1-x)\,\mathrm{d}x \le \int_0^{\mu_\alpha}f_{\Gamma(\alpha)}(x)\,\mathrm{d}x =\frac{1}{2} \le \int_0^{\mu_\alpha}\frac{x^{\alpha-1}}{\Gamma(\alpha)}\,\mathrm{d}x.$$
Evaluating the integrals produces
$$ \frac{\mu_\alpha^\alpha}{\alpha\Gamma(\alpha)}\left(1 - \frac{\alpha}{\alpha+1}\mu_\alpha\right) \le \frac{1}{2} \le \frac{\mu_\alpha^\alpha}{\alpha\Gamma(\alpha)}. $$
This can be simplified a little by solving for $\mu_\alpha$ and recalling $z\Gamma(z) = \Gamma(z+1)$ for any $z:$
$$\mu_\alpha \ge \left(\frac{\Gamma(\alpha+1)}{2}\right)^{1/\alpha} \ge \mu_\alpha\left(1 - \frac{\alpha}{\alpha+1}\,\mu_\alpha\right)^{1/\alpha}.$$
One way to exploit the second inequality is to find a bound for $\mu_\alpha/\alpha$ when $0 \lt \alpha \le 1$. This expression is increasing: we have
$$\frac{\mu_\alpha}{\alpha} = e^{-\varphi(\alpha)} $$
for $\varphi$ as defined in equation (3) in Berg & Pedersen (2006), and Proposition 3.6 in the same paper shows that $\varphi$ is decreasing.
Therefore the value of $\frac{\mu_\alpha}{\alpha}$ at $\alpha=1$, equal to $\log(2)$, provides an upper bound
$$\mu_\alpha \le \alpha \log(2).$$
Crude as this is, it enables us to eliminate $\mu_\alpha$ from the denominator of the right hand side by replacing it with its upper bound, yielding the bounds
$$\left(\frac{\Gamma(\alpha+1)}{2}\right)^{1/\alpha} \le \mu_\alpha \le \left(\frac{\alpha + 1}{\alpha + 1 - \log(2) \alpha^2}\right)^{1/\alpha}\,\left(\frac{\Gamma(\alpha+1)}{2}\right)^{1/\alpha}.$$
Dividing these bounds by $\mu_\alpha$ gives the relative error plotted here:
The lower bound clearly is an accurate approximation for $\alpha \lt 0.2,$ yielding at least two significant decimal digits, while the upper bound gives at least one significant digit throughout.
Having obtained definite bounds (useful for analysis), we may adjust them to produce even more accurate estimates. For instance, $0.9075$ times the upper bound approximates $\mu_\alpha$ to within one percent relative accuracy when $0.16\le\alpha\le 1$ and $1.0035$ times the lower bound achieves $0.4\%$ relative accuracy for $\alpha \lt 0.16.$
|
Approximating the median of a $\Gamma(\alpha,1)$ distribution with $0<\alpha<1$
|
Let $\mu_\alpha$ be the median of a $\Gamma(\alpha)$ distribution. This means the area under the density $$f_{\Gamma(\alpha)}(x) = \frac{x^{\alpha-1}}{\Gamma(\alpha)} \,e^{-x}$$ between $x=0$ and $x=
|
Approximating the median of a $\Gamma(\alpha,1)$ distribution with $0<\alpha<1$
Let $\mu_\alpha$ be the median of a $\Gamma(\alpha)$ distribution. This means the area under the density $$f_{\Gamma(\alpha)}(x) = \frac{x^{\alpha-1}}{\Gamma(\alpha)} \,e^{-x}$$ between $x=0$ and $x=\mu_\alpha$ equals $1/2.$ A graph of $f_{\Gamma(\alpha)}$ is sketched here in black (for $\alpha=0.3$), understanding the graph extends infinitely upwards as $x$ approaches $0$ and flattens down to $0$ as $x$ grows large:
The median $\mu_\alpha$ separates the left half of the area (darkened) from the right half. The dotted red curve is an upper bound for the Gamma density, enabling a lower bound for the median to be found by using the area under the red curve instead of the gray area.
$1 - x \le e^{-x} \le 1$ for $x \ge 0$ implies
$$\frac{x^{\alpha-1}}{\Gamma(\alpha)} \,(1-x) \le f_{\Gamma(\alpha)}(x) \le \frac{x^{\alpha-1}}{\Gamma(\alpha)}$$
which in turn gives
$$ \int_0^{\mu_\alpha}\frac{x^{\alpha-1}}{\Gamma(\alpha)} \,(1-x)\,\mathrm{d}x \le \int_0^{\mu_\alpha}f_{\Gamma(\alpha)}(x)\,\mathrm{d}x =\frac{1}{2} \le \int_0^{\mu_\alpha}\frac{x^{\alpha-1}}{\Gamma(\alpha)}\,\mathrm{d}x.$$
Evaluating the integrals produces
$$ \frac{\mu_\alpha^\alpha}{\alpha\Gamma(\alpha)}\left(1 - \frac{\alpha}{\alpha+1}\mu_\alpha\right) \le \frac{1}{2} \le \frac{\mu_\alpha^\alpha}{\alpha\Gamma(\alpha)}. $$
This can be simplified a little by solving for $\mu_\alpha$ and recalling $z\Gamma(z) = \Gamma(z+1)$ for any $z:$
$$\mu_\alpha \ge \left(\frac{\Gamma(\alpha+1)}{2}\right)^{1/\alpha} \ge \mu_\alpha\left(1 - \frac{\alpha}{\alpha+1}\,\mu_\alpha\right)^{1/\alpha}.$$
One way to exploit the second inequality is to find a bound for $\mu_\alpha/\alpha$ when $0 \lt \alpha \le 1$. This expression is increasing: we have
$$\frac{\mu_\alpha}{\alpha} = e^{-\varphi(\alpha)} $$
for $\varphi$ as defined in equation (3) in Berg & Pedersen (2006), and Proposition 3.6 in the same paper shows that $\varphi$ is decreasing.
Therefore the value of $\frac{\mu_\alpha}{\alpha}$ at $\alpha=1$, equal to $\log(2)$, provides an upper bound
$$\mu_\alpha \le \alpha \log(2).$$
Crude as this is, it enables us to eliminate $\mu_\alpha$ from the denominator of the right hand side by replacing it with its upper bound, yielding the bounds
$$\left(\frac{\Gamma(\alpha+1)}{2}\right)^{1/\alpha} \le \mu_\alpha \le \left(\frac{\alpha + 1}{\alpha + 1 - \log(2) \alpha^2}\right)^{1/\alpha}\,\left(\frac{\Gamma(\alpha+1)}{2}\right)^{1/\alpha}.$$
Dividing these bounds by $\mu_\alpha$ gives the relative error plotted here:
The lower bound clearly is an accurate approximation for $\alpha \lt 0.2,$ yielding at least two significant decimal digits, while the upper bound gives at least one significant digit throughout.
Having obtained definite bounds (useful for analysis), we may adjust them to produce even more accurate estimates. For instance, $0.9075$ times the upper bound approximates $\mu_\alpha$ to within one percent relative accuracy when $0.16\le\alpha\le 1$ and $1.0035$ times the lower bound achieves $0.4\%$ relative accuracy for $\alpha \lt 0.16.$
|
Approximating the median of a $\Gamma(\alpha,1)$ distribution with $0<\alpha<1$
Let $\mu_\alpha$ be the median of a $\Gamma(\alpha)$ distribution. This means the area under the density $$f_{\Gamma(\alpha)}(x) = \frac{x^{\alpha-1}}{\Gamma(\alpha)} \,e^{-x}$$ between $x=0$ and $x=
|
39,887
|
Approximating the median of a $\Gamma(\alpha,1)$ distribution with $0<\alpha<1$
|
The other answer by whuber gives some nice simple bounds for the median. In this answer I will give an alternative closed form approximation based on finite Newton iteration to the true quantile. My answer uses the lower incomplete Gamma function $\gamma$ (so perhaps you consider that cheating), but it does not require the inverse function. in nay case, the quantile equation $F(x) = p$ can be written as:
$$\begin{align}
p = F(x)
= \frac{\gamma(\alpha, x)}{\Gamma(\alpha)}.
\end{align}$$
We can rewrite this as the implicit equation $H(x|p,\alpha)=0$ using the function:
$$H(x|p,\alpha) \equiv \Big[ p \Gamma(\alpha) - \gamma(\alpha, x) \Big] e^x.$$
The first and second derivatives of this function are:
$$\begin{align}
\frac{dH}{dx}(x|p,\alpha)
&= H(x|p,\alpha) - x^{\alpha-1}, \\[12pt]
\frac{d^2 H}{dx^2}(x|p,\alpha)
&= H(x|p,\alpha) - x^{\alpha-1} - (\alpha-1) x^{\alpha-2}. \\[6pt]
\end{align}$$
The second order Newton equation is:
$$x_{t+1} = x_t - \frac{H(x_t|p,\alpha)}{H(x_t|p,\alpha) - x_t^{\alpha-1}}
\Bigg[ 1 + \frac{H(x_t|p,\alpha) (H(x_t|p,\alpha) - x^{\alpha-1} - (\alpha-1) x^{\alpha-2})}{2 (H(x_t|p,\alpha) - x^{\alpha-1})^2} \Bigg].$$
Unless I am mistaken, the initial power series here is valid for all $\alpha>0$ so it should work for the range of values of interest in your question. If you start at a point reasonably close to the true quantile (e.g., one of the bounds that whuber gives in his answer), we would expect fairly rapid convergence to the true quantile. Thus, a valid approximation to the true quantile would be to run this Newton iteration some finite number of steps.
Testing this iterative method: Here is a simple example to confirm that the iterative method is working. Suppose we consider the median of the distribution $\text{Gamma}(2, 1)$. We will start the iterative procedure at the upper-bound approximation in whuber's answer, which is:
$$x_0 = 2 \log 2 = 1.678347.$$
In the code below we will use $m = 4$ iterations of the Newton method, which gives the tiny approximation error of $-2.220446 \times 10^{-16}$. This code uses second-order Newton, but it is possible to get quite a good approximation even with the first order approximation.
#Define the implicit function
H <- function(x, p, alpha) {
H <- gamma(alpha)*(p - pgamma(x, alpha, 1))*exp(x);
attr(H, 'gradient') <- H - x^(alpha-1);
attr(H, 'Hessian') <- attributes(H)$gradient - (alpha-1)*x^(alpha-2);
H; }
#Set the parameters
alpha <- 2;
p <- 0.5;
#Perform m Newton iterations
m <- 4;
x <- rep(NA, m+1);
x[1] <- alpha*log(2);
for (t in 1:m) {
HHH <- H(x[t], p, alpha);
HHD <- attributes(HHH)$gradient;
HDD <- attributes(HHH)$gradient;
x[t+1] <- x[t] - HHH/HHD*(1 + HHH*HDD/(2*HHD^2)); }
#Here is the approximation
x[m+1];
[1] 1.678347
#Here is the true median
qgamma(p, alpha, 1);
[1] 1.678347
#Here is the approximation error
x[m+1] - qgamma(p, alpha, 1)
[1] -2.220446e-16
Anyway, I'm not sure if this type of approximation is useful for your purposes, but it does involve a finite number of iterations. Obviously it uses the evaluation of the incomplete Gamma function, so it is not "closed form". It may be possible to create a closed form version by using a closed form approximation to the incomplete gamma function, and that would allow you to start at the approximation given by whuber, and then iterate towards the true median.
|
Approximating the median of a $\Gamma(\alpha,1)$ distribution with $0<\alpha<1$
|
The other answer by whuber gives some nice simple bounds for the median. In this answer I will give an alternative closed form approximation based on finite Newton iteration to the true quantile. My
|
Approximating the median of a $\Gamma(\alpha,1)$ distribution with $0<\alpha<1$
The other answer by whuber gives some nice simple bounds for the median. In this answer I will give an alternative closed form approximation based on finite Newton iteration to the true quantile. My answer uses the lower incomplete Gamma function $\gamma$ (so perhaps you consider that cheating), but it does not require the inverse function. in nay case, the quantile equation $F(x) = p$ can be written as:
$$\begin{align}
p = F(x)
= \frac{\gamma(\alpha, x)}{\Gamma(\alpha)}.
\end{align}$$
We can rewrite this as the implicit equation $H(x|p,\alpha)=0$ using the function:
$$H(x|p,\alpha) \equiv \Big[ p \Gamma(\alpha) - \gamma(\alpha, x) \Big] e^x.$$
The first and second derivatives of this function are:
$$\begin{align}
\frac{dH}{dx}(x|p,\alpha)
&= H(x|p,\alpha) - x^{\alpha-1}, \\[12pt]
\frac{d^2 H}{dx^2}(x|p,\alpha)
&= H(x|p,\alpha) - x^{\alpha-1} - (\alpha-1) x^{\alpha-2}. \\[6pt]
\end{align}$$
The second order Newton equation is:
$$x_{t+1} = x_t - \frac{H(x_t|p,\alpha)}{H(x_t|p,\alpha) - x_t^{\alpha-1}}
\Bigg[ 1 + \frac{H(x_t|p,\alpha) (H(x_t|p,\alpha) - x^{\alpha-1} - (\alpha-1) x^{\alpha-2})}{2 (H(x_t|p,\alpha) - x^{\alpha-1})^2} \Bigg].$$
Unless I am mistaken, the initial power series here is valid for all $\alpha>0$ so it should work for the range of values of interest in your question. If you start at a point reasonably close to the true quantile (e.g., one of the bounds that whuber gives in his answer), we would expect fairly rapid convergence to the true quantile. Thus, a valid approximation to the true quantile would be to run this Newton iteration some finite number of steps.
Testing this iterative method: Here is a simple example to confirm that the iterative method is working. Suppose we consider the median of the distribution $\text{Gamma}(2, 1)$. We will start the iterative procedure at the upper-bound approximation in whuber's answer, which is:
$$x_0 = 2 \log 2 = 1.678347.$$
In the code below we will use $m = 4$ iterations of the Newton method, which gives the tiny approximation error of $-2.220446 \times 10^{-16}$. This code uses second-order Newton, but it is possible to get quite a good approximation even with the first order approximation.
#Define the implicit function
H <- function(x, p, alpha) {
H <- gamma(alpha)*(p - pgamma(x, alpha, 1))*exp(x);
attr(H, 'gradient') <- H - x^(alpha-1);
attr(H, 'Hessian') <- attributes(H)$gradient - (alpha-1)*x^(alpha-2);
H; }
#Set the parameters
alpha <- 2;
p <- 0.5;
#Perform m Newton iterations
m <- 4;
x <- rep(NA, m+1);
x[1] <- alpha*log(2);
for (t in 1:m) {
HHH <- H(x[t], p, alpha);
HHD <- attributes(HHH)$gradient;
HDD <- attributes(HHH)$gradient;
x[t+1] <- x[t] - HHH/HHD*(1 + HHH*HDD/(2*HHD^2)); }
#Here is the approximation
x[m+1];
[1] 1.678347
#Here is the true median
qgamma(p, alpha, 1);
[1] 1.678347
#Here is the approximation error
x[m+1] - qgamma(p, alpha, 1)
[1] -2.220446e-16
Anyway, I'm not sure if this type of approximation is useful for your purposes, but it does involve a finite number of iterations. Obviously it uses the evaluation of the incomplete Gamma function, so it is not "closed form". It may be possible to create a closed form version by using a closed form approximation to the incomplete gamma function, and that would allow you to start at the approximation given by whuber, and then iterate towards the true median.
|
Approximating the median of a $\Gamma(\alpha,1)$ distribution with $0<\alpha<1$
The other answer by whuber gives some nice simple bounds for the median. In this answer I will give an alternative closed form approximation based on finite Newton iteration to the true quantile. My
|
39,888
|
Using all Metropolis-Hastings proposals to estimate an integral
|
Recycling proposed values in a Metropolis-Hastings algorithm goes under the name of Rao-Blackwellisation. For instance, we made such a proposal in
Casella and Robert (1996) Rao-Blackwellisation of sampling schemes.
Douc and Robert (2013) A vanilla Rao-Blackwellisation of Metropolis-Hastings algorithms
Note that the weighting you propose in the question:
$$[1-\alpha(x_i,y_{i+1})]h(x_i)+\alpha(x_i,y_{i+1})h(y_i)$$
is not optimal in that it is not guaranteed to bring the variance down. Even the one I produce [above] in one of my MCMC course slides does not always reduce the variance because of the correlation between the different terms. (Only the data augmentation case leads to a sure reduction in the variance, cf this fantastic paper by Liu, Wong and Long, 1994. And vanilla Rao-Blackwellisation.)
|
Using all Metropolis-Hastings proposals to estimate an integral
|
Recycling proposed values in a Metropolis-Hastings algorithm goes under the name of Rao-Blackwellisation. For instance, we made such a proposal in
Casella and Robert (1996) Rao-Blackwellisation of s
|
Using all Metropolis-Hastings proposals to estimate an integral
Recycling proposed values in a Metropolis-Hastings algorithm goes under the name of Rao-Blackwellisation. For instance, we made such a proposal in
Casella and Robert (1996) Rao-Blackwellisation of sampling schemes.
Douc and Robert (2013) A vanilla Rao-Blackwellisation of Metropolis-Hastings algorithms
Note that the weighting you propose in the question:
$$[1-\alpha(x_i,y_{i+1})]h(x_i)+\alpha(x_i,y_{i+1})h(y_i)$$
is not optimal in that it is not guaranteed to bring the variance down. Even the one I produce [above] in one of my MCMC course slides does not always reduce the variance because of the correlation between the different terms. (Only the data augmentation case leads to a sure reduction in the variance, cf this fantastic paper by Liu, Wong and Long, 1994. And vanilla Rao-Blackwellisation.)
|
Using all Metropolis-Hastings proposals to estimate an integral
Recycling proposed values in a Metropolis-Hastings algorithm goes under the name of Rao-Blackwellisation. For instance, we made such a proposal in
Casella and Robert (1996) Rao-Blackwellisation of s
|
39,889
|
Using all Metropolis-Hastings proposals to estimate an integral
|
This looks similar to "local" importance sampling. In the literature, constructing estimators of this sort seem to termed as "waste-recyling", and quick search yields a few papers:
This thesis by Murray
PNAS paper by Freknel here
Does waste-recyling help by Delmas and Jourdain here
Their use in parallel MCMC here
Further search using the keyword "waste-recyling" and look within the above references might give you some more papers.
|
Using all Metropolis-Hastings proposals to estimate an integral
|
This looks similar to "local" importance sampling. In the literature, constructing estimators of this sort seem to termed as "waste-recyling", and quick search yields a few papers:
This thesis by Mur
|
Using all Metropolis-Hastings proposals to estimate an integral
This looks similar to "local" importance sampling. In the literature, constructing estimators of this sort seem to termed as "waste-recyling", and quick search yields a few papers:
This thesis by Murray
PNAS paper by Freknel here
Does waste-recyling help by Delmas and Jourdain here
Their use in parallel MCMC here
Further search using the keyword "waste-recyling" and look within the above references might give you some more papers.
|
Using all Metropolis-Hastings proposals to estimate an integral
This looks similar to "local" importance sampling. In the literature, constructing estimators of this sort seem to termed as "waste-recyling", and quick search yields a few papers:
This thesis by Mur
|
39,890
|
Which likelihood function is used in linear regression?
|
As you say, in this case the choice doesn't matter; the maximization over $w$ is the same. But you touch on a good point.
Typically for regression problems we prefer to write the version with the conditioning on $x$ because we think of regression as modeling the conditional distribution $p(y | x)$ while ignoring the details of what $p(x)$ may look like. Succinctly, we only want to model how $y$ responds to $x$, and we don't care about how $x$ itself.
To see why, consider the model $Y = f(X) + \varepsilon$, where $\varepsilon \sim \mathcal{N}(0, \sigma^2)$, we want the estimate function $\hat{f}$ we produce to be as close to $f$ as possible (on average, and measured by e.g. least squares).
So suppose we have known data $(x_1, f(x_1)), ..., (x_N, f(x_N))$. Ultimately we just want to pull $\hat{f}(x_1), ..., \hat{f}(x_N)$ close to $f(x_1), ..., f(x_N)$. It doesn't matter the distribution $p(x)$ of how the inputs are scattered, as long as $\hat{f}$ is close to $f$ on those values ($f$ being how $y$ "responds" to $x$).
Here's how the math works out. From an MLE standpoint the goal is to get our likelihoods $P(x,y|w)$ as large as possible, but as you say, we are not modeling $P(x)$ through $w$, so $P(x)$ factors out and doesn't matter. From a fitting standpoint, if we want to minimize expected prediction error over $f$,
$$\min_f \text{EPE}(f) = \min_f \mathbb{E}(Y - f(X))^2$$
omitting some computation we obtain the minimizing $f$ to be
$$f(x) = \mathbb{E}(Y | X = x)$$
so for least squares loss, the best possible $f$ depends only on the conditional distribution $p(y | x)$, and estimating it should not require any additional information.
However, in classification problems (logistic regression, linear discriminant analysis, Naive Bayes) there is a difference between a "generative" and a "discriminative" model; generative models do not condition on $x$ and discriminative models do. For instance, in linear discriminant analysis we do model $P(x)$ through $w$---we also do not use least squares loss in those.
|
Which likelihood function is used in linear regression?
|
As you say, in this case the choice doesn't matter; the maximization over $w$ is the same. But you touch on a good point.
Typically for regression problems we prefer to write the version with the cond
|
Which likelihood function is used in linear regression?
As you say, in this case the choice doesn't matter; the maximization over $w$ is the same. But you touch on a good point.
Typically for regression problems we prefer to write the version with the conditioning on $x$ because we think of regression as modeling the conditional distribution $p(y | x)$ while ignoring the details of what $p(x)$ may look like. Succinctly, we only want to model how $y$ responds to $x$, and we don't care about how $x$ itself.
To see why, consider the model $Y = f(X) + \varepsilon$, where $\varepsilon \sim \mathcal{N}(0, \sigma^2)$, we want the estimate function $\hat{f}$ we produce to be as close to $f$ as possible (on average, and measured by e.g. least squares).
So suppose we have known data $(x_1, f(x_1)), ..., (x_N, f(x_N))$. Ultimately we just want to pull $\hat{f}(x_1), ..., \hat{f}(x_N)$ close to $f(x_1), ..., f(x_N)$. It doesn't matter the distribution $p(x)$ of how the inputs are scattered, as long as $\hat{f}$ is close to $f$ on those values ($f$ being how $y$ "responds" to $x$).
Here's how the math works out. From an MLE standpoint the goal is to get our likelihoods $P(x,y|w)$ as large as possible, but as you say, we are not modeling $P(x)$ through $w$, so $P(x)$ factors out and doesn't matter. From a fitting standpoint, if we want to minimize expected prediction error over $f$,
$$\min_f \text{EPE}(f) = \min_f \mathbb{E}(Y - f(X))^2$$
omitting some computation we obtain the minimizing $f$ to be
$$f(x) = \mathbb{E}(Y | X = x)$$
so for least squares loss, the best possible $f$ depends only on the conditional distribution $p(y | x)$, and estimating it should not require any additional information.
However, in classification problems (logistic regression, linear discriminant analysis, Naive Bayes) there is a difference between a "generative" and a "discriminative" model; generative models do not condition on $x$ and discriminative models do. For instance, in linear discriminant analysis we do model $P(x)$ through $w$---we also do not use least squares loss in those.
|
Which likelihood function is used in linear regression?
As you say, in this case the choice doesn't matter; the maximization over $w$ is the same. But you touch on a good point.
Typically for regression problems we prefer to write the version with the cond
|
39,891
|
Which likelihood function is used in linear regression?
|
Linear regression is about how $x$ influences/varies with $y$, the outcome or response variable. The model equation is
$$ Y_i =\beta_0 + \beta_1 x_{i1} + \dotsm + \beta_p x_{ip}+\epsilon_i
$$ say, and how $x$ is distributed doesn't by itself give information about the $\beta$'s. That's why your second form of likelihood is irrelevant, so is not used.
See Definition and delimitation of regression model for the meaning of *regression model**, also What are the differences between stochastic v.s. fixed regressors in linear regression model? and especially my answer here: What is the difference between conditioning on regressors vs. treating them as fixed?
|
Which likelihood function is used in linear regression?
|
Linear regression is about how $x$ influences/varies with $y$, the outcome or response variable. The model equation is
$$ Y_i =\beta_0 + \beta_1 x_{i1} + \dotsm + \beta_p x_{ip}+\epsilon_i
$$ say, an
|
Which likelihood function is used in linear regression?
Linear regression is about how $x$ influences/varies with $y$, the outcome or response variable. The model equation is
$$ Y_i =\beta_0 + \beta_1 x_{i1} + \dotsm + \beta_p x_{ip}+\epsilon_i
$$ say, and how $x$ is distributed doesn't by itself give information about the $\beta$'s. That's why your second form of likelihood is irrelevant, so is not used.
See Definition and delimitation of regression model for the meaning of *regression model**, also What are the differences between stochastic v.s. fixed regressors in linear regression model? and especially my answer here: What is the difference between conditioning on regressors vs. treating them as fixed?
|
Which likelihood function is used in linear regression?
Linear regression is about how $x$ influences/varies with $y$, the outcome or response variable. The model equation is
$$ Y_i =\beta_0 + \beta_1 x_{i1} + \dotsm + \beta_p x_{ip}+\epsilon_i
$$ say, an
|
39,892
|
Which likelihood function is used in linear regression?
|
That's a good question since the difference is a bit subtle - hopefully this helps.
The difference between in calculating $p(y|x,w)$ and $p(y,x|w)$ lies in whether you model X as being fixed or random. In the first, you're looking for the joint probability of X and Y conditioned on w, whereas on the 2nd one, you want to determine the probability of Y conditioned on X and w (usually denoted as $\beta$ in statistical settings).
Usually, in simple linear regression,
$$Y = \beta_0 + \beta_1 X + \epsilon$$
you model X as being fixed and independent from $\epsilon$ which follows a $\sim N(0,\sigma^2)$ distribution. That is, Y is modeled as a linear function of some fixed input (X) with some random noise ($\epsilon$). Therefore, it makes sense to model it as $p(y|X,w)$ in this setting as X is fixed or modeled as constant, which is usually denoted explicitly as $X=x$.
Mathematically, when X is fixed, p(X) =1 as it is constant. Therefore
$$p(y,X|w) = p(y|X,w)p(X) \implies p(y,X|w)= p(y|X,w)$$
If X is not constant and given, then p(X) is no longer 1, and the above doesn't hold, so it all comes down to whether you model X as being random or fixed.
|
Which likelihood function is used in linear regression?
|
That's a good question since the difference is a bit subtle - hopefully this helps.
The difference between in calculating $p(y|x,w)$ and $p(y,x|w)$ lies in whether you model X as being fixed or rando
|
Which likelihood function is used in linear regression?
That's a good question since the difference is a bit subtle - hopefully this helps.
The difference between in calculating $p(y|x,w)$ and $p(y,x|w)$ lies in whether you model X as being fixed or random. In the first, you're looking for the joint probability of X and Y conditioned on w, whereas on the 2nd one, you want to determine the probability of Y conditioned on X and w (usually denoted as $\beta$ in statistical settings).
Usually, in simple linear regression,
$$Y = \beta_0 + \beta_1 X + \epsilon$$
you model X as being fixed and independent from $\epsilon$ which follows a $\sim N(0,\sigma^2)$ distribution. That is, Y is modeled as a linear function of some fixed input (X) with some random noise ($\epsilon$). Therefore, it makes sense to model it as $p(y|X,w)$ in this setting as X is fixed or modeled as constant, which is usually denoted explicitly as $X=x$.
Mathematically, when X is fixed, p(X) =1 as it is constant. Therefore
$$p(y,X|w) = p(y|X,w)p(X) \implies p(y,X|w)= p(y|X,w)$$
If X is not constant and given, then p(X) is no longer 1, and the above doesn't hold, so it all comes down to whether you model X as being random or fixed.
|
Which likelihood function is used in linear regression?
That's a good question since the difference is a bit subtle - hopefully this helps.
The difference between in calculating $p(y|x,w)$ and $p(y,x|w)$ lies in whether you model X as being fixed or rando
|
39,893
|
Can we use two convolutional layers without a activation layer in middle of them?
|
Since convolution is a linear operator, two consecutive convolutional layers can be realized by a single convolutional layer if there is no non-linear activation layer between them. Then, it is trivial to train one extra layer which has no positive effect on the representational power of your model.
|
Can we use two convolutional layers without a activation layer in middle of them?
|
Since convolution is a linear operator, two consecutive convolutional layers can be realized by a single convolutional layer if there is no non-linear activation layer between them. Then, it is trivia
|
Can we use two convolutional layers without a activation layer in middle of them?
Since convolution is a linear operator, two consecutive convolutional layers can be realized by a single convolutional layer if there is no non-linear activation layer between them. Then, it is trivial to train one extra layer which has no positive effect on the representational power of your model.
|
Can we use two convolutional layers without a activation layer in middle of them?
Since convolution is a linear operator, two consecutive convolutional layers can be realized by a single convolutional layer if there is no non-linear activation layer between them. Then, it is trivia
|
39,894
|
Can we use two convolutional layers without a activation layer in middle of them?
|
Stacking convolutions is equivalent to convolution, but with different filter size. It might be that the effectively bigger filter gives you different results, but there exists appropriately sized conv layer that is equivalent wiith two conv layers (if the boundary conditions are right)
|
Can we use two convolutional layers without a activation layer in middle of them?
|
Stacking convolutions is equivalent to convolution, but with different filter size. It might be that the effectively bigger filter gives you different results, but there exists appropriately sized con
|
Can we use two convolutional layers without a activation layer in middle of them?
Stacking convolutions is equivalent to convolution, but with different filter size. It might be that the effectively bigger filter gives you different results, but there exists appropriately sized conv layer that is equivalent wiith two conv layers (if the boundary conditions are right)
|
Can we use two convolutional layers without a activation layer in middle of them?
Stacking convolutions is equivalent to convolution, but with different filter size. It might be that the effectively bigger filter gives you different results, but there exists appropriately sized con
|
39,895
|
What's an example of an estimator that is $o_p(n^{-1/2})$?
|
Estimators of percentiles can act like this.
The idea is that when a great deal of probability is concentrated in small neighborhoods around a percentile, then the sample percentile will tend to come extremely close to the true percentile. (Indeed, an extreme case occurs when a distribution has an atom at a percentile, because for sufficiently large samples it is more and more likely that the sample percentile will exactly equal the distribution percentile.)
Rather than get too involved with the analysis, let me present one of the simpler examples of estimating medians, using my post at Central Limit Theorem for Sample Medians as a point of departure. There I consider a distribution $F$ for a sample of size $n$ (assumed to be an even number for convenience) and introduce the Beta$(n/2+1,n/2+1)$ distribution to describe the sample median.
To translate that setting to this one, I propose estimating the median $\tilde \mu$ of $F$ by means of the sample median. If we let $1/2-q_\alpha$ be the lower $100\alpha/2$ percentile of $G$ and $1/2+q_\alpha$ its upper $100\alpha/2$ percentile, then with probability at least $1-\alpha,$ the sample median will lie between $F^{-1}(1/2-q_\alpha)$ and $F^{-1}(1/2+q_\alpha).$
There exist distributions where, given sufficiently small $\epsilon\gt 0,$ for all $q$ with $1/2-\epsilon\lt q \lt 1/2+\epsilon,$
$$F^{-1}(q) = C \operatorname{sgn}(q) |q|^p.$$
Here, $C$ is a positive constant and $p \gt 0.$ (Indeed, this describes the behavior of "most" distributions, but typically $p=1.$) Thus, on the interval $(F^{-1}(1/2-\epsilon), F^{-1}(1/2+\epsilon)),$ $F$ has a density $f.$ When $p\gt 1,$ $f$ diverges at $F^{-1}(1/2)$ because the graph of $F$ becomes vertical there. This signals the special behavior sought in the question--but it remains to analyze what happens.
Here are some examples showing graphs of such $F$, labeled by the values of $p.$ The case $p=\infty$ corresponds to an $F$ for which $F^{-1}(1/2+q)$ approaches the median faster than any positive power of $q$ as $q\to 0.$ This particular $F$ is given by
$$F^{-1}(1/2+q) = \operatorname{sgn}(q) \exp\left(1 - \frac{1}{|2q|}\right).$$
These kinds of distributions serve as natural models of the "peakedness" of any distribution at a specified percentile, and as such would have applications in finance, natural systems, and elsewhere: they are not mere mathematical curiosities or "pathologies."
Because the mean of $G$ is $1/2,$ its variance is asymptotically $1/n,$ and it asymptotically is Normal, we conclude that when $n \gg (Z_{\alpha/2} / \epsilon) ^{2},$
$$q_\alpha \lt n^{-1/2}$$
where $Z_{\alpha/2} = \Phi^{-1}(1-\alpha/2)$ is a percentile of the standard Normal distribution. As a result,
$$F^{-1}(1/2+q_\alpha) = C |q_\alpha|^p \lt C n^{-p/2}.$$
This shows that for such distributions,
The sample median approaches the true median in probability at a rate no slower than $n^{-p/2}.$ Selecting $p\gt 1$ gives the desired example (because $O(n^{-p/2})=o(n^{-1/2})$.
To illustrate, consider the distribution functions defined on $x\in [-1,1]$ by
$$F_p(x) = \frac{1}{2}\left(1 + \operatorname{sgn}(x) |x|^{1/p}\right).$$
I simulated samples of size $n=10$ through $n=10000,$ with $500$ iterations of each simulation, to estimate the standard deviation of the sample median. The foregoing assertion is tantamount to claiming that, on log-log axes, the plot of the SD against the sample size has a slope of $-p/2$ when $p$ is finite. (When $p$ is infinite, the curve never becomes linear, but just keeps dropping faster and faster.) This simulation bears out that claim:
Finally, with more detailed analysis it is possible to control the shape of the peak in great detail. This furnishes examples where the estimator does not behave asymptotically according to any law at all: as $n$ grows ever larger, the estimator can bounce around various regimes of asymptotic behavior and never settle down to any definite rate as a function of $n,$ even though (of course) it will be converging towards the true percentile.
For those interested in the details, here is the R code for the simulation and the last figure.
#
# Generate random variates for a distribution with median 0 and "peakedness"
# of order `p` there.
#
rf <- function(n, p=1) {
u <- runif(n, -1, 1)
if (is.infinite(p)) {
sign(u) * exp(1 - abs(1/u))
} else {
sign(u) * abs(u)^p
}
}
#
# Simulate from some of these distributions to estimate the standard deviation
# of the sample median. This will take a few seconds.
#
n.sim <- 500
n <- ceiling(10^(seq(1, 4, length.out=9)))
l.X <- lapply (c(1,2,3,Inf), function(p) {
s <- sapply(n, function(n) {
x <- apply(matrix(rf(n.sim*n, p), nrow=n), 2, median)
sd(x)
})
data.frame(n=n, sd=s, p=p, n.sim=n.sim)
})
X <- do.call(rbind, l.X)
#
# Plot the results.
#
X$p <- factor(X$p)
library(ggplot2)
ggplot(X, aes(n, sd)) +
scale_x_log10() + scale_y_log10() +
geom_smooth(aes(col=p), se=FALSE, span=.9) +
geom_point(aes(fill=p), pch=21)
|
What's an example of an estimator that is $o_p(n^{-1/2})$?
|
Estimators of percentiles can act like this.
The idea is that when a great deal of probability is concentrated in small neighborhoods around a percentile, then the sample percentile will tend to come
|
What's an example of an estimator that is $o_p(n^{-1/2})$?
Estimators of percentiles can act like this.
The idea is that when a great deal of probability is concentrated in small neighborhoods around a percentile, then the sample percentile will tend to come extremely close to the true percentile. (Indeed, an extreme case occurs when a distribution has an atom at a percentile, because for sufficiently large samples it is more and more likely that the sample percentile will exactly equal the distribution percentile.)
Rather than get too involved with the analysis, let me present one of the simpler examples of estimating medians, using my post at Central Limit Theorem for Sample Medians as a point of departure. There I consider a distribution $F$ for a sample of size $n$ (assumed to be an even number for convenience) and introduce the Beta$(n/2+1,n/2+1)$ distribution to describe the sample median.
To translate that setting to this one, I propose estimating the median $\tilde \mu$ of $F$ by means of the sample median. If we let $1/2-q_\alpha$ be the lower $100\alpha/2$ percentile of $G$ and $1/2+q_\alpha$ its upper $100\alpha/2$ percentile, then with probability at least $1-\alpha,$ the sample median will lie between $F^{-1}(1/2-q_\alpha)$ and $F^{-1}(1/2+q_\alpha).$
There exist distributions where, given sufficiently small $\epsilon\gt 0,$ for all $q$ with $1/2-\epsilon\lt q \lt 1/2+\epsilon,$
$$F^{-1}(q) = C \operatorname{sgn}(q) |q|^p.$$
Here, $C$ is a positive constant and $p \gt 0.$ (Indeed, this describes the behavior of "most" distributions, but typically $p=1.$) Thus, on the interval $(F^{-1}(1/2-\epsilon), F^{-1}(1/2+\epsilon)),$ $F$ has a density $f.$ When $p\gt 1,$ $f$ diverges at $F^{-1}(1/2)$ because the graph of $F$ becomes vertical there. This signals the special behavior sought in the question--but it remains to analyze what happens.
Here are some examples showing graphs of such $F$, labeled by the values of $p.$ The case $p=\infty$ corresponds to an $F$ for which $F^{-1}(1/2+q)$ approaches the median faster than any positive power of $q$ as $q\to 0.$ This particular $F$ is given by
$$F^{-1}(1/2+q) = \operatorname{sgn}(q) \exp\left(1 - \frac{1}{|2q|}\right).$$
These kinds of distributions serve as natural models of the "peakedness" of any distribution at a specified percentile, and as such would have applications in finance, natural systems, and elsewhere: they are not mere mathematical curiosities or "pathologies."
Because the mean of $G$ is $1/2,$ its variance is asymptotically $1/n,$ and it asymptotically is Normal, we conclude that when $n \gg (Z_{\alpha/2} / \epsilon) ^{2},$
$$q_\alpha \lt n^{-1/2}$$
where $Z_{\alpha/2} = \Phi^{-1}(1-\alpha/2)$ is a percentile of the standard Normal distribution. As a result,
$$F^{-1}(1/2+q_\alpha) = C |q_\alpha|^p \lt C n^{-p/2}.$$
This shows that for such distributions,
The sample median approaches the true median in probability at a rate no slower than $n^{-p/2}.$ Selecting $p\gt 1$ gives the desired example (because $O(n^{-p/2})=o(n^{-1/2})$.
To illustrate, consider the distribution functions defined on $x\in [-1,1]$ by
$$F_p(x) = \frac{1}{2}\left(1 + \operatorname{sgn}(x) |x|^{1/p}\right).$$
I simulated samples of size $n=10$ through $n=10000,$ with $500$ iterations of each simulation, to estimate the standard deviation of the sample median. The foregoing assertion is tantamount to claiming that, on log-log axes, the plot of the SD against the sample size has a slope of $-p/2$ when $p$ is finite. (When $p$ is infinite, the curve never becomes linear, but just keeps dropping faster and faster.) This simulation bears out that claim:
Finally, with more detailed analysis it is possible to control the shape of the peak in great detail. This furnishes examples where the estimator does not behave asymptotically according to any law at all: as $n$ grows ever larger, the estimator can bounce around various regimes of asymptotic behavior and never settle down to any definite rate as a function of $n,$ even though (of course) it will be converging towards the true percentile.
For those interested in the details, here is the R code for the simulation and the last figure.
#
# Generate random variates for a distribution with median 0 and "peakedness"
# of order `p` there.
#
rf <- function(n, p=1) {
u <- runif(n, -1, 1)
if (is.infinite(p)) {
sign(u) * exp(1 - abs(1/u))
} else {
sign(u) * abs(u)^p
}
}
#
# Simulate from some of these distributions to estimate the standard deviation
# of the sample median. This will take a few seconds.
#
n.sim <- 500
n <- ceiling(10^(seq(1, 4, length.out=9)))
l.X <- lapply (c(1,2,3,Inf), function(p) {
s <- sapply(n, function(n) {
x <- apply(matrix(rf(n.sim*n, p), nrow=n), 2, median)
sd(x)
})
data.frame(n=n, sd=s, p=p, n.sim=n.sim)
})
X <- do.call(rbind, l.X)
#
# Plot the results.
#
X$p <- factor(X$p)
library(ggplot2)
ggplot(X, aes(n, sd)) +
scale_x_log10() + scale_y_log10() +
geom_smooth(aes(col=p), se=FALSE, span=.9) +
geom_point(aes(fill=p), pch=21)
|
What's an example of an estimator that is $o_p(n^{-1/2})$?
Estimators of percentiles can act like this.
The idea is that when a great deal of probability is concentrated in small neighborhoods around a percentile, then the sample percentile will tend to come
|
39,896
|
What's an example of an estimator that is $o_p(n^{-1/2})$?
|
The range for $n$ i.i.d. uniform random variables on $[0, 1]$ has a $\mbox{Beta}(n-1, 2)$ distribution, thus its variance is $\frac{2(n-1)}{(n+1)^2 (n+2)}$. Thus this estimator is $O(n^{-1})$ and thus $o(n^{-1/2})$.
At the other extreme, the range for $n$ i.i.d. exponential random variables has a variance equal to $\frac{1}{\lambda^2}\sum_{k=1}^{n-1}\frac{1}{k^2}$. Thus the variance converges to $\frac{\pi^2}{6\lambda^2}$. Thus it is $O(1)$.
These results are discussed (with proof) in my recent article A Beautiful Result in Probability Theory.
|
What's an example of an estimator that is $o_p(n^{-1/2})$?
|
The range for $n$ i.i.d. uniform random variables on $[0, 1]$ has a $\mbox{Beta}(n-1, 2)$ distribution, thus its variance is $\frac{2(n-1)}{(n+1)^2 (n+2)}$. Thus this estimator is $O(n^{-1})$ and thus
|
What's an example of an estimator that is $o_p(n^{-1/2})$?
The range for $n$ i.i.d. uniform random variables on $[0, 1]$ has a $\mbox{Beta}(n-1, 2)$ distribution, thus its variance is $\frac{2(n-1)}{(n+1)^2 (n+2)}$. Thus this estimator is $O(n^{-1})$ and thus $o(n^{-1/2})$.
At the other extreme, the range for $n$ i.i.d. exponential random variables has a variance equal to $\frac{1}{\lambda^2}\sum_{k=1}^{n-1}\frac{1}{k^2}$. Thus the variance converges to $\frac{\pi^2}{6\lambda^2}$. Thus it is $O(1)$.
These results are discussed (with proof) in my recent article A Beautiful Result in Probability Theory.
|
What's an example of an estimator that is $o_p(n^{-1/2})$?
The range for $n$ i.i.d. uniform random variables on $[0, 1]$ has a $\mbox{Beta}(n-1, 2)$ distribution, thus its variance is $\frac{2(n-1)}{(n+1)^2 (n+2)}$. Thus this estimator is $O(n^{-1})$ and thus
|
39,897
|
What's an example of an estimator that is $o_p(n^{-1/2})$?
|
Here's an example that doesn't involve quantiles/extremes:
Suppose $(X,Y)$ are bivariate Normal with correlation $\rho$ and consider the usual estimator $$\hat\rho=\frac{\sum_i (X_i-\bar X) (Y_i-\bar Y)}{\sqrt{\sum_i (X_i-\bar X)^2\sum_j(Y_j-\bar Y)^2}}$$
Now suppose we want $\rho^2$ and we estimate it with $\hat\rho^2$. If $\rho\neq 0$,
$$\sqrt{n}(\hat\rho^2-\rho^2)\stackrel{d}{\to} N(0,\tau^2_{\rho})$$
for some complicated $\tau^2_{\rho}$, by the delta method.
But if $\rho=0$, $\partial \rho^2/\partial \rho=0$ and the delta- method tells us
$$\sqrt{n}(\hat\rho^2-\rho^2)\stackrel{p}{\to} 0$$
and $\hat\rho=o_p(n^{-1/2})$
|
What's an example of an estimator that is $o_p(n^{-1/2})$?
|
Here's an example that doesn't involve quantiles/extremes:
Suppose $(X,Y)$ are bivariate Normal with correlation $\rho$ and consider the usual estimator $$\hat\rho=\frac{\sum_i (X_i-\bar X) (Y_i-\bar
|
What's an example of an estimator that is $o_p(n^{-1/2})$?
Here's an example that doesn't involve quantiles/extremes:
Suppose $(X,Y)$ are bivariate Normal with correlation $\rho$ and consider the usual estimator $$\hat\rho=\frac{\sum_i (X_i-\bar X) (Y_i-\bar Y)}{\sqrt{\sum_i (X_i-\bar X)^2\sum_j(Y_j-\bar Y)^2}}$$
Now suppose we want $\rho^2$ and we estimate it with $\hat\rho^2$. If $\rho\neq 0$,
$$\sqrt{n}(\hat\rho^2-\rho^2)\stackrel{d}{\to} N(0,\tau^2_{\rho})$$
for some complicated $\tau^2_{\rho}$, by the delta method.
But if $\rho=0$, $\partial \rho^2/\partial \rho=0$ and the delta- method tells us
$$\sqrt{n}(\hat\rho^2-\rho^2)\stackrel{p}{\to} 0$$
and $\hat\rho=o_p(n^{-1/2})$
|
What's an example of an estimator that is $o_p(n^{-1/2})$?
Here's an example that doesn't involve quantiles/extremes:
Suppose $(X,Y)$ are bivariate Normal with correlation $\rho$ and consider the usual estimator $$\hat\rho=\frac{\sum_i (X_i-\bar X) (Y_i-\bar
|
39,898
|
Linking generative, discriminative models to supervised and unsupervised learning
|
Well first I would nitpick your definition. Consider a conditional GAN which given a category $x$ generates a realistic image $y$ in category $x$ -- that is, it models $P(y|x)$. This is arguably not a discriminative model, but it is according to your definition.
One counterexample to claim 1 would be a model like Neural Scene Derendering. It is a generative model with a highly structured latent space, which can only be learned with supervision (because learning structured latent representations is in general a very hard problem).
A counterexample to 3 is that monocular depth and optical flow models can be learned in an unsupervised manner by exploiting geometric and temporal consistencies. (Yet these are discriminative regression models)
Assuming all models can be dichotomized into generative and discriminative and supervised/unsupervised, Claim 4 is the contrapositive of Claim 1. For an explicit counterexample, consider a GAN conditioned on image category -- this would require labeled data to train, yet is generative.
|
Linking generative, discriminative models to supervised and unsupervised learning
|
Well first I would nitpick your definition. Consider a conditional GAN which given a category $x$ generates a realistic image $y$ in category $x$ -- that is, it models $P(y|x)$. This is arguably not a
|
Linking generative, discriminative models to supervised and unsupervised learning
Well first I would nitpick your definition. Consider a conditional GAN which given a category $x$ generates a realistic image $y$ in category $x$ -- that is, it models $P(y|x)$. This is arguably not a discriminative model, but it is according to your definition.
One counterexample to claim 1 would be a model like Neural Scene Derendering. It is a generative model with a highly structured latent space, which can only be learned with supervision (because learning structured latent representations is in general a very hard problem).
A counterexample to 3 is that monocular depth and optical flow models can be learned in an unsupervised manner by exploiting geometric and temporal consistencies. (Yet these are discriminative regression models)
Assuming all models can be dichotomized into generative and discriminative and supervised/unsupervised, Claim 4 is the contrapositive of Claim 1. For an explicit counterexample, consider a GAN conditioned on image category -- this would require labeled data to train, yet is generative.
|
Linking generative, discriminative models to supervised and unsupervised learning
Well first I would nitpick your definition. Consider a conditional GAN which given a category $x$ generates a realistic image $y$ in category $x$ -- that is, it models $P(y|x)$. This is arguably not a
|
39,899
|
Linking generative, discriminative models to supervised and unsupervised learning
|
A note about the generative-discriminative dichotomy
Although your formal generative-vs-discriminative definition is widely used and very useful [1], I agree with @shimao that it's somewhat of a false dichotomy [2] which starts falling apart when you consider that it's in fact a spectrum which you can even smoothly interpolate between [3], and many popular models do not neatly fall into this dichotomy [4]. Furthermore, it assumes the supervised learning setting and is less useful for classifying unsupervised or semi-supervised methods.
A more general (but more informal) definition [5, 6] to complement it might be:
Discriminative models learn the boundary between classes
Generative models learn the distribution of data
With that in mind...
Addressing the claims
TL;DR There is no blanket claim that can be made linking generative/discriminative models and unsupervised/supervised methods, since every combination of the two exists.
| | Generative | Discriminative |
|--------------+------------------------+-----------------------------------------------|
| Supervised | GANs, Naive Bayes, [7] | SVM, logistic regression,deep neural networks |
| Unsupervised | LDA, normalizing flows | monocular depth and optical flow models, [9] |
Claim 1: False. Many generative models---from the basic like Naive Bayes to complex like a GAN or this generative up-convolutional network [7]---are learnt in a supervised or semi-supervised fashion.
Claim 2.1: True. Unsupervised learning algorithms fall all across the generative-discriminative spectrum, e.g. k-nearest neighbours (kNN) is somewhere in between generative and discriminative [8] (formally generative, informally discriminative).
Claim 2.2: False. Many clustering algorithms are generative models, e.g. latent Dirichlet allocation (LDA).
Claim 3: False. There are discriminative models trained on unsupervised datasets, e.g. [9], and as @shimao pointed out, monocular depth and optical flow models.
Claim 4: False. In disproving Claim 1 we showed some examples of supervised learning algorithms with generative models (Naive Bayes, [7]). Also your phrasing is a bit strange since algorithm != model.
"GANs are generative models that use supervised learning to approximate an intractable cost function" [10]. GANs, like VAEs, have both generative and discriminative components, but are commonly referred to as generative.
Sources
Possibly originating from "Machine Learning - Discriminative and Generative" (Tony Jebara, 2004).
The Generative-Discriminative Fallacy
"Principled Hybrids of Generative and Discriminative Models" (Lasserre et al., 2006)
@shimao's question
benhammer's answer
raegtin's answer
"Learning to Generate Chairs, Tables and Cars with Convolutional Networks" (Dosovitskiy et al., 2017) trains a generative upsampling CNN in a supervised fashion.
Binu Jasim's answer
"Discriminative Unsupervised Feature Learning with Convolutional Neural Networks" (Dosovitskiy et al., 2014)
Goodfellow, Ian (2016). NIPS 2016 GAN tutorial.
|
Linking generative, discriminative models to supervised and unsupervised learning
|
A note about the generative-discriminative dichotomy
Although your formal generative-vs-discriminative definition is widely used and very useful [1], I agree with @shimao that it's somewhat of a false
|
Linking generative, discriminative models to supervised and unsupervised learning
A note about the generative-discriminative dichotomy
Although your formal generative-vs-discriminative definition is widely used and very useful [1], I agree with @shimao that it's somewhat of a false dichotomy [2] which starts falling apart when you consider that it's in fact a spectrum which you can even smoothly interpolate between [3], and many popular models do not neatly fall into this dichotomy [4]. Furthermore, it assumes the supervised learning setting and is less useful for classifying unsupervised or semi-supervised methods.
A more general (but more informal) definition [5, 6] to complement it might be:
Discriminative models learn the boundary between classes
Generative models learn the distribution of data
With that in mind...
Addressing the claims
TL;DR There is no blanket claim that can be made linking generative/discriminative models and unsupervised/supervised methods, since every combination of the two exists.
| | Generative | Discriminative |
|--------------+------------------------+-----------------------------------------------|
| Supervised | GANs, Naive Bayes, [7] | SVM, logistic regression,deep neural networks |
| Unsupervised | LDA, normalizing flows | monocular depth and optical flow models, [9] |
Claim 1: False. Many generative models---from the basic like Naive Bayes to complex like a GAN or this generative up-convolutional network [7]---are learnt in a supervised or semi-supervised fashion.
Claim 2.1: True. Unsupervised learning algorithms fall all across the generative-discriminative spectrum, e.g. k-nearest neighbours (kNN) is somewhere in between generative and discriminative [8] (formally generative, informally discriminative).
Claim 2.2: False. Many clustering algorithms are generative models, e.g. latent Dirichlet allocation (LDA).
Claim 3: False. There are discriminative models trained on unsupervised datasets, e.g. [9], and as @shimao pointed out, monocular depth and optical flow models.
Claim 4: False. In disproving Claim 1 we showed some examples of supervised learning algorithms with generative models (Naive Bayes, [7]). Also your phrasing is a bit strange since algorithm != model.
"GANs are generative models that use supervised learning to approximate an intractable cost function" [10]. GANs, like VAEs, have both generative and discriminative components, but are commonly referred to as generative.
Sources
Possibly originating from "Machine Learning - Discriminative and Generative" (Tony Jebara, 2004).
The Generative-Discriminative Fallacy
"Principled Hybrids of Generative and Discriminative Models" (Lasserre et al., 2006)
@shimao's question
benhammer's answer
raegtin's answer
"Learning to Generate Chairs, Tables and Cars with Convolutional Networks" (Dosovitskiy et al., 2017) trains a generative upsampling CNN in a supervised fashion.
Binu Jasim's answer
"Discriminative Unsupervised Feature Learning with Convolutional Neural Networks" (Dosovitskiy et al., 2014)
Goodfellow, Ian (2016). NIPS 2016 GAN tutorial.
|
Linking generative, discriminative models to supervised and unsupervised learning
A note about the generative-discriminative dichotomy
Although your formal generative-vs-discriminative definition is widely used and very useful [1], I agree with @shimao that it's somewhat of a false
|
39,900
|
Regression as mutual information minimization
|
I don't completely understand your notation; my apologies if I misunderstand. But I think MI is too weak for regression, because it only enforces dependence between variables, rather than any specific relationship (as regression requires). (In fact, it is this generality that makes MI better for detecting hidden statistical relationships.)
For example, in some latent variable generative models (e.g., VAEs, see ELBO surgery: yet another way to carve up the variational evidence lower bound, Hoffman & Johnson), we maximize the mutual information between the data $x$ and its latent representation $z$. But we have to constrain this with other terms (reconstruction likelihood and matching the prior). Indeed, optimizing mutual information is a very active research area in modern machine learning (which I suppose could be considered research in the area of regression), especially in models like variational auto-encoders and generative adversarial networks (see the bottom of this answer).
Separately, something interesting to you might be Bayesian linear regression, which looks at regression from a more general probabilistic viewpoint.
On the other hand, it did make me think of the following simple idea, since mutual information is closely related to KL-divergence:
$$ \mathcal{I}[A;B] = \mathbb{E}_{B}\left[ \mathfrak{D}_\text{KL}[P(A|B)\,||\,P(A)] \right] $$
Suppose we assume the following data generation process:
$$ x\sim\mathcal{U},\;\; y \,|\, x\sim\mathcal{N}(\alpha_r x +\beta_r, \sigma^2_r) $$
We want to learn the parameters $\alpha,\beta$ of a stochastic regressor: given $x$,
$$ \hat{y}\sim\mathcal{N}(\alpha x + \beta, \sigma^2) $$
noting that the KL-divergence is asymmetric,
what is the KL-divergence on the conditional distributions between the data generator and the regressor?
\begin{align}
\mathfrak{D}_\text{KL}[p(y|x)\,||\,p(\hat{y}|x)]
&= \log(\sigma_\hat{y} / \sigma_y) + \frac{\sigma_y^2 + (\mu_y - \mu_{\hat{y}})^2}{2\sigma_{\hat{y}}^2} - \frac{1}{2}\\
&= \log(\sigma) - \log(\sigma_r) + \frac{\sigma_r^2 + (\alpha_r x +\beta_r - \alpha x - \beta)^2}{2\sigma^2} - \frac{1}{2}\\
\end{align}
Suppose we have data $D=\{ (x_i,y_i) \}$. Then we want to minimize
\begin{align}
\sum_i \mathfrak{D}_\text{KL}[p(y_i|x_i)\,||\,p(\hat{y}_i|x_i)]
&= c + \frac{1}{2\sigma^2} \sum_i (y_i - \alpha x_i - \beta)^2
\end{align}
wrt $\alpha$ and $\beta$,
where $c$ is a constant (assuming $\sigma$ and $\sigma_r$ are).
But this just amounts to minimizing the squared error loss here.
|
Regression as mutual information minimization
|
I don't completely understand your notation; my apologies if I misunderstand. But I think MI is too weak for regression, because it only enforces dependence between variables, rather than any specific
|
Regression as mutual information minimization
I don't completely understand your notation; my apologies if I misunderstand. But I think MI is too weak for regression, because it only enforces dependence between variables, rather than any specific relationship (as regression requires). (In fact, it is this generality that makes MI better for detecting hidden statistical relationships.)
For example, in some latent variable generative models (e.g., VAEs, see ELBO surgery: yet another way to carve up the variational evidence lower bound, Hoffman & Johnson), we maximize the mutual information between the data $x$ and its latent representation $z$. But we have to constrain this with other terms (reconstruction likelihood and matching the prior). Indeed, optimizing mutual information is a very active research area in modern machine learning (which I suppose could be considered research in the area of regression), especially in models like variational auto-encoders and generative adversarial networks (see the bottom of this answer).
Separately, something interesting to you might be Bayesian linear regression, which looks at regression from a more general probabilistic viewpoint.
On the other hand, it did make me think of the following simple idea, since mutual information is closely related to KL-divergence:
$$ \mathcal{I}[A;B] = \mathbb{E}_{B}\left[ \mathfrak{D}_\text{KL}[P(A|B)\,||\,P(A)] \right] $$
Suppose we assume the following data generation process:
$$ x\sim\mathcal{U},\;\; y \,|\, x\sim\mathcal{N}(\alpha_r x +\beta_r, \sigma^2_r) $$
We want to learn the parameters $\alpha,\beta$ of a stochastic regressor: given $x$,
$$ \hat{y}\sim\mathcal{N}(\alpha x + \beta, \sigma^2) $$
noting that the KL-divergence is asymmetric,
what is the KL-divergence on the conditional distributions between the data generator and the regressor?
\begin{align}
\mathfrak{D}_\text{KL}[p(y|x)\,||\,p(\hat{y}|x)]
&= \log(\sigma_\hat{y} / \sigma_y) + \frac{\sigma_y^2 + (\mu_y - \mu_{\hat{y}})^2}{2\sigma_{\hat{y}}^2} - \frac{1}{2}\\
&= \log(\sigma) - \log(\sigma_r) + \frac{\sigma_r^2 + (\alpha_r x +\beta_r - \alpha x - \beta)^2}{2\sigma^2} - \frac{1}{2}\\
\end{align}
Suppose we have data $D=\{ (x_i,y_i) \}$. Then we want to minimize
\begin{align}
\sum_i \mathfrak{D}_\text{KL}[p(y_i|x_i)\,||\,p(\hat{y}_i|x_i)]
&= c + \frac{1}{2\sigma^2} \sum_i (y_i - \alpha x_i - \beta)^2
\end{align}
wrt $\alpha$ and $\beta$,
where $c$ is a constant (assuming $\sigma$ and $\sigma_r$ are).
But this just amounts to minimizing the squared error loss here.
|
Regression as mutual information minimization
I don't completely understand your notation; my apologies if I misunderstand. But I think MI is too weak for regression, because it only enforces dependence between variables, rather than any specific
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.