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
31,801
How to interpret coefficients of a multinomial elastic net (glmnet) regression
I emailed kind Dr. Hastie who is the maintainer of the glmnet package and got the following answer: In the traditional case, the base category is arbitrary. In fact you can take a fitted model where say category one is the base category, and simply by subtraction of coefficients, make an equivalent model where another is the base (and the fit is identical). (Care must be taken with the standard errors). Concretely, if category 1 is the base, and you have coefficient vector \beta_k for category k , k=2,…,K (with \beta_1=0) you can make say category K the base. In this case the new coefficients would be \beta’_k = \beta_k-\beta_K and the fitted probabilities would be unchanged. With glmnet we chose a symmetric option instead, because we use regularization. With regularization, it would matter and make a difference if you used an asymmetric representation because of the way the shrinking works. I like the type.multinomial= “grouped” option. In this case a group lasso penalty is applied to the set of coefficients for each feature, and the estimated coefficients average 0. Again, you can post hoc move to an asymmetric representation as above without changing the fitted model.
How to interpret coefficients of a multinomial elastic net (glmnet) regression
I emailed kind Dr. Hastie who is the maintainer of the glmnet package and got the following answer: In the traditional case, the base category is arbitrary. In fact you can take a fitted model where s
How to interpret coefficients of a multinomial elastic net (glmnet) regression I emailed kind Dr. Hastie who is the maintainer of the glmnet package and got the following answer: In the traditional case, the base category is arbitrary. In fact you can take a fitted model where say category one is the base category, and simply by subtraction of coefficients, make an equivalent model where another is the base (and the fit is identical). (Care must be taken with the standard errors). Concretely, if category 1 is the base, and you have coefficient vector \beta_k for category k , k=2,…,K (with \beta_1=0) you can make say category K the base. In this case the new coefficients would be \beta’_k = \beta_k-\beta_K and the fitted probabilities would be unchanged. With glmnet we chose a symmetric option instead, because we use regularization. With regularization, it would matter and make a difference if you used an asymmetric representation because of the way the shrinking works. I like the type.multinomial= “grouped” option. In this case a group lasso penalty is applied to the set of coefficients for each feature, and the estimated coefficients average 0. Again, you can post hoc move to an asymmetric representation as above without changing the fitted model.
How to interpret coefficients of a multinomial elastic net (glmnet) regression I emailed kind Dr. Hastie who is the maintainer of the glmnet package and got the following answer: In the traditional case, the base category is arbitrary. In fact you can take a fitted model where s
31,802
Compute truncated normal distribution with specific mean and variance
What Jarle Tufto points out is that, if $X\sim\mathcal N^+(\mu,\sigma^2)$, then, defining $$\alpha=-\mu/\sigma\quad\text{and}\quad\beta=\infty$$ Wikipedia states that $$\Bbb E_{\mu,\sigma}[X]= \mu + \frac{\varphi(\alpha)-\varphi(\beta)}{\Phi(\beta)-\Phi(\alpha)}\sigma$$ and $$\text{var}_{\mu,\sigma}(X)=\sigma^2\left[1+\frac{\alpha\varphi(\alpha)-\beta\varphi(\beta)}{\Phi(\beta)-\Phi(\alpha)} -\left(\frac{\varphi(\alpha)-\varphi(\beta)}{\Phi(\beta)-\Phi(\alpha)}\right)^2\right]$$ That is, $$\Bbb E_{\mu,\sigma}[X]= \mu + \frac{\varphi(\mu/\sigma)}{1-\Phi(-\mu/\sigma)}\sigma\tag{1}$$ and $$\text{var}_{\mu,\sigma}(X)=\sigma^2\left[1-\frac{\mu\varphi(\mu/\sigma)/\sigma}{1-\Phi(-\mu/\sigma)} -\left(\frac{\varphi(\mu/\sigma)}{1-\Phi(-\mu/\sigma)}\right)^2\right]\tag{2}$$ Given the numerical values of the truncated moments $(\Bbb E_{\mu,\sigma}[X],\text{var}_{\mu,\sigma}(X))$, one can then solve numerically (1) and (2) as a system of two equations in $(\mu,\sigma)$, assuming $(\Bbb E_{\mu,\sigma}[X],\text{var}_{\mu,\sigma}(X))$ is a possible value for a truncated Normal $\mathcal N^+(\mu,\sigma^2)$.
Compute truncated normal distribution with specific mean and variance
What Jarle Tufto points out is that, if $X\sim\mathcal N^+(\mu,\sigma^2)$, then, defining $$\alpha=-\mu/\sigma\quad\text{and}\quad\beta=\infty$$ Wikipedia states that $$\Bbb E_{\mu,\sigma}[X]= \mu +
Compute truncated normal distribution with specific mean and variance What Jarle Tufto points out is that, if $X\sim\mathcal N^+(\mu,\sigma^2)$, then, defining $$\alpha=-\mu/\sigma\quad\text{and}\quad\beta=\infty$$ Wikipedia states that $$\Bbb E_{\mu,\sigma}[X]= \mu + \frac{\varphi(\alpha)-\varphi(\beta)}{\Phi(\beta)-\Phi(\alpha)}\sigma$$ and $$\text{var}_{\mu,\sigma}(X)=\sigma^2\left[1+\frac{\alpha\varphi(\alpha)-\beta\varphi(\beta)}{\Phi(\beta)-\Phi(\alpha)} -\left(\frac{\varphi(\alpha)-\varphi(\beta)}{\Phi(\beta)-\Phi(\alpha)}\right)^2\right]$$ That is, $$\Bbb E_{\mu,\sigma}[X]= \mu + \frac{\varphi(\mu/\sigma)}{1-\Phi(-\mu/\sigma)}\sigma\tag{1}$$ and $$\text{var}_{\mu,\sigma}(X)=\sigma^2\left[1-\frac{\mu\varphi(\mu/\sigma)/\sigma}{1-\Phi(-\mu/\sigma)} -\left(\frac{\varphi(\mu/\sigma)}{1-\Phi(-\mu/\sigma)}\right)^2\right]\tag{2}$$ Given the numerical values of the truncated moments $(\Bbb E_{\mu,\sigma}[X],\text{var}_{\mu,\sigma}(X))$, one can then solve numerically (1) and (2) as a system of two equations in $(\mu,\sigma)$, assuming $(\Bbb E_{\mu,\sigma}[X],\text{var}_{\mu,\sigma}(X))$ is a possible value for a truncated Normal $\mathcal N^+(\mu,\sigma^2)$.
Compute truncated normal distribution with specific mean and variance What Jarle Tufto points out is that, if $X\sim\mathcal N^+(\mu,\sigma^2)$, then, defining $$\alpha=-\mu/\sigma\quad\text{and}\quad\beta=\infty$$ Wikipedia states that $$\Bbb E_{\mu,\sigma}[X]= \mu +
31,803
Compute truncated normal distribution with specific mean and variance
To complement Xi'an's answer, one simple approach to solve numerically such equations would be by using a Taylor series approximation. If we denote $m,s^2$ the target mean and variance of the truncated distributrion, and $\mu,\sigma^2$ the mean and variance of the underlying Gaussian distribution then: \begin{align} m &= \mu+z(\mu/\sigma)\,\sigma\\ s^2 &= \left[1-z(\mu/\sigma)\,\mu/\sigma-z(\mu/\sigma)^2 \right]\sigma^2\\ z(\mu/\sigma) &= \phi(\mu/\sigma)/\Phi(\mu/\sigma) \end{align} The function $z(\mu/\sigma)$ can be approximated with a Taylor's series expansion around $m/s$. Denote $\hat{z}=z(m/s)$, then: \begin{align} z(\mu/\sigma) &\approx \hat{z}+(\mu/\sigma-m/s)\frac{\phi'(m/s)\Phi(m/s)-\phi(m/s)^2}{\Phi(m/s)^2}\\ &= \hat{z}+(\mu/\sigma-m/s)\,(-\hat{z} m/s-\hat{z}^2)\\ &= [1+(m/s)^2+\hat{z} m/s]\hat{z}-(\mu/\sigma)(m/s+\hat{z})\hat{z}\\ &= A - B\mu/\sigma \end{align} Where $A=[1+(m/s)^2+\hat{z} m/s]\hat{z}>0$ and $B=(m/s+\hat{z})\hat{z}>0$. Using this approximation into the first equation we get: \begin{align} m &\approx \mu + (A-B\mu/\sigma)\sigma =(1-B)\mu+A\sigma\\ \Rightarrow \mu &\approx (1-B)^{-1}(m-A\sigma) \end{align} Replacing both approximations into the second equation we get: \begin{align} s^2 &\approx [1-(A-B\mu/\sigma)\mu/\sigma-(A-B\mu/\sigma)^2]\sigma^2\\ &= (1-A^2)\sigma^2-A(1-2B)\mu\sigma+B(1-B)\mu^2\\ &= (1-A^2)\sigma^2-\frac{A(1-2B)}{1-B}(m-A\sigma)\sigma+\frac{B}{1-B}(m-A\sigma)^2\\ \Rightarrow (1-B)s^2 &\approx (1-B)(1-A^2) \sigma^2 -A(1-2B)(m-A\sigma)\sigma +B(m-A\sigma)^2\\ 0 &\approx (1-B)\sigma^2-Am\sigma + Bm^2-(1-B)s^2 \end{align} Such equation has as an approximate solution for $\sigma^2$: \begin{equation} \hat{\sigma}^2 =\frac{2BD+C^2-2D+C\sqrt{C^2-4D(1-B)}}{2(1-B)^2} \end{equation} With $C=Am$, $D=Bm^2-(1-B)s^2$, and provided that $C^2-4D(1-B)>0$ and $\hat{\sigma}^2>0$. The approximate solution for $\mu$ is then: $$ \hat{\mu} = \frac{m-A\hat{\sigma}}{1-B} $$ Thus, given $(m,s)$, one approximate solution $(\hat{\mu},\hat{\sigma}^2)$ for $({\mu},{\sigma}^2)$ can be found following these steps: $\hat{z}=\phi(m/s)/\Phi(m/s)$ $A=[1+(m/s)^2+\hat{z} m/s]\hat{z}$; $B=(m/s+\hat{z})\hat{z}$ $C=Am$; $D=Bm^2-(1-B)s^2$ $\hat{\sigma}^2 =\frac{2BD+C^2-2D+C\sqrt{C^2-4D(1-B)}}{2(1-B)^2}$ (provided $C^2-4D(1-B)>0$ and $\hat{\sigma}^2>0$) $\hat{\mu}=\frac{m-A\hat{\sigma}}{1-B}$
Compute truncated normal distribution with specific mean and variance
To complement Xi'an's answer, one simple approach to solve numerically such equations would be by using a Taylor series approximation. If we denote $m,s^2$ the target mean and variance of the truncat
Compute truncated normal distribution with specific mean and variance To complement Xi'an's answer, one simple approach to solve numerically such equations would be by using a Taylor series approximation. If we denote $m,s^2$ the target mean and variance of the truncated distributrion, and $\mu,\sigma^2$ the mean and variance of the underlying Gaussian distribution then: \begin{align} m &= \mu+z(\mu/\sigma)\,\sigma\\ s^2 &= \left[1-z(\mu/\sigma)\,\mu/\sigma-z(\mu/\sigma)^2 \right]\sigma^2\\ z(\mu/\sigma) &= \phi(\mu/\sigma)/\Phi(\mu/\sigma) \end{align} The function $z(\mu/\sigma)$ can be approximated with a Taylor's series expansion around $m/s$. Denote $\hat{z}=z(m/s)$, then: \begin{align} z(\mu/\sigma) &\approx \hat{z}+(\mu/\sigma-m/s)\frac{\phi'(m/s)\Phi(m/s)-\phi(m/s)^2}{\Phi(m/s)^2}\\ &= \hat{z}+(\mu/\sigma-m/s)\,(-\hat{z} m/s-\hat{z}^2)\\ &= [1+(m/s)^2+\hat{z} m/s]\hat{z}-(\mu/\sigma)(m/s+\hat{z})\hat{z}\\ &= A - B\mu/\sigma \end{align} Where $A=[1+(m/s)^2+\hat{z} m/s]\hat{z}>0$ and $B=(m/s+\hat{z})\hat{z}>0$. Using this approximation into the first equation we get: \begin{align} m &\approx \mu + (A-B\mu/\sigma)\sigma =(1-B)\mu+A\sigma\\ \Rightarrow \mu &\approx (1-B)^{-1}(m-A\sigma) \end{align} Replacing both approximations into the second equation we get: \begin{align} s^2 &\approx [1-(A-B\mu/\sigma)\mu/\sigma-(A-B\mu/\sigma)^2]\sigma^2\\ &= (1-A^2)\sigma^2-A(1-2B)\mu\sigma+B(1-B)\mu^2\\ &= (1-A^2)\sigma^2-\frac{A(1-2B)}{1-B}(m-A\sigma)\sigma+\frac{B}{1-B}(m-A\sigma)^2\\ \Rightarrow (1-B)s^2 &\approx (1-B)(1-A^2) \sigma^2 -A(1-2B)(m-A\sigma)\sigma +B(m-A\sigma)^2\\ 0 &\approx (1-B)\sigma^2-Am\sigma + Bm^2-(1-B)s^2 \end{align} Such equation has as an approximate solution for $\sigma^2$: \begin{equation} \hat{\sigma}^2 =\frac{2BD+C^2-2D+C\sqrt{C^2-4D(1-B)}}{2(1-B)^2} \end{equation} With $C=Am$, $D=Bm^2-(1-B)s^2$, and provided that $C^2-4D(1-B)>0$ and $\hat{\sigma}^2>0$. The approximate solution for $\mu$ is then: $$ \hat{\mu} = \frac{m-A\hat{\sigma}}{1-B} $$ Thus, given $(m,s)$, one approximate solution $(\hat{\mu},\hat{\sigma}^2)$ for $({\mu},{\sigma}^2)$ can be found following these steps: $\hat{z}=\phi(m/s)/\Phi(m/s)$ $A=[1+(m/s)^2+\hat{z} m/s]\hat{z}$; $B=(m/s+\hat{z})\hat{z}$ $C=Am$; $D=Bm^2-(1-B)s^2$ $\hat{\sigma}^2 =\frac{2BD+C^2-2D+C\sqrt{C^2-4D(1-B)}}{2(1-B)^2}$ (provided $C^2-4D(1-B)>0$ and $\hat{\sigma}^2>0$) $\hat{\mu}=\frac{m-A\hat{\sigma}}{1-B}$
Compute truncated normal distribution with specific mean and variance To complement Xi'an's answer, one simple approach to solve numerically such equations would be by using a Taylor series approximation. If we denote $m,s^2$ the target mean and variance of the truncat
31,804
Does the Jensen-Shannon divergence maximise likelihood?
First, it is important to clarify a few things. The KL divergence is a dissimilarity between two distributions, so it cannot maximize the likelihood, which is a function of a single distribution. Given a reference distribution $P(\cdot)$, the value of $\theta$ that minimizes $\text{KL}(P(\cdot)||Q(\cdot|\theta))$ is not the one that maximizes the likelihood. Actually, there is no likelihood because there is no observed value. So, saying that minimizing the KL divergence is equivalent to maximizing the log-likelihood can only mean that choosing $\hat{\theta}$ so as to maximize $Q(x_1, \ldots, x_n|\theta)$, ensures that $ \hat{\theta} \rightarrow \theta^*$, where $$\theta^* = \text{argmin}_\theta \text{ KL}(P(\cdot)||Q(\cdot|\theta)).$$ This is true under some usual regularity conditions. To see this, assume that we compute $Q(x_1, \ldots, x_n|\theta)$, but the sample $x_1, \ldots, x_n$ is actually drawn from $P(\cdot)$. The expected value of the log-likelihood is then $$\int P(x_1, \ldots, x_n) \log Q(x_1, \ldots, x_n|\theta) dx_1 \ldots dx_n.$$ Maximizing this value with respect to $\theta$ is he same as minimizing $$\text{KL}(P(\cdot)||Q(\cdot|\theta)) = \int P(x_1, \ldots, x_n) \log \frac{P(x_1, \ldots, x_n)}{Q(x_1, \ldots, x_n|\theta)}dx_1 \ldots dx_n.$$ This is not an actual proof, but this gives you the main idea. Now, there is no reason why $\theta^*$ should also minimize $$\text{KL}(Q(\cdot|\theta)||P(\cdot)) = \int Q(x_1, \ldots, x_n|\theta) \log \frac{Q(x_1, \ldots, x_n|\theta)}{P(x_1, \ldots, x_n)}dx_1 \ldots dx_n.$$ Your question actually provides a counter-example of this, so it is clear that the value of $\theta$ that minimizes the reverse KL divergence is in general not the same as the maximum likelihood estimate (and thus the same goes for the Jensen-Shannon divergence). What those values minimize is not so well defined. From the argument above, you can see that the minimum of the reverse KL divergence corresponds to computing the likelihood as $P(x_1, \ldots, x_n)$ when $x_1, \ldots, x_n$ is actually drawn from $Q(\cdot|\theta)$, while trying to keep the entropy of $Q(\cdot|\theta)$ as high as possible. The interpretation is not straightforward, but we can think of it as trying to find a "simple" distribution $Q(\cdot|\theta)$ that would "explain" the observations $x_1, \ldots, x_n$ coming from a more complex distribution $P(\cdot)$. This is a typical task of variational inference. The Jensen-Shannon divergence is the average of the two, so one can think of finding a minimum as "a little bit of both", meaning something in between the maximum likelihood estimate and a "simple explanation" for the data.
Does the Jensen-Shannon divergence maximise likelihood?
First, it is important to clarify a few things. The KL divergence is a dissimilarity between two distributions, so it cannot maximize the likelihood, which is a function of a single distribution. G
Does the Jensen-Shannon divergence maximise likelihood? First, it is important to clarify a few things. The KL divergence is a dissimilarity between two distributions, so it cannot maximize the likelihood, which is a function of a single distribution. Given a reference distribution $P(\cdot)$, the value of $\theta$ that minimizes $\text{KL}(P(\cdot)||Q(\cdot|\theta))$ is not the one that maximizes the likelihood. Actually, there is no likelihood because there is no observed value. So, saying that minimizing the KL divergence is equivalent to maximizing the log-likelihood can only mean that choosing $\hat{\theta}$ so as to maximize $Q(x_1, \ldots, x_n|\theta)$, ensures that $ \hat{\theta} \rightarrow \theta^*$, where $$\theta^* = \text{argmin}_\theta \text{ KL}(P(\cdot)||Q(\cdot|\theta)).$$ This is true under some usual regularity conditions. To see this, assume that we compute $Q(x_1, \ldots, x_n|\theta)$, but the sample $x_1, \ldots, x_n$ is actually drawn from $P(\cdot)$. The expected value of the log-likelihood is then $$\int P(x_1, \ldots, x_n) \log Q(x_1, \ldots, x_n|\theta) dx_1 \ldots dx_n.$$ Maximizing this value with respect to $\theta$ is he same as minimizing $$\text{KL}(P(\cdot)||Q(\cdot|\theta)) = \int P(x_1, \ldots, x_n) \log \frac{P(x_1, \ldots, x_n)}{Q(x_1, \ldots, x_n|\theta)}dx_1 \ldots dx_n.$$ This is not an actual proof, but this gives you the main idea. Now, there is no reason why $\theta^*$ should also minimize $$\text{KL}(Q(\cdot|\theta)||P(\cdot)) = \int Q(x_1, \ldots, x_n|\theta) \log \frac{Q(x_1, \ldots, x_n|\theta)}{P(x_1, \ldots, x_n)}dx_1 \ldots dx_n.$$ Your question actually provides a counter-example of this, so it is clear that the value of $\theta$ that minimizes the reverse KL divergence is in general not the same as the maximum likelihood estimate (and thus the same goes for the Jensen-Shannon divergence). What those values minimize is not so well defined. From the argument above, you can see that the minimum of the reverse KL divergence corresponds to computing the likelihood as $P(x_1, \ldots, x_n)$ when $x_1, \ldots, x_n$ is actually drawn from $Q(\cdot|\theta)$, while trying to keep the entropy of $Q(\cdot|\theta)$ as high as possible. The interpretation is not straightforward, but we can think of it as trying to find a "simple" distribution $Q(\cdot|\theta)$ that would "explain" the observations $x_1, \ldots, x_n$ coming from a more complex distribution $P(\cdot)$. This is a typical task of variational inference. The Jensen-Shannon divergence is the average of the two, so one can think of finding a minimum as "a little bit of both", meaning something in between the maximum likelihood estimate and a "simple explanation" for the data.
Does the Jensen-Shannon divergence maximise likelihood? First, it is important to clarify a few things. The KL divergence is a dissimilarity between two distributions, so it cannot maximize the likelihood, which is a function of a single distribution. G
31,805
Random vs Fixed variables in Linear Regression Model
The comment by Jesper indicates the formal point. You are also right that the assumption of whether $X$ is fixed or not has no bearing on the numerical estimates, as we regress $y$ on $X$ with the same command lm in either case. What the assumption is crucially important for, though, is the appropriate interpretation of the results. In particular, when $X$ is random, this opens up the possibility that $E(u|X)\neq0$ or even $E(X'u)\neq0$, i.e., that regressors and errors are not mean independent or not uncorrelated. When this happens, OLS is no longer unbiased or consistent. Loosely speaking, we may no longer interpet the estimates as estimates of causal effects, but rather only as correlations that may or may not be interesting. There are many threads on this page that offer further discussions, see e.g. Understanding and interpreting consistency of OLS, Omitted variable bias: which predictors do I need to include, and why?, Why is OLS estimator of AR(1) coefficient biased?. When the assumption is not satisfied, instrumental variables approaches may provide an alternative, see e.g. What is an instrumental variable?, how to explain instrumental variables to a layman.
Random vs Fixed variables in Linear Regression Model
The comment by Jesper indicates the formal point. You are also right that the assumption of whether $X$ is fixed or not has no bearing on the numerical estimates, as we regress $y$ on $X$ with the sam
Random vs Fixed variables in Linear Regression Model The comment by Jesper indicates the formal point. You are also right that the assumption of whether $X$ is fixed or not has no bearing on the numerical estimates, as we regress $y$ on $X$ with the same command lm in either case. What the assumption is crucially important for, though, is the appropriate interpretation of the results. In particular, when $X$ is random, this opens up the possibility that $E(u|X)\neq0$ or even $E(X'u)\neq0$, i.e., that regressors and errors are not mean independent or not uncorrelated. When this happens, OLS is no longer unbiased or consistent. Loosely speaking, we may no longer interpet the estimates as estimates of causal effects, but rather only as correlations that may or may not be interesting. There are many threads on this page that offer further discussions, see e.g. Understanding and interpreting consistency of OLS, Omitted variable bias: which predictors do I need to include, and why?, Why is OLS estimator of AR(1) coefficient biased?. When the assumption is not satisfied, instrumental variables approaches may provide an alternative, see e.g. What is an instrumental variable?, how to explain instrumental variables to a layman.
Random vs Fixed variables in Linear Regression Model The comment by Jesper indicates the formal point. You are also right that the assumption of whether $X$ is fixed or not has no bearing on the numerical estimates, as we regress $y$ on $X$ with the sam
31,806
What is required for neural network to approximate discontinuous function?
Wikipedia provides a synopsis of the universal approximation theorem. In the mathematical theory of artificial neural networks, the universal approximation theorem states that a feed-forward network with a single hidden layer containing a finite number of neurons can approximate continuous functions on compact subsets of $\mathbb{R}^n$, under mild assumptions on the activation function. This theorem is the core justification for attempting to model complex, nonlinear phenomena using neural networks. Even though it is very flexible, it doesn't cover everything -- in this case, you've defined a discontinuous function, and the universal approximation theorem only extends to continuous functions. I am not aware of a theorem which allows a neural network to approximate arbitrary, discontinuous functions. Perhaps if you treated either case of your target variable as a categorical outcome and used cross-entropy loss you would have success approximating the decision boundary between the two cases.
What is required for neural network to approximate discontinuous function?
Wikipedia provides a synopsis of the universal approximation theorem. In the mathematical theory of artificial neural networks, the universal approximation theorem states that a feed-forward network
What is required for neural network to approximate discontinuous function? Wikipedia provides a synopsis of the universal approximation theorem. In the mathematical theory of artificial neural networks, the universal approximation theorem states that a feed-forward network with a single hidden layer containing a finite number of neurons can approximate continuous functions on compact subsets of $\mathbb{R}^n$, under mild assumptions on the activation function. This theorem is the core justification for attempting to model complex, nonlinear phenomena using neural networks. Even though it is very flexible, it doesn't cover everything -- in this case, you've defined a discontinuous function, and the universal approximation theorem only extends to continuous functions. I am not aware of a theorem which allows a neural network to approximate arbitrary, discontinuous functions. Perhaps if you treated either case of your target variable as a categorical outcome and used cross-entropy loss you would have success approximating the decision boundary between the two cases.
What is required for neural network to approximate discontinuous function? Wikipedia provides a synopsis of the universal approximation theorem. In the mathematical theory of artificial neural networks, the universal approximation theorem states that a feed-forward network
31,807
What is required for neural network to approximate discontinuous function?
Without knowing too much more about your specific implementation, what I can say is that neural networks by and large employ back-propagation/gradient descent in order to tune the network and improve the output's fit to the training data. This means that the loss function is differentiable, in most cases. The function you are trying to approximate has a large jump discontinuity, which would mean that most standard loss functions used in the optimization step of your neural network are going to fail at the discontinuity, and depending on the particular loss function and the details of the optimization algorithm used, will deal with this failure in any of various ways. If you were to apply a sigmoid layer at the end, for instance, you might be able to coax behavior that reasonably approximates the two lines "far enough" away from the discontinuity, but the output would still produce a continuous function connecting the two flat lines. Other approximation techniques will run into similar problems. You might want to check out the Gibbs Phenomenon (https://en.wikipedia.org/wiki/Gibbs_phenomenon) from Fourier analysis and 'ringing artifacts' occurring in signal processing in general.
What is required for neural network to approximate discontinuous function?
Without knowing too much more about your specific implementation, what I can say is that neural networks by and large employ back-propagation/gradient descent in order to tune the network and improve
What is required for neural network to approximate discontinuous function? Without knowing too much more about your specific implementation, what I can say is that neural networks by and large employ back-propagation/gradient descent in order to tune the network and improve the output's fit to the training data. This means that the loss function is differentiable, in most cases. The function you are trying to approximate has a large jump discontinuity, which would mean that most standard loss functions used in the optimization step of your neural network are going to fail at the discontinuity, and depending on the particular loss function and the details of the optimization algorithm used, will deal with this failure in any of various ways. If you were to apply a sigmoid layer at the end, for instance, you might be able to coax behavior that reasonably approximates the two lines "far enough" away from the discontinuity, but the output would still produce a continuous function connecting the two flat lines. Other approximation techniques will run into similar problems. You might want to check out the Gibbs Phenomenon (https://en.wikipedia.org/wiki/Gibbs_phenomenon) from Fourier analysis and 'ringing artifacts' occurring in signal processing in general.
What is required for neural network to approximate discontinuous function? Without knowing too much more about your specific implementation, what I can say is that neural networks by and large employ back-propagation/gradient descent in order to tune the network and improve
31,808
What is required for neural network to approximate discontinuous function?
In general, learning a discontinuous function is hard as the error around the point where the value jumps are usually large. However, in practice, there are ways to get around the problem by making the data less abrupt. For example, in your case, the function jumps when x = 100. We can change it to function: g(x) = 50, x >= 100 g(x) = 25, x < 0 We left the value for the function undefined when 0 <= x < 100. The function g(x) can be also viewed as a displacement of f(x): g(x) = f(x), x >= 100 g(x) = f(x+100), x < 0 Learning g(x) is much easier as there are no abrupt jumps. The neural network is free to choose any value for g(x) when x is between 0 and 100. It is easy to see, one sigmoid function will be enough to describe the sampled data from g(x). After g(x) is learned, it is trivial to convert it back to f(x). This approach works when there are a limited number of know discontinuous points.
What is required for neural network to approximate discontinuous function?
In general, learning a discontinuous function is hard as the error around the point where the value jumps are usually large. However, in practice, there are ways to get around the problem by making th
What is required for neural network to approximate discontinuous function? In general, learning a discontinuous function is hard as the error around the point where the value jumps are usually large. However, in practice, there are ways to get around the problem by making the data less abrupt. For example, in your case, the function jumps when x = 100. We can change it to function: g(x) = 50, x >= 100 g(x) = 25, x < 0 We left the value for the function undefined when 0 <= x < 100. The function g(x) can be also viewed as a displacement of f(x): g(x) = f(x), x >= 100 g(x) = f(x+100), x < 0 Learning g(x) is much easier as there are no abrupt jumps. The neural network is free to choose any value for g(x) when x is between 0 and 100. It is easy to see, one sigmoid function will be enough to describe the sampled data from g(x). After g(x) is learned, it is trivial to convert it back to f(x). This approach works when there are a limited number of know discontinuous points.
What is required for neural network to approximate discontinuous function? In general, learning a discontinuous function is hard as the error around the point where the value jumps are usually large. However, in practice, there are ways to get around the problem by making th
31,809
Sampling z in VAE
Because VAEs are really a graphical model more than they are autoencoders, it can be confusing what exactly "reconstruction" means in context. Recall that we have an lower bound on the log probability given by the RHS of: $$\log p(x) - D_{KL}(Q(z|x)||P(z|x)) = E_{z\sim Q}[\log p(x|z)] - D_{KL}(Q(z|x)||P(z))$$ To compute this lower bound -- a necessary prerequisite for doing a backprop pass to maximize it -- corresponds to passing $x$ through the encoder to arrive at $Q(z|x)$, computing the KL-divergence, then estimating $E_{z \sim Q}[\log p(x|z)]$ by sampling once or more (but usually just once) from $Q$ and running the decoder. This process of estimating the posterior with the encoder and then sampling to approximate the expectation in the RHS so closely mimics the computation of an autoencoder would do that we call it "reconstruction". However, it's really just a side effect of trying to maximize the log probability of the inputs. What happens when you sample multiple times from $Q$? The immediate consequence is that you get a better approximation of the expectation, and hence a better approximation of the lower bound on the log probability. You also need to run the decoder multiple times, which can be expensive, so it is usually not done. Of course if you do this, then you end up with many reconstructions rather than just one. Note that it is definitely not possible to average the reconstructions and have a meaningful output. So you probably just want to sample once. In response to your edit, the correct way to write it would be $$\begin{align*} E_{z \sim Q}[\log p(x|z)] &\approx \frac{1}{n}\sum_{i=1}^N \log p(x|z_i) \\ &\propto -\frac{1}{n}\sum_i ||x-\text{decode}(z_i)||_2^2 \\ &= -\frac{1}{nm} \sum_i \sum_j (x_j - \text{decode}(z_i)_j)^2\end{align*}$$ We would expect that the reconstructions $\text{decode}(z_i)$ look quite similar to each other, but not exactly the same. Exactly how well depends on the nature of the data and how well the model is fitted.
Sampling z in VAE
Because VAEs are really a graphical model more than they are autoencoders, it can be confusing what exactly "reconstruction" means in context. Recall that we have an lower bound on the log probability
Sampling z in VAE Because VAEs are really a graphical model more than they are autoencoders, it can be confusing what exactly "reconstruction" means in context. Recall that we have an lower bound on the log probability given by the RHS of: $$\log p(x) - D_{KL}(Q(z|x)||P(z|x)) = E_{z\sim Q}[\log p(x|z)] - D_{KL}(Q(z|x)||P(z))$$ To compute this lower bound -- a necessary prerequisite for doing a backprop pass to maximize it -- corresponds to passing $x$ through the encoder to arrive at $Q(z|x)$, computing the KL-divergence, then estimating $E_{z \sim Q}[\log p(x|z)]$ by sampling once or more (but usually just once) from $Q$ and running the decoder. This process of estimating the posterior with the encoder and then sampling to approximate the expectation in the RHS so closely mimics the computation of an autoencoder would do that we call it "reconstruction". However, it's really just a side effect of trying to maximize the log probability of the inputs. What happens when you sample multiple times from $Q$? The immediate consequence is that you get a better approximation of the expectation, and hence a better approximation of the lower bound on the log probability. You also need to run the decoder multiple times, which can be expensive, so it is usually not done. Of course if you do this, then you end up with many reconstructions rather than just one. Note that it is definitely not possible to average the reconstructions and have a meaningful output. So you probably just want to sample once. In response to your edit, the correct way to write it would be $$\begin{align*} E_{z \sim Q}[\log p(x|z)] &\approx \frac{1}{n}\sum_{i=1}^N \log p(x|z_i) \\ &\propto -\frac{1}{n}\sum_i ||x-\text{decode}(z_i)||_2^2 \\ &= -\frac{1}{nm} \sum_i \sum_j (x_j - \text{decode}(z_i)_j)^2\end{align*}$$ We would expect that the reconstructions $\text{decode}(z_i)$ look quite similar to each other, but not exactly the same. Exactly how well depends on the nature of the data and how well the model is fitted.
Sampling z in VAE Because VAEs are really a graphical model more than they are autoencoders, it can be confusing what exactly "reconstruction" means in context. Recall that we have an lower bound on the log probability
31,810
Bounds on the difference of correlated random variables
Even without those simplifying assumptions, a bound can be obtained by combining a couple of usual tools: The variance of the difference of two correlated variables. It allows us to turn a two variables problem into an univariate problem. Chebyshev's inequality. It puts a bound on the probability of exceeding a given value. In some detail: $$\sigma^2_{X-Y}=\sigma^2_X+\sigma^2_Y-2·cov(X,Y)$$ $$cov(X,Y)=\sigma_X·\sigma_Y·\rho_{XY}$$ $$\sigma^2_{X-Y}=\sigma^2_X+\sigma^2_Y-2·\sigma_X·\sigma_Y·\rho_{X,Y}$$ According to Chebyshev's inequality, for any random variable $Z$: $$ \Pr(|Z-\mu|\geq k\sigma) \leq \frac{1}{k^2}$$ Then (and using that $\mu_{X-Y}=\mu_X-\mu_Y)$: $$ \Pr(|X-Y-\mu_X+\mu_Y|\geq k·\sqrt{\sigma^2_X+\sigma^2_Y-2·\sigma_X·\sigma_Y·\rho_{X,Y}}) \leq \frac{1}{k^2}$$ We can use the proposed simplifying assumptions to get a simpler expression. When: $$\rho_{X,Y}= {covar(X,Y)} / {\sigma_X \sigma_Y} = 1 - \epsilon $$ $$\mu_x = \mu_y = 0$$ $$\sigma_X^2 = \sigma_Y^2 = \sigma^2$$ Then: $$\sigma^2_X+\sigma^2_Y-2·\sigma_X·\sigma_Y·\rho_{X,Y} = 2·\sigma^2·(1-(1-\epsilon)) = 2\sigma^2\epsilon$$ And therefore: $$\Pr(|X-Y|\geq k·\sigma\sqrt{2\epsilon}) \leq \frac{1}{k^2}$$ Interestingly, this result holds even if $\epsilon$ is not small, and if the condition for correlation changes from $=1-\epsilon$ to $\geq 1-\epsilon$, the result doesn't change (because it's already an inequality).
Bounds on the difference of correlated random variables
Even without those simplifying assumptions, a bound can be obtained by combining a couple of usual tools: The variance of the difference of two correlated variables. It allows us to turn a two variab
Bounds on the difference of correlated random variables Even without those simplifying assumptions, a bound can be obtained by combining a couple of usual tools: The variance of the difference of two correlated variables. It allows us to turn a two variables problem into an univariate problem. Chebyshev's inequality. It puts a bound on the probability of exceeding a given value. In some detail: $$\sigma^2_{X-Y}=\sigma^2_X+\sigma^2_Y-2·cov(X,Y)$$ $$cov(X,Y)=\sigma_X·\sigma_Y·\rho_{XY}$$ $$\sigma^2_{X-Y}=\sigma^2_X+\sigma^2_Y-2·\sigma_X·\sigma_Y·\rho_{X,Y}$$ According to Chebyshev's inequality, for any random variable $Z$: $$ \Pr(|Z-\mu|\geq k\sigma) \leq \frac{1}{k^2}$$ Then (and using that $\mu_{X-Y}=\mu_X-\mu_Y)$: $$ \Pr(|X-Y-\mu_X+\mu_Y|\geq k·\sqrt{\sigma^2_X+\sigma^2_Y-2·\sigma_X·\sigma_Y·\rho_{X,Y}}) \leq \frac{1}{k^2}$$ We can use the proposed simplifying assumptions to get a simpler expression. When: $$\rho_{X,Y}= {covar(X,Y)} / {\sigma_X \sigma_Y} = 1 - \epsilon $$ $$\mu_x = \mu_y = 0$$ $$\sigma_X^2 = \sigma_Y^2 = \sigma^2$$ Then: $$\sigma^2_X+\sigma^2_Y-2·\sigma_X·\sigma_Y·\rho_{X,Y} = 2·\sigma^2·(1-(1-\epsilon)) = 2\sigma^2\epsilon$$ And therefore: $$\Pr(|X-Y|\geq k·\sigma\sqrt{2\epsilon}) \leq \frac{1}{k^2}$$ Interestingly, this result holds even if $\epsilon$ is not small, and if the condition for correlation changes from $=1-\epsilon$ to $\geq 1-\epsilon$, the result doesn't change (because it's already an inequality).
Bounds on the difference of correlated random variables Even without those simplifying assumptions, a bound can be obtained by combining a couple of usual tools: The variance of the difference of two correlated variables. It allows us to turn a two variab
31,811
Must a time series be stationary if it has no unit root?
No, roots outside the unit circle gives asymptotic stationarity, not strict stationarity: For a standard ARMA time-series model, the recursive formula for a model locks in the autocorrelation of the process, but does not lock in the marginal/joint distribution for the process. To get the latter you also need to specify the marginal distribution at some point in time, and this specification then locks in the full joint distribution of the process. (Strictly, for an ARMA model, you need to specify the joint distribution of $p$ elements, where $p$ is the degree of the autoregressive characteristic polynomial.) If all of the roots of an AR process are outside the unit circle (no unit roots and no explosive roots), and the error terms are IID, then the process will have mean-reverting behaviour and will converge asymptotically to a stationary distribution. This asymptotic convergence to a stationary distribution is a weaker property than strict stationarity. It is possible for such a process to be non-stationary by specifying an "anchoring distribution" that is not the asymptotic stationary distribution. Stationarity for an AR(1) process: Consider a standard first-order auto-regressive process defined by the recursive equation: $$\begin{matrix} X_{t+1} = \mu + \alpha (X_t - \mu) + \varepsilon_t & & \varepsilon_t \sim \text{ IID N}(0, \sigma^2). \end{matrix}$$ Suppose that $| \alpha | <1$ so that this has a single root $1/\alpha$ outside the unit circle. This model form defines a broad set of possible time-series processes --- i.e., all processes that obey the requisite recursive equation and have the specified noise distribution. However, with this recursive equation you have not yet specified an "anchoring distribution" for any particular point in the series, and so this presently encompasses some stationary and some non-stationary processes. Now, it can be shown that if $\sigma>0$ then (regardless of the anchoring distribution) this process has the asymptotic stationary distribution: $$X_{\infty} \sim \text{N} \Big( \mu, \frac{\sigma^2}{1 - \alpha^2} \Big).$$ In order to form a strictly stationary process you would need to impose the requirement that the marginal distribution at some arbitrary time is equal to this anchoring distribution. Alternatively, if you want to specify a non-stationary process, you could impose a different marginal distribution at a particular time (perhaps with a different mean or variance, or maybe even a different distributional form). Non-stationary AR(1) model (with root still inside the unit circle): Suppose you specify an "anchoring distribution" for the element $X_0$ that is still a normal distribution, but with some arbitrary mean and variance: $$X_0 \sim \text{N} ( \mu_0, \sigma_0^2 ).$$ With this "anchoring distribution" it can be shown that the series of marginal distributions is: $$X_t \sim \text{N} \Big( (1- \alpha^t) \mu + \alpha^t \mu_0, \alpha^{2t} \sigma_0^2 +\frac{1-\alpha^{2t}}{1-\alpha^2} \sigma^2 \Big).$$ For $\mu_0 \neq \mu$ this series has non-stationary mean, though it converges to the asymptotic mean $\mu$. For $\sigma_0 \neq \sigma$ this series has non-stationary variance, though it converges to the asymptotic variance $\sigma^2 / (1-\alpha^2)$. In this case the process is non-stationary, but it gets closer and closer to being stationary the further you get from the prescribed "anchoring point" of the process.
Must a time series be stationary if it has no unit root?
No, roots outside the unit circle gives asymptotic stationarity, not strict stationarity: For a standard ARMA time-series model, the recursive formula for a model locks in the autocorrelation of the p
Must a time series be stationary if it has no unit root? No, roots outside the unit circle gives asymptotic stationarity, not strict stationarity: For a standard ARMA time-series model, the recursive formula for a model locks in the autocorrelation of the process, but does not lock in the marginal/joint distribution for the process. To get the latter you also need to specify the marginal distribution at some point in time, and this specification then locks in the full joint distribution of the process. (Strictly, for an ARMA model, you need to specify the joint distribution of $p$ elements, where $p$ is the degree of the autoregressive characteristic polynomial.) If all of the roots of an AR process are outside the unit circle (no unit roots and no explosive roots), and the error terms are IID, then the process will have mean-reverting behaviour and will converge asymptotically to a stationary distribution. This asymptotic convergence to a stationary distribution is a weaker property than strict stationarity. It is possible for such a process to be non-stationary by specifying an "anchoring distribution" that is not the asymptotic stationary distribution. Stationarity for an AR(1) process: Consider a standard first-order auto-regressive process defined by the recursive equation: $$\begin{matrix} X_{t+1} = \mu + \alpha (X_t - \mu) + \varepsilon_t & & \varepsilon_t \sim \text{ IID N}(0, \sigma^2). \end{matrix}$$ Suppose that $| \alpha | <1$ so that this has a single root $1/\alpha$ outside the unit circle. This model form defines a broad set of possible time-series processes --- i.e., all processes that obey the requisite recursive equation and have the specified noise distribution. However, with this recursive equation you have not yet specified an "anchoring distribution" for any particular point in the series, and so this presently encompasses some stationary and some non-stationary processes. Now, it can be shown that if $\sigma>0$ then (regardless of the anchoring distribution) this process has the asymptotic stationary distribution: $$X_{\infty} \sim \text{N} \Big( \mu, \frac{\sigma^2}{1 - \alpha^2} \Big).$$ In order to form a strictly stationary process you would need to impose the requirement that the marginal distribution at some arbitrary time is equal to this anchoring distribution. Alternatively, if you want to specify a non-stationary process, you could impose a different marginal distribution at a particular time (perhaps with a different mean or variance, or maybe even a different distributional form). Non-stationary AR(1) model (with root still inside the unit circle): Suppose you specify an "anchoring distribution" for the element $X_0$ that is still a normal distribution, but with some arbitrary mean and variance: $$X_0 \sim \text{N} ( \mu_0, \sigma_0^2 ).$$ With this "anchoring distribution" it can be shown that the series of marginal distributions is: $$X_t \sim \text{N} \Big( (1- \alpha^t) \mu + \alpha^t \mu_0, \alpha^{2t} \sigma_0^2 +\frac{1-\alpha^{2t}}{1-\alpha^2} \sigma^2 \Big).$$ For $\mu_0 \neq \mu$ this series has non-stationary mean, though it converges to the asymptotic mean $\mu$. For $\sigma_0 \neq \sigma$ this series has non-stationary variance, though it converges to the asymptotic variance $\sigma^2 / (1-\alpha^2)$. In this case the process is non-stationary, but it gets closer and closer to being stationary the further you get from the prescribed "anchoring point" of the process.
Must a time series be stationary if it has no unit root? No, roots outside the unit circle gives asymptotic stationarity, not strict stationarity: For a standard ARMA time-series model, the recursive formula for a model locks in the autocorrelation of the p
31,812
Must a time series be stationary if it has no unit root?
A process could be nonstationary in the sense of its distribution not being constant over time even without invoking any kind of autoregressive structure when, e.g., its variance changes over time (in a permanent fashion, so not like in a GARCH situation). E.g., a permanent break in the variance at point in time $c$ would imply nonstationarity: $$ X_t\sim\begin{cases}N(0,\sigma_1^2)&\quad t=-\infty,\ldots,c\\N(0,\sigma_2^2)&\quad t=c+1,\ldots,\infty\\\end{cases} $$
Must a time series be stationary if it has no unit root?
A process could be nonstationary in the sense of its distribution not being constant over time even without invoking any kind of autoregressive structure when, e.g., its variance changes over time (in
Must a time series be stationary if it has no unit root? A process could be nonstationary in the sense of its distribution not being constant over time even without invoking any kind of autoregressive structure when, e.g., its variance changes over time (in a permanent fashion, so not like in a GARCH situation). E.g., a permanent break in the variance at point in time $c$ would imply nonstationarity: $$ X_t\sim\begin{cases}N(0,\sigma_1^2)&\quad t=-\infty,\ldots,c\\N(0,\sigma_2^2)&\quad t=c+1,\ldots,\infty\\\end{cases} $$
Must a time series be stationary if it has no unit root? A process could be nonstationary in the sense of its distribution not being constant over time even without invoking any kind of autoregressive structure when, e.g., its variance changes over time (in
31,813
In PCA, why do we assume that the covariance matrix is always diagonalizable?
Covariance matrix is a symmetric matrix, hence it is always diagonalizable. In fact, in the diagonalization, $C=PDP^{-1}$, we know that we can choose $P$ to be an orthogonal matrix. It belongs to a larger class of matrix known as Hermitian matrix that guarantees that they can be diagonalized.
In PCA, why do we assume that the covariance matrix is always diagonalizable?
Covariance matrix is a symmetric matrix, hence it is always diagonalizable. In fact, in the diagonalization, $C=PDP^{-1}$, we know that we can choose $P$ to be an orthogonal matrix. It belongs to a l
In PCA, why do we assume that the covariance matrix is always diagonalizable? Covariance matrix is a symmetric matrix, hence it is always diagonalizable. In fact, in the diagonalization, $C=PDP^{-1}$, we know that we can choose $P$ to be an orthogonal matrix. It belongs to a larger class of matrix known as Hermitian matrix that guarantees that they can be diagonalized.
In PCA, why do we assume that the covariance matrix is always diagonalizable? Covariance matrix is a symmetric matrix, hence it is always diagonalizable. In fact, in the diagonalization, $C=PDP^{-1}$, we know that we can choose $P$ to be an orthogonal matrix. It belongs to a l
31,814
Approximate the sine function with shallow neural network
So I solved my own problem, and the solution was to use a more advanced optimizer instead of vanilla gradient descent. By using the "nn" module from pytorch, you can select from a range of optimizers which incorporate concepts like "momentum", regularization, and learning rate decay to update the weights of the network in a way that is more likely to find a local minimum. UPDATE: I have created an interactive tutorial on this problem for those interested. It is a Jupyter notebook containing the minimum code to get this problem running, and leaves room for the user to improve the fit of the model through experimentation with layers, optimizers, etc.: link This page has some explanation. More in their cs231n (free) online lectures. Another explanation with nice animations. Training with Adam optimizer, 1000 iterations, loss=L1Loss (Y=loss, X=iter): Resulting model (orange=prediction, blue=training data): zoomed:
Approximate the sine function with shallow neural network
So I solved my own problem, and the solution was to use a more advanced optimizer instead of vanilla gradient descent. By using the "nn" module from pytorch, you can select from a range of optimizers
Approximate the sine function with shallow neural network So I solved my own problem, and the solution was to use a more advanced optimizer instead of vanilla gradient descent. By using the "nn" module from pytorch, you can select from a range of optimizers which incorporate concepts like "momentum", regularization, and learning rate decay to update the weights of the network in a way that is more likely to find a local minimum. UPDATE: I have created an interactive tutorial on this problem for those interested. It is a Jupyter notebook containing the minimum code to get this problem running, and leaves room for the user to improve the fit of the model through experimentation with layers, optimizers, etc.: link This page has some explanation. More in their cs231n (free) online lectures. Another explanation with nice animations. Training with Adam optimizer, 1000 iterations, loss=L1Loss (Y=loss, X=iter): Resulting model (orange=prediction, blue=training data): zoomed:
Approximate the sine function with shallow neural network So I solved my own problem, and the solution was to use a more advanced optimizer instead of vanilla gradient descent. By using the "nn" module from pytorch, you can select from a range of optimizers
31,815
Is a policy always deterministic in reinforcement learning?
There are multiple questions here: 1. Is a policy always deterministic? 2. If the policy is deterministic then shouldn't the value also be deterministic? 3. What is the expectation over in the value function estimate? Your last question is not very clear "Can a policy lead to routes that have different current values?" but I think you mean: 4. Can a policy lead to different routes? A policy is a function can be either deterministic or stochastic. It dictates what action to take given a particular state. The distribution $\pi(a\mid s)$ is used for a stochastic policy and a mapping function $\pi:S \rightarrow A$ is used for a deterministic policy, where $S$ is the set of possible states and $A$ is the set of possible actions. The value function is not deterministic. The value (of a state) is the expected reward if you start at that state and continue to follow a policy. Even if the policy is deterministic the reward function and the environment might not be. The expectation in that formula is over all the possible routes starting from state $s$. Usually, the routes or paths are decomposed into multiple steps, which are used to train value estimators. These steps can be represented by the tuple $(s,a,r,s')$ (state, action, reward, next state) This is related to answer 2, the policy can lead to different paths (even a deterministic policy) because the environment is usually not deterministic.
Is a policy always deterministic in reinforcement learning?
There are multiple questions here: 1. Is a policy always deterministic? 2. If the policy is deterministic then shouldn't the value also be deterministic? 3. What is the expectation over in the value
Is a policy always deterministic in reinforcement learning? There are multiple questions here: 1. Is a policy always deterministic? 2. If the policy is deterministic then shouldn't the value also be deterministic? 3. What is the expectation over in the value function estimate? Your last question is not very clear "Can a policy lead to routes that have different current values?" but I think you mean: 4. Can a policy lead to different routes? A policy is a function can be either deterministic or stochastic. It dictates what action to take given a particular state. The distribution $\pi(a\mid s)$ is used for a stochastic policy and a mapping function $\pi:S \rightarrow A$ is used for a deterministic policy, where $S$ is the set of possible states and $A$ is the set of possible actions. The value function is not deterministic. The value (of a state) is the expected reward if you start at that state and continue to follow a policy. Even if the policy is deterministic the reward function and the environment might not be. The expectation in that formula is over all the possible routes starting from state $s$. Usually, the routes or paths are decomposed into multiple steps, which are used to train value estimators. These steps can be represented by the tuple $(s,a,r,s')$ (state, action, reward, next state) This is related to answer 2, the policy can lead to different paths (even a deterministic policy) because the environment is usually not deterministic.
Is a policy always deterministic in reinforcement learning? There are multiple questions here: 1. Is a policy always deterministic? 2. If the policy is deterministic then shouldn't the value also be deterministic? 3. What is the expectation over in the value
31,816
Is a policy always deterministic in reinforcement learning?
The policy can be stochastic or deterministic. The expectation is over training examples given the conditions. The value function is an estimate of the return, which is why it's an expectation.
Is a policy always deterministic in reinforcement learning?
The policy can be stochastic or deterministic. The expectation is over training examples given the conditions. The value function is an estimate of the return, which is why it's an expectation.
Is a policy always deterministic in reinforcement learning? The policy can be stochastic or deterministic. The expectation is over training examples given the conditions. The value function is an estimate of the return, which is why it's an expectation.
Is a policy always deterministic in reinforcement learning? The policy can be stochastic or deterministic. The expectation is over training examples given the conditions. The value function is an estimate of the return, which is why it's an expectation.
31,817
Can reinforcement learning be "stateless"?
Reinforcement learning is formulated as a problem with states, actions, and rewards, with transitions between states affected by the current state, chosen action and the environment. That is part of its definition (formulated as a Markov Decision Process), so generally you won't find stateless variants of it that are still called reinforcement learning. However, there are related stateless problems. There are multi-armed bandits, which just have actions and rewards. Solutions for these allow for learning of reward based on actions, and can be optimised by selecting the best action (being sure you have the best one, and what total reward you can accumulate whilst still testing for which is the best action are the main optimisation problems). Your button pushing example looks a lot like a multi-armed bandit problem. Another common example might be advert selection online for anonymous visitors to a site - although there is often plenty of data available, there's also a huge amount that is hidden, and a practical approach is to treat the probability of a click through as only depending on the choice of content, which is then the site's action. There is a "stateful" variant of multi-armed bandits called contextual bandits - when there is some kind of signal that can be associated with the correct action, but actions taken have no effect on what the next state will be. Contextual bandits have states, actions and rewards, but no transition rules, they can be treated as a set of entirely separate events. A contextual bandit with added transition rules between states, but no influence from the selected action, is essentially a sub-class of the reinforcement learning problem, and you can use most of the same analysis to predict long term reward and learn optimal behaviour. And just for completeness, there are Markov Reward Processes without agent interaction that have states, and rewards, but no actions. It is possible to use reinforcement learning algorithms on these to predict long term reward and/or the expected long term value of being in a specific state. The rock-paper-scissors game does not fit neatly into any of the above problems because there are two agents (although you could analyse it as a multi-armed bandit if the opponent's policy was fixed to always play with specific unchanging probabilities, or as a contextual bandit if there multiple such opponents or a really easy "tell" to their style of play that never changed). Typically a game of rock-paper-scissors would be analysed using game theory - it has an interesting feature that the Nash equilibrium is achieved by using a stochastic policy with equal $\frac{1}{3}$ probability of each choice. If you wrote a rock-paper-scissors agent to play against a human opponent, you might actually formulate it as a reinforcement learning problem, taking the last N plays as the state, because that could learn to take advantage of human players' poor judgement of randomness.
Can reinforcement learning be "stateless"?
Reinforcement learning is formulated as a problem with states, actions, and rewards, with transitions between states affected by the current state, chosen action and the environment. That is part of i
Can reinforcement learning be "stateless"? Reinforcement learning is formulated as a problem with states, actions, and rewards, with transitions between states affected by the current state, chosen action and the environment. That is part of its definition (formulated as a Markov Decision Process), so generally you won't find stateless variants of it that are still called reinforcement learning. However, there are related stateless problems. There are multi-armed bandits, which just have actions and rewards. Solutions for these allow for learning of reward based on actions, and can be optimised by selecting the best action (being sure you have the best one, and what total reward you can accumulate whilst still testing for which is the best action are the main optimisation problems). Your button pushing example looks a lot like a multi-armed bandit problem. Another common example might be advert selection online for anonymous visitors to a site - although there is often plenty of data available, there's also a huge amount that is hidden, and a practical approach is to treat the probability of a click through as only depending on the choice of content, which is then the site's action. There is a "stateful" variant of multi-armed bandits called contextual bandits - when there is some kind of signal that can be associated with the correct action, but actions taken have no effect on what the next state will be. Contextual bandits have states, actions and rewards, but no transition rules, they can be treated as a set of entirely separate events. A contextual bandit with added transition rules between states, but no influence from the selected action, is essentially a sub-class of the reinforcement learning problem, and you can use most of the same analysis to predict long term reward and learn optimal behaviour. And just for completeness, there are Markov Reward Processes without agent interaction that have states, and rewards, but no actions. It is possible to use reinforcement learning algorithms on these to predict long term reward and/or the expected long term value of being in a specific state. The rock-paper-scissors game does not fit neatly into any of the above problems because there are two agents (although you could analyse it as a multi-armed bandit if the opponent's policy was fixed to always play with specific unchanging probabilities, or as a contextual bandit if there multiple such opponents or a really easy "tell" to their style of play that never changed). Typically a game of rock-paper-scissors would be analysed using game theory - it has an interesting feature that the Nash equilibrium is achieved by using a stochastic policy with equal $\frac{1}{3}$ probability of each choice. If you wrote a rock-paper-scissors agent to play against a human opponent, you might actually formulate it as a reinforcement learning problem, taking the last N plays as the state, because that could learn to take advantage of human players' poor judgement of randomness.
Can reinforcement learning be "stateless"? Reinforcement learning is formulated as a problem with states, actions, and rewards, with transitions between states affected by the current state, chosen action and the environment. That is part of i
31,818
Let $X_{(1)}\leq X_{(2)}$ be the order statistics. Evaluate $\operatorname{Var}(X_{(j)})$, $\operatorname{Cov}(X_{(1)},X_{(2)})$
When two variables $(X_1,X_2)$ are identically distributed with a continuous distribution having density $f$, the joint PDF of their order statistics $(X_{(1)}, X_{(2)})$ is $$2 f(x_1) f(x_2) \mathcal{I}(x_2 \gt x_1).\tag{1}$$ We know how moments depend on location parameters $\mu$ and scale parameters $\sigma$, so it suffices to solve the problem for $\mu=0$ and $\sigma=1$. These figures illustrate the following analysis. At left is a contour plot of the joint density of $(X_1,X_2)$. In the middle is a contour plot of the joint density of the order statistics $(1)$ (it is identical in appearance to the left plot but restricted to the region $x_{(2)}\ge x_{(1)}$; all contour values have been doubled, too), along with vectors depicting the new variables $(U,V)$. At the right is the joint density in $(u,v)$ coordinates, along with vectors depicting the order statistics $(X_{(1)}, X_{(2)})$. Computing the moments in $(u,v)$ coordinates is easy. Simple formulas connect these moments to the moments of the original order statistics. Suppose $f$ is symmetric (as are all Normal distributions). Since $X_1 + X_2 = X_{(1)} + X_{(2)}$ and $(-X_{(2)}, -X_{(1)})$ has the same distribution, $$-\mathbb{E}(X_{(1)}) = \mathbb{E}(X_{(2)}) = \nu,$$ say, and obviously $$\operatorname{Var}(X_{(1)})= \operatorname{Var}(X_{(2)}) = \tau^2,$$ say. At this point let's exploit some special properties of Normal distributions. Upon rotating $(X_{(1)}, X_{(2)})$ clockwise by $\pi/4$ to $U=(X_{(1)}+X_{(2)})/\sqrt{2}$ and $V=(X_{(2)}-X_{(1)})/\sqrt{2}$, this becomes the density of a bivariate standard Normal variable $(U,V)$ that has been truncated to the domain $V \gt 0$. It is immediate that $U$ has a standard Normal distribution and $V$ has a half-Normal distribution. Consequently $$\mathbb{E}(U)=0, \ \mathbb{E}(V) = \sqrt{\frac{1}{\pi}},\ \operatorname{Var}(U)=1,\ \text{and}\ \operatorname{Var}(V) = 1 - \mathbb{E}(V)^2 = 1 - \frac{1}{\pi}.$$ Relating these to the original variables gives $$\cases{ 1 = \operatorname{Var}(U) = \operatorname{Var}\left(\frac{1}{\sqrt{2}}\left(X_1+X_2\right)\right) = \frac{1}{2}\left(\tau^2 + \tau^2+2\operatorname{Cov}(X_1,X_2)\right) \\ 1 - \frac{1}{\pi} = \operatorname{Var}(U) = \cdots = \frac{1}{2}\left(\tau^2 + \tau^2-2\operatorname{Cov}(X_{(1)},X_{(2)})\right). }$$ The solution to these simultaneous linear equations is $$\tau^2 = 1 - \frac{1}{\pi},\ \operatorname{Cov}(X_{(1)},X_{(2)}) = \frac{1}{2\pi}.$$ In the same manner, expressing the expectations of $U$ and $V$ in terms of those of $X_{(1)}$ and $X_{(2)}$ gives equations for $\nu$ whose solution is $\nu = \sqrt{1/\pi}$. Returning to the original question, where the variables are scaled by $\sigma$ and shifted by $\mu$, the answers must therefore be $$\mathbb{E}(X_{(i)}) = \mu + (-1)^i \sigma \sqrt{\frac{1}{\pi}}$$ and $$\operatorname{Var}\left(X_{(1)}, X_{(2)}\right) = \sigma^2\pmatrix{1-\frac{1}{\pi} & \frac{1}{\pi} \\ \frac{1}{\pi} & 1 - \frac{1}{\pi}}.$$
Let $X_{(1)}\leq X_{(2)}$ be the order statistics. Evaluate $\operatorname{Var}(X_{(j)})$, $\operato
When two variables $(X_1,X_2)$ are identically distributed with a continuous distribution having density $f$, the joint PDF of their order statistics $(X_{(1)}, X_{(2)})$ is $$2 f(x_1) f(x_2) \mathcal
Let $X_{(1)}\leq X_{(2)}$ be the order statistics. Evaluate $\operatorname{Var}(X_{(j)})$, $\operatorname{Cov}(X_{(1)},X_{(2)})$ When two variables $(X_1,X_2)$ are identically distributed with a continuous distribution having density $f$, the joint PDF of their order statistics $(X_{(1)}, X_{(2)})$ is $$2 f(x_1) f(x_2) \mathcal{I}(x_2 \gt x_1).\tag{1}$$ We know how moments depend on location parameters $\mu$ and scale parameters $\sigma$, so it suffices to solve the problem for $\mu=0$ and $\sigma=1$. These figures illustrate the following analysis. At left is a contour plot of the joint density of $(X_1,X_2)$. In the middle is a contour plot of the joint density of the order statistics $(1)$ (it is identical in appearance to the left plot but restricted to the region $x_{(2)}\ge x_{(1)}$; all contour values have been doubled, too), along with vectors depicting the new variables $(U,V)$. At the right is the joint density in $(u,v)$ coordinates, along with vectors depicting the order statistics $(X_{(1)}, X_{(2)})$. Computing the moments in $(u,v)$ coordinates is easy. Simple formulas connect these moments to the moments of the original order statistics. Suppose $f$ is symmetric (as are all Normal distributions). Since $X_1 + X_2 = X_{(1)} + X_{(2)}$ and $(-X_{(2)}, -X_{(1)})$ has the same distribution, $$-\mathbb{E}(X_{(1)}) = \mathbb{E}(X_{(2)}) = \nu,$$ say, and obviously $$\operatorname{Var}(X_{(1)})= \operatorname{Var}(X_{(2)}) = \tau^2,$$ say. At this point let's exploit some special properties of Normal distributions. Upon rotating $(X_{(1)}, X_{(2)})$ clockwise by $\pi/4$ to $U=(X_{(1)}+X_{(2)})/\sqrt{2}$ and $V=(X_{(2)}-X_{(1)})/\sqrt{2}$, this becomes the density of a bivariate standard Normal variable $(U,V)$ that has been truncated to the domain $V \gt 0$. It is immediate that $U$ has a standard Normal distribution and $V$ has a half-Normal distribution. Consequently $$\mathbb{E}(U)=0, \ \mathbb{E}(V) = \sqrt{\frac{1}{\pi}},\ \operatorname{Var}(U)=1,\ \text{and}\ \operatorname{Var}(V) = 1 - \mathbb{E}(V)^2 = 1 - \frac{1}{\pi}.$$ Relating these to the original variables gives $$\cases{ 1 = \operatorname{Var}(U) = \operatorname{Var}\left(\frac{1}{\sqrt{2}}\left(X_1+X_2\right)\right) = \frac{1}{2}\left(\tau^2 + \tau^2+2\operatorname{Cov}(X_1,X_2)\right) \\ 1 - \frac{1}{\pi} = \operatorname{Var}(U) = \cdots = \frac{1}{2}\left(\tau^2 + \tau^2-2\operatorname{Cov}(X_{(1)},X_{(2)})\right). }$$ The solution to these simultaneous linear equations is $$\tau^2 = 1 - \frac{1}{\pi},\ \operatorname{Cov}(X_{(1)},X_{(2)}) = \frac{1}{2\pi}.$$ In the same manner, expressing the expectations of $U$ and $V$ in terms of those of $X_{(1)}$ and $X_{(2)}$ gives equations for $\nu$ whose solution is $\nu = \sqrt{1/\pi}$. Returning to the original question, where the variables are scaled by $\sigma$ and shifted by $\mu$, the answers must therefore be $$\mathbb{E}(X_{(i)}) = \mu + (-1)^i \sigma \sqrt{\frac{1}{\pi}}$$ and $$\operatorname{Var}\left(X_{(1)}, X_{(2)}\right) = \sigma^2\pmatrix{1-\frac{1}{\pi} & \frac{1}{\pi} \\ \frac{1}{\pi} & 1 - \frac{1}{\pi}}.$$
Let $X_{(1)}\leq X_{(2)}$ be the order statistics. Evaluate $\operatorname{Var}(X_{(j)})$, $\operato When two variables $(X_1,X_2)$ are identically distributed with a continuous distribution having density $f$, the joint PDF of their order statistics $(X_{(1)}, X_{(2)})$ is $$2 f(x_1) f(x_2) \mathcal
31,819
Let $X_{(1)}\leq X_{(2)}$ be the order statistics. Evaluate $\operatorname{Var}(X_{(j)})$, $\operatorname{Cov}(X_{(1)},X_{(2)})$
Here is a brute-force answer that lacks the elegance of whuber's calculations but arrives at the same conclusions. With $X_i, i = 1, 2,$ denoting independent standard random variables and $$(W,Z) = \left(\min(X_1,X_2),\max(X_1,X_2)\right) = \left (X_{(1)},X_{(2)}\right),$$ we have that $f_{X_1,X_2}(x,y)= \phi(x)\phi(y)$ and $f_{W,Z}(w,z)= \displaystyle \begin{cases}\displaystyle 2\phi(x)\phi(y), & z>w,\\ \ \\ 0, & z<w, \end{cases}$ where $\phi(\cdot)$ denotes the standard normal density function. Now, \begin{align} E[W] &= \int_{-\infty}^\infty \int_{-\infty}^\infty w\cdot f_{W,Z}(w,z)\, \mathrm dz\, \mathrm dw\\ &= \int_0^\infty \int_{\pi/4}^{5\pi/4} r\cos(\theta)\cdot \frac{1}{\pi} \exp\left(\frac{-r^2}{2}\right)\, r\,\mathrm d\theta \, \mathrm dr &\scriptstyle{\text{change to polar coordinates}}\\ &= \left. \int_0^\infty \sin(\theta)\right|_{\pi/4}^{5\pi/4} \cdot \frac{1}{\pi} r^2 \exp\left(\frac{-r^2}{2}\right) \, \mathrm dr\\ &= -\frac{\sqrt 2}{\pi}\int_0^\infty r^2 \exp\left(\frac{-r^2}{2}\right) \, \mathrm dr &\scriptstyle{\text{now re-write the constant}}\\ &= -\frac{1}{\sqrt \pi}\int_{-\infty}^\infty r^2 \frac{1}{\sqrt{2\pi}}\exp\left(\frac{-r^2}{2}\right) \, \mathrm dr &\scriptstyle{\text{and recognize the integral}}\\ &= -\frac{1}{\sqrt \pi}, \end{align} and since $W+Z = X_{(1)}+X_{(2)} = X_1+X_2$, we deduce that $$E[Z] = E[X_{1}+X_{2}]-E[W] = 0 - \left(-\frac{1}{\sqrt \pi}\right) = \frac{1}{\sqrt \pi}.$$ Similarly, \begin{align} E[W^2] &= \int_{-\infty}^\infty \int_{-\infty}^\infty w^2\cdot f_{W,Z}(w,z)\, \mathrm dz\, \mathrm dw\\ &= \int_0^\infty \int_{\pi/4}^{5\pi/4} r^2\cos^2(\theta)\cdot \frac{1}{\pi} \exp\left(\frac{-r^2}{2}\right)\, r\,\mathrm d\theta \, \mathrm dr &\scriptstyle{\text{change to polar coordinates}}\\ &= \left. \int_0^\infty \frac{2\theta+\sin(2\theta)}{4}\right|_{\pi/4}^{5\pi/4} \cdot \frac{1}{\pi} r^3 \exp\left(\frac{-r^2}{2}\right) \, \mathrm dr\\ &= \frac{1}{2}\int_0^\infty r^3 \exp\left(\frac{-r^2}{2}\right) \, \mathrm dr &\scriptstyle{\text{now set }r^2/2 = t}\\ &= \int_0^\infty t \exp\left(-t\right) \, \mathrm dt \\ &= 1, \end{align} and since $W^2+Z^2 = X_{(1)}^2+X_{(2)}^2 = X_1^2+X_2^2$, we have that $$E[W^2+Z^2]= 1+E[Z^2]=E[X_1^2+X_2^2]=2 \implies E[Z^2] = E[W^2]=1.$$ It follows that $\operatorname{var}(W) = \operatorname{var}(Z) = 1-\frac{1}{\pi}.$ Finally, \begin{align} \operatorname{cov}(X_{(1)},X_{(2)})&= \operatorname{cov}(W,Z)\\ &= E[WZ] - E[W]E[Z]\\ &= E[X_1X_2] + \frac{1}{\pi}\\ &= E[X_1]E[X_2] + \frac{1}{\pi}&\scriptstyle{\text{because }X_1~\text{and }X_2~\text{are independent}}\\ &= \frac{1}{\pi} \end{align} If $X_1$ and $X_2$ are scaled by $\sigma$ and translated by $\mu$ to iid $N(\mu,\sigma^2)$, then we ready get that $$E[X_{(1)}] = \mu - \frac{\sigma}{\sqrt{\pi}}, \quad E[X_{(2)}] = \mu + \frac{\sigma}{\sqrt{\pi}}\\ \operatorname{var}(X_{(1)}) = \operatorname{var}(X_{(2)}) = \sigma^2\left(1-\frac{1}{\pi}\right)\\ \operatorname{cov}(X_{(1)},X_{(2)}) = \frac{\sigma^2}{\pi}.$$
Let $X_{(1)}\leq X_{(2)}$ be the order statistics. Evaluate $\operatorname{Var}(X_{(j)})$, $\operato
Here is a brute-force answer that lacks the elegance of whuber's calculations but arrives at the same conclusions. With $X_i, i = 1, 2,$ denoting independent standard random variables and $$(W,Z) = \
Let $X_{(1)}\leq X_{(2)}$ be the order statistics. Evaluate $\operatorname{Var}(X_{(j)})$, $\operatorname{Cov}(X_{(1)},X_{(2)})$ Here is a brute-force answer that lacks the elegance of whuber's calculations but arrives at the same conclusions. With $X_i, i = 1, 2,$ denoting independent standard random variables and $$(W,Z) = \left(\min(X_1,X_2),\max(X_1,X_2)\right) = \left (X_{(1)},X_{(2)}\right),$$ we have that $f_{X_1,X_2}(x,y)= \phi(x)\phi(y)$ and $f_{W,Z}(w,z)= \displaystyle \begin{cases}\displaystyle 2\phi(x)\phi(y), & z>w,\\ \ \\ 0, & z<w, \end{cases}$ where $\phi(\cdot)$ denotes the standard normal density function. Now, \begin{align} E[W] &= \int_{-\infty}^\infty \int_{-\infty}^\infty w\cdot f_{W,Z}(w,z)\, \mathrm dz\, \mathrm dw\\ &= \int_0^\infty \int_{\pi/4}^{5\pi/4} r\cos(\theta)\cdot \frac{1}{\pi} \exp\left(\frac{-r^2}{2}\right)\, r\,\mathrm d\theta \, \mathrm dr &\scriptstyle{\text{change to polar coordinates}}\\ &= \left. \int_0^\infty \sin(\theta)\right|_{\pi/4}^{5\pi/4} \cdot \frac{1}{\pi} r^2 \exp\left(\frac{-r^2}{2}\right) \, \mathrm dr\\ &= -\frac{\sqrt 2}{\pi}\int_0^\infty r^2 \exp\left(\frac{-r^2}{2}\right) \, \mathrm dr &\scriptstyle{\text{now re-write the constant}}\\ &= -\frac{1}{\sqrt \pi}\int_{-\infty}^\infty r^2 \frac{1}{\sqrt{2\pi}}\exp\left(\frac{-r^2}{2}\right) \, \mathrm dr &\scriptstyle{\text{and recognize the integral}}\\ &= -\frac{1}{\sqrt \pi}, \end{align} and since $W+Z = X_{(1)}+X_{(2)} = X_1+X_2$, we deduce that $$E[Z] = E[X_{1}+X_{2}]-E[W] = 0 - \left(-\frac{1}{\sqrt \pi}\right) = \frac{1}{\sqrt \pi}.$$ Similarly, \begin{align} E[W^2] &= \int_{-\infty}^\infty \int_{-\infty}^\infty w^2\cdot f_{W,Z}(w,z)\, \mathrm dz\, \mathrm dw\\ &= \int_0^\infty \int_{\pi/4}^{5\pi/4} r^2\cos^2(\theta)\cdot \frac{1}{\pi} \exp\left(\frac{-r^2}{2}\right)\, r\,\mathrm d\theta \, \mathrm dr &\scriptstyle{\text{change to polar coordinates}}\\ &= \left. \int_0^\infty \frac{2\theta+\sin(2\theta)}{4}\right|_{\pi/4}^{5\pi/4} \cdot \frac{1}{\pi} r^3 \exp\left(\frac{-r^2}{2}\right) \, \mathrm dr\\ &= \frac{1}{2}\int_0^\infty r^3 \exp\left(\frac{-r^2}{2}\right) \, \mathrm dr &\scriptstyle{\text{now set }r^2/2 = t}\\ &= \int_0^\infty t \exp\left(-t\right) \, \mathrm dt \\ &= 1, \end{align} and since $W^2+Z^2 = X_{(1)}^2+X_{(2)}^2 = X_1^2+X_2^2$, we have that $$E[W^2+Z^2]= 1+E[Z^2]=E[X_1^2+X_2^2]=2 \implies E[Z^2] = E[W^2]=1.$$ It follows that $\operatorname{var}(W) = \operatorname{var}(Z) = 1-\frac{1}{\pi}.$ Finally, \begin{align} \operatorname{cov}(X_{(1)},X_{(2)})&= \operatorname{cov}(W,Z)\\ &= E[WZ] - E[W]E[Z]\\ &= E[X_1X_2] + \frac{1}{\pi}\\ &= E[X_1]E[X_2] + \frac{1}{\pi}&\scriptstyle{\text{because }X_1~\text{and }X_2~\text{are independent}}\\ &= \frac{1}{\pi} \end{align} If $X_1$ and $X_2$ are scaled by $\sigma$ and translated by $\mu$ to iid $N(\mu,\sigma^2)$, then we ready get that $$E[X_{(1)}] = \mu - \frac{\sigma}{\sqrt{\pi}}, \quad E[X_{(2)}] = \mu + \frac{\sigma}{\sqrt{\pi}}\\ \operatorname{var}(X_{(1)}) = \operatorname{var}(X_{(2)}) = \sigma^2\left(1-\frac{1}{\pi}\right)\\ \operatorname{cov}(X_{(1)},X_{(2)}) = \frac{\sigma^2}{\pi}.$$
Let $X_{(1)}\leq X_{(2)}$ be the order statistics. Evaluate $\operatorname{Var}(X_{(j)})$, $\operato Here is a brute-force answer that lacks the elegance of whuber's calculations but arrives at the same conclusions. With $X_i, i = 1, 2,$ denoting independent standard random variables and $$(W,Z) = \
31,820
Generate random numbers from "sloped uniform distribution" from mathematical theory
Your deriviation is ok. Note that to get a positive density on $(0,B)$, you have to constraint $$ B^2 \tan\phi < 2. $$ In your code $B = 25$ so you should take $\phi$ between $\pm\tan^{-1}{2\over 625}$, that's where your code fails. You can (and should) avoid using a quadratic solver, and then select the roots between 0 and $B$. The quadratic polynomial equation in $x$ to be solved is $$F(x) = t$$ with $$ F(x) = {1\over 2} \tan \phi \cdot x^2 + \left( {1\over B} - {B\over 2} \tan \phi \right) x.$$ By construction $F(0) = 0$ and $F(B) = 1$; also $F$ increases on $(0,B)$. From this it is easy to see that if $\tan \phi > 0$, the portion of parabola in which we are interested is a part of the right side of the parabola, and the root to keep is the highest of the two roots, that is $$ x = {1\over \tan \phi} \left( {B\over 2} \tan \phi - {1\over B} + \sqrt{ \left( {B\over 2} \tan \phi - {1\over B} \right)^2 + 2 \tan \phi \cdot t}. \right)$$ To the contrary, if $\tan\phi < 0$, the parabola is upside down, and we are interest in its left part. The root to keep is the lowest one. Taking into account the sign of $\tan\phi$ it appears that this is the same root (ie the one with $+\sqrt\Delta$) than in the first case. Here is some R code. phi <- pi/8; B <- 2 f <- function(t) (-(1/B - 0.5*B*tan(phi)) + sqrt( (1/B - 0.5*B*tan(phi))**2 + 2 * tan(phi) * t))/tan(phi) hist(f(runif(1e6))) And with $\phi < 0$: phi <- -pi/8 hist(f(runif(1e6)))
Generate random numbers from "sloped uniform distribution" from mathematical theory
Your deriviation is ok. Note that to get a positive density on $(0,B)$, you have to constraint $$ B^2 \tan\phi < 2. $$ In your code $B = 25$ so you should take $\phi$ between $\pm\tan^{-1}{2\over 625}
Generate random numbers from "sloped uniform distribution" from mathematical theory Your deriviation is ok. Note that to get a positive density on $(0,B)$, you have to constraint $$ B^2 \tan\phi < 2. $$ In your code $B = 25$ so you should take $\phi$ between $\pm\tan^{-1}{2\over 625}$, that's where your code fails. You can (and should) avoid using a quadratic solver, and then select the roots between 0 and $B$. The quadratic polynomial equation in $x$ to be solved is $$F(x) = t$$ with $$ F(x) = {1\over 2} \tan \phi \cdot x^2 + \left( {1\over B} - {B\over 2} \tan \phi \right) x.$$ By construction $F(0) = 0$ and $F(B) = 1$; also $F$ increases on $(0,B)$. From this it is easy to see that if $\tan \phi > 0$, the portion of parabola in which we are interested is a part of the right side of the parabola, and the root to keep is the highest of the two roots, that is $$ x = {1\over \tan \phi} \left( {B\over 2} \tan \phi - {1\over B} + \sqrt{ \left( {B\over 2} \tan \phi - {1\over B} \right)^2 + 2 \tan \phi \cdot t}. \right)$$ To the contrary, if $\tan\phi < 0$, the parabola is upside down, and we are interest in its left part. The root to keep is the lowest one. Taking into account the sign of $\tan\phi$ it appears that this is the same root (ie the one with $+\sqrt\Delta$) than in the first case. Here is some R code. phi <- pi/8; B <- 2 f <- function(t) (-(1/B - 0.5*B*tan(phi)) + sqrt( (1/B - 0.5*B*tan(phi))**2 + 2 * tan(phi) * t))/tan(phi) hist(f(runif(1e6))) And with $\phi < 0$: phi <- -pi/8 hist(f(runif(1e6)))
Generate random numbers from "sloped uniform distribution" from mathematical theory Your deriviation is ok. Note that to get a positive density on $(0,B)$, you have to constraint $$ B^2 \tan\phi < 2. $$ In your code $B = 25$ so you should take $\phi$ between $\pm\tan^{-1}{2\over 625}
31,821
Test homogeneity in lmer models
Yes you could use for example Levene's test using the leveneTest() function from the car package. Here's an example with the Machines dataset from the nlme package: library(lme4) library(nlme); data(Machines) library(car) mod <- lmer(score ~ Machine + (1|Worker), data=Machines) > leveneTest(residuals(mod) ~ Machines$Machine) Levene's Test for Homogeneity of Variance (center = median) Df F value Pr(>F) group 2 0.0811 0.9222 51 Since the result is not significant, the assumption of equal variances (homoscedasticity) is met. Also check ?leveneTest for more options. Let's compare this with a boxplot of the residuals: boxplot(residuals(mod) ~ Machines$Machine) Since the reviewer seems to want a "formal test", it will probably be difficult to convince him accepting your visual inspection, despite, in my opinion, this would be the way to go. Maybe someone else has an actual reference why checking those assumptions visually is superior compared to "formal tests". Edit to address comment by @D_Williams below: A good and strongly cited paper by Zuur et al. 2010 may help to convince your reviewer regarding visual inspection of residuals to test for homogeneity of variances. Also here's is the link to the book Mixed Effects Models and Extensions in Ecology with R.
Test homogeneity in lmer models
Yes you could use for example Levene's test using the leveneTest() function from the car package. Here's an example with the Machines dataset from the nlme package: library(lme4) library(nlme); data(M
Test homogeneity in lmer models Yes you could use for example Levene's test using the leveneTest() function from the car package. Here's an example with the Machines dataset from the nlme package: library(lme4) library(nlme); data(Machines) library(car) mod <- lmer(score ~ Machine + (1|Worker), data=Machines) > leveneTest(residuals(mod) ~ Machines$Machine) Levene's Test for Homogeneity of Variance (center = median) Df F value Pr(>F) group 2 0.0811 0.9222 51 Since the result is not significant, the assumption of equal variances (homoscedasticity) is met. Also check ?leveneTest for more options. Let's compare this with a boxplot of the residuals: boxplot(residuals(mod) ~ Machines$Machine) Since the reviewer seems to want a "formal test", it will probably be difficult to convince him accepting your visual inspection, despite, in my opinion, this would be the way to go. Maybe someone else has an actual reference why checking those assumptions visually is superior compared to "formal tests". Edit to address comment by @D_Williams below: A good and strongly cited paper by Zuur et al. 2010 may help to convince your reviewer regarding visual inspection of residuals to test for homogeneity of variances. Also here's is the link to the book Mixed Effects Models and Extensions in Ecology with R.
Test homogeneity in lmer models Yes you could use for example Levene's test using the leveneTest() function from the car package. Here's an example with the Machines dataset from the nlme package: library(lme4) library(nlme); data(M
31,822
Different definitions of "curse of dimensionality"
It is not a mathematical object like a derivative that needs to be defined formally without any ambiguity. It is an umbrella term for those two issues encountered when using high dimensional data. The issues are strictly speaking separated and both always present. Depending on your algorithm's vulnerability to them, you can have to deal with both, none, one but not the other and vice versa. I have read the first definition in slightly different versions. This definition, as quoted here, does not tell us what is meant by estimating the function with a given level of accuracy. Anyway, if you want to know the value of a function at equidistant points, you will need more points, the more dimensions you have. For example 10 points are needed to sample a 1D line from 0 to 1 every 0.1, 100 points are needed for the unit square, 1000 for the cube etc. This affects only algorithms that need sample points in all directions of the feature space. The second definition is also called "distance concentration effect". Many, but not all algorithms are affected by it. It comes into play when the algorithm uses k nearest neighbors or some other technique relying on distance measures. I don't remember in which canonical reference I picked up the term distance concentration. Here are two papers that discuss the issue in detail though: When is nearest neighbor meaningful, A survey on unsupervised outlier detection in high- dimensional numerical data In practice, they often happen simultaneously. Strictly speaking, they are always both present. The question is whether your algorithm is vulnerable to both or not. For example, with classic k nearest neighbor learning, you want to have training examples in all regions of the space that your test examples could come from. You are thus vulnerable to the curse of dimensionality in the first sense. You are also vulnerable to the second meaning of the term since you need to compute distances to establish the nearest neighbors which makes less sense if all distances converge to the same number. Both definitions are in use. I suggest you infer from context which meaning a source uses and be specific which one you mean when using the term. PS. I've also seen the term used informally when an algorithm's computational complexity increases with the number of dimensions. The term then simply refers to the increasing computational complexity.
Different definitions of "curse of dimensionality"
It is not a mathematical object like a derivative that needs to be defined formally without any ambiguity. It is an umbrella term for those two issues encountered when using high dimensional data. The
Different definitions of "curse of dimensionality" It is not a mathematical object like a derivative that needs to be defined formally without any ambiguity. It is an umbrella term for those two issues encountered when using high dimensional data. The issues are strictly speaking separated and both always present. Depending on your algorithm's vulnerability to them, you can have to deal with both, none, one but not the other and vice versa. I have read the first definition in slightly different versions. This definition, as quoted here, does not tell us what is meant by estimating the function with a given level of accuracy. Anyway, if you want to know the value of a function at equidistant points, you will need more points, the more dimensions you have. For example 10 points are needed to sample a 1D line from 0 to 1 every 0.1, 100 points are needed for the unit square, 1000 for the cube etc. This affects only algorithms that need sample points in all directions of the feature space. The second definition is also called "distance concentration effect". Many, but not all algorithms are affected by it. It comes into play when the algorithm uses k nearest neighbors or some other technique relying on distance measures. I don't remember in which canonical reference I picked up the term distance concentration. Here are two papers that discuss the issue in detail though: When is nearest neighbor meaningful, A survey on unsupervised outlier detection in high- dimensional numerical data In practice, they often happen simultaneously. Strictly speaking, they are always both present. The question is whether your algorithm is vulnerable to both or not. For example, with classic k nearest neighbor learning, you want to have training examples in all regions of the space that your test examples could come from. You are thus vulnerable to the curse of dimensionality in the first sense. You are also vulnerable to the second meaning of the term since you need to compute distances to establish the nearest neighbors which makes less sense if all distances converge to the same number. Both definitions are in use. I suggest you infer from context which meaning a source uses and be specific which one you mean when using the term. PS. I've also seen the term used informally when an algorithm's computational complexity increases with the number of dimensions. The term then simply refers to the increasing computational complexity.
Different definitions of "curse of dimensionality" It is not a mathematical object like a derivative that needs to be defined formally without any ambiguity. It is an umbrella term for those two issues encountered when using high dimensional data. The
31,823
Filtering vs Smoothing in Bayesian Estimation
I guess definitions could be different, but the standard definitions I use are filtering: $p(x_t|y_1,\ldots,y_t,\Theta)$ smoothing: $p(x_t|y_1,\ldots,y_T,\Theta)$ for $0\le t<T$ That is, filtering is the distribution of the current state given all observations up to and including the current time while smoothing is the distribution of a past state (or states) given the data up to the current time. For me, neither filtering nor smoothing refers to $p(x_t|y_{t+1},y_t,y_{t-1},\Theta)$. I'm also guessing that you really wanted $$p(x_t|x_{t+1},y_t,x_{t-1},\Theta) = p(x_t|y_1,\ldots,y_T,x_1,\ldots,x_{t-1},x_{t+1},\ldots,x_T,\theta)$$ which is the full conditional distribution for $x_t$ which some refer to as the conditional posterior.
Filtering vs Smoothing in Bayesian Estimation
I guess definitions could be different, but the standard definitions I use are filtering: $p(x_t|y_1,\ldots,y_t,\Theta)$ smoothing: $p(x_t|y_1,\ldots,y_T,\Theta)$ for $0\le t<T$ That is, filtering
Filtering vs Smoothing in Bayesian Estimation I guess definitions could be different, but the standard definitions I use are filtering: $p(x_t|y_1,\ldots,y_t,\Theta)$ smoothing: $p(x_t|y_1,\ldots,y_T,\Theta)$ for $0\le t<T$ That is, filtering is the distribution of the current state given all observations up to and including the current time while smoothing is the distribution of a past state (or states) given the data up to the current time. For me, neither filtering nor smoothing refers to $p(x_t|y_{t+1},y_t,y_{t-1},\Theta)$. I'm also guessing that you really wanted $$p(x_t|x_{t+1},y_t,x_{t-1},\Theta) = p(x_t|y_1,\ldots,y_T,x_1,\ldots,x_{t-1},x_{t+1},\ldots,x_T,\theta)$$ which is the full conditional distribution for $x_t$ which some refer to as the conditional posterior.
Filtering vs Smoothing in Bayesian Estimation I guess definitions could be different, but the standard definitions I use are filtering: $p(x_t|y_1,\ldots,y_t,\Theta)$ smoothing: $p(x_t|y_1,\ldots,y_T,\Theta)$ for $0\le t<T$ That is, filtering
31,824
Filtering vs Smoothing in Bayesian Estimation
Original model you mentioned in the comments to the other answer: $$ Y_{t+1} = Y_t + \mu \Delta + \sqrt{v_t \Delta} \epsilon_{t+1}^y + \xi_{t+1}^y N_{t+1}^y \\ v_{t+1} = v_t + \kappa(\theta - v_t)\Delta + \sigma_v \sqrt{v_t\Delta}\epsilon_{t+1}^v $$ with $\text{corr}(\epsilon_{t+1}^y,\epsilon_{t+1}^v) = \rho$. The reference you linked to is also linked to at the end of this. 1 Let's call $\epsilon_{t+1}^y = e^1_{t+1}$ and $\epsilon_{t+1}^v = \rho e^1_{t+1} + \sqrt{(1-\rho^2)}e^2_{t+1}$ with $e^1_{t+1}$ and $e^2_{t+1}$ independent standard normals. Making the substitutions we get $$ Y_{t+1} - Y_t = \mu \Delta + \sqrt{v_t \Delta} e^1_{t+1} + \xi_{t+1}^y N_{t+1}^y \\ v_{t+1} = v_t + \kappa(\theta - v_t)\Delta + \sigma_v \sqrt{v_t\Delta}\left[\rho e^1_{t+1} + \sqrt{(1-\rho^2)}e^2_{t+1} \right] $$ Then let $\phi = \sigma_v \rho$ and $w_v = \sigma^2_v(1-\rho^2)$. They say to make this transformation on page 33. $$ Y_{t+1} - Y_t = \mu \Delta + \sqrt{v_t \Delta} e^1_{t+1} + \xi_{t+1}^y N_{t+1}^y \\ v_{t+1} = v_t + \kappa(\theta - v_t)\Delta + \phi\sqrt{v_t\Delta} e^1_{t+1} + \sqrt{v_t\Delta}\sqrt{w_v}e^2_{t+1} $$ 2 They menton that $\Theta = \{\mu, \kappa, \theta, \sigma_v, \rho, \lambda_y, \mu_y, \sigma_y\}$. After the transformation it's actually $\Theta = \{\mu, \kappa, \theta, \phi, w_v, \lambda_y, \mu_y, \sigma_y\}$ for us now. They also describe posteriors for the following (and these must be part of the state vector at some time): $\xi^y_{t+1}$ $N_{t+1}^y$, $v_{t+1}$. So we could define the state vector $$ x_t = [v_{t+1}, v_t, \xi^y_{t+1} N_{t+1}^y]', $$ and this would represent a state space model closer to what the other answer was talking about. But there are probably a lot of ways to do this. At the moment I can't tell if this paper does it that way. 3 Anyway, back to your question...I'm not sure why you relabelled everything becuase that makes it way harder to follow along, but you said in the comment that you're trying to get at the 'conditional posterior of $v_{t+1}$.' If you mean $p(v_{t+1}|y_{1:T}, \Theta)$, then that's a marginal of the smoothing distributon $p(x_{t+1}|y_{1:T}, \Theta)$ that the other answer was talking about. On the other hand, if you were trying to sample from $p(x_{t}|y_{1:T},x_{1:t-1},x_{t+1:T})$ then \begin{align*} p(x_{t}|y_{1:T},x_{1:t-1},x_{t+1:T}) &\propto \prod_{t=2}^T p(y_t|x_t)p(x_t|x_{t-1})p(y_1|x_1)p(x_1) \\ &\propto p(x_t|x_{t-1})p(y_t|x_t)p(x_{t+1}|x_t) \\ &\propto p(x_t|x_{t-1},x_{t+1},y_t) \end{align*} which the other answer also mentioned. I think this is called a "single-site sampler," perhaps useful if you wanted to get at $p(x_{1:T}|y_{1:T},\Theta)$ Gibbs-style. I am guessing that this is what you want, actually. You would get this if you used the state vector in part 2, and used the log returns $Y_{t+1} -Y_t$ as the observations. So I'm kind of echoing the other answer here: it's probably one of those two things. Hope this helps. Reference: http://lib.dr.iastate.edu/cgi/viewcontent.cgi?article=1121&context=stat_las_preprints
Filtering vs Smoothing in Bayesian Estimation
Original model you mentioned in the comments to the other answer: $$ Y_{t+1} = Y_t + \mu \Delta + \sqrt{v_t \Delta} \epsilon_{t+1}^y + \xi_{t+1}^y N_{t+1}^y \\ v_{t+1} = v_t + \kappa(\theta - v_t)\Del
Filtering vs Smoothing in Bayesian Estimation Original model you mentioned in the comments to the other answer: $$ Y_{t+1} = Y_t + \mu \Delta + \sqrt{v_t \Delta} \epsilon_{t+1}^y + \xi_{t+1}^y N_{t+1}^y \\ v_{t+1} = v_t + \kappa(\theta - v_t)\Delta + \sigma_v \sqrt{v_t\Delta}\epsilon_{t+1}^v $$ with $\text{corr}(\epsilon_{t+1}^y,\epsilon_{t+1}^v) = \rho$. The reference you linked to is also linked to at the end of this. 1 Let's call $\epsilon_{t+1}^y = e^1_{t+1}$ and $\epsilon_{t+1}^v = \rho e^1_{t+1} + \sqrt{(1-\rho^2)}e^2_{t+1}$ with $e^1_{t+1}$ and $e^2_{t+1}$ independent standard normals. Making the substitutions we get $$ Y_{t+1} - Y_t = \mu \Delta + \sqrt{v_t \Delta} e^1_{t+1} + \xi_{t+1}^y N_{t+1}^y \\ v_{t+1} = v_t + \kappa(\theta - v_t)\Delta + \sigma_v \sqrt{v_t\Delta}\left[\rho e^1_{t+1} + \sqrt{(1-\rho^2)}e^2_{t+1} \right] $$ Then let $\phi = \sigma_v \rho$ and $w_v = \sigma^2_v(1-\rho^2)$. They say to make this transformation on page 33. $$ Y_{t+1} - Y_t = \mu \Delta + \sqrt{v_t \Delta} e^1_{t+1} + \xi_{t+1}^y N_{t+1}^y \\ v_{t+1} = v_t + \kappa(\theta - v_t)\Delta + \phi\sqrt{v_t\Delta} e^1_{t+1} + \sqrt{v_t\Delta}\sqrt{w_v}e^2_{t+1} $$ 2 They menton that $\Theta = \{\mu, \kappa, \theta, \sigma_v, \rho, \lambda_y, \mu_y, \sigma_y\}$. After the transformation it's actually $\Theta = \{\mu, \kappa, \theta, \phi, w_v, \lambda_y, \mu_y, \sigma_y\}$ for us now. They also describe posteriors for the following (and these must be part of the state vector at some time): $\xi^y_{t+1}$ $N_{t+1}^y$, $v_{t+1}$. So we could define the state vector $$ x_t = [v_{t+1}, v_t, \xi^y_{t+1} N_{t+1}^y]', $$ and this would represent a state space model closer to what the other answer was talking about. But there are probably a lot of ways to do this. At the moment I can't tell if this paper does it that way. 3 Anyway, back to your question...I'm not sure why you relabelled everything becuase that makes it way harder to follow along, but you said in the comment that you're trying to get at the 'conditional posterior of $v_{t+1}$.' If you mean $p(v_{t+1}|y_{1:T}, \Theta)$, then that's a marginal of the smoothing distributon $p(x_{t+1}|y_{1:T}, \Theta)$ that the other answer was talking about. On the other hand, if you were trying to sample from $p(x_{t}|y_{1:T},x_{1:t-1},x_{t+1:T})$ then \begin{align*} p(x_{t}|y_{1:T},x_{1:t-1},x_{t+1:T}) &\propto \prod_{t=2}^T p(y_t|x_t)p(x_t|x_{t-1})p(y_1|x_1)p(x_1) \\ &\propto p(x_t|x_{t-1})p(y_t|x_t)p(x_{t+1}|x_t) \\ &\propto p(x_t|x_{t-1},x_{t+1},y_t) \end{align*} which the other answer also mentioned. I think this is called a "single-site sampler," perhaps useful if you wanted to get at $p(x_{1:T}|y_{1:T},\Theta)$ Gibbs-style. I am guessing that this is what you want, actually. You would get this if you used the state vector in part 2, and used the log returns $Y_{t+1} -Y_t$ as the observations. So I'm kind of echoing the other answer here: it's probably one of those two things. Hope this helps. Reference: http://lib.dr.iastate.edu/cgi/viewcontent.cgi?article=1121&context=stat_las_preprints
Filtering vs Smoothing in Bayesian Estimation Original model you mentioned in the comments to the other answer: $$ Y_{t+1} = Y_t + \mu \Delta + \sqrt{v_t \Delta} \epsilon_{t+1}^y + \xi_{t+1}^y N_{t+1}^y \\ v_{t+1} = v_t + \kappa(\theta - v_t)\Del
31,825
Weibull vs. Gamma Distribution
Translating to your context, "time-to-event" becomes "distance-to-point". The Weibull distribution is appropriate when the probability of observing a point increases or decreases as you move along the vector. The probability declines over time, so most of the points occur at nearer distances: $X \sim Wei(\lambda,k)$, where $k<1$ The probability increases over time, so most of the points are at farther distances: $X \sim Wei(\lambda,k)$, where $k>1$ The gamma distribution would then describe the distance until $k$ points are observed - how far do you have to go to observe $k$ points. The distribution lets you determine the probability of going $X$ units before observing $k$ points. This is a Poisson process, where events (points) occur at a constant rate, $\lambda$. In the Weibull distribution, events can occur at decreasing, increasing, or constant rates (or distances). So, in your case, if the Weibull distribution fits the data better, then you probably have a case where points are “clustering” somewhere. If your scale parameter is less than one, points are closer together at nearer distances, with distances between point increasing as you move along the vector. If it is greater than one, then points are further apart at nearer distances, with distances between points decreasing at you move along the vector.
Weibull vs. Gamma Distribution
Translating to your context, "time-to-event" becomes "distance-to-point". The Weibull distribution is appropriate when the probability of observing a point increases or decreases as you move along the
Weibull vs. Gamma Distribution Translating to your context, "time-to-event" becomes "distance-to-point". The Weibull distribution is appropriate when the probability of observing a point increases or decreases as you move along the vector. The probability declines over time, so most of the points occur at nearer distances: $X \sim Wei(\lambda,k)$, where $k<1$ The probability increases over time, so most of the points are at farther distances: $X \sim Wei(\lambda,k)$, where $k>1$ The gamma distribution would then describe the distance until $k$ points are observed - how far do you have to go to observe $k$ points. The distribution lets you determine the probability of going $X$ units before observing $k$ points. This is a Poisson process, where events (points) occur at a constant rate, $\lambda$. In the Weibull distribution, events can occur at decreasing, increasing, or constant rates (or distances). So, in your case, if the Weibull distribution fits the data better, then you probably have a case where points are “clustering” somewhere. If your scale parameter is less than one, points are closer together at nearer distances, with distances between point increasing as you move along the vector. If it is greater than one, then points are further apart at nearer distances, with distances between points decreasing at you move along the vector.
Weibull vs. Gamma Distribution Translating to your context, "time-to-event" becomes "distance-to-point". The Weibull distribution is appropriate when the probability of observing a point increases or decreases as you move along the
31,826
Estimating the CAPM Beta via OLS Regresson
As Stephen mentions, the confusion is between: (1) the CAPM vs. (2) the market model. Let $R^f$ denote the risk free rate. We often work with excess returns, which involves subtracting of the risk free rate. Some simple models for expected returns ``Market model" $$ R_t - R^f = \alpha + \beta\left(R^m_t - R^f \right) + \epsilon_t $$ $$ E\left[ R_t \right] - R^f = \alpha + \beta\left(E[R^m_t] - R^f \right) $$ The market model is a simple, statistical model and can be justified by assuming that the joint distribution of monthly stock returns is multivariate normal. Capital Asset Pricing Model (CAPM) $$ E\left[ R_t\right] - R^f = \beta\left(E[R^m_t] - R^f \right) $$ The CAPM is an economic theory that expected excess returns of a stock are linear in the excess return of the market, that $\alpha = 0$ from the market model regression. Be aware that the CAPM doesn't work. It's all over MBA corporate finance, but asset pricing people find it useless. Something less crazy to use would be the Fama-French 3 Factor Model. Example of how to use the CAPM (or any of these factor asset pricing models). Compute excess returns: $ R_{i,t} - R^f_t$ Regress excess returns on excess returns of the market and a constant (i.e. run the market model regression). $$ R_{i,t} - R^f_t = \alpha_i + \beta_i \left( R^m_t - R^f_t \right) + \epsilon_{i,t}$$ Ignore the estimated $\hat{\alpha}$. Your estimated expected excess return according to the CAPM is $\hat{\beta_i} E[R^m_t - R^f_t] $.
Estimating the CAPM Beta via OLS Regresson
As Stephen mentions, the confusion is between: (1) the CAPM vs. (2) the market model. Let $R^f$ denote the risk free rate. We often work with excess returns, which involves subtracting of the risk fre
Estimating the CAPM Beta via OLS Regresson As Stephen mentions, the confusion is between: (1) the CAPM vs. (2) the market model. Let $R^f$ denote the risk free rate. We often work with excess returns, which involves subtracting of the risk free rate. Some simple models for expected returns ``Market model" $$ R_t - R^f = \alpha + \beta\left(R^m_t - R^f \right) + \epsilon_t $$ $$ E\left[ R_t \right] - R^f = \alpha + \beta\left(E[R^m_t] - R^f \right) $$ The market model is a simple, statistical model and can be justified by assuming that the joint distribution of monthly stock returns is multivariate normal. Capital Asset Pricing Model (CAPM) $$ E\left[ R_t\right] - R^f = \beta\left(E[R^m_t] - R^f \right) $$ The CAPM is an economic theory that expected excess returns of a stock are linear in the excess return of the market, that $\alpha = 0$ from the market model regression. Be aware that the CAPM doesn't work. It's all over MBA corporate finance, but asset pricing people find it useless. Something less crazy to use would be the Fama-French 3 Factor Model. Example of how to use the CAPM (or any of these factor asset pricing models). Compute excess returns: $ R_{i,t} - R^f_t$ Regress excess returns on excess returns of the market and a constant (i.e. run the market model regression). $$ R_{i,t} - R^f_t = \alpha_i + \beta_i \left( R^m_t - R^f_t \right) + \epsilon_{i,t}$$ Ignore the estimated $\hat{\alpha}$. Your estimated expected excess return according to the CAPM is $\hat{\beta_i} E[R^m_t - R^f_t] $.
Estimating the CAPM Beta via OLS Regresson As Stephen mentions, the confusion is between: (1) the CAPM vs. (2) the market model. Let $R^f$ denote the risk free rate. We often work with excess returns, which involves subtracting of the risk fre
31,827
Estimating the CAPM Beta via OLS Regresson
If I recall correctly, it has something to do with a constant called Jensen's alpha and the extension to something called a multi-factor model. During my classes (and also wikipedia), the CAPM was stated as follows: \begin{align} \mathbb{E}[R_i] = R_{f} + \hat{\beta_{1}}(\mathbb{E}[R_{m}] - R_{f}) \end{align} When taking excess returns, one would simply have: \begin{align} \mathbb{E}[R_i] - R_{f} = \hat{\beta_{1}}(\mathbb{E}[R_{m}] - R_{f}) \end{align} And this is mostly fine. However, this relation assumes that all information can be taken from just the market portfolio in excess to the risk free rate (i.e. $\hat{\beta_0} =0$). However, it could be the case that your specific return $R_i$ could deviate from the returns seen on the market portfolio. In this case, let us add a constant $\beta_0$ to the model, so we have: \begin{align} R_i - R_f= \beta_0 + \beta_{1}(R_{m} - R_{f}) + \epsilon \end{align} and when taking expectations \begin{align} \mathbb{E}[R_i] - R_{f} =\hat{\beta_0}+ \hat{\beta_{1}}(\mathbb{E}[R_{m}] - R_{f}) \end{align} Now, suppose you calculate the estimates of $\hat{\beta_0} , \hat{\beta_1}$ using OLS. You will thus now have 2 estimates for the parameters. The way you will generally use the $\hat{\beta_0}$ is by performing a simple t-test test on it: 1: Before testing you have to make sure that the standard errors are correct. Note that the t-test relies directly on the standard errors being homoskedastic, so keep in mind that you will probably have to use robust standard errors, such as Eicker-Huber-White or Newey-West. 2: After you made sure the standard errors from your regression equation are in order you can simply look at the individual t-test for $\hat{\beta_0}$. On the basis of the hypothesis of \begin{align} H_0 : \beta_0 = 0 \quad vs \quad H1: \beta_0 \ne 0 \end{align} On the basis of rejecting the null-hypothesis or failing to reject it, we can distinguish between three cases. 1: $\hat{\beta_0} =0$. In this case, your expected return $\mathbb{E}[R_i] - R_f$ neither outperforms or under performs with respect to the market (which is what your homework is assuming here). 2:$\hat{\beta_0} > 0$. Here, your return is outperforming the market. In this case, the market portfolio can not fully explain your return and additional factors are needed (three-factor model or multi factor models). 3:$\hat{\beta_0}< 0$ . Same as above, only this time the return is under performing with respect to the market portfolio. All in all, whether or not to include this term depends on whether you assume that no additional factors are needed. If the question states that $R_i$ can be completely explained by just the market portfolio you can simply set this term to zero. In practice, you would perform a statistical hypothesis to test whether it is significantly different from zero or not (Jensen's alpha).
Estimating the CAPM Beta via OLS Regresson
If I recall correctly, it has something to do with a constant called Jensen's alpha and the extension to something called a multi-factor model. During my classes (and also wikipedia), the CAPM was sta
Estimating the CAPM Beta via OLS Regresson If I recall correctly, it has something to do with a constant called Jensen's alpha and the extension to something called a multi-factor model. During my classes (and also wikipedia), the CAPM was stated as follows: \begin{align} \mathbb{E}[R_i] = R_{f} + \hat{\beta_{1}}(\mathbb{E}[R_{m}] - R_{f}) \end{align} When taking excess returns, one would simply have: \begin{align} \mathbb{E}[R_i] - R_{f} = \hat{\beta_{1}}(\mathbb{E}[R_{m}] - R_{f}) \end{align} And this is mostly fine. However, this relation assumes that all information can be taken from just the market portfolio in excess to the risk free rate (i.e. $\hat{\beta_0} =0$). However, it could be the case that your specific return $R_i$ could deviate from the returns seen on the market portfolio. In this case, let us add a constant $\beta_0$ to the model, so we have: \begin{align} R_i - R_f= \beta_0 + \beta_{1}(R_{m} - R_{f}) + \epsilon \end{align} and when taking expectations \begin{align} \mathbb{E}[R_i] - R_{f} =\hat{\beta_0}+ \hat{\beta_{1}}(\mathbb{E}[R_{m}] - R_{f}) \end{align} Now, suppose you calculate the estimates of $\hat{\beta_0} , \hat{\beta_1}$ using OLS. You will thus now have 2 estimates for the parameters. The way you will generally use the $\hat{\beta_0}$ is by performing a simple t-test test on it: 1: Before testing you have to make sure that the standard errors are correct. Note that the t-test relies directly on the standard errors being homoskedastic, so keep in mind that you will probably have to use robust standard errors, such as Eicker-Huber-White or Newey-West. 2: After you made sure the standard errors from your regression equation are in order you can simply look at the individual t-test for $\hat{\beta_0}$. On the basis of the hypothesis of \begin{align} H_0 : \beta_0 = 0 \quad vs \quad H1: \beta_0 \ne 0 \end{align} On the basis of rejecting the null-hypothesis or failing to reject it, we can distinguish between three cases. 1: $\hat{\beta_0} =0$. In this case, your expected return $\mathbb{E}[R_i] - R_f$ neither outperforms or under performs with respect to the market (which is what your homework is assuming here). 2:$\hat{\beta_0} > 0$. Here, your return is outperforming the market. In this case, the market portfolio can not fully explain your return and additional factors are needed (three-factor model or multi factor models). 3:$\hat{\beta_0}< 0$ . Same as above, only this time the return is under performing with respect to the market portfolio. All in all, whether or not to include this term depends on whether you assume that no additional factors are needed. If the question states that $R_i$ can be completely explained by just the market portfolio you can simply set this term to zero. In practice, you would perform a statistical hypothesis to test whether it is significantly different from zero or not (Jensen's alpha).
Estimating the CAPM Beta via OLS Regresson If I recall correctly, it has something to do with a constant called Jensen's alpha and the extension to something called a multi-factor model. During my classes (and also wikipedia), the CAPM was sta
31,828
Effect of baseline on change over time in mixed models?
This seems to be a growth model scenario. Suppose we had the following variables: occasion: taking values 1,2,3,4,5 to reflect the occasion that test was taken, 1 being the first, or baseline. ID: the identifier of the each participant. score: the test score for this participant on this test occasion. Random intercepts for ID will take care of the different baselines (subject to having sufficient participants. Thus a simple linear mixed effects model for these data is (using lme4 syntax): score ~ occasion + (1|ID) or score ~ occasion + (occasion|ID) where the latter allows the linear slope of occasion to vary among participants However, for the particular example in the OP, we have the additional problem that the score variable is bounded above by the maximum score on the test. To allow for this, we need to cater for non-linear growth. This could be achieved in a variety of ways, the simplest being the addition of quadratic and possibly cubic terms to the model: score ~ occasion + I(occasion^2) + I(occasion^3) + (1|ID) Let's look at a toy example: require(lme4) require(ggplot2) dt2 <- structure(list(occasion = c(0, 1, 2, 3, 4, 0, 1, 2, 3, 4, 0, 1, 2, 3, 4, 0, 1, 2, 3, 4, 0, 1, 2, 3, 4, 0, 1, 2, 3, 4), score = c(55.5, 74.5, 92.5, 97.5, 98.5, 54.5, 81.5, 94.5, 97.5, 98.5, 47.5, 68.5, 86.5, 96.5, 98.5, 56.5, 86.5, 91.5, 97.5, 98.5, 60.5, 84.5, 95.5, 97.5, 99.5, 73.5, 87.5, 96.5, 98.5, 99.5), ID = structure(c(1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 3L, 3L, 3L, 3L, 3L, 4L, 4L, 4L, 4L, 4L, 5L, 5L, 5L, 5L, 5L, 6L, 6L, 6L, 6L, 6L), .Label = c("1", "2", "3", "4", "5", "6"), class = "factor")), .Names = c("occasion", "score", "ID"), row.names = c(25L, 26L, 27L, 28L, 29L, 31L, 32L, 33L, 34L, 35L, 37L, 38L, 39L, 40L, 41L, 43L, 44L, 45L, 46L, 47L, 49L, 50L, 51L, 52L, 53L, 55L, 56L, 57L, 58L, 59L), class = "data.frame") m1 <- lmer(score~occasion+(1|ID),data=dt2) fun1 <- function(x) fixef(m1)[1] + fixef(m1)[2]*x ggplot(dt2,aes(x=occasion,y=score, color=ID)) + geom_line(size=0.65) + geom_point() + stat_function(fun=fun1, geom="line", size=1, colour="black") Here we have plots for 6 participants that have been measured over 5 successive occasions, and we have plotted the fixed effects with the solid black line. Clearly this is not a good model for these data, so we introduce a quadratic term, and then a cubic term, after centering the data to reduce collinearity: dt2$occasion <- dt2$occasion - mean(dt2$occasion) m2 <- lmer(score~occasion + I(occasion^2) + (1|ID),data=dt2) fun2 <- function(x) fixef(m2)[1] + fixef(m2)[2]*x + fixef(m2)[3]*(x^2) m3 <- lmer(score~occasion + I(occasion^2) + I(occasion^3) + (1|ID),data=dt2) fun3 <- function(x) fixef(m3)[1] + fixef(m3)[2]*x + fixef(m3)[3]*(x^2) + fixef(m3)[4]*(x^3) p2 <- ggplot(dt2,aes(x=occasion,y=score, color=ID)) + geom_line(size=0.5) + geom_point() p2 + stat_function(fun=fun2, geom="line", size=1, colour="black") Here we see that the quadratic model is an obvious improvement over the linear-only model, but is not ideal because it underestimates the scores for the final measurement, and overestimates it for the previous one. The cubic model on the other hand appears to work very well: p2 + stat_function(fun=fun3, geom="line", size=1, colour="black") A slightly more sophisticated approach is to recognise the upper bound explicity, and use (for example) a logistic growth curve model. One way to accomplish this is to transform the outcome to a proportion (of the upper bound), say $\pi$ and then model the logit of this proportion, $\pi/(1-\pi)$ as the outcome of a linear mixed effects model. In addition to recognising the upper bound, this has the added advantage of modelling heteroscasticity in the residuals of the untransformed data, since it seems likely that over successive tests (assuming that the results get better) there will be less variance. Putting this into practice, as expected, this also models the overall trend in the data very well: pi <- dt2$score/100 dt2$logitpi <- log(pi/(1-pi)) m0 <- lmer(logitpi~occasion+(1|ID),data=dt2) funlogis <- function(x) 100*exp(fixef(m0)[1] + fixef(m0)[2]*x)/(1+exp(fixef(m0)[1] + fixef(m0)[2]*x)) p2 + stat_function(fun=funlogis, geom="line", size=0.5, colour="black") The following shows the cubic mode and the logistic growth models plotted together, and we see very little difference between them, though as mentioned above we may prefer the logistic growth model due to the heteroscedasticity issue: p2 + stat_function(fun=fun3, geom="line", size=1, colour="black") + stat_function(fun=funlogis, geom="line", size=1, colour="blue") A more sophisticated approach still would be to use a nonlinear mixed effects model where the logistic growth curve is modelled explicitly, allowing for random variation in the parameters of the logistic function itself.
Effect of baseline on change over time in mixed models?
This seems to be a growth model scenario. Suppose we had the following variables: occasion: taking values 1,2,3,4,5 to reflect the occasion that test was taken, 1 being the first, or baseline. ID: th
Effect of baseline on change over time in mixed models? This seems to be a growth model scenario. Suppose we had the following variables: occasion: taking values 1,2,3,4,5 to reflect the occasion that test was taken, 1 being the first, or baseline. ID: the identifier of the each participant. score: the test score for this participant on this test occasion. Random intercepts for ID will take care of the different baselines (subject to having sufficient participants. Thus a simple linear mixed effects model for these data is (using lme4 syntax): score ~ occasion + (1|ID) or score ~ occasion + (occasion|ID) where the latter allows the linear slope of occasion to vary among participants However, for the particular example in the OP, we have the additional problem that the score variable is bounded above by the maximum score on the test. To allow for this, we need to cater for non-linear growth. This could be achieved in a variety of ways, the simplest being the addition of quadratic and possibly cubic terms to the model: score ~ occasion + I(occasion^2) + I(occasion^3) + (1|ID) Let's look at a toy example: require(lme4) require(ggplot2) dt2 <- structure(list(occasion = c(0, 1, 2, 3, 4, 0, 1, 2, 3, 4, 0, 1, 2, 3, 4, 0, 1, 2, 3, 4, 0, 1, 2, 3, 4, 0, 1, 2, 3, 4), score = c(55.5, 74.5, 92.5, 97.5, 98.5, 54.5, 81.5, 94.5, 97.5, 98.5, 47.5, 68.5, 86.5, 96.5, 98.5, 56.5, 86.5, 91.5, 97.5, 98.5, 60.5, 84.5, 95.5, 97.5, 99.5, 73.5, 87.5, 96.5, 98.5, 99.5), ID = structure(c(1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 3L, 3L, 3L, 3L, 3L, 4L, 4L, 4L, 4L, 4L, 5L, 5L, 5L, 5L, 5L, 6L, 6L, 6L, 6L, 6L), .Label = c("1", "2", "3", "4", "5", "6"), class = "factor")), .Names = c("occasion", "score", "ID"), row.names = c(25L, 26L, 27L, 28L, 29L, 31L, 32L, 33L, 34L, 35L, 37L, 38L, 39L, 40L, 41L, 43L, 44L, 45L, 46L, 47L, 49L, 50L, 51L, 52L, 53L, 55L, 56L, 57L, 58L, 59L), class = "data.frame") m1 <- lmer(score~occasion+(1|ID),data=dt2) fun1 <- function(x) fixef(m1)[1] + fixef(m1)[2]*x ggplot(dt2,aes(x=occasion,y=score, color=ID)) + geom_line(size=0.65) + geom_point() + stat_function(fun=fun1, geom="line", size=1, colour="black") Here we have plots for 6 participants that have been measured over 5 successive occasions, and we have plotted the fixed effects with the solid black line. Clearly this is not a good model for these data, so we introduce a quadratic term, and then a cubic term, after centering the data to reduce collinearity: dt2$occasion <- dt2$occasion - mean(dt2$occasion) m2 <- lmer(score~occasion + I(occasion^2) + (1|ID),data=dt2) fun2 <- function(x) fixef(m2)[1] + fixef(m2)[2]*x + fixef(m2)[3]*(x^2) m3 <- lmer(score~occasion + I(occasion^2) + I(occasion^3) + (1|ID),data=dt2) fun3 <- function(x) fixef(m3)[1] + fixef(m3)[2]*x + fixef(m3)[3]*(x^2) + fixef(m3)[4]*(x^3) p2 <- ggplot(dt2,aes(x=occasion,y=score, color=ID)) + geom_line(size=0.5) + geom_point() p2 + stat_function(fun=fun2, geom="line", size=1, colour="black") Here we see that the quadratic model is an obvious improvement over the linear-only model, but is not ideal because it underestimates the scores for the final measurement, and overestimates it for the previous one. The cubic model on the other hand appears to work very well: p2 + stat_function(fun=fun3, geom="line", size=1, colour="black") A slightly more sophisticated approach is to recognise the upper bound explicity, and use (for example) a logistic growth curve model. One way to accomplish this is to transform the outcome to a proportion (of the upper bound), say $\pi$ and then model the logit of this proportion, $\pi/(1-\pi)$ as the outcome of a linear mixed effects model. In addition to recognising the upper bound, this has the added advantage of modelling heteroscasticity in the residuals of the untransformed data, since it seems likely that over successive tests (assuming that the results get better) there will be less variance. Putting this into practice, as expected, this also models the overall trend in the data very well: pi <- dt2$score/100 dt2$logitpi <- log(pi/(1-pi)) m0 <- lmer(logitpi~occasion+(1|ID),data=dt2) funlogis <- function(x) 100*exp(fixef(m0)[1] + fixef(m0)[2]*x)/(1+exp(fixef(m0)[1] + fixef(m0)[2]*x)) p2 + stat_function(fun=funlogis, geom="line", size=0.5, colour="black") The following shows the cubic mode and the logistic growth models plotted together, and we see very little difference between them, though as mentioned above we may prefer the logistic growth model due to the heteroscedasticity issue: p2 + stat_function(fun=fun3, geom="line", size=1, colour="black") + stat_function(fun=funlogis, geom="line", size=1, colour="blue") A more sophisticated approach still would be to use a nonlinear mixed effects model where the logistic growth curve is modelled explicitly, allowing for random variation in the parameters of the logistic function itself.
Effect of baseline on change over time in mixed models? This seems to be a growth model scenario. Suppose we had the following variables: occasion: taking values 1,2,3,4,5 to reflect the occasion that test was taken, 1 being the first, or baseline. ID: th
31,829
Variance of the integral of a stochastic process
Interchanging the order of integration and expectation you get $$E(I)=E\int_0^L X(t) dt = \int_0^L EX(t) dt = \int_0^L \mu dt = L\mu $$ and similarly, the second moment of $I$ becomes \begin{align} E(I^2)&=E\left(\int_0^LX(t)dt\int_0^LX(u)du\right) \\ &= E \int_0^L \int_0^L X(t)X(u)du dt \\ &= \int_0^L \int_0^L E[X(t)X(u)]du dt \\ &= \int_0^L \int_0^L [\operatorname{Cov}(X(t),X(u))+EX(t)EX(u)] du dt \\ &= \sigma^2 \int_0^L \int_0^L \rho(t-u)dudt + L^2 \mu^2. \end{align} If the correlation function $\rho(h)$ is for example exponential the double intergral can be easily solved. The variance of $I$ can be found from the general formula $\operatorname{Var}I =E(I^2)-(EI)^2$.
Variance of the integral of a stochastic process
Interchanging the order of integration and expectation you get $$E(I)=E\int_0^L X(t) dt = \int_0^L EX(t) dt = \int_0^L \mu dt = L\mu $$ and similarly, the second moment of $I$ becomes \begin{align} E(
Variance of the integral of a stochastic process Interchanging the order of integration and expectation you get $$E(I)=E\int_0^L X(t) dt = \int_0^L EX(t) dt = \int_0^L \mu dt = L\mu $$ and similarly, the second moment of $I$ becomes \begin{align} E(I^2)&=E\left(\int_0^LX(t)dt\int_0^LX(u)du\right) \\ &= E \int_0^L \int_0^L X(t)X(u)du dt \\ &= \int_0^L \int_0^L E[X(t)X(u)]du dt \\ &= \int_0^L \int_0^L [\operatorname{Cov}(X(t),X(u))+EX(t)EX(u)] du dt \\ &= \sigma^2 \int_0^L \int_0^L \rho(t-u)dudt + L^2 \mu^2. \end{align} If the correlation function $\rho(h)$ is for example exponential the double intergral can be easily solved. The variance of $I$ can be found from the general formula $\operatorname{Var}I =E(I^2)-(EI)^2$.
Variance of the integral of a stochastic process Interchanging the order of integration and expectation you get $$E(I)=E\int_0^L X(t) dt = \int_0^L EX(t) dt = \int_0^L \mu dt = L\mu $$ and similarly, the second moment of $I$ becomes \begin{align} E(
31,830
What is the relationship between the function $\mathbb{E}(Y \mid X = x)$ and linear regression?
Summarizing the question: Given $Y = \beta_0 + \beta_1 X + \varepsilon$, is it then a mathematical theorem that $r(X) = \mathbb{E}(Y \mid X) = (\beta_0 + \beta_1 X)$? Yes, by basic properties of expectation: $$ \begin{align} \operatorname{E}(Y\mid X) & = \operatorname{E}(\beta_0 + \beta_1 X + \varepsilon) \\[6pt] & = \operatorname{E}(\beta_0) + \operatorname{E}(\beta_1 X) + \operatorname{E}(\varepsilon) & & \text{(linearity of expectation)} \\[6pt] & = \beta_0 + \beta_1 X + 0 & & \text{(Noting that $X$ is constant here} \\[-2pt] & & & \quad \text{because we conditioned on it.)} \\[6pt] & = \beta_0 + \beta_1 X \end{align} $$ The historical reasons for regression being called regression relate to Galton noticing the "regression to the mean" effect -- initially in an experiment in plants involving seed-size of offspring compared to the seed size of parents. A relationship through the mean seed size on both variables will have slope less than $1$ (which slope can be estimated by what we call linear regression). The smaller the slope the stronger the "regression" effect. The issue is illustrated by Galton in the linked pdf by heights of children (as adults) compared to average heights of parents (females being scaled up by a constant factor of $8\%$ to make them comparable to males). The diagrams on the third to fifth pages indicate something of what was observed. So an attempt to estimate the size of this "regression to the mean" is obtained by what came to be called linear regression. Of course there's nothing special going on - the regression to the mean isn't some special biological "drive to mediocrity" as might originally have been guessed, but a fairly simple consequence of the mathematics of the situation in essentially the same sense that correlations are always between $-1$ and $1$.
What is the relationship between the function $\mathbb{E}(Y \mid X = x)$ and linear regression?
Summarizing the question: Given $Y = \beta_0 + \beta_1 X + \varepsilon$, is it then a mathematical theorem that $r(X) = \mathbb{E}(Y \mid X) = (\beta_0 + \beta_1 X)$? Yes, by basic properties of e
What is the relationship between the function $\mathbb{E}(Y \mid X = x)$ and linear regression? Summarizing the question: Given $Y = \beta_0 + \beta_1 X + \varepsilon$, is it then a mathematical theorem that $r(X) = \mathbb{E}(Y \mid X) = (\beta_0 + \beta_1 X)$? Yes, by basic properties of expectation: $$ \begin{align} \operatorname{E}(Y\mid X) & = \operatorname{E}(\beta_0 + \beta_1 X + \varepsilon) \\[6pt] & = \operatorname{E}(\beta_0) + \operatorname{E}(\beta_1 X) + \operatorname{E}(\varepsilon) & & \text{(linearity of expectation)} \\[6pt] & = \beta_0 + \beta_1 X + 0 & & \text{(Noting that $X$ is constant here} \\[-2pt] & & & \quad \text{because we conditioned on it.)} \\[6pt] & = \beta_0 + \beta_1 X \end{align} $$ The historical reasons for regression being called regression relate to Galton noticing the "regression to the mean" effect -- initially in an experiment in plants involving seed-size of offspring compared to the seed size of parents. A relationship through the mean seed size on both variables will have slope less than $1$ (which slope can be estimated by what we call linear regression). The smaller the slope the stronger the "regression" effect. The issue is illustrated by Galton in the linked pdf by heights of children (as adults) compared to average heights of parents (females being scaled up by a constant factor of $8\%$ to make them comparable to males). The diagrams on the third to fifth pages indicate something of what was observed. So an attempt to estimate the size of this "regression to the mean" is obtained by what came to be called linear regression. Of course there's nothing special going on - the regression to the mean isn't some special biological "drive to mediocrity" as might originally have been guessed, but a fairly simple consequence of the mathematics of the situation in essentially the same sense that correlations are always between $-1$ and $1$.
What is the relationship between the function $\mathbb{E}(Y \mid X = x)$ and linear regression? Summarizing the question: Given $Y = \beta_0 + \beta_1 X + \varepsilon$, is it then a mathematical theorem that $r(X) = \mathbb{E}(Y \mid X) = (\beta_0 + \beta_1 X)$? Yes, by basic properties of e
31,831
Understanding that $\operatorname{COV}(X,X) = \operatorname{VAR}(X)$ intuitively
This post presents a powerful method of reasoning that avoids a great deal of algebra and calculation. To those familiar with this method, the work is so automatic and natural that one's initial response to a question like this is "it's obvious!" But maybe it's not so obvious until you have seen the method. Therefore, all the details are explained, step by step. Background There are several formulas for the variance of data $\mathbf{x}=x_1, x_2, \ldots, x_n$ (with mean $\bar x = (x_1+\cdots + x_n)/n$), including $$\operatorname{Var}(\mathbf{x}) = \frac{1}{n}\sum_{i=1}^n (x_i - \bar x)^2 = \frac{1}{n}\left(\sum_{i=1}^n x_i^2\right) - \bar x^2.\tag{1}$$ This determines the covariance of paired data $(x_1,y_1), \ldots, (x_n, y_n)$ via $$\operatorname{Cov}(\mathbf{x}, \mathbf{y}) = \frac{1}{4}\left(\operatorname{Var}(\mathbf{x}+\mathbf{y}) - \operatorname{Var}(\mathbf{x}-\mathbf{y})\right).$$ The formula implied in the referenced covariance-with-crayons post is $$C(\mathbf{x}, \mathbf{y}) = \sum_{i=1}^{n-1} \sum_{j=i+1}^n (x_j - x_i)(y_j - y_i) = \frac{1}{2}\sum_{i,j=1}^n (x_j - x_i)(y_j - y_i).\tag{2}$$ That post asserts $C$ is proportional to the covariance. The constant of proportionality $c(n)$ could (and does) vary with $n$. Thus, when $\mathbf{x}=\mathbf{y}$ one implication of this assertion is that $$C(\mathbf{x}, \mathbf{x}) = c(n) \operatorname{Var}(\mathbf{x}).$$ Analysis Although this could be demonstrated with brute-force algebra, there's a better way: let's exploit the fundamental properties of covariance. Which properties would those be? I would like to suggest the following are basic: Location independence. That is, $$\operatorname{Cov}(\mathbf{x}, \mathbf{y}) = \operatorname{Cov}(\mathbf{x}-\mathbf{a}, \mathbf{y})$$ for any number $a$. (The expression $\mathbf{x}-\mathbf{a}$ refers to the dataset $x_1-a, x_2-a, \ldots, x_n-a$.) Multilinearity. This implies $$\operatorname{Cov}(\lambda\,\mathbf{x}, \mathbf{y}) = \lambda\,\operatorname{Cov}(\mathbf{x}, \mathbf{y})$$ for any number $\lambda$. (The expression $\lambda\mathbf{x}$ refers to the dataset $\lambda x_1, \lambda x_2, \ldots, \lambda x_n$.) Symmetry. The covariance of $\mathbf{x}$ and $\mathbf{y}$ is the covariance of $\mathbf{y}$ and $\mathbf{x}$: $$\operatorname{Cov}(\mathbf{x}, \mathbf{y}) =\operatorname{Cov}(\mathbf{y}, \mathbf{x}).$$ Invariance under permutations. The covariance does not change when we re-index the $(x_i, y_i)$. Formally, $$\operatorname{Cov}(\mathbf{x}, \mathbf{y}) = \operatorname{Cov}(\mathbf{x}^\sigma, \mathbf{y}^\sigma)$$ for any permutation $\sigma\in\mathfrak{S}_n$. (Expressions like $\mathbf{x}^\sigma$ represent re-ordering the $x_i$ according to $\sigma$, so that $\mathbf{x}^\sigma = x_{\sigma(1)}, x_{\sigma(2)}, \ldots, x_{\sigma(n)}.$) All these properties obviously hold for both $\operatorname{Var}$ and $C$ from inspecting the forms of expressions $(1)$ and $(2)$. The only one that might need any explanation is location independence. However, a constant shift of values of the $x_i$ changes neither the residuals nor the differences: $$x_i - \bar{x} = (x_i - a) - \overline{x - a}$$ and $$x_j - x_i = (x_j - a) - (x_i - a).$$ Consequently, it is indeed obvious that the first version of $(1)$ and $(2)$ are location-independent. Solution Here, then, is the reasoning. Because $C$ is symmetric and multilinear, it is a quadratic form completely determined by coefficients $c_{ij} = c_{ji}$: $$C(\mathbf{x}, \mathbf{y}) = \sum_{i, j=1}^n c_{ij}\, x_i y_j.$$ Because it is permutation-invariant, $c_{ij} = c_{i^\prime j^\prime}$ for any indices $i,j,i^\prime,j^\prime$ for which $i\ne j$ and $i^\prime \ne j^\prime$; also, $c_{ii} = c_{i^\prime i^\prime}$ for all indices $i$ and $i^\prime$. Thus, $C$ is determined by just two numbers, say $c_{11}$ and $c_{12}$. Finally, one of these numbers determines the other two by virtue of the location-invariance: that condition means $$0 = C(\mathbf{0},\mathbf{0}) \overset{\text{location-invariance}}{=} C(\mathbf{1},\mathbf{0}) \overset{\text{symmetry}}{=} C(\mathbf{0},\mathbf{1}) \overset{\text{location-invariance}}{=} C(\mathbf{1},\mathbf{1})$$ (where "$\mathbf{0}$" and "$\mathbf{1}$" refer to constant $n$-vectors with these values). But $$0=C(\mathbf{1},\mathbf{1}) = \sum_{i,j}^n c_{ij} = nc_{11} + (n^2-n)c_{12},$$ determining each of $c_{11}$ and $c_{12}$ in terms of the other. This already proves the main point: $C$ must be proportional to $\operatorname{Cov}$, since each is determined by any single one of their coefficients. To find the constant of proportionality, inspect the two formulas $(1)$ and $(2)$, looking for all appearances of $x_1^2$: you can read off the associated value of $c_{11}$ from them. From the second version of $(1)$, the coefficient of $x_1^2$ clearly is $1/n - (1/n)^2$. From the first version of $(2)$, with $\mathbf{y} = \mathbf{x}$, the coefficient of $x_1^2$ clearly is $n-1$. (Geometrically, each point in the scatterplot of $(\mathbf{x},\mathbf{x})$ is paired with $n-1$ others, whence the square of its coordinate will appear $n-1$ times.) Therefore $$c(n) = \frac{n-1}{1/n - (1/n)^2} = n^2,$$ QED. This was the only calculation required to demonstrate $$\operatorname{Cov}(\mathbf{x}, \mathbf{y}) = \frac{1}{n^2}C(\mathbf{x}, \mathbf{y}) = \frac{1}{n^2}\sum_{i=1}^{n-1} \sum_{j=i+1}^n (x_j - x_i)(y_j - y_i).$$
Understanding that $\operatorname{COV}(X,X) = \operatorname{VAR}(X)$ intuitively
This post presents a powerful method of reasoning that avoids a great deal of algebra and calculation. To those familiar with this method, the work is so automatic and natural that one's initial resp
Understanding that $\operatorname{COV}(X,X) = \operatorname{VAR}(X)$ intuitively This post presents a powerful method of reasoning that avoids a great deal of algebra and calculation. To those familiar with this method, the work is so automatic and natural that one's initial response to a question like this is "it's obvious!" But maybe it's not so obvious until you have seen the method. Therefore, all the details are explained, step by step. Background There are several formulas for the variance of data $\mathbf{x}=x_1, x_2, \ldots, x_n$ (with mean $\bar x = (x_1+\cdots + x_n)/n$), including $$\operatorname{Var}(\mathbf{x}) = \frac{1}{n}\sum_{i=1}^n (x_i - \bar x)^2 = \frac{1}{n}\left(\sum_{i=1}^n x_i^2\right) - \bar x^2.\tag{1}$$ This determines the covariance of paired data $(x_1,y_1), \ldots, (x_n, y_n)$ via $$\operatorname{Cov}(\mathbf{x}, \mathbf{y}) = \frac{1}{4}\left(\operatorname{Var}(\mathbf{x}+\mathbf{y}) - \operatorname{Var}(\mathbf{x}-\mathbf{y})\right).$$ The formula implied in the referenced covariance-with-crayons post is $$C(\mathbf{x}, \mathbf{y}) = \sum_{i=1}^{n-1} \sum_{j=i+1}^n (x_j - x_i)(y_j - y_i) = \frac{1}{2}\sum_{i,j=1}^n (x_j - x_i)(y_j - y_i).\tag{2}$$ That post asserts $C$ is proportional to the covariance. The constant of proportionality $c(n)$ could (and does) vary with $n$. Thus, when $\mathbf{x}=\mathbf{y}$ one implication of this assertion is that $$C(\mathbf{x}, \mathbf{x}) = c(n) \operatorname{Var}(\mathbf{x}).$$ Analysis Although this could be demonstrated with brute-force algebra, there's a better way: let's exploit the fundamental properties of covariance. Which properties would those be? I would like to suggest the following are basic: Location independence. That is, $$\operatorname{Cov}(\mathbf{x}, \mathbf{y}) = \operatorname{Cov}(\mathbf{x}-\mathbf{a}, \mathbf{y})$$ for any number $a$. (The expression $\mathbf{x}-\mathbf{a}$ refers to the dataset $x_1-a, x_2-a, \ldots, x_n-a$.) Multilinearity. This implies $$\operatorname{Cov}(\lambda\,\mathbf{x}, \mathbf{y}) = \lambda\,\operatorname{Cov}(\mathbf{x}, \mathbf{y})$$ for any number $\lambda$. (The expression $\lambda\mathbf{x}$ refers to the dataset $\lambda x_1, \lambda x_2, \ldots, \lambda x_n$.) Symmetry. The covariance of $\mathbf{x}$ and $\mathbf{y}$ is the covariance of $\mathbf{y}$ and $\mathbf{x}$: $$\operatorname{Cov}(\mathbf{x}, \mathbf{y}) =\operatorname{Cov}(\mathbf{y}, \mathbf{x}).$$ Invariance under permutations. The covariance does not change when we re-index the $(x_i, y_i)$. Formally, $$\operatorname{Cov}(\mathbf{x}, \mathbf{y}) = \operatorname{Cov}(\mathbf{x}^\sigma, \mathbf{y}^\sigma)$$ for any permutation $\sigma\in\mathfrak{S}_n$. (Expressions like $\mathbf{x}^\sigma$ represent re-ordering the $x_i$ according to $\sigma$, so that $\mathbf{x}^\sigma = x_{\sigma(1)}, x_{\sigma(2)}, \ldots, x_{\sigma(n)}.$) All these properties obviously hold for both $\operatorname{Var}$ and $C$ from inspecting the forms of expressions $(1)$ and $(2)$. The only one that might need any explanation is location independence. However, a constant shift of values of the $x_i$ changes neither the residuals nor the differences: $$x_i - \bar{x} = (x_i - a) - \overline{x - a}$$ and $$x_j - x_i = (x_j - a) - (x_i - a).$$ Consequently, it is indeed obvious that the first version of $(1)$ and $(2)$ are location-independent. Solution Here, then, is the reasoning. Because $C$ is symmetric and multilinear, it is a quadratic form completely determined by coefficients $c_{ij} = c_{ji}$: $$C(\mathbf{x}, \mathbf{y}) = \sum_{i, j=1}^n c_{ij}\, x_i y_j.$$ Because it is permutation-invariant, $c_{ij} = c_{i^\prime j^\prime}$ for any indices $i,j,i^\prime,j^\prime$ for which $i\ne j$ and $i^\prime \ne j^\prime$; also, $c_{ii} = c_{i^\prime i^\prime}$ for all indices $i$ and $i^\prime$. Thus, $C$ is determined by just two numbers, say $c_{11}$ and $c_{12}$. Finally, one of these numbers determines the other two by virtue of the location-invariance: that condition means $$0 = C(\mathbf{0},\mathbf{0}) \overset{\text{location-invariance}}{=} C(\mathbf{1},\mathbf{0}) \overset{\text{symmetry}}{=} C(\mathbf{0},\mathbf{1}) \overset{\text{location-invariance}}{=} C(\mathbf{1},\mathbf{1})$$ (where "$\mathbf{0}$" and "$\mathbf{1}$" refer to constant $n$-vectors with these values). But $$0=C(\mathbf{1},\mathbf{1}) = \sum_{i,j}^n c_{ij} = nc_{11} + (n^2-n)c_{12},$$ determining each of $c_{11}$ and $c_{12}$ in terms of the other. This already proves the main point: $C$ must be proportional to $\operatorname{Cov}$, since each is determined by any single one of their coefficients. To find the constant of proportionality, inspect the two formulas $(1)$ and $(2)$, looking for all appearances of $x_1^2$: you can read off the associated value of $c_{11}$ from them. From the second version of $(1)$, the coefficient of $x_1^2$ clearly is $1/n - (1/n)^2$. From the first version of $(2)$, with $\mathbf{y} = \mathbf{x}$, the coefficient of $x_1^2$ clearly is $n-1$. (Geometrically, each point in the scatterplot of $(\mathbf{x},\mathbf{x})$ is paired with $n-1$ others, whence the square of its coordinate will appear $n-1$ times.) Therefore $$c(n) = \frac{n-1}{1/n - (1/n)^2} = n^2,$$ QED. This was the only calculation required to demonstrate $$\operatorname{Cov}(\mathbf{x}, \mathbf{y}) = \frac{1}{n^2}C(\mathbf{x}, \mathbf{y}) = \frac{1}{n^2}\sum_{i=1}^{n-1} \sum_{j=i+1}^n (x_j - x_i)(y_j - y_i).$$
Understanding that $\operatorname{COV}(X,X) = \operatorname{VAR}(X)$ intuitively This post presents a powerful method of reasoning that avoids a great deal of algebra and calculation. To those familiar with this method, the work is so automatic and natural that one's initial resp
31,832
What is the point of dividing data into training and test parts to assess prediction properties when we have AIC?
In practice, I always use cross-validation or a simple train–test split rather than AIC (or BIC). I'm not too familiar with the theory behind AIC, but two chief concerns lead me to prefer more direct estimates of predictive accuracy: The number itself doesn't tell you much about how accurate a model is. AIC can provide evidence as to which of several models is the most accurate, but it doesn't tell you how accurate the model is in units of the DV. I'm almost always interested in concrete accuracy estimates of this kind, because it tells me how useful a model is in absolute terms, and also how much more accurate it is than a comparison model. AIC, like BIC, needs for each model a parameter count or some other value that measures the model's complexity. It isn't clear what you should do for this in the case of less traditional predictive methods like nearest-neighbor classification, random forests, or the wacky new ensemble method you scribbled onto a cocktail napkin midway through last month's bender. By contrast, accuracy estimates can be produced for any predictive model, and in the same way.
What is the point of dividing data into training and test parts to assess prediction properties when
In practice, I always use cross-validation or a simple train–test split rather than AIC (or BIC). I'm not too familiar with the theory behind AIC, but two chief concerns lead me to prefer more direct
What is the point of dividing data into training and test parts to assess prediction properties when we have AIC? In practice, I always use cross-validation or a simple train–test split rather than AIC (or BIC). I'm not too familiar with the theory behind AIC, but two chief concerns lead me to prefer more direct estimates of predictive accuracy: The number itself doesn't tell you much about how accurate a model is. AIC can provide evidence as to which of several models is the most accurate, but it doesn't tell you how accurate the model is in units of the DV. I'm almost always interested in concrete accuracy estimates of this kind, because it tells me how useful a model is in absolute terms, and also how much more accurate it is than a comparison model. AIC, like BIC, needs for each model a parameter count or some other value that measures the model's complexity. It isn't clear what you should do for this in the case of less traditional predictive methods like nearest-neighbor classification, random forests, or the wacky new ensemble method you scribbled onto a cocktail napkin midway through last month's bender. By contrast, accuracy estimates can be produced for any predictive model, and in the same way.
What is the point of dividing data into training and test parts to assess prediction properties when In practice, I always use cross-validation or a simple train–test split rather than AIC (or BIC). I'm not too familiar with the theory behind AIC, but two chief concerns lead me to prefer more direct
31,833
Using the drop1 command in R and AIC
The given AIC from drop1 relates to the whole model - not to a variable, so the output tells you which variable to remove in order to yield the model with the lowest AIC. For example, with the built-in dataset swiss lm1 <- lm(Fertility ~ ., data = swiss) drop1(lm1, test = "F") # So called 'type II' anova Single term deletions Model: Fertility ~ Agriculture + Examination + Education + Catholic + Infant.Mortality Df Sum of Sq RSS AIC F value Pr(>F) <none> 2105.0 190.69 Agriculture 1 307.72 2412.8 195.10 5.9934 0.018727 * Examination 1 53.03 2158.1 189.86 1.0328 0.315462 Education 1 1162.56 3267.6 209.36 22.6432 2.431e-05 *** Catholic 1 447.71 2552.8 197.75 8.7200 0.005190 ** Infant.Mortality 1 408.75 2513.8 197.03 7.9612 0.007336 ** --- Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 Here, the removal of Examination will yield the model with the lowest AIC On a related note, while it may be better to use AIC than p values, it is considered bad practice to use any automatic model selection algorithms: Algorithms for automatic model selection
Using the drop1 command in R and AIC
The given AIC from drop1 relates to the whole model - not to a variable, so the output tells you which variable to remove in order to yield the model with the lowest AIC. For example, with the built-i
Using the drop1 command in R and AIC The given AIC from drop1 relates to the whole model - not to a variable, so the output tells you which variable to remove in order to yield the model with the lowest AIC. For example, with the built-in dataset swiss lm1 <- lm(Fertility ~ ., data = swiss) drop1(lm1, test = "F") # So called 'type II' anova Single term deletions Model: Fertility ~ Agriculture + Examination + Education + Catholic + Infant.Mortality Df Sum of Sq RSS AIC F value Pr(>F) <none> 2105.0 190.69 Agriculture 1 307.72 2412.8 195.10 5.9934 0.018727 * Examination 1 53.03 2158.1 189.86 1.0328 0.315462 Education 1 1162.56 3267.6 209.36 22.6432 2.431e-05 *** Catholic 1 447.71 2552.8 197.75 8.7200 0.005190 ** Infant.Mortality 1 408.75 2513.8 197.03 7.9612 0.007336 ** --- Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 Here, the removal of Examination will yield the model with the lowest AIC On a related note, while it may be better to use AIC than p values, it is considered bad practice to use any automatic model selection algorithms: Algorithms for automatic model selection
Using the drop1 command in R and AIC The given AIC from drop1 relates to the whole model - not to a variable, so the output tells you which variable to remove in order to yield the model with the lowest AIC. For example, with the built-i
31,834
Normal Distribution Existence Non-affine Invariant Transformation?
There are a huge number of non-affine transformations that will preserve normality of a variable. For ease of exposition, let's focus on the one-dimensional case with a normal random variable $X$ with distribution function $F$. Note that the question can be reduced to the analogous situation for a uniform variate by means of the probability integral transform $$U = F^{-1}(X).$$ Any measurable function $\phi:[0,1]\to [0,1]$ that preserves probability induces a probability-preserving transformation of $X$ via $$\phi^F: X \to F(\phi(F^{-1}(X))).$$ Such functions $\phi$ may be incredibly complex. To illustrate, I will focus on those that are linear, with slope $1$, at all but finitely many points. Examples can be constructed by choosing any positive integer $n$, carving the interval $[0,1)$ into $n$ equal intervals $I_i = [(i-1)/n, i/n)$ for $i=1, 2, \ldots, n$, and applying an arbitrary permutation $\sigma$ to those intervals. Any $t\in[0,1)$ lies uniquely in the interval with index $i = 1 + \lfloor t/n \rfloor$. For $t \in[0, 1)$, define $$\phi_\sigma(t) = t - \frac{i-1}{n} + \frac{\sigma(i)-1}{n} = t + \frac{\sigma(i) - i}{n}$$ and otherwise let $\phi_\sigma(t)=t$. $\phi$ may be discontinuous at the values $0, 1/n, 2/n, \ldots, (n-1)/n, 1$, but otherwise obviously is linear with unit slope on $[0,1]$. That implies it preserves probabilities: that is, for any measurable set $E \subset [0, 1)$, $$\Pr(U \in E) = \int_E du = \int_{\phi(E)} |D\phi(u)|^{-1} du = \int_{\phi(E)} du = \Pr(U \in \phi(E)).$$ Moreover, $\phi$ is invertible, with inverse $\phi_\sigma^{-1} = \phi_{\sigma^{-1}}$. Here is the graph of a $\phi_\sigma$ for $n=7$: Here are examples of $\phi^F$ for $n=3, 10, 31, 100$. Each example shows the graph of a one-to-one function for which $\phi(X)$ also has a standard Normal distribution. Obviously none of these are affine. The only special property of $F$ that was used in these examples was that it is the distribution function of a continuous variable. Thus, this same construction gives many non-affine transformations that will map a variable $X$ with any given continuous distribution into another variable that is identically distributed. These are by no means the only examples of such probability-preserving non-affine transformations, but they do form a family that is sufficiently rich to construct examples of arbitrary complexity.
Normal Distribution Existence Non-affine Invariant Transformation?
There are a huge number of non-affine transformations that will preserve normality of a variable. For ease of exposition, let's focus on the one-dimensional case with a normal random variable $X$ with
Normal Distribution Existence Non-affine Invariant Transformation? There are a huge number of non-affine transformations that will preserve normality of a variable. For ease of exposition, let's focus on the one-dimensional case with a normal random variable $X$ with distribution function $F$. Note that the question can be reduced to the analogous situation for a uniform variate by means of the probability integral transform $$U = F^{-1}(X).$$ Any measurable function $\phi:[0,1]\to [0,1]$ that preserves probability induces a probability-preserving transformation of $X$ via $$\phi^F: X \to F(\phi(F^{-1}(X))).$$ Such functions $\phi$ may be incredibly complex. To illustrate, I will focus on those that are linear, with slope $1$, at all but finitely many points. Examples can be constructed by choosing any positive integer $n$, carving the interval $[0,1)$ into $n$ equal intervals $I_i = [(i-1)/n, i/n)$ for $i=1, 2, \ldots, n$, and applying an arbitrary permutation $\sigma$ to those intervals. Any $t\in[0,1)$ lies uniquely in the interval with index $i = 1 + \lfloor t/n \rfloor$. For $t \in[0, 1)$, define $$\phi_\sigma(t) = t - \frac{i-1}{n} + \frac{\sigma(i)-1}{n} = t + \frac{\sigma(i) - i}{n}$$ and otherwise let $\phi_\sigma(t)=t$. $\phi$ may be discontinuous at the values $0, 1/n, 2/n, \ldots, (n-1)/n, 1$, but otherwise obviously is linear with unit slope on $[0,1]$. That implies it preserves probabilities: that is, for any measurable set $E \subset [0, 1)$, $$\Pr(U \in E) = \int_E du = \int_{\phi(E)} |D\phi(u)|^{-1} du = \int_{\phi(E)} du = \Pr(U \in \phi(E)).$$ Moreover, $\phi$ is invertible, with inverse $\phi_\sigma^{-1} = \phi_{\sigma^{-1}}$. Here is the graph of a $\phi_\sigma$ for $n=7$: Here are examples of $\phi^F$ for $n=3, 10, 31, 100$. Each example shows the graph of a one-to-one function for which $\phi(X)$ also has a standard Normal distribution. Obviously none of these are affine. The only special property of $F$ that was used in these examples was that it is the distribution function of a continuous variable. Thus, this same construction gives many non-affine transformations that will map a variable $X$ with any given continuous distribution into another variable that is identically distributed. These are by no means the only examples of such probability-preserving non-affine transformations, but they do form a family that is sufficiently rich to construct examples of arbitrary complexity.
Normal Distribution Existence Non-affine Invariant Transformation? There are a huge number of non-affine transformations that will preserve normality of a variable. For ease of exposition, let's focus on the one-dimensional case with a normal random variable $X$ with
31,835
Bad Controls and Omitted Variables
There is no reason to wonder whether a variable is a "bad control" anymore. We have simple graphical criteria for deciding whether a variable should be included in the regression equation given your target query and your model. If, for instance, you want to estimate the average causal effect via regression adjustment, "good controls" are characterized by the backdoor criterion. For instance, let me show an example where your case 2 would also be problematic. Consider the model below, where all disturbances $u$ are mutually independent standard gaussian random variables: $$ z = u_1 + u_2 + u_z\\ x = u_1 + u_x\\ y = x + u_2 + u_y $$ Note that $z$ is correlated both with $x$ and $y$, and $z$ is not an "outcome" (it is a pretreatment variable). Yet, $z$ is "bad control" here, and adjusting for $z$ will bias your effect estimates. This happens because adjusting for $z$ opens a spurious colliding path $x \leftarrow u_1 \rightarrow z \leftarrow u_2 \rightarrow y$. Here is a simple R code for you to see this in practice: n <- 1e5 u1 <- rnorm(n) u2 <- rnorm(n) z <- u1 + u2 + rnorm(n) x <- u1 + rnorm(n) y <- x - 2*u2 + rnorm(n) lm(y ~ x) # unbiased #> #> Call: #> lm(formula = y ~ x) #> #> Coefficients: #> (Intercept) x #> -0.002443 0.996894 lm(y ~ x + z) # biased, bad control #> #> Call: #> lm(formula = y ~ x + z) #> #> Coefficients: #> (Intercept) x z #> -0.0009577 1.3976798 -0.8012717 Another interesting example is the following: Again, here $z$ is a pre-treatment variable. But, if you naively "control" for $z$ this will amplify any existing bias. In this case, it turns out you can't obtain an unbiased estimate via adjustment, but you could recover the causal effect using instrumental variables. Here is some R code for you to see this in practice: n <- 1e5 z <- rnorm(n) u <- rnorm(n) x <- 2*z + u + rnorm(n) y <- x + u + rnorm(n) lm(y ~ x) # biased #> #> Call: #> lm(formula = y ~ x) #> #> Coefficients: #> (Intercept) x #> 0.00338 1.16838 lm(y ~ x + z) # even more biased #> #> Call: #> lm(formula = y ~ x + z) #> #> Coefficients: #> (Intercept) x z #> 0.002855 1.495812 -0.985012 This discussion may also be helpful.
Bad Controls and Omitted Variables
There is no reason to wonder whether a variable is a "bad control" anymore. We have simple graphical criteria for deciding whether a variable should be included in the regression equation given your t
Bad Controls and Omitted Variables There is no reason to wonder whether a variable is a "bad control" anymore. We have simple graphical criteria for deciding whether a variable should be included in the regression equation given your target query and your model. If, for instance, you want to estimate the average causal effect via regression adjustment, "good controls" are characterized by the backdoor criterion. For instance, let me show an example where your case 2 would also be problematic. Consider the model below, where all disturbances $u$ are mutually independent standard gaussian random variables: $$ z = u_1 + u_2 + u_z\\ x = u_1 + u_x\\ y = x + u_2 + u_y $$ Note that $z$ is correlated both with $x$ and $y$, and $z$ is not an "outcome" (it is a pretreatment variable). Yet, $z$ is "bad control" here, and adjusting for $z$ will bias your effect estimates. This happens because adjusting for $z$ opens a spurious colliding path $x \leftarrow u_1 \rightarrow z \leftarrow u_2 \rightarrow y$. Here is a simple R code for you to see this in practice: n <- 1e5 u1 <- rnorm(n) u2 <- rnorm(n) z <- u1 + u2 + rnorm(n) x <- u1 + rnorm(n) y <- x - 2*u2 + rnorm(n) lm(y ~ x) # unbiased #> #> Call: #> lm(formula = y ~ x) #> #> Coefficients: #> (Intercept) x #> -0.002443 0.996894 lm(y ~ x + z) # biased, bad control #> #> Call: #> lm(formula = y ~ x + z) #> #> Coefficients: #> (Intercept) x z #> -0.0009577 1.3976798 -0.8012717 Another interesting example is the following: Again, here $z$ is a pre-treatment variable. But, if you naively "control" for $z$ this will amplify any existing bias. In this case, it turns out you can't obtain an unbiased estimate via adjustment, but you could recover the causal effect using instrumental variables. Here is some R code for you to see this in practice: n <- 1e5 z <- rnorm(n) u <- rnorm(n) x <- 2*z + u + rnorm(n) y <- x + u + rnorm(n) lm(y ~ x) # biased #> #> Call: #> lm(formula = y ~ x) #> #> Coefficients: #> (Intercept) x #> 0.00338 1.16838 lm(y ~ x + z) # even more biased #> #> Call: #> lm(formula = y ~ x + z) #> #> Coefficients: #> (Intercept) x z #> 0.002855 1.495812 -0.985012 This discussion may also be helpful.
Bad Controls and Omitted Variables There is no reason to wonder whether a variable is a "bad control" anymore. We have simple graphical criteria for deciding whether a variable should be included in the regression equation given your t
31,836
How to understand the geometric intuition of the inner workings of neural networks?
There are two great recent articles on some of the geometric properties of deep neural networks with piecewise linear nonlinearities (which would include the ReLU activation): On the Number of Linear Regions of Deep Neural Networks by Montufar, Pascanu, Cho and Bengio. On the number of response regions of deep feed forward networks with piece-wise linear activations by Pascanu, Montufar and Bengio. They provide some badly needed theory and rigor when it comes to neural networks. Their analysis centers around the idea that: deep networks are able to separate their input space into exponentially more linear response regions than their shallow counterparts, despite using the same number of computational units. Thus we may interpret deep neural networks with piecewise linear activations as partitioning the input space into a bunch of regions, and over each region is some linear hypersurface. In the graphic you have referenced, notice that the various (x,y)-regions have linear hypersurfaces over them (seemingly either slanted planes or flat planes). So we see the hypothesis from the above two articles in action in your referenced graphics. Furthermore they state (emphasis from the co-authors): deep networks are able to identify an exponential number of input neighborhoods by mapping them to a common output of some intermediary hidden layer. The computations carried out on the activations of this intermediary layer are replicated many times, once in each of the identified neighborhoods. This allows the networks to compute very complex looking functions even when they are defined with relatively few parameters. Basically this is the mechanism that allows deep networks to have incredibly robust and diverse feature representations despite having a fewer number of parameters than their shallow counterparts. In particular, the deep neural networks can learn an exponential number of these linear regions. Take for example, Theorem 8 from the first referenced paper, which states: Theorem 8: A maxout network with $L$ layers of width $n_0$ and rank $k$ can compute functions with at least $k^{L-1}k^{n_0}$ linear regions. This is again for deep neural networks with piecewise linear activations, like ReLUs for example. If you used sigmoid-like activations, you would have smoother sinusoidal looking hypersurfaces. A lot of researchers now use ReLUs or some variation of ReLUs (leaky ReLUs, PReLUs, ELUs, RReLUs, the list goes on) because their piecewise linear structure allows for better gradient backpropagation vs the sigmoidal-units which can saturate (have very flat/asymptotic regions) and effectively kill gradients. This exponentiality result is crucial, otherwise the piecewise linearity might not be able to efficiently represent the types of nonlinear functions we must learn when it comes to computer vision or other hard machine learning tasks. However, we do have this exponentiality result and therefore these deep networks can (in theory) learn all sorts of nonlinearities by approximating them with a huge number of linear regions. As for your question about the hypersurface: you can absolutely setup a regression problem where your deep net tries to learn the $y = f(x_1, x_2)$ hypersurface. This is tantamount to just using a deep net to setup a regression problem, many deep learning packages can do this, no problem. If you want to just test your intuition, there's a lot of great deep learning packages available these days: Theano (Lasagne, No Learn and Keras built on top of it), TensorFlow, a bunch of others I'm sure I'm leaving out. These deep learning packages will compute the backpropagation for you. However, for a smaller scale problem like the one you mentioned it really is a good idea to code up the backpropagation yourself, just to do it once, and learn how to gradient check it. But like I said, if you just want to try it out and visualize it, you can get started pretty quickly with these deep learning packages. If one is able to properly train the network (we use enough data points, initialize it properly, training goes well, this is its own whole other issue to be frank), then one way to visualize what our network has learned, in this case, a hypersurface, is to just graph our hypersurface over an xy-mesh or grid and visualize it. If the above intuition is correct, then using deep nets with ReLUs, our deep net will have learned an exponential number of regions, each region having its own linear hypersurface. Of course, the whole point is that because we have exponentially many, the linear approximations can become so fine and we do not perceive the jagged-ness of it all, given that we used a deep/large enough network.
How to understand the geometric intuition of the inner workings of neural networks?
There are two great recent articles on some of the geometric properties of deep neural networks with piecewise linear nonlinearities (which would include the ReLU activation): On the Number of Linear
How to understand the geometric intuition of the inner workings of neural networks? There are two great recent articles on some of the geometric properties of deep neural networks with piecewise linear nonlinearities (which would include the ReLU activation): On the Number of Linear Regions of Deep Neural Networks by Montufar, Pascanu, Cho and Bengio. On the number of response regions of deep feed forward networks with piece-wise linear activations by Pascanu, Montufar and Bengio. They provide some badly needed theory and rigor when it comes to neural networks. Their analysis centers around the idea that: deep networks are able to separate their input space into exponentially more linear response regions than their shallow counterparts, despite using the same number of computational units. Thus we may interpret deep neural networks with piecewise linear activations as partitioning the input space into a bunch of regions, and over each region is some linear hypersurface. In the graphic you have referenced, notice that the various (x,y)-regions have linear hypersurfaces over them (seemingly either slanted planes or flat planes). So we see the hypothesis from the above two articles in action in your referenced graphics. Furthermore they state (emphasis from the co-authors): deep networks are able to identify an exponential number of input neighborhoods by mapping them to a common output of some intermediary hidden layer. The computations carried out on the activations of this intermediary layer are replicated many times, once in each of the identified neighborhoods. This allows the networks to compute very complex looking functions even when they are defined with relatively few parameters. Basically this is the mechanism that allows deep networks to have incredibly robust and diverse feature representations despite having a fewer number of parameters than their shallow counterparts. In particular, the deep neural networks can learn an exponential number of these linear regions. Take for example, Theorem 8 from the first referenced paper, which states: Theorem 8: A maxout network with $L$ layers of width $n_0$ and rank $k$ can compute functions with at least $k^{L-1}k^{n_0}$ linear regions. This is again for deep neural networks with piecewise linear activations, like ReLUs for example. If you used sigmoid-like activations, you would have smoother sinusoidal looking hypersurfaces. A lot of researchers now use ReLUs or some variation of ReLUs (leaky ReLUs, PReLUs, ELUs, RReLUs, the list goes on) because their piecewise linear structure allows for better gradient backpropagation vs the sigmoidal-units which can saturate (have very flat/asymptotic regions) and effectively kill gradients. This exponentiality result is crucial, otherwise the piecewise linearity might not be able to efficiently represent the types of nonlinear functions we must learn when it comes to computer vision or other hard machine learning tasks. However, we do have this exponentiality result and therefore these deep networks can (in theory) learn all sorts of nonlinearities by approximating them with a huge number of linear regions. As for your question about the hypersurface: you can absolutely setup a regression problem where your deep net tries to learn the $y = f(x_1, x_2)$ hypersurface. This is tantamount to just using a deep net to setup a regression problem, many deep learning packages can do this, no problem. If you want to just test your intuition, there's a lot of great deep learning packages available these days: Theano (Lasagne, No Learn and Keras built on top of it), TensorFlow, a bunch of others I'm sure I'm leaving out. These deep learning packages will compute the backpropagation for you. However, for a smaller scale problem like the one you mentioned it really is a good idea to code up the backpropagation yourself, just to do it once, and learn how to gradient check it. But like I said, if you just want to try it out and visualize it, you can get started pretty quickly with these deep learning packages. If one is able to properly train the network (we use enough data points, initialize it properly, training goes well, this is its own whole other issue to be frank), then one way to visualize what our network has learned, in this case, a hypersurface, is to just graph our hypersurface over an xy-mesh or grid and visualize it. If the above intuition is correct, then using deep nets with ReLUs, our deep net will have learned an exponential number of regions, each region having its own linear hypersurface. Of course, the whole point is that because we have exponentially many, the linear approximations can become so fine and we do not perceive the jagged-ness of it all, given that we used a deep/large enough network.
How to understand the geometric intuition of the inner workings of neural networks? There are two great recent articles on some of the geometric properties of deep neural networks with piecewise linear nonlinearities (which would include the ReLU activation): On the Number of Linear
31,837
Why ever use F-statistic?
Here I assume you intend to compare some test based on the minimum p-value with an overall F-test. By choosing the smallest p-value and comparing with some particular significance level $\alpha$, your p-value no longer has the same meaning as it would do for a single test. In effect you're testing all individual variables (and if any lead to rejection, you conclude at least one of the predictors has an effect on the response). The overall type I error rate is much higher than a single test. (The multiple testing problem.) If you reduce your significance level on the individual tests, so you make fewer type I errors (to make it more comparable with the overall test at significance level $\alpha$), you're less likely to find a significant effect (you give up power by reducing the type I error rate). Even if you don't account for the multiple testing by shifting the significance level, the univariate statistics can easily all be insignificant when there's a clear joint relationship involving both of them. Here's an example. First, some data: y: 4.941, 4.459, 4.116, 3.759, 5.171, 5.101, 5.454, 5.277, 5.402, 4.68, 3.433, 5.508, 4.122, 3.355, 3.622, 4.45, 4.872, 4.202, 5.276, 4.415, 5.311, 4.105, 3.282, 4.152, 5.416, 4.615, 3.804, 5.299, 4.603, 4.868 x1: 42.305, 16.828, 46.515, 32.567, 40.827, 45.755, 34.227, 43.799, 54.659, 34.991, 15.134, 29.115, 20.617, 1.252, 25.844, 19.563, 21.53, 22.989, 38.993, 44.955, 30.799, 32.639, 8.707, 46.945, 38.992, 25.717, 40.875, 26.049, 36.121, 39.868 x2: 24.279, 8.844, 27.888, 19.099, 23.732, 28.648, 19.26, 26.578, 32.764, 21.302, 8.583, 17.026, 12.047, 0.085, 16.636, 10.021, 12.487, 13.745, 23.557, 26.67, 19.881, 20.23, 4.377, 27.865, 23.359, 15.006, 25.909, 14.772, 21.5, 23.002 Regression output (from R:) Coefficients: Estimate Std. Error t value Pr(>|t|) (Intercept) 3.47760 0.32703 10.634 3.74e-11 x1 0.14999 0.09194 1.631 0.114 x2 -0.19524 0.14741 -1.324 0.196 --- Residual standard error: 0.5884 on 27 degrees of freedom Multiple R-squared: 0.3167, Adjusted R-squared: 0.2661 F-statistic: 6.257 on 2 and 27 DF, p-value: 0.005851 The smallest p-value is 0.114 -- you wouldn't have rejected the null hypothesis of no association even at the 10% significance level, but the overall regression would lead to rejection even if your significance level were 1%. This is without even dealing with the multiple testing problem. It's also no help to run separate regressions and check p-values there, because (in a different sort of example to the one above) its quite possible for the to be no relationship in the univariate regressions while there's a strong relationship in the bivariate regression.
Why ever use F-statistic?
Here I assume you intend to compare some test based on the minimum p-value with an overall F-test. By choosing the smallest p-value and comparing with some particular significance level $\alpha$, you
Why ever use F-statistic? Here I assume you intend to compare some test based on the minimum p-value with an overall F-test. By choosing the smallest p-value and comparing with some particular significance level $\alpha$, your p-value no longer has the same meaning as it would do for a single test. In effect you're testing all individual variables (and if any lead to rejection, you conclude at least one of the predictors has an effect on the response). The overall type I error rate is much higher than a single test. (The multiple testing problem.) If you reduce your significance level on the individual tests, so you make fewer type I errors (to make it more comparable with the overall test at significance level $\alpha$), you're less likely to find a significant effect (you give up power by reducing the type I error rate). Even if you don't account for the multiple testing by shifting the significance level, the univariate statistics can easily all be insignificant when there's a clear joint relationship involving both of them. Here's an example. First, some data: y: 4.941, 4.459, 4.116, 3.759, 5.171, 5.101, 5.454, 5.277, 5.402, 4.68, 3.433, 5.508, 4.122, 3.355, 3.622, 4.45, 4.872, 4.202, 5.276, 4.415, 5.311, 4.105, 3.282, 4.152, 5.416, 4.615, 3.804, 5.299, 4.603, 4.868 x1: 42.305, 16.828, 46.515, 32.567, 40.827, 45.755, 34.227, 43.799, 54.659, 34.991, 15.134, 29.115, 20.617, 1.252, 25.844, 19.563, 21.53, 22.989, 38.993, 44.955, 30.799, 32.639, 8.707, 46.945, 38.992, 25.717, 40.875, 26.049, 36.121, 39.868 x2: 24.279, 8.844, 27.888, 19.099, 23.732, 28.648, 19.26, 26.578, 32.764, 21.302, 8.583, 17.026, 12.047, 0.085, 16.636, 10.021, 12.487, 13.745, 23.557, 26.67, 19.881, 20.23, 4.377, 27.865, 23.359, 15.006, 25.909, 14.772, 21.5, 23.002 Regression output (from R:) Coefficients: Estimate Std. Error t value Pr(>|t|) (Intercept) 3.47760 0.32703 10.634 3.74e-11 x1 0.14999 0.09194 1.631 0.114 x2 -0.19524 0.14741 -1.324 0.196 --- Residual standard error: 0.5884 on 27 degrees of freedom Multiple R-squared: 0.3167, Adjusted R-squared: 0.2661 F-statistic: 6.257 on 2 and 27 DF, p-value: 0.005851 The smallest p-value is 0.114 -- you wouldn't have rejected the null hypothesis of no association even at the 10% significance level, but the overall regression would lead to rejection even if your significance level were 1%. This is without even dealing with the multiple testing problem. It's also no help to run separate regressions and check p-values there, because (in a different sort of example to the one above) its quite possible for the to be no relationship in the univariate regressions while there's a strong relationship in the bivariate regression.
Why ever use F-statistic? Here I assume you intend to compare some test based on the minimum p-value with an overall F-test. By choosing the smallest p-value and comparing with some particular significance level $\alpha$, you
31,838
Statistical Independence in the real world
It seems to me that the author assumes that most scientists don't know about or understand how to deal with correlation and assumes almost that the use of methods to handle correlated data doesn't exist (perhaps outside of Makov Chains). That's not the case. There are many statistical methods that account for correlated data and most statisticians, epidemiologists, ecologists, and other scientists know (or should) when to use the appropriate methods. I don't think scientists need to abandon methods that assume independence as they are quite useful -- if they weren't simulations and real-world experiments which have demonstrated their usefulness would not abound. Instead, if anything, scientists need better training or education to understand when to use methods that account for correlation and when to use methods that require assumptions of independence. That's just my two cents.
Statistical Independence in the real world
It seems to me that the author assumes that most scientists don't know about or understand how to deal with correlation and assumes almost that the use of methods to handle correlated data doesn't exi
Statistical Independence in the real world It seems to me that the author assumes that most scientists don't know about or understand how to deal with correlation and assumes almost that the use of methods to handle correlated data doesn't exist (perhaps outside of Makov Chains). That's not the case. There are many statistical methods that account for correlated data and most statisticians, epidemiologists, ecologists, and other scientists know (or should) when to use the appropriate methods. I don't think scientists need to abandon methods that assume independence as they are quite useful -- if they weren't simulations and real-world experiments which have demonstrated their usefulness would not abound. Instead, if anything, scientists need better training or education to understand when to use methods that account for correlation and when to use methods that require assumptions of independence. That's just my two cents.
Statistical Independence in the real world It seems to me that the author assumes that most scientists don't know about or understand how to deal with correlation and assumes almost that the use of methods to handle correlated data doesn't exi
31,839
Statistical Independence in the real world
I don't subscribe to the author's view at all. In particular from my experience it is absolutely not the case that "[..] the overwhelming common practice is simply to assume that sampled events are independent". On the contrary, the issue of correlation is something we have to deal with on a regular basis (during my work in the financial industry). And, mostly important, we are clearly aware of this! I totally agree, though, with the statements on simplifying the real world. For me the famous words attributed to George Box are the leading guide here: All models are wrong; some models are useful.
Statistical Independence in the real world
I don't subscribe to the author's view at all. In particular from my experience it is absolutely not the case that "[..] the overwhelming common practice is simply to assume that sampled events are in
Statistical Independence in the real world I don't subscribe to the author's view at all. In particular from my experience it is absolutely not the case that "[..] the overwhelming common practice is simply to assume that sampled events are independent". On the contrary, the issue of correlation is something we have to deal with on a regular basis (during my work in the financial industry). And, mostly important, we are clearly aware of this! I totally agree, though, with the statements on simplifying the real world. For me the famous words attributed to George Box are the leading guide here: All models are wrong; some models are useful.
Statistical Independence in the real world I don't subscribe to the author's view at all. In particular from my experience it is absolutely not the case that "[..] the overwhelming common practice is simply to assume that sampled events are in
31,840
Statistical Independence in the real world
Of course the notion of statistical independence as has been popularly preached till now, is pretty much a myth (most of it). I don't think so anybody should disagree that the universe and everything inside it, works in conjunction with everything else. In fact as far as statistical independence goes, its only in the datasets or kind of, it exists in very specific terms. But in general, dependency is an integral part of the universe.
Statistical Independence in the real world
Of course the notion of statistical independence as has been popularly preached till now, is pretty much a myth (most of it). I don't think so anybody should disagree that the universe and everything
Statistical Independence in the real world Of course the notion of statistical independence as has been popularly preached till now, is pretty much a myth (most of it). I don't think so anybody should disagree that the universe and everything inside it, works in conjunction with everything else. In fact as far as statistical independence goes, its only in the datasets or kind of, it exists in very specific terms. But in general, dependency is an integral part of the universe.
Statistical Independence in the real world Of course the notion of statistical independence as has been popularly preached till now, is pretty much a myth (most of it). I don't think so anybody should disagree that the universe and everything
31,841
Effective degrees of freedom
If $H$ is such that $\hat y = H y$, then it would be quite standard to obtain the effective degrees of freedom from $\text{tr}(H)$. See Hastie and Tibshirani's Generalized Additive Models, and there's a similar treatment in Hastie et al Elements of Statistical Learning (2nd ed) in chapter 5 (In the section on Degrees of Freedom and Smoother Matrices). The discussion in in that section of ESL II is on effective degrees of freedom in smoothing splines but as they say there (where they're specifically discussing such a definition of generalized degrees of freedom given in eq 5.16) "This very useful definition allows us a more intuitive way to parameterize the smoothing spline, and indeed many other smoothers as well, in a consistent fashion"; they then mention that there are many possible justifications for this and they go on to give some of the possible justifications. See also equation 7.6 and the nearby text. Considerably more broadly, look at Ye (1998) "On Measuring and Correcting the Effects of Data Mining and Model Selection", JASA 93(441):120-131 where the author proposes using $\sum_i \frac{\partial \hat{y}_i}{\partial y_i}$ as the degrees of freedom for a huge variety of models for which you can take a set of data $y$ and compute a $\hat{y}$. For a model which can be written in hat-matrix form $\hat y = H y$, that's the trace of $H$.
Effective degrees of freedom
If $H$ is such that $\hat y = H y$, then it would be quite standard to obtain the effective degrees of freedom from $\text{tr}(H)$. See Hastie and Tibshirani's Generalized Additive Models, and there's
Effective degrees of freedom If $H$ is such that $\hat y = H y$, then it would be quite standard to obtain the effective degrees of freedom from $\text{tr}(H)$. See Hastie and Tibshirani's Generalized Additive Models, and there's a similar treatment in Hastie et al Elements of Statistical Learning (2nd ed) in chapter 5 (In the section on Degrees of Freedom and Smoother Matrices). The discussion in in that section of ESL II is on effective degrees of freedom in smoothing splines but as they say there (where they're specifically discussing such a definition of generalized degrees of freedom given in eq 5.16) "This very useful definition allows us a more intuitive way to parameterize the smoothing spline, and indeed many other smoothers as well, in a consistent fashion"; they then mention that there are many possible justifications for this and they go on to give some of the possible justifications. See also equation 7.6 and the nearby text. Considerably more broadly, look at Ye (1998) "On Measuring and Correcting the Effects of Data Mining and Model Selection", JASA 93(441):120-131 where the author proposes using $\sum_i \frac{\partial \hat{y}_i}{\partial y_i}$ as the degrees of freedom for a huge variety of models for which you can take a set of data $y$ and compute a $\hat{y}$. For a model which can be written in hat-matrix form $\hat y = H y$, that's the trace of $H$.
Effective degrees of freedom If $H$ is such that $\hat y = H y$, then it would be quite standard to obtain the effective degrees of freedom from $\text{tr}(H)$. See Hastie and Tibshirani's Generalized Additive Models, and there's
31,842
My ReLU network fails to launch
The problem is that output units will sometimes get pushed into a regime where they are "dead" - that is, not responsive to any input. Once they're dead, they're dead - all gradients from that unit become zero, and therefore they can not learn to be useful again. This is a well-known problem with ReLU units. As work-arounds, some folks have designed alternative activation functions which are largely similar, but do not have a flat gradient. The Leaky ReLU function $L$ is probably the simplest $$ L(x) = \begin{cases} x &\text{if}~x > 0\\ \alpha x &\text{otherwise} \end{cases} $$ where $0 < \alpha< 1$ is some constant chosen by the user, usually something like $\alpha=0.2$. This always has positive gradient, so the weights can always update. They can more easily be pushed into this regime when the learning rate is higher. This thread addresses your observation about larger learning rates. the reason that the larger gradient flowing through an ReLU neuron can cause it to die
My ReLU network fails to launch
The problem is that output units will sometimes get pushed into a regime where they are "dead" - that is, not responsive to any input. Once they're dead, they're dead - all gradients from that unit be
My ReLU network fails to launch The problem is that output units will sometimes get pushed into a regime where they are "dead" - that is, not responsive to any input. Once they're dead, they're dead - all gradients from that unit become zero, and therefore they can not learn to be useful again. This is a well-known problem with ReLU units. As work-arounds, some folks have designed alternative activation functions which are largely similar, but do not have a flat gradient. The Leaky ReLU function $L$ is probably the simplest $$ L(x) = \begin{cases} x &\text{if}~x > 0\\ \alpha x &\text{otherwise} \end{cases} $$ where $0 < \alpha< 1$ is some constant chosen by the user, usually something like $\alpha=0.2$. This always has positive gradient, so the weights can always update. They can more easily be pushed into this regime when the learning rate is higher. This thread addresses your observation about larger learning rates. the reason that the larger gradient flowing through an ReLU neuron can cause it to die
My ReLU network fails to launch The problem is that output units will sometimes get pushed into a regime where they are "dead" - that is, not responsive to any input. Once they're dead, they're dead - all gradients from that unit be
31,843
My ReLU network fails to launch
Lately there has been some work on why deep learning is successful. Loss Surfaces of Multilayer Networks Identifying and attacking the saddle point problem in high-dimensional non-convex optimization are some good references, and of course the references therein. Roughly it seems that high dimensional optimization problems, which frequently occur in deep learning, are hypothesized to have better optimization landscapes. For example, consult Figure 3 in the first link. Notice that the local minima obtained by wider MLPs (more parameters, higher dimensional optimization problem) have their local minimas banded much closely together than with the thinner nets. Further note that they did an experiment similar to yours, i.e. n = 100 hidden units and they have quite a wide band in local minima values. That's from a theory perspective. From a computational perspective, can you try bumping up the number of hidden units, and perhaps even the number of hidden layers? You might start to see that training the network is less and less sensitive to your step size (within reason of course, choosing step size 1e+10 is probably a bad idea). Geometrically, perhaps shallower/thinner networks have much more "treacherous" optimization landscapes and can get caught in these sorts of local minima.
My ReLU network fails to launch
Lately there has been some work on why deep learning is successful. Loss Surfaces of Multilayer Networks Identifying and attacking the saddle point problem in high-dimensional non-convex optimization
My ReLU network fails to launch Lately there has been some work on why deep learning is successful. Loss Surfaces of Multilayer Networks Identifying and attacking the saddle point problem in high-dimensional non-convex optimization are some good references, and of course the references therein. Roughly it seems that high dimensional optimization problems, which frequently occur in deep learning, are hypothesized to have better optimization landscapes. For example, consult Figure 3 in the first link. Notice that the local minima obtained by wider MLPs (more parameters, higher dimensional optimization problem) have their local minimas banded much closely together than with the thinner nets. Further note that they did an experiment similar to yours, i.e. n = 100 hidden units and they have quite a wide band in local minima values. That's from a theory perspective. From a computational perspective, can you try bumping up the number of hidden units, and perhaps even the number of hidden layers? You might start to see that training the network is less and less sensitive to your step size (within reason of course, choosing step size 1e+10 is probably a bad idea). Geometrically, perhaps shallower/thinner networks have much more "treacherous" optimization landscapes and can get caught in these sorts of local minima.
My ReLU network fails to launch Lately there has been some work on why deep learning is successful. Loss Surfaces of Multilayer Networks Identifying and attacking the saddle point problem in high-dimensional non-convex optimization
31,844
Is it possible to calculate R-squared on a total least squares regression?
To elaborate on whuber's answer above - Pearson will give you what you want. It determines how well y correlates with x using an approach that is independent of regression model: $\rho_{X,Y}=\dfrac{cov(X,Y)}{\sigma_{X}\sigma_{Y}}$ gx.rma from the rgr package will do total least squares and calculate Pearson for you (or you can continue with Deming and do it manually). require(rgr) set.seed(3) x<-rnorm(101,mean=2.3,sd=4.2) x<-x+seq(0,100) set.seed(3) y<-rnorm(101,mean=4.9,sd=1.9) y<-y+seq(6,206,length=101) rma<-gx.rma(x,y) rma$corr [1] 0.9922014 So, the basic answer to your question is, when doing total least squares, forget R-squared and just use Pearson. You can always square that if you want a result between 0 and 1. This will do everything you need. Having said that, I will elaborate a little as I understand it feels like we should be able to calculate an R-squared equivalent. First, let's try a normal sum of squares regression on the data using lm. Notice that it gives the same correlation coefficient as Pearson (after square rooting and only worrying about magnitude, obviously). ols<-lm(y~x) sqrt(summary(ols)$r.squared) [1] 0.9922014 This is calculated from the lm model result using the traditional sum of squares approach $R^{2}=1-\dfrac{S_{res}}{S_{tot}}$ So, provided you use the model given by lm, (Pearson)-squared and R-squared are equivalent. However, if you use the model from the total sum of squares regression, and try to use the latter equation, you will get a slightly different result. That's obvious because normal and total least squares use different minimisation functions so give models with slightly different gradients and intercepts. (Remember, the first equation will still give the same result as it is looking at the data only.) This is where I get hung up though. If the two equations give the same result when using the lm model, then surely there must be an equivalent formulation for the latter equation, but when using the total least squares model, which also gives the same result? I had a quick play around with different approaches using the appropriate minimisation function (as has the poster here: Coefficient of determination of a orthogonal regression), but cannot find a way to do it - if there is a way. Perhaps we are both getting hung up on the fact that Pearson and R-squared give the same result when using normal least sqaures - and there simply isn't a way to do R-squared on total least squares, which will give the same result as Pearson. But I don't know enough about this to say why not.
Is it possible to calculate R-squared on a total least squares regression?
To elaborate on whuber's answer above - Pearson will give you what you want. It determines how well y correlates with x using an approach that is independent of regression model: $\rho_{X,Y}=\dfrac{co
Is it possible to calculate R-squared on a total least squares regression? To elaborate on whuber's answer above - Pearson will give you what you want. It determines how well y correlates with x using an approach that is independent of regression model: $\rho_{X,Y}=\dfrac{cov(X,Y)}{\sigma_{X}\sigma_{Y}}$ gx.rma from the rgr package will do total least squares and calculate Pearson for you (or you can continue with Deming and do it manually). require(rgr) set.seed(3) x<-rnorm(101,mean=2.3,sd=4.2) x<-x+seq(0,100) set.seed(3) y<-rnorm(101,mean=4.9,sd=1.9) y<-y+seq(6,206,length=101) rma<-gx.rma(x,y) rma$corr [1] 0.9922014 So, the basic answer to your question is, when doing total least squares, forget R-squared and just use Pearson. You can always square that if you want a result between 0 and 1. This will do everything you need. Having said that, I will elaborate a little as I understand it feels like we should be able to calculate an R-squared equivalent. First, let's try a normal sum of squares regression on the data using lm. Notice that it gives the same correlation coefficient as Pearson (after square rooting and only worrying about magnitude, obviously). ols<-lm(y~x) sqrt(summary(ols)$r.squared) [1] 0.9922014 This is calculated from the lm model result using the traditional sum of squares approach $R^{2}=1-\dfrac{S_{res}}{S_{tot}}$ So, provided you use the model given by lm, (Pearson)-squared and R-squared are equivalent. However, if you use the model from the total sum of squares regression, and try to use the latter equation, you will get a slightly different result. That's obvious because normal and total least squares use different minimisation functions so give models with slightly different gradients and intercepts. (Remember, the first equation will still give the same result as it is looking at the data only.) This is where I get hung up though. If the two equations give the same result when using the lm model, then surely there must be an equivalent formulation for the latter equation, but when using the total least squares model, which also gives the same result? I had a quick play around with different approaches using the appropriate minimisation function (as has the poster here: Coefficient of determination of a orthogonal regression), but cannot find a way to do it - if there is a way. Perhaps we are both getting hung up on the fact that Pearson and R-squared give the same result when using normal least sqaures - and there simply isn't a way to do R-squared on total least squares, which will give the same result as Pearson. But I don't know enough about this to say why not.
Is it possible to calculate R-squared on a total least squares regression? To elaborate on whuber's answer above - Pearson will give you what you want. It determines how well y correlates with x using an approach that is independent of regression model: $\rho_{X,Y}=\dfrac{co
31,845
Is it possible to calculate R-squared on a total least squares regression?
Using the package "mcr" and using function to generate your deming regression model yourmodel<-mcreg(x, y, ...) # you need to be familiar with the various types of deming constant SD or CV%. these can give very different results. But that's different question. and producing a plot using the function MCResult.plot(your model) This displays the Pearson's production moment correlation on the plot for the model, which tells you the strength and the direction of the linear relationship between your two x,y variables, but does not give the proportion of the variation that is explained. Hope that helps.
Is it possible to calculate R-squared on a total least squares regression?
Using the package "mcr" and using function to generate your deming regression model yourmodel<-mcreg(x, y, ...) # you need to be familiar with the various types of deming constant SD or CV%. these ca
Is it possible to calculate R-squared on a total least squares regression? Using the package "mcr" and using function to generate your deming regression model yourmodel<-mcreg(x, y, ...) # you need to be familiar with the various types of deming constant SD or CV%. these can give very different results. But that's different question. and producing a plot using the function MCResult.plot(your model) This displays the Pearson's production moment correlation on the plot for the model, which tells you the strength and the direction of the linear relationship between your two x,y variables, but does not give the proportion of the variation that is explained. Hope that helps.
Is it possible to calculate R-squared on a total least squares regression? Using the package "mcr" and using function to generate your deming regression model yourmodel<-mcreg(x, y, ...) # you need to be familiar with the various types of deming constant SD or CV%. these ca
31,846
Drawing samples from a multivariate normal distribution subject to quadratic constraints
The formal resolution of this problem first requires a proper definition of a "$\mathcal{N}_d(μ,Σ)$ distribution subject to the constraint that $||x||^2=1$" The natural way is to define the distribution of $X\sim\mathcal{N}_d(μ,Σ)$ conditional on $||X||=\varrho$. And to apply this conditional to the case $\varrho=1$. If we use polar coordinates, $$\eqalign{ x_1&=\varrho\cos(\theta_1)\qquad&\theta_1\in[0,\pi]\\ x_2&=\varrho\sin(\theta_1)\cos(\theta_2)\qquad&\theta_2\in[0,\pi]\\ &\vdots\\ x_{d-1}&=\varrho \left( \prod_{i=1}^{d-2}\sin(\theta_i) \right) \cos(\theta_{d-1})\qquad&\theta_{d-1}\in[0,2\pi]\\ x_{d}&=\varrho\prod_{i=1}^{d-1}\sin(\theta_i) }$$ the Jacobian of the transform is $$\varrho^{d-1}\prod_{i=1}^{d-2}\sin(\theta_i)^{d-1-i}$$ Therefore the conditional density of the distribution of $\mathbf{\theta}=(\theta_1,\ldots,\theta_{d-1})$ given $\varrho$ is $$ f(\mathbf{\theta}|\varrho) \propto \exp\frac{-1}{2}\left\{(x(\theta,\varrho)-\mu)^T\Sigma^{-1}(x(\theta,\varrho)-\mu) \right\} \prod_{i=1}^{d-2}\sin(\theta_i)^{d-1-i}$$ Conclusion: This density differs from simply applying the Normal density to a point on the unit sphere because of the Jacobian. The second step is to consider the target density $$ f(\mathbf{\theta}|\varrho=1) \propto \exp\frac{-1}{2}\left\{(x(\theta,1)-\mu)^T\Sigma^{-1}(x(\theta,1)-\mu) \right\} \prod_{i=1}^{d-2}\sin(\theta_i)^{d-1-i}$$ and design a Markov chain Monte Carlo algorithm to explore the parameter space $[0,\pi]^{d-2}\times[0,2\pi]$. My first attempt would be at a Gibbs sampler, initialised at the point on the sphere closest to $\mu$, that is, $\mu/||\mu||$, and proceeding one angle at a time in a Metropolis-within-Gibbs manner: Generate $\theta_1^{(t+1)}\sim\mathcal{U}([\theta_1^{(t)}-\delta_1,\theta_1^{(t)}+\delta_1])$ (where sums are computed modulo $\pi$) and accept this new value with probability $$\dfrac{f(\theta_1^{(t+1)},\theta_2^{(t)},...|\varrho=1)}{f(\theta_1^{(t)},\theta_2^{(t)},...|\varrho=1)}\wedge 1$$ else $\theta_1^{(t+1)}=\theta_1^{(t)}$ Generate $\theta_2^{(t+1)}\sim\mathcal{U}([\theta_2^{(t)}-\delta_2,\theta_2^{(t)}+\delta_2])$ (where sums are computed modulo $\pi$) and accept this new value with probability $$\dfrac{f(\theta_1^{(t+1)},\theta_2^{(t+1)},\theta_3^{(t)},...|\varrho=1)}{f(\theta_1^{(t+1)},\theta_2^{(t)},\theta_3^{(t)},...|\varrho=1)}\wedge 1$$ else $\theta_2^{(t+1)}=\theta_2^{(t)}$ $\ldots$ Generate $\theta_{d-1}^{(t+1)}\sim\mathcal{U}([\theta_{d-1}^{(t)}-\delta_{d-1},\theta_{d-1}^{(t)}+\delta_{d-1}])$ (where sums are computed modulo $2\pi$) and accept this new value with probability $$\dfrac{f(\theta_1^{(t+1)},\theta_2^{(t+1)},...,\theta_{d-1}^{(t+1)}|\varrho=1)}{f(\theta_1^{(t+1)},\theta_2^{(t+1)},...,\theta_{d-1}^{(t)}| \varrho=1)}\wedge 1$$ else $\theta_{d-1}^{(t+1)}=\theta_{d-1}^{(t)}$ The scales $\delta_1$, $\delta_2$, $\ldots$, $\delta_{d-1}$ can be scaled against the acceptance rates of the steps, towards an ideal goal of $50\%$. Here is an R code to illustrate the above, with default values for $\mu$ and $\Sigma$: library(mvtnorm) d=4 target=function(the,mu=1:d,sigma=diag(1/(1:d))){ carte=cos(the[1]) for (i in 2:(d-1)) carte=c(carte,prod(sin(the[1:(i-1)]))*cos(the[i])) carte=c(carte,prod(sin(the[1:(d-1)]))) prod(sin(the)^((d-2):0))*dmvnorm(carte,mean=mu,sigma=sigma)} #Gibbs T=1e4 #starting point mu=(1:d) mup=mu/sqrt(sum(mu^2)) mut=acos(mup[1]) for (i in 2:(d-1)) mut=c(mut,acos(mup[i]/prod(sin(mut)))) thes=matrix(mut,nrow=T,ncol=d-1,byrow=TRUE) delta=rep(pi/2,d-1) #scale past=target(thes[1,]) #current target for (t in 2:T){ thes[t,]=thes[t-1,] for (j in 1:(d-1)){ prop=thes[t,] prop[j]=prop[j]+runif(1,-delta[j],delta[j]) prop[j]=prop[j]%%(2*pi-(j<d-1)*pi) prof=target(prop) if (runif(1)<prof/past){ past=prof;thes[t,]=prop} } }
Drawing samples from a multivariate normal distribution subject to quadratic constraints
The formal resolution of this problem first requires a proper definition of a "$\mathcal{N}_d(μ,Σ)$ distribution subject to the constraint that $||x||^2=1$" The natural way is to define the distr
Drawing samples from a multivariate normal distribution subject to quadratic constraints The formal resolution of this problem first requires a proper definition of a "$\mathcal{N}_d(μ,Σ)$ distribution subject to the constraint that $||x||^2=1$" The natural way is to define the distribution of $X\sim\mathcal{N}_d(μ,Σ)$ conditional on $||X||=\varrho$. And to apply this conditional to the case $\varrho=1$. If we use polar coordinates, $$\eqalign{ x_1&=\varrho\cos(\theta_1)\qquad&\theta_1\in[0,\pi]\\ x_2&=\varrho\sin(\theta_1)\cos(\theta_2)\qquad&\theta_2\in[0,\pi]\\ &\vdots\\ x_{d-1}&=\varrho \left( \prod_{i=1}^{d-2}\sin(\theta_i) \right) \cos(\theta_{d-1})\qquad&\theta_{d-1}\in[0,2\pi]\\ x_{d}&=\varrho\prod_{i=1}^{d-1}\sin(\theta_i) }$$ the Jacobian of the transform is $$\varrho^{d-1}\prod_{i=1}^{d-2}\sin(\theta_i)^{d-1-i}$$ Therefore the conditional density of the distribution of $\mathbf{\theta}=(\theta_1,\ldots,\theta_{d-1})$ given $\varrho$ is $$ f(\mathbf{\theta}|\varrho) \propto \exp\frac{-1}{2}\left\{(x(\theta,\varrho)-\mu)^T\Sigma^{-1}(x(\theta,\varrho)-\mu) \right\} \prod_{i=1}^{d-2}\sin(\theta_i)^{d-1-i}$$ Conclusion: This density differs from simply applying the Normal density to a point on the unit sphere because of the Jacobian. The second step is to consider the target density $$ f(\mathbf{\theta}|\varrho=1) \propto \exp\frac{-1}{2}\left\{(x(\theta,1)-\mu)^T\Sigma^{-1}(x(\theta,1)-\mu) \right\} \prod_{i=1}^{d-2}\sin(\theta_i)^{d-1-i}$$ and design a Markov chain Monte Carlo algorithm to explore the parameter space $[0,\pi]^{d-2}\times[0,2\pi]$. My first attempt would be at a Gibbs sampler, initialised at the point on the sphere closest to $\mu$, that is, $\mu/||\mu||$, and proceeding one angle at a time in a Metropolis-within-Gibbs manner: Generate $\theta_1^{(t+1)}\sim\mathcal{U}([\theta_1^{(t)}-\delta_1,\theta_1^{(t)}+\delta_1])$ (where sums are computed modulo $\pi$) and accept this new value with probability $$\dfrac{f(\theta_1^{(t+1)},\theta_2^{(t)},...|\varrho=1)}{f(\theta_1^{(t)},\theta_2^{(t)},...|\varrho=1)}\wedge 1$$ else $\theta_1^{(t+1)}=\theta_1^{(t)}$ Generate $\theta_2^{(t+1)}\sim\mathcal{U}([\theta_2^{(t)}-\delta_2,\theta_2^{(t)}+\delta_2])$ (where sums are computed modulo $\pi$) and accept this new value with probability $$\dfrac{f(\theta_1^{(t+1)},\theta_2^{(t+1)},\theta_3^{(t)},...|\varrho=1)}{f(\theta_1^{(t+1)},\theta_2^{(t)},\theta_3^{(t)},...|\varrho=1)}\wedge 1$$ else $\theta_2^{(t+1)}=\theta_2^{(t)}$ $\ldots$ Generate $\theta_{d-1}^{(t+1)}\sim\mathcal{U}([\theta_{d-1}^{(t)}-\delta_{d-1},\theta_{d-1}^{(t)}+\delta_{d-1}])$ (where sums are computed modulo $2\pi$) and accept this new value with probability $$\dfrac{f(\theta_1^{(t+1)},\theta_2^{(t+1)},...,\theta_{d-1}^{(t+1)}|\varrho=1)}{f(\theta_1^{(t+1)},\theta_2^{(t+1)},...,\theta_{d-1}^{(t)}| \varrho=1)}\wedge 1$$ else $\theta_{d-1}^{(t+1)}=\theta_{d-1}^{(t)}$ The scales $\delta_1$, $\delta_2$, $\ldots$, $\delta_{d-1}$ can be scaled against the acceptance rates of the steps, towards an ideal goal of $50\%$. Here is an R code to illustrate the above, with default values for $\mu$ and $\Sigma$: library(mvtnorm) d=4 target=function(the,mu=1:d,sigma=diag(1/(1:d))){ carte=cos(the[1]) for (i in 2:(d-1)) carte=c(carte,prod(sin(the[1:(i-1)]))*cos(the[i])) carte=c(carte,prod(sin(the[1:(d-1)]))) prod(sin(the)^((d-2):0))*dmvnorm(carte,mean=mu,sigma=sigma)} #Gibbs T=1e4 #starting point mu=(1:d) mup=mu/sqrt(sum(mu^2)) mut=acos(mup[1]) for (i in 2:(d-1)) mut=c(mut,acos(mup[i]/prod(sin(mut)))) thes=matrix(mut,nrow=T,ncol=d-1,byrow=TRUE) delta=rep(pi/2,d-1) #scale past=target(thes[1,]) #current target for (t in 2:T){ thes[t,]=thes[t-1,] for (j in 1:(d-1)){ prop=thes[t,] prop[j]=prop[j]+runif(1,-delta[j],delta[j]) prop[j]=prop[j]%%(2*pi-(j<d-1)*pi) prof=target(prop) if (runif(1)<prof/past){ past=prof;thes[t,]=prop} } }
Drawing samples from a multivariate normal distribution subject to quadratic constraints The formal resolution of this problem first requires a proper definition of a "$\mathcal{N}_d(μ,Σ)$ distribution subject to the constraint that $||x||^2=1$" The natural way is to define the distr
31,847
Drawing samples from a multivariate normal distribution subject to quadratic constraints
$||x||_2^2=1$ is not strictly possible since $x$ is a (continuous) random variable. If you would like it to have a variance of 1, i.e. $E[(x-\mu)^2]\tilde{=} \frac{1}{n}\sum (x-\mu)^2=\frac{1}{n} ||x-n||_2^2=\frac{1}{n}$ (where the tilde means we estimate the variance), then you would need to require its variance to be $\frac{1}{n}$. However, this demand may conflict with $\Sigma$. That is, to get samples with this variance you need the diagonal of $\Sigma$ to be equal to $\frac{1}{n}$. To sample form this distribution in general, you can generate i.i.d standard normals, and then multiply by $\Sigma^{0.5}$, the square root of $\Sigma$, and then add the means $\mu$.
Drawing samples from a multivariate normal distribution subject to quadratic constraints
$||x||_2^2=1$ is not strictly possible since $x$ is a (continuous) random variable. If you would like it to have a variance of 1, i.e. $E[(x-\mu)^2]\tilde{=} \frac{1}{n}\sum (x-\mu)^2=\frac{1}{n} ||x-
Drawing samples from a multivariate normal distribution subject to quadratic constraints $||x||_2^2=1$ is not strictly possible since $x$ is a (continuous) random variable. If you would like it to have a variance of 1, i.e. $E[(x-\mu)^2]\tilde{=} \frac{1}{n}\sum (x-\mu)^2=\frac{1}{n} ||x-n||_2^2=\frac{1}{n}$ (where the tilde means we estimate the variance), then you would need to require its variance to be $\frac{1}{n}$. However, this demand may conflict with $\Sigma$. That is, to get samples with this variance you need the diagonal of $\Sigma$ to be equal to $\frac{1}{n}$. To sample form this distribution in general, you can generate i.i.d standard normals, and then multiply by $\Sigma^{0.5}$, the square root of $\Sigma$, and then add the means $\mu$.
Drawing samples from a multivariate normal distribution subject to quadratic constraints $||x||_2^2=1$ is not strictly possible since $x$ is a (continuous) random variable. If you would like it to have a variance of 1, i.e. $E[(x-\mu)^2]\tilde{=} \frac{1}{n}\sum (x-\mu)^2=\frac{1}{n} ||x-
31,848
Random forest regression - residuals correlated with response
This is exactly what you should expect to see. You see exactly the same thing with an ordinary regression model; if the model has $R^2$ higher than 0, residuals are correlated with the response. It's the fitted values that the residuals are uncorrelated with. Specifically, each regression captures all of the variation in $y$ that's explained by the predictors. Doing that means that $\hat{y}$ is uncorrelated with the residual -- because if it were not uncorrelated, there would be uncaptured variation that the $x$'s could capture. As a result of capturing everything that the $x$'s can capture in the regression model, there must be a correlation of residuals with the actual $y$ values: $\text{Cov}(y,y-\hat{y}) = \text{Cov}(y-\hat{y},y-\hat{y})+ \text{Cov}(\hat{y},y-\hat{y})= \text{Var}(y-\hat{y})+0=\sigma^2$ -- since that covariance is positive, the correlation will be. Regularization changes things somewhat but the same correlation appears. [The component of $y$ that's uncaptured by the model, even if it's just pure noise, is obviously correlated with itself. That's really all we're seeing here] Such a correlation will be present in every one of the regressions, and so correlation will carry over to the random forest as a whole. There's nothing to fix here, it's actually supposed to do that. You see it even if you fit exactly the model that generated your data. x = rbeta(1000,1.8,1.8)*20+5 # make some x variable y = 0.8+0.3*x+rnorm(1000,0,1.5) # simulate a regression model lmfit = lm(y~x) # fit the true regression model plot(y,lmfit$residual) # voila! $ cor(y,lmfit$residual) $\qquad$ You'll see a correlation in the vicinity of 70% for this example. In fact if you increase the variance of the noise term (other things being equal), the correlation is stronger. Try the above with more noise: y = 0.8+0.3*x+rnorm(1000,0,2.5) # simulate a regression model and see what happens! It may be that you will want to ask another question explaining the original problem you were trying to solve, because your choice of how to go about it may not have been ideal (it's hard to tell from what is here).
Random forest regression - residuals correlated with response
This is exactly what you should expect to see. You see exactly the same thing with an ordinary regression model; if the model has $R^2$ higher than 0, residuals are correlated with the response. It's
Random forest regression - residuals correlated with response This is exactly what you should expect to see. You see exactly the same thing with an ordinary regression model; if the model has $R^2$ higher than 0, residuals are correlated with the response. It's the fitted values that the residuals are uncorrelated with. Specifically, each regression captures all of the variation in $y$ that's explained by the predictors. Doing that means that $\hat{y}$ is uncorrelated with the residual -- because if it were not uncorrelated, there would be uncaptured variation that the $x$'s could capture. As a result of capturing everything that the $x$'s can capture in the regression model, there must be a correlation of residuals with the actual $y$ values: $\text{Cov}(y,y-\hat{y}) = \text{Cov}(y-\hat{y},y-\hat{y})+ \text{Cov}(\hat{y},y-\hat{y})= \text{Var}(y-\hat{y})+0=\sigma^2$ -- since that covariance is positive, the correlation will be. Regularization changes things somewhat but the same correlation appears. [The component of $y$ that's uncaptured by the model, even if it's just pure noise, is obviously correlated with itself. That's really all we're seeing here] Such a correlation will be present in every one of the regressions, and so correlation will carry over to the random forest as a whole. There's nothing to fix here, it's actually supposed to do that. You see it even if you fit exactly the model that generated your data. x = rbeta(1000,1.8,1.8)*20+5 # make some x variable y = 0.8+0.3*x+rnorm(1000,0,1.5) # simulate a regression model lmfit = lm(y~x) # fit the true regression model plot(y,lmfit$residual) # voila! $ cor(y,lmfit$residual) $\qquad$ You'll see a correlation in the vicinity of 70% for this example. In fact if you increase the variance of the noise term (other things being equal), the correlation is stronger. Try the above with more noise: y = 0.8+0.3*x+rnorm(1000,0,2.5) # simulate a regression model and see what happens! It may be that you will want to ask another question explaining the original problem you were trying to solve, because your choice of how to go about it may not have been ideal (it's hard to tell from what is here).
Random forest regression - residuals correlated with response This is exactly what you should expect to see. You see exactly the same thing with an ordinary regression model; if the model has $R^2$ higher than 0, residuals are correlated with the response. It's
31,849
When is log-loss metric appropriate for evaluating performance of a classifier?
Log-loss is an appropriate performance measure when you're model output is the probability of a binary outcome. The log-loss measure considers confidence of the prediction when assessing how to penalize incorrect classification. For instance consider two predictions of an outcome P(Y=1|X), where the predictions are 0.51 and 0.99 respectively. In the former case the model is only slightly confident of the class prediction (assuming a 0.5 cutoff), while in the latter it is extremely confident. Since in our case both are wrong, the penalty will be more harsh for the more confident (but incorrect) prediction by employing a log-loss penalty.
When is log-loss metric appropriate for evaluating performance of a classifier?
Log-loss is an appropriate performance measure when you're model output is the probability of a binary outcome. The log-loss measure considers confidence of the prediction when assessing how to penali
When is log-loss metric appropriate for evaluating performance of a classifier? Log-loss is an appropriate performance measure when you're model output is the probability of a binary outcome. The log-loss measure considers confidence of the prediction when assessing how to penalize incorrect classification. For instance consider two predictions of an outcome P(Y=1|X), where the predictions are 0.51 and 0.99 respectively. In the former case the model is only slightly confident of the class prediction (assuming a 0.5 cutoff), while in the latter it is extremely confident. Since in our case both are wrong, the penalty will be more harsh for the more confident (but incorrect) prediction by employing a log-loss penalty.
When is log-loss metric appropriate for evaluating performance of a classifier? Log-loss is an appropriate performance measure when you're model output is the probability of a binary outcome. The log-loss measure considers confidence of the prediction when assessing how to penali
31,850
When is log-loss metric appropriate for evaluating performance of a classifier?
If you want a good probability estimate that punishes extreme values when these are wrong, then logloss can do that. Read more on Making Sense of Logarithmic Loss. Log Loss heavily penalises classifiers that are confident about an incorrect classification. For example, if for a particular observation, the classifier assigns a very small probability to the correct class then the corresponding contribution to the Log Loss will be very large indeed. Naturally this is going to have a significant impact on the overall Log Loss for the classifier. The bottom line is that it’s better to be somewhat wrong than emphatically wrong. Of course it’s always better to be completely right, but that is seldom achievable in practice!
When is log-loss metric appropriate for evaluating performance of a classifier?
If you want a good probability estimate that punishes extreme values when these are wrong, then logloss can do that. Read more on Making Sense of Logarithmic Loss. Log Loss heavily penalises classifi
When is log-loss metric appropriate for evaluating performance of a classifier? If you want a good probability estimate that punishes extreme values when these are wrong, then logloss can do that. Read more on Making Sense of Logarithmic Loss. Log Loss heavily penalises classifiers that are confident about an incorrect classification. For example, if for a particular observation, the classifier assigns a very small probability to the correct class then the corresponding contribution to the Log Loss will be very large indeed. Naturally this is going to have a significant impact on the overall Log Loss for the classifier. The bottom line is that it’s better to be somewhat wrong than emphatically wrong. Of course it’s always better to be completely right, but that is seldom achievable in practice!
When is log-loss metric appropriate for evaluating performance of a classifier? If you want a good probability estimate that punishes extreme values when these are wrong, then logloss can do that. Read more on Making Sense of Logarithmic Loss. Log Loss heavily penalises classifi
31,851
How are graphs of k-nearest neighbors built? (for clustering)
Any normalised (dis)similarity matrix can be converted to the adjacency matrix of an undirected graph (weighted or not). For an unweighted graph you'll want to empirically set a threshold to its adjacency matrix, i.e. a minimum similarity value for a connection to take place between two nodes. For a given partition of the graph, the modularity metric will quantify the total strength of its clusters, therefore by maximising modularity you get the optimal community structure corresponding to that graph (clustering). To answer your questions: The graph in question will be undirected as long as your similarity matrix is symmetric. Weights (when present) are the normalised similarity values. The modularity function is basically the objective function of a NP-hard combinatorial problem. There are plenty of (meta)heuristics that do the task and if I'm not mistaken the normalised cut algorithm used in spectral clustering is one of them. I don't have experience with Chameleon but the concept of maximising intracluster similarity while minimising intercluster similarity is the same in modularity optimisation. Unfortunately there is no package (that I know of) that can automate the adjacency matrix conversion since finding the optimal threshold is a manual process. However, once you have that matrix, R and Mathematica have great packages to do the rest.
How are graphs of k-nearest neighbors built? (for clustering)
Any normalised (dis)similarity matrix can be converted to the adjacency matrix of an undirected graph (weighted or not). For an unweighted graph you'll want to empirically set a threshold to its adjac
How are graphs of k-nearest neighbors built? (for clustering) Any normalised (dis)similarity matrix can be converted to the adjacency matrix of an undirected graph (weighted or not). For an unweighted graph you'll want to empirically set a threshold to its adjacency matrix, i.e. a minimum similarity value for a connection to take place between two nodes. For a given partition of the graph, the modularity metric will quantify the total strength of its clusters, therefore by maximising modularity you get the optimal community structure corresponding to that graph (clustering). To answer your questions: The graph in question will be undirected as long as your similarity matrix is symmetric. Weights (when present) are the normalised similarity values. The modularity function is basically the objective function of a NP-hard combinatorial problem. There are plenty of (meta)heuristics that do the task and if I'm not mistaken the normalised cut algorithm used in spectral clustering is one of them. I don't have experience with Chameleon but the concept of maximising intracluster similarity while minimising intercluster similarity is the same in modularity optimisation. Unfortunately there is no package (that I know of) that can automate the adjacency matrix conversion since finding the optimal threshold is a manual process. However, once you have that matrix, R and Mathematica have great packages to do the rest.
How are graphs of k-nearest neighbors built? (for clustering) Any normalised (dis)similarity matrix can be converted to the adjacency matrix of an undirected graph (weighted or not). For an unweighted graph you'll want to empirically set a threshold to its adjac
31,852
How are graphs of k-nearest neighbors built? (for clustering)
Standard Chameleon is initialized using asymmetrical k-NN algorithm, where parameter $k$ could be fixed to sufficiently large number, e.g. $10$ or derived from dataset size, e.g. $k=\sqrt{n}$. Weight of edge between $A$ and $B$ is set to $w(e) = dist(A,B)$, where distance is defined as Euclidean distance (or any other distance complying with triangular inequality). The graph is not directed. The authors suggest that also a symmetrical k-NN could be used for graph initialization (when a point A has another point B as a near neighbor but point B doesn’t have point A as a near neighbor, then the edge isn't created). However this approach is typically not used due to its high computational complexity. Some experiments with symmetrical k-NN are presented by Lesna, Shatovska. Having a simple dataset: you create a graph from k-NN: after partitioning the graph will be much simplified (having a large $k$ at the begging might not have any influence at all, because most of the edges will be removed during partitioning).
How are graphs of k-nearest neighbors built? (for clustering)
Standard Chameleon is initialized using asymmetrical k-NN algorithm, where parameter $k$ could be fixed to sufficiently large number, e.g. $10$ or derived from dataset size, e.g. $k=\sqrt{n}$. Weight
How are graphs of k-nearest neighbors built? (for clustering) Standard Chameleon is initialized using asymmetrical k-NN algorithm, where parameter $k$ could be fixed to sufficiently large number, e.g. $10$ or derived from dataset size, e.g. $k=\sqrt{n}$. Weight of edge between $A$ and $B$ is set to $w(e) = dist(A,B)$, where distance is defined as Euclidean distance (or any other distance complying with triangular inequality). The graph is not directed. The authors suggest that also a symmetrical k-NN could be used for graph initialization (when a point A has another point B as a near neighbor but point B doesn’t have point A as a near neighbor, then the edge isn't created). However this approach is typically not used due to its high computational complexity. Some experiments with symmetrical k-NN are presented by Lesna, Shatovska. Having a simple dataset: you create a graph from k-NN: after partitioning the graph will be much simplified (having a large $k$ at the begging might not have any influence at all, because most of the edges will be removed during partitioning).
How are graphs of k-nearest neighbors built? (for clustering) Standard Chameleon is initialized using asymmetrical k-NN algorithm, where parameter $k$ could be fixed to sufficiently large number, e.g. $10$ or derived from dataset size, e.g. $k=\sqrt{n}$. Weight
31,853
How does the R function arima() calculate its residuals?
The equation you expect does hold but only if the conditional sum-of-squares (CSS) estimator is used. The default in arima() is to use CSS only for the starting values and then carry out full maximum likelihood (ML) estimation to integrate over the starting values. But the computations you expected can be obtained in the following way: css <- arima(y, order = c(0, 0, 2), method = "CSS") cf <- coef(css) residuals(css)[1:3] ## [1] 3.1099177 1.0096719 -0.6039833 This only sets two starting values for the innovations to zero, i.e., assumes $a_0 = a_{-1} = 0$. All subsequent computations are done conditional on this: a <- c(0, 0) The iteration for the first three residuals can then be done by the following for() loop. (Note that the index of a always has to be shifted due to the starting values.) for(i in 1:3) a[i + 2] <- y[i] - cf[3] - cf[1] * a[i + 1] - cf[2] * a[i] a ## [1] 0.0000000 0.0000000 3.1099177 1.0096719 -0.6039833 So this replicates exactly what you expected. For the default ML estimation the situation is more complex because this integrates out the distribution of the starting values. See the references listed in ?arima for more details. A good introductory textbook is also Cryer & Chan which covers this topic in Chapter 7.
How does the R function arima() calculate its residuals?
The equation you expect does hold but only if the conditional sum-of-squares (CSS) estimator is used. The default in arima() is to use CSS only for the starting values and then carry out full maximum
How does the R function arima() calculate its residuals? The equation you expect does hold but only if the conditional sum-of-squares (CSS) estimator is used. The default in arima() is to use CSS only for the starting values and then carry out full maximum likelihood (ML) estimation to integrate over the starting values. But the computations you expected can be obtained in the following way: css <- arima(y, order = c(0, 0, 2), method = "CSS") cf <- coef(css) residuals(css)[1:3] ## [1] 3.1099177 1.0096719 -0.6039833 This only sets two starting values for the innovations to zero, i.e., assumes $a_0 = a_{-1} = 0$. All subsequent computations are done conditional on this: a <- c(0, 0) The iteration for the first three residuals can then be done by the following for() loop. (Note that the index of a always has to be shifted due to the starting values.) for(i in 1:3) a[i + 2] <- y[i] - cf[3] - cf[1] * a[i + 1] - cf[2] * a[i] a ## [1] 0.0000000 0.0000000 3.1099177 1.0096719 -0.6039833 So this replicates exactly what you expected. For the default ML estimation the situation is more complex because this integrates out the distribution of the starting values. See the references listed in ?arima for more details. A good introductory textbook is also Cryer & Chan which covers this topic in Chapter 7.
How does the R function arima() calculate its residuals? The equation you expect does hold but only if the conditional sum-of-squares (CSS) estimator is used. The default in arima() is to use CSS only for the starting values and then carry out full maximum
31,854
Fitting a plane to a set of points in 3D using PCA
When you perform principal component analysis (PCA) on your 27 points in 3D, you first subtract the mean vector $\mathbf m$ and then obtain three eigenvectors $\mathbf e_1, \mathbf e_2, \mathbf e_3$ of the covariance matrix. The first two eigenvectors (with two largest eigenvalues) span the plane that you want to find, so the geometric situation looks like that: The question is: how to get from here to the equation of this plane in the form $$ax+by+cz=d.$$ This equation can be reformulated as follows: $\mathbf a \cdot \mathbf x = d$, where $\mathbf x$ is any point lying in the plane and $\mathbf a$ is a vector $(a,b,c)$. In other words, we need to find a vector $\mathbf a$ such that its dot product with any point in the plane gives the same constant value $d$. From the picture above, we see that any point belonging to the plane can be written as $\mathbf x = \mathbf m+ g\mathbf e_1 + h\mathbf e_2$, where $g$ and $h$ are some real numbers. It follows that the dot product between $\mathbf e_3$ and $\mathbf x$ is given by $$\mathbf e_3 \cdot \mathbf x = \mathbf e_3 \cdot (\mathbf m+ g\mathbf e_1 + h\mathbf e_2) = \mathbf e_3 \cdot \mathbf m = \mathrm{const}.$$ So here we have it: we can take $\mathbf a = \mathbf e_3$ and $d = \mathbf e_3 \cdot \mathbf m$. Putting it all together, the solution is: \begin{align} a &= e_{31}\\ b&=e_{32} \\ c&=e_{33} \\ d&=e_{31}m_1+e_{32}m_2 + e_{33}m_3. \end{align}
Fitting a plane to a set of points in 3D using PCA
When you perform principal component analysis (PCA) on your 27 points in 3D, you first subtract the mean vector $\mathbf m$ and then obtain three eigenvectors $\mathbf e_1, \mathbf e_2, \mathbf e_3$ o
Fitting a plane to a set of points in 3D using PCA When you perform principal component analysis (PCA) on your 27 points in 3D, you first subtract the mean vector $\mathbf m$ and then obtain three eigenvectors $\mathbf e_1, \mathbf e_2, \mathbf e_3$ of the covariance matrix. The first two eigenvectors (with two largest eigenvalues) span the plane that you want to find, so the geometric situation looks like that: The question is: how to get from here to the equation of this plane in the form $$ax+by+cz=d.$$ This equation can be reformulated as follows: $\mathbf a \cdot \mathbf x = d$, where $\mathbf x$ is any point lying in the plane and $\mathbf a$ is a vector $(a,b,c)$. In other words, we need to find a vector $\mathbf a$ such that its dot product with any point in the plane gives the same constant value $d$. From the picture above, we see that any point belonging to the plane can be written as $\mathbf x = \mathbf m+ g\mathbf e_1 + h\mathbf e_2$, where $g$ and $h$ are some real numbers. It follows that the dot product between $\mathbf e_3$ and $\mathbf x$ is given by $$\mathbf e_3 \cdot \mathbf x = \mathbf e_3 \cdot (\mathbf m+ g\mathbf e_1 + h\mathbf e_2) = \mathbf e_3 \cdot \mathbf m = \mathrm{const}.$$ So here we have it: we can take $\mathbf a = \mathbf e_3$ and $d = \mathbf e_3 \cdot \mathbf m$. Putting it all together, the solution is: \begin{align} a &= e_{31}\\ b&=e_{32} \\ c&=e_{33} \\ d&=e_{31}m_1+e_{32}m_2 + e_{33}m_3. \end{align}
Fitting a plane to a set of points in 3D using PCA When you perform principal component analysis (PCA) on your 27 points in 3D, you first subtract the mean vector $\mathbf m$ and then obtain three eigenvectors $\mathbf e_1, \mathbf e_2, \mathbf e_3$ o
31,855
Can someone explain what the foldid argument in glmnet does?
fold.id allows the user to pre-specify the cross validation folds for cv.glmnet. For example, if I have some data x | y | fold.id -----+------+-------- 0 | 1 | 1 1 | 1 | 1 0 | 0 | 2 1 | 2 | 2 . | . | . Then passing in the indicated column as the fold.id argument to cv.glmnet will cause (for example) the first two observations to reside in the same fold, and the third and fourth observations to reside in the same (different) fold. The authors are suggesting that if you would like to choose between some discrete collection of $\alpha$ based on a cross validation estimate of some error at an optimal $\lambda_{\alpha}$, then it is best practice to use the same fold structure in each of your cross validations when determining each $\lambda_{\alpha}$.
Can someone explain what the foldid argument in glmnet does?
fold.id allows the user to pre-specify the cross validation folds for cv.glmnet. For example, if I have some data x | y | fold.id -----+------+-------- 0 | 1 | 1 1 | 1 | 1 0 | 0
Can someone explain what the foldid argument in glmnet does? fold.id allows the user to pre-specify the cross validation folds for cv.glmnet. For example, if I have some data x | y | fold.id -----+------+-------- 0 | 1 | 1 1 | 1 | 1 0 | 0 | 2 1 | 2 | 2 . | . | . Then passing in the indicated column as the fold.id argument to cv.glmnet will cause (for example) the first two observations to reside in the same fold, and the third and fourth observations to reside in the same (different) fold. The authors are suggesting that if you would like to choose between some discrete collection of $\alpha$ based on a cross validation estimate of some error at an optimal $\lambda_{\alpha}$, then it is best practice to use the same fold structure in each of your cross validations when determining each $\lambda_{\alpha}$.
Can someone explain what the foldid argument in glmnet does? fold.id allows the user to pre-specify the cross validation folds for cv.glmnet. For example, if I have some data x | y | fold.id -----+------+-------- 0 | 1 | 1 1 | 1 | 1 0 | 0
31,856
Can someone explain what the foldid argument in glmnet does?
According to the Glmnet Vignette, one way to set-up the foldid for glmnet is by: foldid<-sample(1:10,size=length(y),replace=TRUE) And then apply to a series of alphas: cv1=cv.glmnet(x,y,foldid=foldid,alpha=1) cv.5=cv.glmnet(x,y,foldid=foldid,alpha=.5) cv0=cv.glmnet(x,y,foldid=foldid,alpha=0) The sample() function basically allows you to generate a vector of random numbers in the range you supply (= 1:nfolds) for the length of the response variable matrix y. In this way, you assign each of your input matrix rows to a random (but now set) fold.
Can someone explain what the foldid argument in glmnet does?
According to the Glmnet Vignette, one way to set-up the foldid for glmnet is by: foldid<-sample(1:10,size=length(y),replace=TRUE) And then apply to a series of alphas: cv1=cv.glmnet(x,y,foldid=foldid
Can someone explain what the foldid argument in glmnet does? According to the Glmnet Vignette, one way to set-up the foldid for glmnet is by: foldid<-sample(1:10,size=length(y),replace=TRUE) And then apply to a series of alphas: cv1=cv.glmnet(x,y,foldid=foldid,alpha=1) cv.5=cv.glmnet(x,y,foldid=foldid,alpha=.5) cv0=cv.glmnet(x,y,foldid=foldid,alpha=0) The sample() function basically allows you to generate a vector of random numbers in the range you supply (= 1:nfolds) for the length of the response variable matrix y. In this way, you assign each of your input matrix rows to a random (but now set) fold.
Can someone explain what the foldid argument in glmnet does? According to the Glmnet Vignette, one way to set-up the foldid for glmnet is by: foldid<-sample(1:10,size=length(y),replace=TRUE) And then apply to a series of alphas: cv1=cv.glmnet(x,y,foldid=foldid
31,857
Confidence intervals for Kendall's tau
This paper discusses the contexts where you can and can't use a normal approximation for Tau. According to Wikipedia, it also looks like the validity of normal/Z depends on how your version of Tau handles ties. My sense is that it's probably safer not to assume that it's Gaussian, especially with relatively low sample sizes. I couldn't think of a reason why Kendall's Tau wouldn't be compatible with the bootstrap, but I wasn't 100% sure. So I looked it up: Here's a paper by Brad Efron, the inventor of the bootstrap, that uses it for Tau (Section 5). Here's a paper that spends some time discussing the bootstrap in the context of Tau (mostly Section 4). Looks like you shouldn't have any serious problems using the bootstrap for tau.
Confidence intervals for Kendall's tau
This paper discusses the contexts where you can and can't use a normal approximation for Tau. According to Wikipedia, it also looks like the validity of normal/Z depends on how your version of Tau han
Confidence intervals for Kendall's tau This paper discusses the contexts where you can and can't use a normal approximation for Tau. According to Wikipedia, it also looks like the validity of normal/Z depends on how your version of Tau handles ties. My sense is that it's probably safer not to assume that it's Gaussian, especially with relatively low sample sizes. I couldn't think of a reason why Kendall's Tau wouldn't be compatible with the bootstrap, but I wasn't 100% sure. So I looked it up: Here's a paper by Brad Efron, the inventor of the bootstrap, that uses it for Tau (Section 5). Here's a paper that spends some time discussing the bootstrap in the context of Tau (mostly Section 4). Looks like you shouldn't have any serious problems using the bootstrap for tau.
Confidence intervals for Kendall's tau This paper discusses the contexts where you can and can't use a normal approximation for Tau. According to Wikipedia, it also looks like the validity of normal/Z depends on how your version of Tau han
31,858
How to compute Deviance Statistic for a simple Logistic Regression Model in the case that any $n_i = y_i$?
When calculating the binomial deviance we use the convention that $0 \log(0) = \lim_{x \downarrow 0} x \log(x) = 0$. To understand why this convention makes sense here it's helpful for simplicity to think in terms of the Bernoulli likelihood function $\prod_{i=1}^{n} p_i^{y_i} (1 - p_i)^{1 - y_i}$ (the general binomial case will just be an extension of the main idea here), where $y_i$ is either zero or one. Now when we talk about the saturated model (the likelihood of which is part of the deviance statistic) we mean the model where $\hat{p}_i = y_i$ for each $i$. But clearly the likelihood should equal one here (our model says that the data are certain to arise as they did), which means we should treat $0^0$ as itself being equal to one, and for the sake of consistency we should therefore treat the logarithm of $0^0$ as being equal to zero.
How to compute Deviance Statistic for a simple Logistic Regression Model in the case that any $n_i =
When calculating the binomial deviance we use the convention that $0 \log(0) = \lim_{x \downarrow 0} x \log(x) = 0$. To understand why this convention makes sense here it's helpful for simplicity to t
How to compute Deviance Statistic for a simple Logistic Regression Model in the case that any $n_i = y_i$? When calculating the binomial deviance we use the convention that $0 \log(0) = \lim_{x \downarrow 0} x \log(x) = 0$. To understand why this convention makes sense here it's helpful for simplicity to think in terms of the Bernoulli likelihood function $\prod_{i=1}^{n} p_i^{y_i} (1 - p_i)^{1 - y_i}$ (the general binomial case will just be an extension of the main idea here), where $y_i$ is either zero or one. Now when we talk about the saturated model (the likelihood of which is part of the deviance statistic) we mean the model where $\hat{p}_i = y_i$ for each $i$. But clearly the likelihood should equal one here (our model says that the data are certain to arise as they did), which means we should treat $0^0$ as itself being equal to one, and for the sake of consistency we should therefore treat the logarithm of $0^0$ as being equal to zero.
How to compute Deviance Statistic for a simple Logistic Regression Model in the case that any $n_i = When calculating the binomial deviance we use the convention that $0 \log(0) = \lim_{x \downarrow 0} x \log(x) = 0$. To understand why this convention makes sense here it's helpful for simplicity to t
31,859
Poisson regression for count data - predictions
Predictions from a Poisson model are the mean parameter of a Poisson distribution, which is not constrained to be an integer. (Think of the old "the average family has 2.4 children" conundrum.) Simulated outcomes from your model using those predicted means will of course be integers: for the predictor combination giving a predicted mean of 41.2 you might well get 45, 39, 42, or 40 as simulated outcomes.
Poisson regression for count data - predictions
Predictions from a Poisson model are the mean parameter of a Poisson distribution, which is not constrained to be an integer. (Think of the old "the average family has 2.4 children" conundrum.) Simula
Poisson regression for count data - predictions Predictions from a Poisson model are the mean parameter of a Poisson distribution, which is not constrained to be an integer. (Think of the old "the average family has 2.4 children" conundrum.) Simulated outcomes from your model using those predicted means will of course be integers: for the predictor combination giving a predicted mean of 41.2 you might well get 45, 39, 42, or 40 as simulated outcomes.
Poisson regression for count data - predictions Predictions from a Poisson model are the mean parameter of a Poisson distribution, which is not constrained to be an integer. (Think of the old "the average family has 2.4 children" conundrum.) Simula
31,860
What is the best way to present rank survey data? [duplicate]
I would try to put the data into the same chart, not split into different panels, to allow more comparisons. Of course, there is a lot of experimentation with graphics before you decide which show the data best. Here are a handful that I would try. Assuming 1 is most important I might reverse the category axis, take off the numbers, and show Most and Least Important in the bottom left chart above, like this: EDIT: This is an old thread, but I think it's worth adding one visualization type to the mix. It's a diverging stacked bar chart, which shows more positive rankings to the right and less positive to the left. I think it more clearly shows the sentiment of the survey responses. I made this in Excel, believe it or not. It's very tedious to do so by hand, but I've written a commercial program to automate the process.
What is the best way to present rank survey data? [duplicate]
I would try to put the data into the same chart, not split into different panels, to allow more comparisons. Of course, there is a lot of experimentation with graphics before you decide which show the
What is the best way to present rank survey data? [duplicate] I would try to put the data into the same chart, not split into different panels, to allow more comparisons. Of course, there is a lot of experimentation with graphics before you decide which show the data best. Here are a handful that I would try. Assuming 1 is most important I might reverse the category axis, take off the numbers, and show Most and Least Important in the bottom left chart above, like this: EDIT: This is an old thread, but I think it's worth adding one visualization type to the mix. It's a diverging stacked bar chart, which shows more positive rankings to the right and less positive to the left. I think it more clearly shows the sentiment of the survey responses. I made this in Excel, believe it or not. It's very tedious to do so by hand, but I've written a commercial program to automate the process.
What is the best way to present rank survey data? [duplicate] I would try to put the data into the same chart, not split into different panels, to allow more comparisons. Of course, there is a lot of experimentation with graphics before you decide which show the
31,861
Finding the point of maximum probability in a mixture of gaussians
If you have a mixture of $n$ one-dimensional Gaussians, you can have anything between one and $n$ local maxima: weights <- c(0.2,0.3,0.5) weights <- weights/sum(weights) sds <- c(1,2,3) means <- c(-1,0,1) xx <- seq(min(means-3*sds),max(means+3*sds),by=0.01) plot(xx, rowSums(mapply(dnorm,mean=means,sd=sds,MoreArgs=list(x=xx))), type="l",xlab="",ylab="") means <- c(-5,0,5) xx <- seq(min(means-3*sds),max(means+3*sds),by=0.01) plot(xx, rowSums(mapply(dnorm,mean=means,sd=sds,MoreArgs=list(x=xx))), type="l",xlab="",ylab="") And of course, (some of) these maxima may have the same height, so you may not only have multiple local maxima, but multiple global ones. As Martin O'Leary very helpfully points out, linking to this extremely helpful page, this does not hold in higher dimensions. Instead, you can easily have more than $n$ maxima in higher dimensions. Consequently, you won't get around searching for your maxima. Use multiple starting values and a simple Newton-type maximizer over the mixture density, evaluate the density at each local maximum you find, and output the local maximum with the highest density. In one dimension, if in the course of your search you have found $n$ different local maxima, then you know that the one with the highest density is one of your global maxima. If not, you either have fewer local maxima than $n$ (as in the examples above), or you may have missed some (and the global maximum among them). As per above, this check will not work in higher dimensions.
Finding the point of maximum probability in a mixture of gaussians
If you have a mixture of $n$ one-dimensional Gaussians, you can have anything between one and $n$ local maxima: weights <- c(0.2,0.3,0.5) weights <- weights/sum(weights) sds <- c(1,2,3) means <- c(-1
Finding the point of maximum probability in a mixture of gaussians If you have a mixture of $n$ one-dimensional Gaussians, you can have anything between one and $n$ local maxima: weights <- c(0.2,0.3,0.5) weights <- weights/sum(weights) sds <- c(1,2,3) means <- c(-1,0,1) xx <- seq(min(means-3*sds),max(means+3*sds),by=0.01) plot(xx, rowSums(mapply(dnorm,mean=means,sd=sds,MoreArgs=list(x=xx))), type="l",xlab="",ylab="") means <- c(-5,0,5) xx <- seq(min(means-3*sds),max(means+3*sds),by=0.01) plot(xx, rowSums(mapply(dnorm,mean=means,sd=sds,MoreArgs=list(x=xx))), type="l",xlab="",ylab="") And of course, (some of) these maxima may have the same height, so you may not only have multiple local maxima, but multiple global ones. As Martin O'Leary very helpfully points out, linking to this extremely helpful page, this does not hold in higher dimensions. Instead, you can easily have more than $n$ maxima in higher dimensions. Consequently, you won't get around searching for your maxima. Use multiple starting values and a simple Newton-type maximizer over the mixture density, evaluate the density at each local maximum you find, and output the local maximum with the highest density. In one dimension, if in the course of your search you have found $n$ different local maxima, then you know that the one with the highest density is one of your global maxima. If not, you either have fewer local maxima than $n$ (as in the examples above), or you may have missed some (and the global maximum among them). As per above, this check will not work in higher dimensions.
Finding the point of maximum probability in a mixture of gaussians If you have a mixture of $n$ one-dimensional Gaussians, you can have anything between one and $n$ local maxima: weights <- c(0.2,0.3,0.5) weights <- weights/sum(weights) sds <- c(1,2,3) means <- c(-1
31,862
How does one use Bayes theorem with a continuous prior?
For comparing models, say $$\mathfrak{M}_1=\{f_1(\cdot|\theta_1);\ \theta_1\in\Theta_1\}$$ and $$\mathfrak{M}_2=\{f_2(\cdot|\theta_2);\ \theta_2\in\Theta_2\}$$the classical Bayesian answer is (Jeffreys, 1939) to produce a Bayes factor $$\mathfrak{B}_{12}(x)=\frac{\int_{\Theta_1} f_1(x|\theta_1)\pi_1(\text{d}\theta_1)}{\int_{\Theta_2} f_2(x|\theta_2)\pi_2(\text{d}\theta_2)}$$When $\mathfrak{B}_{12}(x)$ is larger than $1$ the data favours model $\mathfrak{M}_1$; when $\mathfrak{B}_{12}(x)$ is smaller than $1$, the data favours model $\mathfrak{M}_2$.
How does one use Bayes theorem with a continuous prior?
For comparing models, say $$\mathfrak{M}_1=\{f_1(\cdot|\theta_1);\ \theta_1\in\Theta_1\}$$ and $$\mathfrak{M}_2=\{f_2(\cdot|\theta_2);\ \theta_2\in\Theta_2\}$$the classical Bayesian answer is (Jeffrey
How does one use Bayes theorem with a continuous prior? For comparing models, say $$\mathfrak{M}_1=\{f_1(\cdot|\theta_1);\ \theta_1\in\Theta_1\}$$ and $$\mathfrak{M}_2=\{f_2(\cdot|\theta_2);\ \theta_2\in\Theta_2\}$$the classical Bayesian answer is (Jeffreys, 1939) to produce a Bayes factor $$\mathfrak{B}_{12}(x)=\frac{\int_{\Theta_1} f_1(x|\theta_1)\pi_1(\text{d}\theta_1)}{\int_{\Theta_2} f_2(x|\theta_2)\pi_2(\text{d}\theta_2)}$$When $\mathfrak{B}_{12}(x)$ is larger than $1$ the data favours model $\mathfrak{M}_1$; when $\mathfrak{B}_{12}(x)$ is smaller than $1$, the data favours model $\mathfrak{M}_2$.
How does one use Bayes theorem with a continuous prior? For comparing models, say $$\mathfrak{M}_1=\{f_1(\cdot|\theta_1);\ \theta_1\in\Theta_1\}$$ and $$\mathfrak{M}_2=\{f_2(\cdot|\theta_2);\ \theta_2\in\Theta_2\}$$the classical Bayesian answer is (Jeffrey
31,863
How does one use Bayes theorem with a continuous prior?
Bayes theorem is: $$ P(A|B) = \frac{P(B|A)P(A)}{P(B)} $$ In a case where you have some data and a parameter, it is common to use $\theta$ for the parameter (or parameter vector) and $x$ for the data. You might place a prior on $\theta$, $p(\theta)$, and you might have a model $p(x|\theta)$ which gives the probability of your data given the model. You can then use Bayes rule/theorem to "invert" this and get $p(\theta|x)$. Only in a relatively small set of examples is it possible to get closed form solutions for $p(\theta|x)$. For arbitrary cases, often you approximate the posterior distribution using some standard methods in Bayesian statistics -- for example, the two most common broad approaches are markov chain monte carlo or variational Bayes. Suppose you are interested in a simple case where a closed form posterior exists. An example of this would be if $p(\theta)$ is a standard normal (Gaussian with unit variance and zero mean) and $p(x|\theta)$ is a normal with mean value of $\theta$ and unit variance. I will omit normalization factors for convenience. Also note that the denominator in Bayes rule tends to simply renormalize things: $$ p(\theta|x) \propto e^{-(x-\theta)^2/2} e^{-\theta^2/2}\\ $$ Let's combine the exponents and complete the square $$ -(x-\theta)^2/2 - \theta^2/2 \propto - (x^2 - 2\theta x + \theta^2) - \theta^2 $$ Recall that x is fixed here because it has been observed and we want expect our answer will be in terms of it. Complete the square and see that the exponent is $\propto -(\theta - x/2)^2$ with other terms of which depend on x. So: $$ p(\theta|x) \propto e^{-a(\theta - x/2)^2} $$ where 'a' is a factor that can be obtained by book-keeping. Notice that the posterior is a normal distribution with mean value x/2. Attempt to compute the variance for yourself. Note that our answer makes intuitive sense...the prior said that $\theta$ is zero and we observe a sample $x$ that has expected value of $\theta$. Since the variance of the prior and the distribution $p(x|\theta)$ are equal magnitude, we trust them equally. Accordingly, our posterior is a distribution with a mean that is the average of $x$ and 0 and which ends up having smaller variance than the initial $p(x|\theta)$ or $p(x)$ (not shown here). For model comparison, you could look at a ratio: $$ \frac{p(x|\theta_1)}{p(x|\theta_2)} $$ This is called the likelihood ratio (see wikipedia or elsewhere). Here you don't need the posterior, you simply are looking at how (relatively) likely your data (or observations) are given either $\theta_1$ or $\theta_2$ being the parameter of the model that generated your observations. Hope this helps.
How does one use Bayes theorem with a continuous prior?
Bayes theorem is: $$ P(A|B) = \frac{P(B|A)P(A)}{P(B)} $$ In a case where you have some data and a parameter, it is common to use $\theta$ for the parameter (or parameter vector) and $x$ for the data.
How does one use Bayes theorem with a continuous prior? Bayes theorem is: $$ P(A|B) = \frac{P(B|A)P(A)}{P(B)} $$ In a case where you have some data and a parameter, it is common to use $\theta$ for the parameter (or parameter vector) and $x$ for the data. You might place a prior on $\theta$, $p(\theta)$, and you might have a model $p(x|\theta)$ which gives the probability of your data given the model. You can then use Bayes rule/theorem to "invert" this and get $p(\theta|x)$. Only in a relatively small set of examples is it possible to get closed form solutions for $p(\theta|x)$. For arbitrary cases, often you approximate the posterior distribution using some standard methods in Bayesian statistics -- for example, the two most common broad approaches are markov chain monte carlo or variational Bayes. Suppose you are interested in a simple case where a closed form posterior exists. An example of this would be if $p(\theta)$ is a standard normal (Gaussian with unit variance and zero mean) and $p(x|\theta)$ is a normal with mean value of $\theta$ and unit variance. I will omit normalization factors for convenience. Also note that the denominator in Bayes rule tends to simply renormalize things: $$ p(\theta|x) \propto e^{-(x-\theta)^2/2} e^{-\theta^2/2}\\ $$ Let's combine the exponents and complete the square $$ -(x-\theta)^2/2 - \theta^2/2 \propto - (x^2 - 2\theta x + \theta^2) - \theta^2 $$ Recall that x is fixed here because it has been observed and we want expect our answer will be in terms of it. Complete the square and see that the exponent is $\propto -(\theta - x/2)^2$ with other terms of which depend on x. So: $$ p(\theta|x) \propto e^{-a(\theta - x/2)^2} $$ where 'a' is a factor that can be obtained by book-keeping. Notice that the posterior is a normal distribution with mean value x/2. Attempt to compute the variance for yourself. Note that our answer makes intuitive sense...the prior said that $\theta$ is zero and we observe a sample $x$ that has expected value of $\theta$. Since the variance of the prior and the distribution $p(x|\theta)$ are equal magnitude, we trust them equally. Accordingly, our posterior is a distribution with a mean that is the average of $x$ and 0 and which ends up having smaller variance than the initial $p(x|\theta)$ or $p(x)$ (not shown here). For model comparison, you could look at a ratio: $$ \frac{p(x|\theta_1)}{p(x|\theta_2)} $$ This is called the likelihood ratio (see wikipedia or elsewhere). Here you don't need the posterior, you simply are looking at how (relatively) likely your data (or observations) are given either $\theta_1$ or $\theta_2$ being the parameter of the model that generated your observations. Hope this helps.
How does one use Bayes theorem with a continuous prior? Bayes theorem is: $$ P(A|B) = \frac{P(B|A)P(A)}{P(B)} $$ In a case where you have some data and a parameter, it is common to use $\theta$ for the parameter (or parameter vector) and $x$ for the data.
31,864
Estimates of random effects in binomial model (lme4)
What you're seeing is a phenomenon called shrinkage, which is a fundamental property of mixed models; individual group estimates are "shrunk" toward the overall mean as a function of the relative variance of each estimate. (While shrinkage is discussed in various answers on CrossValidated, most refer to techniques such as lasso or ridge regression; answers to this question provide connections between mixed models and other views of shrinkage.) Shrinkage is arguably desirable; it is sometimes referred to as borrowing strength. Especially when we have few samples per group, the separate estimates for each group are going to be less precise than estimates that take advantage of some pooling from each population. In a Bayesian or empirical Bayesian framework, we can think of the population-level distribution as acting as a prior for the group-level estimates. Shrinkage estimates are especially useful/powerful when (as is not the case in this example) the amount of information per group (sample size/precision) varies widely, e.g. in a spatial epidemiological model where there are regions with very small and very large populations. The shrinkage property should apply to both Bayesian and frequentist fitting approaches -- the real differences between the approaches lie at the top level (the frequentist's "penalized weighted residual sum of squares" is the Bayesian's log-posterior deviance at the group level ...) The main difference in the picture below, which shows lme4 and MCMCglmm results, is that because MCMCglmm uses a stochastic algorithm the estimates for different groups with the same observed proportions differ slightly. With a little more work, I think we could figure out the precise degree of shrinkage expected by comparing the binomial variances for the groups and the overall data set, but in the meantime here's a demonstration (the fact that the J=10 case looks less shrunk than J=20 is just sampling variation, I think). (I accidentally changed the simulation parameters to mean=0.5, RE standard deviation=0.7 (on logit scale) ...) library("lme4") library("MCMCglmm") ##' @param I number of groups ##' @param J number of Bernoulli trials within each group ##' @param theta random effects standard deviation (logit scale) ##' @param beta intercept (logit scale) simfun <- function(I=30,J=10,theta=0.7,beta=0,seed=NULL) { if (!is.null(seed)) set.seed(seed) ddd <- expand.grid(subject=factor(1:I),rep=1:J) ddd <- transform(ddd, result=suppressMessages(simulate(~1+(1|subject), family=binomial, newdata=ddd, newparams=list(theta=theta,beta=beta))[[1]])) } sumfun <- function(ddd) { fit <- glmer(result~(1|subject), data=ddd, family="binomial") fit2 <- MCMCglmm(result~1,random=~subject, data=ddd, family="categorical",verbose=FALSE, pr=TRUE) res <- data.frame( props=with(ddd,tapply(result,list(subject),mean)), lme4=plogis(coef(fit)$subject[,1]), MCMCglmm=plogis(colMeans(fit2$Sol[,-1]))) return(res) } set.seed(101) res <- do.call(rbind, lapply(c(10,20,50,100,500), function(J) { data.frame(J=J,sumfun(simfun(J=J))) })) library("reshape2") m <- melt(res,id.vars=c("J","props")) library("ggplot2"); theme_set(theme_bw()) ggplot(m,aes(props,value))+ geom_point(aes(colour=factor(J),shape=variable))+ geom_abline(intercept=0,slope=1,colour="gray")+ labs(x="observed proportion",y="estimate") ggsave("shrinkage.png",width=5,height=5)
Estimates of random effects in binomial model (lme4)
What you're seeing is a phenomenon called shrinkage, which is a fundamental property of mixed models; individual group estimates are "shrunk" toward the overall mean as a function of the relative vari
Estimates of random effects in binomial model (lme4) What you're seeing is a phenomenon called shrinkage, which is a fundamental property of mixed models; individual group estimates are "shrunk" toward the overall mean as a function of the relative variance of each estimate. (While shrinkage is discussed in various answers on CrossValidated, most refer to techniques such as lasso or ridge regression; answers to this question provide connections between mixed models and other views of shrinkage.) Shrinkage is arguably desirable; it is sometimes referred to as borrowing strength. Especially when we have few samples per group, the separate estimates for each group are going to be less precise than estimates that take advantage of some pooling from each population. In a Bayesian or empirical Bayesian framework, we can think of the population-level distribution as acting as a prior for the group-level estimates. Shrinkage estimates are especially useful/powerful when (as is not the case in this example) the amount of information per group (sample size/precision) varies widely, e.g. in a spatial epidemiological model where there are regions with very small and very large populations. The shrinkage property should apply to both Bayesian and frequentist fitting approaches -- the real differences between the approaches lie at the top level (the frequentist's "penalized weighted residual sum of squares" is the Bayesian's log-posterior deviance at the group level ...) The main difference in the picture below, which shows lme4 and MCMCglmm results, is that because MCMCglmm uses a stochastic algorithm the estimates for different groups with the same observed proportions differ slightly. With a little more work, I think we could figure out the precise degree of shrinkage expected by comparing the binomial variances for the groups and the overall data set, but in the meantime here's a demonstration (the fact that the J=10 case looks less shrunk than J=20 is just sampling variation, I think). (I accidentally changed the simulation parameters to mean=0.5, RE standard deviation=0.7 (on logit scale) ...) library("lme4") library("MCMCglmm") ##' @param I number of groups ##' @param J number of Bernoulli trials within each group ##' @param theta random effects standard deviation (logit scale) ##' @param beta intercept (logit scale) simfun <- function(I=30,J=10,theta=0.7,beta=0,seed=NULL) { if (!is.null(seed)) set.seed(seed) ddd <- expand.grid(subject=factor(1:I),rep=1:J) ddd <- transform(ddd, result=suppressMessages(simulate(~1+(1|subject), family=binomial, newdata=ddd, newparams=list(theta=theta,beta=beta))[[1]])) } sumfun <- function(ddd) { fit <- glmer(result~(1|subject), data=ddd, family="binomial") fit2 <- MCMCglmm(result~1,random=~subject, data=ddd, family="categorical",verbose=FALSE, pr=TRUE) res <- data.frame( props=with(ddd,tapply(result,list(subject),mean)), lme4=plogis(coef(fit)$subject[,1]), MCMCglmm=plogis(colMeans(fit2$Sol[,-1]))) return(res) } set.seed(101) res <- do.call(rbind, lapply(c(10,20,50,100,500), function(J) { data.frame(J=J,sumfun(simfun(J=J))) })) library("reshape2") m <- melt(res,id.vars=c("J","props")) library("ggplot2"); theme_set(theme_bw()) ggplot(m,aes(props,value))+ geom_point(aes(colour=factor(J),shape=variable))+ geom_abline(intercept=0,slope=1,colour="gray")+ labs(x="observed proportion",y="estimate") ggsave("shrinkage.png",width=5,height=5)
Estimates of random effects in binomial model (lme4) What you're seeing is a phenomenon called shrinkage, which is a fundamental property of mixed models; individual group estimates are "shrunk" toward the overall mean as a function of the relative vari
31,865
What is the relation between singular correlation matrix and PCA?
The citation and its last sentence says of the following. Singular matrix is a one where rows or columns are linearly interdependent. Most of factor analysis extraction methods require that the analyzed correlation or covariance matrix be nonsingular. It must be strictly positive definite. The reasons for it is that at various stages of the analysis (preliminary, extraction, scores) factor analysis algorithm addresses true inverse of the matrix or needs its determinant. Minimal residuals (minres) method can work with singular matrix at extraction, but it is absent in SPSS. PCA is not iterative and is not true factor analysis. Its extraction phase is single eigen-decomposition of the intact correlation matrix, which doesn't require the matrix to be full rank. Whenever it is not, one or several last eigenvalues turn out to be exactly zero rather than being small positive. Zero eigenvalue means that the corresponding dimension (component) has variance 0 and therefore does not exist. That's all; it doesn't hamper the extraction, nor it precludes computing component scores. So, you can do PCA with singular, multicollinear data. Sometimes PCA is used specifically for the purpose to get rid of the multicollinearity.
What is the relation between singular correlation matrix and PCA?
The citation and its last sentence says of the following. Singular matrix is a one where rows or columns are linearly interdependent. Most of factor analysis extraction methods require that the analyz
What is the relation between singular correlation matrix and PCA? The citation and its last sentence says of the following. Singular matrix is a one where rows or columns are linearly interdependent. Most of factor analysis extraction methods require that the analyzed correlation or covariance matrix be nonsingular. It must be strictly positive definite. The reasons for it is that at various stages of the analysis (preliminary, extraction, scores) factor analysis algorithm addresses true inverse of the matrix or needs its determinant. Minimal residuals (minres) method can work with singular matrix at extraction, but it is absent in SPSS. PCA is not iterative and is not true factor analysis. Its extraction phase is single eigen-decomposition of the intact correlation matrix, which doesn't require the matrix to be full rank. Whenever it is not, one or several last eigenvalues turn out to be exactly zero rather than being small positive. Zero eigenvalue means that the corresponding dimension (component) has variance 0 and therefore does not exist. That's all; it doesn't hamper the extraction, nor it precludes computing component scores. So, you can do PCA with singular, multicollinear data. Sometimes PCA is used specifically for the purpose to get rid of the multicollinearity.
What is the relation between singular correlation matrix and PCA? The citation and its last sentence says of the following. Singular matrix is a one where rows or columns are linearly interdependent. Most of factor analysis extraction methods require that the analyz
31,866
What is the relation between singular correlation matrix and PCA?
It's related to the mathematical property of the correlation matrix. In simple words, PCA is essentially an orthogonal transformation of the given correlation matrix, which can be either invertible or singular (I.e. doesn't have an inverse matrix).
What is the relation between singular correlation matrix and PCA?
It's related to the mathematical property of the correlation matrix. In simple words, PCA is essentially an orthogonal transformation of the given correlation matrix, which can be either invertible o
What is the relation between singular correlation matrix and PCA? It's related to the mathematical property of the correlation matrix. In simple words, PCA is essentially an orthogonal transformation of the given correlation matrix, which can be either invertible or singular (I.e. doesn't have an inverse matrix).
What is the relation between singular correlation matrix and PCA? It's related to the mathematical property of the correlation matrix. In simple words, PCA is essentially an orthogonal transformation of the given correlation matrix, which can be either invertible o
31,867
Pitfalls in Fitting Nonlinear Models by Transforming to Linearity
Some nonlinear models can be transformed into linear models. Usually only by ignoring the error term, unless by some amazing chance it enters in just such a way that the error term becomes additive after transforming. My understanding is that there might be a one-to-one relationship between the estimates of the nonlinear model and its linear model form Not in general. For example, consider: $y = \exp(\alpha+\beta x)+e$ $\log(y) = \alpha+\beta x+\eta$ where in each case the model had the variance of the error term constant. If you fit both models via least squares to the same data (nonlinear least squares and linear least squares), the parameter estimates will differ. but their corresponding standard errors are not related to each other. Yes, if we put "and" rather than "but". Here's an example in R (the model isn't really suitable, but that doesn't change the issue): > carsfit=lm(log(dist)~speed,cars) > summary(carsfit) Coefficients: Estimate Std. Error t value Pr(>|t|) (Intercept) 1.67612 0.19614 8.546 3.34e-11 speed 0.12077 0.01206 10.015 2.41e-13 Residual standard error: 0.4463 on 48 degrees of freedom Multiple R-squared: 0.6763, Adjusted R-squared: 0.6696 F-statistic: 100.3 on 1 and 48 DF, p-value: 2.413e-13 (some unnecessary output removed) vs: > carsexp=nls(dist~exp(a+b*speed),data=cars,start=list(a=1.67,b=0.12)) > summary(carsexp) Formula: dist ~ exp(a + b * speed) Parameters: Estimate Std. Error t value Pr(>|t|) a 2.24119 0.20815 10.767 2.13e-14 *** b 0.09168 0.01028 8.917 9.38e-12 *** --- Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 Residual standard error: 15.07 on 48 degrees of freedom Number of iterations to convergence: 4 Achieved convergence tolerance: 3.598e-07 Sometimes it really matters which model you choose! Are there any pitfalls in fitting Nonlinear Models by transforming to linearity? Well, possibly quite a few, depending on how broad this question is -- answering it might fill a book. Once you're clear about what your error term is, it's usually clearer whether (and how) models should transform. Clearly, at least, it potentially makes a large difference to parameter estimates. Secondly, consider if the additive error were large enough that some of the smaller observations could be negative; clearly we can't just take logs.
Pitfalls in Fitting Nonlinear Models by Transforming to Linearity
Some nonlinear models can be transformed into linear models. Usually only by ignoring the error term, unless by some amazing chance it enters in just such a way that the error term becomes additive a
Pitfalls in Fitting Nonlinear Models by Transforming to Linearity Some nonlinear models can be transformed into linear models. Usually only by ignoring the error term, unless by some amazing chance it enters in just such a way that the error term becomes additive after transforming. My understanding is that there might be a one-to-one relationship between the estimates of the nonlinear model and its linear model form Not in general. For example, consider: $y = \exp(\alpha+\beta x)+e$ $\log(y) = \alpha+\beta x+\eta$ where in each case the model had the variance of the error term constant. If you fit both models via least squares to the same data (nonlinear least squares and linear least squares), the parameter estimates will differ. but their corresponding standard errors are not related to each other. Yes, if we put "and" rather than "but". Here's an example in R (the model isn't really suitable, but that doesn't change the issue): > carsfit=lm(log(dist)~speed,cars) > summary(carsfit) Coefficients: Estimate Std. Error t value Pr(>|t|) (Intercept) 1.67612 0.19614 8.546 3.34e-11 speed 0.12077 0.01206 10.015 2.41e-13 Residual standard error: 0.4463 on 48 degrees of freedom Multiple R-squared: 0.6763, Adjusted R-squared: 0.6696 F-statistic: 100.3 on 1 and 48 DF, p-value: 2.413e-13 (some unnecessary output removed) vs: > carsexp=nls(dist~exp(a+b*speed),data=cars,start=list(a=1.67,b=0.12)) > summary(carsexp) Formula: dist ~ exp(a + b * speed) Parameters: Estimate Std. Error t value Pr(>|t|) a 2.24119 0.20815 10.767 2.13e-14 *** b 0.09168 0.01028 8.917 9.38e-12 *** --- Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 Residual standard error: 15.07 on 48 degrees of freedom Number of iterations to convergence: 4 Achieved convergence tolerance: 3.598e-07 Sometimes it really matters which model you choose! Are there any pitfalls in fitting Nonlinear Models by transforming to linearity? Well, possibly quite a few, depending on how broad this question is -- answering it might fill a book. Once you're clear about what your error term is, it's usually clearer whether (and how) models should transform. Clearly, at least, it potentially makes a large difference to parameter estimates. Secondly, consider if the additive error were large enough that some of the smaller observations could be negative; clearly we can't just take logs.
Pitfalls in Fitting Nonlinear Models by Transforming to Linearity Some nonlinear models can be transformed into linear models. Usually only by ignoring the error term, unless by some amazing chance it enters in just such a way that the error term becomes additive a
31,868
How to interpret the direction of the Harvey-Collier test and Rainbow test for linearity?
OK, I can't find great references for the Harvey-Collier test; they appear to almost all be paywalled. However, the intuition behind the rainbow test is easy to describe. Suppose you're trying to fit a linear model where it's inadequate. Let's use a very simple quadratic model for example: $X \sim N(1, 1); Y \sim X^2 + N(0, 0.2)$. The idea of the rainbow test is that, when you "zoom in" on the curve $Y = X^2 + \epsilon$ (by looking only at the central data), the curve looks less curvy--more like a line--and so the model's fit improves. So for instance, if we make a linear model on a full dataset of 100 draws from the model above, here's what we get: By contrast, if we restrict to points 1 SD away from the mean, here's what we get: As you can see, the fit improves noticeably, and the restriction also looks visibly more like a linear model. On the other hand, if the true model were linear, we wouldn't expect the fit to get much better in this scenario. (It might get a little better, because we'd be fitting to fewer data points, but linear regression would converge to the same model on the restricted data as the full dataset, so in the limit you'd get the same model on both.) The rainbow test basically quantifies how much better we'd expect the fit to get when we remove data, under the null hypothesis that the true model is linear. If the true model is not linear, then the improvement will be bigger than we expected. As for your specific question about the direction of the tests, the documentation for harvtest states: The Harvey-Collier test performs a t-test (with parameter degrees of freedom) on the recursive residuals. If the true relationship is not linear but convex or concave the mean of the recursive residuals should differ from 0 significantly. (Emphasis added.) This means that a significant result means that you can reject the null hypothesis that the true model is linear. Similarly, the documentation for raintest states: The basic idea of the Rainbow test is that even if the true relationship is non-linear, a good linear fit can be achieved on a subsample in the "middle" of the data. The null hypothesis is rejected whenever the overall fit is significantly worse than the fit for the subsample. This means that a significant result (rejecting the null) occurs when the fit is better with a range restriction (which is what happens if the model is nonlinear). So both tests suggest that the true model is not linear.
How to interpret the direction of the Harvey-Collier test and Rainbow test for linearity?
OK, I can't find great references for the Harvey-Collier test; they appear to almost all be paywalled. However, the intuition behind the rainbow test is easy to describe. Suppose you're trying to fit
How to interpret the direction of the Harvey-Collier test and Rainbow test for linearity? OK, I can't find great references for the Harvey-Collier test; they appear to almost all be paywalled. However, the intuition behind the rainbow test is easy to describe. Suppose you're trying to fit a linear model where it's inadequate. Let's use a very simple quadratic model for example: $X \sim N(1, 1); Y \sim X^2 + N(0, 0.2)$. The idea of the rainbow test is that, when you "zoom in" on the curve $Y = X^2 + \epsilon$ (by looking only at the central data), the curve looks less curvy--more like a line--and so the model's fit improves. So for instance, if we make a linear model on a full dataset of 100 draws from the model above, here's what we get: By contrast, if we restrict to points 1 SD away from the mean, here's what we get: As you can see, the fit improves noticeably, and the restriction also looks visibly more like a linear model. On the other hand, if the true model were linear, we wouldn't expect the fit to get much better in this scenario. (It might get a little better, because we'd be fitting to fewer data points, but linear regression would converge to the same model on the restricted data as the full dataset, so in the limit you'd get the same model on both.) The rainbow test basically quantifies how much better we'd expect the fit to get when we remove data, under the null hypothesis that the true model is linear. If the true model is not linear, then the improvement will be bigger than we expected. As for your specific question about the direction of the tests, the documentation for harvtest states: The Harvey-Collier test performs a t-test (with parameter degrees of freedom) on the recursive residuals. If the true relationship is not linear but convex or concave the mean of the recursive residuals should differ from 0 significantly. (Emphasis added.) This means that a significant result means that you can reject the null hypothesis that the true model is linear. Similarly, the documentation for raintest states: The basic idea of the Rainbow test is that even if the true relationship is non-linear, a good linear fit can be achieved on a subsample in the "middle" of the data. The null hypothesis is rejected whenever the overall fit is significantly worse than the fit for the subsample. This means that a significant result (rejecting the null) occurs when the fit is better with a range restriction (which is what happens if the model is nonlinear). So both tests suggest that the true model is not linear.
How to interpret the direction of the Harvey-Collier test and Rainbow test for linearity? OK, I can't find great references for the Harvey-Collier test; they appear to almost all be paywalled. However, the intuition behind the rainbow test is easy to describe. Suppose you're trying to fit
31,869
Sequential pattern matching in time series data
A few approaches come to mind but this list is far from exhaustive: Andreas Brandmaier's permutation distribution clustering is a method rooted in the dissimilarities between time series, formalized as the divergence between their permutation distributions. Personally, I think this is your "best" option http://cran.r-project.org/web/packages/pdc/index.html Eamonn Keogh's SAX (Symbolic Aggregate Approximation) and iSAX routines develop "shape clustering" for time series http://www.cs.ucr.edu/~eamonn/SAX.htm There are approaches based on text compression algorithms that remove the redundancy in a sequence of characters (or numbers), creating a kind of distance or density metric that can be used as inputs to clustering see, e.g., http://link.springer.com/chapter/10.1007/978-0-387-84816-7_4 This paper by Rob Hyndman Dimension Reduction for Clustering Time Series Using Global Characteristics, discusses compressing a time series down to a small set of global moments or metrics and clustering on those: http://www.robjhyndman.com/papers/wang2.pdf Chapter 15 in Aggarwal and Reddy's excellent book, Data Clustering, is devoted to a wide range (a laundry list, really) of time-series clustering methods (pps 357-380). The discussion provides excellent background to many of the issues specific to clustering a time series" http://users.eecs.northwestern.edu/~goce/SomePubs/Similarity-Pubs/Chapter-ClusteringTimeSeries.pdf
Sequential pattern matching in time series data
A few approaches come to mind but this list is far from exhaustive: Andreas Brandmaier's permutation distribution clustering is a method rooted in the dissimilarities between time series, formalized
Sequential pattern matching in time series data A few approaches come to mind but this list is far from exhaustive: Andreas Brandmaier's permutation distribution clustering is a method rooted in the dissimilarities between time series, formalized as the divergence between their permutation distributions. Personally, I think this is your "best" option http://cran.r-project.org/web/packages/pdc/index.html Eamonn Keogh's SAX (Symbolic Aggregate Approximation) and iSAX routines develop "shape clustering" for time series http://www.cs.ucr.edu/~eamonn/SAX.htm There are approaches based on text compression algorithms that remove the redundancy in a sequence of characters (or numbers), creating a kind of distance or density metric that can be used as inputs to clustering see, e.g., http://link.springer.com/chapter/10.1007/978-0-387-84816-7_4 This paper by Rob Hyndman Dimension Reduction for Clustering Time Series Using Global Characteristics, discusses compressing a time series down to a small set of global moments or metrics and clustering on those: http://www.robjhyndman.com/papers/wang2.pdf Chapter 15 in Aggarwal and Reddy's excellent book, Data Clustering, is devoted to a wide range (a laundry list, really) of time-series clustering methods (pps 357-380). The discussion provides excellent background to many of the issues specific to clustering a time series" http://users.eecs.northwestern.edu/~goce/SomePubs/Similarity-Pubs/Chapter-ClusteringTimeSeries.pdf
Sequential pattern matching in time series data A few approaches come to mind but this list is far from exhaustive: Andreas Brandmaier's permutation distribution clustering is a method rooted in the dissimilarities between time series, formalized
31,870
Sequential pattern matching in time series data
You can do this in R. Your time series data is represented by v and the pattern you wish to match by p. Returns match indices. > v<-c(1,2,3,4,5,6,7,8,9,1,2,3,4,6,7,5,8,1,2,3,4,5) > p<-"123" > gregexpr(p,paste(v,collapse = "")) [[1]] [1] 1 10 18 attr(,"match.length") [1] 3 3 3 attr(,"useBytes") [1] TRUE
Sequential pattern matching in time series data
You can do this in R. Your time series data is represented by v and the pattern you wish to match by p. Returns match indices. > v<-c(1,2,3,4,5,6,7,8,9,1,2,3,4,6,7,5,8,1,2,3,4,5) > p<-"123" > gregexpr
Sequential pattern matching in time series data You can do this in R. Your time series data is represented by v and the pattern you wish to match by p. Returns match indices. > v<-c(1,2,3,4,5,6,7,8,9,1,2,3,4,6,7,5,8,1,2,3,4,5) > p<-"123" > gregexpr(p,paste(v,collapse = "")) [[1]] [1] 1 10 18 attr(,"match.length") [1] 3 3 3 attr(,"useBytes") [1] TRUE
Sequential pattern matching in time series data You can do this in R. Your time series data is represented by v and the pattern you wish to match by p. Returns match indices. > v<-c(1,2,3,4,5,6,7,8,9,1,2,3,4,6,7,5,8,1,2,3,4,5) > p<-"123" > gregexpr
31,871
Deriving K-means algorithm as a limit of Expectation Maximization for Gaussian Mixtures
Let us write $$\|\textbf x_n - \boldsymbol \mu_k\|^2=\delta_k\,.$$ Then $$\frac{\pi_k \exp\{ - \| \textbf x_n - \boldsymbol \mu_k\|^2 / 2 \epsilon\}}{\sum_{j=1}^K \pi_j \exp\{ - \| \textbf x_n - \boldsymbol \mu_j\|^2 / 2 \epsilon\}}=\frac{\pi_k \exp\{ - \delta_k/ 2 \epsilon\}}{\sum_{j=1}^K \pi_j \exp\{ - \delta_j/ 2 \epsilon\}}$$ If we take$$\delta^*=\min_n\delta_n\,,$$ we have \begin{align*} \frac{\pi_k \exp\{ - \delta_k/ 2 \epsilon\}}{\sum_{j=1}^K \pi_j \exp\{ - \delta_j/ 2 \epsilon\}}&=\frac{\pi_k \exp\{(\delta^*- \delta_k)/ 2 \epsilon\}}{\sum_{j=1}^K \pi_j \exp\{(\delta^* - \delta_j)/ 2 \epsilon\}} \end{align*} where $\delta^*-\delta_k<0$ except for $k=k^*$ where $\delta^*-\delta_{k^*}=0$. So, for all $k\ne k^*$, $$\lim_{\epsilon\to 0} \frac{\pi_k \exp\{(\delta^*- \delta_k)/ 2 \epsilon\}}{\sum_{j=1}^K \pi_j \exp\{(\delta^* - \delta_j)/ 2 \epsilon\}}=\lim_{\epsilon\to 0} \frac{\pi_k \exp\{(\delta^*- \delta_k)/ 2 \epsilon\}}{\pi_{k^*}+\sum_{j\ne k^*} \pi_j \exp\{(\delta^* - \delta_j)/ 2 \epsilon\}}=0$$ since, for $a>0$, $$\lim_{\epsilon\to 0}\exp\{-a/\epsilon \}=0$$ while $$\lim_{\epsilon\to 0} \frac{\pi_{k^*} \exp\{(\delta^*- \delta_{k^*})/ 2 \epsilon\}}{\sum_{j=1}^K \pi_j \exp\{(\delta^* - \delta_j)/ 2 \epsilon\}}=\lim_{\epsilon\to 0} \frac{\pi_{k^*} \times 1}{\pi_{k^*}+\sum_{j\ne k^*} \pi_j \exp\{(\delta^* - \delta_j)/ 2 \epsilon\}}=1$$
Deriving K-means algorithm as a limit of Expectation Maximization for Gaussian Mixtures
Let us write $$\|\textbf x_n - \boldsymbol \mu_k\|^2=\delta_k\,.$$ Then $$\frac{\pi_k \exp\{ - \| \textbf x_n - \boldsymbol \mu_k\|^2 / 2 \epsilon\}}{\sum_{j=1}^K \pi_j \exp\{ - \| \textbf x_n - \bold
Deriving K-means algorithm as a limit of Expectation Maximization for Gaussian Mixtures Let us write $$\|\textbf x_n - \boldsymbol \mu_k\|^2=\delta_k\,.$$ Then $$\frac{\pi_k \exp\{ - \| \textbf x_n - \boldsymbol \mu_k\|^2 / 2 \epsilon\}}{\sum_{j=1}^K \pi_j \exp\{ - \| \textbf x_n - \boldsymbol \mu_j\|^2 / 2 \epsilon\}}=\frac{\pi_k \exp\{ - \delta_k/ 2 \epsilon\}}{\sum_{j=1}^K \pi_j \exp\{ - \delta_j/ 2 \epsilon\}}$$ If we take$$\delta^*=\min_n\delta_n\,,$$ we have \begin{align*} \frac{\pi_k \exp\{ - \delta_k/ 2 \epsilon\}}{\sum_{j=1}^K \pi_j \exp\{ - \delta_j/ 2 \epsilon\}}&=\frac{\pi_k \exp\{(\delta^*- \delta_k)/ 2 \epsilon\}}{\sum_{j=1}^K \pi_j \exp\{(\delta^* - \delta_j)/ 2 \epsilon\}} \end{align*} where $\delta^*-\delta_k<0$ except for $k=k^*$ where $\delta^*-\delta_{k^*}=0$. So, for all $k\ne k^*$, $$\lim_{\epsilon\to 0} \frac{\pi_k \exp\{(\delta^*- \delta_k)/ 2 \epsilon\}}{\sum_{j=1}^K \pi_j \exp\{(\delta^* - \delta_j)/ 2 \epsilon\}}=\lim_{\epsilon\to 0} \frac{\pi_k \exp\{(\delta^*- \delta_k)/ 2 \epsilon\}}{\pi_{k^*}+\sum_{j\ne k^*} \pi_j \exp\{(\delta^* - \delta_j)/ 2 \epsilon\}}=0$$ since, for $a>0$, $$\lim_{\epsilon\to 0}\exp\{-a/\epsilon \}=0$$ while $$\lim_{\epsilon\to 0} \frac{\pi_{k^*} \exp\{(\delta^*- \delta_{k^*})/ 2 \epsilon\}}{\sum_{j=1}^K \pi_j \exp\{(\delta^* - \delta_j)/ 2 \epsilon\}}=\lim_{\epsilon\to 0} \frac{\pi_{k^*} \times 1}{\pi_{k^*}+\sum_{j\ne k^*} \pi_j \exp\{(\delta^* - \delta_j)/ 2 \epsilon\}}=1$$
Deriving K-means algorithm as a limit of Expectation Maximization for Gaussian Mixtures Let us write $$\|\textbf x_n - \boldsymbol \mu_k\|^2=\delta_k\,.$$ Then $$\frac{\pi_k \exp\{ - \| \textbf x_n - \boldsymbol \mu_k\|^2 / 2 \epsilon\}}{\sum_{j=1}^K \pi_j \exp\{ - \| \textbf x_n - \bold
31,872
Why did KS test give significant result?
The K-S is an omnibus test. It doesn't identify the form of difference. You can identify the place or places where the difference in ECDF is largest but that doesn't always tell you much. You can spot some kinds of change in the ECDF. Here's some examples: If you look at the ECDFs in your post, you can see the blue cdf is lower than the red across pretty much the entire range (which implies the blue values are typically larger*), though the shape is broadly similar. * You can also see that in the histogram where the pink is higher in the leftmost bar, but past 300 the blue bars are typically a little taller. So anyway, that's how I'd describe the main difference in distributions (somewhat similar in general shape, but the values in the blue category tend to be a bit larger on average). I wouldn't characterize it as either a location shift or a scale-shift. One thing that worries me is that the distribution looks quite discrete. If so, the p-value from the Kolmogorov-Smirnov test isn't particularly meaningful. What's your sample size?
Why did KS test give significant result?
The K-S is an omnibus test. It doesn't identify the form of difference. You can identify the place or places where the difference in ECDF is largest but that doesn't always tell you much. You can spo
Why did KS test give significant result? The K-S is an omnibus test. It doesn't identify the form of difference. You can identify the place or places where the difference in ECDF is largest but that doesn't always tell you much. You can spot some kinds of change in the ECDF. Here's some examples: If you look at the ECDFs in your post, you can see the blue cdf is lower than the red across pretty much the entire range (which implies the blue values are typically larger*), though the shape is broadly similar. * You can also see that in the histogram where the pink is higher in the leftmost bar, but past 300 the blue bars are typically a little taller. So anyway, that's how I'd describe the main difference in distributions (somewhat similar in general shape, but the values in the blue category tend to be a bit larger on average). I wouldn't characterize it as either a location shift or a scale-shift. One thing that worries me is that the distribution looks quite discrete. If so, the p-value from the Kolmogorov-Smirnov test isn't particularly meaningful. What's your sample size?
Why did KS test give significant result? The K-S is an omnibus test. It doesn't identify the form of difference. You can identify the place or places where the difference in ECDF is largest but that doesn't always tell you much. You can spo
31,873
Why did KS test give significant result?
As far as I know, the (two sample) K-S test is not that helpful in telling you how the two distributions differ, as it compares both location and shape. If you think the difference lies in location, run a Mann-Whitney. If you think it lies in shape...that's more complicated. Some people calculate GINI to compare skewness. Others recommend running bootstraps, so you get (say) 10,000 skewness and kurtosis scores per sample, and then you can just run a t-test to compare them. This has always seemed a bit odd to me, though.
Why did KS test give significant result?
As far as I know, the (two sample) K-S test is not that helpful in telling you how the two distributions differ, as it compares both location and shape. If you think the difference lies in location, r
Why did KS test give significant result? As far as I know, the (two sample) K-S test is not that helpful in telling you how the two distributions differ, as it compares both location and shape. If you think the difference lies in location, run a Mann-Whitney. If you think it lies in shape...that's more complicated. Some people calculate GINI to compare skewness. Others recommend running bootstraps, so you get (say) 10,000 skewness and kurtosis scores per sample, and then you can just run a t-test to compare them. This has always seemed a bit odd to me, though.
Why did KS test give significant result? As far as I know, the (two sample) K-S test is not that helpful in telling you how the two distributions differ, as it compares both location and shape. If you think the difference lies in location, r
31,874
What is the correct formula for between-class scatter matrix in LDA?
Within- and between-class scatter matrices in LDA are direct multivariate generalizations of the within- and between-class sums of squares in ANOVA. So let us consider those. The idea is to decompose the total sum of squares into two parts. Let $x_{ij}$ be a $j$-th data point from the $i$-th class with $n_i$ data points. Total sum of squares and within-class sum of squares are given by the obvious expressions: \begin{equation} T = \sum_{ij} (x_{ij} - \bar x)^2 \\ W = \sum_{ij} (x_{ij} - \bar x_i)^2 \end{equation} Let us now derive the expression for the between-class sum of squares: \begin{equation} x_{ij} - \bar x = (\bar x_i - \bar x) + (x_{ij} - \bar x_i) \\ (x_{ij} - \bar x)^2 = (\bar x_i - \bar x)^2 + (x_{ij} - \bar x_i)^2 + 2(\bar x_i - \bar x)(x_{ij} - \bar x_i) \\ \sum_{ij}(x_{ij} - \bar x)^2 = \sum_{ij}(\bar x_i - \bar x)^2 + \sum_{ij}(x_{ij} - \bar x_i)^2 + 2\sum_i\left[(\bar x_i - \bar x)\sum_j(x_{ij} - \bar x_i)\right] \\ T = \sum_i n_i (\bar x_i - \bar x)^2 + W \end{equation} and so we see that a reasonable definition for between-class sum of squares is $$B = \sum_i n_i (\bar x_i - \bar x)^2,$$ so that $T=B+W$. The generalization to the multivariate case is straightforward: replace all $x^2$ by $\mathbf x \mathbf x^\top$, and that's it. So the correct expression for LDA is your first formula. As I said above in the comments, I cannot imagine any justification for the alternative formula (what you called $B^*$). In all the machine learning textbooks I know, the standard formula is always used. See e.g. Bishop's "Pattern Recognition and Machine Learning". Update I think I realized when the alternative formula might make sense. If the classes are very different in size, then the between-class scatter matrix $$\mathbf B=\sum_i n_i(\bar{\mathbf x}_i - \bar{ \mathbf x})(\bar{\mathbf x}_i - \bar{\mathbf x})^\top$$ will be dominated by the large classes. Imagine three classes with large $n_1$ and $n_2$, and small $n_3$. Then $\mathbf B$ will be hardly influenced by the third class at all, hence LDA will be looking for projections separating first two classes but will not care much about how well the third class is separated. This is not always desired. One might choose to "re-balance" such an unbalanced case and define $$\mathbf B^* = \bar n \sum_i (\bar{\mathbf x}_i - \bar{ \mathbf x}^*)(\bar{\mathbf x}_i - \bar{\mathbf x}^*)^\top,$$ where $\bar{ \mathbf x}^*$ is the mean of class means and $\bar n = \sum n_i / k$ is the mean number of points per class. This puts all classes on equal footing independent of their size, and might result in more meaningful projections. Note that this will violate the decomposition of the sum of squares: $\mathbf T = \mathbf B + \mathbf W \ne \mathbf B^* + \mathbf W$, but this can be regarded as no big deal. However, the identity can be restored if the within-class and total scatter matrix are also defined in a "balanced" way: \begin{equation} \mathbf T^* = \bar n \sum_{i} \frac{1}{n_i} \sum_j (\mathbf x_{ij} - \bar{\mathbf x}^*)(\mathbf x_{ij} - \bar{\mathbf x}^*)^\top \\ \mathbf W^* = \bar n \sum_{i}\frac{1}{n_i}\sum_j (\bar{\mathbf x}_{ij} - \bar{ \mathbf x}_i)(\bar{\mathbf x}_{ij} - \bar{\mathbf x}_i)^\top \\ \mathbf B^* = \bar n \sum_i (\bar{\mathbf x}_i - \bar{ \mathbf x}^*)(\bar{\mathbf x}_i - \bar{\mathbf x}^*)^\top. \end{equation} If all $n_i$ are equal, these formulas will coincide with the standard ones.
What is the correct formula for between-class scatter matrix in LDA?
Within- and between-class scatter matrices in LDA are direct multivariate generalizations of the within- and between-class sums of squares in ANOVA. So let us consider those. The idea is to decompose
What is the correct formula for between-class scatter matrix in LDA? Within- and between-class scatter matrices in LDA are direct multivariate generalizations of the within- and between-class sums of squares in ANOVA. So let us consider those. The idea is to decompose the total sum of squares into two parts. Let $x_{ij}$ be a $j$-th data point from the $i$-th class with $n_i$ data points. Total sum of squares and within-class sum of squares are given by the obvious expressions: \begin{equation} T = \sum_{ij} (x_{ij} - \bar x)^2 \\ W = \sum_{ij} (x_{ij} - \bar x_i)^2 \end{equation} Let us now derive the expression for the between-class sum of squares: \begin{equation} x_{ij} - \bar x = (\bar x_i - \bar x) + (x_{ij} - \bar x_i) \\ (x_{ij} - \bar x)^2 = (\bar x_i - \bar x)^2 + (x_{ij} - \bar x_i)^2 + 2(\bar x_i - \bar x)(x_{ij} - \bar x_i) \\ \sum_{ij}(x_{ij} - \bar x)^2 = \sum_{ij}(\bar x_i - \bar x)^2 + \sum_{ij}(x_{ij} - \bar x_i)^2 + 2\sum_i\left[(\bar x_i - \bar x)\sum_j(x_{ij} - \bar x_i)\right] \\ T = \sum_i n_i (\bar x_i - \bar x)^2 + W \end{equation} and so we see that a reasonable definition for between-class sum of squares is $$B = \sum_i n_i (\bar x_i - \bar x)^2,$$ so that $T=B+W$. The generalization to the multivariate case is straightforward: replace all $x^2$ by $\mathbf x \mathbf x^\top$, and that's it. So the correct expression for LDA is your first formula. As I said above in the comments, I cannot imagine any justification for the alternative formula (what you called $B^*$). In all the machine learning textbooks I know, the standard formula is always used. See e.g. Bishop's "Pattern Recognition and Machine Learning". Update I think I realized when the alternative formula might make sense. If the classes are very different in size, then the between-class scatter matrix $$\mathbf B=\sum_i n_i(\bar{\mathbf x}_i - \bar{ \mathbf x})(\bar{\mathbf x}_i - \bar{\mathbf x})^\top$$ will be dominated by the large classes. Imagine three classes with large $n_1$ and $n_2$, and small $n_3$. Then $\mathbf B$ will be hardly influenced by the third class at all, hence LDA will be looking for projections separating first two classes but will not care much about how well the third class is separated. This is not always desired. One might choose to "re-balance" such an unbalanced case and define $$\mathbf B^* = \bar n \sum_i (\bar{\mathbf x}_i - \bar{ \mathbf x}^*)(\bar{\mathbf x}_i - \bar{\mathbf x}^*)^\top,$$ where $\bar{ \mathbf x}^*$ is the mean of class means and $\bar n = \sum n_i / k$ is the mean number of points per class. This puts all classes on equal footing independent of their size, and might result in more meaningful projections. Note that this will violate the decomposition of the sum of squares: $\mathbf T = \mathbf B + \mathbf W \ne \mathbf B^* + \mathbf W$, but this can be regarded as no big deal. However, the identity can be restored if the within-class and total scatter matrix are also defined in a "balanced" way: \begin{equation} \mathbf T^* = \bar n \sum_{i} \frac{1}{n_i} \sum_j (\mathbf x_{ij} - \bar{\mathbf x}^*)(\mathbf x_{ij} - \bar{\mathbf x}^*)^\top \\ \mathbf W^* = \bar n \sum_{i}\frac{1}{n_i}\sum_j (\bar{\mathbf x}_{ij} - \bar{ \mathbf x}_i)(\bar{\mathbf x}_{ij} - \bar{\mathbf x}_i)^\top \\ \mathbf B^* = \bar n \sum_i (\bar{\mathbf x}_i - \bar{ \mathbf x}^*)(\bar{\mathbf x}_i - \bar{\mathbf x}^*)^\top. \end{equation} If all $n_i$ are equal, these formulas will coincide with the standard ones.
What is the correct formula for between-class scatter matrix in LDA? Within- and between-class scatter matrices in LDA are direct multivariate generalizations of the within- and between-class sums of squares in ANOVA. So let us consider those. The idea is to decompose
31,875
What is the correct formula for between-class scatter matrix in LDA?
[@ttnphns' remark: This answer looks like a question/comment to @amoeba's answer] Amoeba, whats $\bar{x}_{ij}$ in W* stand for? Maybe just $x_{ij}$? And in B* you wrote $\bar{x}$*, but maybe its must be $\bar{x}$ (whole mean)? So: \begin{equation} \mathbf T^* = \bar n \sum_{i} \frac{1}{n_i} \sum_j ({\mathbf x}_{ij} - \bar{\mathbf x})({\mathbf x}_{ij} - \bar{\mathbf x})^\top \\ \mathbf W^* = \bar n \sum_{i}\frac{1}{n_i}\sum_j ({\mathbf x}_{ij} - \bar{ \mathbf x}_i)({\mathbf x}_{ij} - \bar{\mathbf x}_i)^\top \\ \mathbf B^* = \bar n \sum_i (\bar{\mathbf x}_i - \bar{ \mathbf x})(\bar{\mathbf x}_i - \bar{\mathbf x})^\top. \end{equation} ? If so, then it's accurate coincide when all $n_i$ are equal, like so: \begin{equation} \mathbf W^* = \frac{kn}{k}\frac{1}{n} \sum_{i}\sum_j ({\mathbf x}_{ij} - \bar{ \mathbf x}_i)({\mathbf x}_{ij} - \bar{\mathbf x}_i)^\top = \sum_{i}\sum_j ({\mathbf x}_{ij} - \bar{ \mathbf x}_i)({\mathbf x}_{ij} - \bar{\mathbf x}_i)^\top\\ \mathbf B^* = \frac{kn}{k} \sum_i (\bar{\mathbf x}_i - \bar{ \mathbf x})(\bar{\mathbf x}_i - \bar{\mathbf x})^\top = \sum_i n_{[i]}(\bar{\mathbf x}_i - \bar{ \mathbf x})(\bar{\mathbf x}_i - \bar{\mathbf x})^\top. \end{equation}
What is the correct formula for between-class scatter matrix in LDA?
[@ttnphns' remark: This answer looks like a question/comment to @amoeba's answer] Amoeba, whats $\bar{x}_{ij}$ in W* stand for? Maybe just $x_{ij}$? And in B* you wrote $\bar{x}$*, but maybe its must
What is the correct formula for between-class scatter matrix in LDA? [@ttnphns' remark: This answer looks like a question/comment to @amoeba's answer] Amoeba, whats $\bar{x}_{ij}$ in W* stand for? Maybe just $x_{ij}$? And in B* you wrote $\bar{x}$*, but maybe its must be $\bar{x}$ (whole mean)? So: \begin{equation} \mathbf T^* = \bar n \sum_{i} \frac{1}{n_i} \sum_j ({\mathbf x}_{ij} - \bar{\mathbf x})({\mathbf x}_{ij} - \bar{\mathbf x})^\top \\ \mathbf W^* = \bar n \sum_{i}\frac{1}{n_i}\sum_j ({\mathbf x}_{ij} - \bar{ \mathbf x}_i)({\mathbf x}_{ij} - \bar{\mathbf x}_i)^\top \\ \mathbf B^* = \bar n \sum_i (\bar{\mathbf x}_i - \bar{ \mathbf x})(\bar{\mathbf x}_i - \bar{\mathbf x})^\top. \end{equation} ? If so, then it's accurate coincide when all $n_i$ are equal, like so: \begin{equation} \mathbf W^* = \frac{kn}{k}\frac{1}{n} \sum_{i}\sum_j ({\mathbf x}_{ij} - \bar{ \mathbf x}_i)({\mathbf x}_{ij} - \bar{\mathbf x}_i)^\top = \sum_{i}\sum_j ({\mathbf x}_{ij} - \bar{ \mathbf x}_i)({\mathbf x}_{ij} - \bar{\mathbf x}_i)^\top\\ \mathbf B^* = \frac{kn}{k} \sum_i (\bar{\mathbf x}_i - \bar{ \mathbf x})(\bar{\mathbf x}_i - \bar{\mathbf x})^\top = \sum_i n_{[i]}(\bar{\mathbf x}_i - \bar{ \mathbf x})(\bar{\mathbf x}_i - \bar{\mathbf x})^\top. \end{equation}
What is the correct formula for between-class scatter matrix in LDA? [@ttnphns' remark: This answer looks like a question/comment to @amoeba's answer] Amoeba, whats $\bar{x}_{ij}$ in W* stand for? Maybe just $x_{ij}$? And in B* you wrote $\bar{x}$*, but maybe its must
31,876
Can the mean lie outside the the interquartile range (Q1 and Q3)? and if so what does it do to the distribution
If "mean" refers to a statistic for a batch of data, then consider the dataset $(1,2,3,4,10^6)$ whose quartiles must lie between $1$ and $4$ (depending on how you compute them) but whose mean is $200,002$. If instead it refers to a property of a distribution, then assign a probability of $1/5$ to each of the five numbers in the previous batch to create a (discrete) distribution. The same calculations apply, leading to the same conclusions. The point is that quartiles are resistant to changes in the data, whereas the mean is sensitive to changes in even any one data value. When we add $\epsilon$ to any single value in a dataset of $n\gt 4$ numbers, the mean changes by $\epsilon/n$--which may be arbitrarily large--but the quartiles (if they change at all) only shift to the neighboring values in the original dataset and therefore are limited in how much they can change. The preceding example exploited this in an extreme way. Influence functions study how such changes in data values create changes in statistical summaries of those values.
Can the mean lie outside the the interquartile range (Q1 and Q3)? and if so what does it do to the d
If "mean" refers to a statistic for a batch of data, then consider the dataset $(1,2,3,4,10^6)$ whose quartiles must lie between $1$ and $4$ (depending on how you compute them) but whose mean is $200,
Can the mean lie outside the the interquartile range (Q1 and Q3)? and if so what does it do to the distribution If "mean" refers to a statistic for a batch of data, then consider the dataset $(1,2,3,4,10^6)$ whose quartiles must lie between $1$ and $4$ (depending on how you compute them) but whose mean is $200,002$. If instead it refers to a property of a distribution, then assign a probability of $1/5$ to each of the five numbers in the previous batch to create a (discrete) distribution. The same calculations apply, leading to the same conclusions. The point is that quartiles are resistant to changes in the data, whereas the mean is sensitive to changes in even any one data value. When we add $\epsilon$ to any single value in a dataset of $n\gt 4$ numbers, the mean changes by $\epsilon/n$--which may be arbitrarily large--but the quartiles (if they change at all) only shift to the neighboring values in the original dataset and therefore are limited in how much they can change. The preceding example exploited this in an extreme way. Influence functions study how such changes in data values create changes in statistical summaries of those values.
Can the mean lie outside the the interquartile range (Q1 and Q3)? and if so what does it do to the d If "mean" refers to a statistic for a batch of data, then consider the dataset $(1,2,3,4,10^6)$ whose quartiles must lie between $1$ and $4$ (depending on how you compute them) but whose mean is $200,
31,877
Expectation of von Mises Fisher Distribution
You can derive the answer as follows. Start with the definition of the normalizing constant: $$ \int \exp(\kappa \mu^{T} x) dx = \frac{(2\pi)^{p/2-1} I_{p/2-1}(\kappa)}{\kappa^{p/2-1}} $$ (Note I have corrected an error in the question.) Let $y = \kappa \mu$ so that $y$ is an unconstrained vector with $\kappa = \sqrt{y^T y}$. It is easy to show that $d\kappa/dy = \mu$. $$ \int x \exp(y^T x) dx = \frac{d}{dy} \int \exp(y^T x) dx \\ = \frac{d\kappa}{dy} \frac{d}{d\kappa} \int \exp(y^T x) dx \\ = \mu \frac{d}{d\kappa} \frac{(2\pi)^{p/2-1} I_{p/2-1}(\kappa)}{\kappa^{p/2-1}} \\ = \mu \left(\frac{I'_{p/2-1}(\kappa)}{I_{p/2-1}(\kappa)} - \frac{p/2-1}{\kappa}\right) \frac{(2\pi)^{p/2-1} I_{p/2-1}(\kappa)}{\kappa^{p/2-1}} $$ $$ E(x) = \frac{\int x \exp(y^T x) dx}{\int \exp(y^T x) dx} = \mu \left(\frac{I'_{p/2-1}(\kappa)}{I_{p/2-1}(\kappa)} - \frac{p/2-1}{\kappa}\right) $$ Note $I'$ can be written in terms of $I$, as explained in wikipedia.
Expectation of von Mises Fisher Distribution
You can derive the answer as follows. Start with the definition of the normalizing constant: $$ \int \exp(\kappa \mu^{T} x) dx = \frac{(2\pi)^{p/2-1} I_{p/2-1}(\kappa)}{\kappa^{p/2-1}} $$ (Note I hav
Expectation of von Mises Fisher Distribution You can derive the answer as follows. Start with the definition of the normalizing constant: $$ \int \exp(\kappa \mu^{T} x) dx = \frac{(2\pi)^{p/2-1} I_{p/2-1}(\kappa)}{\kappa^{p/2-1}} $$ (Note I have corrected an error in the question.) Let $y = \kappa \mu$ so that $y$ is an unconstrained vector with $\kappa = \sqrt{y^T y}$. It is easy to show that $d\kappa/dy = \mu$. $$ \int x \exp(y^T x) dx = \frac{d}{dy} \int \exp(y^T x) dx \\ = \frac{d\kappa}{dy} \frac{d}{d\kappa} \int \exp(y^T x) dx \\ = \mu \frac{d}{d\kappa} \frac{(2\pi)^{p/2-1} I_{p/2-1}(\kappa)}{\kappa^{p/2-1}} \\ = \mu \left(\frac{I'_{p/2-1}(\kappa)}{I_{p/2-1}(\kappa)} - \frac{p/2-1}{\kappa}\right) \frac{(2\pi)^{p/2-1} I_{p/2-1}(\kappa)}{\kappa^{p/2-1}} $$ $$ E(x) = \frac{\int x \exp(y^T x) dx}{\int \exp(y^T x) dx} = \mu \left(\frac{I'_{p/2-1}(\kappa)}{I_{p/2-1}(\kappa)} - \frac{p/2-1}{\kappa}\right) $$ Note $I'$ can be written in terms of $I$, as explained in wikipedia.
Expectation of von Mises Fisher Distribution You can derive the answer as follows. Start with the definition of the normalizing constant: $$ \int \exp(\kappa \mu^{T} x) dx = \frac{(2\pi)^{p/2-1} I_{p/2-1}(\kappa)}{\kappa^{p/2-1}} $$ (Note I hav
31,878
Expectation of von Mises Fisher Distribution
This is more like an extended comment rather than a full answer. I am working on a problem that is, I think, somewhat related to the question so I share my thoughts. In what sense are you interested in the expectation? For example, for $\kappa = 0$ I don't think you can define a sensible expectation which is location "on" the sphere. Let \begin{equation} c_d(\kappa) = \frac{\kappa^{p/2-1}}{2\pi I_{p/2-1}(\kappa)} \text, \end{equation} so the normalization constant is easier to handle. Note that the problem is symmetric for rotation, so you can take, say, $\mu = e_1 = (1, 0, 0, \ldots, 0)$. In this case the PDF is simply \begin{equation} P(x) = c_p(\kappa) \exp(\kappa x_1) \text. \end{equation} If you then take the expectation of $x$ componentwise, you get for each $x_i$, $i = 2, 3, \ldots, p$ \begin{equation} \mathbb{E}[x_i] = \int_{x_i \in S^{p - 1}} x_i c_p(\kappa) \exp{\kappa x_1} \,dx_i \text, \tag{*} \end{equation} where $S^{p - 1} = \{x \in \mathbb{R}^p : |x| = 1\}$ the $(p - 1)$-sphere on which the $p$-variate vMF distribution is defined. Now divide $S^{p - 1}$ into two "hemispheres" $H_1$ and $H_2$, \begin{align} H_1 &= \{x \in S^{p - 1} : x_i \ge 0\} \text, \\ H_2 &= \{x \in S^{p - 1} : x_i < 0\} \text. \end{align} It doesn't really matter which inequality is strict, the integrand of (*) vanishes for $x_i = 0$ anyway. Now let's write (*) using $H_1$ and $H_2$ (remember that $i \ne 1$, so $x_i$ will not appear in the argument of $\exp$), \begin{align} \mathbb{E}[x_i] &= \int_{x_i \in H_1 \cup H_2} x_i c_p(\kappa) \exp{\kappa x_1} \,dx_i \\ &= \int_{x_i \in H_1} x_i c_p(\kappa) \exp{\kappa x_1} + \int_{x_i \in H_2} x_i c_p(\kappa) \exp{\kappa x_1} \\ &= \int_{x_i \in H_1} x_i c_p(\kappa) \exp{\kappa x_1} + \int_{x_i \in H_1} -x_i c_p(\kappa) \exp{\kappa x_1} \\ &= 0 \text. \end{align} Well, the situation for $x_1$ is considerably harder, as evaluating $\mathbb{E}[x_1]$ would result in and ugly mess of Gamma and modified Bessel functions... For $\kappa = 0$, we have the uniform distribution on $S^{p - 1}$, so $\mathbb{E}[x_1] = 0$. For $\kappa > 0$, intuitively, there is more probability mass on the $x_1 \ge 0$ "hemisphere" than on the $x_1 < 0$ "hemisphere", so $\mathbb{E}[x_1]$ should be $> 0$. If we accept the handwaving above (or do the integration for real), we get $\mathbb{E}[x] = \mathbb{E}[x_1] e_1 = \mathbb{E}[x_1] \mu$. Combined with the fact that $\mathbb{E}[x_1] > 0$, this is vector pointing to the same direction as $\mu$. To get a vector that lies in $S^{p - 1}$, we can normalize to get \begin{equation} \frac{\mathbb{E}[x]}{|\mathbb{E}[x]|} = \frac{\mathbb{E}[x_1]\mu}{|\mathbb{E}[x_1]|} = \mu \text. \end{equation} If you remove the middle part of the equality above, the result will hold for any $\mu$ by rotation. In this sense, yes, the expectation of the vMF distribution on the unit sphre is $\mu$ for $\kappa > 0$. For $\kappa = 1$, $\mathbb{E}[x] = 0$ (in the Euclidean sense) and the normalization will fail. The distribution of $x_i$ (with $\mu = e_1$) is interesting for another reason, only slightly related to your question. It is the same thing for cosine similarity (or after a bit of scaling and shifting, cosine distance) and the vMF distribution that the $\chi$-distribution is for the Euclidean distance and the Gaussian distribution. That is, \begin{align} \chi &= |x - \mu| && \text{for $x \sim \mathcal{N}(\mu, 1)$,} \\ \text{like } x_1 &= \mu^T x = \frac{\mu^T x}{|\mu| \cdot |x|} && \text{for $x \sim \mathrm{vMF}(\mu, \kappa)$.} \end{align}
Expectation of von Mises Fisher Distribution
This is more like an extended comment rather than a full answer. I am working on a problem that is, I think, somewhat related to the question so I share my thoughts. In what sense are you interested i
Expectation of von Mises Fisher Distribution This is more like an extended comment rather than a full answer. I am working on a problem that is, I think, somewhat related to the question so I share my thoughts. In what sense are you interested in the expectation? For example, for $\kappa = 0$ I don't think you can define a sensible expectation which is location "on" the sphere. Let \begin{equation} c_d(\kappa) = \frac{\kappa^{p/2-1}}{2\pi I_{p/2-1}(\kappa)} \text, \end{equation} so the normalization constant is easier to handle. Note that the problem is symmetric for rotation, so you can take, say, $\mu = e_1 = (1, 0, 0, \ldots, 0)$. In this case the PDF is simply \begin{equation} P(x) = c_p(\kappa) \exp(\kappa x_1) \text. \end{equation} If you then take the expectation of $x$ componentwise, you get for each $x_i$, $i = 2, 3, \ldots, p$ \begin{equation} \mathbb{E}[x_i] = \int_{x_i \in S^{p - 1}} x_i c_p(\kappa) \exp{\kappa x_1} \,dx_i \text, \tag{*} \end{equation} where $S^{p - 1} = \{x \in \mathbb{R}^p : |x| = 1\}$ the $(p - 1)$-sphere on which the $p$-variate vMF distribution is defined. Now divide $S^{p - 1}$ into two "hemispheres" $H_1$ and $H_2$, \begin{align} H_1 &= \{x \in S^{p - 1} : x_i \ge 0\} \text, \\ H_2 &= \{x \in S^{p - 1} : x_i < 0\} \text. \end{align} It doesn't really matter which inequality is strict, the integrand of (*) vanishes for $x_i = 0$ anyway. Now let's write (*) using $H_1$ and $H_2$ (remember that $i \ne 1$, so $x_i$ will not appear in the argument of $\exp$), \begin{align} \mathbb{E}[x_i] &= \int_{x_i \in H_1 \cup H_2} x_i c_p(\kappa) \exp{\kappa x_1} \,dx_i \\ &= \int_{x_i \in H_1} x_i c_p(\kappa) \exp{\kappa x_1} + \int_{x_i \in H_2} x_i c_p(\kappa) \exp{\kappa x_1} \\ &= \int_{x_i \in H_1} x_i c_p(\kappa) \exp{\kappa x_1} + \int_{x_i \in H_1} -x_i c_p(\kappa) \exp{\kappa x_1} \\ &= 0 \text. \end{align} Well, the situation for $x_1$ is considerably harder, as evaluating $\mathbb{E}[x_1]$ would result in and ugly mess of Gamma and modified Bessel functions... For $\kappa = 0$, we have the uniform distribution on $S^{p - 1}$, so $\mathbb{E}[x_1] = 0$. For $\kappa > 0$, intuitively, there is more probability mass on the $x_1 \ge 0$ "hemisphere" than on the $x_1 < 0$ "hemisphere", so $\mathbb{E}[x_1]$ should be $> 0$. If we accept the handwaving above (or do the integration for real), we get $\mathbb{E}[x] = \mathbb{E}[x_1] e_1 = \mathbb{E}[x_1] \mu$. Combined with the fact that $\mathbb{E}[x_1] > 0$, this is vector pointing to the same direction as $\mu$. To get a vector that lies in $S^{p - 1}$, we can normalize to get \begin{equation} \frac{\mathbb{E}[x]}{|\mathbb{E}[x]|} = \frac{\mathbb{E}[x_1]\mu}{|\mathbb{E}[x_1]|} = \mu \text. \end{equation} If you remove the middle part of the equality above, the result will hold for any $\mu$ by rotation. In this sense, yes, the expectation of the vMF distribution on the unit sphre is $\mu$ for $\kappa > 0$. For $\kappa = 1$, $\mathbb{E}[x] = 0$ (in the Euclidean sense) and the normalization will fail. The distribution of $x_i$ (with $\mu = e_1$) is interesting for another reason, only slightly related to your question. It is the same thing for cosine similarity (or after a bit of scaling and shifting, cosine distance) and the vMF distribution that the $\chi$-distribution is for the Euclidean distance and the Gaussian distribution. That is, \begin{align} \chi &= |x - \mu| && \text{for $x \sim \mathcal{N}(\mu, 1)$,} \\ \text{like } x_1 &= \mu^T x = \frac{\mu^T x}{|\mu| \cdot |x|} && \text{for $x \sim \mathrm{vMF}(\mu, \kappa)$.} \end{align}
Expectation of von Mises Fisher Distribution This is more like an extended comment rather than a full answer. I am working on a problem that is, I think, somewhat related to the question so I share my thoughts. In what sense are you interested i
31,879
AIC criterion: definition
Of course, you get the same answer without the factor of 2. Burnham & Anderson refer to Akaike's multiplication by -2 as done for "historical reasons." I believe what they mean is the following. Historically, AIC was developed in the context of linear regression, which assumes errors are iid mean 0. Oneof the classic ways to fit such models was chi-square fitting. Twice the NLL happens to exactly equal the chi-square value (see https://en.wikipedia.org/wiki/Akaike_information_criterion#Chi-squared_fits). I believe that is why Akaike multiplied the loglikelihood by -2, so as to make it equivalent. Also, see section 4 of this paper.
AIC criterion: definition
Of course, you get the same answer without the factor of 2. Burnham & Anderson refer to Akaike's multiplication by -2 as done for "historical reasons." I believe what they mean is the following. Histo
AIC criterion: definition Of course, you get the same answer without the factor of 2. Burnham & Anderson refer to Akaike's multiplication by -2 as done for "historical reasons." I believe what they mean is the following. Historically, AIC was developed in the context of linear regression, which assumes errors are iid mean 0. Oneof the classic ways to fit such models was chi-square fitting. Twice the NLL happens to exactly equal the chi-square value (see https://en.wikipedia.org/wiki/Akaike_information_criterion#Chi-squared_fits). I believe that is why Akaike multiplied the loglikelihood by -2, so as to make it equivalent. Also, see section 4 of this paper.
AIC criterion: definition Of course, you get the same answer without the factor of 2. Burnham & Anderson refer to Akaike's multiplication by -2 as done for "historical reasons." I believe what they mean is the following. Histo
31,880
AIC criterion: definition
The −2ln(l) is the deviance of a model, and it is useful to compare models of the same size (same number of variables). All the likelihood ratio tests is based in the comparison of the deviances between models, and the 2 is necessary for know the theoretical distribution of the statistic (chi-squared) The deviance decreases always when you add one variable to the model and the 2k of the AIC is a penalization for evaluate if this decrement is small. Then, the AIC is useful to compare models of different sizes. Deleting the 2 of the formulas, it is the same, but conceptually with the 2 you see the relationship between deviance and AIC.
AIC criterion: definition
The −2ln(l) is the deviance of a model, and it is useful to compare models of the same size (same number of variables). All the likelihood ratio tests is based in the comparison of the deviances betwe
AIC criterion: definition The −2ln(l) is the deviance of a model, and it is useful to compare models of the same size (same number of variables). All the likelihood ratio tests is based in the comparison of the deviances between models, and the 2 is necessary for know the theoretical distribution of the statistic (chi-squared) The deviance decreases always when you add one variable to the model and the 2k of the AIC is a penalization for evaluate if this decrement is small. Then, the AIC is useful to compare models of different sizes. Deleting the 2 of the formulas, it is the same, but conceptually with the 2 you see the relationship between deviance and AIC.
AIC criterion: definition The −2ln(l) is the deviance of a model, and it is useful to compare models of the same size (same number of variables). All the likelihood ratio tests is based in the comparison of the deviances betwe
31,881
Why autocorrelation affects OLS coefficient standard errors?
Suppose your OLS regression is well specified and contains all the right explanatory variables, but you have an unspecified correlation structure of the residuals: $$ y_t = x_t' \beta + \epsilon_t, \mathbb{V}[\mathbf{\epsilon}]=\Omega $$ The OLS estimates are $$ \hat\beta = (X'X)^{-1} X'Y = \beta + (X'X)^{-1} X'\mathbf{\epsilon} $$ and their variance is $$ \mathbb{V}[\hat\beta] = \mathbb{E} [ (X'X)^{-1} X'\mathbf{\epsilon}\mathbf{\epsilon}'X (X'X)^{-1} ] $$ Typically, at this stage, we'd have to assume something like existence of the probability limit of $\frac1T (X'X) \to \Sigma$, so that $$ T \mathbb{V}[\hat\beta] \to \Sigma^{-1} {\rm plim} \bigl[ \frac1T X'\mathbf{\epsilon}\mathbf{\epsilon}'X \bigr] \Sigma^{-1} = \Sigma^{-1} {\rm plim} \bigl[ \frac1T X'\Omega X \bigr] \Sigma^{-1} $$ This expression is different from what the naive OLS standard errors produce, and so in general the OLS standard errors are wrong. Of course, if $X$ can be considered fixed, then there is no need for asymptotic approximations, and $X$ can be carried through the expectations, so that $$ \mathbb{V}[\hat\beta] = (X'X)^{-1} X'\Omega X (X'X)^{-1} $$ to the same effect.
Why autocorrelation affects OLS coefficient standard errors?
Suppose your OLS regression is well specified and contains all the right explanatory variables, but you have an unspecified correlation structure of the residuals: $$ y_t = x_t' \beta + \epsilon_t, \m
Why autocorrelation affects OLS coefficient standard errors? Suppose your OLS regression is well specified and contains all the right explanatory variables, but you have an unspecified correlation structure of the residuals: $$ y_t = x_t' \beta + \epsilon_t, \mathbb{V}[\mathbf{\epsilon}]=\Omega $$ The OLS estimates are $$ \hat\beta = (X'X)^{-1} X'Y = \beta + (X'X)^{-1} X'\mathbf{\epsilon} $$ and their variance is $$ \mathbb{V}[\hat\beta] = \mathbb{E} [ (X'X)^{-1} X'\mathbf{\epsilon}\mathbf{\epsilon}'X (X'X)^{-1} ] $$ Typically, at this stage, we'd have to assume something like existence of the probability limit of $\frac1T (X'X) \to \Sigma$, so that $$ T \mathbb{V}[\hat\beta] \to \Sigma^{-1} {\rm plim} \bigl[ \frac1T X'\mathbf{\epsilon}\mathbf{\epsilon}'X \bigr] \Sigma^{-1} = \Sigma^{-1} {\rm plim} \bigl[ \frac1T X'\Omega X \bigr] \Sigma^{-1} $$ This expression is different from what the naive OLS standard errors produce, and so in general the OLS standard errors are wrong. Of course, if $X$ can be considered fixed, then there is no need for asymptotic approximations, and $X$ can be carried through the expectations, so that $$ \mathbb{V}[\hat\beta] = (X'X)^{-1} X'\Omega X (X'X)^{-1} $$ to the same effect.
Why autocorrelation affects OLS coefficient standard errors? Suppose your OLS regression is well specified and contains all the right explanatory variables, but you have an unspecified correlation structure of the residuals: $$ y_t = x_t' \beta + \epsilon_t, \m
31,882
Why autocorrelation affects OLS coefficient standard errors?
Auto correlation (Exogeneity) : If the observation of residual in t1 is dependent on the observation of residual in t0, then it basically violates the underlying assumption of OLS which states "Error term is independently distributed and not correlated". This can bias the estimation of Beta coefficient of OLS term. When such trend is observed in the residuals, the residuals of regression model picks up the influence of those variables that are affecting the dependent variables that aren't part of the regression equation. The persistence in excluded variables is most of the times a cause for autocorrelation. This is more prevalent in Time series data. This can be mitigated by using some of the transformations techniques like, Paris Winston Transformation of Data Differencing the dependent variables Differencing all variables One simpler approach would be, estimating the linear model using OLS. Compute the residuals. Regress the residuals of all Independent variables and lagged variables. Use t-test, if the coefficient of lagged residual is significant, we can reject the null of independent errors. Test to detect Auto correlation: ** Durbin - Watson Bruesch - Godfrey This assumption/issue is violated/exempted if the explanatory variables are stochastic, for instance when they are measured with error, or are endogenous.
Why autocorrelation affects OLS coefficient standard errors?
Auto correlation (Exogeneity) : If the observation of residual in t1 is dependent on the observation of residual in t0, then it basically violates the underlying assumption of OLS which states "Error
Why autocorrelation affects OLS coefficient standard errors? Auto correlation (Exogeneity) : If the observation of residual in t1 is dependent on the observation of residual in t0, then it basically violates the underlying assumption of OLS which states "Error term is independently distributed and not correlated". This can bias the estimation of Beta coefficient of OLS term. When such trend is observed in the residuals, the residuals of regression model picks up the influence of those variables that are affecting the dependent variables that aren't part of the regression equation. The persistence in excluded variables is most of the times a cause for autocorrelation. This is more prevalent in Time series data. This can be mitigated by using some of the transformations techniques like, Paris Winston Transformation of Data Differencing the dependent variables Differencing all variables One simpler approach would be, estimating the linear model using OLS. Compute the residuals. Regress the residuals of all Independent variables and lagged variables. Use t-test, if the coefficient of lagged residual is significant, we can reject the null of independent errors. Test to detect Auto correlation: ** Durbin - Watson Bruesch - Godfrey This assumption/issue is violated/exempted if the explanatory variables are stochastic, for instance when they are measured with error, or are endogenous.
Why autocorrelation affects OLS coefficient standard errors? Auto correlation (Exogeneity) : If the observation of residual in t1 is dependent on the observation of residual in t0, then it basically violates the underlying assumption of OLS which states "Error
31,883
Why do you have to provide a variogram model when you are kriging?
Introduction and Summary Tobler's Law of Geography asserts Everything is related to everything else, but near things are more related than distant things. Kriging adopts a model of those relationships in which "Things" are numerical values at locations on the earth's surface (or in space), usually represented as a Euclidean plane. These numerical values are assumed to be realizations of random variables. "Related" is expressed in terms of the means and covariances of these random variables. (A collection of random variables associated with points in space is called a "stochastic process.") The variogram provides the information needed to compute those covariances. What Kriging Is Kriging specifically is the prediction of things at places where they have not been observed. To make the prediction process mathematically tractable, Kriging limits the possible formulas to be linear functions of the observed values. That makes the problem a finite one of determining what the coefficients should be. These can be found by requiring that the prediction procedure have certain properties. Intuitively, an excellent property is that the differences between the predictor and the true (but unknown) value should tend to be small: that is, the predictor should be precise. Another property which is highly touted but is more questionable is that on average the predictor should equal the true value: it should be accurate. (The reason that insisting on perfect accuracy is questionable--but not necessarily bad--is that it usually makes any statistical procedure less precise: that is, more variable. When shooting at a target would you prefer to scatter the hits evenly around the rim and rarely hitting the center or would you accept results that are focused just next to, but not exactly on, the center? The former is accurate but imprecise while the latter is inaccurate but precise.) These assumptions and criteria--that means and covariances are appropriate ways to quantify relatedness, that a linear prediction will work, and that the predictor should be as precise as possible subject to being perfectly accurate--lead to a system of equations that has a unique solution provided the covariances have been specified in a consistent manner. The resulting predictor is thereby called a "BLUP": Best Linear Unbiased Predictor. Where the Variogram Comes In Finding these equations requires operationalizing the program just described. This is done by writing down the covariances between the predictor and the observations thought of as random variables. The algebra of covariances causes the covariances among the observed values to enter into the Kriging equations, too. At this point we reach a dead end, because those covariances are almost always unknown. After all, in most applications we have observed only one realization of each of the random variables: namely, our dataset, which constitutes just one number at each distinct location. Enter the variogram: this mathematical function tells us what the covariance between any two values ought to be. It is constrained to ensure that these covariances are "consistent" (in the sense that it will never give a set of covariances that are mathematically impossible: not all collections of numerical measures of "relatedness" will form actual covariance matrices). That is why a variogram is essential to Kriging. References Because the immediate question has been answered, I will stop here. Interested readers can learn how variograms are estimated and interpreted by consulting good texts such as Journel & Huijbregts' Mining Geostatistics (1978) or Isaaks & Srivastava's Applied Geostatistics (1989). (Note that the estimation process introduces two objects called "variograms": an empirical variogram derived from data and a model variogram that is fitted to it. All references to "variogram" in this answer are to the model. The call to vgm in the question returns a computer representation of a model variogram.) For a more modern approach in which variogram estimation and Kriging are appropriately combined, see Diggle & Ribeiro Jr.'s Model-based Geostatistics (2007) (which is also an extended manual for the R packages GeoR and GeoRglm). Comments Incidentally, whether you are using Kriging for prediction or some other algorithm, the quantitative characterization of relatedness afforded by the variogram is useful for assessing any prediction procedure. Notice that all spatial interpolation methods are predictors from this point of view--and many of them are linear predictors, such as IDW (Inverse Distance Weighted). The variogram can be used to assess the average value and dispersion (standard deviation) of any of the interpolation methods. Thus it has applicability far beyond its use in Kriging.
Why do you have to provide a variogram model when you are kriging?
Introduction and Summary Tobler's Law of Geography asserts Everything is related to everything else, but near things are more related than distant things. Kriging adopts a model of those relationshi
Why do you have to provide a variogram model when you are kriging? Introduction and Summary Tobler's Law of Geography asserts Everything is related to everything else, but near things are more related than distant things. Kriging adopts a model of those relationships in which "Things" are numerical values at locations on the earth's surface (or in space), usually represented as a Euclidean plane. These numerical values are assumed to be realizations of random variables. "Related" is expressed in terms of the means and covariances of these random variables. (A collection of random variables associated with points in space is called a "stochastic process.") The variogram provides the information needed to compute those covariances. What Kriging Is Kriging specifically is the prediction of things at places where they have not been observed. To make the prediction process mathematically tractable, Kriging limits the possible formulas to be linear functions of the observed values. That makes the problem a finite one of determining what the coefficients should be. These can be found by requiring that the prediction procedure have certain properties. Intuitively, an excellent property is that the differences between the predictor and the true (but unknown) value should tend to be small: that is, the predictor should be precise. Another property which is highly touted but is more questionable is that on average the predictor should equal the true value: it should be accurate. (The reason that insisting on perfect accuracy is questionable--but not necessarily bad--is that it usually makes any statistical procedure less precise: that is, more variable. When shooting at a target would you prefer to scatter the hits evenly around the rim and rarely hitting the center or would you accept results that are focused just next to, but not exactly on, the center? The former is accurate but imprecise while the latter is inaccurate but precise.) These assumptions and criteria--that means and covariances are appropriate ways to quantify relatedness, that a linear prediction will work, and that the predictor should be as precise as possible subject to being perfectly accurate--lead to a system of equations that has a unique solution provided the covariances have been specified in a consistent manner. The resulting predictor is thereby called a "BLUP": Best Linear Unbiased Predictor. Where the Variogram Comes In Finding these equations requires operationalizing the program just described. This is done by writing down the covariances between the predictor and the observations thought of as random variables. The algebra of covariances causes the covariances among the observed values to enter into the Kriging equations, too. At this point we reach a dead end, because those covariances are almost always unknown. After all, in most applications we have observed only one realization of each of the random variables: namely, our dataset, which constitutes just one number at each distinct location. Enter the variogram: this mathematical function tells us what the covariance between any two values ought to be. It is constrained to ensure that these covariances are "consistent" (in the sense that it will never give a set of covariances that are mathematically impossible: not all collections of numerical measures of "relatedness" will form actual covariance matrices). That is why a variogram is essential to Kriging. References Because the immediate question has been answered, I will stop here. Interested readers can learn how variograms are estimated and interpreted by consulting good texts such as Journel & Huijbregts' Mining Geostatistics (1978) or Isaaks & Srivastava's Applied Geostatistics (1989). (Note that the estimation process introduces two objects called "variograms": an empirical variogram derived from data and a model variogram that is fitted to it. All references to "variogram" in this answer are to the model. The call to vgm in the question returns a computer representation of a model variogram.) For a more modern approach in which variogram estimation and Kriging are appropriately combined, see Diggle & Ribeiro Jr.'s Model-based Geostatistics (2007) (which is also an extended manual for the R packages GeoR and GeoRglm). Comments Incidentally, whether you are using Kriging for prediction or some other algorithm, the quantitative characterization of relatedness afforded by the variogram is useful for assessing any prediction procedure. Notice that all spatial interpolation methods are predictors from this point of view--and many of them are linear predictors, such as IDW (Inverse Distance Weighted). The variogram can be used to assess the average value and dispersion (standard deviation) of any of the interpolation methods. Thus it has applicability far beyond its use in Kriging.
Why do you have to provide a variogram model when you are kriging? Introduction and Summary Tobler's Law of Geography asserts Everything is related to everything else, but near things are more related than distant things. Kriging adopts a model of those relationshi
31,884
K-fold or hold-out cross validation for ridge regression using R
You can use caret package (vignnettes, paper ) for this type of things, which can wrap a number of machine learning models or you can use your own customized models . As you are interested in ridge regression here is just custom codes for ridge regression, you might want to adopt to your situation more precisely. For simple split in data: set.seed(107) # stratified random split of the data inTrain <- createDataPartition(y = myd$y, p = .5,list = FALSE) training <- myd[ inTrain,] testing <- myd[-inTrain,] For K-fold validation and other type of CV including default boot ridgeFit1 <- train(y ~ ., data = training,method = 'ridge', preProc = c("center", "scale"), metric = "ROC") plot(ridgeFit1) Here is discussion on how to use train function. Note the ridge method depends upon the package elasticnet functions ( and its dependency on lars, should or need to be installed). If not installed in the system will ask if you want to do so. the type of resampling used, The simple bootstrap is used by default.To modify the resampling method, a trainControl function is used The option method controls the type of resampling and defaults to "boot". Another method, "repeatedcv", is used to specify repeated K–fold cross–validation (and the argument repeats controls the number of repetitions). K is controlled by the number argument and defaults to 10. ctrl <- trainControl(method = "repeatedcv", repeats = 5) ridgeFit <- train(y ~ ., data = training,method = 'ridge', preProc = c("center", "scale"),trControl = ctrl, metric = "ROC") plot(ridgefit) For predictions: plsClasses <- predict(ridgeFit, newdata = testing)
K-fold or hold-out cross validation for ridge regression using R
You can use caret package (vignnettes, paper ) for this type of things, which can wrap a number of machine learning models or you can use your own customized models . As you are interested in ridge re
K-fold or hold-out cross validation for ridge regression using R You can use caret package (vignnettes, paper ) for this type of things, which can wrap a number of machine learning models or you can use your own customized models . As you are interested in ridge regression here is just custom codes for ridge regression, you might want to adopt to your situation more precisely. For simple split in data: set.seed(107) # stratified random split of the data inTrain <- createDataPartition(y = myd$y, p = .5,list = FALSE) training <- myd[ inTrain,] testing <- myd[-inTrain,] For K-fold validation and other type of CV including default boot ridgeFit1 <- train(y ~ ., data = training,method = 'ridge', preProc = c("center", "scale"), metric = "ROC") plot(ridgeFit1) Here is discussion on how to use train function. Note the ridge method depends upon the package elasticnet functions ( and its dependency on lars, should or need to be installed). If not installed in the system will ask if you want to do so. the type of resampling used, The simple bootstrap is used by default.To modify the resampling method, a trainControl function is used The option method controls the type of resampling and defaults to "boot". Another method, "repeatedcv", is used to specify repeated K–fold cross–validation (and the argument repeats controls the number of repetitions). K is controlled by the number argument and defaults to 10. ctrl <- trainControl(method = "repeatedcv", repeats = 5) ridgeFit <- train(y ~ ., data = training,method = 'ridge', preProc = c("center", "scale"),trControl = ctrl, metric = "ROC") plot(ridgefit) For predictions: plsClasses <- predict(ridgeFit, newdata = testing)
K-fold or hold-out cross validation for ridge regression using R You can use caret package (vignnettes, paper ) for this type of things, which can wrap a number of machine learning models or you can use your own customized models . As you are interested in ridge re
31,885
K-fold or hold-out cross validation for ridge regression using R
This is extension of the suggestion by Frank in the comments. Dr. Harrel please correct if I am wrong (appreciate corrections). Your data: #random population of 200 subjects with 1000 variables M <- matrix(rep(0,200*100),200,1000) for (i in 1:200) { set.seed(i) M[i,] <- ifelse(runif(1000)<0.5,-1,1) } rownames(M) <- 1:200 #random yvars set.seed(1234) u <- rnorm(1000) g <- as.vector(crossprod(t(M),u)) h2 <- 0.5 set.seed(234) y <- g + rnorm(200,mean=0,sd=sqrt((1-h2)/h2*var(g))) myd <- data.frame(y=y, M) Install rms package and load it. require(rms) ols function is used for Linear Model Estimation Using Ordinary Least Squares where can specify penalty term. As suggested below in comments I added petrace function. This function trace AIC and BIC vs Penalty. # using holdout (50% of the data) cross validation training.id <- sample(1:nrow(myd), round(nrow(myd)/2,0), replace = FALSE) test.id <- setdiff(1:nrow(myd), training.id) myd_train <- myd[training.id,] myd_test <- myd[test.id,] frm <- as.formula(paste("y~",paste(names(myd_train)[2:100],collapse="+"))) Important note I could not use all 1000 of the variables as the program complains if number of variable exceeds 100. Also y~. type formula designation did not work. So see above way of doing same creating formula object frm f <- ols(frm, data = myd_train, method="qr", x=TRUE, y=TRUE) p <- pentrace(f, seq(.2,1,by=.05)) Error in array(x, c(length(x), 1L), if (!is.null(names(x))) list(names(x), : 'data' must be of a vector type, was 'NULL' plot(p) "For an ordinary unpenalized fit from lrm or ols and for a vector or list of penalties, fits a series of logistic or linear models using penalized maximum likelihood estimation, and saves the effective degrees of freedom, Akaike Information Criterion (AIC), Schwarz Bayesian Information Criterion (BIC), and Hurvich and Tsai's corrected AIC (AIC_c). Optionally pentrace can use the nlminb function to solve for the optimum penalty factor or combination of factors penalizing different kinds of terms in the model." from rms package manual. calibrate function is for Resampling Model Calibration and Uses bootstrapping or cross-validation to get bias-corrected (overfitting- corrected) estimates of predicted vs. observed values based on subsetting predictions into intervals. The validate function does resampling validation of a regression model, with or without backward step-down variable deletion. B = number of repetitions. For method="crossvalidation", is the number of groups of omitted observations cal <- calibrate(f, method = "cross validation", B=20) plot(cal) You can use Predict function to compute predicted values and confidence limits. I am not sure I this works in test situation.
K-fold or hold-out cross validation for ridge regression using R
This is extension of the suggestion by Frank in the comments. Dr. Harrel please correct if I am wrong (appreciate corrections). Your data: #random population of 200 subjects with 1000 variables
K-fold or hold-out cross validation for ridge regression using R This is extension of the suggestion by Frank in the comments. Dr. Harrel please correct if I am wrong (appreciate corrections). Your data: #random population of 200 subjects with 1000 variables M <- matrix(rep(0,200*100),200,1000) for (i in 1:200) { set.seed(i) M[i,] <- ifelse(runif(1000)<0.5,-1,1) } rownames(M) <- 1:200 #random yvars set.seed(1234) u <- rnorm(1000) g <- as.vector(crossprod(t(M),u)) h2 <- 0.5 set.seed(234) y <- g + rnorm(200,mean=0,sd=sqrt((1-h2)/h2*var(g))) myd <- data.frame(y=y, M) Install rms package and load it. require(rms) ols function is used for Linear Model Estimation Using Ordinary Least Squares where can specify penalty term. As suggested below in comments I added petrace function. This function trace AIC and BIC vs Penalty. # using holdout (50% of the data) cross validation training.id <- sample(1:nrow(myd), round(nrow(myd)/2,0), replace = FALSE) test.id <- setdiff(1:nrow(myd), training.id) myd_train <- myd[training.id,] myd_test <- myd[test.id,] frm <- as.formula(paste("y~",paste(names(myd_train)[2:100],collapse="+"))) Important note I could not use all 1000 of the variables as the program complains if number of variable exceeds 100. Also y~. type formula designation did not work. So see above way of doing same creating formula object frm f <- ols(frm, data = myd_train, method="qr", x=TRUE, y=TRUE) p <- pentrace(f, seq(.2,1,by=.05)) Error in array(x, c(length(x), 1L), if (!is.null(names(x))) list(names(x), : 'data' must be of a vector type, was 'NULL' plot(p) "For an ordinary unpenalized fit from lrm or ols and for a vector or list of penalties, fits a series of logistic or linear models using penalized maximum likelihood estimation, and saves the effective degrees of freedom, Akaike Information Criterion (AIC), Schwarz Bayesian Information Criterion (BIC), and Hurvich and Tsai's corrected AIC (AIC_c). Optionally pentrace can use the nlminb function to solve for the optimum penalty factor or combination of factors penalizing different kinds of terms in the model." from rms package manual. calibrate function is for Resampling Model Calibration and Uses bootstrapping or cross-validation to get bias-corrected (overfitting- corrected) estimates of predicted vs. observed values based on subsetting predictions into intervals. The validate function does resampling validation of a regression model, with or without backward step-down variable deletion. B = number of repetitions. For method="crossvalidation", is the number of groups of omitted observations cal <- calibrate(f, method = "cross validation", B=20) plot(cal) You can use Predict function to compute predicted values and confidence limits. I am not sure I this works in test situation.
K-fold or hold-out cross validation for ridge regression using R This is extension of the suggestion by Frank in the comments. Dr. Harrel please correct if I am wrong (appreciate corrections). Your data: #random population of 200 subjects with 1000 variables
31,886
K-fold or hold-out cross validation for ridge regression using R
R package glmnet (vignette) has a wrapper function that does exactly what you want, called cv.glmnet (doc). I just used it yesterday, it works like a dream.
K-fold or hold-out cross validation for ridge regression using R
R package glmnet (vignette) has a wrapper function that does exactly what you want, called cv.glmnet (doc). I just used it yesterday, it works like a dream.
K-fold or hold-out cross validation for ridge regression using R R package glmnet (vignette) has a wrapper function that does exactly what you want, called cv.glmnet (doc). I just used it yesterday, it works like a dream.
K-fold or hold-out cross validation for ridge regression using R R package glmnet (vignette) has a wrapper function that does exactly what you want, called cv.glmnet (doc). I just used it yesterday, it works like a dream.
31,887
Plotting the decision boundary of a kernel SVM (RBF)
I figured out what is needed to be done. Actually, it's something simple, but its seems I had a matlaboid bug... Here is the code and the resulting figure for the "XOR" binary classification problem. gamma = getGamma(); b = getB(); points_x1 = linspace(xLimits(1), xLimits(2), 100); points_x2 = linspace(yLimits(1), yLimits(2), 100); [X1, X2] = meshgrid(points_x1, points_x2); % Initialize f f = ones(length(points_x1), length(points_x2))*rho; % Iter. all SVs for i=1:N_sv alpha_i = getAlpha(i); sv_i = getSV(i); for j=1:length(points_x1) for k=1:length(points_x2) x = [points_x1(j);points_x2(k)]; f(j,k) = f(j,k) + alpha_i*y_i*kernel_func(gamma, x, sv_i); end end end surf(X1,X2,f); shading interp; lighting phong; alpha(.6) contourf(X1, X2, f, 1); where the function function k = kernel_func(gamma, x, x_i) k = exp(-gamma*norm(x - x_i)^2); end just produces the kernel function (RBF kernel), $k(\mathbf{x},\mathbf{x}')=\operatorname{exp}\left(-\gamma\lVert\mathbf{x}-\mathbf{x}'\rVert^2\right)$. Here is the result for the XOR problem. Here $\gamma=4$.
Plotting the decision boundary of a kernel SVM (RBF)
I figured out what is needed to be done. Actually, it's something simple, but its seems I had a matlaboid bug... Here is the code and the resulting figure for the "XOR" binary classification problem.
Plotting the decision boundary of a kernel SVM (RBF) I figured out what is needed to be done. Actually, it's something simple, but its seems I had a matlaboid bug... Here is the code and the resulting figure for the "XOR" binary classification problem. gamma = getGamma(); b = getB(); points_x1 = linspace(xLimits(1), xLimits(2), 100); points_x2 = linspace(yLimits(1), yLimits(2), 100); [X1, X2] = meshgrid(points_x1, points_x2); % Initialize f f = ones(length(points_x1), length(points_x2))*rho; % Iter. all SVs for i=1:N_sv alpha_i = getAlpha(i); sv_i = getSV(i); for j=1:length(points_x1) for k=1:length(points_x2) x = [points_x1(j);points_x2(k)]; f(j,k) = f(j,k) + alpha_i*y_i*kernel_func(gamma, x, sv_i); end end end surf(X1,X2,f); shading interp; lighting phong; alpha(.6) contourf(X1, X2, f, 1); where the function function k = kernel_func(gamma, x, x_i) k = exp(-gamma*norm(x - x_i)^2); end just produces the kernel function (RBF kernel), $k(\mathbf{x},\mathbf{x}')=\operatorname{exp}\left(-\gamma\lVert\mathbf{x}-\mathbf{x}'\rVert^2\right)$. Here is the result for the XOR problem. Here $\gamma=4$.
Plotting the decision boundary of a kernel SVM (RBF) I figured out what is needed to be done. Actually, it's something simple, but its seems I had a matlaboid bug... Here is the code and the resulting figure for the "XOR" binary classification problem.
31,888
Plotting the decision boundary of a kernel SVM (RBF)
Use a grid approach, divide your 2D space into a k by k grid, evaluate that point as a sample in your SVM (i.e., predict the label), and plot the predictions at all points.
Plotting the decision boundary of a kernel SVM (RBF)
Use a grid approach, divide your 2D space into a k by k grid, evaluate that point as a sample in your SVM (i.e., predict the label), and plot the predictions at all points.
Plotting the decision boundary of a kernel SVM (RBF) Use a grid approach, divide your 2D space into a k by k grid, evaluate that point as a sample in your SVM (i.e., predict the label), and plot the predictions at all points.
Plotting the decision boundary of a kernel SVM (RBF) Use a grid approach, divide your 2D space into a k by k grid, evaluate that point as a sample in your SVM (i.e., predict the label), and plot the predictions at all points.
31,889
anova type III test for a GLMM
If you're willing to settle for Wald tests this should work: library(lme4) library(car) gm1 <- glmer(cbind(incidence, size - incidence) ~ period + (1 | herd), data = cbpp, family = binomial) Anova(gm1,type="III") However, note (from ?Anova) that: The designations "type-II" and "type-III" are borrowed from SAS, but the definitions used here do not correspond precisely to those employed by SAS. Type-II tests are calculated according to the principle of marginality, testing each term after all others, except ignoring the term's higher-order relatives; so-called type-III tests violate marginality, testing each term in the model after all of the others. This definition of Type-II tests corresponds to the tests produced by SAS for analysis-of-variance models, where all of the predictors are factors, but not more generally (i.e., when there are quantitative predictors). Be very careful in formulating the model for type-III tests, or the hypotheses tested will not make sense. I would check your results very carefully to make sure they make sense! Alternatively, you can use afex::mixed to get analogous tables via likelihood ratio test or parametric bootstrap; the latter is the most accurate, but also the slowest by far. See ?pvalues in the lme4 package for more general discussion of p-value computation in the context of GLMMs.
anova type III test for a GLMM
If you're willing to settle for Wald tests this should work: library(lme4) library(car) gm1 <- glmer(cbind(incidence, size - incidence) ~ period + (1 | herd), data = cbpp, family =
anova type III test for a GLMM If you're willing to settle for Wald tests this should work: library(lme4) library(car) gm1 <- glmer(cbind(incidence, size - incidence) ~ period + (1 | herd), data = cbpp, family = binomial) Anova(gm1,type="III") However, note (from ?Anova) that: The designations "type-II" and "type-III" are borrowed from SAS, but the definitions used here do not correspond precisely to those employed by SAS. Type-II tests are calculated according to the principle of marginality, testing each term after all others, except ignoring the term's higher-order relatives; so-called type-III tests violate marginality, testing each term in the model after all of the others. This definition of Type-II tests corresponds to the tests produced by SAS for analysis-of-variance models, where all of the predictors are factors, but not more generally (i.e., when there are quantitative predictors). Be very careful in formulating the model for type-III tests, or the hypotheses tested will not make sense. I would check your results very carefully to make sure they make sense! Alternatively, you can use afex::mixed to get analogous tables via likelihood ratio test or parametric bootstrap; the latter is the most accurate, but also the slowest by far. See ?pvalues in the lme4 package for more general discussion of p-value computation in the context of GLMMs.
anova type III test for a GLMM If you're willing to settle for Wald tests this should work: library(lme4) library(car) gm1 <- glmer(cbind(incidence, size - incidence) ~ period + (1 | herd), data = cbpp, family =
31,890
How to include $x$ and $x^2$ into regression, and whether to center them?
Your question is in fact comprised of several sub-questions, which I will try to address to the best of my understanding. How to distinguish low and high values' dependence on a regression? Considering $x$ and $x^2$ is a way of doing it, but are you sure your test is conclusive? Will you be able to conclude something useful for all possible outcomes of the regression? I think posing the question clearly beforehand can help, and asking similar and related questions can help as well. For instance, you can consider a threshold of $x$ for which the regression slopes are different. This can be done using moderator variables. If the different slopes (while imposing the same intercept) are compatible then you have no difference, otherwise you provided yourself a clear argument for their difference. When should you center and standartize? I think this question should not be mixed with the first question and test, and I'm afraid centering around $x$ or $x^2$ beforehand might bias the results. I would advise not to center, at least in a first stage. Remember you will probably not die of multicollinearity, many authors argue it's just equivalent to working with a smaller sample size (here and here). Does transforming the discrete count variable in a (continuous) floating-point variable change the interpretation of the results? Yes it will, but this will depend heavily on the first 2 points, so I would suggest you to address one thing at a time. I see no reason why the regression would not work without this transformation, so I would advise you to ignore it for now. Note also that by dividing by a common element you are changing the scale at which $x^2 = x$, but there are completely different ways of looking at it, like I wrote above, in which this threshold is considered in more explicit way.
How to include $x$ and $x^2$ into regression, and whether to center them?
Your question is in fact comprised of several sub-questions, which I will try to address to the best of my understanding. How to distinguish low and high values' dependence on a regression? Consider
How to include $x$ and $x^2$ into regression, and whether to center them? Your question is in fact comprised of several sub-questions, which I will try to address to the best of my understanding. How to distinguish low and high values' dependence on a regression? Considering $x$ and $x^2$ is a way of doing it, but are you sure your test is conclusive? Will you be able to conclude something useful for all possible outcomes of the regression? I think posing the question clearly beforehand can help, and asking similar and related questions can help as well. For instance, you can consider a threshold of $x$ for which the regression slopes are different. This can be done using moderator variables. If the different slopes (while imposing the same intercept) are compatible then you have no difference, otherwise you provided yourself a clear argument for their difference. When should you center and standartize? I think this question should not be mixed with the first question and test, and I'm afraid centering around $x$ or $x^2$ beforehand might bias the results. I would advise not to center, at least in a first stage. Remember you will probably not die of multicollinearity, many authors argue it's just equivalent to working with a smaller sample size (here and here). Does transforming the discrete count variable in a (continuous) floating-point variable change the interpretation of the results? Yes it will, but this will depend heavily on the first 2 points, so I would suggest you to address one thing at a time. I see no reason why the regression would not work without this transformation, so I would advise you to ignore it for now. Note also that by dividing by a common element you are changing the scale at which $x^2 = x$, but there are completely different ways of looking at it, like I wrote above, in which this threshold is considered in more explicit way.
How to include $x$ and $x^2$ into regression, and whether to center them? Your question is in fact comprised of several sub-questions, which I will try to address to the best of my understanding. How to distinguish low and high values' dependence on a regression? Consider
31,891
How to include $x$ and $x^2$ into regression, and whether to center them?
In general centering could help to reduce multicollinearity, but "you will probably not die of multicollinearity" (see predrofigueira's answer). Most important, centering is often needed to make the intercept meaningful. In the simple model $y_i=\alpha+\beta x_i+\varepsilon$, the intercept is defined as the expected outcome for $x=0$. If an $x$ value of zero is not meaningful, neither the itercept is. It is often useful to center the variable $x$ around its mean; in this case, the predictor is of the form $(x_i-\bar{x})$ and the intercept $\alpha$ is the expected outcome for a subject whose value on $x_i$ is equal to the mean $\bar{x}$. In such cases, you must center $x$ and then square. You cannot center $x$ and $x^2$ separately, because you are regressing the outcome on a "new" variable, $(x_i-\bar{x})$, so you must square this new variable. What could centering $x^2$ mean? You can center a count variable, if its mean is meaningful, but you could just scale it. For example, if $x=1,2,3,4,5$ and "2" could be a baseline, you can subtract 2: $(x_i-2)=-1,0,1,2,3$. The intercept becomes the expected outcome for a subject whose value on $x_i$ is equal to "2", a reference value. As to dividing, no trouble: your estimated coefficients would be larger! Gelman and Hill, §4.1, give an example: $$\begin{align} \text{earnings}&=-61000+1300\cdot\text{height (in inches)}+\text{error} \\ \text{earnings}&=-61000+51\cdot\text{height (in millimeters)}+\text{error}\\ \text{earnings}&=-61000+81000000\cdot\text{height (in miles)}+\text{error} \end{align}$$ One inch is $25.4$ millimeters, so $51$ is $1300/25.4$. One inch is $1.6e-5$ emiles, so $81000000$ is $1300/1.6e-5$. But these three equations are entirely equivalent.
How to include $x$ and $x^2$ into regression, and whether to center them?
In general centering could help to reduce multicollinearity, but "you will probably not die of multicollinearity" (see predrofigueira's answer). Most important, centering is often needed to make the i
How to include $x$ and $x^2$ into regression, and whether to center them? In general centering could help to reduce multicollinearity, but "you will probably not die of multicollinearity" (see predrofigueira's answer). Most important, centering is often needed to make the intercept meaningful. In the simple model $y_i=\alpha+\beta x_i+\varepsilon$, the intercept is defined as the expected outcome for $x=0$. If an $x$ value of zero is not meaningful, neither the itercept is. It is often useful to center the variable $x$ around its mean; in this case, the predictor is of the form $(x_i-\bar{x})$ and the intercept $\alpha$ is the expected outcome for a subject whose value on $x_i$ is equal to the mean $\bar{x}$. In such cases, you must center $x$ and then square. You cannot center $x$ and $x^2$ separately, because you are regressing the outcome on a "new" variable, $(x_i-\bar{x})$, so you must square this new variable. What could centering $x^2$ mean? You can center a count variable, if its mean is meaningful, but you could just scale it. For example, if $x=1,2,3,4,5$ and "2" could be a baseline, you can subtract 2: $(x_i-2)=-1,0,1,2,3$. The intercept becomes the expected outcome for a subject whose value on $x_i$ is equal to "2", a reference value. As to dividing, no trouble: your estimated coefficients would be larger! Gelman and Hill, §4.1, give an example: $$\begin{align} \text{earnings}&=-61000+1300\cdot\text{height (in inches)}+\text{error} \\ \text{earnings}&=-61000+51\cdot\text{height (in millimeters)}+\text{error}\\ \text{earnings}&=-61000+81000000\cdot\text{height (in miles)}+\text{error} \end{align}$$ One inch is $25.4$ millimeters, so $51$ is $1300/25.4$. One inch is $1.6e-5$ emiles, so $81000000$ is $1300/1.6e-5$. But these three equations are entirely equivalent.
How to include $x$ and $x^2$ into regression, and whether to center them? In general centering could help to reduce multicollinearity, but "you will probably not die of multicollinearity" (see predrofigueira's answer). Most important, centering is often needed to make the i
31,892
How to include $x$ and $x^2$ into regression, and whether to center them?
I assume that low values of x have a positive effect on the dependent variable and high values have a negative effect. While I appreciate others' treatment of centering and interpretation of coefficients, what you've described here is simply a linear effect. In other words, what you've described doesn't indicate any need to test the square of x.
How to include $x$ and $x^2$ into regression, and whether to center them?
I assume that low values of x have a positive effect on the dependent variable and high values have a negative effect. While I appreciate others' treatment of centering and interpretation of coeffici
How to include $x$ and $x^2$ into regression, and whether to center them? I assume that low values of x have a positive effect on the dependent variable and high values have a negative effect. While I appreciate others' treatment of centering and interpretation of coefficients, what you've described here is simply a linear effect. In other words, what you've described doesn't indicate any need to test the square of x.
How to include $x$ and $x^2$ into regression, and whether to center them? I assume that low values of x have a positive effect on the dependent variable and high values have a negative effect. While I appreciate others' treatment of centering and interpretation of coeffici
31,893
A stochastically increasing exponential family for which $\lim_{\theta\rightarrow\inf\Theta}\mbox{P}_\theta(X\leq x)\neq 1$
If discontinuities in the density is allowed, it is possible to construct a distribution that repeats itself over two consecutive intervals, which bounds the CDF at the first interval to $[0,0.5]$ and at the second interval to $[0.5,1]$. For example, let \begin{equation} h(x) = 1, x\in [0,4] \end{equation} \begin{equation} T(x) = \left\{ \begin{array}{ll} 1 & \quad x \in [0,1) \cup[2,3) \\ 2 & \quad x \in [1,2) \cup [3,4] \end{array} \right. \end{equation} Now, for a density proportional to $h(x)e^{\theta T(x)}$, the CDF is \begin{equation} F_\theta(x) = \left\{ \begin{array}{ll} \frac{1}{2}\,\frac{x}{1+e^\theta} & \quad x \in [0,1) \\ \frac{1}{2}\, \frac{1 + (x-1)e^\theta}{1+e^\theta} & \quad x \in [1,2) \\ \frac{1}{2} + \frac{1}{2}\,\frac{x-2}{1+e^\theta} & \quad x \in [2,3) \\ \frac{1}{2} + \frac{1}{2}\, \frac{1 + (x-3)e^\theta}{1+e^\theta} & \quad x \in [3,4) \\ \end{array} \right. \end{equation} which is decreasing as a function of $\theta$ for any $x$ in the sample space, but, for example, \begin{equation} \lim_{\theta \rightarrow \infty} F_\theta(2.1) = \frac{1}{2}. \end{equation}
A stochastically increasing exponential family for which $\lim_{\theta\rightarrow\inf\Theta}\mbox{P}
If discontinuities in the density is allowed, it is possible to construct a distribution that repeats itself over two consecutive intervals, which bounds the CDF at the first interval to $[0,0.5]$ and
A stochastically increasing exponential family for which $\lim_{\theta\rightarrow\inf\Theta}\mbox{P}_\theta(X\leq x)\neq 1$ If discontinuities in the density is allowed, it is possible to construct a distribution that repeats itself over two consecutive intervals, which bounds the CDF at the first interval to $[0,0.5]$ and at the second interval to $[0.5,1]$. For example, let \begin{equation} h(x) = 1, x\in [0,4] \end{equation} \begin{equation} T(x) = \left\{ \begin{array}{ll} 1 & \quad x \in [0,1) \cup[2,3) \\ 2 & \quad x \in [1,2) \cup [3,4] \end{array} \right. \end{equation} Now, for a density proportional to $h(x)e^{\theta T(x)}$, the CDF is \begin{equation} F_\theta(x) = \left\{ \begin{array}{ll} \frac{1}{2}\,\frac{x}{1+e^\theta} & \quad x \in [0,1) \\ \frac{1}{2}\, \frac{1 + (x-1)e^\theta}{1+e^\theta} & \quad x \in [1,2) \\ \frac{1}{2} + \frac{1}{2}\,\frac{x-2}{1+e^\theta} & \quad x \in [2,3) \\ \frac{1}{2} + \frac{1}{2}\, \frac{1 + (x-3)e^\theta}{1+e^\theta} & \quad x \in [3,4) \\ \end{array} \right. \end{equation} which is decreasing as a function of $\theta$ for any $x$ in the sample space, but, for example, \begin{equation} \lim_{\theta \rightarrow \infty} F_\theta(2.1) = \frac{1}{2}. \end{equation}
A stochastically increasing exponential family for which $\lim_{\theta\rightarrow\inf\Theta}\mbox{P} If discontinuities in the density is allowed, it is possible to construct a distribution that repeats itself over two consecutive intervals, which bounds the CDF at the first interval to $[0,0.5]$ and
31,894
A stochastically increasing exponential family for which $\lim_{\theta\rightarrow\inf\Theta}\mbox{P}_\theta(X\leq x)\neq 1$
Based on comments, we are not restricted to considering the natural parameter but are allowed to use the general form \begin{equation} f_\theta(x) \propto h(x) e^{T(x)\eta(\theta)} \end{equation} In this case, it is possible to 'cheat' by constructing $\eta$ so that some values in the natural space of $\eta$ are not reached with any $\theta$. For example, let \begin{equation} f_\theta(x) \propto e^{-x\,\frac{1}{1+e^\theta}},~x\geq0 \end{equation} This is a (strangely parametrized) exponential distribution with CDF \begin{equation} F_\theta(x) = 1 - e^{-x / ({1+e^\theta})}, \end{equation} which is a decreasing function for $\theta$ as desired. However, \begin{equation} \lim_{\theta\rightarrow -\infty} F_\theta(x) = 1-e^{-x} < 1. \end{equation} The case with natural parametrization $(\eta(\theta) = \theta)$ remains open (at least to me).
A stochastically increasing exponential family for which $\lim_{\theta\rightarrow\inf\Theta}\mbox{P}
Based on comments, we are not restricted to considering the natural parameter but are allowed to use the general form \begin{equation} f_\theta(x) \propto h(x) e^{T(x)\eta(\theta)} \end{equation} In t
A stochastically increasing exponential family for which $\lim_{\theta\rightarrow\inf\Theta}\mbox{P}_\theta(X\leq x)\neq 1$ Based on comments, we are not restricted to considering the natural parameter but are allowed to use the general form \begin{equation} f_\theta(x) \propto h(x) e^{T(x)\eta(\theta)} \end{equation} In this case, it is possible to 'cheat' by constructing $\eta$ so that some values in the natural space of $\eta$ are not reached with any $\theta$. For example, let \begin{equation} f_\theta(x) \propto e^{-x\,\frac{1}{1+e^\theta}},~x\geq0 \end{equation} This is a (strangely parametrized) exponential distribution with CDF \begin{equation} F_\theta(x) = 1 - e^{-x / ({1+e^\theta})}, \end{equation} which is a decreasing function for $\theta$ as desired. However, \begin{equation} \lim_{\theta\rightarrow -\infty} F_\theta(x) = 1-e^{-x} < 1. \end{equation} The case with natural parametrization $(\eta(\theta) = \theta)$ remains open (at least to me).
A stochastically increasing exponential family for which $\lim_{\theta\rightarrow\inf\Theta}\mbox{P} Based on comments, we are not restricted to considering the natural parameter but are allowed to use the general form \begin{equation} f_\theta(x) \propto h(x) e^{T(x)\eta(\theta)} \end{equation} In t
31,895
Different non-parametric methods for estimating the probability distribution of data
You don't specify that you're talking about continuous random variables, but I'll assume, since you mention KDE, that you intend this. Two other methods for fitting smooth densities: 1) log-spline density estimation. Here a spline curve is fitted to the log-density. An example paper: Kooperberg and Stone (1991), "A study of logspline density estimation," Computational Statistics & Data Analysis, 12, 327-347 Kooperberg provides a link to a pdf of his paper here, under "1991". If you use R, there's a package for this. An example of a fit generated by it is here. Below is a histogram of the logs of the data set there, and reproductions of the logspline and kernel density estimates from the answer: $$ $$ Logspline density estimate: Kernel density estimate: 2) Finite mixture models. Here some convenient family of distributions is chosen (in many cases, the normal), and the density is assumed to be a mixture of several different members of that family. Note that kernel density estimates can be seen as such a mixture (with a Gaussian kernel, they're a mixture of Gaussians). More generally these might be fitted via ML, or the EM algorithm, or in some cases via moment matching, though in particular circumstances other approaches may be feasible. (There are a plethora of R packages that do various forms of mixture modelling.) Added in edit: 3) Averaged shifted histograms (which are not literally smooth, but perhaps smooth enough for your unstated criteria): Imagine computing a sequence of histograms at some fixed binwidth ($b$), across a bin-origin that shifts by $b/k$ for some integer $k$ each time, and then averaged. This looks at first glance like a histogram done at binwidth $b/k$, but is much smoother. E.g. compute 4 histograms each at binwidth 1, but offset by +0,+0.25,+0.5,+0.75 and then average the heights at any given $x$. You end up with something like so: Diagram taken from this answer. As I say there, if you go to that level of effort, you might as well do kernel density estimation.
Different non-parametric methods for estimating the probability distribution of data
You don't specify that you're talking about continuous random variables, but I'll assume, since you mention KDE, that you intend this. Two other methods for fitting smooth densities: 1) log-spline den
Different non-parametric methods for estimating the probability distribution of data You don't specify that you're talking about continuous random variables, but I'll assume, since you mention KDE, that you intend this. Two other methods for fitting smooth densities: 1) log-spline density estimation. Here a spline curve is fitted to the log-density. An example paper: Kooperberg and Stone (1991), "A study of logspline density estimation," Computational Statistics & Data Analysis, 12, 327-347 Kooperberg provides a link to a pdf of his paper here, under "1991". If you use R, there's a package for this. An example of a fit generated by it is here. Below is a histogram of the logs of the data set there, and reproductions of the logspline and kernel density estimates from the answer: $$ $$ Logspline density estimate: Kernel density estimate: 2) Finite mixture models. Here some convenient family of distributions is chosen (in many cases, the normal), and the density is assumed to be a mixture of several different members of that family. Note that kernel density estimates can be seen as such a mixture (with a Gaussian kernel, they're a mixture of Gaussians). More generally these might be fitted via ML, or the EM algorithm, or in some cases via moment matching, though in particular circumstances other approaches may be feasible. (There are a plethora of R packages that do various forms of mixture modelling.) Added in edit: 3) Averaged shifted histograms (which are not literally smooth, but perhaps smooth enough for your unstated criteria): Imagine computing a sequence of histograms at some fixed binwidth ($b$), across a bin-origin that shifts by $b/k$ for some integer $k$ each time, and then averaged. This looks at first glance like a histogram done at binwidth $b/k$, but is much smoother. E.g. compute 4 histograms each at binwidth 1, but offset by +0,+0.25,+0.5,+0.75 and then average the heights at any given $x$. You end up with something like so: Diagram taken from this answer. As I say there, if you go to that level of effort, you might as well do kernel density estimation.
Different non-parametric methods for estimating the probability distribution of data You don't specify that you're talking about continuous random variables, but I'll assume, since you mention KDE, that you intend this. Two other methods for fitting smooth densities: 1) log-spline den
31,896
Different non-parametric methods for estimating the probability distribution of data
Subject to the comments above about assumptions such as smoothness etc. You can do Bayesian nonparametric density estimation using mixture models with the Dirichlet process prior. The picture below shows the probability density contours recovered from MCMC estimation of a bivariate normal DP-mixture model for the 'old faithful' data. The points are coloured IIRC according to the clustering obtained on the last MCMC step. Teh 2010 provides some good background.
Different non-parametric methods for estimating the probability distribution of data
Subject to the comments above about assumptions such as smoothness etc. You can do Bayesian nonparametric density estimation using mixture models with the Dirichlet process prior. The picture below s
Different non-parametric methods for estimating the probability distribution of data Subject to the comments above about assumptions such as smoothness etc. You can do Bayesian nonparametric density estimation using mixture models with the Dirichlet process prior. The picture below shows the probability density contours recovered from MCMC estimation of a bivariate normal DP-mixture model for the 'old faithful' data. The points are coloured IIRC according to the clustering obtained on the last MCMC step. Teh 2010 provides some good background.
Different non-parametric methods for estimating the probability distribution of data Subject to the comments above about assumptions such as smoothness etc. You can do Bayesian nonparametric density estimation using mixture models with the Dirichlet process prior. The picture below s
31,897
Different non-parametric methods for estimating the probability distribution of data
A popular choice are random forest (see concretely chapter five of "Decision Forests: A Unified Framework for Classification, Regression, Density Estimation, Manifold Learning and Semi-Supervised Learning". It describes in detail the algorithm and evaluates it against other popular choices like k-means, GMM and KDE. Random Forest are implemented in R and scikit-learn. Random Forest are bagged decision trees in a clever way.
Different non-parametric methods for estimating the probability distribution of data
A popular choice are random forest (see concretely chapter five of "Decision Forests: A Unified Framework for Classification, Regression, Density Estimation, Manifold Learning and Semi-Supervised Lear
Different non-parametric methods for estimating the probability distribution of data A popular choice are random forest (see concretely chapter five of "Decision Forests: A Unified Framework for Classification, Regression, Density Estimation, Manifold Learning and Semi-Supervised Learning". It describes in detail the algorithm and evaluates it against other popular choices like k-means, GMM and KDE. Random Forest are implemented in R and scikit-learn. Random Forest are bagged decision trees in a clever way.
Different non-parametric methods for estimating the probability distribution of data A popular choice are random forest (see concretely chapter five of "Decision Forests: A Unified Framework for Classification, Regression, Density Estimation, Manifold Learning and Semi-Supervised Lear
31,898
Gradient of multivariate Gaussian log-likelihood
What about optimization? Let's see if I understand you correctly. You have a model $p(y|x, \theta)$ conditioned on some observation $x$ and a set of parameters $\theta$ and a prior $p(\theta)$ leading to a joint likelihood of $\mathcal{L} = p(y|x, \theta)p(\theta)$. The parameters are distributed according to a known multivariate normal, i.e. $\theta \sim \mathcal{N}(\mu, \Sigma)$. You want to find the MAP solution to this problem, i.e. $$ \text{argmax}_{\theta} \mathcal{L}. $$ A special case of this problem is well studied in the neural networks community, known as weight decay. In that case, $\mu=\mathbf{0}$ and $\Sigma = \mathbf{I}\sigma^2$. As you already noted, the trick is that $\text{argmax}_{\theta} \mathcal{L} = \text{argmax}_{\theta} \log \mathcal{L}$. When you take the log of the Gaussian density, many ugly terms (the exponential) vanish and you will end up with sth like $\log p(\theta) = -{1 \over 2}(\theta - \mu)^T\Sigma^{-1}(\theta - \mu) + \text{const}$. If you differentiate that, Sam Roweis' matrix identities will come in handy and let you arrive at $$ -{1 \over 2}{\partial (\theta - \mu)^T\Sigma^{-1}(\theta - \mu) \over \partial \theta} = -\Sigma^{-1}(\theta - \mu). $$ (Please verify, this was done quickly and in my head.) Together with the derivatives of your model, you can use off-the-shelf optimizers to arrive at a MAP solution. Update: Incorporated comment by David J. Harris. Formulas should be correct now.
Gradient of multivariate Gaussian log-likelihood
What about optimization? Let's see if I understand you correctly. You have a model $p(y|x, \theta)$ conditioned on some observation $x$ and a set of parameters $\theta$ and a prior $p(\theta)$ leading
Gradient of multivariate Gaussian log-likelihood What about optimization? Let's see if I understand you correctly. You have a model $p(y|x, \theta)$ conditioned on some observation $x$ and a set of parameters $\theta$ and a prior $p(\theta)$ leading to a joint likelihood of $\mathcal{L} = p(y|x, \theta)p(\theta)$. The parameters are distributed according to a known multivariate normal, i.e. $\theta \sim \mathcal{N}(\mu, \Sigma)$. You want to find the MAP solution to this problem, i.e. $$ \text{argmax}_{\theta} \mathcal{L}. $$ A special case of this problem is well studied in the neural networks community, known as weight decay. In that case, $\mu=\mathbf{0}$ and $\Sigma = \mathbf{I}\sigma^2$. As you already noted, the trick is that $\text{argmax}_{\theta} \mathcal{L} = \text{argmax}_{\theta} \log \mathcal{L}$. When you take the log of the Gaussian density, many ugly terms (the exponential) vanish and you will end up with sth like $\log p(\theta) = -{1 \over 2}(\theta - \mu)^T\Sigma^{-1}(\theta - \mu) + \text{const}$. If you differentiate that, Sam Roweis' matrix identities will come in handy and let you arrive at $$ -{1 \over 2}{\partial (\theta - \mu)^T\Sigma^{-1}(\theta - \mu) \over \partial \theta} = -\Sigma^{-1}(\theta - \mu). $$ (Please verify, this was done quickly and in my head.) Together with the derivatives of your model, you can use off-the-shelf optimizers to arrive at a MAP solution. Update: Incorporated comment by David J. Harris. Formulas should be correct now.
Gradient of multivariate Gaussian log-likelihood What about optimization? Let's see if I understand you correctly. You have a model $p(y|x, \theta)$ conditioned on some observation $x$ and a set of parameters $\theta$ and a prior $p(\theta)$ leading
31,899
Gradient of multivariate Gaussian log-likelihood
If the likelihood is not Gaussian it's not possible to say if there are analytic results. Also, the second bullet is then incorrect in general. Since Gaussian prior and general likelihood does not make for conditional gaussian distributions on the vector components. One way to get the MAP would be to do a full Bayesian analysis, e.g. using MCMC and use the samples from the posterior to estimate it. [In which case you'd have better information available than only using the MAP.] Out of interest- why not go down this route anyhow? Another approach could be to do (I've not seen this done generally so someone please correct me if it's nuts): $ p(\theta|x) = \frac{p(x|\theta)p(\theta)}{p(x)}$ $ l(\theta|x) = l(x|\theta) + l(\theta) - l(x) $ $ \frac{dl(\theta|x)}{d\theta} = \frac{dl(x|\theta)}{d\theta} + \frac{dl(\theta)}{d\theta} = 0$ Then solve for $\theta$ (probably numerically).
Gradient of multivariate Gaussian log-likelihood
If the likelihood is not Gaussian it's not possible to say if there are analytic results. Also, the second bullet is then incorrect in general. Since Gaussian prior and general likelihood does not mak
Gradient of multivariate Gaussian log-likelihood If the likelihood is not Gaussian it's not possible to say if there are analytic results. Also, the second bullet is then incorrect in general. Since Gaussian prior and general likelihood does not make for conditional gaussian distributions on the vector components. One way to get the MAP would be to do a full Bayesian analysis, e.g. using MCMC and use the samples from the posterior to estimate it. [In which case you'd have better information available than only using the MAP.] Out of interest- why not go down this route anyhow? Another approach could be to do (I've not seen this done generally so someone please correct me if it's nuts): $ p(\theta|x) = \frac{p(x|\theta)p(\theta)}{p(x)}$ $ l(\theta|x) = l(x|\theta) + l(\theta) - l(x) $ $ \frac{dl(\theta|x)}{d\theta} = \frac{dl(x|\theta)}{d\theta} + \frac{dl(\theta)}{d\theta} = 0$ Then solve for $\theta$ (probably numerically).
Gradient of multivariate Gaussian log-likelihood If the likelihood is not Gaussian it's not possible to say if there are analytic results. Also, the second bullet is then incorrect in general. Since Gaussian prior and general likelihood does not mak
31,900
Relation between Scoring rule and Loss function in Parameter estimation and model selection?
MLEs are an example of a scoring rule. From Adrian E. Raftery and Tilmann Gneiting, "Strictly Proper Scoring Rules, Prediction and Estimation" Nov. 2005: In estimation problems, strictly proper scoring rules provide attractive loss and utility functions that can be tailored to a scientific problem. To fix the idea, suppose that we wish to fit a parametric model $P_\theta $ based on a sample $X_1,...,X_n$. To estimate $\theta$, we might measure the goodness-of-fit by the mean score $$\mathcal{S}_n(\theta)=\frac{1}{n}\sum_{i=1}^{n}S(P_\theta,X_i),$$ where $S$ is a strictly proper scoring rule. If $\theta_0$ denotes the true parameter, asymptotic arguments indicate that $\text{arg max}_\theta\mathcal{S}_n(\theta)\to\theta_0$ as $n\to\infty$. This suggests a general approach to estimation: choose a strictly proper scoring rule that is tailored to the scientific problem at hand, maximize $\mathcal{S}_n(\theta)$ over the parameter space, and take $\hat{\theta}_n=\text{arg max}_\theta\mathcal{S}_n(\theta)$ as the optimum score estimatior based on the scoring rule $S$... Maximum likelihood estimation forms a special case of optimum score estimation, and optimum score estimation forms a special case of $M$-estimation, in that the function to be optimized derives from a strictly proper scoring rule. So we can see that in general, we have a very flexible mechanism to estimating $\hat{\theta}$ by means of choice of $S$ and that MLE is just one particularly well-studied scoring rule within this framework.
Relation between Scoring rule and Loss function in Parameter estimation and model selection?
MLEs are an example of a scoring rule. From Adrian E. Raftery and Tilmann Gneiting, "Strictly Proper Scoring Rules, Prediction and Estimation" Nov. 2005: In estimation problems, strictly proper scori
Relation between Scoring rule and Loss function in Parameter estimation and model selection? MLEs are an example of a scoring rule. From Adrian E. Raftery and Tilmann Gneiting, "Strictly Proper Scoring Rules, Prediction and Estimation" Nov. 2005: In estimation problems, strictly proper scoring rules provide attractive loss and utility functions that can be tailored to a scientific problem. To fix the idea, suppose that we wish to fit a parametric model $P_\theta $ based on a sample $X_1,...,X_n$. To estimate $\theta$, we might measure the goodness-of-fit by the mean score $$\mathcal{S}_n(\theta)=\frac{1}{n}\sum_{i=1}^{n}S(P_\theta,X_i),$$ where $S$ is a strictly proper scoring rule. If $\theta_0$ denotes the true parameter, asymptotic arguments indicate that $\text{arg max}_\theta\mathcal{S}_n(\theta)\to\theta_0$ as $n\to\infty$. This suggests a general approach to estimation: choose a strictly proper scoring rule that is tailored to the scientific problem at hand, maximize $\mathcal{S}_n(\theta)$ over the parameter space, and take $\hat{\theta}_n=\text{arg max}_\theta\mathcal{S}_n(\theta)$ as the optimum score estimatior based on the scoring rule $S$... Maximum likelihood estimation forms a special case of optimum score estimation, and optimum score estimation forms a special case of $M$-estimation, in that the function to be optimized derives from a strictly proper scoring rule. So we can see that in general, we have a very flexible mechanism to estimating $\hat{\theta}$ by means of choice of $S$ and that MLE is just one particularly well-studied scoring rule within this framework.
Relation between Scoring rule and Loss function in Parameter estimation and model selection? MLEs are an example of a scoring rule. From Adrian E. Raftery and Tilmann Gneiting, "Strictly Proper Scoring Rules, Prediction and Estimation" Nov. 2005: In estimation problems, strictly proper scori