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
|
|---|---|---|---|---|---|---|
41,001
|
How to prove that the probability of spurious correlation increases with random walk length?
|
This isn't a direct answer to your question but provides some pointers that relate to the asymptotic distribution of the Pearson correlation in a Gaussian random walk. (Neither replacing Spearman with Pearson nor a Bernoulli random walk with a Gaussian is going to be of much consequence asymptotically; the Spearman may make a small difference, the increments to the random walk should make no difference asymptotically)
There's been a fair amount of work on this kind of problem in the econometrics literature -- unsurprisingly.
Phillips (1986) gives information about the asymptotic behaviour of $R^2$,
$$R^2 \mathbf{\Rightarrow} \frac{\zeta^2\left\{\int_0^1 W(t)^2\, \mathrm{d}t- (\int_0^1 W(t)\, \mathrm{d}t)^2 \right\}}{\int_0^1 V(t)^2\, \mathrm{d}t- (\int_0^1 V(t) \,\mathrm{d}t)^2}\,, $$
where
$\zeta = \frac{\int_0^1 V(t)W(t)\, \mathrm{d}t\,- \int_0^1 V(t)\, \mathrm{d}t\int_0^1 W(t)\, \mathrm{d}t }{\int_0^1 W(t)^2\, \mathrm{d}t\,-\, (\int_0^1 W(t)\, \mathrm{d}t)^2}$
and $V$ and $W$ are independent Wiener processes; at another point Phillips explains $\mathbf{\Rightarrow}$ (which should be able to be carried over, mutatis mutandis):
The notation ‘$\mathbf{\Rightarrow}$’ [...] is used to signify the
weak convergence of the probability measure of $Z_T(t)$ to the probability
measure (here, multivariate Wiener measure) of the random function $Z(t)$.
(p317 and appendix) while Marmol(1996) discusses Bannerjee et al. (1993)
who describe the density of R (rather than $R^2$):
When both variables are I(1), the density of R is close to a
semi-ellipse with excess frequency at both ends of the distribution
and, consequently, values of R well away from zero are far more
likely here than in [the case of two I(0) series].
(I didn't get hold of Bannerjee et al)
I don't agree with their characterization of the shape of the distribution of R; convergence to the limiting case seems to be very rapid, and the shape is almost flat over the middle half of the range:
Those are histograms of the distribution of the correlation of independent $I(1)$ series (cumulated Gaussian) of different lengths -- $n=10,100,1000,10000$, with 100,000 values
generated for each case. We see that the distribution hardly changes between 10 and 100, and seems to be essentially stable after that. It looks to me like a slightly rounded off symmetric trapezium (/trapezoid), flat in the middle half of the range.
Meanwhile the null distribution (under the assumption of independent $I(0)$ series) would be $N(0,\frac{1}{n})$; the standard deviation decreases as $1/\sqrt{n}$; this means more and more of the above distribution is in the critical region as we take longer series.
Here's the corresponding histograms for the Bernoulli random walk and Spearman correlation:
Those are histograms of the distribution of the Spearman correlation of independent cumulated random $\pm 1$ values for series of varying lengths -- $n=10,100,1000,10000$, with 100,000 values
generated for each case.
The equilibrium distribution looks about the same as for the Pearson/Gaussian case, but is perhaps just a little "rounder" (less flat in the middle half).
(Some additional simulations show that this slight difference is indeed mainly due to the Spearman/Pearson difference rather than the binomial/Gaussian)
Nevertheless, even if the distribution is very slightly different, the result will be the same -- both tests will see a very similar increase rejection rate with sample size.
So for random walks we have this stable distribution that settles down pretty quickly with sample size and then stays the same, but the standard deviation of the null distribution of the correlation coefficient shrinks as $1/\sqrt{n}$ so more and more of this distribution will lie in the rejection region as $n$ increases.
Looked at another way -- under the null hypothesis, $\sqrt{n}\,r$ is approximately standard normal, but because the distribution of these correlations don't shrink around zero as sample size increases, $\sqrt{n}\,r$ gets wider with $n$ -- less and less of it will lie within $0 \pm z_{1-\alpha/2}$ as $n$ increases.
Phillips, P.C.B, (1986),
"Understanding Spurious Regressions in Econometrics"
Journal of Econometrics, 33, p311-340.
However the published version has a number of printing issues
so you may also want this working version to be able to get some of the details:
https://cowles.yale.edu/sites/default/files/files/pub/d07/d0757.pdf
Marmol, F., (1996),
Correlation theory of spuriously related higher order integrated processes,
Economics Letters, 50, 169-173
Banerjee, A., Dolado, J.J., Galbraith, J.W. and D.F. Hendry, (1993),
Co-integration, error-correction, and the econometric analysis of non-stationary data
(Oxford University Press, Oxford).
|
How to prove that the probability of spurious correlation increases with random walk length?
|
This isn't a direct answer to your question but provides some pointers that relate to the asymptotic distribution of the Pearson correlation in a Gaussian random walk. (Neither replacing Spearman with
|
How to prove that the probability of spurious correlation increases with random walk length?
This isn't a direct answer to your question but provides some pointers that relate to the asymptotic distribution of the Pearson correlation in a Gaussian random walk. (Neither replacing Spearman with Pearson nor a Bernoulli random walk with a Gaussian is going to be of much consequence asymptotically; the Spearman may make a small difference, the increments to the random walk should make no difference asymptotically)
There's been a fair amount of work on this kind of problem in the econometrics literature -- unsurprisingly.
Phillips (1986) gives information about the asymptotic behaviour of $R^2$,
$$R^2 \mathbf{\Rightarrow} \frac{\zeta^2\left\{\int_0^1 W(t)^2\, \mathrm{d}t- (\int_0^1 W(t)\, \mathrm{d}t)^2 \right\}}{\int_0^1 V(t)^2\, \mathrm{d}t- (\int_0^1 V(t) \,\mathrm{d}t)^2}\,, $$
where
$\zeta = \frac{\int_0^1 V(t)W(t)\, \mathrm{d}t\,- \int_0^1 V(t)\, \mathrm{d}t\int_0^1 W(t)\, \mathrm{d}t }{\int_0^1 W(t)^2\, \mathrm{d}t\,-\, (\int_0^1 W(t)\, \mathrm{d}t)^2}$
and $V$ and $W$ are independent Wiener processes; at another point Phillips explains $\mathbf{\Rightarrow}$ (which should be able to be carried over, mutatis mutandis):
The notation ‘$\mathbf{\Rightarrow}$’ [...] is used to signify the
weak convergence of the probability measure of $Z_T(t)$ to the probability
measure (here, multivariate Wiener measure) of the random function $Z(t)$.
(p317 and appendix) while Marmol(1996) discusses Bannerjee et al. (1993)
who describe the density of R (rather than $R^2$):
When both variables are I(1), the density of R is close to a
semi-ellipse with excess frequency at both ends of the distribution
and, consequently, values of R well away from zero are far more
likely here than in [the case of two I(0) series].
(I didn't get hold of Bannerjee et al)
I don't agree with their characterization of the shape of the distribution of R; convergence to the limiting case seems to be very rapid, and the shape is almost flat over the middle half of the range:
Those are histograms of the distribution of the correlation of independent $I(1)$ series (cumulated Gaussian) of different lengths -- $n=10,100,1000,10000$, with 100,000 values
generated for each case. We see that the distribution hardly changes between 10 and 100, and seems to be essentially stable after that. It looks to me like a slightly rounded off symmetric trapezium (/trapezoid), flat in the middle half of the range.
Meanwhile the null distribution (under the assumption of independent $I(0)$ series) would be $N(0,\frac{1}{n})$; the standard deviation decreases as $1/\sqrt{n}$; this means more and more of the above distribution is in the critical region as we take longer series.
Here's the corresponding histograms for the Bernoulli random walk and Spearman correlation:
Those are histograms of the distribution of the Spearman correlation of independent cumulated random $\pm 1$ values for series of varying lengths -- $n=10,100,1000,10000$, with 100,000 values
generated for each case.
The equilibrium distribution looks about the same as for the Pearson/Gaussian case, but is perhaps just a little "rounder" (less flat in the middle half).
(Some additional simulations show that this slight difference is indeed mainly due to the Spearman/Pearson difference rather than the binomial/Gaussian)
Nevertheless, even if the distribution is very slightly different, the result will be the same -- both tests will see a very similar increase rejection rate with sample size.
So for random walks we have this stable distribution that settles down pretty quickly with sample size and then stays the same, but the standard deviation of the null distribution of the correlation coefficient shrinks as $1/\sqrt{n}$ so more and more of this distribution will lie in the rejection region as $n$ increases.
Looked at another way -- under the null hypothesis, $\sqrt{n}\,r$ is approximately standard normal, but because the distribution of these correlations don't shrink around zero as sample size increases, $\sqrt{n}\,r$ gets wider with $n$ -- less and less of it will lie within $0 \pm z_{1-\alpha/2}$ as $n$ increases.
Phillips, P.C.B, (1986),
"Understanding Spurious Regressions in Econometrics"
Journal of Econometrics, 33, p311-340.
However the published version has a number of printing issues
so you may also want this working version to be able to get some of the details:
https://cowles.yale.edu/sites/default/files/files/pub/d07/d0757.pdf
Marmol, F., (1996),
Correlation theory of spuriously related higher order integrated processes,
Economics Letters, 50, 169-173
Banerjee, A., Dolado, J.J., Galbraith, J.W. and D.F. Hendry, (1993),
Co-integration, error-correction, and the econometric analysis of non-stationary data
(Oxford University Press, Oxford).
|
How to prove that the probability of spurious correlation increases with random walk length?
This isn't a direct answer to your question but provides some pointers that relate to the asymptotic distribution of the Pearson correlation in a Gaussian random walk. (Neither replacing Spearman with
|
41,002
|
How to prove that the probability of spurious correlation increases with random walk length?
|
Ok, I am gonna try and take whuber's advice to attend to the distribution of $\rho_{\text{s}}$. I do not have a mathematical statistics background, so gentle prodding me to make my thinking more rigorous is welcome.
Here goes:
The random walk length $T$ is a natural number.
There are $2^{T}$ possible random walks of this form for a specific value of $T$. This is because for each time $t$ from $1$ to $T$ has two possible outcomes.
There are therefore $2^{2T}$ possible pairs of of random walks, for a specific value of $T$ (i.e. there are $2^{T}$ possible random walks to pair with each random walk of length $T$).
For all values of $T>3$, $\rho_{\text{s}} \ne 0$, for $T=3$ half the values of $\rho_{\text{s}} \ne 0$; for $T=2$ all four values of $\rho_{\text{s}} \ne 0$. Therefore, $E(\rho_{\text{s}}) \ne 0$ for all $T$. (This is because for all random walks $\text{cov}(\text{rank}(RW_{1}), \text{rank}(RW_{2}))$ is non-zero, except in half the cases when $T=3$.)
As $\lim{T \to \infty}$, $\sigma_{\rho_{\text{s}}}$ gets small as fast as $n^{3} - n$. Therefore $E(t)$ gets big, and $E(p)$ gets small as $T$ grows.
|
How to prove that the probability of spurious correlation increases with random walk length?
|
Ok, I am gonna try and take whuber's advice to attend to the distribution of $\rho_{\text{s}}$. I do not have a mathematical statistics background, so gentle prodding me to make my thinking more rigor
|
How to prove that the probability of spurious correlation increases with random walk length?
Ok, I am gonna try and take whuber's advice to attend to the distribution of $\rho_{\text{s}}$. I do not have a mathematical statistics background, so gentle prodding me to make my thinking more rigorous is welcome.
Here goes:
The random walk length $T$ is a natural number.
There are $2^{T}$ possible random walks of this form for a specific value of $T$. This is because for each time $t$ from $1$ to $T$ has two possible outcomes.
There are therefore $2^{2T}$ possible pairs of of random walks, for a specific value of $T$ (i.e. there are $2^{T}$ possible random walks to pair with each random walk of length $T$).
For all values of $T>3$, $\rho_{\text{s}} \ne 0$, for $T=3$ half the values of $\rho_{\text{s}} \ne 0$; for $T=2$ all four values of $\rho_{\text{s}} \ne 0$. Therefore, $E(\rho_{\text{s}}) \ne 0$ for all $T$. (This is because for all random walks $\text{cov}(\text{rank}(RW_{1}), \text{rank}(RW_{2}))$ is non-zero, except in half the cases when $T=3$.)
As $\lim{T \to \infty}$, $\sigma_{\rho_{\text{s}}}$ gets small as fast as $n^{3} - n$. Therefore $E(t)$ gets big, and $E(p)$ gets small as $T$ grows.
|
How to prove that the probability of spurious correlation increases with random walk length?
Ok, I am gonna try and take whuber's advice to attend to the distribution of $\rho_{\text{s}}$. I do not have a mathematical statistics background, so gentle prodding me to make my thinking more rigor
|
41,003
|
2 hidden layers are more powerful than 1
|
I found the answer to my question in the paper Feedback stabilization using two-hidden-layer nets by E.D. Sontag. From the introduction:
It is by now well-known that functions computable by nets with a single hidden layer can approximate continuous functions, uniformly on compacts, under only weak assumptions on $\theta$. Consider now the following inversion problem: Given a continuous function $f : \mathbb{R}^m \rightarrow \mathbb{R}^p$, a compact subset $C \subseteq \mathbb{R}^p$ included in the image of $f$, and an $\varepsilon > 0$, find a function $\phi : \mathbb{R}^p \rightarrow \mathbb{R}^m$ so that $\|f(\phi(x)) - x \| < \varepsilon$ for all $x \in C$. It is trivial to see that in general discontinuous functions $\phi$ are needed. We show later that nets with just one hidden layer are not enough to guarantee the solution of all such problems, but nets with two hidden layers are.
|
2 hidden layers are more powerful than 1
|
I found the answer to my question in the paper Feedback stabilization using two-hidden-layer nets by E.D. Sontag. From the introduction:
It is by now well-known that functions computable by nets with
|
2 hidden layers are more powerful than 1
I found the answer to my question in the paper Feedback stabilization using two-hidden-layer nets by E.D. Sontag. From the introduction:
It is by now well-known that functions computable by nets with a single hidden layer can approximate continuous functions, uniformly on compacts, under only weak assumptions on $\theta$. Consider now the following inversion problem: Given a continuous function $f : \mathbb{R}^m \rightarrow \mathbb{R}^p$, a compact subset $C \subseteq \mathbb{R}^p$ included in the image of $f$, and an $\varepsilon > 0$, find a function $\phi : \mathbb{R}^p \rightarrow \mathbb{R}^m$ so that $\|f(\phi(x)) - x \| < \varepsilon$ for all $x \in C$. It is trivial to see that in general discontinuous functions $\phi$ are needed. We show later that nets with just one hidden layer are not enough to guarantee the solution of all such problems, but nets with two hidden layers are.
|
2 hidden layers are more powerful than 1
I found the answer to my question in the paper Feedback stabilization using two-hidden-layer nets by E.D. Sontag. From the introduction:
It is by now well-known that functions computable by nets with
|
41,004
|
2 hidden layers are more powerful than 1
|
Another paper about a qualitative difference between 1- and 2-hidden layer networks:
Neural networks for localized approximation (1994)
We prove that feedforward artificial neural networks with a single hidden layer and an ideal sigmoidal response function cannot provide localized approximation in a Euclidean space of dimension higher than one. We also show that networks with two hidden layers can be designed to provide localized approximation.
The objective of this paper is to investigate the possibility of constructing networks suitable for localized approximation, i.e., a network with the property that if the target function is modified only on a small subset of the Euclidean space, then only a few neurons, rather than the entire network, need to be retrained... We prove that if the dimension of the input space is greater than one, then such a network with one hidden layer and a Heaviside activation function cannot be constructed. In contrast, we also show that a network with two or more hidden layers can always be constructed to accomplish the task.
AMS link
|
2 hidden layers are more powerful than 1
|
Another paper about a qualitative difference between 1- and 2-hidden layer networks:
Neural networks for localized approximation (1994)
We prove that feedforward artificial neural networks with a sin
|
2 hidden layers are more powerful than 1
Another paper about a qualitative difference between 1- and 2-hidden layer networks:
Neural networks for localized approximation (1994)
We prove that feedforward artificial neural networks with a single hidden layer and an ideal sigmoidal response function cannot provide localized approximation in a Euclidean space of dimension higher than one. We also show that networks with two hidden layers can be designed to provide localized approximation.
The objective of this paper is to investigate the possibility of constructing networks suitable for localized approximation, i.e., a network with the property that if the target function is modified only on a small subset of the Euclidean space, then only a few neurons, rather than the entire network, need to be retrained... We prove that if the dimension of the input space is greater than one, then such a network with one hidden layer and a Heaviside activation function cannot be constructed. In contrast, we also show that a network with two or more hidden layers can always be constructed to accomplish the task.
AMS link
|
2 hidden layers are more powerful than 1
Another paper about a qualitative difference between 1- and 2-hidden layer networks:
Neural networks for localized approximation (1994)
We prove that feedforward artificial neural networks with a sin
|
41,005
|
Understanding batch normalization
|
Their notation is confusing. For instance, they use the hat symbol to denote the normalized variable $\hat x=x-E[x]$, then even worse they use the expectation symbol to denote what is clearly a sample average estimator: $E[x]=\frac 1 N\sum_{i=1}^Nx_i$
I assume that when you wrote $E[b]=b$, you mean the expectation of bias. That's not what they would denote by $E[b]$: they'd mean a simple sample average estimator, the quantity that is usually denoted as $\bar b=\frac 1 N\sum_jb_j$, where $b_j$ is the bias learned from a batch $j$.
All they're saying in this paragraph is that you have to be mindful of how you implement normalization, because if you do it wrong then it will interfere with the gradient descent. Their example is first learning the bias, then normalizing. So, you learn the bias $\Delta b$ from a batch, but then when you normalize subsequently you negate the learning by subtracting what you learned.
It goes like this. First you learned $\Delta b$, which means you are prepared to output $u+b+\Delta b$. However, you squeezed another operation just before outputting from the layer: you decided to normalize. So, you subtract the sample average, i.e. what they denote unfortunately by $E[u+b+\Delta b]$. This will lead to $E[\Delta b]$ cancelling each other in gradient descent and normalization, i.e.e you didn't learn anything.
|
Understanding batch normalization
|
Their notation is confusing. For instance, they use the hat symbol to denote the normalized variable $\hat x=x-E[x]$, then even worse they use the expectation symbol to denote what is clearly a sample
|
Understanding batch normalization
Their notation is confusing. For instance, they use the hat symbol to denote the normalized variable $\hat x=x-E[x]$, then even worse they use the expectation symbol to denote what is clearly a sample average estimator: $E[x]=\frac 1 N\sum_{i=1}^Nx_i$
I assume that when you wrote $E[b]=b$, you mean the expectation of bias. That's not what they would denote by $E[b]$: they'd mean a simple sample average estimator, the quantity that is usually denoted as $\bar b=\frac 1 N\sum_jb_j$, where $b_j$ is the bias learned from a batch $j$.
All they're saying in this paragraph is that you have to be mindful of how you implement normalization, because if you do it wrong then it will interfere with the gradient descent. Their example is first learning the bias, then normalizing. So, you learn the bias $\Delta b$ from a batch, but then when you normalize subsequently you negate the learning by subtracting what you learned.
It goes like this. First you learned $\Delta b$, which means you are prepared to output $u+b+\Delta b$. However, you squeezed another operation just before outputting from the layer: you decided to normalize. So, you subtract the sample average, i.e. what they denote unfortunately by $E[u+b+\Delta b]$. This will lead to $E[\Delta b]$ cancelling each other in gradient descent and normalization, i.e.e you didn't learn anything.
|
Understanding batch normalization
Their notation is confusing. For instance, they use the hat symbol to denote the normalized variable $\hat x=x-E[x]$, then even worse they use the expectation symbol to denote what is clearly a sample
|
41,006
|
Feature scaling in svm: Does it depend on the Kernel?
|
Yes feature scaling depends on the kernel and in general it's a good idea. The kernel is effectively a distance and if different features vary on different scales then this can matter. For the RBF kernel, for instance, we have
$$
K(x, x') = \exp\left(-\gamma ||x-x'||^2\right)
$$
so if one dimension takes much larger values than others then it will dominate the kernel values and you'll lose some signal in other dimensions. This applies to the linear kernel too.
But this doesn't apply to all kernels, since some have scaling built in. For example, you could do something like the ARD kernel or Mahalanobis kernel with
$$
K(x, x') = \exp\left(-\gamma (x-x')^T\hat \Sigma^{-1}(x-x')\right)
$$
where $\hat \Sigma$ is the sample covariance matrix or maybe just the diagonal matrix of individual variances. As a function of $x$ and $x'$ this is still PD so it's a valid kernel.
As a general strategy for deciding if this is an issue for any particular kernel, just do what they did in the linked question and try it with data like $x=(1000,1,2,3)$, $x'=(500, .5, 3, 2)$ and see if the first dimension necessarily dominates.
Another way to try to assess a given kernel is to try to see if it inherits scale issues from subfunctions. For example, consider the polynomial kernel $K_{poly}(x,x') = (a+cx^Tx')^d$. We can write this as a function of the linear kernel $x^Tx'$, which we already know to be sensitive to scale, and the map $z \mapsto (a+cz)^d$ won't undo scale issues, so we can see that the polynomial kernel inherits these issues. We can do a similar analysis by writing the RBF kernel as a function of the scale-sensitive $||x-x'||^2$.
|
Feature scaling in svm: Does it depend on the Kernel?
|
Yes feature scaling depends on the kernel and in general it's a good idea. The kernel is effectively a distance and if different features vary on different scales then this can matter. For the RBF ker
|
Feature scaling in svm: Does it depend on the Kernel?
Yes feature scaling depends on the kernel and in general it's a good idea. The kernel is effectively a distance and if different features vary on different scales then this can matter. For the RBF kernel, for instance, we have
$$
K(x, x') = \exp\left(-\gamma ||x-x'||^2\right)
$$
so if one dimension takes much larger values than others then it will dominate the kernel values and you'll lose some signal in other dimensions. This applies to the linear kernel too.
But this doesn't apply to all kernels, since some have scaling built in. For example, you could do something like the ARD kernel or Mahalanobis kernel with
$$
K(x, x') = \exp\left(-\gamma (x-x')^T\hat \Sigma^{-1}(x-x')\right)
$$
where $\hat \Sigma$ is the sample covariance matrix or maybe just the diagonal matrix of individual variances. As a function of $x$ and $x'$ this is still PD so it's a valid kernel.
As a general strategy for deciding if this is an issue for any particular kernel, just do what they did in the linked question and try it with data like $x=(1000,1,2,3)$, $x'=(500, .5, 3, 2)$ and see if the first dimension necessarily dominates.
Another way to try to assess a given kernel is to try to see if it inherits scale issues from subfunctions. For example, consider the polynomial kernel $K_{poly}(x,x') = (a+cx^Tx')^d$. We can write this as a function of the linear kernel $x^Tx'$, which we already know to be sensitive to scale, and the map $z \mapsto (a+cz)^d$ won't undo scale issues, so we can see that the polynomial kernel inherits these issues. We can do a similar analysis by writing the RBF kernel as a function of the scale-sensitive $||x-x'||^2$.
|
Feature scaling in svm: Does it depend on the Kernel?
Yes feature scaling depends on the kernel and in general it's a good idea. The kernel is effectively a distance and if different features vary on different scales then this can matter. For the RBF ker
|
41,007
|
How to know when to use linear dimensionality reduction vs non-linear dimensionality reduction?
|
One approach is to learn more about the structure of the data. Dimensionality reduction supposes that the data are distributed near a low dimensional manifold. If this is the case, one might choose PCA if the manifold is (approximately) linear, and nonlinear dimensionality reduction (NLDR) if the manifold is nonlinear. So, some questions to address: are the data low dimensional and, if so, are they distributed near a nonlinear manifold?
Estimating dimensionality and checking for nonlinearity
A good first step is to perform PCA and examine the variance along each component, or the fraction of variance explained ($R^2$) as a function of the number of components. Typically, one looks for an elbow in the plot, or the number of components needed to explain some fixed fraction of the variance (often 95%). Alternatively, there are more principled procedures for choosing the number of components. This gives an estimate of the dimensionality of the linear subspace that the data approximately occupy.
If the data are distributed near a low dimensional nonlinear manifold, then the intrinsic dimensionality will be less than the dimensionality of this linear subspace. For example, imagine a curved 2d sheet embedded in 3 dimensions (e.g. the classic swiss roll manifold). Now project it linearly into 5 dimensions. The extrinsic dimensionality would be 5, and the data would occupy a 3 dimensional linear subspace. However, the intrinsic dimensionality would be 2. The dimensionality of the linear subspace is higher than the intrinsic dimensionality because of the curvature of the manifold.
Many intrinsic dimensionality estimators have been described in the literature. Using one of these methods, one can estimate the intrinsic dimensionality of the data and compare this to the dimensionality of the linear subspace (estimated using PCA). If the intrinsic dimensionality is less, this suggests the manifold could be nonlinear. Keep in mind that we're working with estimates that may be subject to error, so this is somewhat of a heuristic procedure.
Fortunately, intrinsic dimensionality estimators are often independent of any particular NLDR algorithm. This is nice because there are dozens of NLDR algorithms to choose from, and they each operate under different assumptions and preserve different forms of structure in the data. Keep in mind that an intrinsic dimensionality of $k$ doesn't imply that any particular NLDR algorithm will be able to find a good $k$ dimensional representation. For example the surface of a sphere is intrinsically two dimensional, but many NLDR algorithms would require three dimensions to represent it because it can't be flattened.
Other considerations
Sometimes a choice can be made on the basis of practical considerations. These are things like runtime/memory costs, ease of use and/or interpretation, etc. I described some of these issues for PCA vs. NLDR in this post (the question was framed as 'why use PCA instead of NLDR?' so the answer leans toward PCA, which is not always the most appropriate method).
Sometimes it makes sense to simply try multiple methods and see what works best for your application. For example, if dimensionality reduction is used as a preprocessing step for a downstream supervised learning algorithm, then the choice of dimensionality reduction algorithm is a model selection problem (along with the dimensionality and any hyperparameters). This can be addressed using cross validation. Sometimes no dimensionality reduction at all works best in this context. If dimensionality reduction is performed for visualization, then you might choose the method that helps give better visual intuition about the data (highly application specific).
|
How to know when to use linear dimensionality reduction vs non-linear dimensionality reduction?
|
One approach is to learn more about the structure of the data. Dimensionality reduction supposes that the data are distributed near a low dimensional manifold. If this is the case, one might choose PC
|
How to know when to use linear dimensionality reduction vs non-linear dimensionality reduction?
One approach is to learn more about the structure of the data. Dimensionality reduction supposes that the data are distributed near a low dimensional manifold. If this is the case, one might choose PCA if the manifold is (approximately) linear, and nonlinear dimensionality reduction (NLDR) if the manifold is nonlinear. So, some questions to address: are the data low dimensional and, if so, are they distributed near a nonlinear manifold?
Estimating dimensionality and checking for nonlinearity
A good first step is to perform PCA and examine the variance along each component, or the fraction of variance explained ($R^2$) as a function of the number of components. Typically, one looks for an elbow in the plot, or the number of components needed to explain some fixed fraction of the variance (often 95%). Alternatively, there are more principled procedures for choosing the number of components. This gives an estimate of the dimensionality of the linear subspace that the data approximately occupy.
If the data are distributed near a low dimensional nonlinear manifold, then the intrinsic dimensionality will be less than the dimensionality of this linear subspace. For example, imagine a curved 2d sheet embedded in 3 dimensions (e.g. the classic swiss roll manifold). Now project it linearly into 5 dimensions. The extrinsic dimensionality would be 5, and the data would occupy a 3 dimensional linear subspace. However, the intrinsic dimensionality would be 2. The dimensionality of the linear subspace is higher than the intrinsic dimensionality because of the curvature of the manifold.
Many intrinsic dimensionality estimators have been described in the literature. Using one of these methods, one can estimate the intrinsic dimensionality of the data and compare this to the dimensionality of the linear subspace (estimated using PCA). If the intrinsic dimensionality is less, this suggests the manifold could be nonlinear. Keep in mind that we're working with estimates that may be subject to error, so this is somewhat of a heuristic procedure.
Fortunately, intrinsic dimensionality estimators are often independent of any particular NLDR algorithm. This is nice because there are dozens of NLDR algorithms to choose from, and they each operate under different assumptions and preserve different forms of structure in the data. Keep in mind that an intrinsic dimensionality of $k$ doesn't imply that any particular NLDR algorithm will be able to find a good $k$ dimensional representation. For example the surface of a sphere is intrinsically two dimensional, but many NLDR algorithms would require three dimensions to represent it because it can't be flattened.
Other considerations
Sometimes a choice can be made on the basis of practical considerations. These are things like runtime/memory costs, ease of use and/or interpretation, etc. I described some of these issues for PCA vs. NLDR in this post (the question was framed as 'why use PCA instead of NLDR?' so the answer leans toward PCA, which is not always the most appropriate method).
Sometimes it makes sense to simply try multiple methods and see what works best for your application. For example, if dimensionality reduction is used as a preprocessing step for a downstream supervised learning algorithm, then the choice of dimensionality reduction algorithm is a model selection problem (along with the dimensionality and any hyperparameters). This can be addressed using cross validation. Sometimes no dimensionality reduction at all works best in this context. If dimensionality reduction is performed for visualization, then you might choose the method that helps give better visual intuition about the data (highly application specific).
|
How to know when to use linear dimensionality reduction vs non-linear dimensionality reduction?
One approach is to learn more about the structure of the data. Dimensionality reduction supposes that the data are distributed near a low dimensional manifold. If this is the case, one might choose PC
|
41,008
|
What does this E symbol mean? [duplicate]
|
In mathematics and statistics many symbols are used to denote different things, e.g. $\pi$ does not always have to be the $3.14.15...$ constant. However the uppercase "E" (written in many forms, e.g. $\mathbb{E}, E, \mathrm{E}$) is almost always used in statistics to denote the expected value. In the case of your equation
$$
\mathbb{E}_{x\sim p_\text{data}(x)}\left( \log D(x) \right)
$$
means: the expected value of $\log D(x)$ given $x$ distributed as $p_\text{data}(x)$.
|
What does this E symbol mean? [duplicate]
|
In mathematics and statistics many symbols are used to denote different things, e.g. $\pi$ does not always have to be the $3.14.15...$ constant. However the uppercase "E" (written in many forms, e.g.
|
What does this E symbol mean? [duplicate]
In mathematics and statistics many symbols are used to denote different things, e.g. $\pi$ does not always have to be the $3.14.15...$ constant. However the uppercase "E" (written in many forms, e.g. $\mathbb{E}, E, \mathrm{E}$) is almost always used in statistics to denote the expected value. In the case of your equation
$$
\mathbb{E}_{x\sim p_\text{data}(x)}\left( \log D(x) \right)
$$
means: the expected value of $\log D(x)$ given $x$ distributed as $p_\text{data}(x)$.
|
What does this E symbol mean? [duplicate]
In mathematics and statistics many symbols are used to denote different things, e.g. $\pi$ does not always have to be the $3.14.15...$ constant. However the uppercase "E" (written in many forms, e.g.
|
41,009
|
The fundamental theorem of simulation
|
Your question is unclear: when simulating $X\sim f(x)$, one can instead simulate$$(X,U)\sim\mathcal{U}(\{(x,u);\ 0<u<f(x)\})$$which has the joint density$$\mathbb{I}_{(0,f(x)}(u)\mathbb{I}_\mathcal{X}(x)$$and then use only the $X$ component in the simulation. For instance, here is a figure from our book depicting many realisations of such a Uniform when $f$ is the density of a Beta distribution [black dots]. The remaining dots are rejected simulations from a Uniform over a square that contains the subgraph of $f$.
Once this new target is set, any simulation method aimed at it is valid. Like Accept-Reject in the above picture. What matters is to find an efficient simulation method. (The quote is then wrong in that $U$ is no longer $\mathcal{U}(0,1)$
As to your second question, the $U$ component in the above indeed behaves like a latent variable in the sense that $$f(x)=\int_0^\infty f(x,u)\text{d}u$$ represents the density of interest as the marginal density of a joint distribution of $(X,U)$, $U$ being "unobserved". However, latent variables are most often used in statistical settings where the joint $f(x,u)$ makes life easier, for instance allowing for an EM algorithm. In that sense $U$ is not a latent variable since this is not a statistical problem but a simulation problem. I would use "auxiliary" rather than "latent".
|
The fundamental theorem of simulation
|
Your question is unclear: when simulating $X\sim f(x)$, one can instead simulate$$(X,U)\sim\mathcal{U}(\{(x,u);\ 0<u<f(x)\})$$which has the joint density$$\mathbb{I}_{(0,f(x)}(u)\mathbb{I}_\mathcal{X}
|
The fundamental theorem of simulation
Your question is unclear: when simulating $X\sim f(x)$, one can instead simulate$$(X,U)\sim\mathcal{U}(\{(x,u);\ 0<u<f(x)\})$$which has the joint density$$\mathbb{I}_{(0,f(x)}(u)\mathbb{I}_\mathcal{X}(x)$$and then use only the $X$ component in the simulation. For instance, here is a figure from our book depicting many realisations of such a Uniform when $f$ is the density of a Beta distribution [black dots]. The remaining dots are rejected simulations from a Uniform over a square that contains the subgraph of $f$.
Once this new target is set, any simulation method aimed at it is valid. Like Accept-Reject in the above picture. What matters is to find an efficient simulation method. (The quote is then wrong in that $U$ is no longer $\mathcal{U}(0,1)$
As to your second question, the $U$ component in the above indeed behaves like a latent variable in the sense that $$f(x)=\int_0^\infty f(x,u)\text{d}u$$ represents the density of interest as the marginal density of a joint distribution of $(X,U)$, $U$ being "unobserved". However, latent variables are most often used in statistical settings where the joint $f(x,u)$ makes life easier, for instance allowing for an EM algorithm. In that sense $U$ is not a latent variable since this is not a statistical problem but a simulation problem. I would use "auxiliary" rather than "latent".
|
The fundamental theorem of simulation
Your question is unclear: when simulating $X\sim f(x)$, one can instead simulate$$(X,U)\sim\mathcal{U}(\{(x,u);\ 0<u<f(x)\})$$which has the joint density$$\mathbb{I}_{(0,f(x)}(u)\mathbb{I}_\mathcal{X}
|
41,010
|
Optimum number of epochs and neurons for an LSTM network
|
The optimum parametrization depends on the problem (there is not a rule that can do what you want), but there are some techniques that can help you, see the link below.
http://machinelearningmastery.com/tune-lstm-hyperparameters-keras-time-series-forecasting/
Basically what the upper link does is:
First calculate the RMSE of train and test data for each epoch with different number of maximum epochs. This prevents you to overfit and gives an aproximated range of epochs to start with.
Afterwards you can repeat the method but maintaining the epochs constant (previously selected) and testing with different neuron number.
It's important that the RMSE test curve must not be convex as it denotes overfitting. Whith this method you can tune this paramaters obtaining a good trade off between accuracy and generalization.
|
Optimum number of epochs and neurons for an LSTM network
|
The optimum parametrization depends on the problem (there is not a rule that can do what you want), but there are some techniques that can help you, see the link below.
http://machinelearningmastery.
|
Optimum number of epochs and neurons for an LSTM network
The optimum parametrization depends on the problem (there is not a rule that can do what you want), but there are some techniques that can help you, see the link below.
http://machinelearningmastery.com/tune-lstm-hyperparameters-keras-time-series-forecasting/
Basically what the upper link does is:
First calculate the RMSE of train and test data for each epoch with different number of maximum epochs. This prevents you to overfit and gives an aproximated range of epochs to start with.
Afterwards you can repeat the method but maintaining the epochs constant (previously selected) and testing with different neuron number.
It's important that the RMSE test curve must not be convex as it denotes overfitting. Whith this method you can tune this paramaters obtaining a good trade off between accuracy and generalization.
|
Optimum number of epochs and neurons for an LSTM network
The optimum parametrization depends on the problem (there is not a rule that can do what you want), but there are some techniques that can help you, see the link below.
http://machinelearningmastery.
|
41,011
|
Logistic regression for a continuous dependent variable
|
Your first option could work. It assumes that the residuals from the model on the transformed data are normally distributed. You need to check this. If it's true, you will be OK.
Option 2 depends on how you set up the GLM. Simply using a logit link function does not necessitate that you use any particular response distribution. Certainly, the logit link is most commonly used with a binomial distribution, but it doesn't need to be. I assume you are thinking about something like using a normal distribution for the response with a logit link. If so, that probably wouldn't be a great choice, as the normal distribution assumes the data are unbounded, but yours are not. For example, the positive residuals you could have could only exist in the interval $(1-\hat\mu,\ 0)$, whereas the negative residuals could only exist in $(0,\ 0-\hat\mu)$; it is very likely you would have heteroscedastic residuals with differing skews. Even if not, they could not possibly be normal. The effect that will have on the predictive ability of the model is unclear to me, but I just wouldn't go this route.
My guess is that your best be may be to use Beta regression. The Beta distribution is very flexible and should typically be the best choice for continuous proportions. Note however, that it is possible to have data bounded by 0 and 1 that do not fit any Beta distribution, so you again need to check if it's sensible.
|
Logistic regression for a continuous dependent variable
|
Your first option could work. It assumes that the residuals from the model on the transformed data are normally distributed. You need to check this. If it's true, you will be OK.
Option 2 depends
|
Logistic regression for a continuous dependent variable
Your first option could work. It assumes that the residuals from the model on the transformed data are normally distributed. You need to check this. If it's true, you will be OK.
Option 2 depends on how you set up the GLM. Simply using a logit link function does not necessitate that you use any particular response distribution. Certainly, the logit link is most commonly used with a binomial distribution, but it doesn't need to be. I assume you are thinking about something like using a normal distribution for the response with a logit link. If so, that probably wouldn't be a great choice, as the normal distribution assumes the data are unbounded, but yours are not. For example, the positive residuals you could have could only exist in the interval $(1-\hat\mu,\ 0)$, whereas the negative residuals could only exist in $(0,\ 0-\hat\mu)$; it is very likely you would have heteroscedastic residuals with differing skews. Even if not, they could not possibly be normal. The effect that will have on the predictive ability of the model is unclear to me, but I just wouldn't go this route.
My guess is that your best be may be to use Beta regression. The Beta distribution is very flexible and should typically be the best choice for continuous proportions. Note however, that it is possible to have data bounded by 0 and 1 that do not fit any Beta distribution, so you again need to check if it's sensible.
|
Logistic regression for a continuous dependent variable
Your first option could work. It assumes that the residuals from the model on the transformed data are normally distributed. You need to check this. If it's true, you will be OK.
Option 2 depends
|
41,012
|
Logistic regression for a continuous dependent variable
|
Your idea is to use the logit (I call it $f$ to make clear that what $f$ is does not matter in what I will explain) in order to fall between 0 and 1. This idea of yours is not especially related to logistic regression. It is similar to using a log link function in order to deal with a positive $Y$.
So the difference between model 1 and model 2 is the same as if you used a log. The first is transformed linear regression, the second is GLM. The key difference is :
Transformed : $E(f(Y)|X)=\beta X$
GLM : $f(E(Y|X))=\beta X$
What is best ?
It depends on what you want. One of the problems with transformed linear regression is explained here (with log): http://davegiles.blogspot.fr/2013/08/forecasting-from-log-linear-regressions.html. If this bias on the mean is a true problem for you then GLM solves this problem.
Otherwise transformed linear regression would more natural (see gung's answer).
|
Logistic regression for a continuous dependent variable
|
Your idea is to use the logit (I call it $f$ to make clear that what $f$ is does not matter in what I will explain) in order to fall between 0 and 1. This idea of yours is not especially related to lo
|
Logistic regression for a continuous dependent variable
Your idea is to use the logit (I call it $f$ to make clear that what $f$ is does not matter in what I will explain) in order to fall between 0 and 1. This idea of yours is not especially related to logistic regression. It is similar to using a log link function in order to deal with a positive $Y$.
So the difference between model 1 and model 2 is the same as if you used a log. The first is transformed linear regression, the second is GLM. The key difference is :
Transformed : $E(f(Y)|X)=\beta X$
GLM : $f(E(Y|X))=\beta X$
What is best ?
It depends on what you want. One of the problems with transformed linear regression is explained here (with log): http://davegiles.blogspot.fr/2013/08/forecasting-from-log-linear-regressions.html. If this bias on the mean is a true problem for you then GLM solves this problem.
Otherwise transformed linear regression would more natural (see gung's answer).
|
Logistic regression for a continuous dependent variable
Your idea is to use the logit (I call it $f$ to make clear that what $f$ is does not matter in what I will explain) in order to fall between 0 and 1. This idea of yours is not especially related to lo
|
41,013
|
Logistic regression for a continuous dependent variable
|
The difference between the two models you've described is that the first supposes that the DV is a continuous variable that varies between 0 and 1, whereas the second (usually called "logistic regression") supposes that the DV is a discrete variable that can take only the values 0 and 1. So the second one is inappropriate for your case.
|
Logistic regression for a continuous dependent variable
|
The difference between the two models you've described is that the first supposes that the DV is a continuous variable that varies between 0 and 1, whereas the second (usually called "logistic regress
|
Logistic regression for a continuous dependent variable
The difference between the two models you've described is that the first supposes that the DV is a continuous variable that varies between 0 and 1, whereas the second (usually called "logistic regression") supposes that the DV is a discrete variable that can take only the values 0 and 1. So the second one is inappropriate for your case.
|
Logistic regression for a continuous dependent variable
The difference between the two models you've described is that the first supposes that the DV is a continuous variable that varies between 0 and 1, whereas the second (usually called "logistic regress
|
41,014
|
What is the intuition behind convolutional neural network?
|
Fourier basis functions are "global", extending over the entire signal/image domain. More typically the convolution filters used in image processing/computer vision will be local. For example moving average or derivative style filters.
My understanding of ConvNets is that the filters are typically local. But rather than using a pre-defined set of filters, the filter coefficients are learned (only the window-sizes are pre-specified).
To expand on the global vs. local distinction, for FFT, one basis function gives a single (complex-valued) output for a given image, since the basis function is global. For a local filter, as in CNN, one basis function (filter) gives an image output of local filter-response over the input image. (Possibly the output image is smaller, depending on padding and stride.)
In each case the total output will be a set of filter-responses, one for each basis-function in the filter bank. For the FFT the "filters" will correspond to different frequencies for FFT. For CNNs the filters are more flexible, e.g. after training they could end up effectively being "oriented edge detectors".
Beyond this, at a high level, a key component of successful CNNs is depth, which is enabled* by nonlinearity such as max-pooling and ReLU activations. (*Since composition of linear functions would just give a linear function.) I cannot really speak from experience on the details of how this plays out.
But to speculate, both of those classic CNN nonlinearities would allow "attention focusing", by eliminating non-salient filter responses. Thus at the lower levels the CNN can implicitly accomplish feature detection and then description, while at the higher levels feature-arrangements can be used for object detection and then discrimination. So a single deep architecture can accomplish multiple tasks in the more classical end-to-end pipeline (e.g. SIFT).
|
What is the intuition behind convolutional neural network?
|
Fourier basis functions are "global", extending over the entire signal/image domain. More typically the convolution filters used in image processing/computer vision will be local. For example moving a
|
What is the intuition behind convolutional neural network?
Fourier basis functions are "global", extending over the entire signal/image domain. More typically the convolution filters used in image processing/computer vision will be local. For example moving average or derivative style filters.
My understanding of ConvNets is that the filters are typically local. But rather than using a pre-defined set of filters, the filter coefficients are learned (only the window-sizes are pre-specified).
To expand on the global vs. local distinction, for FFT, one basis function gives a single (complex-valued) output for a given image, since the basis function is global. For a local filter, as in CNN, one basis function (filter) gives an image output of local filter-response over the input image. (Possibly the output image is smaller, depending on padding and stride.)
In each case the total output will be a set of filter-responses, one for each basis-function in the filter bank. For the FFT the "filters" will correspond to different frequencies for FFT. For CNNs the filters are more flexible, e.g. after training they could end up effectively being "oriented edge detectors".
Beyond this, at a high level, a key component of successful CNNs is depth, which is enabled* by nonlinearity such as max-pooling and ReLU activations. (*Since composition of linear functions would just give a linear function.) I cannot really speak from experience on the details of how this plays out.
But to speculate, both of those classic CNN nonlinearities would allow "attention focusing", by eliminating non-salient filter responses. Thus at the lower levels the CNN can implicitly accomplish feature detection and then description, while at the higher levels feature-arrangements can be used for object detection and then discrimination. So a single deep architecture can accomplish multiple tasks in the more classical end-to-end pipeline (e.g. SIFT).
|
What is the intuition behind convolutional neural network?
Fourier basis functions are "global", extending over the entire signal/image domain. More typically the convolution filters used in image processing/computer vision will be local. For example moving a
|
41,015
|
What is the intuition behind convolutional neural network?
|
In this blog post (Deep Learning in a Nutshell: Core Concepts), the author had a very good explanation of the intuition behind convolution.
Convolution is important in physics and mathematics as it defines a bridge between the spatial and time domains (pixel with intensity 147 at position (0,30)) and the frequency domain (amplitude of 0.3, at 30Hz, with 60-degree phase) through the convolution theorem. This bridge is defined by the use of Fourier transforms: When you use a Fourier transform on both the kernel and the feature map, then the convolution operation is simplified significantly (integration becomes mere multiplication).
...
Convolution can describe the diffusion of information, for example, the diffusion that takes place if you put milk into your coffee and do not stir can be accurately modeled by a convolution operation (pixels diffuse towards contours in an image). In quantum mechanics, it describes the probability of a quantum particle being in a certain place when you measure the particle’s position (average probability for a pixel’s position is highest at contours). In probability theory, it describes cross-correlation, which is the degree of similarity for two sequences that overlap (similarity high if the pixels of a feature (e.g. nose) overlap in an image (e.g. face)). In statistics, it describes a weighted moving average over a normalized sequence of input (large weights for contours, small weights for everything else). Many other interpretations exist.
|
What is the intuition behind convolutional neural network?
|
In this blog post (Deep Learning in a Nutshell: Core Concepts), the author had a very good explanation of the intuition behind convolution.
Convolution is important in physics and mathematics as it d
|
What is the intuition behind convolutional neural network?
In this blog post (Deep Learning in a Nutshell: Core Concepts), the author had a very good explanation of the intuition behind convolution.
Convolution is important in physics and mathematics as it defines a bridge between the spatial and time domains (pixel with intensity 147 at position (0,30)) and the frequency domain (amplitude of 0.3, at 30Hz, with 60-degree phase) through the convolution theorem. This bridge is defined by the use of Fourier transforms: When you use a Fourier transform on both the kernel and the feature map, then the convolution operation is simplified significantly (integration becomes mere multiplication).
...
Convolution can describe the diffusion of information, for example, the diffusion that takes place if you put milk into your coffee and do not stir can be accurately modeled by a convolution operation (pixels diffuse towards contours in an image). In quantum mechanics, it describes the probability of a quantum particle being in a certain place when you measure the particle’s position (average probability for a pixel’s position is highest at contours). In probability theory, it describes cross-correlation, which is the degree of similarity for two sequences that overlap (similarity high if the pixels of a feature (e.g. nose) overlap in an image (e.g. face)). In statistics, it describes a weighted moving average over a normalized sequence of input (large weights for contours, small weights for everything else). Many other interpretations exist.
|
What is the intuition behind convolutional neural network?
In this blog post (Deep Learning in a Nutshell: Core Concepts), the author had a very good explanation of the intuition behind convolution.
Convolution is important in physics and mathematics as it d
|
41,016
|
Some general questions on Generative Adversarial Networks
|
after nothing came from anyone, I like to summarize my own research on the topic.
Question number 1: Is it ok to use a Generated sample for extracting data from an actual sample?
There will be some "changed" values in the generated sample but a practical view can help us understand why we might use it. in many applications, the "changed values" are not important as much as they can change the output of a process so it's ok to use a generated sample for these kinds of applications.
Questions Number 2 and 3: What is the role of noise and noise sampling?
Noise can role like a balancer! we can for sure change the way we sample from it or even create it(not a pure noise but something else!) but it will lead to a biased Generator to the "noise input". So it might be a good idea to keep it as random as possible.
Question Number 4: Can we have a Deeper GAN?
Well, again Practicality is what we must focus on. it is possible to make a "Deeper GAN" but it's only when we need extra processes to be done on a data. in fact, when we input a generated sample from a GAN to another one, we are basically feeding it in instead of the "Noise" so that the G part can do "Something" on it. How many stages do we need? it depends on our design. What are the downsides? for sure it would take a lot to train! but also it can increase some "weird representations" in the final output. cause we are using some Generated Sample as Noise. it might perform well on Some cases but there is no guaranty for others.
so. this was my interpretation from what I read and also what I spoke with my professors. please feel free to correct me in comments or post a new Answer.
thanks
|
Some general questions on Generative Adversarial Networks
|
after nothing came from anyone, I like to summarize my own research on the topic.
Question number 1: Is it ok to use a Generated sample for extracting data from an actual sample?
There will be some "c
|
Some general questions on Generative Adversarial Networks
after nothing came from anyone, I like to summarize my own research on the topic.
Question number 1: Is it ok to use a Generated sample for extracting data from an actual sample?
There will be some "changed" values in the generated sample but a practical view can help us understand why we might use it. in many applications, the "changed values" are not important as much as they can change the output of a process so it's ok to use a generated sample for these kinds of applications.
Questions Number 2 and 3: What is the role of noise and noise sampling?
Noise can role like a balancer! we can for sure change the way we sample from it or even create it(not a pure noise but something else!) but it will lead to a biased Generator to the "noise input". So it might be a good idea to keep it as random as possible.
Question Number 4: Can we have a Deeper GAN?
Well, again Practicality is what we must focus on. it is possible to make a "Deeper GAN" but it's only when we need extra processes to be done on a data. in fact, when we input a generated sample from a GAN to another one, we are basically feeding it in instead of the "Noise" so that the G part can do "Something" on it. How many stages do we need? it depends on our design. What are the downsides? for sure it would take a lot to train! but also it can increase some "weird representations" in the final output. cause we are using some Generated Sample as Noise. it might perform well on Some cases but there is no guaranty for others.
so. this was my interpretation from what I read and also what I spoke with my professors. please feel free to correct me in comments or post a new Answer.
thanks
|
Some general questions on Generative Adversarial Networks
after nothing came from anyone, I like to summarize my own research on the topic.
Question number 1: Is it ok to use a Generated sample for extracting data from an actual sample?
There will be some "c
|
41,017
|
Some general questions on Generative Adversarial Networks
|
Not a complete answer from my side, but adding my 2 cents to Question 3: What happens if you change Noise to another type of distribution?
Essentially you get a Conditional Generative Adversarial Network (CGAN) (Mirza & Osindero, 2014). CGAN's have been used in many applications including image super-resolution (which seems to be the case of the paper you might have referenced regarding astronomical image data), as well as image-to-image translation (Isola et. al. 2016). Superpixel resolution could be seen as a specific case of Image-to-Image translation; other applications include dense semantic labeling and image colorization.
|
Some general questions on Generative Adversarial Networks
|
Not a complete answer from my side, but adding my 2 cents to Question 3: What happens if you change Noise to another type of distribution?
Essentially you get a Conditional Generative Adversarial Net
|
Some general questions on Generative Adversarial Networks
Not a complete answer from my side, but adding my 2 cents to Question 3: What happens if you change Noise to another type of distribution?
Essentially you get a Conditional Generative Adversarial Network (CGAN) (Mirza & Osindero, 2014). CGAN's have been used in many applications including image super-resolution (which seems to be the case of the paper you might have referenced regarding astronomical image data), as well as image-to-image translation (Isola et. al. 2016). Superpixel resolution could be seen as a specific case of Image-to-Image translation; other applications include dense semantic labeling and image colorization.
|
Some general questions on Generative Adversarial Networks
Not a complete answer from my side, but adding my 2 cents to Question 3: What happens if you change Noise to another type of distribution?
Essentially you get a Conditional Generative Adversarial Net
|
41,018
|
How does GBM work with a Poisson loss fonction
|
I am going to define the GBM algorithm first to clarify the question:
Algorithm 10.3: Gradient Tree Boosting Algorithm from Hastie's The Elements of Statistical Learning states the following:
Where $N$ is the number of samples, $M$ is the number of iterations and $J_m$ is the number of terminal regions or size of the tree. Line 3 produces $\hat{f}(x)$ which is a $K$ sized vector where $K$ corresponds to the number of classes.
How is the residual transformed before being fit by a tree? Log of the residual?
The residual is defined above by (a) and depends directly on the loss function. Similar to other problems, the loss function depends on the distribution chosen to model the conditional probability of y|x and is analogous to the negative log-likelihood of the distribution. For a Poisson distribution the log-likelihood is:
$$ll(y;\lambda) = \sum_k y_k\log(\lambda_k) - \lambda_k - \log(x_k!)$$
Or the loss:
$$L(y;\lambda) = \sum_k \lambda_k + \log(x_k!) - y_k\log(\lambda_k) $$
Since we want to minimize the loss and will eventually be taking a derivative, we can drop the constant term $\log(x_k!)$ and the above simplifies to:
$$L(y;\lambda) = \sum_k \lambda_k - y_k\log(\lambda_k) $$
In the algorithm outlined above, the residual is equivalent to the partial derivative w.r.t $f(x_i)$ evaluated at $f_{m-1}$. This can be interpreted as the residual produced by our previous update of $f$.
Do we need to apply a transform at the end to get the prediction? Exemple : prediction = exp(average of Y + prediction of the first tree + prediction of the second tree + …)
To produce probabilities the following transformation is used:
$$p_k(x) = \frac{\exp{f_k(x)}}{\sum_{l=1}^K \exp{f_l(x)}}$$
where again, $k$ is the class of interest. To make a prediction we simply take the $k$ that produces the maximum $p$.
|
How does GBM work with a Poisson loss fonction
|
I am going to define the GBM algorithm first to clarify the question:
Algorithm 10.3: Gradient Tree Boosting Algorithm from Hastie's The Elements of Statistical Learning states the following:
Where $
|
How does GBM work with a Poisson loss fonction
I am going to define the GBM algorithm first to clarify the question:
Algorithm 10.3: Gradient Tree Boosting Algorithm from Hastie's The Elements of Statistical Learning states the following:
Where $N$ is the number of samples, $M$ is the number of iterations and $J_m$ is the number of terminal regions or size of the tree. Line 3 produces $\hat{f}(x)$ which is a $K$ sized vector where $K$ corresponds to the number of classes.
How is the residual transformed before being fit by a tree? Log of the residual?
The residual is defined above by (a) and depends directly on the loss function. Similar to other problems, the loss function depends on the distribution chosen to model the conditional probability of y|x and is analogous to the negative log-likelihood of the distribution. For a Poisson distribution the log-likelihood is:
$$ll(y;\lambda) = \sum_k y_k\log(\lambda_k) - \lambda_k - \log(x_k!)$$
Or the loss:
$$L(y;\lambda) = \sum_k \lambda_k + \log(x_k!) - y_k\log(\lambda_k) $$
Since we want to minimize the loss and will eventually be taking a derivative, we can drop the constant term $\log(x_k!)$ and the above simplifies to:
$$L(y;\lambda) = \sum_k \lambda_k - y_k\log(\lambda_k) $$
In the algorithm outlined above, the residual is equivalent to the partial derivative w.r.t $f(x_i)$ evaluated at $f_{m-1}$. This can be interpreted as the residual produced by our previous update of $f$.
Do we need to apply a transform at the end to get the prediction? Exemple : prediction = exp(average of Y + prediction of the first tree + prediction of the second tree + …)
To produce probabilities the following transformation is used:
$$p_k(x) = \frac{\exp{f_k(x)}}{\sum_{l=1}^K \exp{f_l(x)}}$$
where again, $k$ is the class of interest. To make a prediction we simply take the $k$ that produces the maximum $p$.
|
How does GBM work with a Poisson loss fonction
I am going to define the GBM algorithm first to clarify the question:
Algorithm 10.3: Gradient Tree Boosting Algorithm from Hastie's The Elements of Statistical Learning states the following:
Where $
|
41,019
|
"Random variable" vs. "random value" (when translating from Russian into English)
|
I side with your editor. You plot the obtained values on the plot, then draw a mean (average) line, then calculate three standard deviations above and below the line to show the boundaries. There's really no modeling involved here, hence, there's no random variable defined explicitly. You could argue that implicitly the variables are introduced, of course, but I'd go with your editor's choice to de-emphasize modeling at this stage.
Here's the original page with a chart.
If you read the whole text they consistently use terms значение (величина) that stand for value or quantity, in my opinion, to emphasize the phenomenological nature of the approach. There's very little of statistical content in the paper. All they do is to watch control boundary breaches to detect stochastic controllability as they define it. I'd definitely stick with value here.
UPDATE: The link I gave was just one example how this paragraph is copied in Russian from one text to another. Google will spit you out dozens of example such as this one from medical field. There must be the original text from which this is copied, I suspect it's Russian translation of Chambers Wheeler book Understanding Statistical Process control. So, the precise answer would be to locate the English original in this (or other?) book.
UPDATE 2:
I don't the have the original English text from translation of which the Russian paragraph was copied, but here's a control chart description on NIST web site. Notice how they never use the term "variable". Consistent with my answer they use "measurement", "value" and "data point".
|
"Random variable" vs. "random value" (when translating from Russian into English)
|
I side with your editor. You plot the obtained values on the plot, then draw a mean (average) line, then calculate three standard deviations above and below the line to show the boundaries. There's re
|
"Random variable" vs. "random value" (when translating from Russian into English)
I side with your editor. You plot the obtained values on the plot, then draw a mean (average) line, then calculate three standard deviations above and below the line to show the boundaries. There's really no modeling involved here, hence, there's no random variable defined explicitly. You could argue that implicitly the variables are introduced, of course, but I'd go with your editor's choice to de-emphasize modeling at this stage.
Here's the original page with a chart.
If you read the whole text they consistently use terms значение (величина) that stand for value or quantity, in my opinion, to emphasize the phenomenological nature of the approach. There's very little of statistical content in the paper. All they do is to watch control boundary breaches to detect stochastic controllability as they define it. I'd definitely stick with value here.
UPDATE: The link I gave was just one example how this paragraph is copied in Russian from one text to another. Google will spit you out dozens of example such as this one from medical field. There must be the original text from which this is copied, I suspect it's Russian translation of Chambers Wheeler book Understanding Statistical Process control. So, the precise answer would be to locate the English original in this (or other?) book.
UPDATE 2:
I don't the have the original English text from translation of which the Russian paragraph was copied, but here's a control chart description on NIST web site. Notice how they never use the term "variable". Consistent with my answer they use "measurement", "value" and "data point".
|
"Random variable" vs. "random value" (when translating from Russian into English)
I side with your editor. You plot the obtained values on the plot, then draw a mean (average) line, then calculate three standard deviations above and below the line to show the boundaries. There's re
|
41,020
|
"Random variable" vs. "random value" (when translating from Russian into English)
|
The correct phrase in order to make statistical sense, is "random variable". And this is because it refers to the "mean line" - and random values do not have a mean, only random variables do.
If the Russian word is "value", and even if the Russian author meant "value", (s)he was simply mistaken.
Alternatively, one could consider writing "...mean line of the random values" - plural, since probably here the theoretical expected value is unknown, and so "the mean line" is the sample mean of the observed values.
|
"Random variable" vs. "random value" (when translating from Russian into English)
|
The correct phrase in order to make statistical sense, is "random variable". And this is because it refers to the "mean line" - and random values do not have a mean, only random variables do.
If the
|
"Random variable" vs. "random value" (when translating from Russian into English)
The correct phrase in order to make statistical sense, is "random variable". And this is because it refers to the "mean line" - and random values do not have a mean, only random variables do.
If the Russian word is "value", and even if the Russian author meant "value", (s)he was simply mistaken.
Alternatively, one could consider writing "...mean line of the random values" - plural, since probably here the theoretical expected value is unknown, and so "the mean line" is the sample mean of the observed values.
|
"Random variable" vs. "random value" (when translating from Russian into English)
The correct phrase in order to make statistical sense, is "random variable". And this is because it refers to the "mean line" - and random values do not have a mean, only random variables do.
If the
|
41,021
|
Solving constrained optimization problem: projected gradient vs. dual?
|
Essentially yes, projected gradient descent is another method for solving constrained optimization problems. It's only useful when the projection operation is easy or has a closed form, for example, box constraints or linear constraint sets.
Besides directly solving constrained problems with simple constraint sets, it can be used on the dual with good results on some problems.
For instance, there are many problems where the primal is unconstrained but involves non-smooth terms. By taking the dual the non-smooth terms can be (often) converted to simple constraints, leaving the rest of the problem differentiable. Projected gradient descent can then be used. Examples of this include L1 norm regularized problems; I particularly like this application of the technique.
|
Solving constrained optimization problem: projected gradient vs. dual?
|
Essentially yes, projected gradient descent is another method for solving constrained optimization problems. It's only useful when the projection operation is easy or has a closed form, for example, b
|
Solving constrained optimization problem: projected gradient vs. dual?
Essentially yes, projected gradient descent is another method for solving constrained optimization problems. It's only useful when the projection operation is easy or has a closed form, for example, box constraints or linear constraint sets.
Besides directly solving constrained problems with simple constraint sets, it can be used on the dual with good results on some problems.
For instance, there are many problems where the primal is unconstrained but involves non-smooth terms. By taking the dual the non-smooth terms can be (often) converted to simple constraints, leaving the rest of the problem differentiable. Projected gradient descent can then be used. Examples of this include L1 norm regularized problems; I particularly like this application of the technique.
|
Solving constrained optimization problem: projected gradient vs. dual?
Essentially yes, projected gradient descent is another method for solving constrained optimization problems. It's only useful when the projection operation is easy or has a closed form, for example, b
|
41,022
|
Solving constrained optimization problem: projected gradient vs. dual?
|
AaronDefazio had a very good answer:
It's only useful when the projection operation is easy or has a closed form, for example, box constraints or linear constraint sets.
I am just adding some details and an example of this statement.
Note that, in Projected Gradient Decent, the projection step is another optimization problem. In this problem, we want to find a point in $C$ (constraint set), this point is closest to a given point $x^*$. Which is
$$
\underset{x \in C}{\text{arg min}} \|x-x^*\|
$$
In certain cases, this optimization problem is easy to solve and have closed from. AaronDefazio mentioned box constraint and linear constraint set. I will use an even simpler example, sphere constraint to demonstrate (Sphere constraint is L2, and box constraint is L1).
$$
\underset{x \in C}{\text{arg min}} \|x-x^*\|=\left\{
\begin{array}{ll}
x^* & \|x^*\| \leq r \\
r \frac {x^*} {\|x\|} & \text{otherwise} \\
\end{array}
\right.
$$
The equation tells, if the point is inside of the constraint domain, then the projection is the point itself.
And I will demonstrate the $r \frac {x^*} {\|x\|}$ case graphically, check the points (labeled with numbers) in blue track and red track, the relationship is easy: connect the blue dots with the center of the circle (gray dashed line), the intersection with the circle is the projection.
The whole point of this example is trying to show finding the projection is easy and intuitive in this case, and it has a closed form solution. On the other hand, if we have a very complicated $C$, solving $\underset{x \in C}{\text{arg min}} \|x-x^*\|$ will be not this trivial. In such case, we may not use projected gradient descent.
|
Solving constrained optimization problem: projected gradient vs. dual?
|
AaronDefazio had a very good answer:
It's only useful when the projection operation is easy or has a closed form, for example, box constraints or linear constraint sets.
I am just adding some detail
|
Solving constrained optimization problem: projected gradient vs. dual?
AaronDefazio had a very good answer:
It's only useful when the projection operation is easy or has a closed form, for example, box constraints or linear constraint sets.
I am just adding some details and an example of this statement.
Note that, in Projected Gradient Decent, the projection step is another optimization problem. In this problem, we want to find a point in $C$ (constraint set), this point is closest to a given point $x^*$. Which is
$$
\underset{x \in C}{\text{arg min}} \|x-x^*\|
$$
In certain cases, this optimization problem is easy to solve and have closed from. AaronDefazio mentioned box constraint and linear constraint set. I will use an even simpler example, sphere constraint to demonstrate (Sphere constraint is L2, and box constraint is L1).
$$
\underset{x \in C}{\text{arg min}} \|x-x^*\|=\left\{
\begin{array}{ll}
x^* & \|x^*\| \leq r \\
r \frac {x^*} {\|x\|} & \text{otherwise} \\
\end{array}
\right.
$$
The equation tells, if the point is inside of the constraint domain, then the projection is the point itself.
And I will demonstrate the $r \frac {x^*} {\|x\|}$ case graphically, check the points (labeled with numbers) in blue track and red track, the relationship is easy: connect the blue dots with the center of the circle (gray dashed line), the intersection with the circle is the projection.
The whole point of this example is trying to show finding the projection is easy and intuitive in this case, and it has a closed form solution. On the other hand, if we have a very complicated $C$, solving $\underset{x \in C}{\text{arg min}} \|x-x^*\|$ will be not this trivial. In such case, we may not use projected gradient descent.
|
Solving constrained optimization problem: projected gradient vs. dual?
AaronDefazio had a very good answer:
It's only useful when the projection operation is easy or has a closed form, for example, box constraints or linear constraint sets.
I am just adding some detail
|
41,023
|
MCMC - Metropolis Hasting: formal derivation of detailed balance
|
That follows by an easy case distinction: If $P(x')g(x|x')>P(x)g(x'|x)$, then $A(x'|x)=1$ and, by symmetry, $A(x|x')=\frac{P(x)g(x'|x)}{P(x')g(x|x')}$ and the claim holds. The case $P(x')g(x|x')\le P(x)g(x'|x)$ works similarly.
Maybe, the equality
$$A(x'|x)\cdot P(x)g(x'|x)= A(x|x')\cdot P(x')g(x|x')$$
is easier to see by plugging in the definition of $A$
$$\min(P(x)g(x'|x), P(x')g(x|x')) = \min(P(x')g(x|x'),P(x)g(x'|x))$$
|
MCMC - Metropolis Hasting: formal derivation of detailed balance
|
That follows by an easy case distinction: If $P(x')g(x|x')>P(x)g(x'|x)$, then $A(x'|x)=1$ and, by symmetry, $A(x|x')=\frac{P(x)g(x'|x)}{P(x')g(x|x')}$ and the claim holds. The case $P(x')g(x|x')\le P(
|
MCMC - Metropolis Hasting: formal derivation of detailed balance
That follows by an easy case distinction: If $P(x')g(x|x')>P(x)g(x'|x)$, then $A(x'|x)=1$ and, by symmetry, $A(x|x')=\frac{P(x)g(x'|x)}{P(x')g(x|x')}$ and the claim holds. The case $P(x')g(x|x')\le P(x)g(x'|x)$ works similarly.
Maybe, the equality
$$A(x'|x)\cdot P(x)g(x'|x)= A(x|x')\cdot P(x')g(x|x')$$
is easier to see by plugging in the definition of $A$
$$\min(P(x)g(x'|x), P(x')g(x|x')) = \min(P(x')g(x|x'),P(x)g(x'|x))$$
|
MCMC - Metropolis Hasting: formal derivation of detailed balance
That follows by an easy case distinction: If $P(x')g(x|x')>P(x)g(x'|x)$, then $A(x'|x)=1$ and, by symmetry, $A(x|x')=\frac{P(x)g(x'|x)}{P(x')g(x|x')}$ and the claim holds. The case $P(x')g(x|x')\le P(
|
41,024
|
How to prove a Hamming distance as a Kernel?
|
Step 1. For an arbitrary set of strings $\{x_i\}$, first sort them by their length. Then the kernel matrix is block-diagonal, since the kernel value between any two strings of different lengths is zero.
This lets us see that we only need to consider strings of the same length; how?
Step 2. So, we only need to consider a set of strings $\{ x_i \}$ all of length $m$. Then we can see that $$K(x, z) = \frac1m \sum_{i=1}^m \mathbb{1}(x_i = z_i), \tag{*}$$
where $\mathbb{1}(x_i = z_i)$ is 1 if $x_i = z_i$, 0 otherwise.
Looking at it this way lets us find an explicit feature map from the space of strings of length $m$ to vectors of a certain length: that is, $K(x, z) = \varphi(x)^T \varphi(z)$, for some function $\varphi$. Do you see what that function is?
Hint: if $a = (0, 1, 0, 1)$ and $b = (1, 1, 0, 0)$, then $a^T b = 0 + 1 + 0 + 0$; in general, for length-$k$ vectors whose entries are all either $0$ or $1$, $a^T b = \sum_{i=1}^k a_i b_i = \sum_{i=1}^k \mathbb 1(a_i = 1, b_i = 1)$. So you might want to come up with some function $\varphi$ that turns this into something that looks like (*).
Step 3. From there, it's a standard result that we have positive definiteness pretty quickly. Supposing that $\varphi$ maps into $\mathbb R^k$, let $\Phi$ be the $n \times k$ matrix whose $i$th row is $\varphi(x_i)$, so that $(\Phi \Phi^T)_{ij} = \varphi(x_i)^T \varphi(x_j) = K(x_i, x_j)$. Then the psd condition is that for all $a \in \mathbb R^n$, we have that
$$
\sum_{i=1}^n a_i K(x_i, x_j) a_j = a^T K a = a^T \Phi \Phi^T a = (\Phi^T a)^T (\Phi^T a) = \lVert \Phi^T a \rVert^2 \ge 0
.$$
|
How to prove a Hamming distance as a Kernel?
|
Step 1. For an arbitrary set of strings $\{x_i\}$, first sort them by their length. Then the kernel matrix is block-diagonal, since the kernel value between any two strings of different lengths is zer
|
How to prove a Hamming distance as a Kernel?
Step 1. For an arbitrary set of strings $\{x_i\}$, first sort them by their length. Then the kernel matrix is block-diagonal, since the kernel value between any two strings of different lengths is zero.
This lets us see that we only need to consider strings of the same length; how?
Step 2. So, we only need to consider a set of strings $\{ x_i \}$ all of length $m$. Then we can see that $$K(x, z) = \frac1m \sum_{i=1}^m \mathbb{1}(x_i = z_i), \tag{*}$$
where $\mathbb{1}(x_i = z_i)$ is 1 if $x_i = z_i$, 0 otherwise.
Looking at it this way lets us find an explicit feature map from the space of strings of length $m$ to vectors of a certain length: that is, $K(x, z) = \varphi(x)^T \varphi(z)$, for some function $\varphi$. Do you see what that function is?
Hint: if $a = (0, 1, 0, 1)$ and $b = (1, 1, 0, 0)$, then $a^T b = 0 + 1 + 0 + 0$; in general, for length-$k$ vectors whose entries are all either $0$ or $1$, $a^T b = \sum_{i=1}^k a_i b_i = \sum_{i=1}^k \mathbb 1(a_i = 1, b_i = 1)$. So you might want to come up with some function $\varphi$ that turns this into something that looks like (*).
Step 3. From there, it's a standard result that we have positive definiteness pretty quickly. Supposing that $\varphi$ maps into $\mathbb R^k$, let $\Phi$ be the $n \times k$ matrix whose $i$th row is $\varphi(x_i)$, so that $(\Phi \Phi^T)_{ij} = \varphi(x_i)^T \varphi(x_j) = K(x_i, x_j)$. Then the psd condition is that for all $a \in \mathbb R^n$, we have that
$$
\sum_{i=1}^n a_i K(x_i, x_j) a_j = a^T K a = a^T \Phi \Phi^T a = (\Phi^T a)^T (\Phi^T a) = \lVert \Phi^T a \rVert^2 \ge 0
.$$
|
How to prove a Hamming distance as a Kernel?
Step 1. For an arbitrary set of strings $\{x_i\}$, first sort them by their length. Then the kernel matrix is block-diagonal, since the kernel value between any two strings of different lengths is zer
|
41,025
|
How to calculate $R^2$ for LASSO (glmnet)
|
I'm using
r2 <- fit$glmnet.fit$dev.ratio[which(fitnet$glmnet.fit$lambda == fitnet$lambda.min)]
or if you have chosen the lambda.1se
r2 <- fit$glmnet.fit$dev.ratio[which(fitnet$glmnet.fit$lambda == fitnet$lambda.1se)]
If you do a cross check with the traditional regression lm() and summary()$r.squared it will match the results if weights are close to the elastic net.
|
How to calculate $R^2$ for LASSO (glmnet)
|
I'm using
r2 <- fit$glmnet.fit$dev.ratio[which(fitnet$glmnet.fit$lambda == fitnet$lambda.min)]
or if you have chosen the lambda.1se
r2 <- fit$glmnet.fit$dev.ratio[which(fitnet$glmnet.fit$lambda ==
|
How to calculate $R^2$ for LASSO (glmnet)
I'm using
r2 <- fit$glmnet.fit$dev.ratio[which(fitnet$glmnet.fit$lambda == fitnet$lambda.min)]
or if you have chosen the lambda.1se
r2 <- fit$glmnet.fit$dev.ratio[which(fitnet$glmnet.fit$lambda == fitnet$lambda.1se)]
If you do a cross check with the traditional regression lm() and summary()$r.squared it will match the results if weights are close to the elastic net.
|
How to calculate $R^2$ for LASSO (glmnet)
I'm using
r2 <- fit$glmnet.fit$dev.ratio[which(fitnet$glmnet.fit$lambda == fitnet$lambda.min)]
or if you have chosen the lambda.1se
r2 <- fit$glmnet.fit$dev.ratio[which(fitnet$glmnet.fit$lambda ==
|
41,026
|
How to calculate $R^2$ for LASSO (glmnet)
|
I think I know why the two calculations produce different answers. The cvm variable from the cvm.glmnet object is a cross-validated error. It's calculated from the residuals in the validation folds. The predict() function on the other hand, is not cross-validated. It's calculated from the residuals of predictions on the whole data set.
|
How to calculate $R^2$ for LASSO (glmnet)
|
I think I know why the two calculations produce different answers. The cvm variable from the cvm.glmnet object is a cross-validated error. It's calculated from the residuals in the validation folds.
|
How to calculate $R^2$ for LASSO (glmnet)
I think I know why the two calculations produce different answers. The cvm variable from the cvm.glmnet object is a cross-validated error. It's calculated from the residuals in the validation folds. The predict() function on the other hand, is not cross-validated. It's calculated from the residuals of predictions on the whole data set.
|
How to calculate $R^2$ for LASSO (glmnet)
I think I know why the two calculations produce different answers. The cvm variable from the cvm.glmnet object is a cross-validated error. It's calculated from the residuals in the validation folds.
|
41,027
|
Over-represented values in FDR-adjusted p-values
|
There is nothing wrong with these q-values. Correcting p-values (corrected p-values are often referred to as q-values) is a concept that's newer than the Benjamini-Hochberg (BH) procedure, which in its purest form only outputs significant: yes or no. To understand why your q-values look the way they look we need to look at how the BH step-up procedure works. The steps below are adapted from Wasserman's All of Statistics:
Order your p-values $p_1 < p_2 < \ldots < p_m$.
Define $l_i = \frac{i\alpha}{m}$, where $\alpha$ is your desired false discovery rate. Also define $T = \max\{p_i: p_i < l_i\}$, ie $T$ is the largest p-value for which $p_i < l_i$.
Let $T$ be your BH rejection threshold.
Reject the null-hypotheses $H_{0i}$ for which $p_i \leq T$.
To avoid having to choose an $\alpha,$ the q-value turns this procedure upside-down and asks what is the smallest $\alpha$ at which $H_{0i}$ would be rejected? The threshold $T$ is always going to be one of your $m$ p-values, so the threshold for acceptance as a function of the FDR $\alpha$ is going to look like some stairs:
library(plyr)
ps <- c(0.019, 0.022, 0.023, 0.023, 0.025, 0.025, 0.027, 0.028, 0.029, 0.030, 0.030, 0.030, 0.031, 0.033, 0.034, 0.035, 0.036, 0.037, 0.037, 0.039, 0.051, 0.060, 0.063, 0.065, 0.085, 0.110, 0.170, 0.196, 0.241, 0.316, 0.318, 0.325, 0.694)
# calculate T as function of alpha
BHT <- function(alpha) {
l <- 1:length(ps)*alpha/length(ps)
i <- sum(ps < l)
if (i == 0) return(i)
ps[i] # threshold
}
alphas <- seq(0,1,by=.001)
Ts <- aaply(alphas, 1, BHT)
plot(alphas, Ts, type="l")
For each threshold, there is a single smallest $\alpha$ that makes this the new rejection threshold. If we put some lines in the previous plot for your different p-values, you'll see that many of them sit on the same step of the staircase:
plot(alphas, Ts, type="n")
abline(v=ps, col="grey")
lines(alphas, Ts)
These will get rejected at the same threshold and correspond to the same smallest $\alpha$. This $\alpha$ is your q-value, so it's OK and pretty much inevitable to get repeated q-values.
|
Over-represented values in FDR-adjusted p-values
|
There is nothing wrong with these q-values. Correcting p-values (corrected p-values are often referred to as q-values) is a concept that's newer than the Benjamini-Hochberg (BH) procedure, which in it
|
Over-represented values in FDR-adjusted p-values
There is nothing wrong with these q-values. Correcting p-values (corrected p-values are often referred to as q-values) is a concept that's newer than the Benjamini-Hochberg (BH) procedure, which in its purest form only outputs significant: yes or no. To understand why your q-values look the way they look we need to look at how the BH step-up procedure works. The steps below are adapted from Wasserman's All of Statistics:
Order your p-values $p_1 < p_2 < \ldots < p_m$.
Define $l_i = \frac{i\alpha}{m}$, where $\alpha$ is your desired false discovery rate. Also define $T = \max\{p_i: p_i < l_i\}$, ie $T$ is the largest p-value for which $p_i < l_i$.
Let $T$ be your BH rejection threshold.
Reject the null-hypotheses $H_{0i}$ for which $p_i \leq T$.
To avoid having to choose an $\alpha,$ the q-value turns this procedure upside-down and asks what is the smallest $\alpha$ at which $H_{0i}$ would be rejected? The threshold $T$ is always going to be one of your $m$ p-values, so the threshold for acceptance as a function of the FDR $\alpha$ is going to look like some stairs:
library(plyr)
ps <- c(0.019, 0.022, 0.023, 0.023, 0.025, 0.025, 0.027, 0.028, 0.029, 0.030, 0.030, 0.030, 0.031, 0.033, 0.034, 0.035, 0.036, 0.037, 0.037, 0.039, 0.051, 0.060, 0.063, 0.065, 0.085, 0.110, 0.170, 0.196, 0.241, 0.316, 0.318, 0.325, 0.694)
# calculate T as function of alpha
BHT <- function(alpha) {
l <- 1:length(ps)*alpha/length(ps)
i <- sum(ps < l)
if (i == 0) return(i)
ps[i] # threshold
}
alphas <- seq(0,1,by=.001)
Ts <- aaply(alphas, 1, BHT)
plot(alphas, Ts, type="l")
For each threshold, there is a single smallest $\alpha$ that makes this the new rejection threshold. If we put some lines in the previous plot for your different p-values, you'll see that many of them sit on the same step of the staircase:
plot(alphas, Ts, type="n")
abline(v=ps, col="grey")
lines(alphas, Ts)
These will get rejected at the same threshold and correspond to the same smallest $\alpha$. This $\alpha$ is your q-value, so it's OK and pretty much inevitable to get repeated q-values.
|
Over-represented values in FDR-adjusted p-values
There is nothing wrong with these q-values. Correcting p-values (corrected p-values are often referred to as q-values) is a concept that's newer than the Benjamini-Hochberg (BH) procedure, which in it
|
41,028
|
In online convex optimization, what is a leader in FTL algorithm?
|
The Follow-The-Leader (FTL) algorithm is a simple algorithm for solving online prediction problems. Imagine that you have a committee of experts, each of which suggests a strategy. At each time point, you pick an expert and follow his or her advice, which yields some associated cost (or reward) at the next time step. Your goal is to minimize the total cost/maximize your total reward.
Follow-The-Leader uses a very simple approach: track the performance of all experts over all previous time steps, then select the expert/strategy/etc that has performed the best so far, and follow its advice on the next round. Update everything and choose again.
This approach is called follow the leader, in part because you're following (the advice) of the leading strategy (e.g., the player with the best score in a game). Follow the leader is also the name of a traditional children's game, where everyone imitates the movements of a "leader", which is close enough to the algorithm to be (mildly) funny.
|
In online convex optimization, what is a leader in FTL algorithm?
|
The Follow-The-Leader (FTL) algorithm is a simple algorithm for solving online prediction problems. Imagine that you have a committee of experts, each of which suggests a strategy. At each time point,
|
In online convex optimization, what is a leader in FTL algorithm?
The Follow-The-Leader (FTL) algorithm is a simple algorithm for solving online prediction problems. Imagine that you have a committee of experts, each of which suggests a strategy. At each time point, you pick an expert and follow his or her advice, which yields some associated cost (or reward) at the next time step. Your goal is to minimize the total cost/maximize your total reward.
Follow-The-Leader uses a very simple approach: track the performance of all experts over all previous time steps, then select the expert/strategy/etc that has performed the best so far, and follow its advice on the next round. Update everything and choose again.
This approach is called follow the leader, in part because you're following (the advice) of the leading strategy (e.g., the player with the best score in a game). Follow the leader is also the name of a traditional children's game, where everyone imitates the movements of a "leader", which is close enough to the algorithm to be (mildly) funny.
|
In online convex optimization, what is a leader in FTL algorithm?
The Follow-The-Leader (FTL) algorithm is a simple algorithm for solving online prediction problems. Imagine that you have a committee of experts, each of which suggests a strategy. At each time point,
|
41,029
|
In online convex optimization, what is a leader in FTL algorithm?
|
In the particular case of on-line convex optimization a leader corresponds to a point in the convex domain of optimization. So in principle you have an infinite number of experts.
|
In online convex optimization, what is a leader in FTL algorithm?
|
In the particular case of on-line convex optimization a leader corresponds to a point in the convex domain of optimization. So in principle you have an infinite number of experts.
|
In online convex optimization, what is a leader in FTL algorithm?
In the particular case of on-line convex optimization a leader corresponds to a point in the convex domain of optimization. So in principle you have an infinite number of experts.
|
In online convex optimization, what is a leader in FTL algorithm?
In the particular case of on-line convex optimization a leader corresponds to a point in the convex domain of optimization. So in principle you have an infinite number of experts.
|
41,030
|
The discriminant function in linear discriminant analysis
|
it can be shown that this is equivalent to assigning the observation to the class for which the below equation is largest
Deriving the discriminant function for LDA
For LDA we assume that the random variable $X$ is a vector $\mathbf{X} = (X_1,X_2,...,X_p)$ which is drawn from a multivariate Gaussian with class-specific mean vector and a common covariance matrix $\Sigma$. In other words the covariance matrix is common to all $K$ classes: $Cov(X) = \Sigma$ of shape $p \times p$
Since $x$ follows a multivariate Gaussian distribution, the probability $p(X = x | Y = k)$ is given by:
$$ f_k(x) = \frac{1}{(2 \pi)^{p/2} |\Sigma|^{1/2}} \exp \left( - \frac{1}{2} (x - \mu_k)^T \Sigma^{-1} (x - \mu_k) \right)$$
($\mu_k$ is the mean of inputs for category $k$)
Assume that we know the prior distribution exactly: $P(Y = k) = \pi_k$, then we can find the posterior distribution using Bayes theorem as
$$ p_k(x) = p(Y = k | X = x) = \frac{f_k(x) \ \pi_k}{P(X = x)} = C \times f_k(x) \ \pi_k $$
There is the summation term which remains , how we do we go about eliminating it?
If you look at the term in which there is a summation, it is actually equal to $P(X = x)$ in the equation above. Since $P(X = x)$ does not depend on $k$ and we are only interested in the terms which are function of $k$ (see later) we can push it into a constant $C$.
We will now proceed to expand and simplify the algebra, putting all constant terms into $C, C', C''$ etc..
\begin{aligned}
p_k(x) &= p(Y = k | X = x) = \frac{f_k(x) \ \pi_k}{P(X = x)} = C \times f_k(x) \ \pi_k
\\
& = C \ \pi_k \ \frac{1}{(2 \pi)^{p/2} |\Sigma|^{1/2}} \exp \left( - \frac{1}{2} (x - \mu_k)^T \Sigma^{-1} (x - \mu_k) \right)
\\
& = C' \pi_k \ \exp \left( - \frac{1}{2} (x - \mu_k)^T \Sigma^{-1} (x - \mu_k) \right)
\end{aligned}
Take the log of both sides:
\begin{aligned}
\log p_k(x) &= \log ( C' \pi_k \ \exp \left( - \frac{1}{2} (x - \mu_k)^T \Sigma^{-1} (x - \mu_k) \right) )
\\
& = \log C' + \log \pi_k - \frac{1}{2} (x - \mu_k)^T \Sigma^{-1} (x - \mu_k)
\end{aligned}
Since the term $\log C'$ does not depend on $k$ and we aim to maximize the posterior probability over $k$, we can ignore it:
\begin{aligned}
\log \pi_k - \frac{1}{2} (x - \mu_k)^T \Sigma^{-1} (x - \mu_k)
\\
= \log \pi_k - \frac{1}{2} [ x^T \Sigma^{-1} x + \mu^T_k \Sigma^{-1} \mu_k ] + x^T \Sigma^{-1} \mu_k
\\
= C'' + \log \pi_k - \frac{1}{2} \mu^T_k \Sigma^{-1} \mu_k + x^T \Sigma^{-1} \mu_k
\end{aligned}
And so the objective function, sometimes called the linear discriminant function is:
$$ \delta_k(x) = \log \pi_k - \frac{1}{2} \mu^T_k \Sigma^{-1} \mu_k + x^T \Sigma^{-1} \mu_k $$
Which means that given an input $x$ we predict the class with the highest value of $\delta_k(x)$.
See here for an implementation in Python
|
The discriminant function in linear discriminant analysis
|
it can be shown that this is equivalent to assigning the observation to the class for which the below equation is largest
Deriving the discriminant function for LDA
For LDA we assume that the random
|
The discriminant function in linear discriminant analysis
it can be shown that this is equivalent to assigning the observation to the class for which the below equation is largest
Deriving the discriminant function for LDA
For LDA we assume that the random variable $X$ is a vector $\mathbf{X} = (X_1,X_2,...,X_p)$ which is drawn from a multivariate Gaussian with class-specific mean vector and a common covariance matrix $\Sigma$. In other words the covariance matrix is common to all $K$ classes: $Cov(X) = \Sigma$ of shape $p \times p$
Since $x$ follows a multivariate Gaussian distribution, the probability $p(X = x | Y = k)$ is given by:
$$ f_k(x) = \frac{1}{(2 \pi)^{p/2} |\Sigma|^{1/2}} \exp \left( - \frac{1}{2} (x - \mu_k)^T \Sigma^{-1} (x - \mu_k) \right)$$
($\mu_k$ is the mean of inputs for category $k$)
Assume that we know the prior distribution exactly: $P(Y = k) = \pi_k$, then we can find the posterior distribution using Bayes theorem as
$$ p_k(x) = p(Y = k | X = x) = \frac{f_k(x) \ \pi_k}{P(X = x)} = C \times f_k(x) \ \pi_k $$
There is the summation term which remains , how we do we go about eliminating it?
If you look at the term in which there is a summation, it is actually equal to $P(X = x)$ in the equation above. Since $P(X = x)$ does not depend on $k$ and we are only interested in the terms which are function of $k$ (see later) we can push it into a constant $C$.
We will now proceed to expand and simplify the algebra, putting all constant terms into $C, C', C''$ etc..
\begin{aligned}
p_k(x) &= p(Y = k | X = x) = \frac{f_k(x) \ \pi_k}{P(X = x)} = C \times f_k(x) \ \pi_k
\\
& = C \ \pi_k \ \frac{1}{(2 \pi)^{p/2} |\Sigma|^{1/2}} \exp \left( - \frac{1}{2} (x - \mu_k)^T \Sigma^{-1} (x - \mu_k) \right)
\\
& = C' \pi_k \ \exp \left( - \frac{1}{2} (x - \mu_k)^T \Sigma^{-1} (x - \mu_k) \right)
\end{aligned}
Take the log of both sides:
\begin{aligned}
\log p_k(x) &= \log ( C' \pi_k \ \exp \left( - \frac{1}{2} (x - \mu_k)^T \Sigma^{-1} (x - \mu_k) \right) )
\\
& = \log C' + \log \pi_k - \frac{1}{2} (x - \mu_k)^T \Sigma^{-1} (x - \mu_k)
\end{aligned}
Since the term $\log C'$ does not depend on $k$ and we aim to maximize the posterior probability over $k$, we can ignore it:
\begin{aligned}
\log \pi_k - \frac{1}{2} (x - \mu_k)^T \Sigma^{-1} (x - \mu_k)
\\
= \log \pi_k - \frac{1}{2} [ x^T \Sigma^{-1} x + \mu^T_k \Sigma^{-1} \mu_k ] + x^T \Sigma^{-1} \mu_k
\\
= C'' + \log \pi_k - \frac{1}{2} \mu^T_k \Sigma^{-1} \mu_k + x^T \Sigma^{-1} \mu_k
\end{aligned}
And so the objective function, sometimes called the linear discriminant function is:
$$ \delta_k(x) = \log \pi_k - \frac{1}{2} \mu^T_k \Sigma^{-1} \mu_k + x^T \Sigma^{-1} \mu_k $$
Which means that given an input $x$ we predict the class with the highest value of $\delta_k(x)$.
See here for an implementation in Python
|
The discriminant function in linear discriminant analysis
it can be shown that this is equivalent to assigning the observation to the class for which the below equation is largest
Deriving the discriminant function for LDA
For LDA we assume that the random
|
41,031
|
The discriminant function in linear discriminant analysis
|
Given $x$, the summation term is the same for each $p_k(x)$, where $k=1,...K$.
Therefore when comparing the probabilities, you can delete it.
|
The discriminant function in linear discriminant analysis
|
Given $x$, the summation term is the same for each $p_k(x)$, where $k=1,...K$.
Therefore when comparing the probabilities, you can delete it.
|
The discriminant function in linear discriminant analysis
Given $x$, the summation term is the same for each $p_k(x)$, where $k=1,...K$.
Therefore when comparing the probabilities, you can delete it.
|
The discriminant function in linear discriminant analysis
Given $x$, the summation term is the same for each $p_k(x)$, where $k=1,...K$.
Therefore when comparing the probabilities, you can delete it.
|
41,032
|
The advantages and disadvantages of using Kaiser Rule to select the number of principal components
|
The advantage of the rule is that it is easy to calculate, especially if you live in the 1950s, and don't have access to a fast computer.
The disadvantages ... well, I'm going to quote Preacher and MacCallum, in their paper "Repairing Tom Swift’s Electric Factor Analysis Machine". It's worth reading the whole paper, available here: http://www.quantpsy.org/pubs/preacher_maccallum_2003.pdf
"... use of the rule in practice is problematic for several reasons.
First, Guttman’s proof regarding the weakest lower bound applies to
the population correlation matrix and assumes that the model holds
exactly in the population with m factors. In practice, of course, the
population correlation matrix is not available and the model will not
hold exactly. Application of the rule to a sample correlation matrix
under conditions of imperfect model fit represents circumstances under
which the theoretical foundation of the rule is no longer applicable.
Second, the Kaiser criterion is appropriately applied to eigenvalues
of the unreduced correlation matrix rather than to those of the
reduced correlation matrix. In practice, the criterion is often
misapplied to eigenvalues of a reduced correlation matrix. Third,
Gorsuch (1983) noted that many researchers interpret the Kaiser
criterion as the actual number of factors to retain rather than as a
lower bound for the number of factors. In addition, other researchers
have found that the criterion underestimates (Cattell & Vogelmann,
1977; Cliff, 1988; Humphreys, 1964) or overestimates (Browne, 1968;
Cattell & Vogelmann, 1977; Horn, 1965; Lee & Comrey, 1979; Linn, 1968;
Revelle & Rocklin, 1979; Yeomans & Golder, 1982;Zwick & Velicer, 1982)
the number of factors that should be retained. It has also been
demonstrated that the number of factors suggested by the Kaiser
criterion is dependent on the number of variables (Gorsuch, 1983;
Yeomans & Golder, 1982; Zwick & Velicer, 1982), the reliability of the
factors (Cliff, 1988, 1992), or on the MV-to-factor ratio and the
range of communalities (Tucker, Koopman, & Linn,1969). Thus, the
general conclusion is that there is little justification for using the
Kaiser criterion to decide how many factors to retain. ... There is
little theoretical evidence to support it, ample evidence to the
contrary, and better alternatives that were ignored."
|
The advantages and disadvantages of using Kaiser Rule to select the number of principal components
|
The advantage of the rule is that it is easy to calculate, especially if you live in the 1950s, and don't have access to a fast computer.
The disadvantages ... well, I'm going to quote Preacher and Ma
|
The advantages and disadvantages of using Kaiser Rule to select the number of principal components
The advantage of the rule is that it is easy to calculate, especially if you live in the 1950s, and don't have access to a fast computer.
The disadvantages ... well, I'm going to quote Preacher and MacCallum, in their paper "Repairing Tom Swift’s Electric Factor Analysis Machine". It's worth reading the whole paper, available here: http://www.quantpsy.org/pubs/preacher_maccallum_2003.pdf
"... use of the rule in practice is problematic for several reasons.
First, Guttman’s proof regarding the weakest lower bound applies to
the population correlation matrix and assumes that the model holds
exactly in the population with m factors. In practice, of course, the
population correlation matrix is not available and the model will not
hold exactly. Application of the rule to a sample correlation matrix
under conditions of imperfect model fit represents circumstances under
which the theoretical foundation of the rule is no longer applicable.
Second, the Kaiser criterion is appropriately applied to eigenvalues
of the unreduced correlation matrix rather than to those of the
reduced correlation matrix. In practice, the criterion is often
misapplied to eigenvalues of a reduced correlation matrix. Third,
Gorsuch (1983) noted that many researchers interpret the Kaiser
criterion as the actual number of factors to retain rather than as a
lower bound for the number of factors. In addition, other researchers
have found that the criterion underestimates (Cattell & Vogelmann,
1977; Cliff, 1988; Humphreys, 1964) or overestimates (Browne, 1968;
Cattell & Vogelmann, 1977; Horn, 1965; Lee & Comrey, 1979; Linn, 1968;
Revelle & Rocklin, 1979; Yeomans & Golder, 1982;Zwick & Velicer, 1982)
the number of factors that should be retained. It has also been
demonstrated that the number of factors suggested by the Kaiser
criterion is dependent on the number of variables (Gorsuch, 1983;
Yeomans & Golder, 1982; Zwick & Velicer, 1982), the reliability of the
factors (Cliff, 1988, 1992), or on the MV-to-factor ratio and the
range of communalities (Tucker, Koopman, & Linn,1969). Thus, the
general conclusion is that there is little justification for using the
Kaiser criterion to decide how many factors to retain. ... There is
little theoretical evidence to support it, ample evidence to the
contrary, and better alternatives that were ignored."
|
The advantages and disadvantages of using Kaiser Rule to select the number of principal components
The advantage of the rule is that it is easy to calculate, especially if you live in the 1950s, and don't have access to a fast computer.
The disadvantages ... well, I'm going to quote Preacher and Ma
|
41,033
|
Why use the normal approximation to the binomial?
|
I know of no reason to use the normal approximation to the binomial distribution in practice. There are a variety of exact algorithms that are more than good enough for general use, and these are what you get when you use the binomial RNGs from R, SciPy, etc. The only good reason I can think of to discuss the method in a statistics class is that you can use it to illustrate the central limit theorem.
|
Why use the normal approximation to the binomial?
|
I know of no reason to use the normal approximation to the binomial distribution in practice. There are a variety of exact algorithms that are more than good enough for general use, and these are what
|
Why use the normal approximation to the binomial?
I know of no reason to use the normal approximation to the binomial distribution in practice. There are a variety of exact algorithms that are more than good enough for general use, and these are what you get when you use the binomial RNGs from R, SciPy, etc. The only good reason I can think of to discuss the method in a statistics class is that you can use it to illustrate the central limit theorem.
|
Why use the normal approximation to the binomial?
I know of no reason to use the normal approximation to the binomial distribution in practice. There are a variety of exact algorithms that are more than good enough for general use, and these are what
|
41,034
|
Why use the normal approximation to the binomial?
|
The central limit theorem provides the reason why the normal can approximate the binomial in sufficiently large sample sizes. Sufficiently large depends on the success parameter $p$. When $p=0.5$, the binomial is symmetric and so the sample size does not need to be as much as if $p=0.95$, in which case the binomial could be highly skewed. Also, you get a better approximation when the continuity correction is applied.
Regarding your question about calculating binomial probabilities on the computer, the computer can calculate these probabilities quickly and therefore you really don't need a normal approximation.
|
Why use the normal approximation to the binomial?
|
The central limit theorem provides the reason why the normal can approximate the binomial in sufficiently large sample sizes. Sufficiently large depends on the success parameter $p$. When $p=0.5$, t
|
Why use the normal approximation to the binomial?
The central limit theorem provides the reason why the normal can approximate the binomial in sufficiently large sample sizes. Sufficiently large depends on the success parameter $p$. When $p=0.5$, the binomial is symmetric and so the sample size does not need to be as much as if $p=0.95$, in which case the binomial could be highly skewed. Also, you get a better approximation when the continuity correction is applied.
Regarding your question about calculating binomial probabilities on the computer, the computer can calculate these probabilities quickly and therefore you really don't need a normal approximation.
|
Why use the normal approximation to the binomial?
The central limit theorem provides the reason why the normal can approximate the binomial in sufficiently large sample sizes. Sufficiently large depends on the success parameter $p$. When $p=0.5$, t
|
41,035
|
Test for the significance of the effect of an intervention in a time series
|
What you are referring to is called a test for structural change/break or a changepoint model.
As you have a known change date, you can simply add an interaction in the model, and use a standard t-test for this coefficient. If you test for more coefficients, use the Chow test formulation (see this post for example). This will work for both a linear regression or an ARIMA. So the choice between these two models should be made based on general considerations, and is not influenced by your desire to do a test.
So you just model:
$y_i = \alpha + \alpha^+ 1(x>10) +\beta x_i + \beta^+x_i1(x>10) + \epsilon_i$
And run a test for the (joint) significance of $\beta^+$ and $\alpha^+$.
Quick example, without the Chow test, just looking at individual coefs:
y <- c(rnorm(10, 10, 0.12), 9.6, 9.4, 9.3, 9.2, 9.15)
x <- seq(1:15)
df <- data.frame(y = y, x = x)
df$D <- ifelse(x<10, 0,1)
reg <- lm(y~1+D+ x*(1-D)+x*(D), data=df)
Then the summary method will show if your coefficients are significant:
summary(reg)
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 9.82048 0.08167 120.241 < 2e-16 ***
D 1.62439 0.34875 4.658 0.000696 ***
x 0.03889 0.01451 2.680 0.021417 *
D:x -0.19901 0.03054 -6.516 4.33e-05 ***
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
D and D:x are the $\alpha^+$ and $\beta^+$ coefficients. Hence, you can check three tests:
$H_0: \alpha^+=0$, i.e. break in intercept. Here, very low p-value for D, hence rejectected, so there is break in intercept.
$H_0: \beta^+=0$, i.e. break in slope. Also very low p-value for D:x.
$H_0: \alpha^+ \beta^+=0$ Null of no break in all coefficient (joint test).
For this, use linearHypothesis as below. Also rejected.
library(car)
linearHypothesis(reg, c("D=0", "D:x=0"))
Finally, plotting is pretty easy:
plot(y~x, data=df)
lines(predict(reg))
In general, look at the strucchange package in R, which is really good, and more general (allows you to search for the date/change value itself). For example:
library(strucchange)
breakpoints(y~1+x, data=df, h=0.2, breaks=1)
sctest(Fstats(y~1+x, data=df, from=0.2, to=0.2))
The first estimates the break point (10, which corresponds to your 11 I believe), the second tests for constancy.
|
Test for the significance of the effect of an intervention in a time series
|
What you are referring to is called a test for structural change/break or a changepoint model.
As you have a known change date, you can simply add an interaction in the model, and use a standard t-te
|
Test for the significance of the effect of an intervention in a time series
What you are referring to is called a test for structural change/break or a changepoint model.
As you have a known change date, you can simply add an interaction in the model, and use a standard t-test for this coefficient. If you test for more coefficients, use the Chow test formulation (see this post for example). This will work for both a linear regression or an ARIMA. So the choice between these two models should be made based on general considerations, and is not influenced by your desire to do a test.
So you just model:
$y_i = \alpha + \alpha^+ 1(x>10) +\beta x_i + \beta^+x_i1(x>10) + \epsilon_i$
And run a test for the (joint) significance of $\beta^+$ and $\alpha^+$.
Quick example, without the Chow test, just looking at individual coefs:
y <- c(rnorm(10, 10, 0.12), 9.6, 9.4, 9.3, 9.2, 9.15)
x <- seq(1:15)
df <- data.frame(y = y, x = x)
df$D <- ifelse(x<10, 0,1)
reg <- lm(y~1+D+ x*(1-D)+x*(D), data=df)
Then the summary method will show if your coefficients are significant:
summary(reg)
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 9.82048 0.08167 120.241 < 2e-16 ***
D 1.62439 0.34875 4.658 0.000696 ***
x 0.03889 0.01451 2.680 0.021417 *
D:x -0.19901 0.03054 -6.516 4.33e-05 ***
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
D and D:x are the $\alpha^+$ and $\beta^+$ coefficients. Hence, you can check three tests:
$H_0: \alpha^+=0$, i.e. break in intercept. Here, very low p-value for D, hence rejectected, so there is break in intercept.
$H_0: \beta^+=0$, i.e. break in slope. Also very low p-value for D:x.
$H_0: \alpha^+ \beta^+=0$ Null of no break in all coefficient (joint test).
For this, use linearHypothesis as below. Also rejected.
library(car)
linearHypothesis(reg, c("D=0", "D:x=0"))
Finally, plotting is pretty easy:
plot(y~x, data=df)
lines(predict(reg))
In general, look at the strucchange package in R, which is really good, and more general (allows you to search for the date/change value itself). For example:
library(strucchange)
breakpoints(y~1+x, data=df, h=0.2, breaks=1)
sctest(Fstats(y~1+x, data=df, from=0.2, to=0.2))
The first estimates the break point (10, which corresponds to your 11 I believe), the second tests for constancy.
|
Test for the significance of the effect of an intervention in a time series
What you are referring to is called a test for structural change/break or a changepoint model.
As you have a known change date, you can simply add an interaction in the model, and use a standard t-te
|
41,036
|
Why is Binary Classification not a Hypothesis Test?
|
It seems perfectly reasonable to me that the binary classification of a given pattern could be analogous to a hypothesis test, but it isn't necessarily. It also depends on exactly what situation you have in mind here. Let us assume that you have a classifier (hopefully a good one), and want to use it determine which class a given pattern belongs to. This should be a new pattern for which you don't already know the true class. It is common in machine learning to assess the value of your classifier by comparing its predicted classes to known (true) classes, but that is a different endeavor. Then,
From within the Neyman-Pearson approach to hypothesis testing (cf., here), you will act as though the null is correct unless there is sufficient evidence to reject it. To be clear, that does not mean that you have 'proven' the null to be true (cf., here), you will eventually make errors in both directions. The key to this is deciding what long-run error rates you think you can live with. Typically, the null and alternative are not treated symmetrically—preference is given to the null. Thus for example, people will usually only reject the null if the evidence is sufficient that their long-run 'type I' error rate is 5%. Generally, a study to test the hypothesis is constructed such that the null will be rejected 80% of the time when the alternative obtains. Those facts imply that people are more comfortable erring on the side of not rejecting the null, than the other way around. But that is a particular value judgment regarding the demerits of the different types of mistakes, there is nothing logically necessary about that.
On the other hand, when classifying a novel pattern in machine learning, it is typical that all patterns are classified, and are classified as the maximum a-posteriori class. That is, a pattern will be classified as class A if the classifier suggests it is more likely to be an A than a not-A. This again is a value judgment. Classifiers can be 'weighted' so that they will prioritize sensitivity or specificity.
Thus, these represent different cultural and conceptual frameworks, but can be put in correspondence with regard to the underlying logical structure of the two activities.
There are other perspectives we could take on comparing and contrasting these as well. For example, we could discuss whether the classifier performs adequately (judged according to some criterion) based on how well the function the classifier embodies, $\hat f({\rm data})$ mimics the true underlying function $f({\rm data})$, and whether / how closely the assumptions of the particular hypothesis test are met. Similarly, we could contrast how classifiers are trained in machine learning (e.g., by minimizing cross validation error), vs. how models are built to create a context within which a specific hypothesis can be tested.
For a broader viewpoint, you may be interested in my answer here: What is the difference between data mining, statistics, machine learning and AI?
|
Why is Binary Classification not a Hypothesis Test?
|
It seems perfectly reasonable to me that the binary classification of a given pattern could be analogous to a hypothesis test, but it isn't necessarily. It also depends on exactly what situation you
|
Why is Binary Classification not a Hypothesis Test?
It seems perfectly reasonable to me that the binary classification of a given pattern could be analogous to a hypothesis test, but it isn't necessarily. It also depends on exactly what situation you have in mind here. Let us assume that you have a classifier (hopefully a good one), and want to use it determine which class a given pattern belongs to. This should be a new pattern for which you don't already know the true class. It is common in machine learning to assess the value of your classifier by comparing its predicted classes to known (true) classes, but that is a different endeavor. Then,
From within the Neyman-Pearson approach to hypothesis testing (cf., here), you will act as though the null is correct unless there is sufficient evidence to reject it. To be clear, that does not mean that you have 'proven' the null to be true (cf., here), you will eventually make errors in both directions. The key to this is deciding what long-run error rates you think you can live with. Typically, the null and alternative are not treated symmetrically—preference is given to the null. Thus for example, people will usually only reject the null if the evidence is sufficient that their long-run 'type I' error rate is 5%. Generally, a study to test the hypothesis is constructed such that the null will be rejected 80% of the time when the alternative obtains. Those facts imply that people are more comfortable erring on the side of not rejecting the null, than the other way around. But that is a particular value judgment regarding the demerits of the different types of mistakes, there is nothing logically necessary about that.
On the other hand, when classifying a novel pattern in machine learning, it is typical that all patterns are classified, and are classified as the maximum a-posteriori class. That is, a pattern will be classified as class A if the classifier suggests it is more likely to be an A than a not-A. This again is a value judgment. Classifiers can be 'weighted' so that they will prioritize sensitivity or specificity.
Thus, these represent different cultural and conceptual frameworks, but can be put in correspondence with regard to the underlying logical structure of the two activities.
There are other perspectives we could take on comparing and contrasting these as well. For example, we could discuss whether the classifier performs adequately (judged according to some criterion) based on how well the function the classifier embodies, $\hat f({\rm data})$ mimics the true underlying function $f({\rm data})$, and whether / how closely the assumptions of the particular hypothesis test are met. Similarly, we could contrast how classifiers are trained in machine learning (e.g., by minimizing cross validation error), vs. how models are built to create a context within which a specific hypothesis can be tested.
For a broader viewpoint, you may be interested in my answer here: What is the difference between data mining, statistics, machine learning and AI?
|
Why is Binary Classification not a Hypothesis Test?
It seems perfectly reasonable to me that the binary classification of a given pattern could be analogous to a hypothesis test, but it isn't necessarily. It also depends on exactly what situation you
|
41,037
|
Why is Binary Classification not a Hypothesis Test?
|
The two are not necessarily non-overlapping in practice. I would also note that hypothesis-testing and statistical-significance seem slightly different to me (at least going by the tag descriptions on this site): Not all hypothesis testing has to be comparing to a "null" (or "random/by chance/no effect") alternative.
That said, hypothesis tests are perhaps typically associated with pre-defined hypotheses, commonly specified in terms of parametric distributions.
So for example, in training a gaussian-mixture model, the parameters ($\mu_k$,$\Sigma_k$) and data labels $k_i\in\mathrm{components}$ (where $i\in\mathrm{data}$) typically vary. However for a fixed set of component parameters, deciding which component (class) a point belongs to is at least akin to hypothesis testing (e.g. when classifying new examples, or deciding labels in the "E-step" of E-M training).
So I guess the key distinction (in my view), would be that in (classical?) statistical hypothesis testing, changing the hypothesis is strictly not allowed, once the data have been seen.
(See, for example, the controversial phenomenon of "p-hacking".)
|
Why is Binary Classification not a Hypothesis Test?
|
The two are not necessarily non-overlapping in practice. I would also note that hypothesis-testing and statistical-significance seem slightly different to me (at least going by the tag descriptions on
|
Why is Binary Classification not a Hypothesis Test?
The two are not necessarily non-overlapping in practice. I would also note that hypothesis-testing and statistical-significance seem slightly different to me (at least going by the tag descriptions on this site): Not all hypothesis testing has to be comparing to a "null" (or "random/by chance/no effect") alternative.
That said, hypothesis tests are perhaps typically associated with pre-defined hypotheses, commonly specified in terms of parametric distributions.
So for example, in training a gaussian-mixture model, the parameters ($\mu_k$,$\Sigma_k$) and data labels $k_i\in\mathrm{components}$ (where $i\in\mathrm{data}$) typically vary. However for a fixed set of component parameters, deciding which component (class) a point belongs to is at least akin to hypothesis testing (e.g. when classifying new examples, or deciding labels in the "E-step" of E-M training).
So I guess the key distinction (in my view), would be that in (classical?) statistical hypothesis testing, changing the hypothesis is strictly not allowed, once the data have been seen.
(See, for example, the controversial phenomenon of "p-hacking".)
|
Why is Binary Classification not a Hypothesis Test?
The two are not necessarily non-overlapping in practice. I would also note that hypothesis-testing and statistical-significance seem slightly different to me (at least going by the tag descriptions on
|
41,038
|
Generalized Gamma GLM
|
There are several reasonably clear options.
You can use the survival model. Treat the response values as all-uncensored survival times. I've used this strategy to fit Weibull models for example; it often works quite well.
There's an example here that shows doing it with a Weibull model for non-survival data. [There's a second example here of using it to simply fit a Weibull distribution in a case where the usual fitdistr approach was having trouble.]
Those two examples should be sufficient to convey the general idea, and apply it to the generalized gamma.
If you know the "power" parameter ($p$ in the Wikipedia link) you can transform the data to a Gamma and use GLM.
If $p$ is unknown, you can use the fact that conditional on $p$ you can fit a GLM (and then ML estimation of the scale parameter for that, such as via the relevant function in MASS - which is using a similar idea) to get a profile likelihood for $p$, to obtain an overall MLE for $p$ and the gamma parameters.
Alternatively you can try to use direct optimization of the likelihood.
|
Generalized Gamma GLM
|
There are several reasonably clear options.
You can use the survival model. Treat the response values as all-uncensored survival times. I've used this strategy to fit Weibull models for example; it
|
Generalized Gamma GLM
There are several reasonably clear options.
You can use the survival model. Treat the response values as all-uncensored survival times. I've used this strategy to fit Weibull models for example; it often works quite well.
There's an example here that shows doing it with a Weibull model for non-survival data. [There's a second example here of using it to simply fit a Weibull distribution in a case where the usual fitdistr approach was having trouble.]
Those two examples should be sufficient to convey the general idea, and apply it to the generalized gamma.
If you know the "power" parameter ($p$ in the Wikipedia link) you can transform the data to a Gamma and use GLM.
If $p$ is unknown, you can use the fact that conditional on $p$ you can fit a GLM (and then ML estimation of the scale parameter for that, such as via the relevant function in MASS - which is using a similar idea) to get a profile likelihood for $p$, to obtain an overall MLE for $p$ and the gamma parameters.
Alternatively you can try to use direct optimization of the likelihood.
|
Generalized Gamma GLM
There are several reasonably clear options.
You can use the survival model. Treat the response values as all-uncensored survival times. I've used this strategy to fit Weibull models for example; it
|
41,039
|
Similarity metrics for more than two vectors?
|
The cosine similarity between two column vectors $x_1$ and $x_2$ is simply the dot product between their unit vectors
$$\mathrm{CosSim}[x_1,x_2]=\frac{x_1}{\|x_1\|}\bullet\frac{x_2}{\|x_2\|}$$
and varies from -1 to +1, similar to a correlation coefficient $R$ (to which it is closely related).
There are many ways to generalize this idea to a set of $n$ vectors, but as requested in the comments, here I will expand on one possibility, related to the idea of (linear) dimensionality reduction.
First, in the $n=2$ case, we can think of $R^2\in[0,1]$ as the "fraction of the variance explained" by a linear regression. For the squared cosine similarity, a similar interpretation is possible, except the associated regression has no "intercept term" (i.e. the vectors are scaled, but not centered).
In the $n$ dimensional case, we can concatenate the vectors into a matrix
$$X=\begin{bmatrix}x_1 \, \ldots \, x_n\end{bmatrix}$$
analogous to the cosine similarity case, we can consider dot products based on the scaled matrix
$$Y=\begin{bmatrix}y_1 \, \ldots \, y_n\end{bmatrix}$$
assembled from the corresponding unit vectors
$$y_i=\frac{x_i}{\|x_i\|}$$
In general we could then conduct varying analyses on the "correlation matrix" $Y^TY$, including dimension reduction via PCA.
The general idea here is to create a low-rank approximation to the matrix $Y$ by truncating its singular value decomposition (SVD). Mathematically, we have
$$Y=USV^T=\sum_{k=1}^n\sigma_ku_kv_k^T$$
where the singular values $\sigma_1,\ldots,\sigma_n$ are non-negative and arranged in decreasing order. (For simplicity I am assuming that for $x_i\in\mathbb{R}^m$ the number of vectors is at least $n\geq m$. Otherwise the sum will have $m$ terms.) If we truncate the sum at $K<n$, then we get a "rank $K$ approximation" $\hat{Y}_K$ to the matrix $Y=\hat{Y}_n$. The truncated SVD is optimal in the sense that it minimizes the Frobenius norm of the reconstruction error $\|\hat{Y}_K-Y\|_F^2$.
The squared Frobenius norm is just the sum of the squares of all the entries of a matrix. In particular, for the scaled matrix $Y$ we will always have $$\|Y\|_F^2=n$$
For any matrix, the Frobenius norm is also equal to the sum of the squares of the singular values. In particular, for the $K$-rank approximation $\hat{Y}_K$ we have
$$\|\hat{Y}_K\|_F^2=\sum_{k=1}^K\sigma_k^2$$
So we can define an "order $K$ coefficient of determination" as
$$R_K^2\equiv\frac{\|\hat{Y}_K\|_F^2}{\|Y\|_F^2}\in[0,1]$$
A simple option would be to just use the first singular value, i.e.
$$R_1^2\equiv\frac{\sigma_1^2}{n}$$
The maximum similarity would be for $n$ parallel vectors (i.e. scalar multiples of a single vector), giving $R_1^2=1$. The minimum similarity would be for $n$ orthogonal vectors, giving $R_1^2=\frac{1}{n}$.
A few final notes:
The first singular value $\sigma_1$ can be computed via an iterative method, so no detailed SVD need be computed. (Similar to PageRank; e.g. svds(Y,1) in Matlab.)
To get a similarity that can range over the entire [0,1] interval, you could simply normalize, i.e.
$$\hat{R}_1^2\equiv\frac{\sigma_1^2-1}{n-1}$$
So in Matlab the similarity function could be defined via CosSimN = @(Y) (svds(Y,1)^2-1)/(size(Y,2)-1), if we assume that $Y$ is already available as input.
For $n=2$ the above will reduce to the absolute value of the standard cosine similarity.
|
Similarity metrics for more than two vectors?
|
The cosine similarity between two column vectors $x_1$ and $x_2$ is simply the dot product between their unit vectors
$$\mathrm{CosSim}[x_1,x_2]=\frac{x_1}{\|x_1\|}\bullet\frac{x_2}{\|x_2\|}$$
and var
|
Similarity metrics for more than two vectors?
The cosine similarity between two column vectors $x_1$ and $x_2$ is simply the dot product between their unit vectors
$$\mathrm{CosSim}[x_1,x_2]=\frac{x_1}{\|x_1\|}\bullet\frac{x_2}{\|x_2\|}$$
and varies from -1 to +1, similar to a correlation coefficient $R$ (to which it is closely related).
There are many ways to generalize this idea to a set of $n$ vectors, but as requested in the comments, here I will expand on one possibility, related to the idea of (linear) dimensionality reduction.
First, in the $n=2$ case, we can think of $R^2\in[0,1]$ as the "fraction of the variance explained" by a linear regression. For the squared cosine similarity, a similar interpretation is possible, except the associated regression has no "intercept term" (i.e. the vectors are scaled, but not centered).
In the $n$ dimensional case, we can concatenate the vectors into a matrix
$$X=\begin{bmatrix}x_1 \, \ldots \, x_n\end{bmatrix}$$
analogous to the cosine similarity case, we can consider dot products based on the scaled matrix
$$Y=\begin{bmatrix}y_1 \, \ldots \, y_n\end{bmatrix}$$
assembled from the corresponding unit vectors
$$y_i=\frac{x_i}{\|x_i\|}$$
In general we could then conduct varying analyses on the "correlation matrix" $Y^TY$, including dimension reduction via PCA.
The general idea here is to create a low-rank approximation to the matrix $Y$ by truncating its singular value decomposition (SVD). Mathematically, we have
$$Y=USV^T=\sum_{k=1}^n\sigma_ku_kv_k^T$$
where the singular values $\sigma_1,\ldots,\sigma_n$ are non-negative and arranged in decreasing order. (For simplicity I am assuming that for $x_i\in\mathbb{R}^m$ the number of vectors is at least $n\geq m$. Otherwise the sum will have $m$ terms.) If we truncate the sum at $K<n$, then we get a "rank $K$ approximation" $\hat{Y}_K$ to the matrix $Y=\hat{Y}_n$. The truncated SVD is optimal in the sense that it minimizes the Frobenius norm of the reconstruction error $\|\hat{Y}_K-Y\|_F^2$.
The squared Frobenius norm is just the sum of the squares of all the entries of a matrix. In particular, for the scaled matrix $Y$ we will always have $$\|Y\|_F^2=n$$
For any matrix, the Frobenius norm is also equal to the sum of the squares of the singular values. In particular, for the $K$-rank approximation $\hat{Y}_K$ we have
$$\|\hat{Y}_K\|_F^2=\sum_{k=1}^K\sigma_k^2$$
So we can define an "order $K$ coefficient of determination" as
$$R_K^2\equiv\frac{\|\hat{Y}_K\|_F^2}{\|Y\|_F^2}\in[0,1]$$
A simple option would be to just use the first singular value, i.e.
$$R_1^2\equiv\frac{\sigma_1^2}{n}$$
The maximum similarity would be for $n$ parallel vectors (i.e. scalar multiples of a single vector), giving $R_1^2=1$. The minimum similarity would be for $n$ orthogonal vectors, giving $R_1^2=\frac{1}{n}$.
A few final notes:
The first singular value $\sigma_1$ can be computed via an iterative method, so no detailed SVD need be computed. (Similar to PageRank; e.g. svds(Y,1) in Matlab.)
To get a similarity that can range over the entire [0,1] interval, you could simply normalize, i.e.
$$\hat{R}_1^2\equiv\frac{\sigma_1^2-1}{n-1}$$
So in Matlab the similarity function could be defined via CosSimN = @(Y) (svds(Y,1)^2-1)/(size(Y,2)-1), if we assume that $Y$ is already available as input.
For $n=2$ the above will reduce to the absolute value of the standard cosine similarity.
|
Similarity metrics for more than two vectors?
The cosine similarity between two column vectors $x_1$ and $x_2$ is simply the dot product between their unit vectors
$$\mathrm{CosSim}[x_1,x_2]=\frac{x_1}{\|x_1\|}\bullet\frac{x_2}{\|x_2\|}$$
and var
|
41,040
|
Model with complications
|
Sandwich based robust error estimation handles both heteroscedasticity and non-normal error distribution asymptotically. That also happens to mean that you get approximately valid inference in relatively samples.
One criticism might be that a method which is so robust must be of low power. Generally, not as true as one might think. But...could you make weaker or different assumptions about the distribution of the errors? For instance, instead of being normal, perhaps they could come from a general family of errors inclusive of the normal distribution like a t-distribution family or a 3 parameter normal family. This blurs the lines between classical inference, which in small samples relies upon strong distributional assumptions, and robust error estimation which is pretty much bullet proof in relatively large samples.
An example of blurring these lines for a hybrid approach, is maximizing a conditional likelihood that allows for platykurtic error distributions like a $t$-distribution with relatively low degrees of freedom. For the case of heteroscedasticity, you can inspect variograms to model the errors as a function of the mean, such as with a mean-variance relationship that is linear (alternately consider a Poisson GLM with an identity link).
|
Model with complications
|
Sandwich based robust error estimation handles both heteroscedasticity and non-normal error distribution asymptotically. That also happens to mean that you get approximately valid inference in relativ
|
Model with complications
Sandwich based robust error estimation handles both heteroscedasticity and non-normal error distribution asymptotically. That also happens to mean that you get approximately valid inference in relatively samples.
One criticism might be that a method which is so robust must be of low power. Generally, not as true as one might think. But...could you make weaker or different assumptions about the distribution of the errors? For instance, instead of being normal, perhaps they could come from a general family of errors inclusive of the normal distribution like a t-distribution family or a 3 parameter normal family. This blurs the lines between classical inference, which in small samples relies upon strong distributional assumptions, and robust error estimation which is pretty much bullet proof in relatively large samples.
An example of blurring these lines for a hybrid approach, is maximizing a conditional likelihood that allows for platykurtic error distributions like a $t$-distribution with relatively low degrees of freedom. For the case of heteroscedasticity, you can inspect variograms to model the errors as a function of the mean, such as with a mean-variance relationship that is linear (alternately consider a Poisson GLM with an identity link).
|
Model with complications
Sandwich based robust error estimation handles both heteroscedasticity and non-normal error distribution asymptotically. That also happens to mean that you get approximately valid inference in relativ
|
41,041
|
Model with complications
|
Both heteroscedasticity and heavy-tailedness can be considered violations of the distributional assumptions of a standard linear model. If the distribution is nonetheless symmetrical, and the relationship is between $x$ and $y$ is rectilinear, your model should not be biased. Instead, interval estimates and inferences would be incorrect. With enough data, they may be approximately right anyway. Unfortunately, it is difficult to know how much data would be 'enough', and the amount may be prohibitively large without your awareness one way or the other. Thus, you need methods that do not rely on the standard distributional assumptions. @AdamO's suggestions are viable. Two additional approaches jump to mind:
You could bootstrap your model to get better confidence intervals and p-values. The advantage here is that your model is otherwise similar (particularly with respect to interpretability). The disadvantages are that you need enough data to adequately represent the population, and that this probably requires you to write original code (i.e., there may not be convenient routines already).
The ultimate distribution-free regression method is to use ordinal logistic regression. Ordinal models do not make any assumptions about the conditional distribution, they only require that you can claim, say, that a $7$ is $>$ a $6$. That is not very restrictive. The upside is considerable robustness, and there will be convenient functions for this in your software of choice. The downside is that OLR models tend to be hard to interpret.
|
Model with complications
|
Both heteroscedasticity and heavy-tailedness can be considered violations of the distributional assumptions of a standard linear model. If the distribution is nonetheless symmetrical, and the relatio
|
Model with complications
Both heteroscedasticity and heavy-tailedness can be considered violations of the distributional assumptions of a standard linear model. If the distribution is nonetheless symmetrical, and the relationship is between $x$ and $y$ is rectilinear, your model should not be biased. Instead, interval estimates and inferences would be incorrect. With enough data, they may be approximately right anyway. Unfortunately, it is difficult to know how much data would be 'enough', and the amount may be prohibitively large without your awareness one way or the other. Thus, you need methods that do not rely on the standard distributional assumptions. @AdamO's suggestions are viable. Two additional approaches jump to mind:
You could bootstrap your model to get better confidence intervals and p-values. The advantage here is that your model is otherwise similar (particularly with respect to interpretability). The disadvantages are that you need enough data to adequately represent the population, and that this probably requires you to write original code (i.e., there may not be convenient routines already).
The ultimate distribution-free regression method is to use ordinal logistic regression. Ordinal models do not make any assumptions about the conditional distribution, they only require that you can claim, say, that a $7$ is $>$ a $6$. That is not very restrictive. The upside is considerable robustness, and there will be convenient functions for this in your software of choice. The downside is that OLR models tend to be hard to interpret.
|
Model with complications
Both heteroscedasticity and heavy-tailedness can be considered violations of the distributional assumptions of a standard linear model. If the distribution is nonetheless symmetrical, and the relatio
|
41,042
|
Violin plot or bean plot? What are the advantages of each?
|
I don't know about bean plots but for small sample sizes violin plots may be unstable and I would prefer to just show the raw data with a rug plot or spike histogram. Sometimes I superimpose a violin plot with an extended box plot and the raw data. An extended box plot shows many more quantiles than a regular box plot. In R you can see a demonstration of many variations by running
require(Hmisc)
example(panel.bpplot)
See also some of the examples in https://hbiostat.org/bbr/descript.html#sec-descript-graphics
See http://biostat.app.vumc.org/HmiscNew for other examples of back-to-back violin plots for displaying distributions for two treatment groups over time. No need to always show the mirror images.
|
Violin plot or bean plot? What are the advantages of each?
|
I don't know about bean plots but for small sample sizes violin plots may be unstable and I would prefer to just show the raw data with a rug plot or spike histogram. Sometimes I superimpose a violin
|
Violin plot or bean plot? What are the advantages of each?
I don't know about bean plots but for small sample sizes violin plots may be unstable and I would prefer to just show the raw data with a rug plot or spike histogram. Sometimes I superimpose a violin plot with an extended box plot and the raw data. An extended box plot shows many more quantiles than a regular box plot. In R you can see a demonstration of many variations by running
require(Hmisc)
example(panel.bpplot)
See also some of the examples in https://hbiostat.org/bbr/descript.html#sec-descript-graphics
See http://biostat.app.vumc.org/HmiscNew for other examples of back-to-back violin plots for displaying distributions for two treatment groups over time. No need to always show the mirror images.
|
Violin plot or bean plot? What are the advantages of each?
I don't know about bean plots but for small sample sizes violin plots may be unstable and I would prefer to just show the raw data with a rug plot or spike histogram. Sometimes I superimpose a violin
|
41,043
|
Confused by a simple setting in Bayesian inference
|
For continuous models, the Bayes factor is defined as the ratio of marginal likelihoods (marginal density functions of the data):
$$P(M_i\vert x) = \int p(x\vert\theta_i, M_i)\pi(\theta_i)d\theta_i \neq 0,$$
where $p$ denotes the likelihood function (joint density of the data given the parameters of model $M_i$).
See:
Kass, Robert E., and Adrian E. Raftery. "Bayes factors." Journal of the american statistical association 90.430 (1995): 773-795.
EDIT:
Regarding the derivation of the formula. Recall that discrete and continuous variables cannot be treated the same way. Thus, the conditional probability is given by
$$P(M_i\vert x) = \dfrac{P(M_i)f(x\vert M_i)}{f(x)}.$$
Using the Law of total probability:
$$f(x\vert M_i) = \int f(x\vert M_i,\theta_i)\pi(\theta_i)d\theta_i.$$
Thus:
$$P(M_i\vert x) = \dfrac{P(M_i)\int f(x\vert M_i,\theta_i)\pi(\theta_i)d\theta_i}{f(x)}.$$
Finally:
$$\frac{P(M_1\vert x)}{P(M_2\vert x)} = \dfrac{P(M_1)\int f(x\vert M_1,\theta_1)\pi(\theta_1)d\theta_1}{P(M_2)\int f(x\vert M_2,\theta_2)\pi(\theta_2)d\theta_2}.$$
$\theta_i$ represent the parameters associated to model $M_i$.
|
Confused by a simple setting in Bayesian inference
|
For continuous models, the Bayes factor is defined as the ratio of marginal likelihoods (marginal density functions of the data):
$$P(M_i\vert x) = \int p(x\vert\theta_i, M_i)\pi(\theta_i)d\theta_i \n
|
Confused by a simple setting in Bayesian inference
For continuous models, the Bayes factor is defined as the ratio of marginal likelihoods (marginal density functions of the data):
$$P(M_i\vert x) = \int p(x\vert\theta_i, M_i)\pi(\theta_i)d\theta_i \neq 0,$$
where $p$ denotes the likelihood function (joint density of the data given the parameters of model $M_i$).
See:
Kass, Robert E., and Adrian E. Raftery. "Bayes factors." Journal of the american statistical association 90.430 (1995): 773-795.
EDIT:
Regarding the derivation of the formula. Recall that discrete and continuous variables cannot be treated the same way. Thus, the conditional probability is given by
$$P(M_i\vert x) = \dfrac{P(M_i)f(x\vert M_i)}{f(x)}.$$
Using the Law of total probability:
$$f(x\vert M_i) = \int f(x\vert M_i,\theta_i)\pi(\theta_i)d\theta_i.$$
Thus:
$$P(M_i\vert x) = \dfrac{P(M_i)\int f(x\vert M_i,\theta_i)\pi(\theta_i)d\theta_i}{f(x)}.$$
Finally:
$$\frac{P(M_1\vert x)}{P(M_2\vert x)} = \dfrac{P(M_1)\int f(x\vert M_1,\theta_1)\pi(\theta_1)d\theta_1}{P(M_2)\int f(x\vert M_2,\theta_2)\pi(\theta_2)d\theta_2}.$$
$\theta_i$ represent the parameters associated to model $M_i$.
|
Confused by a simple setting in Bayesian inference
For continuous models, the Bayes factor is defined as the ratio of marginal likelihoods (marginal density functions of the data):
$$P(M_i\vert x) = \int p(x\vert\theta_i, M_i)\pi(\theta_i)d\theta_i \n
|
41,044
|
Confused by a simple setting in Bayesian inference
|
In model $M_1$, there is no parameter, hence no need for a prior distribution. The marginal density of $X$ under model $M_1$ is thus the normal $N(0,1)$ in this case. The marginal density under model $M_2$ is indeed the integral
$$ \int f_{X}(x|\mu)f_\mu(\mu)\text{d}\mu = \int_1^2 \frac{1}{\sqrt{2\pi}}e^{-\frac{(x-\mu)^2}{2}}\text{d}\mu=\Phi(2-x)-\Phi(1-x)$$
The Bayes factor is an odds ratio associated with the posterior probability over the model index (1 versus 2), when the parameter (if any) is integrated out. Hence it stems from Bayes' theorem.
Note: You should not use the notation $P(X=x|M)$ for continuous random variables, as this probability is always zero.
|
Confused by a simple setting in Bayesian inference
|
In model $M_1$, there is no parameter, hence no need for a prior distribution. The marginal density of $X$ under model $M_1$ is thus the normal $N(0,1)$ in this case. The marginal density under model
|
Confused by a simple setting in Bayesian inference
In model $M_1$, there is no parameter, hence no need for a prior distribution. The marginal density of $X$ under model $M_1$ is thus the normal $N(0,1)$ in this case. The marginal density under model $M_2$ is indeed the integral
$$ \int f_{X}(x|\mu)f_\mu(\mu)\text{d}\mu = \int_1^2 \frac{1}{\sqrt{2\pi}}e^{-\frac{(x-\mu)^2}{2}}\text{d}\mu=\Phi(2-x)-\Phi(1-x)$$
The Bayes factor is an odds ratio associated with the posterior probability over the model index (1 versus 2), when the parameter (if any) is integrated out. Hence it stems from Bayes' theorem.
Note: You should not use the notation $P(X=x|M)$ for continuous random variables, as this probability is always zero.
|
Confused by a simple setting in Bayesian inference
In model $M_1$, there is no parameter, hence no need for a prior distribution. The marginal density of $X$ under model $M_1$ is thus the normal $N(0,1)$ in this case. The marginal density under model
|
41,045
|
An Information Criterion that considers how many variables we can choose from
|
I think simple cross validation is the best fit.
Both AIC and BIC consider the balance between model complexity and the amount of information available. With more data, more complex models can be learned. However, this balance is fixed and not based on the data.
Cross validation is based on the data. It also balances model complexity with the amount of information available. With more data more complex models can be learned. The performance on unseen data quantifies how well the model works. Implicitly, models that are to complex (overfitting) are penalized because they make bad predictions.
In the case of many variables the highly correlated ones can be chosen during training. During testing however it becomes apparent that the learned relations do not generalize to unseen data.
Another advantage of cross validation is that you can choose your own performance measurement.
|
An Information Criterion that considers how many variables we can choose from
|
I think simple cross validation is the best fit.
Both AIC and BIC consider the balance between model complexity and the amount of information available. With more data, more complex models can be lea
|
An Information Criterion that considers how many variables we can choose from
I think simple cross validation is the best fit.
Both AIC and BIC consider the balance between model complexity and the amount of information available. With more data, more complex models can be learned. However, this balance is fixed and not based on the data.
Cross validation is based on the data. It also balances model complexity with the amount of information available. With more data more complex models can be learned. The performance on unseen data quantifies how well the model works. Implicitly, models that are to complex (overfitting) are penalized because they make bad predictions.
In the case of many variables the highly correlated ones can be chosen during training. During testing however it becomes apparent that the learned relations do not generalize to unseen data.
Another advantage of cross validation is that you can choose your own performance measurement.
|
An Information Criterion that considers how many variables we can choose from
I think simple cross validation is the best fit.
Both AIC and BIC consider the balance between model complexity and the amount of information available. With more data, more complex models can be lea
|
41,046
|
What is an orthogonal design?
|
Perhaps you haven't fully grasped the definition yet. The requirements for orthogonal designs are that the blocking is orthogonal and the treatment is orthogonal. This simply means that crossproducts total to zero, whether the blocking or treatment is continuous, pseudo-continuous, polytomous, or binary. As @whuber correctly points out, statisticians often call dot products cross products, and furthermore often assume blocking and treatment factors have mean 0. So any blocking factor or treatment factor "crossed" with any other will come out to 0.
Efficiency.
Absolutely. We would expect that cross products between any two columns of the design matrix will total out to zero.
|
What is an orthogonal design?
|
Perhaps you haven't fully grasped the definition yet. The requirements for orthogonal designs are that the blocking is orthogonal and the treatment is orthogonal. This simply means that crossproducts
|
What is an orthogonal design?
Perhaps you haven't fully grasped the definition yet. The requirements for orthogonal designs are that the blocking is orthogonal and the treatment is orthogonal. This simply means that crossproducts total to zero, whether the blocking or treatment is continuous, pseudo-continuous, polytomous, or binary. As @whuber correctly points out, statisticians often call dot products cross products, and furthermore often assume blocking and treatment factors have mean 0. So any blocking factor or treatment factor "crossed" with any other will come out to 0.
Efficiency.
Absolutely. We would expect that cross products between any two columns of the design matrix will total out to zero.
|
What is an orthogonal design?
Perhaps you haven't fully grasped the definition yet. The requirements for orthogonal designs are that the blocking is orthogonal and the treatment is orthogonal. This simply means that crossproducts
|
41,047
|
PDF/CDF of max-min type random variable
|
I will illustrate with the example in the question, because a general answer is too complicated to write down.
Let $F$ be the common distribution function. We will need the distributions of the order statistics $x_{[1]} \le x_{[2]} \le \cdots \le x_{[n]}$. Their distribution functions $f_{[k]}$ are easy to express in terms of $F$ and its distribution function $f=F^\prime$ because, heuristically, the chance that $x_{[k]}$ lies within an infinitesimal interval $(x, x+dx]$ is given by the trinomial distribution with probabilities $F(x)$, $f(x)dx$, and $(1-F(x+dx))$,
$$\eqalign{
f_{[k]}(x)dx &=
\Pr(x_{[k]} \in (x, x+dx]) \\&= \binom{n}{k-1,1,n-k} F(x)^{k-1} (1-F(x+dx))^{n-k} f(x)dx\\
&= \frac{n!}{(k-1)!(1)!(n-k)!} F(x)^{k-1} (1-F(x))^{n-k} f(x)dx.
}$$
Because the $x_i$ are iid, they are exchangeable: every possible ordering $\sigma$ of the $n$ indices has equal probability. $X$ will correspond to some order statistic, but which order statistic depends on $\sigma$. Therefore let $\operatorname{Rk}(\sigma)$ be the value of $k$ for which
$$\eqalign{
x_{[k]} = X = \max&\left( \min(x_{\sigma(1)},x_{\sigma(2)},x_{\sigma(3)}),\min(x_{\sigma(1)},x_{\sigma(4)},x_{\sigma(5)}), \right. \\
& \left. \min(x_{\sigma(5)},x_{\sigma(6)},x_{\sigma(7)}),\min(x_{\sigma(3)},x_{\sigma(6)},x_{\sigma(8)})\right).
}$$
The distribution of $X$ is a mixture over all the values of $\sigma\in\mathfrak{S}_n$. To write this down, let $p(k)$ be the number of reorderings $\sigma$ for which $\operatorname{Rk}(\sigma)=k$, whence $p(k)/n!$ is the chance that $\operatorname{Rk}(\sigma)=k$. Thus the density function of $X$ is
$$\eqalign{
g(x) &= \frac{1}{n!} \sum_{\sigma \in \mathfrak{S}_n} f_{k(\sigma)}(x) \\
&= \frac{1}{n!}\sum_{k=1}^n p(k)\binom{n}{k-1,1,n-k} F(x)^{k-1} (1-F(x))^{n-k} f(x) \\
&=\left(\sum_{k=1}^n \frac{p(k)}{(k-1)!(n-k)!}F(x)^{k-1} (1-F(x))^{n-k} \right)f(x) .}$$
I do not know of any general way to find the $p(k)$. In this example, exhaustive enumeration gives
$$\begin{array}{l|rrrrrrrrr}
k & 1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 & 9\\
\hline
p(k) & 0 & 20160 & 74880 & 106560 & 92160 & 51840 & 17280 & 0 & 0
\end{array}$$
The figure shows a histogram of $10,000$ simulated values of $X$ where $F$ is an Exponential$(1)$ distribution. On it is superimposed in red the graph of $g$. It fits beautifully.
The R code that produced this simulation follows.
set.seed(17)
n.sim <- 1e4
n <- 9
x <- matrix(rexp(n.sim*n), n)
X <- pmax(pmin(x[1,], x[2,], x[3,]),
pmin(x[1,], x[4,], x[5,]),
pmin(x[5,], x[6,], x[7,]),
pmin(x[3,], x[6,], x[8,]))
f <- function(x, p) {
n <- length(p)
y <- outer(1:n, x, function(k, x) {
pexp(x)^(k-1) * pexp(x, lower.tail=FALSE)^(n-k) * dexp(x) * p[k] /
(factorial(k-1) * factorial(n-k))
})
colSums(y)
}
hist(X, freq=FALSE)
curve(f(x, p), add=TRUE, lwd=2, col="Red")
|
PDF/CDF of max-min type random variable
|
I will illustrate with the example in the question, because a general answer is too complicated to write down.
Let $F$ be the common distribution function. We will need the distributions of the order
|
PDF/CDF of max-min type random variable
I will illustrate with the example in the question, because a general answer is too complicated to write down.
Let $F$ be the common distribution function. We will need the distributions of the order statistics $x_{[1]} \le x_{[2]} \le \cdots \le x_{[n]}$. Their distribution functions $f_{[k]}$ are easy to express in terms of $F$ and its distribution function $f=F^\prime$ because, heuristically, the chance that $x_{[k]}$ lies within an infinitesimal interval $(x, x+dx]$ is given by the trinomial distribution with probabilities $F(x)$, $f(x)dx$, and $(1-F(x+dx))$,
$$\eqalign{
f_{[k]}(x)dx &=
\Pr(x_{[k]} \in (x, x+dx]) \\&= \binom{n}{k-1,1,n-k} F(x)^{k-1} (1-F(x+dx))^{n-k} f(x)dx\\
&= \frac{n!}{(k-1)!(1)!(n-k)!} F(x)^{k-1} (1-F(x))^{n-k} f(x)dx.
}$$
Because the $x_i$ are iid, they are exchangeable: every possible ordering $\sigma$ of the $n$ indices has equal probability. $X$ will correspond to some order statistic, but which order statistic depends on $\sigma$. Therefore let $\operatorname{Rk}(\sigma)$ be the value of $k$ for which
$$\eqalign{
x_{[k]} = X = \max&\left( \min(x_{\sigma(1)},x_{\sigma(2)},x_{\sigma(3)}),\min(x_{\sigma(1)},x_{\sigma(4)},x_{\sigma(5)}), \right. \\
& \left. \min(x_{\sigma(5)},x_{\sigma(6)},x_{\sigma(7)}),\min(x_{\sigma(3)},x_{\sigma(6)},x_{\sigma(8)})\right).
}$$
The distribution of $X$ is a mixture over all the values of $\sigma\in\mathfrak{S}_n$. To write this down, let $p(k)$ be the number of reorderings $\sigma$ for which $\operatorname{Rk}(\sigma)=k$, whence $p(k)/n!$ is the chance that $\operatorname{Rk}(\sigma)=k$. Thus the density function of $X$ is
$$\eqalign{
g(x) &= \frac{1}{n!} \sum_{\sigma \in \mathfrak{S}_n} f_{k(\sigma)}(x) \\
&= \frac{1}{n!}\sum_{k=1}^n p(k)\binom{n}{k-1,1,n-k} F(x)^{k-1} (1-F(x))^{n-k} f(x) \\
&=\left(\sum_{k=1}^n \frac{p(k)}{(k-1)!(n-k)!}F(x)^{k-1} (1-F(x))^{n-k} \right)f(x) .}$$
I do not know of any general way to find the $p(k)$. In this example, exhaustive enumeration gives
$$\begin{array}{l|rrrrrrrrr}
k & 1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 & 9\\
\hline
p(k) & 0 & 20160 & 74880 & 106560 & 92160 & 51840 & 17280 & 0 & 0
\end{array}$$
The figure shows a histogram of $10,000$ simulated values of $X$ where $F$ is an Exponential$(1)$ distribution. On it is superimposed in red the graph of $g$. It fits beautifully.
The R code that produced this simulation follows.
set.seed(17)
n.sim <- 1e4
n <- 9
x <- matrix(rexp(n.sim*n), n)
X <- pmax(pmin(x[1,], x[2,], x[3,]),
pmin(x[1,], x[4,], x[5,]),
pmin(x[5,], x[6,], x[7,]),
pmin(x[3,], x[6,], x[8,]))
f <- function(x, p) {
n <- length(p)
y <- outer(1:n, x, function(k, x) {
pexp(x)^(k-1) * pexp(x, lower.tail=FALSE)^(n-k) * dexp(x) * p[k] /
(factorial(k-1) * factorial(n-k))
})
colSums(y)
}
hist(X, freq=FALSE)
curve(f(x, p), add=TRUE, lwd=2, col="Red")
|
PDF/CDF of max-min type random variable
I will illustrate with the example in the question, because a general answer is too complicated to write down.
Let $F$ be the common distribution function. We will need the distributions of the order
|
41,048
|
How to Understand the Relationships Among Random Variables, Samples, and Populations?
|
Between the question and the existing answers there is some contradiction and confusion. Let's start by clearing up the definitions. Then I will provide an intuitive analog for thinking about them. I will finish by sketching out how a sample really doesn't have to be thought of any differently than a single element of a population.
Definitions
A population is usually modeled as a set $\mathcal S$ together with a probability measure $\mathbb{P}$ on that set. The probability measure indeed is a set function: there are distinguished subsets of $\mathcal S$, called "events," to which are assigned numbers between $0$ and $1$, inclusive. When that assignment satisfies simple and intuitively obvious axioms, it models probabilities.
A (univariate) random variable $X:\mathcal{S}\to\mathbb{R}$ assigns numbers to the elements of $\mathcal S$. It does so in a way that is consistent with the events of $\mathcal{S}$ and the subsets of $\mathcal{R}$ of the form $(-\infty, a]$: that is, every set of the form $E=\{s\in \mathcal{S}\mid X(s) \le a\}$ must be an event. This enables us to construct the distribution of $X$ defined by $$F_X(a) = \mathbb{P}(X \le a).$$It is defined for all real numbers $a$ and has values ranging from $0$ through $1$.
A multivariate random variable is defined similarly, but takes $m$ separate values: its codomain is $\mathbb{R}^m$ rather than $\mathbb{R}$, for $m\ge 1$.
Sampling is modeled in various ways. One procedure is to construe a sample as a finite sequence $(s_1, s_2, \ldots, s_n)\in \mathcal{S}^n$. It is implicit that subsets of the form $E_1\times E_2\times \cdots \times E_n \subset \mathcal{S}^n$ are events. Another procedure focuses on a random variable, rather than the population, and views an independent and identically distributed ("iid") sample as a sequence $$X_1, X_2, \ldots, X_n$$ of random variables on $\mathcal S$ (a) that are independent and (b) for which all the $X_i$ have the same distribution.
A conceptual model
There is an intuitive, rigorous physical model of these mathematical abstractions in which
The population is represented by slips of paper ("tickets") in a box, with one or more identically labeled slips representing each $s\in\mathcal{S}$;
The probability of an event is the proportion of all tickets it comprises in the box; and
A random variable $X$ consists of writing a sequence of $m$ numbers on each kind of ticket.
In this model, a random variable is realized by mixing the tickets in the box, blindly drawing one out, observing the values of $X$ written on it, and returning the drawn ticket to the box (so that the contents of the box remain unchanged). From this point of view a sample is obtained through some definite procedure for drawing one or more tickets. An iid sample is simply obtained as $n$ realizations.
See https://stats.stackexchange.com/a/54894/919 for an elaboration of these ideas.
Although this conceptual model seems to suppose the population is finite, the entire theory of probability--including for "infinite populations"--has been developed with it. See Edward Nelson, Radically Elementary Probability Theory (Princeton University Press, 1987).
How to model and think about samples
This setup does not look sufficiently rich or general to handle important statistical settings like time series analysis, financial analysis, sampling without replacement, etc. However, various constructions show just how powerful it is. I will give one (important) example to illustrate.
All possible realizations of a sample of size $n$ consist of sequences $\mathbf{s}=(s_1, s_2, \ldots, s_n)$ with $s_i\in\mathcal S$. The set of all such realizations is, by definition, the Cartesian product $\mathcal{S}^n$. The events of $\mathcal S$ determine events of the form $E = E_1\times E_2 \times \cdots \times E_n\subset \mathcal{S}^n$ where each $E_i$ is an event of $\mathcal S$. Specifically, $\mathbf{s}\in E$ if and only if each $s_i\in E_i$. (These "basis" events in turn define a larger set of events of $\mathcal{S}^n$, according to the axioms of probability, but the details of that need not concern us here.) This makes it possible to define probability measures on $\mathcal{S}^n$ that are "compatible" with $\mathbb{P}$.
Any sequence of random variables becomes a single (multivariate) random variable defined on $\mathcal{S}^n$ in the simplest way possible: create a ticket to represent every possible $\mathbf{s}=(s_1,s_2,\ldots, s_n)$ and on those tickets write down, in order, the numbers specified by $X_1(s_1)$, then $X_2(s_2)$, and so on. This is how multivariate random variables usually arise (and explains why we need to accommodate them in the theory).
This Cartesian product construction thereby enables us to view any realization of a sample of $\mathcal{S}$ as a realization of one element of the population $\mathcal{S}^n$, provided we are willing to work with multivariate random variables instead of just univariate ones. This is a huge conceptual simplification, for now statistical inference can largely be framed as the study of drawing a single ticket out of a (much larger) box. Moreover, by selecting a suitable probability function for the events of $\mathcal{S}^n$ we may model complex sampling procedures (giving rise to theories of sampling and experimental design) as well as interdependence among the random variables (giving rise to analyses of time series, panel data, spatial phenomena, financial series, and more).
Conclusions
In summary, comparing the definitions given here to those in the question will reveal where the question might have gone astray and will settle most of the issues it raises. And consider both what has been included here and what has not been mentioned:
Although measurement can be modeled (and usually is) with tickets in a box and random variables, it is not an essential part of any of the concepts.
"Randomness" arises only through the concept of drawing tickets from a box. It is not a part of any of the mathematical constructions or definitions.
Sampling, even the most complex designs, is modeled mathematically. Samples can be analyzed as mathematical objects.
Uniform distributions are not an essential part of the concept of sampling.
|
How to Understand the Relationships Among Random Variables, Samples, and Populations?
|
Between the question and the existing answers there is some contradiction and confusion. Let's start by clearing up the definitions. Then I will provide an intuitive analog for thinking about them.
|
How to Understand the Relationships Among Random Variables, Samples, and Populations?
Between the question and the existing answers there is some contradiction and confusion. Let's start by clearing up the definitions. Then I will provide an intuitive analog for thinking about them. I will finish by sketching out how a sample really doesn't have to be thought of any differently than a single element of a population.
Definitions
A population is usually modeled as a set $\mathcal S$ together with a probability measure $\mathbb{P}$ on that set. The probability measure indeed is a set function: there are distinguished subsets of $\mathcal S$, called "events," to which are assigned numbers between $0$ and $1$, inclusive. When that assignment satisfies simple and intuitively obvious axioms, it models probabilities.
A (univariate) random variable $X:\mathcal{S}\to\mathbb{R}$ assigns numbers to the elements of $\mathcal S$. It does so in a way that is consistent with the events of $\mathcal{S}$ and the subsets of $\mathcal{R}$ of the form $(-\infty, a]$: that is, every set of the form $E=\{s\in \mathcal{S}\mid X(s) \le a\}$ must be an event. This enables us to construct the distribution of $X$ defined by $$F_X(a) = \mathbb{P}(X \le a).$$It is defined for all real numbers $a$ and has values ranging from $0$ through $1$.
A multivariate random variable is defined similarly, but takes $m$ separate values: its codomain is $\mathbb{R}^m$ rather than $\mathbb{R}$, for $m\ge 1$.
Sampling is modeled in various ways. One procedure is to construe a sample as a finite sequence $(s_1, s_2, \ldots, s_n)\in \mathcal{S}^n$. It is implicit that subsets of the form $E_1\times E_2\times \cdots \times E_n \subset \mathcal{S}^n$ are events. Another procedure focuses on a random variable, rather than the population, and views an independent and identically distributed ("iid") sample as a sequence $$X_1, X_2, \ldots, X_n$$ of random variables on $\mathcal S$ (a) that are independent and (b) for which all the $X_i$ have the same distribution.
A conceptual model
There is an intuitive, rigorous physical model of these mathematical abstractions in which
The population is represented by slips of paper ("tickets") in a box, with one or more identically labeled slips representing each $s\in\mathcal{S}$;
The probability of an event is the proportion of all tickets it comprises in the box; and
A random variable $X$ consists of writing a sequence of $m$ numbers on each kind of ticket.
In this model, a random variable is realized by mixing the tickets in the box, blindly drawing one out, observing the values of $X$ written on it, and returning the drawn ticket to the box (so that the contents of the box remain unchanged). From this point of view a sample is obtained through some definite procedure for drawing one or more tickets. An iid sample is simply obtained as $n$ realizations.
See https://stats.stackexchange.com/a/54894/919 for an elaboration of these ideas.
Although this conceptual model seems to suppose the population is finite, the entire theory of probability--including for "infinite populations"--has been developed with it. See Edward Nelson, Radically Elementary Probability Theory (Princeton University Press, 1987).
How to model and think about samples
This setup does not look sufficiently rich or general to handle important statistical settings like time series analysis, financial analysis, sampling without replacement, etc. However, various constructions show just how powerful it is. I will give one (important) example to illustrate.
All possible realizations of a sample of size $n$ consist of sequences $\mathbf{s}=(s_1, s_2, \ldots, s_n)$ with $s_i\in\mathcal S$. The set of all such realizations is, by definition, the Cartesian product $\mathcal{S}^n$. The events of $\mathcal S$ determine events of the form $E = E_1\times E_2 \times \cdots \times E_n\subset \mathcal{S}^n$ where each $E_i$ is an event of $\mathcal S$. Specifically, $\mathbf{s}\in E$ if and only if each $s_i\in E_i$. (These "basis" events in turn define a larger set of events of $\mathcal{S}^n$, according to the axioms of probability, but the details of that need not concern us here.) This makes it possible to define probability measures on $\mathcal{S}^n$ that are "compatible" with $\mathbb{P}$.
Any sequence of random variables becomes a single (multivariate) random variable defined on $\mathcal{S}^n$ in the simplest way possible: create a ticket to represent every possible $\mathbf{s}=(s_1,s_2,\ldots, s_n)$ and on those tickets write down, in order, the numbers specified by $X_1(s_1)$, then $X_2(s_2)$, and so on. This is how multivariate random variables usually arise (and explains why we need to accommodate them in the theory).
This Cartesian product construction thereby enables us to view any realization of a sample of $\mathcal{S}$ as a realization of one element of the population $\mathcal{S}^n$, provided we are willing to work with multivariate random variables instead of just univariate ones. This is a huge conceptual simplification, for now statistical inference can largely be framed as the study of drawing a single ticket out of a (much larger) box. Moreover, by selecting a suitable probability function for the events of $\mathcal{S}^n$ we may model complex sampling procedures (giving rise to theories of sampling and experimental design) as well as interdependence among the random variables (giving rise to analyses of time series, panel data, spatial phenomena, financial series, and more).
Conclusions
In summary, comparing the definitions given here to those in the question will reveal where the question might have gone astray and will settle most of the issues it raises. And consider both what has been included here and what has not been mentioned:
Although measurement can be modeled (and usually is) with tickets in a box and random variables, it is not an essential part of any of the concepts.
"Randomness" arises only through the concept of drawing tickets from a box. It is not a part of any of the mathematical constructions or definitions.
Sampling, even the most complex designs, is modeled mathematically. Samples can be analyzed as mathematical objects.
Uniform distributions are not an essential part of the concept of sampling.
|
How to Understand the Relationships Among Random Variables, Samples, and Populations?
Between the question and the existing answers there is some contradiction and confusion. Let's start by clearing up the definitions. Then I will provide an intuitive analog for thinking about them.
|
41,049
|
How to Understand the Relationships Among Random Variables, Samples, and Populations?
|
Neither a sample nor a population can be considered variables. I think measurement is the missing piece of the puzzle in your question.
Strictly speaking, a sample is considered random when every element in the population has an equal chance of being sampled (simple random sampling) or at least a known probability (random sampling in a broader sense).
The "randomness" in random variable has more to do with the fact that you're measuring things that vary and that you can't know in advance what their value will be.
Now for the sample space, for tossing a coin it is just {heads, tails}, but when you are measuring a person's height for instance, the sample space is all the heights a human being could possibly have (sample space of infinite size theoretically -- even though not practically), no matter what your population (or sample) size is. Edit I realize there is room for debate on that specific point and some prefer considering the sample space as the height of all individuals in the population.
|
How to Understand the Relationships Among Random Variables, Samples, and Populations?
|
Neither a sample nor a population can be considered variables. I think measurement is the missing piece of the puzzle in your question.
Strictly speaking, a sample is considered random when every elem
|
How to Understand the Relationships Among Random Variables, Samples, and Populations?
Neither a sample nor a population can be considered variables. I think measurement is the missing piece of the puzzle in your question.
Strictly speaking, a sample is considered random when every element in the population has an equal chance of being sampled (simple random sampling) or at least a known probability (random sampling in a broader sense).
The "randomness" in random variable has more to do with the fact that you're measuring things that vary and that you can't know in advance what their value will be.
Now for the sample space, for tossing a coin it is just {heads, tails}, but when you are measuring a person's height for instance, the sample space is all the heights a human being could possibly have (sample space of infinite size theoretically -- even though not practically), no matter what your population (or sample) size is. Edit I realize there is room for debate on that specific point and some prefer considering the sample space as the height of all individuals in the population.
|
How to Understand the Relationships Among Random Variables, Samples, and Populations?
Neither a sample nor a population can be considered variables. I think measurement is the missing piece of the puzzle in your question.
Strictly speaking, a sample is considered random when every elem
|
41,050
|
How to Understand the Relationships Among Random Variables, Samples, and Populations?
|
A 'random variable' is a mathematical object, more precisely a measurable function.
A 'random' sample is not a mathematical object. It is only a way to pick individuals at random in a population. A way to do it is to simply consider that the population is uniformly distributed, so every individuals have the same chance to get picked, and then to pick the number of individuals you want to form your sample. This way of sampling data doesn't involve considering that sample are random variables.
|
How to Understand the Relationships Among Random Variables, Samples, and Populations?
|
A 'random variable' is a mathematical object, more precisely a measurable function.
A 'random' sample is not a mathematical object. It is only a way to pick individuals at random in a population. A w
|
How to Understand the Relationships Among Random Variables, Samples, and Populations?
A 'random variable' is a mathematical object, more precisely a measurable function.
A 'random' sample is not a mathematical object. It is only a way to pick individuals at random in a population. A way to do it is to simply consider that the population is uniformly distributed, so every individuals have the same chance to get picked, and then to pick the number of individuals you want to form your sample. This way of sampling data doesn't involve considering that sample are random variables.
|
How to Understand the Relationships Among Random Variables, Samples, and Populations?
A 'random variable' is a mathematical object, more precisely a measurable function.
A 'random' sample is not a mathematical object. It is only a way to pick individuals at random in a population. A w
|
41,051
|
How does R function summary.glm calculate the covariance matrix for glm model?
|
I was confused about this several months ago. After reading some material, I have a clue about the problem. But I am not sure that the following is correct.
Suppose the distribution of response $Y$ is an exponential family, $X^TX>0$. $p(Y|\eta)\sim \exp(\phi^{-1}\eta^T T(Y)-A(\eta)+B(Y))$, $\eta=g(E(Y|X))=X\beta$, $g$ is the canonical link, $\phi$ is the dispersion parameter of the distribution.
Fitting GLM uses MLE, and we have the Wald-type CI for MLE. The variance-covariance matrix is $I(\hat\beta)^{-1}$. $I(\hat\beta)=-E(\dfrac{\partial^2}{\partial\beta^2}\log p(Y|\eta)|\hat\beta)=\dfrac{\partial^2}{\partial\beta^2}A(X\beta)|\hat\beta=X^T(\dfrac{\partial^2}{\partial\eta^2}A(\eta)|\hat\eta )X=X^TWX$. Here $W$ is a diagonal matrix with weights. The variance-covariance matrix is $(X^TWX)^{-1}$.
Edit:
An easier way is to use $I(\beta)=(\dfrac{d \eta}{d \beta})^TI(\eta)\dfrac{d \eta}{d \beta}$.
reference:
exponential family
Fisher information
|
How does R function summary.glm calculate the covariance matrix for glm model?
|
I was confused about this several months ago. After reading some material, I have a clue about the problem. But I am not sure that the following is correct.
Suppose the distribution of response $Y$ is
|
How does R function summary.glm calculate the covariance matrix for glm model?
I was confused about this several months ago. After reading some material, I have a clue about the problem. But I am not sure that the following is correct.
Suppose the distribution of response $Y$ is an exponential family, $X^TX>0$. $p(Y|\eta)\sim \exp(\phi^{-1}\eta^T T(Y)-A(\eta)+B(Y))$, $\eta=g(E(Y|X))=X\beta$, $g$ is the canonical link, $\phi$ is the dispersion parameter of the distribution.
Fitting GLM uses MLE, and we have the Wald-type CI for MLE. The variance-covariance matrix is $I(\hat\beta)^{-1}$. $I(\hat\beta)=-E(\dfrac{\partial^2}{\partial\beta^2}\log p(Y|\eta)|\hat\beta)=\dfrac{\partial^2}{\partial\beta^2}A(X\beta)|\hat\beta=X^T(\dfrac{\partial^2}{\partial\eta^2}A(\eta)|\hat\eta )X=X^TWX$. Here $W$ is a diagonal matrix with weights. The variance-covariance matrix is $(X^TWX)^{-1}$.
Edit:
An easier way is to use $I(\beta)=(\dfrac{d \eta}{d \beta})^TI(\eta)\dfrac{d \eta}{d \beta}$.
reference:
exponential family
Fisher information
|
How does R function summary.glm calculate the covariance matrix for glm model?
I was confused about this several months ago. After reading some material, I have a clue about the problem. But I am not sure that the following is correct.
Suppose the distribution of response $Y$ is
|
41,052
|
How does R function summary.glm calculate the covariance matrix for glm model?
|
?chol2inv says:
Invert a symmetric, positive definite square matrix from its
Choleski decomposition. Equivalently, compute (X'X)^(-1) from the
(R part) of the QR decomposition of X.
and if you want to dig deeper into the numerics:
This is an interface to the LAPACK routine ‘DPOTRI’
and the documentation for DPOTRI says:
DPOTRI computes the inverse of a real symmetric positive definite
matrix A using the Cholesky factorization A = U**T*U or A = L*L**T
computed by DPOTRF. [here **T denotes transposition]
The point is that once you have the $R$ component, you don't need to take the crossproduct and then invert - you can much more easily compute the inversion directly.
Hence, the chol2inv(Qr$qr[p1, p1, drop = FALSE]) computes $(R^\top R)^{-1}=(X^\top WX)^{-1}$, where $R$ is the upper triangular matrix from the QR decomposition $QR(\sqrt{W}X)$.
|
How does R function summary.glm calculate the covariance matrix for glm model?
|
?chol2inv says:
Invert a symmetric, positive definite square matrix from its
Choleski decomposition. Equivalently, compute (X'X)^(-1) from the
(R part) of the QR decomposition of X.
a
|
How does R function summary.glm calculate the covariance matrix for glm model?
?chol2inv says:
Invert a symmetric, positive definite square matrix from its
Choleski decomposition. Equivalently, compute (X'X)^(-1) from the
(R part) of the QR decomposition of X.
and if you want to dig deeper into the numerics:
This is an interface to the LAPACK routine ‘DPOTRI’
and the documentation for DPOTRI says:
DPOTRI computes the inverse of a real symmetric positive definite
matrix A using the Cholesky factorization A = U**T*U or A = L*L**T
computed by DPOTRF. [here **T denotes transposition]
The point is that once you have the $R$ component, you don't need to take the crossproduct and then invert - you can much more easily compute the inversion directly.
Hence, the chol2inv(Qr$qr[p1, p1, drop = FALSE]) computes $(R^\top R)^{-1}=(X^\top WX)^{-1}$, where $R$ is the upper triangular matrix from the QR decomposition $QR(\sqrt{W}X)$.
|
How does R function summary.glm calculate the covariance matrix for glm model?
?chol2inv says:
Invert a symmetric, positive definite square matrix from its
Choleski decomposition. Equivalently, compute (X'X)^(-1) from the
(R part) of the QR decomposition of X.
a
|
41,053
|
How to determine a prior, if there is no relevant prior empirical information?
|
If you have no strong prior beliefs or assumptions, you can use non-informative priors, which don't impose strong structure or constraints. Rather, they try to express ignorance about the parameters in a principled way. The Jeffreys prior and reference priors are prominent examples. Very general constraints may be imposed (for example, that particular parameters must be non-negative). Non-informative priors are useful when 'stronger' priors would unjustifiably favor some hypotheses in a way that's inconsistent with your actual (lack of) knowledge/beliefs. Along similar lines, see principles of indifference and maximum entropy. Because non-informative priors express a large degree of ignorance about the parameters, the posterior distribution will generally be influenced more strongly by the likelihood function. For more information, see:
Kass and Wasserman (1996). The selection of prior distributions by formal rules.
If you have stronger prior knowledge/beliefs about the system you're modeling (e.g. domain knowledge, previous findings), you can use an informative prior. Your beliefs may not completely specify a full distribution. For example, you might have a notion that certain parameter ranges are more probable, but do your beliefs correspond precisely to some particular parametric form (e.g. a normal distribution, gamma distribution, etc.)? In practice, the choice of prior will reflect some combination of satisfying your (perhaps incomplete) beliefs, convention, and computational convenience.
You can distill knowledge from domain experts into a prior distribution. This is called 'prior elicitation' (e.g. see discusssion here). The general approach is to ask a series of questions to extract the experts' knowledge/beliefs, then use the answers to construct a prior distribution.
|
How to determine a prior, if there is no relevant prior empirical information?
|
If you have no strong prior beliefs or assumptions, you can use non-informative priors, which don't impose strong structure or constraints. Rather, they try to express ignorance about the parameters i
|
How to determine a prior, if there is no relevant prior empirical information?
If you have no strong prior beliefs or assumptions, you can use non-informative priors, which don't impose strong structure or constraints. Rather, they try to express ignorance about the parameters in a principled way. The Jeffreys prior and reference priors are prominent examples. Very general constraints may be imposed (for example, that particular parameters must be non-negative). Non-informative priors are useful when 'stronger' priors would unjustifiably favor some hypotheses in a way that's inconsistent with your actual (lack of) knowledge/beliefs. Along similar lines, see principles of indifference and maximum entropy. Because non-informative priors express a large degree of ignorance about the parameters, the posterior distribution will generally be influenced more strongly by the likelihood function. For more information, see:
Kass and Wasserman (1996). The selection of prior distributions by formal rules.
If you have stronger prior knowledge/beliefs about the system you're modeling (e.g. domain knowledge, previous findings), you can use an informative prior. Your beliefs may not completely specify a full distribution. For example, you might have a notion that certain parameter ranges are more probable, but do your beliefs correspond precisely to some particular parametric form (e.g. a normal distribution, gamma distribution, etc.)? In practice, the choice of prior will reflect some combination of satisfying your (perhaps incomplete) beliefs, convention, and computational convenience.
You can distill knowledge from domain experts into a prior distribution. This is called 'prior elicitation' (e.g. see discusssion here). The general approach is to ask a series of questions to extract the experts' knowledge/beliefs, then use the answers to construct a prior distribution.
|
How to determine a prior, if there is no relevant prior empirical information?
If you have no strong prior beliefs or assumptions, you can use non-informative priors, which don't impose strong structure or constraints. Rather, they try to express ignorance about the parameters i
|
41,054
|
How to determine a prior, if there is no relevant prior empirical information?
|
In my case, I have an empirical prior probability to use in calculating the posterior probability. But this isn’t the subjective way of doing it, I believe.
On the contrary. The 'subjective way of doing it' is to ask what information you want to assume and then construct a prior accordingly. If you're happy to make exchangeability judgements about cases, then that implies some distributional constraints on the prior (see multi-level models). If you have a known constraint e.g. you think some quantity should have a finite variance, without knowing what that variance is, (or even that some quantities should add up to 7), then that implies other distributional constraints (see maximum entropy). If you have historical data, better yet; this may help to pin down some of the parameters for the distributions implied by the previous information.
None of this is required, not least because the subject presupposed by a subjective prior need not be you. However, in ordinary situations you would not want to build a prior around the beliefs of the sort of subject that would, for example, ignore historical evidence. So you'd usually take the historical information into account. What makes the constructed prior 'subjective' is that it could be informed by more than that historical data.
If I didn’t have any prior empirical information, how could I estimate the prior probability?
Neither you, nor anyone else, are ever in this situation, so it doesn't matter.
|
How to determine a prior, if there is no relevant prior empirical information?
|
In my case, I have an empirical prior probability to use in calculating the posterior probability. But this isn’t the subjective way of doing it, I believe.
On the contrary. The 'subjective way of d
|
How to determine a prior, if there is no relevant prior empirical information?
In my case, I have an empirical prior probability to use in calculating the posterior probability. But this isn’t the subjective way of doing it, I believe.
On the contrary. The 'subjective way of doing it' is to ask what information you want to assume and then construct a prior accordingly. If you're happy to make exchangeability judgements about cases, then that implies some distributional constraints on the prior (see multi-level models). If you have a known constraint e.g. you think some quantity should have a finite variance, without knowing what that variance is, (or even that some quantities should add up to 7), then that implies other distributional constraints (see maximum entropy). If you have historical data, better yet; this may help to pin down some of the parameters for the distributions implied by the previous information.
None of this is required, not least because the subject presupposed by a subjective prior need not be you. However, in ordinary situations you would not want to build a prior around the beliefs of the sort of subject that would, for example, ignore historical evidence. So you'd usually take the historical information into account. What makes the constructed prior 'subjective' is that it could be informed by more than that historical data.
If I didn’t have any prior empirical information, how could I estimate the prior probability?
Neither you, nor anyone else, are ever in this situation, so it doesn't matter.
|
How to determine a prior, if there is no relevant prior empirical information?
In my case, I have an empirical prior probability to use in calculating the posterior probability. But this isn’t the subjective way of doing it, I believe.
On the contrary. The 'subjective way of d
|
41,055
|
How is the $ \chi^2 $ distribution defined at 0 for various degrees of freedom?
|
The pdf of a $\chi^2$ distribution is
$f(x;k)=\frac{1}{2^{\frac{k}{2}}\Gamma(k/2)}x^{k/2-1}\exp(-x/2).$
So we just need to evaluate the expression for $f(0;k)$.
$$
f(0;1)=\infty
$$
$$
f(0;2)=0.5
$$
$$
f(0;3)=0
$$
And so on. The R code for this is dchisq(0,k) for some positive k. It's really only interesting for $k= 2$ because $f(0;k)$ is infinite for $0<k<2$ and 0 for $k>2$.
|
How is the $ \chi^2 $ distribution defined at 0 for various degrees of freedom?
|
The pdf of a $\chi^2$ distribution is
$f(x;k)=\frac{1}{2^{\frac{k}{2}}\Gamma(k/2)}x^{k/2-1}\exp(-x/2).$
So we just need to evaluate the expression for $f(0;k)$.
$$
f(0;1)=\infty
$$
$$
f(0;2)=0.5
$$
$
|
How is the $ \chi^2 $ distribution defined at 0 for various degrees of freedom?
The pdf of a $\chi^2$ distribution is
$f(x;k)=\frac{1}{2^{\frac{k}{2}}\Gamma(k/2)}x^{k/2-1}\exp(-x/2).$
So we just need to evaluate the expression for $f(0;k)$.
$$
f(0;1)=\infty
$$
$$
f(0;2)=0.5
$$
$$
f(0;3)=0
$$
And so on. The R code for this is dchisq(0,k) for some positive k. It's really only interesting for $k= 2$ because $f(0;k)$ is infinite for $0<k<2$ and 0 for $k>2$.
|
How is the $ \chi^2 $ distribution defined at 0 for various degrees of freedom?
The pdf of a $\chi^2$ distribution is
$f(x;k)=\frac{1}{2^{\frac{k}{2}}\Gamma(k/2)}x^{k/2-1}\exp(-x/2).$
So we just need to evaluate the expression for $f(0;k)$.
$$
f(0;1)=\infty
$$
$$
f(0;2)=0.5
$$
$
|
41,056
|
How is the $ \chi^2 $ distribution defined at 0 for various degrees of freedom?
|
Let's try to go back to the definition of this distribution and see what happens around 0.
By definition, the $\chi^2$ distribution is that of the sum of the squares of independent normal random variables:
$$
Y = \sum_{i=1}^k Z_i^2 ,
$$
(see the wikipedia page). We see easily that the value of the density is $0$ for $k\geq 3$ and $.5$ for $k=2$. For $k=1$, the case is a bit different.
Let's consider just that case to resolve your question: by a change of variable, we have $y=g(z)=z^2$ such that:
$$
f_Y(y) = \left| \frac{d}{dy} (g^{-1}(y)) \right| \cdot f_Z(g^{-1}(y))\\
= \left| \frac{d}{dy} (\sqrt{y}) \right| \cdot f_Z(\sqrt{y})\\
= \frac{1}{2\sqrt{y}} \cdot \frac{1}{\sqrt{2}\pi} \exp(-y/2)
$$
We understand a basic fact, the $\chi_1$ is not defined at $0$ because the squaring operation at that point is flat $g(0)=0$ and thus that $g^{-1}(0)$ is not defined (infinite).
|
How is the $ \chi^2 $ distribution defined at 0 for various degrees of freedom?
|
Let's try to go back to the definition of this distribution and see what happens around 0.
By definition, the $\chi^2$ distribution is that of the sum of the squares of independent normal random vari
|
How is the $ \chi^2 $ distribution defined at 0 for various degrees of freedom?
Let's try to go back to the definition of this distribution and see what happens around 0.
By definition, the $\chi^2$ distribution is that of the sum of the squares of independent normal random variables:
$$
Y = \sum_{i=1}^k Z_i^2 ,
$$
(see the wikipedia page). We see easily that the value of the density is $0$ for $k\geq 3$ and $.5$ for $k=2$. For $k=1$, the case is a bit different.
Let's consider just that case to resolve your question: by a change of variable, we have $y=g(z)=z^2$ such that:
$$
f_Y(y) = \left| \frac{d}{dy} (g^{-1}(y)) \right| \cdot f_Z(g^{-1}(y))\\
= \left| \frac{d}{dy} (\sqrt{y}) \right| \cdot f_Z(\sqrt{y})\\
= \frac{1}{2\sqrt{y}} \cdot \frac{1}{\sqrt{2}\pi} \exp(-y/2)
$$
We understand a basic fact, the $\chi_1$ is not defined at $0$ because the squaring operation at that point is flat $g(0)=0$ and thus that $g^{-1}(0)$ is not defined (infinite).
|
How is the $ \chi^2 $ distribution defined at 0 for various degrees of freedom?
Let's try to go back to the definition of this distribution and see what happens around 0.
By definition, the $\chi^2$ distribution is that of the sum of the squares of independent normal random vari
|
41,057
|
Question about joint distribution of Bernoulli random variables under constraint that sum must be 1
|
This is a categorical distribution, also known as a multinomial distribution with number of trials equal to $1$.
If the binomial probabilities are $q_k, \;k=1,\dots n$ then the multinomial probability is
$$p_k=\frac {q_k\prod_{j\neq k} (1-q_j)}{\sum_r q_r\prod_{s\neq r}(1-q_s)}$$
To derive this you simply use the conditional probability $p (A_k|B)=p (A_kB)/p (B) $ where $A_k$ is the event "variable $k $ is equal to $1$" and $B $ is the event "sum of all $n $ variables equals 1". Then you can deduce that for both $A_k $ and $B $ to be true, all the other bernoulli variables must be zero. This probability is the numerator for the value of $p_k $ I gave earlier. Then $p (B)=\sum_r p (A_rB)$ using law of total probability and independence and the denominator I gave.
|
Question about joint distribution of Bernoulli random variables under constraint that sum must be 1
|
This is a categorical distribution, also known as a multinomial distribution with number of trials equal to $1$.
If the binomial probabilities are $q_k, \;k=1,\dots n$ then the multinomial probability
|
Question about joint distribution of Bernoulli random variables under constraint that sum must be 1
This is a categorical distribution, also known as a multinomial distribution with number of trials equal to $1$.
If the binomial probabilities are $q_k, \;k=1,\dots n$ then the multinomial probability is
$$p_k=\frac {q_k\prod_{j\neq k} (1-q_j)}{\sum_r q_r\prod_{s\neq r}(1-q_s)}$$
To derive this you simply use the conditional probability $p (A_k|B)=p (A_kB)/p (B) $ where $A_k$ is the event "variable $k $ is equal to $1$" and $B $ is the event "sum of all $n $ variables equals 1". Then you can deduce that for both $A_k $ and $B $ to be true, all the other bernoulli variables must be zero. This probability is the numerator for the value of $p_k $ I gave earlier. Then $p (B)=\sum_r p (A_rB)$ using law of total probability and independence and the denominator I gave.
|
Question about joint distribution of Bernoulli random variables under constraint that sum must be 1
This is a categorical distribution, also known as a multinomial distribution with number of trials equal to $1$.
If the binomial probabilities are $q_k, \;k=1,\dots n$ then the multinomial probability
|
41,058
|
Question about joint distribution of Bernoulli random variables under constraint that sum must be 1
|
There are only $n$ ways the variables can sum to $1$: one of them will equal $1$ and the other $n-1$ will equal zero. The very phrasing of the question indicates the variables are exchangeable: thus, the joint distribution will not change when the variables are permuted. Since permutations of the variables merely change each of these outcomes into other outcomes, they are all equally likely. Consequently the distribution is the uniform one on those $n$ outcomes, with probability $1/n$ for each outcome. That fully describes the joint distribution.
Edit
The original question assumed neither exchangeability nor independence. But without making some such assumption, the only conclusion we can draw is that the joint distribution is some distribution on the $n$ possible outcomes I have described. The probabilities may be any $n$ non-negative values that sum to unity, as required by the axioms of probability.
|
Question about joint distribution of Bernoulli random variables under constraint that sum must be 1
|
There are only $n$ ways the variables can sum to $1$: one of them will equal $1$ and the other $n-1$ will equal zero. The very phrasing of the question indicates the variables are exchangeable: thus,
|
Question about joint distribution of Bernoulli random variables under constraint that sum must be 1
There are only $n$ ways the variables can sum to $1$: one of them will equal $1$ and the other $n-1$ will equal zero. The very phrasing of the question indicates the variables are exchangeable: thus, the joint distribution will not change when the variables are permuted. Since permutations of the variables merely change each of these outcomes into other outcomes, they are all equally likely. Consequently the distribution is the uniform one on those $n$ outcomes, with probability $1/n$ for each outcome. That fully describes the joint distribution.
Edit
The original question assumed neither exchangeability nor independence. But without making some such assumption, the only conclusion we can draw is that the joint distribution is some distribution on the $n$ possible outcomes I have described. The probabilities may be any $n$ non-negative values that sum to unity, as required by the axioms of probability.
|
Question about joint distribution of Bernoulli random variables under constraint that sum must be 1
There are only $n$ ways the variables can sum to $1$: one of them will equal $1$ and the other $n-1$ will equal zero. The very phrasing of the question indicates the variables are exchangeable: thus,
|
41,059
|
A few clarifications regarding convolutional neural networks
|
Fully connected layers can only deal with input of a fixed size, because it requires a certain amount of parameters to "fully connect" the input and output. While convolutional layers just "slide" the same filters across the input, so it can basically deal with input of an arbitrary spatial size.
In the example network with fully-connected layers at the end, a 224*224 image will output an 1000d vector of class scores. If we apply the network on a larger image, the network will fail because of the inconsistency between the input and parameters of the first fully-connected layer.
One the other hand, if we use a fully convolutional network, when applied to a larger image we'll get 1000 "heatmaps" of class scores.
As shown in the following figure (from the FCN segmentation paper), the upper network gives one score per class, and after the conversion (convolutionalization), we can get the a heatmap per class for a larger image.
About "stride", on the same page, in the section Spatial arrangement:
When the stride is 1 then we move the filters one pixel at a time. When the stride is 2 (or uncommonly 3 or more, though this is rare in practice) then the filters jump 2 pixels at a time as we slide them around. This will produce smaller output volumes spatially.
|
A few clarifications regarding convolutional neural networks
|
Fully connected layers can only deal with input of a fixed size, because it requires a certain amount of parameters to "fully connect" the input and output. While convolutional layers just "slide" the
|
A few clarifications regarding convolutional neural networks
Fully connected layers can only deal with input of a fixed size, because it requires a certain amount of parameters to "fully connect" the input and output. While convolutional layers just "slide" the same filters across the input, so it can basically deal with input of an arbitrary spatial size.
In the example network with fully-connected layers at the end, a 224*224 image will output an 1000d vector of class scores. If we apply the network on a larger image, the network will fail because of the inconsistency between the input and parameters of the first fully-connected layer.
One the other hand, if we use a fully convolutional network, when applied to a larger image we'll get 1000 "heatmaps" of class scores.
As shown in the following figure (from the FCN segmentation paper), the upper network gives one score per class, and after the conversion (convolutionalization), we can get the a heatmap per class for a larger image.
About "stride", on the same page, in the section Spatial arrangement:
When the stride is 1 then we move the filters one pixel at a time. When the stride is 2 (or uncommonly 3 or more, though this is rare in practice) then the filters jump 2 pixels at a time as we slide them around. This will produce smaller output volumes spatially.
|
A few clarifications regarding convolutional neural networks
Fully connected layers can only deal with input of a fixed size, because it requires a certain amount of parameters to "fully connect" the input and output. While convolutional layers just "slide" the
|
41,060
|
What is cross-lagged panel design?
|
The cross-lagged panel model (CLPM) is a type of structural equation model (specifically a path analysis model) that is used where two or more variables are measured at two or more occasions and interest is centered on the associations (often causal theories) with each other over time. For example, there may be interest in seeking to understand the direction of causality between intelligence/academic achievement at a macro/national level and a nation’s GDP – do higher levels of education cause higher GDP or does higher GDP bring about higher levels of education, or is there a bi-directional/reciprocal relationship? This can be investigated by considering the effect of variable A at time 1 on variable B at time 2, and of variable B at time 1 on variable A at time 2.
In the figure you have 2 variables, Assessment A and Assessment B, each measured on 2 occasions, 2016 and 2019. The interest may be on whether results in Assessment A in 2016 affect the results of Assessment B in 2019 and whether results in Assessment B in 2016 affect the results of Assessment A in 2019.
The way that the figure is drawn, it appears that this model is a cross-lagged panel correlation model, where each line between the observed variables represents a correlation or covariance. However, following Rogosa (1980), this model was abandoned in favour of one where each of the later measurements are regressed on the other at the earlier time point. The successive measurements of the same variable may either be modelled as autocorrelation or regression. That is:
or
where single headed arrows represent regressions (assumed causal relations) and double-headed arrows represent covariance/correlation.
Rogosa, D. R. (1980). A critique of cross-lagged correlation. Psychological
Bulletin, 88, 245–258.
http://psycnet.apa.org/doi/10.1037/0033-2909.88.2.245
|
What is cross-lagged panel design?
|
The cross-lagged panel model (CLPM) is a type of structural equation model (specifically a path analysis model) that is used where two or more variables are measured at two or more occasions and inter
|
What is cross-lagged panel design?
The cross-lagged panel model (CLPM) is a type of structural equation model (specifically a path analysis model) that is used where two or more variables are measured at two or more occasions and interest is centered on the associations (often causal theories) with each other over time. For example, there may be interest in seeking to understand the direction of causality between intelligence/academic achievement at a macro/national level and a nation’s GDP – do higher levels of education cause higher GDP or does higher GDP bring about higher levels of education, or is there a bi-directional/reciprocal relationship? This can be investigated by considering the effect of variable A at time 1 on variable B at time 2, and of variable B at time 1 on variable A at time 2.
In the figure you have 2 variables, Assessment A and Assessment B, each measured on 2 occasions, 2016 and 2019. The interest may be on whether results in Assessment A in 2016 affect the results of Assessment B in 2019 and whether results in Assessment B in 2016 affect the results of Assessment A in 2019.
The way that the figure is drawn, it appears that this model is a cross-lagged panel correlation model, where each line between the observed variables represents a correlation or covariance. However, following Rogosa (1980), this model was abandoned in favour of one where each of the later measurements are regressed on the other at the earlier time point. The successive measurements of the same variable may either be modelled as autocorrelation or regression. That is:
or
where single headed arrows represent regressions (assumed causal relations) and double-headed arrows represent covariance/correlation.
Rogosa, D. R. (1980). A critique of cross-lagged correlation. Psychological
Bulletin, 88, 245–258.
http://psycnet.apa.org/doi/10.1037/0033-2909.88.2.245
|
What is cross-lagged panel design?
The cross-lagged panel model (CLPM) is a type of structural equation model (specifically a path analysis model) that is used where two or more variables are measured at two or more occasions and inter
|
41,061
|
Scoring quantile regressor
|
The first thing we expect from a quantile forecast is that it respects the prespecified quantile, i.e., that it provides quantile predictions that are larger than a proportion $\tau$ of your realizations. You can check this by looking at your $n$ quantile predictions $\hat{y}_i$ and assessing whether
$$\hat{\tau} := \frac{1}{n} \#\{i\colon y_i<\hat{y}_i\} \approx \tau.$$
As a matter of fact, you can of course even do inferential statistics. Under the null hypothesis that $\hat{\tau}=\tau$, whether or not a given future realization fulfills $y_i<\hat{y}_i$ is Bernoulli distributed with probability $\tau$. Given $n$ future realizations, the total number $\#\{i\colon y_i<\hat{y}_i\}$ of successes will, under the null hypothesis, be $(n,\tau)$-binomially distributed, so you can calculate confidence intervals into which you expect (say) 95% of numbers of successes to fall. If your actual number of successes is outside this interval, you can reject the null hypothesis that $\hat{\tau}=\tau$ at $\alpha=0.05$. Similarly, two different quantile forecasting algorithms may yield different $\hat{\tau}_1$ and $\hat{\tau}_2$, and you can similarly assess whether these are significantly different.
However, this is certainly not the end of the story. A little more thinking gives us a somewhat more stringent criterion for a model to be good: the best possible model for $\tau$-quantile predictions will provide quantile predictions that are larger than a proportion $\tau$ of your realizations - and do this independently of the predictors $x$.
To see why the last clause is important, assume that $x$ is a one-dimensional predictor which takes the values $x=(1,0,1,0,1,0,\dots)$. Assume further that the true future distribution is a mixture of two uniforms and depends on $x$ as follows:
$$ y \sim \begin{cases}
U[0,1], & x=0 \\
U[1,2], & x=1
\end{cases} $$
Now, the unconditional distribution of $y$ is $U[0,2]$, since half of our $x$ are 0 and half are 1. Thus, if we want a median forecast ($\tau=0.5$), we could simply forecast $\hat{y}=1$. Then half of our observations would be below this prediction (namely, the ones where $x=0$), and half would be above it (those with $x=1$). We thus would have a wonderful median forecast that covers exactly the prespecified proportion of realizations.
Nevertheless, we would certainly not say that this median forecast is good, since its performance still depends heavily on $x$. The best median forecast would of course take the dependence on $x$ into account:
$$ \hat{y} := \begin{cases} 0.5, & x=0 \\ 1.5, & x=1 \end{cases} $$
Thus, another test you should do is to take the indicator variable of successes $I_{\{y_i<\hat{y}_i\}}$ and check whether this is independent of $x_i$. You can do a logistic regression of $I_{\{y_i<\hat{y}_i\}}$ against $x_i$ and check the significance of this model, or you could do any kind of machine learning algorithm, like feeding $I_{\{y_i<\hat{y}_i\}}$ and $x_i$ into a Random Forest - any predictive power of $x_i$ against $I_{\{y_i<\hat{y}_i\}}$ that you find is evidence that your quantile prediction is not yet optimal.
This question is actually rather important in time series analysis and forecasting. Here, the question is one of forecasting Value at Risk, where you don't want a simple approach that gives correct quantiles on average, but overshoots the quantile during calm periods in the market, but undershoots it during turbulent times. Or there may be periodicities in variances, which a good quantile forecast had better incorporate. (See my example above.)
Thus, what we are most interested in in the context of time series analysis is not so much whether $I_{\{y_i<\hat{y}_i\}}$ depends on some predictor $x_i$, but rather more in whether there is any autoregressive behavior in the time series $I_{\{y_t<\hat{y}_t\}}$. Tests have been developed to check for such autoregressive dynamics. Probably the first paper on this was Christoffersen (1998, International Economic Review), or later Clements & Taylor (2003, Journal of Applied Econometrics), and recently Dumitrescu, Hurlin & Madkour (2013, Journal of Forecasting). If your underlying data have time series characteristics, I'd very much recommend that you look into this literature.
Finally, for a somewhat different take on this question, I recommend Gneiting (2011, International Journal of Forecasting), who investigates proper scoring rules for quantile forecasts as point forecasts. He shows that all such proper scoring rules are actually slight generalizations of Koenker's $\rho_\tau$ function you note. This might be interesting for you.
|
Scoring quantile regressor
|
The first thing we expect from a quantile forecast is that it respects the prespecified quantile, i.e., that it provides quantile predictions that are larger than a proportion $\tau$ of your realizati
|
Scoring quantile regressor
The first thing we expect from a quantile forecast is that it respects the prespecified quantile, i.e., that it provides quantile predictions that are larger than a proportion $\tau$ of your realizations. You can check this by looking at your $n$ quantile predictions $\hat{y}_i$ and assessing whether
$$\hat{\tau} := \frac{1}{n} \#\{i\colon y_i<\hat{y}_i\} \approx \tau.$$
As a matter of fact, you can of course even do inferential statistics. Under the null hypothesis that $\hat{\tau}=\tau$, whether or not a given future realization fulfills $y_i<\hat{y}_i$ is Bernoulli distributed with probability $\tau$. Given $n$ future realizations, the total number $\#\{i\colon y_i<\hat{y}_i\}$ of successes will, under the null hypothesis, be $(n,\tau)$-binomially distributed, so you can calculate confidence intervals into which you expect (say) 95% of numbers of successes to fall. If your actual number of successes is outside this interval, you can reject the null hypothesis that $\hat{\tau}=\tau$ at $\alpha=0.05$. Similarly, two different quantile forecasting algorithms may yield different $\hat{\tau}_1$ and $\hat{\tau}_2$, and you can similarly assess whether these are significantly different.
However, this is certainly not the end of the story. A little more thinking gives us a somewhat more stringent criterion for a model to be good: the best possible model for $\tau$-quantile predictions will provide quantile predictions that are larger than a proportion $\tau$ of your realizations - and do this independently of the predictors $x$.
To see why the last clause is important, assume that $x$ is a one-dimensional predictor which takes the values $x=(1,0,1,0,1,0,\dots)$. Assume further that the true future distribution is a mixture of two uniforms and depends on $x$ as follows:
$$ y \sim \begin{cases}
U[0,1], & x=0 \\
U[1,2], & x=1
\end{cases} $$
Now, the unconditional distribution of $y$ is $U[0,2]$, since half of our $x$ are 0 and half are 1. Thus, if we want a median forecast ($\tau=0.5$), we could simply forecast $\hat{y}=1$. Then half of our observations would be below this prediction (namely, the ones where $x=0$), and half would be above it (those with $x=1$). We thus would have a wonderful median forecast that covers exactly the prespecified proportion of realizations.
Nevertheless, we would certainly not say that this median forecast is good, since its performance still depends heavily on $x$. The best median forecast would of course take the dependence on $x$ into account:
$$ \hat{y} := \begin{cases} 0.5, & x=0 \\ 1.5, & x=1 \end{cases} $$
Thus, another test you should do is to take the indicator variable of successes $I_{\{y_i<\hat{y}_i\}}$ and check whether this is independent of $x_i$. You can do a logistic regression of $I_{\{y_i<\hat{y}_i\}}$ against $x_i$ and check the significance of this model, or you could do any kind of machine learning algorithm, like feeding $I_{\{y_i<\hat{y}_i\}}$ and $x_i$ into a Random Forest - any predictive power of $x_i$ against $I_{\{y_i<\hat{y}_i\}}$ that you find is evidence that your quantile prediction is not yet optimal.
This question is actually rather important in time series analysis and forecasting. Here, the question is one of forecasting Value at Risk, where you don't want a simple approach that gives correct quantiles on average, but overshoots the quantile during calm periods in the market, but undershoots it during turbulent times. Or there may be periodicities in variances, which a good quantile forecast had better incorporate. (See my example above.)
Thus, what we are most interested in in the context of time series analysis is not so much whether $I_{\{y_i<\hat{y}_i\}}$ depends on some predictor $x_i$, but rather more in whether there is any autoregressive behavior in the time series $I_{\{y_t<\hat{y}_t\}}$. Tests have been developed to check for such autoregressive dynamics. Probably the first paper on this was Christoffersen (1998, International Economic Review), or later Clements & Taylor (2003, Journal of Applied Econometrics), and recently Dumitrescu, Hurlin & Madkour (2013, Journal of Forecasting). If your underlying data have time series characteristics, I'd very much recommend that you look into this literature.
Finally, for a somewhat different take on this question, I recommend Gneiting (2011, International Journal of Forecasting), who investigates proper scoring rules for quantile forecasts as point forecasts. He shows that all such proper scoring rules are actually slight generalizations of Koenker's $\rho_\tau$ function you note. This might be interesting for you.
|
Scoring quantile regressor
The first thing we expect from a quantile forecast is that it respects the prespecified quantile, i.e., that it provides quantile predictions that are larger than a proportion $\tau$ of your realizati
|
41,062
|
Testing linear restriction in R
|
I think your current parameterization is sufficient to test either coefficient restriction (via the t-tests for each coefficient), but not both restrictions at the same time. To do that one can conduct an F-test between the unrestricted and the restricted model (since it is nested).
Example below in R using the car package.
library(car)
set.seed(10)
x1 <- rnorm(100)
x2 <- rnorm(100)
x3 <- rnorm(100)
y <- 5*x1 + 0.5*x2 - 0.5*x3 + rnorm(100)
m1 <- lm(y~x1+x2+x3)
linearHypothesis(m1,c("x2 = 0.5","x3 = -0.5"),test="F")
Which then spits out a table with the RSS for each model and the degrees of freedom, needed to calculate the F-statistic.
Linear hypothesis test
Hypothesis:
x2 = 0.5
x3 = - 0.5
Model 1: restricted model
Model 2: y ~ x1 + x2 + x3
Res.Df RSS Df Sum of Sq F Pr(>F)
1 98 107.21
2 96 107.10 2 0.10752 0.0482 0.953
You answered you own question in terms of testing individual coefficients, you can transform the variable on the left hand side. To replicate the linearHypothesis function I trick R here by making the transformed variable:
#equivalent F test - can trick R by making y a new variable
y <- y -0.5*x2 +0.5*x3
m2 <- lm(y~x1)
anova(m2,m1)
Which reproduces the earlier table. You can use this same trick to get the default summary t-test's in the regression output to test against the alternative hypotheses:
#test for either coefficient restriction (with updated y)
m3 <- lm(y~x1+x2+x3)
summary(m3)
#you can see m3 is equivalent to m1 - just changes the location of the test
#anova(m1,m3)
Which produces for coefficient estimates:
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 0.208282 0.107351 1.940 0.0553 .
x1 5.045149 0.112973 44.658 <2e-16 ***
x2 0.033042 0.110693 0.299 0.7660
x3 -0.004875 0.110122 -0.044 0.9648
To test with the original values, user2864849 answers that question. You just subtract out the null from the point estimate and use the same standard error. So using the coefficients from m1 you can see below t_est reproduces the t-statistic in model 3.
#to see how it is just the original t-test with the location changed for x2
pt_est <- summary(m1)$coefficients[3,1] #point estimate x2
se_est <- summary(m1)$coefficients[3,2] #standard error x2
t_est <- (pt_est - 0.5)/se_est #t-stat for null of 0.5
t_est
|
Testing linear restriction in R
|
I think your current parameterization is sufficient to test either coefficient restriction (via the t-tests for each coefficient), but not both restrictions at the same time. To do that one can conduc
|
Testing linear restriction in R
I think your current parameterization is sufficient to test either coefficient restriction (via the t-tests for each coefficient), but not both restrictions at the same time. To do that one can conduct an F-test between the unrestricted and the restricted model (since it is nested).
Example below in R using the car package.
library(car)
set.seed(10)
x1 <- rnorm(100)
x2 <- rnorm(100)
x3 <- rnorm(100)
y <- 5*x1 + 0.5*x2 - 0.5*x3 + rnorm(100)
m1 <- lm(y~x1+x2+x3)
linearHypothesis(m1,c("x2 = 0.5","x3 = -0.5"),test="F")
Which then spits out a table with the RSS for each model and the degrees of freedom, needed to calculate the F-statistic.
Linear hypothesis test
Hypothesis:
x2 = 0.5
x3 = - 0.5
Model 1: restricted model
Model 2: y ~ x1 + x2 + x3
Res.Df RSS Df Sum of Sq F Pr(>F)
1 98 107.21
2 96 107.10 2 0.10752 0.0482 0.953
You answered you own question in terms of testing individual coefficients, you can transform the variable on the left hand side. To replicate the linearHypothesis function I trick R here by making the transformed variable:
#equivalent F test - can trick R by making y a new variable
y <- y -0.5*x2 +0.5*x3
m2 <- lm(y~x1)
anova(m2,m1)
Which reproduces the earlier table. You can use this same trick to get the default summary t-test's in the regression output to test against the alternative hypotheses:
#test for either coefficient restriction (with updated y)
m3 <- lm(y~x1+x2+x3)
summary(m3)
#you can see m3 is equivalent to m1 - just changes the location of the test
#anova(m1,m3)
Which produces for coefficient estimates:
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 0.208282 0.107351 1.940 0.0553 .
x1 5.045149 0.112973 44.658 <2e-16 ***
x2 0.033042 0.110693 0.299 0.7660
x3 -0.004875 0.110122 -0.044 0.9648
To test with the original values, user2864849 answers that question. You just subtract out the null from the point estimate and use the same standard error. So using the coefficients from m1 you can see below t_est reproduces the t-statistic in model 3.
#to see how it is just the original t-test with the location changed for x2
pt_est <- summary(m1)$coefficients[3,1] #point estimate x2
se_est <- summary(m1)$coefficients[3,2] #standard error x2
t_est <- (pt_est - 0.5)/se_est #t-stat for null of 0.5
t_est
|
Testing linear restriction in R
I think your current parameterization is sufficient to test either coefficient restriction (via the t-tests for each coefficient), but not both restrictions at the same time. To do that one can conduc
|
41,063
|
Testing linear restriction in R
|
You can test the hypothesized value of $\beta_k$ much in the same way that it would be tested for $\beta_k = 0$. You can get a t-value on n-2 df with the formula:
$$T = \frac{\beta_i- hypothesezed~~ \beta_i}{Standard~~ Error~~ \beta_i}$$
In many cases this simplifies to beta over standard error because making the hypothesis be zero removes it from the equation.
|
Testing linear restriction in R
|
You can test the hypothesized value of $\beta_k$ much in the same way that it would be tested for $\beta_k = 0$. You can get a t-value on n-2 df with the formula:
$$T = \frac{\beta_i- hypothesezed~~ \
|
Testing linear restriction in R
You can test the hypothesized value of $\beta_k$ much in the same way that it would be tested for $\beta_k = 0$. You can get a t-value on n-2 df with the formula:
$$T = \frac{\beta_i- hypothesezed~~ \beta_i}{Standard~~ Error~~ \beta_i}$$
In many cases this simplifies to beta over standard error because making the hypothesis be zero removes it from the equation.
|
Testing linear restriction in R
You can test the hypothesized value of $\beta_k$ much in the same way that it would be tested for $\beta_k = 0$. You can get a t-value on n-2 df with the formula:
$$T = \frac{\beta_i- hypothesezed~~ \
|
41,064
|
Testing linear restriction in R
|
Let's say you want to test the hypothesis of the form $R\beta = r$. In your case:
$$\underbrace{\left[ \begin{array}{cccc} \ldots & 1& 0 & \ldots \\ \ldots & 0& 1 & \ldots \end{array}\right]}_R \underbrace{\left[ \begin{array}{c}\ldots \\ \beta_j \\ \beta_k \\ \ldots \end{array} \right]}_\beta = \underbrace{\left[ \begin{array}{c}-.5 \\ .5 \end{array} \right]}_r $$
Let $\hat{\beta}$ be your regression estimates of $\beta$. Under the condition that $\hat{\beta} \sim \mathcal{N}\left(\beta, \Sigma \right)$ conditional on data $X$ (eg. $\hat{\beta}$ asymptotically normal with mean $\beta$ and covariance matrix $\Sigma$) then the linear restrictions $R \beta = r$ can be tested with a $\chi^2$ test. Observe that $R\hat{\beta}-r$ would be normal with $Var(R \hat{\beta} - r\mid X) = R \Sigma R'$. Then we would have:
$$(R\hat{\beta} - r)' \left( R \Sigma R' \right)^{-1} (R \hat{\beta} - r) \sim \chi^2_{\#r}$$
Where $\#r$ is the number of restrictions (in your case two).
The most classic way though is to do an F-test. This would take the form:
$$(R\hat{b} - r)' \left(R \Sigma R' \right)^{-1} (R\hat{b} - r) / (\#r)\sim F(\#r, n- k) $$
where $\Sigma$ is estimate of $Var(\hat{\beta} \mid X)$ and $\#r$ is the number of restrictions (note rank of R should be $\#r$.)
See Fumio Hayashi Econometrics p. 65-66
|
Testing linear restriction in R
|
Let's say you want to test the hypothesis of the form $R\beta = r$. In your case:
$$\underbrace{\left[ \begin{array}{cccc} \ldots & 1& 0 & \ldots \\ \ldots & 0& 1 & \ldots \end{array}\right]}_R \unde
|
Testing linear restriction in R
Let's say you want to test the hypothesis of the form $R\beta = r$. In your case:
$$\underbrace{\left[ \begin{array}{cccc} \ldots & 1& 0 & \ldots \\ \ldots & 0& 1 & \ldots \end{array}\right]}_R \underbrace{\left[ \begin{array}{c}\ldots \\ \beta_j \\ \beta_k \\ \ldots \end{array} \right]}_\beta = \underbrace{\left[ \begin{array}{c}-.5 \\ .5 \end{array} \right]}_r $$
Let $\hat{\beta}$ be your regression estimates of $\beta$. Under the condition that $\hat{\beta} \sim \mathcal{N}\left(\beta, \Sigma \right)$ conditional on data $X$ (eg. $\hat{\beta}$ asymptotically normal with mean $\beta$ and covariance matrix $\Sigma$) then the linear restrictions $R \beta = r$ can be tested with a $\chi^2$ test. Observe that $R\hat{\beta}-r$ would be normal with $Var(R \hat{\beta} - r\mid X) = R \Sigma R'$. Then we would have:
$$(R\hat{\beta} - r)' \left( R \Sigma R' \right)^{-1} (R \hat{\beta} - r) \sim \chi^2_{\#r}$$
Where $\#r$ is the number of restrictions (in your case two).
The most classic way though is to do an F-test. This would take the form:
$$(R\hat{b} - r)' \left(R \Sigma R' \right)^{-1} (R\hat{b} - r) / (\#r)\sim F(\#r, n- k) $$
where $\Sigma$ is estimate of $Var(\hat{\beta} \mid X)$ and $\#r$ is the number of restrictions (note rank of R should be $\#r$.)
See Fumio Hayashi Econometrics p. 65-66
|
Testing linear restriction in R
Let's say you want to test the hypothesis of the form $R\beta = r$. In your case:
$$\underbrace{\left[ \begin{array}{cccc} \ldots & 1& 0 & \ldots \\ \ldots & 0& 1 & \ldots \end{array}\right]}_R \unde
|
41,065
|
Rotating a new matrix into the same basis as another using SVD
|
What you are doing is essentially PCA, even though you did not use this term. It is exactly PCA if your $X$ is centered; if not, then it is a sort of "uncentered PCA".
In any case, to get from $A$ to $UD$ you need to right-multiply it with $V$: $$AV=UDV^\top V = UD.$$
So to apply the same transformation to $B$, you simply right-multiply it with $V$ too.
If you only need the first $k$ columns, then you right-multiply with $V_k$ which is the matrix of the first $k$ columns of $V$.
|
Rotating a new matrix into the same basis as another using SVD
|
What you are doing is essentially PCA, even though you did not use this term. It is exactly PCA if your $X$ is centered; if not, then it is a sort of "uncentered PCA".
In any case, to get from $A$ to
|
Rotating a new matrix into the same basis as another using SVD
What you are doing is essentially PCA, even though you did not use this term. It is exactly PCA if your $X$ is centered; if not, then it is a sort of "uncentered PCA".
In any case, to get from $A$ to $UD$ you need to right-multiply it with $V$: $$AV=UDV^\top V = UD.$$
So to apply the same transformation to $B$, you simply right-multiply it with $V$ too.
If you only need the first $k$ columns, then you right-multiply with $V_k$ which is the matrix of the first $k$ columns of $V$.
|
Rotating a new matrix into the same basis as another using SVD
What you are doing is essentially PCA, even though you did not use this term. It is exactly PCA if your $X$ is centered; if not, then it is a sort of "uncentered PCA".
In any case, to get from $A$ to
|
41,066
|
Recurrent event analysis
|
The main decision to be made is about the time scale that you plan on using. Is it time since the origin of the recurrent event process (like some diagnosis or some intervention, or birth) or is it time between two visits? These two approaches are called calendar time and gap time. As a general rule, what answers one of them does not necessarily answer the other one.
For calendar time, the canonical framework is like this: each individual has a counting process $N(t)$ which denotes the number of visits up to time $t$. The intensity of this process is denoted as $\lambda(t)$ and it has to satisfy certain conditions, but for the most part you can treat it as the hazard function from classical survival analysis. What is commonly done is that you take a form such as $\lambda(t | x_i) = \lambda_0(t) e^{\beta' x_i}$. In this case $t$ is time since origin. For an individual with events at $t_1 < t_2 < ... t_n$ and a followup until $\tau > t_n$, you can estimate a model like that in $R$ by taking
coxph(Surv(tstart, tstop, status) ~ x)
with tstart = c(0, t_1 ... t_n), tstop = c(t_1, ... t_n, tau) and status = c(1, 1, 1 ... 0) and status is 1 for when tstop corresponds to an event and tau corresponds to the end of follow-up. You should also use a +cluster(id) specification in the formula to get the correct standard errors.
The model implies that the number of events in a given period $(t_a, t_b)$ is Poisson distributed with expectation $\int_{t_a}^{t_b} \lambda(t)dt$, analogous to the cumulative hazard. So in some sense it is really easy to answer this kind of questions.
The cool thing is that you can easily incorporate random effects called frailty with the specification +frailty(id). This is used quite often as a variance reduction technique. You can also use it for prediction although that might require a bit more work and thinking.
The second option is to use gap time scale. The gaps would be defined as tstop - tstart from the calendar time case. In this case the model would be something like $\phi(w | x_i) = \phi_0(w) e^{\beta'x_i}$ where $w$ is time since the previous visit. If the gaps for an individual are gaps = c(w_1 ... w_n) then you would fit this as
coxph(Surv(gaps, status) ~ x) again with a +cluster(id) and the status variable as before. Essentially this is the exact same problem as clustered survival data.
The model implies that the individual gets "restarted" after every visit. Hence, it's really easy to predict "survival" probabilities (which would be the probability not to get another visit in some time). You can do some math to see that given that an individual "survived" up to some time, what is the survival conditional on that.
Here you can use the +frailty option to account for individual heterogeneity as well.
It is common to use gap times and include some covariate like previous number of events (or log(previous number of events)), or stratify on the previous number of events so that you get different $\phi_0$'s for the time between the first and the second visit, second and third, etc. Here however you should be able to really defend you choices, as you are de facto altering the time scale of the model.
In general, with the calendar time approach you have quick access to the distribution of the events in a certain time window, and with the gap time scale you have easy access to the distribution of the gaps themselves, but you can not easily get the best of both worlds, at least not in nice closed forms (you can achieve many things by simulation though). The only time when the two coincide is when $\lambda_0$ (or $\phi_0$) is constant. In that case, the number of events in any time interval is Poisson (with the same expectation) and the gaps follow an exponential distribution. This is usually seen as a very strong assumption.
A book that is arguably the best introduction to the analysis of the recurrent events is this one. The authors there emphasise that the decision between which time scale to use may depend a lot on the problem at hand. Their general point seems to be that for incident events, that do not alter the process itself, calendar time is the most useful (like warranty repairs on cars, myocardial infarctions). On the other hand, gap time scales are most useful when you want to predict the time to the next event, and is most natural when at every event the unit of interest has some intervention (like a car repair, or some transplant).
|
Recurrent event analysis
|
The main decision to be made is about the time scale that you plan on using. Is it time since the origin of the recurrent event process (like some diagnosis or some intervention, or birth) or is it ti
|
Recurrent event analysis
The main decision to be made is about the time scale that you plan on using. Is it time since the origin of the recurrent event process (like some diagnosis or some intervention, or birth) or is it time between two visits? These two approaches are called calendar time and gap time. As a general rule, what answers one of them does not necessarily answer the other one.
For calendar time, the canonical framework is like this: each individual has a counting process $N(t)$ which denotes the number of visits up to time $t$. The intensity of this process is denoted as $\lambda(t)$ and it has to satisfy certain conditions, but for the most part you can treat it as the hazard function from classical survival analysis. What is commonly done is that you take a form such as $\lambda(t | x_i) = \lambda_0(t) e^{\beta' x_i}$. In this case $t$ is time since origin. For an individual with events at $t_1 < t_2 < ... t_n$ and a followup until $\tau > t_n$, you can estimate a model like that in $R$ by taking
coxph(Surv(tstart, tstop, status) ~ x)
with tstart = c(0, t_1 ... t_n), tstop = c(t_1, ... t_n, tau) and status = c(1, 1, 1 ... 0) and status is 1 for when tstop corresponds to an event and tau corresponds to the end of follow-up. You should also use a +cluster(id) specification in the formula to get the correct standard errors.
The model implies that the number of events in a given period $(t_a, t_b)$ is Poisson distributed with expectation $\int_{t_a}^{t_b} \lambda(t)dt$, analogous to the cumulative hazard. So in some sense it is really easy to answer this kind of questions.
The cool thing is that you can easily incorporate random effects called frailty with the specification +frailty(id). This is used quite often as a variance reduction technique. You can also use it for prediction although that might require a bit more work and thinking.
The second option is to use gap time scale. The gaps would be defined as tstop - tstart from the calendar time case. In this case the model would be something like $\phi(w | x_i) = \phi_0(w) e^{\beta'x_i}$ where $w$ is time since the previous visit. If the gaps for an individual are gaps = c(w_1 ... w_n) then you would fit this as
coxph(Surv(gaps, status) ~ x) again with a +cluster(id) and the status variable as before. Essentially this is the exact same problem as clustered survival data.
The model implies that the individual gets "restarted" after every visit. Hence, it's really easy to predict "survival" probabilities (which would be the probability not to get another visit in some time). You can do some math to see that given that an individual "survived" up to some time, what is the survival conditional on that.
Here you can use the +frailty option to account for individual heterogeneity as well.
It is common to use gap times and include some covariate like previous number of events (or log(previous number of events)), or stratify on the previous number of events so that you get different $\phi_0$'s for the time between the first and the second visit, second and third, etc. Here however you should be able to really defend you choices, as you are de facto altering the time scale of the model.
In general, with the calendar time approach you have quick access to the distribution of the events in a certain time window, and with the gap time scale you have easy access to the distribution of the gaps themselves, but you can not easily get the best of both worlds, at least not in nice closed forms (you can achieve many things by simulation though). The only time when the two coincide is when $\lambda_0$ (or $\phi_0$) is constant. In that case, the number of events in any time interval is Poisson (with the same expectation) and the gaps follow an exponential distribution. This is usually seen as a very strong assumption.
A book that is arguably the best introduction to the analysis of the recurrent events is this one. The authors there emphasise that the decision between which time scale to use may depend a lot on the problem at hand. Their general point seems to be that for incident events, that do not alter the process itself, calendar time is the most useful (like warranty repairs on cars, myocardial infarctions). On the other hand, gap time scales are most useful when you want to predict the time to the next event, and is most natural when at every event the unit of interest has some intervention (like a car repair, or some transplant).
|
Recurrent event analysis
The main decision to be made is about the time scale that you plan on using. Is it time since the origin of the recurrent event process (like some diagnosis or some intervention, or birth) or is it ti
|
41,067
|
The Frog Riddle - Conditional Probabilities
|
Let's look at the pair of frogs. Male frogs are identified by croaking in the video.
As explained in the video, before we hear any croaking, there are 4 equally likely outcomes given 2 frogs:
Frog 1 is Male, Frog 2 is Male
Frog 1 is Female, Frog 2 is Male
Frog 1 is Male, Frog 2 is Female
Frog 1 is Female, Frog 2 is Female
Making the assumptions about males and females occurring equally and independently, our sample space is $\{(M,M),(F,M),(M,F),(F,F)\}$, and we have probability $1/4$ for each element.
Now, once we hear the croak coming from this pair, we know that at least one frog is male. Thus the event $(F,F)$ is impossible. We then have a new, reduced sample space induced by this condition: $\{(M,M),(F,M),(M,F)\}$. Each remaining possibility is still equally likely, and the probability of all the events added together must be $1$. So the probability of each of these three events in the new sample space must be $1/3$.
The only event that ends badly for us is $(M,M)$, so there is a $2/3$ chance of survival.
More formally, the definition of conditional probability says:
$$P(A|B) = \frac{P(A \cap B)}{P(B)}$$
So if $A$ is the event that at least one female is present and $B$ is the event that at least one male is present, we have:
\begin{align}P(\text{F given at least 1 M}) &= \frac{P(\text{F and at least 1 male})}{P(\text{at least 1 M})}\\
&= \frac{P(\text{1 M and 1 F})}{P(\text{1 M or 2 M})} \\
&= \frac{P[(M,F),(F,M)]}{P[(M,M),(F,M),(M,F)]} \\
&= \frac{1/2}{3/4} = 2/3 \end{align}
This is really the same procedure we reasoned through as above.
|
The Frog Riddle - Conditional Probabilities
|
Let's look at the pair of frogs. Male frogs are identified by croaking in the video.
As explained in the video, before we hear any croaking, there are 4 equally likely outcomes given 2 frogs:
Frog 1
|
The Frog Riddle - Conditional Probabilities
Let's look at the pair of frogs. Male frogs are identified by croaking in the video.
As explained in the video, before we hear any croaking, there are 4 equally likely outcomes given 2 frogs:
Frog 1 is Male, Frog 2 is Male
Frog 1 is Female, Frog 2 is Male
Frog 1 is Male, Frog 2 is Female
Frog 1 is Female, Frog 2 is Female
Making the assumptions about males and females occurring equally and independently, our sample space is $\{(M,M),(F,M),(M,F),(F,F)\}$, and we have probability $1/4$ for each element.
Now, once we hear the croak coming from this pair, we know that at least one frog is male. Thus the event $(F,F)$ is impossible. We then have a new, reduced sample space induced by this condition: $\{(M,M),(F,M),(M,F)\}$. Each remaining possibility is still equally likely, and the probability of all the events added together must be $1$. So the probability of each of these three events in the new sample space must be $1/3$.
The only event that ends badly for us is $(M,M)$, so there is a $2/3$ chance of survival.
More formally, the definition of conditional probability says:
$$P(A|B) = \frac{P(A \cap B)}{P(B)}$$
So if $A$ is the event that at least one female is present and $B$ is the event that at least one male is present, we have:
\begin{align}P(\text{F given at least 1 M}) &= \frac{P(\text{F and at least 1 male})}{P(\text{at least 1 M})}\\
&= \frac{P(\text{1 M and 1 F})}{P(\text{1 M or 2 M})} \\
&= \frac{P[(M,F),(F,M)]}{P[(M,M),(F,M),(M,F)]} \\
&= \frac{1/2}{3/4} = 2/3 \end{align}
This is really the same procedure we reasoned through as above.
|
The Frog Riddle - Conditional Probabilities
Let's look at the pair of frogs. Male frogs are identified by croaking in the video.
As explained in the video, before we hear any croaking, there are 4 equally likely outcomes given 2 frogs:
Frog 1
|
41,068
|
The Frog Riddle - Conditional Probabilities
|
Since the math is already laid out I'll try to provide some intuition. The issue is that knowing that at least one frog is male is different from knowing that any particular frog is male. The former case carries less information and this effectively increases our chances over the latter situation.
Call the frogs left and right, and suppose we are told that the right frog is male. Then we have eliminated two possible events from the sample space: the event where both frogs are female and the event where the left frog is male and the right frog is female. Now the probability truly is one half and it doesn't matter which one we choose. The exact same argument is true if we learn that the left frog is male.
But if we are told only that at least one frog is male, which is what happens when we hear the croak, then we cannot eliminate the event that the left frog is male and the right frog is female. We can only eliminate the event that both are female, which makes the event that at least one is female more likely than the previous setting.
I think the reason why this is confusing is that we naturally think learning that at least one is male should make us disinclined to choose the pair of frogs. It is true that this information makes it less probable that at least one is female, but recognize also that there was a full three quarters chance of at least one female before we learned anything at all. It's the ambiguity of the information we receive which makes it so we should still prefer the two frogs over the one.
|
The Frog Riddle - Conditional Probabilities
|
Since the math is already laid out I'll try to provide some intuition. The issue is that knowing that at least one frog is male is different from knowing that any particular frog is male. The former
|
The Frog Riddle - Conditional Probabilities
Since the math is already laid out I'll try to provide some intuition. The issue is that knowing that at least one frog is male is different from knowing that any particular frog is male. The former case carries less information and this effectively increases our chances over the latter situation.
Call the frogs left and right, and suppose we are told that the right frog is male. Then we have eliminated two possible events from the sample space: the event where both frogs are female and the event where the left frog is male and the right frog is female. Now the probability truly is one half and it doesn't matter which one we choose. The exact same argument is true if we learn that the left frog is male.
But if we are told only that at least one frog is male, which is what happens when we hear the croak, then we cannot eliminate the event that the left frog is male and the right frog is female. We can only eliminate the event that both are female, which makes the event that at least one is female more likely than the previous setting.
I think the reason why this is confusing is that we naturally think learning that at least one is male should make us disinclined to choose the pair of frogs. It is true that this information makes it less probable that at least one is female, but recognize also that there was a full three quarters chance of at least one female before we learned anything at all. It's the ambiguity of the information we receive which makes it so we should still prefer the two frogs over the one.
|
The Frog Riddle - Conditional Probabilities
Since the math is already laid out I'll try to provide some intuition. The issue is that knowing that at least one frog is male is different from knowing that any particular frog is male. The former
|
41,069
|
The Frog Riddle - Conditional Probabilities
|
Your intuition is correct in this case. As the problem is stated your odds of survival are 50%. The video incorrectly states the problem space based on the information we have and therefore comes to an incorrect conclusion. The correct problem space contains 8 conditions and is as follows.
We have two frogs on a log, and one of them has croaked what are our possibilities? (M designates male, F designates female and c designates croaked, first position is left, second position is right)
[
[Mc, M],
[M, Mc],
[Mc, F],
[M, Fc], (X No Male croak)
[Fc, M], (X No Male croak)
[F, Mc],
[Fc, F], (X No Male croak)
[F, Fc], (X No Male croak)
]
Each case is equally likely based on the information that we have, when we eliminate the conditions given the knowledge that a male frog has croaked. We find that there are 4 outcomes to expect. Left male frog croaked next to a right male frog that was silent. Right male frog croaked next to a left male frog that was silent. Or there was a croaking male frog paired with a single female frog in either direction. For an intuitive way to understand this, the two male frogs are twice as likely to croak than the single male frog paired with a female, so we have to weight it appropriately.
You could also divide the search space by croaking frog (C) and non croaking frog (N). Since the croaking frog is 100% a male, you can eliminate it from your search since it has no chance of helping you survive. While the author intended to create a "monty hall problem" they inadvertently created a "boy or girl paradox".
The following questions yield different results:
Given that there is a male what is the likelihood the other is female?
Given that a male frog croaked what is the likelihood the other is female?
I know more information in the second case
https://en.wikipedia.org/wiki/Monty_Hall_problem
https://en.wikipedia.org/wiki/Boy_or_Girl_paradox
|
The Frog Riddle - Conditional Probabilities
|
Your intuition is correct in this case. As the problem is stated your odds of survival are 50%. The video incorrectly states the problem space based on the information we have and therefore comes to a
|
The Frog Riddle - Conditional Probabilities
Your intuition is correct in this case. As the problem is stated your odds of survival are 50%. The video incorrectly states the problem space based on the information we have and therefore comes to an incorrect conclusion. The correct problem space contains 8 conditions and is as follows.
We have two frogs on a log, and one of them has croaked what are our possibilities? (M designates male, F designates female and c designates croaked, first position is left, second position is right)
[
[Mc, M],
[M, Mc],
[Mc, F],
[M, Fc], (X No Male croak)
[Fc, M], (X No Male croak)
[F, Mc],
[Fc, F], (X No Male croak)
[F, Fc], (X No Male croak)
]
Each case is equally likely based on the information that we have, when we eliminate the conditions given the knowledge that a male frog has croaked. We find that there are 4 outcomes to expect. Left male frog croaked next to a right male frog that was silent. Right male frog croaked next to a left male frog that was silent. Or there was a croaking male frog paired with a single female frog in either direction. For an intuitive way to understand this, the two male frogs are twice as likely to croak than the single male frog paired with a female, so we have to weight it appropriately.
You could also divide the search space by croaking frog (C) and non croaking frog (N). Since the croaking frog is 100% a male, you can eliminate it from your search since it has no chance of helping you survive. While the author intended to create a "monty hall problem" they inadvertently created a "boy or girl paradox".
The following questions yield different results:
Given that there is a male what is the likelihood the other is female?
Given that a male frog croaked what is the likelihood the other is female?
I know more information in the second case
https://en.wikipedia.org/wiki/Monty_Hall_problem
https://en.wikipedia.org/wiki/Boy_or_Girl_paradox
|
The Frog Riddle - Conditional Probabilities
Your intuition is correct in this case. As the problem is stated your odds of survival are 50%. The video incorrectly states the problem space based on the information we have and therefore comes to a
|
41,070
|
The Frog Riddle - Conditional Probabilities
|
A clearer answer to this, since the previous was too long and not easy to understand.
The possible outcomes are different, although I used same letters. To make clear the sample space, I will describe the possible outcomes
M M --> "The male is on the left" - "A random male on the right"
M F --> "The male is on the left" - "A random female on the right"
M M --> "The male is on the right" - "A random male on the left"
M F --> "The male is on the right" - "A random female on the left"
|
The Frog Riddle - Conditional Probabilities
|
A clearer answer to this, since the previous was too long and not easy to understand.
The possible outcomes are different, although I used same letters. To make clear the sample space, I will describ
|
The Frog Riddle - Conditional Probabilities
A clearer answer to this, since the previous was too long and not easy to understand.
The possible outcomes are different, although I used same letters. To make clear the sample space, I will describe the possible outcomes
M M --> "The male is on the left" - "A random male on the right"
M F --> "The male is on the left" - "A random female on the right"
M M --> "The male is on the right" - "A random male on the left"
M F --> "The male is on the right" - "A random female on the left"
|
The Frog Riddle - Conditional Probabilities
A clearer answer to this, since the previous was too long and not easy to understand.
The possible outcomes are different, although I used same letters. To make clear the sample space, I will describ
|
41,071
|
The Frog Riddle - Conditional Probabilities
|
The problem I have with this problem, is that the solution seems to be using different rules for what it considers a possible result for the two frogs being male and female, and male and male.
The F/M pair, and the M/F pair, are different because we don't know whether the first frog or the second frog is male, so F/M and M/F are two separate possibilities, even though the result still amounts to "one female frog, one male frog".
But the M/M pair is only considered one possible result, even though the same logic should apply: we don't know which frog is the one that made the croaking sound, so either frog could be the one we heard, and the other one could still be male, it just didn't happen to croak.
|
The Frog Riddle - Conditional Probabilities
|
The problem I have with this problem, is that the solution seems to be using different rules for what it considers a possible result for the two frogs being male and female, and male and male.
The F/M
|
The Frog Riddle - Conditional Probabilities
The problem I have with this problem, is that the solution seems to be using different rules for what it considers a possible result for the two frogs being male and female, and male and male.
The F/M pair, and the M/F pair, are different because we don't know whether the first frog or the second frog is male, so F/M and M/F are two separate possibilities, even though the result still amounts to "one female frog, one male frog".
But the M/M pair is only considered one possible result, even though the same logic should apply: we don't know which frog is the one that made the croaking sound, so either frog could be the one we heard, and the other one could still be male, it just didn't happen to croak.
|
The Frog Riddle - Conditional Probabilities
The problem I have with this problem, is that the solution seems to be using different rules for what it considers a possible result for the two frogs being male and female, and male and male.
The F/M
|
41,072
|
The Frog Riddle - Conditional Probabilities
|
Not knowing anything: $\{(M,M), (M,F), (F,M), (F,F)\}$.
Three pairs with at least one female out of four possible combinations: $3/4$ or $75\%$
Knowing the first one is male: $\{(M,M), (M,F)\}$. One pair with at least one female out of two possible combinations: $1/2$ or $50\%$
Knowing that there is at least one male: $\{(M,M), (M,F), (F,M)\}$. Two pairs with at least one female out of three possible combinations: $2/3$ or $67\%$
|
The Frog Riddle - Conditional Probabilities
|
Not knowing anything: $\{(M,M), (M,F), (F,M), (F,F)\}$.
Three pairs with at least one female out of four possible combinations: $3/4$ or $75\%$
Knowing the first one is male: $\{(M,M), (M,F)\}$. One p
|
The Frog Riddle - Conditional Probabilities
Not knowing anything: $\{(M,M), (M,F), (F,M), (F,F)\}$.
Three pairs with at least one female out of four possible combinations: $3/4$ or $75\%$
Knowing the first one is male: $\{(M,M), (M,F)\}$. One pair with at least one female out of two possible combinations: $1/2$ or $50\%$
Knowing that there is at least one male: $\{(M,M), (M,F), (F,M)\}$. Two pairs with at least one female out of three possible combinations: $2/3$ or $67\%$
|
The Frog Riddle - Conditional Probabilities
Not knowing anything: $\{(M,M), (M,F), (F,M), (F,F)\}$.
Three pairs with at least one female out of four possible combinations: $3/4$ or $75\%$
Knowing the first one is male: $\{(M,M), (M,F)\}$. One p
|
41,073
|
The Frog Riddle - Conditional Probabilities
|
The correct answer is given above by tomciopp and the video is incorrect. I want to elaborate on their answer with a little more to diagnose the video's mistake and give an intuitive illustration or two.
The Video's Mistake
In the video, they conditionalize on the statement "at least one frog is male." However, the information we receive is "there was exactly one croak in the clearing." This statement implies that there is at least one male frog in the clearing, but it is not logically equivalent to it. If exactly one croaked, then at least one is male; however, "if at least one is male, exactly one croaked" is false.
If we conditionalize on the information we receive (instead of a statement which it merely implies) tomciopp's analysis is correct.
An intuitive illustration
Here's an intuitive case to help understand the difference. Suppose I flip two coins and exactly one of them is a penny. Then I ask you "what's the probability that the non-penny is a heads?" The answer is 0.5. It doesn't matter what the penny did. If I add a piece of information like "All the pennies I have ever flipped were heads" that doesn't change one whit your expectation about non-pennies.
In the case of the clearing, we have a croaker (=penny) and a non-croaker (=non-penny.) We also know that croakers are irrelevant to our decisions. 50% of non-croakers are female. The case is symmetric to coins. (This is sort of implied in the problem. Technically, if a frog hasn't croaked for a certain amount of time, I probably start to think it is more likely to be female, since males sometimes croak. In this case, however, we can fairly ignore this since each non-croaking frog has been observed the same about of time, they have the same increasing probability of being female.)
A Different Case
There is a species of toad that prevents mushroom poisoning. Only the females of this species have the necessary secretion to prevent mushroom poisoning. The females of this species do a funny dance whenever there is another female around, but not otherwise.
In this case, the pair is not dancing if and only if at least one is male. Thus, we can conditionalize on "at least one is male" and validly draw the conclusion there is a 2/3 probability of a female in a non-dancing pair.
|
The Frog Riddle - Conditional Probabilities
|
The correct answer is given above by tomciopp and the video is incorrect. I want to elaborate on their answer with a little more to diagnose the video's mistake and give an intuitive illustration or t
|
The Frog Riddle - Conditional Probabilities
The correct answer is given above by tomciopp and the video is incorrect. I want to elaborate on their answer with a little more to diagnose the video's mistake and give an intuitive illustration or two.
The Video's Mistake
In the video, they conditionalize on the statement "at least one frog is male." However, the information we receive is "there was exactly one croak in the clearing." This statement implies that there is at least one male frog in the clearing, but it is not logically equivalent to it. If exactly one croaked, then at least one is male; however, "if at least one is male, exactly one croaked" is false.
If we conditionalize on the information we receive (instead of a statement which it merely implies) tomciopp's analysis is correct.
An intuitive illustration
Here's an intuitive case to help understand the difference. Suppose I flip two coins and exactly one of them is a penny. Then I ask you "what's the probability that the non-penny is a heads?" The answer is 0.5. It doesn't matter what the penny did. If I add a piece of information like "All the pennies I have ever flipped were heads" that doesn't change one whit your expectation about non-pennies.
In the case of the clearing, we have a croaker (=penny) and a non-croaker (=non-penny.) We also know that croakers are irrelevant to our decisions. 50% of non-croakers are female. The case is symmetric to coins. (This is sort of implied in the problem. Technically, if a frog hasn't croaked for a certain amount of time, I probably start to think it is more likely to be female, since males sometimes croak. In this case, however, we can fairly ignore this since each non-croaking frog has been observed the same about of time, they have the same increasing probability of being female.)
A Different Case
There is a species of toad that prevents mushroom poisoning. Only the females of this species have the necessary secretion to prevent mushroom poisoning. The females of this species do a funny dance whenever there is another female around, but not otherwise.
In this case, the pair is not dancing if and only if at least one is male. Thus, we can conditionalize on "at least one is male" and validly draw the conclusion there is a 2/3 probability of a female in a non-dancing pair.
|
The Frog Riddle - Conditional Probabilities
The correct answer is given above by tomciopp and the video is incorrect. I want to elaborate on their answer with a little more to diagnose the video's mistake and give an intuitive illustration or t
|
41,074
|
The Frog Riddle - Conditional Probabilities
|
The issue with considering Mm and mM separately is that there's a 50% chance of Mx and a 50% chance of Cy, where M is male and C is the croaker, but that's only if x is also male. If x is female, then the chances of the first frog being the croaker (i.e. Cy) doubles to 100%, which means the likelihood of that situation (i.e. MF) is also double (compared to Mm).
|
The Frog Riddle - Conditional Probabilities
|
The issue with considering Mm and mM separately is that there's a 50% chance of Mx and a 50% chance of Cy, where M is male and C is the croaker, but that's only if x is also male. If x is female, then
|
The Frog Riddle - Conditional Probabilities
The issue with considering Mm and mM separately is that there's a 50% chance of Mx and a 50% chance of Cy, where M is male and C is the croaker, but that's only if x is also male. If x is female, then the chances of the first frog being the croaker (i.e. Cy) doubles to 100%, which means the likelihood of that situation (i.e. MF) is also double (compared to Mm).
|
The Frog Riddle - Conditional Probabilities
The issue with considering Mm and mM separately is that there's a 50% chance of Mx and a 50% chance of Cy, where M is male and C is the croaker, but that's only if x is also male. If x is female, then
|
41,075
|
The Frog Riddle - Conditional Probabilities
|
Before we hear any croaking, there are 4 equally likely outcomes given 2 frogs:
Frog 1 is Male, Frog 2 is Male
Frog 1 is Female, Frog 2 is Male
Frog 1 is Male, Frog 2 is Female
Frog 1 is Female, Frog 2 is Female
Making the assumptions about males and females occurring equally and independently, our sample space is {(M,M),(F,M),(M,F),(F,F)}, and we have probability 1/4 for each element.
Once we hear the croak coming from this pair, we know that at least one frog is male. This male can equally likely be Frog 1 or Frog 2.
So there are 2 equally likely outcomes for the Frog 1:
Frog 1 is Male
Frog 1 is Random Frog
Making the assumptions about males and females occurring equally and independently, the Random Frog is equally likely to be a Random Male or a Random Female.
P(Frog 1 is Random Male given Frog 1 is Random Frog)=P(Frog 1 is Random Female given Frog 1 is Random Frog)=1/2
P(Frog 1 is Random Male and Frog 1 is Random Frog)=P(Frog 1 is Random Frog)P(Frog 1 is Random Male given Frog 1 is Random Frog)=(1/2)(1/2)=1/4
P(Frog 1 is Random Female and Frog 1 is Random Frog)=P(Frog 1 is Random Frog)P(Frog 1 is Random Female given Frog 1 is Random Frog)=(1/2)(1/2)=1/4
So there are 3 possible outcomes for the Frog 1:
Frog 1 is Male
Frog 1 is Random Male
Frog 1 is Random Female
and probabilities are:
P(Frog 1 is Male)=1/2
P(Frog 1 is Random Male)=1/4
P(Frog 1 is Random Female)=1/4
Now, for each possible outcome for Frog 1, there are 2 possible outcomes for the Frog 2:
Frog 2 is Male
Frog 2 is Random Frog
For each possible outcome for Frog 1, the Random Frog is equally likely to be a Random Male or a Random Female.
So, for each possible outcome for Frog 1, there are 3 possible outcomes for the Frog 2:
Frog 2 is Male
Frog 2 is Random Male
Frog 2 is Random Female
P(Frog 2 is Male given Frog 1 is Male)=0
P(Frog 2 is Male given Frog 1 is Random Male)=1
P(Frog 2 is Male given Frog 1 is Random Female)=1
P(Frog 2 is Random Male given Frog 1 is Male)=1/2
P(Frog 2 is Random Male given Frog 1 is Random Male)=0
P(Frog 2 is Random Male given Frog 1 is Random Female)=0
P(Frog 2 is Random Female given Frog 1 is Male)=1/2
P(Frog 2 is Random Female given Frog 1 is Random Male)=0
P(Frog 2 is Random Female given Frog 1 is Random Female)=0
P(Frog 2 is Random Male and Frog 1 is Male)=P(Frog 1 is Male)P(Frog 2 is Random Male given Frog 1 is Male)=(1/2)(1/2)=1/4
P(Frog 2 is Random Female and Frog 1 is Male)=P(Frog 1 is Male)P(Frog 2 is Random Female given Frog 1 is Male)=(1/2)(1/2)=1/4
P(Frog 2 is Male and Frog 1 is Random Male)=P(Frog 1 is Random Male)*P(Frog 2 is Male given Frog 1 is Random Male)=(1/4)*1=1/4
P(Frog 2 is Male and Frog 1 is Random Female)=P(Frog 1 is Random Female)*P(Frog 2 is Male given Frog 1 is Random Female)=(1/4)*1=1/4
So, our sample space is {(Male,Random Male),(Male,Random Female),(Random Male,Male),(Random Female,Male)}, and we have probability 1/4 for each element.
P(F given at least 1 M)=P(F and at least 1 male)/P(at least 1 M)=P(1 M and 1 F)/P(1 M or 2 M)=P[(Male,Random Female),(Random Female,Male)]/P[(Male,Random Male),(Male,Random Female),(Random Male,Male),(Random Female,Male)]=(1/2)/(4/4)=1/2
|
The Frog Riddle - Conditional Probabilities
|
Before we hear any croaking, there are 4 equally likely outcomes given 2 frogs:
Frog 1 is Male, Frog 2 is Male
Frog 1 is Female, Frog 2 is Male
Frog 1 is Male, Frog 2 is Female
Frog 1 is Female, Frog
|
The Frog Riddle - Conditional Probabilities
Before we hear any croaking, there are 4 equally likely outcomes given 2 frogs:
Frog 1 is Male, Frog 2 is Male
Frog 1 is Female, Frog 2 is Male
Frog 1 is Male, Frog 2 is Female
Frog 1 is Female, Frog 2 is Female
Making the assumptions about males and females occurring equally and independently, our sample space is {(M,M),(F,M),(M,F),(F,F)}, and we have probability 1/4 for each element.
Once we hear the croak coming from this pair, we know that at least one frog is male. This male can equally likely be Frog 1 or Frog 2.
So there are 2 equally likely outcomes for the Frog 1:
Frog 1 is Male
Frog 1 is Random Frog
Making the assumptions about males and females occurring equally and independently, the Random Frog is equally likely to be a Random Male or a Random Female.
P(Frog 1 is Random Male given Frog 1 is Random Frog)=P(Frog 1 is Random Female given Frog 1 is Random Frog)=1/2
P(Frog 1 is Random Male and Frog 1 is Random Frog)=P(Frog 1 is Random Frog)P(Frog 1 is Random Male given Frog 1 is Random Frog)=(1/2)(1/2)=1/4
P(Frog 1 is Random Female and Frog 1 is Random Frog)=P(Frog 1 is Random Frog)P(Frog 1 is Random Female given Frog 1 is Random Frog)=(1/2)(1/2)=1/4
So there are 3 possible outcomes for the Frog 1:
Frog 1 is Male
Frog 1 is Random Male
Frog 1 is Random Female
and probabilities are:
P(Frog 1 is Male)=1/2
P(Frog 1 is Random Male)=1/4
P(Frog 1 is Random Female)=1/4
Now, for each possible outcome for Frog 1, there are 2 possible outcomes for the Frog 2:
Frog 2 is Male
Frog 2 is Random Frog
For each possible outcome for Frog 1, the Random Frog is equally likely to be a Random Male or a Random Female.
So, for each possible outcome for Frog 1, there are 3 possible outcomes for the Frog 2:
Frog 2 is Male
Frog 2 is Random Male
Frog 2 is Random Female
P(Frog 2 is Male given Frog 1 is Male)=0
P(Frog 2 is Male given Frog 1 is Random Male)=1
P(Frog 2 is Male given Frog 1 is Random Female)=1
P(Frog 2 is Random Male given Frog 1 is Male)=1/2
P(Frog 2 is Random Male given Frog 1 is Random Male)=0
P(Frog 2 is Random Male given Frog 1 is Random Female)=0
P(Frog 2 is Random Female given Frog 1 is Male)=1/2
P(Frog 2 is Random Female given Frog 1 is Random Male)=0
P(Frog 2 is Random Female given Frog 1 is Random Female)=0
P(Frog 2 is Random Male and Frog 1 is Male)=P(Frog 1 is Male)P(Frog 2 is Random Male given Frog 1 is Male)=(1/2)(1/2)=1/4
P(Frog 2 is Random Female and Frog 1 is Male)=P(Frog 1 is Male)P(Frog 2 is Random Female given Frog 1 is Male)=(1/2)(1/2)=1/4
P(Frog 2 is Male and Frog 1 is Random Male)=P(Frog 1 is Random Male)*P(Frog 2 is Male given Frog 1 is Random Male)=(1/4)*1=1/4
P(Frog 2 is Male and Frog 1 is Random Female)=P(Frog 1 is Random Female)*P(Frog 2 is Male given Frog 1 is Random Female)=(1/4)*1=1/4
So, our sample space is {(Male,Random Male),(Male,Random Female),(Random Male,Male),(Random Female,Male)}, and we have probability 1/4 for each element.
P(F given at least 1 M)=P(F and at least 1 male)/P(at least 1 M)=P(1 M and 1 F)/P(1 M or 2 M)=P[(Male,Random Female),(Random Female,Male)]/P[(Male,Random Male),(Male,Random Female),(Random Male,Male),(Random Female,Male)]=(1/2)/(4/4)=1/2
|
The Frog Riddle - Conditional Probabilities
Before we hear any croaking, there are 4 equally likely outcomes given 2 frogs:
Frog 1 is Male, Frog 2 is Male
Frog 1 is Female, Frog 2 is Male
Frog 1 is Male, Frog 2 is Female
Frog 1 is Female, Frog
|
41,076
|
Do the principal components change if we apply PCA more than once (recursively) on data?
|
PCA at it's heart involves diagonalizing a matrix which means solving for the eigenvalues and eigenvectors of said matrix. The whole purpose of the calculation is to find a diagonal representation of your matrix (i.e. only elements along the diagonal of the matrix). If you solve again, you will find that you are trying to calculate the eigenvalues of a diagonal matrix, which yields the exact same diagonal matrix. Hence your PC vectors will be the same regardless of how many times you apply the transformation.
|
Do the principal components change if we apply PCA more than once (recursively) on data?
|
PCA at it's heart involves diagonalizing a matrix which means solving for the eigenvalues and eigenvectors of said matrix. The whole purpose of the calculation is to find a diagonal representation of
|
Do the principal components change if we apply PCA more than once (recursively) on data?
PCA at it's heart involves diagonalizing a matrix which means solving for the eigenvalues and eigenvectors of said matrix. The whole purpose of the calculation is to find a diagonal representation of your matrix (i.e. only elements along the diagonal of the matrix). If you solve again, you will find that you are trying to calculate the eigenvalues of a diagonal matrix, which yields the exact same diagonal matrix. Hence your PC vectors will be the same regardless of how many times you apply the transformation.
|
Do the principal components change if we apply PCA more than once (recursively) on data?
PCA at it's heart involves diagonalizing a matrix which means solving for the eigenvalues and eigenvectors of said matrix. The whole purpose of the calculation is to find a diagonal representation of
|
41,077
|
compute 95% confidence interval for predictions using a pooled model after multiple imputation?
|
The t matrix is the one to use in the way you describe. Eqs. 4 through 7 in the Dong & Peng paper that Joe_74 references correspond to the elements of the same names in the mipo object (documentation here), and so t is the accurate variance-covariance matrix for the pooled regression coefficients qbar you're actually using. ubar and b only matter here in that they are/were used to compute t.
Presumably you'll be using more than one predictor, so here's a MWE for that, which should be easy to modify.
set.seed(500)
dat <- data.frame(y = runif(20, 0, .5), x1 = c(runif(15),rep(NA, 5)), x2 = runif(20, 0.5))
imp <- mice(dat)
impMods <- with(imp, lm(y ~ x1 + x2))
pooledMod <- pool(impMods)
# Generate some hypothetical cases we want predictions for
newCases <- data.frame(x1=c(4,7), x2=c(-6,0))
# Tack on the column of 1's for the intercept
newCases <- cbind(1, newCases)
# Generating the actual predictions is simple: sums of values times coefficients
yhats <- rowSums( sweep(newCases, 2, pooledMod$qbar, `*`) )
# Take each new case and perform the standard operation
# with the t matrix to get the pred. err.
predErr <- apply(newCases, 1, function(X) sqrt(t(X) %*% pooledMod$t %*% X))
# Finally, put together a plot-worthy table of predictions with upper and lower bounds
# (I'm just assuming normality here rather than using T-distribution critical values)
results <- data.frame(yhats, lwr=yhats-predErr*1.96, upr=yhats+predErr*1.96)
|
compute 95% confidence interval for predictions using a pooled model after multiple imputation?
|
The t matrix is the one to use in the way you describe. Eqs. 4 through 7 in the Dong & Peng paper that Joe_74 references correspond to the elements of the same names in the mipo object (documentation
|
compute 95% confidence interval for predictions using a pooled model after multiple imputation?
The t matrix is the one to use in the way you describe. Eqs. 4 through 7 in the Dong & Peng paper that Joe_74 references correspond to the elements of the same names in the mipo object (documentation here), and so t is the accurate variance-covariance matrix for the pooled regression coefficients qbar you're actually using. ubar and b only matter here in that they are/were used to compute t.
Presumably you'll be using more than one predictor, so here's a MWE for that, which should be easy to modify.
set.seed(500)
dat <- data.frame(y = runif(20, 0, .5), x1 = c(runif(15),rep(NA, 5)), x2 = runif(20, 0.5))
imp <- mice(dat)
impMods <- with(imp, lm(y ~ x1 + x2))
pooledMod <- pool(impMods)
# Generate some hypothetical cases we want predictions for
newCases <- data.frame(x1=c(4,7), x2=c(-6,0))
# Tack on the column of 1's for the intercept
newCases <- cbind(1, newCases)
# Generating the actual predictions is simple: sums of values times coefficients
yhats <- rowSums( sweep(newCases, 2, pooledMod$qbar, `*`) )
# Take each new case and perform the standard operation
# with the t matrix to get the pred. err.
predErr <- apply(newCases, 1, function(X) sqrt(t(X) %*% pooledMod$t %*% X))
# Finally, put together a plot-worthy table of predictions with upper and lower bounds
# (I'm just assuming normality here rather than using T-distribution critical values)
results <- data.frame(yhats, lwr=yhats-predErr*1.96, upr=yhats+predErr*1.96)
|
compute 95% confidence interval for predictions using a pooled model after multiple imputation?
The t matrix is the one to use in the way you describe. Eqs. 4 through 7 in the Dong & Peng paper that Joe_74 references correspond to the elements of the same names in the mipo object (documentation
|
41,078
|
compute 95% confidence interval for predictions using a pooled model after multiple imputation?
|
I recommend you to simply follow Rubin's rule, as spelled out in page 4 of this paper by Dong and Peng, SpringerPlus 2013:
http://www.ncbi.nlm.nih.gov/pmc/articles/PMC3701793/pdf/40064_2013_Article_296.pdf
Once you have obtained the variance, just proceed to the standard error (square root of the variance), and then use it to build the confidence interval using the t distribution with the correct degrees of freedom.
|
compute 95% confidence interval for predictions using a pooled model after multiple imputation?
|
I recommend you to simply follow Rubin's rule, as spelled out in page 4 of this paper by Dong and Peng, SpringerPlus 2013:
http://www.ncbi.nlm.nih.gov/pmc/articles/PMC3701793/pdf/40064_2013_Article_2
|
compute 95% confidence interval for predictions using a pooled model after multiple imputation?
I recommend you to simply follow Rubin's rule, as spelled out in page 4 of this paper by Dong and Peng, SpringerPlus 2013:
http://www.ncbi.nlm.nih.gov/pmc/articles/PMC3701793/pdf/40064_2013_Article_296.pdf
Once you have obtained the variance, just proceed to the standard error (square root of the variance), and then use it to build the confidence interval using the t distribution with the correct degrees of freedom.
|
compute 95% confidence interval for predictions using a pooled model after multiple imputation?
I recommend you to simply follow Rubin's rule, as spelled out in page 4 of this paper by Dong and Peng, SpringerPlus 2013:
http://www.ncbi.nlm.nih.gov/pmc/articles/PMC3701793/pdf/40064_2013_Article_2
|
41,079
|
compute 95% confidence interval for predictions using a pooled model after multiple imputation?
|
Perhaps something along the lines of extracting each of the fitted models from each of the imputed data sets, invoke predict on each of these and then bootstrap the results. The code below is laughably inefficient but may serve as a starting point for testing the idea. Additionally, there isn't really a need to compute the fitted values as you can obtain these directly from the pooled parameter estimates.
init = mice(df, maxit=0)
meth = init$method
predM = init$predictorMatrix
idat= mice(df, method=meth, predictorMatrix=predM, maxit = 20, m=10)
m1 <- with(idat, glm(adhered ~ age, family = binomial(link = "logit")))
summary(pool(m1))
newdata <- data.frame(age = seq(from = 25, to = 50, by = 1))
predictMI <- function(m, newdata, myseed = 12355){
n.mods <- length(m$analyses)
fit <- list()
se <- list()
for (i in 1:n.mods){
mymod <- m$analyses[[i]]
pred <- predict(mymod,
newdata = newdata,
type = "response",
se = T)
fit[[i]] <- pred$fit
se[[i]] <- pred$se
}
fit <- matrix(unlist(fit), ncol = n.mods, byrow = F)
se <- matrix(unlist(se), ncol = n.mods, byrow = F)
newdata$fit <- NA
newdata$se <- NA
set.seed(myseed)
for (i in 1:nrow(newdata)){
vals.fit <- fit[i,]
vals.se <- se[i,]
boot.res.fit <- vector()
boot.res.se <- vector()
for (j in 1:999){
new.vals <- base::sample(vals.fit, length(vals.fit), replace = T)
boot.res.fit[j] <- mean(new.vals)
new.vals <- base::sample(vals.se, length(vals.se), replace = T)
boot.res.se[j] <- mean(new.vals)
}
newdata$fit[i] <- mean(boot.res.fit)
newdata$se[i] <- mean(boot.res.se)
}
newdata$lwr <- newdata$fit - 1.96 * newdata$se
newdata$upr <- newdata$fit + 1.96 * newdata$se
newdata
}
Alternatively:
newdata <- data.frame(intercept = 1, age = seq(from = 25, to = 50, by = 1))
newdata <- as.matrix(newdata)
p1 <- pool(m1)
coefs <- p1$qbar
sigma <- p1$ubar
std.err <- vector()
for (i in 1:nrow(newdata)){
C <- as.numeric(newdata[i,])
std.err[i] <- sqrt(t(C) %*% sigma %*% C)
}
mu <- newdata %*% matrix(coefs, ncol = 1)
invlogit <- function (x) {1/(1+exp(-x))}
newdata <- data.frame(newdata)
newdata$fit <- as.numeric(invlogit(mu))
newdata$lwr <- as.numeric(invlogit(mu - 1.96*std.err))
newdata$upr <- as.numeric(invlogit(mu + 1.96*std.err))
ggplot(data = newdata, aes(x = age, y = fit)) +
geom_line() +
geom_line(data = tes, aes(x = age, y = lwr), linetype = 2) +
geom_line(data = tes, aes(x = age, y = upr), linetype = 2) +
ylim(c(0,1))
|
compute 95% confidence interval for predictions using a pooled model after multiple imputation?
|
Perhaps something along the lines of extracting each of the fitted models from each of the imputed data sets, invoke predict on each of these and then bootstrap the results. The code below is laughabl
|
compute 95% confidence interval for predictions using a pooled model after multiple imputation?
Perhaps something along the lines of extracting each of the fitted models from each of the imputed data sets, invoke predict on each of these and then bootstrap the results. The code below is laughably inefficient but may serve as a starting point for testing the idea. Additionally, there isn't really a need to compute the fitted values as you can obtain these directly from the pooled parameter estimates.
init = mice(df, maxit=0)
meth = init$method
predM = init$predictorMatrix
idat= mice(df, method=meth, predictorMatrix=predM, maxit = 20, m=10)
m1 <- with(idat, glm(adhered ~ age, family = binomial(link = "logit")))
summary(pool(m1))
newdata <- data.frame(age = seq(from = 25, to = 50, by = 1))
predictMI <- function(m, newdata, myseed = 12355){
n.mods <- length(m$analyses)
fit <- list()
se <- list()
for (i in 1:n.mods){
mymod <- m$analyses[[i]]
pred <- predict(mymod,
newdata = newdata,
type = "response",
se = T)
fit[[i]] <- pred$fit
se[[i]] <- pred$se
}
fit <- matrix(unlist(fit), ncol = n.mods, byrow = F)
se <- matrix(unlist(se), ncol = n.mods, byrow = F)
newdata$fit <- NA
newdata$se <- NA
set.seed(myseed)
for (i in 1:nrow(newdata)){
vals.fit <- fit[i,]
vals.se <- se[i,]
boot.res.fit <- vector()
boot.res.se <- vector()
for (j in 1:999){
new.vals <- base::sample(vals.fit, length(vals.fit), replace = T)
boot.res.fit[j] <- mean(new.vals)
new.vals <- base::sample(vals.se, length(vals.se), replace = T)
boot.res.se[j] <- mean(new.vals)
}
newdata$fit[i] <- mean(boot.res.fit)
newdata$se[i] <- mean(boot.res.se)
}
newdata$lwr <- newdata$fit - 1.96 * newdata$se
newdata$upr <- newdata$fit + 1.96 * newdata$se
newdata
}
Alternatively:
newdata <- data.frame(intercept = 1, age = seq(from = 25, to = 50, by = 1))
newdata <- as.matrix(newdata)
p1 <- pool(m1)
coefs <- p1$qbar
sigma <- p1$ubar
std.err <- vector()
for (i in 1:nrow(newdata)){
C <- as.numeric(newdata[i,])
std.err[i] <- sqrt(t(C) %*% sigma %*% C)
}
mu <- newdata %*% matrix(coefs, ncol = 1)
invlogit <- function (x) {1/(1+exp(-x))}
newdata <- data.frame(newdata)
newdata$fit <- as.numeric(invlogit(mu))
newdata$lwr <- as.numeric(invlogit(mu - 1.96*std.err))
newdata$upr <- as.numeric(invlogit(mu + 1.96*std.err))
ggplot(data = newdata, aes(x = age, y = fit)) +
geom_line() +
geom_line(data = tes, aes(x = age, y = lwr), linetype = 2) +
geom_line(data = tes, aes(x = age, y = upr), linetype = 2) +
ylim(c(0,1))
|
compute 95% confidence interval for predictions using a pooled model after multiple imputation?
Perhaps something along the lines of extracting each of the fitted models from each of the imputed data sets, invoke predict on each of these and then bootstrap the results. The code below is laughabl
|
41,080
|
Probability of failure in a finite population
|
Suppose you sample $n$ members from a population of $N$ (without replacement) and $k$ of them are failures. The definition of confidence tells us to ask this question:
If there are $K$ failures in the population, what is the chance we observe $k$ or fewer failures in the sample?
Without going into the combinatorial details, let's just call this number $p(k,K;n,N)$. It can be used to establish upper confidence limits on $K$ through a form of logical inversion. Let $N$ and $n$ both be known and $\alpha$ be a specified probability. If $K^\prime$ is so large that $p(k,K^\prime;n,N) \lt \alpha$, then it is unlikely we would have observed $k$ or fewer failures in the first place. This gives us confidence that the true number of failures, $K$, is strictly less than $K^\prime$.
Pushing this reasoning to its natural limit, we therefore seek the smallest value $K^\prime$ for which $p(k, K^\prime; n, N) \lt \alpha$. We will use $K^\prime - 1$ for the $1-\alpha$ upper confidence limit on $K$. Equivalently we could maximize the value $K^{\prime\prime}$ for which $p(k, K^{\prime\prime}; n, N) \ge \alpha$:
$$\operatorname{UCL}_\alpha(k) = \max\{K\,|\, p(k, K; n, N) \ge \alpha\}.\tag{1}$$
Now for the details. The chance of observing exactly $k$ failures is the chance that (a) our $n$-element sample contains those $k$ failures and (b) the remaining $N-n$ members of the population contain the remaining $K-k$ failures. This describes $\binom{K}{k} \binom{N-K}{n-k}$ subsets out of $\binom{N}{n}$ equally likely subsets. Summing these for all values from $k=0$ to $k$ equal to the actual number of observed failures gives
$$p(k,K;n,N) = \frac{1}{\binom{N}{n}}\sum_{j=0}^k \binom{K}{j} \binom{N-K}{n-j}.$$
This is the Hypergeometric distribution.
In R, for instance, the parameters to supply to the Hypergeometric functions are $N-K$ (called m on the manual page), $K$, (n), and $n$ (k). The phyper function implements $p$ and the qhyper function implements its inverse.
Take, for example, a case of a population with $N=8$ elements from which a sample of size $n=4$ is drawn and $k=1$ failure is observed. Then
$$p(3, K, 4, 8) = \frac{1}{\binom{8}{4}}\sum_{j=0}^1 \binom{K}{j}\binom{8-K}{4-j} = \frac{1}{70}\left(\binom{8-K}{4} + K\binom{8-K}{3}\right).$$
The possible values of $K$ range from a minimum of $k=1$ (the one failure observed) to $k = k + (N-n) = 5$ (occurring when every non-observed member of the population is a failure). Plugging these values into the preceding equation gives the sequence
$$(70, 55, 35, 17, 5)/70 \approx (100, 79, 50, 24, 7)/100.$$
R will compute them in one stroke as
phyper(1, 1:5, 8-(1:5), 4)
We read these numbers like this:
There is $100\%$ confidence the population has at least $K=1$ failure. (We have seen it.)
There is $79\%$ confidence the population has at least $K=2$ failures. In other words, we attach high confidence to the existence of at least one more failure in the $N-n=4$ members not observed.
There is $50\%$ confidence the population has at least $K=3$ failures. This may seem counter-intuitive: since we have seen half the population and observed $k=1$ failure, shouldn't we assign exactly $1/2=50\%$ confidence to seeing one more failure in the other half of the population? This is where confidence differs from probability. The correct approach asks this question: when there are $K=3$ failures in the population (of size $N=8$) and we sample half of it, what is the chance we will see just zero or one failures? By symmetry--the unsampled members themselves constitute a random sample of $N-n=4$, too--this is the chance that the remaining unsampled members will consist of just zero or one failures. Thus observing zero or one failures out of three in the population is an event that will occur half the time. Consequently, actually observing one failure is perfectly consistent with the presence of three failures total.
There is $24\%$ confidence the population has at least $K=4$ failures and $7\%$ confidence it has at least $K=5$ failures. These numbers are starting to get close to typical values of $\alpha$. For instance, with $\alpha=0.10$ the $90\%$ upper confidence limit for $K$ would be $K=4$. But with $\alpha=0.05$ the upper $95\%$ UCL for $K$ is $K=5$. When we observe one failure out of four, in a sample from a population of eight, there is an appreciable risk that all the unsampled members are failures! This is because when five of eight members are failures, there's still a considerable chance--more than $7\%$--that our sample just happens to include all three successes.
Note that qhyper in R does not compute confidence limits. You need to search, just as we did in this example. A brute-force search (but relatively efficient for R) tests all the values, as in
which(phyper(1, 1:5, 8-(1:5), 4) >= .10)
This command returns the indexes 1 2 3 4, showing that the first four elements of the vector 1:5 (representing the possible values of $K$) are consistent with our observations at the $\alpha=0.10$ level. The largest of those, $4$, corresponds to $K=4$ as we found through inspection.
In the example of the question, a sample of size $n=100$ is taken from a population of $N=500$ and $k=3$ failures are observed. What is a $90\%$ upper confidence limit for the total number of failures $K$? The R search is
`max(which(phyper(3, 1:100, 500-(1:100), 100) >= .10))`
(The correspondence between this and the mathematical formula for the UCL in $(1)$ is evident.)
It returns a UCL of $30$. Let's double-check by computing the probabilities $p(3,30;100,500)$ and $p(3,31;100,500)$. The first should exceed $10\%$ and the second should drop just below it:
> phyper(3, 30, 500-30, 100)
[1] 0.1151626
> phyper(3, 31, 500-31, 100)
[1] 0.09959309
That's exactly what happens. We conclude, with at least $90\%$ confidence, that there exist up to (but no more than) $K-k=30-3=27$ additional failures among the $N-n=500-100=400$ unsampled members of the population.
|
Probability of failure in a finite population
|
Suppose you sample $n$ members from a population of $N$ (without replacement) and $k$ of them are failures. The definition of confidence tells us to ask this question:
If there are $K$ failures in t
|
Probability of failure in a finite population
Suppose you sample $n$ members from a population of $N$ (without replacement) and $k$ of them are failures. The definition of confidence tells us to ask this question:
If there are $K$ failures in the population, what is the chance we observe $k$ or fewer failures in the sample?
Without going into the combinatorial details, let's just call this number $p(k,K;n,N)$. It can be used to establish upper confidence limits on $K$ through a form of logical inversion. Let $N$ and $n$ both be known and $\alpha$ be a specified probability. If $K^\prime$ is so large that $p(k,K^\prime;n,N) \lt \alpha$, then it is unlikely we would have observed $k$ or fewer failures in the first place. This gives us confidence that the true number of failures, $K$, is strictly less than $K^\prime$.
Pushing this reasoning to its natural limit, we therefore seek the smallest value $K^\prime$ for which $p(k, K^\prime; n, N) \lt \alpha$. We will use $K^\prime - 1$ for the $1-\alpha$ upper confidence limit on $K$. Equivalently we could maximize the value $K^{\prime\prime}$ for which $p(k, K^{\prime\prime}; n, N) \ge \alpha$:
$$\operatorname{UCL}_\alpha(k) = \max\{K\,|\, p(k, K; n, N) \ge \alpha\}.\tag{1}$$
Now for the details. The chance of observing exactly $k$ failures is the chance that (a) our $n$-element sample contains those $k$ failures and (b) the remaining $N-n$ members of the population contain the remaining $K-k$ failures. This describes $\binom{K}{k} \binom{N-K}{n-k}$ subsets out of $\binom{N}{n}$ equally likely subsets. Summing these for all values from $k=0$ to $k$ equal to the actual number of observed failures gives
$$p(k,K;n,N) = \frac{1}{\binom{N}{n}}\sum_{j=0}^k \binom{K}{j} \binom{N-K}{n-j}.$$
This is the Hypergeometric distribution.
In R, for instance, the parameters to supply to the Hypergeometric functions are $N-K$ (called m on the manual page), $K$, (n), and $n$ (k). The phyper function implements $p$ and the qhyper function implements its inverse.
Take, for example, a case of a population with $N=8$ elements from which a sample of size $n=4$ is drawn and $k=1$ failure is observed. Then
$$p(3, K, 4, 8) = \frac{1}{\binom{8}{4}}\sum_{j=0}^1 \binom{K}{j}\binom{8-K}{4-j} = \frac{1}{70}\left(\binom{8-K}{4} + K\binom{8-K}{3}\right).$$
The possible values of $K$ range from a minimum of $k=1$ (the one failure observed) to $k = k + (N-n) = 5$ (occurring when every non-observed member of the population is a failure). Plugging these values into the preceding equation gives the sequence
$$(70, 55, 35, 17, 5)/70 \approx (100, 79, 50, 24, 7)/100.$$
R will compute them in one stroke as
phyper(1, 1:5, 8-(1:5), 4)
We read these numbers like this:
There is $100\%$ confidence the population has at least $K=1$ failure. (We have seen it.)
There is $79\%$ confidence the population has at least $K=2$ failures. In other words, we attach high confidence to the existence of at least one more failure in the $N-n=4$ members not observed.
There is $50\%$ confidence the population has at least $K=3$ failures. This may seem counter-intuitive: since we have seen half the population and observed $k=1$ failure, shouldn't we assign exactly $1/2=50\%$ confidence to seeing one more failure in the other half of the population? This is where confidence differs from probability. The correct approach asks this question: when there are $K=3$ failures in the population (of size $N=8$) and we sample half of it, what is the chance we will see just zero or one failures? By symmetry--the unsampled members themselves constitute a random sample of $N-n=4$, too--this is the chance that the remaining unsampled members will consist of just zero or one failures. Thus observing zero or one failures out of three in the population is an event that will occur half the time. Consequently, actually observing one failure is perfectly consistent with the presence of three failures total.
There is $24\%$ confidence the population has at least $K=4$ failures and $7\%$ confidence it has at least $K=5$ failures. These numbers are starting to get close to typical values of $\alpha$. For instance, with $\alpha=0.10$ the $90\%$ upper confidence limit for $K$ would be $K=4$. But with $\alpha=0.05$ the upper $95\%$ UCL for $K$ is $K=5$. When we observe one failure out of four, in a sample from a population of eight, there is an appreciable risk that all the unsampled members are failures! This is because when five of eight members are failures, there's still a considerable chance--more than $7\%$--that our sample just happens to include all three successes.
Note that qhyper in R does not compute confidence limits. You need to search, just as we did in this example. A brute-force search (but relatively efficient for R) tests all the values, as in
which(phyper(1, 1:5, 8-(1:5), 4) >= .10)
This command returns the indexes 1 2 3 4, showing that the first four elements of the vector 1:5 (representing the possible values of $K$) are consistent with our observations at the $\alpha=0.10$ level. The largest of those, $4$, corresponds to $K=4$ as we found through inspection.
In the example of the question, a sample of size $n=100$ is taken from a population of $N=500$ and $k=3$ failures are observed. What is a $90\%$ upper confidence limit for the total number of failures $K$? The R search is
`max(which(phyper(3, 1:100, 500-(1:100), 100) >= .10))`
(The correspondence between this and the mathematical formula for the UCL in $(1)$ is evident.)
It returns a UCL of $30$. Let's double-check by computing the probabilities $p(3,30;100,500)$ and $p(3,31;100,500)$. The first should exceed $10\%$ and the second should drop just below it:
> phyper(3, 30, 500-30, 100)
[1] 0.1151626
> phyper(3, 31, 500-31, 100)
[1] 0.09959309
That's exactly what happens. We conclude, with at least $90\%$ confidence, that there exist up to (but no more than) $K-k=30-3=27$ additional failures among the $N-n=500-100=400$ unsampled members of the population.
|
Probability of failure in a finite population
Suppose you sample $n$ members from a population of $N$ (without replacement) and $k$ of them are failures. The definition of confidence tells us to ask this question:
If there are $K$ failures in t
|
41,081
|
Random Forest Learning Curve
|
I suspect you have trained a series of RF regression models and have plotted explained variance(not error) against training set size. Explained variance is the opposite than a error. The value would be between 0 and 1.
Secondly it does not make much sense to diagnose training explained accuracy for a random forest. Samples take the same paths through the trees when training and predicting, so of course a near perfect fit is obtained. That is why out-of-bag training accuracy/error is used.
The cross-validated score increases a little because more samples both lowers bias(deeper trees + denser sampling from data structure) and lowers variance(decreased tree correlation + less sample error).
So everything looks ok and you probably neither have overly over- nor underfitting. I would prefer to (a) simply plot OOB-CV against different settings of hyperparameters or (b) wrap the model in a repeated nested-CV grid search, if you wanna be really thorough. You will probably find the default parameters are close to optimal.
|
Random Forest Learning Curve
|
I suspect you have trained a series of RF regression models and have plotted explained variance(not error) against training set size. Explained variance is the opposite than a error. The value would b
|
Random Forest Learning Curve
I suspect you have trained a series of RF regression models and have plotted explained variance(not error) against training set size. Explained variance is the opposite than a error. The value would be between 0 and 1.
Secondly it does not make much sense to diagnose training explained accuracy for a random forest. Samples take the same paths through the trees when training and predicting, so of course a near perfect fit is obtained. That is why out-of-bag training accuracy/error is used.
The cross-validated score increases a little because more samples both lowers bias(deeper trees + denser sampling from data structure) and lowers variance(decreased tree correlation + less sample error).
So everything looks ok and you probably neither have overly over- nor underfitting. I would prefer to (a) simply plot OOB-CV against different settings of hyperparameters or (b) wrap the model in a repeated nested-CV grid search, if you wanna be really thorough. You will probably find the default parameters are close to optimal.
|
Random Forest Learning Curve
I suspect you have trained a series of RF regression models and have plotted explained variance(not error) against training set size. Explained variance is the opposite than a error. The value would b
|
41,082
|
How can I control for a variable while conducting Wilcoxon Rank Sum Test?
|
The generalization of the Wilcoxon-Mann-Whitney 2-sample test and the Kruskal-Wallis $k$-sample test is the proportional odds model. The PO model allows all the modeling flexibility that regression models support, including covariate adjustment. Details may be found in my course notes.
|
How can I control for a variable while conducting Wilcoxon Rank Sum Test?
|
The generalization of the Wilcoxon-Mann-Whitney 2-sample test and the Kruskal-Wallis $k$-sample test is the proportional odds model. The PO model allows all the modeling flexibility that regression m
|
How can I control for a variable while conducting Wilcoxon Rank Sum Test?
The generalization of the Wilcoxon-Mann-Whitney 2-sample test and the Kruskal-Wallis $k$-sample test is the proportional odds model. The PO model allows all the modeling flexibility that regression models support, including covariate adjustment. Details may be found in my course notes.
|
How can I control for a variable while conducting Wilcoxon Rank Sum Test?
The generalization of the Wilcoxon-Mann-Whitney 2-sample test and the Kruskal-Wallis $k$-sample test is the proportional odds model. The PO model allows all the modeling flexibility that regression m
|
41,083
|
Why is K-Means++ SLOWER than random initialization K-Means?
|
kmeans in R is pretty good Fortran code.
I haven't looked at the package you got kmeanspp from, but I wouldn't expect it to be of the same quality. If it uses R code to do the initialization that can hurt badly.
So in the end, you haven't been benchmarking kmeans vs. kmeans++, but you have been showing that the quality of R packages varies a lot, and the R interpreter is substantially slower than Fortran/C/C++ functions, and you therefore cannot rely on such benchmarks.
The low performance of flexclust is probably because it uses even more R code?
|
Why is K-Means++ SLOWER than random initialization K-Means?
|
kmeans in R is pretty good Fortran code.
I haven't looked at the package you got kmeanspp from, but I wouldn't expect it to be of the same quality. If it uses R code to do the initialization that can
|
Why is K-Means++ SLOWER than random initialization K-Means?
kmeans in R is pretty good Fortran code.
I haven't looked at the package you got kmeanspp from, but I wouldn't expect it to be of the same quality. If it uses R code to do the initialization that can hurt badly.
So in the end, you haven't been benchmarking kmeans vs. kmeans++, but you have been showing that the quality of R packages varies a lot, and the R interpreter is substantially slower than Fortran/C/C++ functions, and you therefore cannot rely on such benchmarks.
The low performance of flexclust is probably because it uses even more R code?
|
Why is K-Means++ SLOWER than random initialization K-Means?
kmeans in R is pretty good Fortran code.
I haven't looked at the package you got kmeanspp from, but I wouldn't expect it to be of the same quality. If it uses R code to do the initialization that can
|
41,084
|
Why is K-Means++ SLOWER than random initialization K-Means?
|
Why is K-Means++ SLOWER than random initialization K-Means?
I would argue that it depends. First recall the difference between the two:
K-means ++
K-means++ involves a somewhat intensive initialization step where:
Choose on center uniformly at random among the data points
For each data point, compute the distance $D(x)$ between $x$ and the nearest center that has already been chosen
Choose one new data point at random as a new center, using a weighted probability distribution where a point $x$ is chosen with probability proportional to $D(x)^2$
Repeat the above steps until $k$ centers have been chosen
Proceed with standard $k$-means
K-means
Jump straight here --> Randomly initialize $k$ centers
Repeat until convergence:
For every obervation $i$, assign it to the closest cluster center:
$$ c^{(i)} := \arg min_{j} \ || x^{(i)} - \mu_j ||^2_2$$
For every cluster $j$, update its value as the mean of assigned observations
$$ \mu_j := \frac{\sum_{i=1}^m \mathcal{I}\{ c^{(i)} = j\} x^{(i)} }{\sum_{i=1}^m \mathcal{I}\{ c^{(i)} = j\}} $$
An intuitive interpretation of relative speeds
Steps 2 and 3 involve computing the euclidean distance between all points $k$ times before the actual algorithm even starts. It must also calculate the proportional probabilities for each point, and implementations often add an inner loop which performs "trials" and selects the best result. All these steps are performed across the entire dataset, which can be quite slow.
On the other hand, where k-means++ gains in speed is in the convergence of step 6. But that is dependent on the structure of your dataset, not necessarily on its size.
See here for the Sklearn implementation - around lines 100
|
Why is K-Means++ SLOWER than random initialization K-Means?
|
Why is K-Means++ SLOWER than random initialization K-Means?
I would argue that it depends. First recall the difference between the two:
K-means ++
K-means++ involves a somewhat intensive initializati
|
Why is K-Means++ SLOWER than random initialization K-Means?
Why is K-Means++ SLOWER than random initialization K-Means?
I would argue that it depends. First recall the difference between the two:
K-means ++
K-means++ involves a somewhat intensive initialization step where:
Choose on center uniformly at random among the data points
For each data point, compute the distance $D(x)$ between $x$ and the nearest center that has already been chosen
Choose one new data point at random as a new center, using a weighted probability distribution where a point $x$ is chosen with probability proportional to $D(x)^2$
Repeat the above steps until $k$ centers have been chosen
Proceed with standard $k$-means
K-means
Jump straight here --> Randomly initialize $k$ centers
Repeat until convergence:
For every obervation $i$, assign it to the closest cluster center:
$$ c^{(i)} := \arg min_{j} \ || x^{(i)} - \mu_j ||^2_2$$
For every cluster $j$, update its value as the mean of assigned observations
$$ \mu_j := \frac{\sum_{i=1}^m \mathcal{I}\{ c^{(i)} = j\} x^{(i)} }{\sum_{i=1}^m \mathcal{I}\{ c^{(i)} = j\}} $$
An intuitive interpretation of relative speeds
Steps 2 and 3 involve computing the euclidean distance between all points $k$ times before the actual algorithm even starts. It must also calculate the proportional probabilities for each point, and implementations often add an inner loop which performs "trials" and selects the best result. All these steps are performed across the entire dataset, which can be quite slow.
On the other hand, where k-means++ gains in speed is in the convergence of step 6. But that is dependent on the structure of your dataset, not necessarily on its size.
See here for the Sklearn implementation - around lines 100
|
Why is K-Means++ SLOWER than random initialization K-Means?
Why is K-Means++ SLOWER than random initialization K-Means?
I would argue that it depends. First recall the difference between the two:
K-means ++
K-means++ involves a somewhat intensive initializati
|
41,085
|
Dirichlet Prior for Multinomial
|
I do not think this has anything to do with a wrong definition of the Dirichlet prior or posterior: simply, when
$$(x_1,\ldots,x_k)\sim\mathcal{D}(\alpha_1,...,\alpha_k)$$
the mean is given by
$$\mathbb{E}[(x_1,\ldots,x_k)]=\dfrac{(\alpha_1,...,\alpha_k)}{\sum_{i=1}^k\alpha_i}$$
which explains for the discrepancy with the MLE.
>c(11.,4.,5.)/sum(c(11.,4.,5.))
[1] 0.55 0.20 0.25
> c(10.,3.,4.)/sum(c(10.,3.,4.))
[1] 0.5882353 0.1764706 0.2352941
If instead you use the mode of the Dirichlet distribution,
$$(x_1^\text{mode},\ldots,x_k^\text{mode})=\dfrac{(\alpha_1-1,...,\alpha_k-1)}{\sum_{i=1}^k\alpha_i-k}$$
which recovers the MLE. And this makes complete sense because the MAP is the MLE under a flat prior.
|
Dirichlet Prior for Multinomial
|
I do not think this has anything to do with a wrong definition of the Dirichlet prior or posterior: simply, when
$$(x_1,\ldots,x_k)\sim\mathcal{D}(\alpha_1,...,\alpha_k)$$
the mean is given by
$$\math
|
Dirichlet Prior for Multinomial
I do not think this has anything to do with a wrong definition of the Dirichlet prior or posterior: simply, when
$$(x_1,\ldots,x_k)\sim\mathcal{D}(\alpha_1,...,\alpha_k)$$
the mean is given by
$$\mathbb{E}[(x_1,\ldots,x_k)]=\dfrac{(\alpha_1,...,\alpha_k)}{\sum_{i=1}^k\alpha_i}$$
which explains for the discrepancy with the MLE.
>c(11.,4.,5.)/sum(c(11.,4.,5.))
[1] 0.55 0.20 0.25
> c(10.,3.,4.)/sum(c(10.,3.,4.))
[1] 0.5882353 0.1764706 0.2352941
If instead you use the mode of the Dirichlet distribution,
$$(x_1^\text{mode},\ldots,x_k^\text{mode})=\dfrac{(\alpha_1-1,...,\alpha_k-1)}{\sum_{i=1}^k\alpha_i-k}$$
which recovers the MLE. And this makes complete sense because the MAP is the MLE under a flat prior.
|
Dirichlet Prior for Multinomial
I do not think this has anything to do with a wrong definition of the Dirichlet prior or posterior: simply, when
$$(x_1,\ldots,x_k)\sim\mathcal{D}(\alpha_1,...,\alpha_k)$$
the mean is given by
$$\math
|
41,086
|
Why doesn't gradient descent terminate on saddle point?
|
This answer will only consider asymptotic outcomes, that is, whether we get stuck after infinite number of iterations. We will also only consider the classical gradient descent with zero noise. Noisy variants of GD such as SGD always have a non-zero probability of randomly making several consecutive steps away from the equilibrium, so they never really get asymptotically stuck. While asymptotic convergence of classical GD definitely is related to the performance / convergence rate of SGD, I think that optimization of SGD vastly exceeds the scope of the original question.
We will consider the probability of getting stuck in an unstable equilibrium, that is a saddle point or a maximum. We will define unstable equilibria by having zero gradients and a Hessian matrix that is not positive definite.
It is effectively impossible to get stuck in the unstable equillibrium point itself. It is easy to see that a point or a line in 2D have zero area, so the probability of landing on those is zero unless the starting point is fine-tuned.
To finish the analysis of classical GD, it remains to see if one can construct an unstable equillibrium whose basin of attraction has non-zero area/hypervolume of the same dimension as the domain, which would make the probability of landing there from a random init point non-zero. Consider a weird saddle point with the following gradient
$$ f'_x = x\cdot \mathrm{sign}(xy) $$
$$ f'_y = y\cdot \mathrm{sign}(xy) $$
While the sign function may be a bit unrealistic, the same argument holds if we replace it with a sigmoid. If we consider the plot of this gradient (arrows are normalized, because in asymptotic analysis we only care about direction, not magnitude)
we find that its basin of attraction (yellow) has nonzero area. With this particular arrangement, it is possible and likely to get stuck forever with classical GD
|
Why doesn't gradient descent terminate on saddle point?
|
This answer will only consider asymptotic outcomes, that is, whether we get stuck after infinite number of iterations. We will also only consider the classical gradient descent with zero noise. Noisy
|
Why doesn't gradient descent terminate on saddle point?
This answer will only consider asymptotic outcomes, that is, whether we get stuck after infinite number of iterations. We will also only consider the classical gradient descent with zero noise. Noisy variants of GD such as SGD always have a non-zero probability of randomly making several consecutive steps away from the equilibrium, so they never really get asymptotically stuck. While asymptotic convergence of classical GD definitely is related to the performance / convergence rate of SGD, I think that optimization of SGD vastly exceeds the scope of the original question.
We will consider the probability of getting stuck in an unstable equilibrium, that is a saddle point or a maximum. We will define unstable equilibria by having zero gradients and a Hessian matrix that is not positive definite.
It is effectively impossible to get stuck in the unstable equillibrium point itself. It is easy to see that a point or a line in 2D have zero area, so the probability of landing on those is zero unless the starting point is fine-tuned.
To finish the analysis of classical GD, it remains to see if one can construct an unstable equillibrium whose basin of attraction has non-zero area/hypervolume of the same dimension as the domain, which would make the probability of landing there from a random init point non-zero. Consider a weird saddle point with the following gradient
$$ f'_x = x\cdot \mathrm{sign}(xy) $$
$$ f'_y = y\cdot \mathrm{sign}(xy) $$
While the sign function may be a bit unrealistic, the same argument holds if we replace it with a sigmoid. If we consider the plot of this gradient (arrows are normalized, because in asymptotic analysis we only care about direction, not magnitude)
we find that its basin of attraction (yellow) has nonzero area. With this particular arrangement, it is possible and likely to get stuck forever with classical GD
|
Why doesn't gradient descent terminate on saddle point?
This answer will only consider asymptotic outcomes, that is, whether we get stuck after infinite number of iterations. We will also only consider the classical gradient descent with zero noise. Noisy
|
41,087
|
Why doesn't gradient descent terminate on saddle point?
|
Old gradient descent will terminate once it touch a point with derivative zero. And so also will terminate in a saddle if the derivative is zero. But in the everyday gradient descent (stochastic) it's pretty hard or almost impossible to terminate in maximum or saddle, because those aren't points with stable equilibrium, in the sense that the Hessian matrix of the function isn't definite positive.
|
Why doesn't gradient descent terminate on saddle point?
|
Old gradient descent will terminate once it touch a point with derivative zero. And so also will terminate in a saddle if the derivative is zero. But in the everyday gradient descent (stochastic) it's
|
Why doesn't gradient descent terminate on saddle point?
Old gradient descent will terminate once it touch a point with derivative zero. And so also will terminate in a saddle if the derivative is zero. But in the everyday gradient descent (stochastic) it's pretty hard or almost impossible to terminate in maximum or saddle, because those aren't points with stable equilibrium, in the sense that the Hessian matrix of the function isn't definite positive.
|
Why doesn't gradient descent terminate on saddle point?
Old gradient descent will terminate once it touch a point with derivative zero. And so also will terminate in a saddle if the derivative is zero. But in the everyday gradient descent (stochastic) it's
|
41,088
|
Why doesn't gradient descent terminate on saddle point?
|
Gradient descent can indeed converge to a saddle point, given a worst case initialization (Nesterov 2013, section 1.2.3).
Random initialization can prevent convergence to saddle points
Things are different when gradient descent is initialized randomly (given certain assumptions). Lee et al. (2016) prove that:
If $f: \mathbb{R}^d \to \mathbb{R}$ is twice continuously differentiable and satisfies the strict saddle property, then gradient descent with a random initialization and sufficiently small constant step size almost surely converges to a local minimizer.
A 'sufficently small' step size means less than the inverse of the Lipschitz constant of the gradient, which they say is standard in practice. The 'strict saddle property' means that all critical points (where the gradient is zero) are either local minima or strict saddles (i.e. the Hessian has at least one strictly negative eigenvalue). This property doesn't apply universally, but they claim that it applies to many objective functions of practical interest.
The proof proceeds by treating gradient descent as a dynamical system. Each critical point has a surrounding basin of attraction. If gradient descent enters this basin, then it will converge to the corresponding critical point. Given the assumptions above, the basin of attraction around saddle points has zero measure. This implies that, with random initialization, there's zero probability of landing in such a basin (and therefore converging to a saddle point).
Escaping saddle points may require exponential time
The above result concerns asymptotic convergence. It says that gradient descent with random initialization will eventually converge to a local minimum, but it provides no guarantees about how long convergence will take. Unfortunately, Du et al. (2017) show that gradient descent may require exponential time to escape saddle points, even with random initialization and non-pathological objective functions. That is, there exist 'natural' objective functions where the required number of steps scales exponentially with the number of saddle points to escape. Although gradient descent will eventually converge in these cases, it may take an infeasibly long time. Note that this result describes the worst case scenario; it doesn't imply exponential time for all objective functions.
Speeding up convergence
There are various ways to speed up convergence in the presence of saddle points (see references in Du et al. 2017). One approach involves clever initialization schemes, but this is problem-specific. Another strategy exploits curvature information in the Hessian, yielding polynomial-time convergence to a local minimum (this is no longer gradient descent). This requires access to the Hessian (or the computation of Hessian-vector products) and may not scale to extremely large problems.
Pure gradient-based methods can escape saddle points in polynomial time if augmented with random perturbations. Intuitively, this works because, saddle points are unstable fixed points; if the optimization algorithm is randomly pushed away, there's a high probability it will move elsewhere. Random perturbations can be implemented by explicitly adding noise. Alternatively, standard stochastic gradient descent (SGD) might provide a similar effect, provided the noise in the gradient is sufficiently large in all directions (Ge et al. 2015; however Du et al. speculate that SGD will require exponential time in general).
References
Du, S. S., Jin, C., Lee, J. D., Jordan, M. I., Singh, A., & Poczos, B. (2017). Gradient descent can take exponential time to escape saddle points. In Advances in neural information processing systems (pp. 1067-1077).
Ge, R., Huang, F., Jin, C., & Yuan, Y. (2015, June). Escaping from saddle points—online stochastic gradient for tensor decomposition. In Conference on Learning Theory (pp. 797-842).
Lee, J. D., Simchowitz, M., Jordan, M. I., & Recht, B. (2016, June). Gradient descent only converges to minimizers. In Conference on learning theory (pp. 1246-1257).
Nesterov, Y. (2013). Introductory lectures on convex optimization: A basic course (Vol. 87). Springer Science & Business Media.
|
Why doesn't gradient descent terminate on saddle point?
|
Gradient descent can indeed converge to a saddle point, given a worst case initialization (Nesterov 2013, section 1.2.3).
Random initialization can prevent convergence to saddle points
Things are diff
|
Why doesn't gradient descent terminate on saddle point?
Gradient descent can indeed converge to a saddle point, given a worst case initialization (Nesterov 2013, section 1.2.3).
Random initialization can prevent convergence to saddle points
Things are different when gradient descent is initialized randomly (given certain assumptions). Lee et al. (2016) prove that:
If $f: \mathbb{R}^d \to \mathbb{R}$ is twice continuously differentiable and satisfies the strict saddle property, then gradient descent with a random initialization and sufficiently small constant step size almost surely converges to a local minimizer.
A 'sufficently small' step size means less than the inverse of the Lipschitz constant of the gradient, which they say is standard in practice. The 'strict saddle property' means that all critical points (where the gradient is zero) are either local minima or strict saddles (i.e. the Hessian has at least one strictly negative eigenvalue). This property doesn't apply universally, but they claim that it applies to many objective functions of practical interest.
The proof proceeds by treating gradient descent as a dynamical system. Each critical point has a surrounding basin of attraction. If gradient descent enters this basin, then it will converge to the corresponding critical point. Given the assumptions above, the basin of attraction around saddle points has zero measure. This implies that, with random initialization, there's zero probability of landing in such a basin (and therefore converging to a saddle point).
Escaping saddle points may require exponential time
The above result concerns asymptotic convergence. It says that gradient descent with random initialization will eventually converge to a local minimum, but it provides no guarantees about how long convergence will take. Unfortunately, Du et al. (2017) show that gradient descent may require exponential time to escape saddle points, even with random initialization and non-pathological objective functions. That is, there exist 'natural' objective functions where the required number of steps scales exponentially with the number of saddle points to escape. Although gradient descent will eventually converge in these cases, it may take an infeasibly long time. Note that this result describes the worst case scenario; it doesn't imply exponential time for all objective functions.
Speeding up convergence
There are various ways to speed up convergence in the presence of saddle points (see references in Du et al. 2017). One approach involves clever initialization schemes, but this is problem-specific. Another strategy exploits curvature information in the Hessian, yielding polynomial-time convergence to a local minimum (this is no longer gradient descent). This requires access to the Hessian (or the computation of Hessian-vector products) and may not scale to extremely large problems.
Pure gradient-based methods can escape saddle points in polynomial time if augmented with random perturbations. Intuitively, this works because, saddle points are unstable fixed points; if the optimization algorithm is randomly pushed away, there's a high probability it will move elsewhere. Random perturbations can be implemented by explicitly adding noise. Alternatively, standard stochastic gradient descent (SGD) might provide a similar effect, provided the noise in the gradient is sufficiently large in all directions (Ge et al. 2015; however Du et al. speculate that SGD will require exponential time in general).
References
Du, S. S., Jin, C., Lee, J. D., Jordan, M. I., Singh, A., & Poczos, B. (2017). Gradient descent can take exponential time to escape saddle points. In Advances in neural information processing systems (pp. 1067-1077).
Ge, R., Huang, F., Jin, C., & Yuan, Y. (2015, June). Escaping from saddle points—online stochastic gradient for tensor decomposition. In Conference on Learning Theory (pp. 797-842).
Lee, J. D., Simchowitz, M., Jordan, M. I., & Recht, B. (2016, June). Gradient descent only converges to minimizers. In Conference on learning theory (pp. 1246-1257).
Nesterov, Y. (2013). Introductory lectures on convex optimization: A basic course (Vol. 87). Springer Science & Business Media.
|
Why doesn't gradient descent terminate on saddle point?
Gradient descent can indeed converge to a saddle point, given a worst case initialization (Nesterov 2013, section 1.2.3).
Random initialization can prevent convergence to saddle points
Things are diff
|
41,089
|
Are there any theoretically rigorous justification for why scaling or normalizing data should improve statistical performance?
|
In the context of kernel methods, this is quite easy to see. Any given data matrix $\mathbf{X}$ corresponds to a kernel matrix $\mathbf{K}$, which in turns corresponds to a certain solution of the training problem which, due to convexity, is unique and guaranteed to be the global optimum.
However, if we change $\mathbf{X}$ into $\mathbf{X}'$, via some transformation, then we get a different kernel matrix $\mathbf{K}'$ and evidently a different solution. I explicitly mention this, because it is important to realize that the solution changes when we change $\mathbf{X}$, for instance by scaling. The solution is still found by solving a convex problem, and hence is still unique and the global optimum of its corresponding training problem (which is different for $\mathbf{K}$ and $\mathbf{K}'$).
The reason we do scaling, then, has nothing to do with solving the optimization problem but rather with defining it. For simplicity, lets assume we use the standard linear kernel:
$$\kappa(\mathbf{u},\mathbf{v}) = \mathbf{u}^T\mathbf{v}$$
If the features are on different scales, say, the first dimension is in $[0, 10^{99}]$ and the second is in $[0, 1]$, then it is easy to see that in all these kernel evaluations the first feature will completely dominate in the resulting distance estimates (that is, entries in the kernel matrix are almost exclusively based on the first dimension).
When you start building a model, you typically want to give each feature a similar contribution in the model, and for kernel methods that implies that they should be on the same scale. Scaling in no way guarantees better performing models, but it is usually the best "prior" you have. For example assume that the first feature in the contrived example above is informative while the second is not, in this case leaving the first feature on a far larger scale is in fact better.
Another example is available here.
|
Are there any theoretically rigorous justification for why scaling or normalizing data should improv
|
In the context of kernel methods, this is quite easy to see. Any given data matrix $\mathbf{X}$ corresponds to a kernel matrix $\mathbf{K}$, which in turns corresponds to a certain solution of the tra
|
Are there any theoretically rigorous justification for why scaling or normalizing data should improve statistical performance?
In the context of kernel methods, this is quite easy to see. Any given data matrix $\mathbf{X}$ corresponds to a kernel matrix $\mathbf{K}$, which in turns corresponds to a certain solution of the training problem which, due to convexity, is unique and guaranteed to be the global optimum.
However, if we change $\mathbf{X}$ into $\mathbf{X}'$, via some transformation, then we get a different kernel matrix $\mathbf{K}'$ and evidently a different solution. I explicitly mention this, because it is important to realize that the solution changes when we change $\mathbf{X}$, for instance by scaling. The solution is still found by solving a convex problem, and hence is still unique and the global optimum of its corresponding training problem (which is different for $\mathbf{K}$ and $\mathbf{K}'$).
The reason we do scaling, then, has nothing to do with solving the optimization problem but rather with defining it. For simplicity, lets assume we use the standard linear kernel:
$$\kappa(\mathbf{u},\mathbf{v}) = \mathbf{u}^T\mathbf{v}$$
If the features are on different scales, say, the first dimension is in $[0, 10^{99}]$ and the second is in $[0, 1]$, then it is easy to see that in all these kernel evaluations the first feature will completely dominate in the resulting distance estimates (that is, entries in the kernel matrix are almost exclusively based on the first dimension).
When you start building a model, you typically want to give each feature a similar contribution in the model, and for kernel methods that implies that they should be on the same scale. Scaling in no way guarantees better performing models, but it is usually the best "prior" you have. For example assume that the first feature in the contrived example above is informative while the second is not, in this case leaving the first feature on a far larger scale is in fact better.
Another example is available here.
|
Are there any theoretically rigorous justification for why scaling or normalizing data should improv
In the context of kernel methods, this is quite easy to see. Any given data matrix $\mathbf{X}$ corresponds to a kernel matrix $\mathbf{K}$, which in turns corresponds to a certain solution of the tra
|
41,090
|
What purpose does multiplying by 3 serve in Pearson's second coefficient of skewness?
|
This is a very interesting question.
The answer lies in history. There was one skewness measure, which was very popular initially, say in the beginning of XX-th century: $$\frac{mean-mode}{s.d.}$$. Since the mode is difficult to estimate the next best thing was to use the (approximate) relationship $$mean - mode \approx 3 (mean - median)$$
This relationship was discovered empirically for near symmetric distributions, as Yule explained in the text below.
Here's the reference: Yule, Introduction to the theory of Statistics (1922), see p.150 and p.121
|
What purpose does multiplying by 3 serve in Pearson's second coefficient of skewness?
|
This is a very interesting question.
The answer lies in history. There was one skewness measure, which was very popular initially, say in the beginning of XX-th century: $$\frac{mean-mode}{s.d.}$$. Si
|
What purpose does multiplying by 3 serve in Pearson's second coefficient of skewness?
This is a very interesting question.
The answer lies in history. There was one skewness measure, which was very popular initially, say in the beginning of XX-th century: $$\frac{mean-mode}{s.d.}$$. Since the mode is difficult to estimate the next best thing was to use the (approximate) relationship $$mean - mode \approx 3 (mean - median)$$
This relationship was discovered empirically for near symmetric distributions, as Yule explained in the text below.
Here's the reference: Yule, Introduction to the theory of Statistics (1922), see p.150 and p.121
|
What purpose does multiplying by 3 serve in Pearson's second coefficient of skewness?
This is a very interesting question.
The answer lies in history. There was one skewness measure, which was very popular initially, say in the beginning of XX-th century: $$\frac{mean-mode}{s.d.}$$. Si
|
41,091
|
How is the determinant of $(X'X)$ related to variance?
|
This is a result of using Cramer's rule to calculate the inverse of $\mathbf{X}^{\prime}\Sigma^{-1}\mathbf{X}$.
Note that the matrix $(\mathbf{X}^{\prime}\Sigma^{-1}\mathbf{X})^{-1}$ is the covariance matrix of the parameters $\beta_i$. So
$$
\text{Var}(\beta_1) = (\mathbf{X}^{\prime}\Sigma^{-1}\mathbf{X})^{-1}_{1,1}
$$
The first element in the matrix above is the variance of this parameter $\beta_1$. Now to calculate this value we can use Cramer's rule. To use Cramer's rule to find the inverse of a matrix $A$ we have
$$
A^{-1} = \frac{1}{\text{det}(A)}\text{Adj}(A)
$$
In this case $A=\mathbf{X}^{\prime}\Sigma^{-1}\mathbf{X}$, and the element we are seeking in $\text{Adj}(A)$ is $|F|$.
Cramer's rule is a very ineffective way of computing an inverse compared to standard methods. This rule usually pops up in situations like these, where one needs an expression for a specific element in the inverse.
|
How is the determinant of $(X'X)$ related to variance?
|
This is a result of using Cramer's rule to calculate the inverse of $\mathbf{X}^{\prime}\Sigma^{-1}\mathbf{X}$.
Note that the matrix $(\mathbf{X}^{\prime}\Sigma^{-1}\mathbf{X})^{-1}$ is the covariance
|
How is the determinant of $(X'X)$ related to variance?
This is a result of using Cramer's rule to calculate the inverse of $\mathbf{X}^{\prime}\Sigma^{-1}\mathbf{X}$.
Note that the matrix $(\mathbf{X}^{\prime}\Sigma^{-1}\mathbf{X})^{-1}$ is the covariance matrix of the parameters $\beta_i$. So
$$
\text{Var}(\beta_1) = (\mathbf{X}^{\prime}\Sigma^{-1}\mathbf{X})^{-1}_{1,1}
$$
The first element in the matrix above is the variance of this parameter $\beta_1$. Now to calculate this value we can use Cramer's rule. To use Cramer's rule to find the inverse of a matrix $A$ we have
$$
A^{-1} = \frac{1}{\text{det}(A)}\text{Adj}(A)
$$
In this case $A=\mathbf{X}^{\prime}\Sigma^{-1}\mathbf{X}$, and the element we are seeking in $\text{Adj}(A)$ is $|F|$.
Cramer's rule is a very ineffective way of computing an inverse compared to standard methods. This rule usually pops up in situations like these, where one needs an expression for a specific element in the inverse.
|
How is the determinant of $(X'X)$ related to variance?
This is a result of using Cramer's rule to calculate the inverse of $\mathbf{X}^{\prime}\Sigma^{-1}\mathbf{X}$.
Note that the matrix $(\mathbf{X}^{\prime}\Sigma^{-1}\mathbf{X})^{-1}$ is the covariance
|
41,092
|
In a multiple linear regression model, how do I test the null hypothesis that multiple coefficients are equal to zero simultaneously?
|
In your case, you want to know if the coefficients are equal to $0$. A model where the coefficients are $0$ is the same as a model that does not include those variables. Thus, you can perform a nested model test of a reduced model without those variables versus a full model that includes all the variables.
In a linear model context, that is called an $F$-change test, or $R^2$-change test, because you can compute the test value from the $F$ (or $R^2$) statistics from the two models (it is also sometimes called a 'multiple partial $F$ test, and by a dozen other names). I show a version of the formula here: Testing for moderation with continuous vs. categorical moderators. In a non-linear context (e.g., a logistic regression model), a likelihood ratio test can be used. More generally, testing multiple parameters at the same time is called a simultaneous test or a chunk test.
Concretely, to do this in R you would do something like:
m.full = lm(Y~X1+X2+X3+X4)
m.reduced = lm(Y~X2+X4)
anova(m.reduced, m.full)
|
In a multiple linear regression model, how do I test the null hypothesis that multiple coefficients
|
In your case, you want to know if the coefficients are equal to $0$. A model where the coefficients are $0$ is the same as a model that does not include those variables. Thus, you can perform a nest
|
In a multiple linear regression model, how do I test the null hypothesis that multiple coefficients are equal to zero simultaneously?
In your case, you want to know if the coefficients are equal to $0$. A model where the coefficients are $0$ is the same as a model that does not include those variables. Thus, you can perform a nested model test of a reduced model without those variables versus a full model that includes all the variables.
In a linear model context, that is called an $F$-change test, or $R^2$-change test, because you can compute the test value from the $F$ (or $R^2$) statistics from the two models (it is also sometimes called a 'multiple partial $F$ test, and by a dozen other names). I show a version of the formula here: Testing for moderation with continuous vs. categorical moderators. In a non-linear context (e.g., a logistic regression model), a likelihood ratio test can be used. More generally, testing multiple parameters at the same time is called a simultaneous test or a chunk test.
Concretely, to do this in R you would do something like:
m.full = lm(Y~X1+X2+X3+X4)
m.reduced = lm(Y~X2+X4)
anova(m.reduced, m.full)
|
In a multiple linear regression model, how do I test the null hypothesis that multiple coefficients
In your case, you want to know if the coefficients are equal to $0$. A model where the coefficients are $0$ is the same as a model that does not include those variables. Thus, you can perform a nest
|
41,093
|
In a multiple linear regression model, how do I test the null hypothesis that multiple coefficients are equal to zero simultaneously?
|
I will illustrate for models with one and two regressors, the generalization to four variables should be obvious.
library(lmtest)
y <- rnorm(100)
x1 <- rnorm(100)
x2 <- rnorm(100)
reg1 <- lm(y~x1)
reg2 <- lm(y~x1+x2)
waldtest(reg1,reg2)
So, load the lmtest package (the next three lines just create some example data), run the restricted regession reg1, the unrestricted one reg2 and let waldtest do the comparison for you.
For my random numbers, I get the following output:
Wald test
Model 1: y ~ x1
Model 2: y ~ x1 + x2
Res.Df Df F Pr(>F)
1 98
2 97 1 0.0178 0.8942
Thus, the null that $\beta_2=0$ cannot be rejected at $\alpha=0.05$, as the $p$-value Pr(>F) is way larger. This is not surprising in view of how I generated the data: there s no relationship between the x and y.
|
In a multiple linear regression model, how do I test the null hypothesis that multiple coefficients
|
I will illustrate for models with one and two regressors, the generalization to four variables should be obvious.
library(lmtest)
y <- rnorm(100)
x1 <- rnorm(100)
x2 <- rnorm(100)
reg1 <- lm(y~x1)
re
|
In a multiple linear regression model, how do I test the null hypothesis that multiple coefficients are equal to zero simultaneously?
I will illustrate for models with one and two regressors, the generalization to four variables should be obvious.
library(lmtest)
y <- rnorm(100)
x1 <- rnorm(100)
x2 <- rnorm(100)
reg1 <- lm(y~x1)
reg2 <- lm(y~x1+x2)
waldtest(reg1,reg2)
So, load the lmtest package (the next three lines just create some example data), run the restricted regession reg1, the unrestricted one reg2 and let waldtest do the comparison for you.
For my random numbers, I get the following output:
Wald test
Model 1: y ~ x1
Model 2: y ~ x1 + x2
Res.Df Df F Pr(>F)
1 98
2 97 1 0.0178 0.8942
Thus, the null that $\beta_2=0$ cannot be rejected at $\alpha=0.05$, as the $p$-value Pr(>F) is way larger. This is not surprising in view of how I generated the data: there s no relationship between the x and y.
|
In a multiple linear regression model, how do I test the null hypothesis that multiple coefficients
I will illustrate for models with one and two regressors, the generalization to four variables should be obvious.
library(lmtest)
y <- rnorm(100)
x1 <- rnorm(100)
x2 <- rnorm(100)
reg1 <- lm(y~x1)
re
|
41,094
|
Convex optimization: why so much effort on it?
|
To get started I recommend reading the introduction to this book by Stephen Boyd. He is doing a lot of cutting edge research in convex optimization, and is one of the biggest names in the field.
Often the issue of "making" your problem convex is reparameterization of the problem formulation. But sometimes the function your are trying to optimize is not convex and thus you can optimize a convex approximation which often agrees on the same global optimum. Still there are functions which are highly non-convex, e.g. deep neural networks, where one needs to resort to other methods, (back propagation).
The fact why this subject is important relates to the history of optimization. People managed to solve linear programs, where the simplex method is one of the first widely used methods to solve those kind of problems. Then they started to solve quadratic programs and other kinds of problems, but there was no obvious generalization. What these problems had in common was the convexity. It turns out that you can put the convex optimization problems in a canonical form, which is just a linear program. Thus making it a possibility to attack a huge class of problems. This is the best generalization we have so far, and I do not think we can generalize much further than this. Continues relaxations of discrete problems often also yields problems that are convex.
Most basic optimization problems are convex, a lot of statistics rely on convex optimization. In some cases you can get a closed form solution for the optimum (e.g. linear regression), but it is easy to define problems that do not have a closed form solution, (e.g. the lasso). If you are working on such a problem it is nice to have a tool to verify if your objective function is convex and to optimize it. This is possible in the software CVX developed by Boyd and others. This is very nice for prototyping, but if you need faster solvers sometimes you need to exploit the intricacies of the problem that you have to create a solver that works faster.
The newton method, the simplex method and others have in common that they are deterministic. They always yield the same results. Genetic algorithms do not give you this guarantee. They usually run much slower and are more suitable for when you have a noisy objective function or potentially a highly multi modal objective function.
It is entirely dependent on the problem that you are solving what method you would like to use. Read the introduction to the book and it will take you far!
|
Convex optimization: why so much effort on it?
|
To get started I recommend reading the introduction to this book by Stephen Boyd. He is doing a lot of cutting edge research in convex optimization, and is one of the biggest names in the field.
Often
|
Convex optimization: why so much effort on it?
To get started I recommend reading the introduction to this book by Stephen Boyd. He is doing a lot of cutting edge research in convex optimization, and is one of the biggest names in the field.
Often the issue of "making" your problem convex is reparameterization of the problem formulation. But sometimes the function your are trying to optimize is not convex and thus you can optimize a convex approximation which often agrees on the same global optimum. Still there are functions which are highly non-convex, e.g. deep neural networks, where one needs to resort to other methods, (back propagation).
The fact why this subject is important relates to the history of optimization. People managed to solve linear programs, where the simplex method is one of the first widely used methods to solve those kind of problems. Then they started to solve quadratic programs and other kinds of problems, but there was no obvious generalization. What these problems had in common was the convexity. It turns out that you can put the convex optimization problems in a canonical form, which is just a linear program. Thus making it a possibility to attack a huge class of problems. This is the best generalization we have so far, and I do not think we can generalize much further than this. Continues relaxations of discrete problems often also yields problems that are convex.
Most basic optimization problems are convex, a lot of statistics rely on convex optimization. In some cases you can get a closed form solution for the optimum (e.g. linear regression), but it is easy to define problems that do not have a closed form solution, (e.g. the lasso). If you are working on such a problem it is nice to have a tool to verify if your objective function is convex and to optimize it. This is possible in the software CVX developed by Boyd and others. This is very nice for prototyping, but if you need faster solvers sometimes you need to exploit the intricacies of the problem that you have to create a solver that works faster.
The newton method, the simplex method and others have in common that they are deterministic. They always yield the same results. Genetic algorithms do not give you this guarantee. They usually run much slower and are more suitable for when you have a noisy objective function or potentially a highly multi modal objective function.
It is entirely dependent on the problem that you are solving what method you would like to use. Read the introduction to the book and it will take you far!
|
Convex optimization: why so much effort on it?
To get started I recommend reading the introduction to this book by Stephen Boyd. He is doing a lot of cutting edge research in convex optimization, and is one of the biggest names in the field.
Often
|
41,095
|
Convex optimization: why so much effort on it?
|
The reason so much time is spent developing convex programming is that it already works so well for so many problems, so improving it further is worthwhile.
Also, simple gradient descent does not work on many large non-smooth (but convex) problems that are very interesting. Stuff that is easy to deal efficiently with in 1-2 dimensions can become difficult in 1000 dimensions.
|
Convex optimization: why so much effort on it?
|
The reason so much time is spent developing convex programming is that it already works so well for so many problems, so improving it further is worthwhile.
Also, simple gradient descent does not wor
|
Convex optimization: why so much effort on it?
The reason so much time is spent developing convex programming is that it already works so well for so many problems, so improving it further is worthwhile.
Also, simple gradient descent does not work on many large non-smooth (but convex) problems that are very interesting. Stuff that is easy to deal efficiently with in 1-2 dimensions can become difficult in 1000 dimensions.
|
Convex optimization: why so much effort on it?
The reason so much time is spent developing convex programming is that it already works so well for so many problems, so improving it further is worthwhile.
Also, simple gradient descent does not wor
|
41,096
|
What is a predictive distribution? [duplicate]
|
Some want to close this question because they think Predictive Distributions is a Bayesian concept only, so already answered. But there are also frequentist tries on defining predictive distributions, one is the paper
by A C Davison: "Approximate Predictive Likelihood" (Biometrika) http://biomet.oxfordjournals.org/content/73/2/323.abstract
The abstract sayes: "A predictive likelihood is given which approximates both Bayes and maximum likelihood predictive inference by expansion of a posterior likelihood. This synthesizes and extends previous results and is widely applicable. The approximation usually differs from exact Bayes posterior predictive density by Op(n–2), and from exact predictive likelihood by Op(n–2) but does not depend on the availability of prior information and is applicable when exact predictive likelihood cannot be found. The results are applied to the prediction of extremes using the generalized extreme-value distribution. "
So what is a predictive distribution, day for a (future) random variable $X$? It tries to approximate the conditional distribution $P(X \mid \text{data})$. In general such a conditional distribution will depend on unknown parameters, and a Bayesian solution will try to integrate out thse unknown parameers, over their posterior distribution. Frequentist solutions will try to eliminate those unknown parameters by other methods.
(I will come back and write more about those "other methods" later, now out of time).
|
What is a predictive distribution? [duplicate]
|
Some want to close this question because they think Predictive Distributions is a Bayesian concept only, so already answered. But there are also frequentist tries on defining predictive distributions
|
What is a predictive distribution? [duplicate]
Some want to close this question because they think Predictive Distributions is a Bayesian concept only, so already answered. But there are also frequentist tries on defining predictive distributions, one is the paper
by A C Davison: "Approximate Predictive Likelihood" (Biometrika) http://biomet.oxfordjournals.org/content/73/2/323.abstract
The abstract sayes: "A predictive likelihood is given which approximates both Bayes and maximum likelihood predictive inference by expansion of a posterior likelihood. This synthesizes and extends previous results and is widely applicable. The approximation usually differs from exact Bayes posterior predictive density by Op(n–2), and from exact predictive likelihood by Op(n–2) but does not depend on the availability of prior information and is applicable when exact predictive likelihood cannot be found. The results are applied to the prediction of extremes using the generalized extreme-value distribution. "
So what is a predictive distribution, day for a (future) random variable $X$? It tries to approximate the conditional distribution $P(X \mid \text{data})$. In general such a conditional distribution will depend on unknown parameters, and a Bayesian solution will try to integrate out thse unknown parameers, over their posterior distribution. Frequentist solutions will try to eliminate those unknown parameters by other methods.
(I will come back and write more about those "other methods" later, now out of time).
|
What is a predictive distribution? [duplicate]
Some want to close this question because they think Predictive Distributions is a Bayesian concept only, so already answered. But there are also frequentist tries on defining predictive distributions
|
41,097
|
Generalisation of the notion of correlation for $\alpha$-stable distributions
|
I have found something that could be useful. An alternative to the traditional correlation for $\alpha$-stable distributions with $\alpha > 1$ is the signed symmetric covariation coefficient.
Definition. Let $(X_{1},X_{2})$ be a bivariate symmetric $\alpha$-stable random vector with $\alpha > 1$. The signed symmetric covariation coefficient between $X_{1}$ and $X_{2}$ is the quantity:
$$ scov(X_{1},X_{2}) = \kappa_{(X_{1},X_{2})} | \frac{[X_{1},X_{2}]_{\alpha}[X_{2},X_{1}]_{\alpha}}{|| X_{1}||_{\alpha}^{\alpha} || X_{2}||_{\alpha}^{\alpha}} |^{\frac{1}{2}}, $$
where
$[X_{1},X_{2}]_{\alpha} = \int_{S_{2}} s_{1}s_{2}^{\langle\alpha -1\rangle} \mathbf{\Gamma}(d\mathbf{s})$, where $\mathbf{\Gamma}$ is the sprectral measure of the random vector $(X_{1},X_{2})$;
$||X_{1}||_{\alpha} = ([X_{1},X_{1}]_{\alpha})^{\frac{1}{\alpha}}$;
$ \kappa_{(X_{1},X_{2})} = sign([X_{1},X_{2}]_{\alpha}) \quad if\quad sign([X_{1},X_{2}]_{\alpha}) = sign([X_{2},X_{1}]_{\alpha})$;
$ \kappa_{(X_{1},X_{2})} = - 1 \quad if\quad sign([X_{1},X_{2}]_{\alpha}) = - sign([X_{2},X_{1}]_{\alpha})$.
The following proposition shows that the signed symmetric covariation coefficient has desirable properties as does the ordinary correlation coefficient of a bivariate Gaussian random vector.
Proposition. Let $(X_{1},X_{2})$ be a bivariate symmetric $\alpha$-stable random vector with $\alpha > 1$. The signed symmetric covariation coefficient has the following properties:
$-1 \leq scov(X_{1},X_{2}) \leq 1$
if $X_{1},X_{2}$ are independent, then $scov(X_{1},X_{2}) = 0$;
$|scov(X_{1},X_{2})| = 1$ if and only if $X_{2} = \lambda X_{1}$ for some $\lambda \in \mathbb{R}, \, \lambda \neq 0$;
for $\alpha = 2$, $scov(X_{1},X_{2})$ coincides with the usual correlation coefficient.
For further details refer to: Estimation and comparison of signed symmetric
covariation coefficient and generalized association
parameter for alpha-stable dependence by Bernédy Kodia and Bernard Garel
url: https://hal.archives-ouvertes.fr/hal-00951885/document
|
Generalisation of the notion of correlation for $\alpha$-stable distributions
|
I have found something that could be useful. An alternative to the traditional correlation for $\alpha$-stable distributions with $\alpha > 1$ is the signed symmetric covariation coefficient.
Definiti
|
Generalisation of the notion of correlation for $\alpha$-stable distributions
I have found something that could be useful. An alternative to the traditional correlation for $\alpha$-stable distributions with $\alpha > 1$ is the signed symmetric covariation coefficient.
Definition. Let $(X_{1},X_{2})$ be a bivariate symmetric $\alpha$-stable random vector with $\alpha > 1$. The signed symmetric covariation coefficient between $X_{1}$ and $X_{2}$ is the quantity:
$$ scov(X_{1},X_{2}) = \kappa_{(X_{1},X_{2})} | \frac{[X_{1},X_{2}]_{\alpha}[X_{2},X_{1}]_{\alpha}}{|| X_{1}||_{\alpha}^{\alpha} || X_{2}||_{\alpha}^{\alpha}} |^{\frac{1}{2}}, $$
where
$[X_{1},X_{2}]_{\alpha} = \int_{S_{2}} s_{1}s_{2}^{\langle\alpha -1\rangle} \mathbf{\Gamma}(d\mathbf{s})$, where $\mathbf{\Gamma}$ is the sprectral measure of the random vector $(X_{1},X_{2})$;
$||X_{1}||_{\alpha} = ([X_{1},X_{1}]_{\alpha})^{\frac{1}{\alpha}}$;
$ \kappa_{(X_{1},X_{2})} = sign([X_{1},X_{2}]_{\alpha}) \quad if\quad sign([X_{1},X_{2}]_{\alpha}) = sign([X_{2},X_{1}]_{\alpha})$;
$ \kappa_{(X_{1},X_{2})} = - 1 \quad if\quad sign([X_{1},X_{2}]_{\alpha}) = - sign([X_{2},X_{1}]_{\alpha})$.
The following proposition shows that the signed symmetric covariation coefficient has desirable properties as does the ordinary correlation coefficient of a bivariate Gaussian random vector.
Proposition. Let $(X_{1},X_{2})$ be a bivariate symmetric $\alpha$-stable random vector with $\alpha > 1$. The signed symmetric covariation coefficient has the following properties:
$-1 \leq scov(X_{1},X_{2}) \leq 1$
if $X_{1},X_{2}$ are independent, then $scov(X_{1},X_{2}) = 0$;
$|scov(X_{1},X_{2})| = 1$ if and only if $X_{2} = \lambda X_{1}$ for some $\lambda \in \mathbb{R}, \, \lambda \neq 0$;
for $\alpha = 2$, $scov(X_{1},X_{2})$ coincides with the usual correlation coefficient.
For further details refer to: Estimation and comparison of signed symmetric
covariation coefficient and generalized association
parameter for alpha-stable dependence by Bernédy Kodia and Bernard Garel
url: https://hal.archives-ouvertes.fr/hal-00951885/document
|
Generalisation of the notion of correlation for $\alpha$-stable distributions
I have found something that could be useful. An alternative to the traditional correlation for $\alpha$-stable distributions with $\alpha > 1$ is the signed symmetric covariation coefficient.
Definiti
|
41,098
|
Generalisation of the notion of correlation for $\alpha$-stable distributions
|
I found this idea in the book Gilchrist: "Statistical Modelling with Quantile Functions"; this are based on medians:
The comedian (don't laugh) of $X$ and $Y$ is defined by
$$
\text{coMED}(X,Y) = M[(X-M(X))(Y-M(Y))]
$$
where $M(X)$ is the median of $X$. Then one would have to standardize this by some measures of variability, that book gives MedAD as the sample median of the deviations $d_i$ from the median. How well that works for the stable distribution I do not know; you could investigate it by simulation.
Answer to additional question in the comments: "Do you think comedian is bilinear, like covariance?": First, the median itself satisfies $M(aX+b)=aM(X)+b$ (assuming that in the even $n$ case we use the mid-median, that is, taking the median of $X_1, X_2, X_3, X_4$ as $\frac{X_{(2)}+X_{(3)}}{2}$ where $X_{(i)}$ denotes the order statistics). This is because a linear transformation $ax+b$ of the data will not change the order ($a>0$) or will reverse the order ($a<0$). It is the last case which forces the use of the mid-median! But this is not enough to conclude that the median is linear, we would need that $M(X+Y)=M(X)+M(Y)$ and that is manifestly false. So without linearity of the median itself, bilinearity of the comedian is too much to ask. It cannot be true.
|
Generalisation of the notion of correlation for $\alpha$-stable distributions
|
I found this idea in the book Gilchrist: "Statistical Modelling with Quantile Functions"; this are based on medians:
The comedian (don't laugh) of $X$ and $Y$ is defined by
$$
\text{coMED}(X,Y) = M[(X
|
Generalisation of the notion of correlation for $\alpha$-stable distributions
I found this idea in the book Gilchrist: "Statistical Modelling with Quantile Functions"; this are based on medians:
The comedian (don't laugh) of $X$ and $Y$ is defined by
$$
\text{coMED}(X,Y) = M[(X-M(X))(Y-M(Y))]
$$
where $M(X)$ is the median of $X$. Then one would have to standardize this by some measures of variability, that book gives MedAD as the sample median of the deviations $d_i$ from the median. How well that works for the stable distribution I do not know; you could investigate it by simulation.
Answer to additional question in the comments: "Do you think comedian is bilinear, like covariance?": First, the median itself satisfies $M(aX+b)=aM(X)+b$ (assuming that in the even $n$ case we use the mid-median, that is, taking the median of $X_1, X_2, X_3, X_4$ as $\frac{X_{(2)}+X_{(3)}}{2}$ where $X_{(i)}$ denotes the order statistics). This is because a linear transformation $ax+b$ of the data will not change the order ($a>0$) or will reverse the order ($a<0$). It is the last case which forces the use of the mid-median! But this is not enough to conclude that the median is linear, we would need that $M(X+Y)=M(X)+M(Y)$ and that is manifestly false. So without linearity of the median itself, bilinearity of the comedian is too much to ask. It cannot be true.
|
Generalisation of the notion of correlation for $\alpha$-stable distributions
I found this idea in the book Gilchrist: "Statistical Modelling with Quantile Functions"; this are based on medians:
The comedian (don't laugh) of $X$ and $Y$ is defined by
$$
\text{coMED}(X,Y) = M[(X
|
41,099
|
Training a random forest in R with a fixed maximum false positive rate
|
The default RF classification aggregate trees by majority vote. Either you must modify the distribution of class votes of trees(see example A) or you must change the aggregation rule (see example B). Option A could be achieved by stratification/downsampling or classweight. I mainly mention because it is possible, as it probably will decrease overall prediction performance (AUC of ROC of test set predictions). Option B is to modify aggregation rule. Any sample predicted by a forest will get a number of votes(or 0) on each of the classes. The pluralism of the votes can be understood as a pseudo estimate of predicted probability, where the predicted probability of k'th class is votes on class k divided by all-votes. The voting threshold can be modified with the cutoff parameter, either during training or during prediction. The predicted class probabilities are basically divided with the class cutoffs. if cutoff = c(.5,.5) there is no change. if cutoff = c(.1,.9) much more votes on class 1. There is a gotcha in the randomForest, such that OOB-CV predictions only will take effect from cutoff if modified during training, whereas for predictions of newdata or testsets cutoff can be modified after training.
library(randomForest)
make.data = function(obs=1000,vars=6) {
X = data.frame(replicate(vars,rnorm(obs)))
noise=rnorm(obs)
y.value = with(X,X1^2+sin(X2)+X3*X4) + noise
y.class = factor(y.value>median(y.value),labels=c("-1","200"))
return(data.frame(y=y.class,X=X))
}
train.data = make.data()
test.data = make.data()
#native RF
RF.default = randomForest(y~.,data=train.data)
print(RF.default)
>Confusion matrix:
> predClass
>trainClass -1 200
> -1 386 114 (~22% false positive class 200)
> 200 131 369
#solution A: Unbalancing the data by stratification.
#It works, but not recommendable.
#stratified RF, downsample, false postive class "200" is ~5.2%
RF.stratify = randomForest(y~.,data=train.data,
sampsize=c(500,140),
strata=train.data$y)
print(RF.stratify)
>Confusion matrix:
> -1 200 class.error
>-1 468 32 0.064 (~10% false positive class 200)
>200 236 264 0.472
#solution B:
#changed vote-rule with cutoff
RF.default$forest$cutoff=c(.17,.83)
#cutoff is not implemented for OOB-CV in predict.randomForest!
preds.train = predict(RF.default)
table(trainClass=train.data$y,
predClass=preds.train)
> predClass
>trainClass -1 200
> -1 389 111 (OOB take no effect from cutoff after training)
> 200 108 392
#but it does work for newdata prediction
preds.test = predict(RF.default,newdata=test.data)
table(testClass=test.data$y,
predClass=preds.test)
> predClass
>testClass -1 200
> -1 487 13 (~10% false positive class 200)
> 200 362 138
#found the 'gotcha' in the source file of randomForest
#cutoff only modifies OOB predictions if modified during training
RF.default = randomForest(y~.,data=train.data,cutoff=c(.17,.83))
preds.train = predict(RF.default)
table(trainClass=train.data$y,
predClass=preds.train)
> predClass
>trainClass -1 200
> -1 490 10
> 200 366 134
#extra tip use a ROC plot to investigate the relationship between false positive and false negative, to helpt choose your favorite cutoff.
library(AUC)
plot(roc(predict(RF.default,type="vote")[,2],train.data$y))
|
Training a random forest in R with a fixed maximum false positive rate
|
The default RF classification aggregate trees by majority vote. Either you must modify the distribution of class votes of trees(see example A) or you must change the aggregation rule (see example B).
|
Training a random forest in R with a fixed maximum false positive rate
The default RF classification aggregate trees by majority vote. Either you must modify the distribution of class votes of trees(see example A) or you must change the aggregation rule (see example B). Option A could be achieved by stratification/downsampling or classweight. I mainly mention because it is possible, as it probably will decrease overall prediction performance (AUC of ROC of test set predictions). Option B is to modify aggregation rule. Any sample predicted by a forest will get a number of votes(or 0) on each of the classes. The pluralism of the votes can be understood as a pseudo estimate of predicted probability, where the predicted probability of k'th class is votes on class k divided by all-votes. The voting threshold can be modified with the cutoff parameter, either during training or during prediction. The predicted class probabilities are basically divided with the class cutoffs. if cutoff = c(.5,.5) there is no change. if cutoff = c(.1,.9) much more votes on class 1. There is a gotcha in the randomForest, such that OOB-CV predictions only will take effect from cutoff if modified during training, whereas for predictions of newdata or testsets cutoff can be modified after training.
library(randomForest)
make.data = function(obs=1000,vars=6) {
X = data.frame(replicate(vars,rnorm(obs)))
noise=rnorm(obs)
y.value = with(X,X1^2+sin(X2)+X3*X4) + noise
y.class = factor(y.value>median(y.value),labels=c("-1","200"))
return(data.frame(y=y.class,X=X))
}
train.data = make.data()
test.data = make.data()
#native RF
RF.default = randomForest(y~.,data=train.data)
print(RF.default)
>Confusion matrix:
> predClass
>trainClass -1 200
> -1 386 114 (~22% false positive class 200)
> 200 131 369
#solution A: Unbalancing the data by stratification.
#It works, but not recommendable.
#stratified RF, downsample, false postive class "200" is ~5.2%
RF.stratify = randomForest(y~.,data=train.data,
sampsize=c(500,140),
strata=train.data$y)
print(RF.stratify)
>Confusion matrix:
> -1 200 class.error
>-1 468 32 0.064 (~10% false positive class 200)
>200 236 264 0.472
#solution B:
#changed vote-rule with cutoff
RF.default$forest$cutoff=c(.17,.83)
#cutoff is not implemented for OOB-CV in predict.randomForest!
preds.train = predict(RF.default)
table(trainClass=train.data$y,
predClass=preds.train)
> predClass
>trainClass -1 200
> -1 389 111 (OOB take no effect from cutoff after training)
> 200 108 392
#but it does work for newdata prediction
preds.test = predict(RF.default,newdata=test.data)
table(testClass=test.data$y,
predClass=preds.test)
> predClass
>testClass -1 200
> -1 487 13 (~10% false positive class 200)
> 200 362 138
#found the 'gotcha' in the source file of randomForest
#cutoff only modifies OOB predictions if modified during training
RF.default = randomForest(y~.,data=train.data,cutoff=c(.17,.83))
preds.train = predict(RF.default)
table(trainClass=train.data$y,
predClass=preds.train)
> predClass
>trainClass -1 200
> -1 490 10
> 200 366 134
#extra tip use a ROC plot to investigate the relationship between false positive and false negative, to helpt choose your favorite cutoff.
library(AUC)
plot(roc(predict(RF.default,type="vote")[,2],train.data$y))
|
Training a random forest in R with a fixed maximum false positive rate
The default RF classification aggregate trees by majority vote. Either you must modify the distribution of class votes of trees(see example A) or you must change the aggregation rule (see example B).
|
41,100
|
How to visualize a significant interaction between two linear predictors using the rms package?
|
The rms package allows you to model interactions between continuous variables very flexibly. This is a demonstration of modeling crossed regression splines with that data:
(m <- cph(Surv(time, status) ~ rcs(bili,3) * rcs(alk.phos,3), data=d))
bplot(Predict(m, bili=seq(.5,25,by=.5), alk.phos=seq(300,10000, by=500), fun=exp),
lfun=contourplot, at=1:20)
You can find similar code described in Frank Harrell's "Regression Modeling Strategies" in chapter 10; Section 10.5:'Assessment of Model Fit'. There he used pseudo-3D plots which can also be useful in the visualization of interactions. That code was in the Binary Regression chapter, but there is no reason it cannot be used in a survival analysis (cph) context. One caveat that needs to be added is that this plot extends to regions of the bili-by-alk-phos "space" where there is no data, especially in the upper right quadrant. I will add a further example code section and plot section that shows how to use the rms perim function to restrict the contours to regions actually containing data and will make some further comments on interpretation.
> anova(m)
Wald Statistics Response: Surv(time, status)
Factor Chi-Square d.f. P
bili (Factor+Higher Order Factors) 141.86 6 <.0001
All Interactions 7.48 4 0.1128
Nonlinear (Factor+Higher Order Factors) 36.61 3 <.0001
alk.phos (Factor+Higher Order Factors) 8.17 6 0.2261
All Interactions 7.48 4 0.1128
Nonlinear (Factor+Higher Order Factors) 3.04 3 0.3854
bili * alk.phos (Factor+Higher Order Factors) 7.48 4 0.1128
Nonlinear 6.95 3 0.0735
Nonlinear Interaction : f(A,B) vs. AB 6.95 3 0.0735
f(A,B) vs. Af(B) + Bg(A) 0.13 1 0.7195
Nonlinear Interaction in bili vs. Af(B) 4.42 2 0.1096
Nonlinear Interaction in alk.phos vs. Bg(A) 2.75 2 0.2534
TOTAL NONLINEAR 53.97 5 <.0001
TOTAL NONLINEAR + INTERACTION 61.75 6 <.0001
TOTAL 147.36 8 <.0001
In my own work using cph with tens of thousands of events, I generally increase the default values of n for the perimeter function, but in this very small dataset I found it necessary to decrease the value to get a good example. I used a simple call to plot to see where the data actually extended.
with(d, plot(bili, alk.phos, col=status+1))
# needed to ad one to status to get both deaths and censored.
perim <- with(d, perimeter(bili, alk.phos, n=2))
# perim constructs a set of ranges where subjects are actually present
bplot( Predict(m, bili=seq(.5,25,by=.5), alk.phos=seq(300,10000, by=500),
fun=exp), # contours of relative risk
lfun=contourplot, # call to lattice function
at=1:20, # levels for contours
perim=perim) # regions to include
The plot shows that in the region where bilirubin is less than 4 or 5, that the risk increases primarily with increasing bilirubin with relative risks in the range of 1-3, but \ when bilirubin is greater than 5, that the risk increases to relative risks of 4 to 9 under the joint effect of decreasing alkaline phosphatase and bilirubin. Clinical interpretation: In the higher bilirubin "domain" a low alk.phos has what might be considered a paradoxical effect. There may be such substantial loss of functional liver tissuethat the remaining liver is so diminished that it is unable to produce as much of the alk-phos enzyme. This is a typical example of "effect modification" using the terminology of epidemiology. The higher "effect" associated with a given decrease in alk.phos is fairly small when bilirubin is low, but the alk.phos-"effect" gets magnified as bili-rubin rises.
|
How to visualize a significant interaction between two linear predictors using the rms package?
|
The rms package allows you to model interactions between continuous variables very flexibly. This is a demonstration of modeling crossed regression splines with that data:
(m <- cph(Surv(time, status)
|
How to visualize a significant interaction between two linear predictors using the rms package?
The rms package allows you to model interactions between continuous variables very flexibly. This is a demonstration of modeling crossed regression splines with that data:
(m <- cph(Surv(time, status) ~ rcs(bili,3) * rcs(alk.phos,3), data=d))
bplot(Predict(m, bili=seq(.5,25,by=.5), alk.phos=seq(300,10000, by=500), fun=exp),
lfun=contourplot, at=1:20)
You can find similar code described in Frank Harrell's "Regression Modeling Strategies" in chapter 10; Section 10.5:'Assessment of Model Fit'. There he used pseudo-3D plots which can also be useful in the visualization of interactions. That code was in the Binary Regression chapter, but there is no reason it cannot be used in a survival analysis (cph) context. One caveat that needs to be added is that this plot extends to regions of the bili-by-alk-phos "space" where there is no data, especially in the upper right quadrant. I will add a further example code section and plot section that shows how to use the rms perim function to restrict the contours to regions actually containing data and will make some further comments on interpretation.
> anova(m)
Wald Statistics Response: Surv(time, status)
Factor Chi-Square d.f. P
bili (Factor+Higher Order Factors) 141.86 6 <.0001
All Interactions 7.48 4 0.1128
Nonlinear (Factor+Higher Order Factors) 36.61 3 <.0001
alk.phos (Factor+Higher Order Factors) 8.17 6 0.2261
All Interactions 7.48 4 0.1128
Nonlinear (Factor+Higher Order Factors) 3.04 3 0.3854
bili * alk.phos (Factor+Higher Order Factors) 7.48 4 0.1128
Nonlinear 6.95 3 0.0735
Nonlinear Interaction : f(A,B) vs. AB 6.95 3 0.0735
f(A,B) vs. Af(B) + Bg(A) 0.13 1 0.7195
Nonlinear Interaction in bili vs. Af(B) 4.42 2 0.1096
Nonlinear Interaction in alk.phos vs. Bg(A) 2.75 2 0.2534
TOTAL NONLINEAR 53.97 5 <.0001
TOTAL NONLINEAR + INTERACTION 61.75 6 <.0001
TOTAL 147.36 8 <.0001
In my own work using cph with tens of thousands of events, I generally increase the default values of n for the perimeter function, but in this very small dataset I found it necessary to decrease the value to get a good example. I used a simple call to plot to see where the data actually extended.
with(d, plot(bili, alk.phos, col=status+1))
# needed to ad one to status to get both deaths and censored.
perim <- with(d, perimeter(bili, alk.phos, n=2))
# perim constructs a set of ranges where subjects are actually present
bplot( Predict(m, bili=seq(.5,25,by=.5), alk.phos=seq(300,10000, by=500),
fun=exp), # contours of relative risk
lfun=contourplot, # call to lattice function
at=1:20, # levels for contours
perim=perim) # regions to include
The plot shows that in the region where bilirubin is less than 4 or 5, that the risk increases primarily with increasing bilirubin with relative risks in the range of 1-3, but \ when bilirubin is greater than 5, that the risk increases to relative risks of 4 to 9 under the joint effect of decreasing alkaline phosphatase and bilirubin. Clinical interpretation: In the higher bilirubin "domain" a low alk.phos has what might be considered a paradoxical effect. There may be such substantial loss of functional liver tissuethat the remaining liver is so diminished that it is unable to produce as much of the alk-phos enzyme. This is a typical example of "effect modification" using the terminology of epidemiology. The higher "effect" associated with a given decrease in alk.phos is fairly small when bilirubin is low, but the alk.phos-"effect" gets magnified as bili-rubin rises.
|
How to visualize a significant interaction between two linear predictors using the rms package?
The rms package allows you to model interactions between continuous variables very flexibly. This is a demonstration of modeling crossed regression splines with that data:
(m <- cph(Surv(time, status)
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.