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
10,101
Would a Random Forest with multiple outputs be possible/practical?
Multiple output decision trees (and hence, random forests) have been developed and published. Pierre Guertz distributes a package for this (download). See also Segal & Xiao, Multivariate random forests, WIREs Data Mining Knowl Discov 2011 1 80–87, DOI: 10.1002/widm.12 I believe the latest version of Scikit-learn also supports this. A good review of the state of the art can be found in the thesis by Henrik Linusson entitled "MULTI-OUTPUT RANDOM FORESTS". The simplest method for making the split choices at each node is to randomly choose ONE of the output variables and then follow the usual random forest approach for choosing a split. Other methods based on a weighted sum of the mutual information score with respect to each input feature and output variable have been developed, but they are quite expensive compared to the randomized approach.
Would a Random Forest with multiple outputs be possible/practical?
Multiple output decision trees (and hence, random forests) have been developed and published. Pierre Guertz distributes a package for this (download). See also Segal & Xiao, Multivariate random forest
Would a Random Forest with multiple outputs be possible/practical? Multiple output decision trees (and hence, random forests) have been developed and published. Pierre Guertz distributes a package for this (download). See also Segal & Xiao, Multivariate random forests, WIREs Data Mining Knowl Discov 2011 1 80–87, DOI: 10.1002/widm.12 I believe the latest version of Scikit-learn also supports this. A good review of the state of the art can be found in the thesis by Henrik Linusson entitled "MULTI-OUTPUT RANDOM FORESTS". The simplest method for making the split choices at each node is to randomly choose ONE of the output variables and then follow the usual random forest approach for choosing a split. Other methods based on a weighted sum of the mutual information score with respect to each input feature and output variable have been developed, but they are quite expensive compared to the randomized approach.
Would a Random Forest with multiple outputs be possible/practical? Multiple output decision trees (and hence, random forests) have been developed and published. Pierre Guertz distributes a package for this (download). See also Segal & Xiao, Multivariate random forest
10,102
Would a Random Forest with multiple outputs be possible/practical?
As stated here: All classifiers in scikit-learn do multiclass classification out-of-the-box. And that includes Random Forest. Also the page: http://scikit-learn.org/stable/modules/tree.html#tree-multioutput has a lot of references on that topic.
Would a Random Forest with multiple outputs be possible/practical?
As stated here: All classifiers in scikit-learn do multiclass classification out-of-the-box. And that includes Random Forest. Also the page: http://scikit-learn.org/stable/modules/tree.html#tree-mul
Would a Random Forest with multiple outputs be possible/practical? As stated here: All classifiers in scikit-learn do multiclass classification out-of-the-box. And that includes Random Forest. Also the page: http://scikit-learn.org/stable/modules/tree.html#tree-multioutput has a lot of references on that topic.
Would a Random Forest with multiple outputs be possible/practical? As stated here: All classifiers in scikit-learn do multiclass classification out-of-the-box. And that includes Random Forest. Also the page: http://scikit-learn.org/stable/modules/tree.html#tree-mul
10,103
Would a Random Forest with multiple outputs be possible/practical?
Version 0.24.2 is taking this use case into account: https://scikit-learn.org/stable/modules/generated/sklearn.ensemble.RandomForestClassifier.html#sklearn.ensemble.RandomForestClassifier As specified in the documentation, the shape of the target you're passing to the fit function is like (n_samples, n_outputs).
Would a Random Forest with multiple outputs be possible/practical?
Version 0.24.2 is taking this use case into account: https://scikit-learn.org/stable/modules/generated/sklearn.ensemble.RandomForestClassifier.html#sklearn.ensemble.RandomForestClassifier As specified
Would a Random Forest with multiple outputs be possible/practical? Version 0.24.2 is taking this use case into account: https://scikit-learn.org/stable/modules/generated/sklearn.ensemble.RandomForestClassifier.html#sklearn.ensemble.RandomForestClassifier As specified in the documentation, the shape of the target you're passing to the fit function is like (n_samples, n_outputs).
Would a Random Forest with multiple outputs be possible/practical? Version 0.24.2 is taking this use case into account: https://scikit-learn.org/stable/modules/generated/sklearn.ensemble.RandomForestClassifier.html#sklearn.ensemble.RandomForestClassifier As specified
10,104
What diagnostic plots exists for quantile regression?
Quantile regression does not make distributional assumptions, i.e., assumptions about residuals, other than assuming that the response variable is almost continuous. If you are addressing the problem of estimating a single quantile as a function predictors X, far and away the major things that can go wrong are misspecification of the linear predictor $X\beta$ by underfitting, i.e., failing to include nonlinear effects (a common problem) or interaction effects. There are at least two recommended approaches. First, if your sample size is large, just fit a more flexible model. A good compromise is to allow all main effects to be nonlinear using regression splines such as restricted cubic splines (natural splines). Then there is nothing that needs to be checked except for interactions. The second approach is to hope that the model is simple (why?) but allow it to be complex, then to assess the impact of the complex additions to the simple model. For example, we can assess the combined contributions of nonlinear or interaction terms or both. An example follows, using the R rms and quantreg packages. A compromise interaction form is used, to limit the number of parameters. The interactions are restricted to not be doubly nonlinear. require(rms) # Estimate 25th percentile of y as a function of x1 and x2 f <- Rq(y ~ rcs(x1, 4) + rcs(x2, 4) + rcs(x1, 4) %ia% rcs(x2, 4), tau=.25) # rcs = restricted cubic spline, here with 4 default knots # %ia% = restricted interaction # To use general interactions (all cross product terms), use: # f <- Rq(y ~ rcs(x1, 4)*rcs(x2, 4), tau=.25) anova(f) # get automatic combined 'chunk' tests: nonlinearity, interaction # anova also provides the combined test of complexity (nonlin. + interact.)
What diagnostic plots exists for quantile regression?
Quantile regression does not make distributional assumptions, i.e., assumptions about residuals, other than assuming that the response variable is almost continuous. If you are addressing the problem
What diagnostic plots exists for quantile regression? Quantile regression does not make distributional assumptions, i.e., assumptions about residuals, other than assuming that the response variable is almost continuous. If you are addressing the problem of estimating a single quantile as a function predictors X, far and away the major things that can go wrong are misspecification of the linear predictor $X\beta$ by underfitting, i.e., failing to include nonlinear effects (a common problem) or interaction effects. There are at least two recommended approaches. First, if your sample size is large, just fit a more flexible model. A good compromise is to allow all main effects to be nonlinear using regression splines such as restricted cubic splines (natural splines). Then there is nothing that needs to be checked except for interactions. The second approach is to hope that the model is simple (why?) but allow it to be complex, then to assess the impact of the complex additions to the simple model. For example, we can assess the combined contributions of nonlinear or interaction terms or both. An example follows, using the R rms and quantreg packages. A compromise interaction form is used, to limit the number of parameters. The interactions are restricted to not be doubly nonlinear. require(rms) # Estimate 25th percentile of y as a function of x1 and x2 f <- Rq(y ~ rcs(x1, 4) + rcs(x2, 4) + rcs(x1, 4) %ia% rcs(x2, 4), tau=.25) # rcs = restricted cubic spline, here with 4 default knots # %ia% = restricted interaction # To use general interactions (all cross product terms), use: # f <- Rq(y ~ rcs(x1, 4)*rcs(x2, 4), tau=.25) anova(f) # get automatic combined 'chunk' tests: nonlinearity, interaction # anova also provides the combined test of complexity (nonlin. + interact.)
What diagnostic plots exists for quantile regression? Quantile regression does not make distributional assumptions, i.e., assumptions about residuals, other than assuming that the response variable is almost continuous. If you are addressing the problem
10,105
Multiple hypothesis testing correction with Benjamini-Hochberg, p-values or q-values?
As Robin said, you've got the Benjamini-Hochberg method backwards. With that method, you set a value for Q (upper case Q; the maximum desired FDR) and it then sorts your comparisons into two piles. The goal is that no more than Q% of the comparisons in the "discovery" pile are false, and thus at least 100%-Q% are true. If you computed a new value for each comparison, which is the value of Q at which that comparisons would just barely be considered a discovery, then those new values are q-values (lower case q; see the link to a paper by John Storey in the original question).
Multiple hypothesis testing correction with Benjamini-Hochberg, p-values or q-values?
As Robin said, you've got the Benjamini-Hochberg method backwards. With that method, you set a value for Q (upper case Q; the maximum desired FDR) and it then sorts your comparisons into two piles. Th
Multiple hypothesis testing correction with Benjamini-Hochberg, p-values or q-values? As Robin said, you've got the Benjamini-Hochberg method backwards. With that method, you set a value for Q (upper case Q; the maximum desired FDR) and it then sorts your comparisons into two piles. The goal is that no more than Q% of the comparisons in the "discovery" pile are false, and thus at least 100%-Q% are true. If you computed a new value for each comparison, which is the value of Q at which that comparisons would just barely be considered a discovery, then those new values are q-values (lower case q; see the link to a paper by John Storey in the original question).
Multiple hypothesis testing correction with Benjamini-Hochberg, p-values or q-values? As Robin said, you've got the Benjamini-Hochberg method backwards. With that method, you set a value for Q (upper case Q; the maximum desired FDR) and it then sorts your comparisons into two piles. Th
10,106
Intuition behind logistic regression
The logistic regression model is maximum likelihood using the natural parameter (the log-odds ratio) to contrast the relative changes in the risk of the outcome per unit difference in the predictor. This is assuming, of course, a binomial probability model for the outcome. That means that the consistency and robustness properties of logistic regression extend directly from maximum likelihood: robust to missing at random data, root-n consistency, and existence and uniqueness of solutions to estimating equations. This is assuming the solutions are not on the boundaries of parameter space (where log odds ratios are $\pm \infty$). Because logistic regression is maximum likelihood, the loss function is related to the likelihood, since they're equivalent optimization problems. With quasilikelihood or estimating equations (semiparametric inference), existence, uniqueness properties still hold but the assumption that the mean model holds is not relevant and the inference and standard errors are consistent regardless of model misspecification. So in this case, it's not a matter of whether the sigmoid is the correct function, but one that gives us a trend that we can believe in and is parameterized by parameters that have an extensible interpretation. The sigmoid, however, is not the only such binary modeling function around. The most commonly contrasted probit function has similar properties. It doesn't estimate log-odds ratios, but functionally they look very similar and tend to give very similar approximations to the exact same thing. One need not use boundness properties in the mean model function either. Simply using a log curve with a binomial variance function gives relative risk regression, an identity link with binomial variance gives additive risk models. All this is determined by the user. The popularity of logistic regression is, sadly, why it's so commonly used. However, I have my reasons (the ones that I stated) why I think it's well justified for it's use in most binary outcome modeling circumstances. In the inference world, for rare outcomes, the odds ratio can be roughly interpreted as a "relative risk", i.e. a "percent relative change in the risk of outcome comparing X+1 to X". This isn't always the case and, in general, an odds ratio cannot and should not be interpreted as such. However, that parameters have interpretation and can be easily communicated to other researchers is an important point, something sadly missing from the machine learnists' didactic materials. The logistic regression model also provides the conceptual foundations for more sophisticated approaches such as hierarchical modeling, as well as mixed modelling and conditional likelihood approaches which are consistent and robust to exponentially growing numbers of nuisance parameters. GLMMs and conditional logistic regression are very important concepts in high dimensional statistics.
Intuition behind logistic regression
The logistic regression model is maximum likelihood using the natural parameter (the log-odds ratio) to contrast the relative changes in the risk of the outcome per unit difference in the predictor. T
Intuition behind logistic regression The logistic regression model is maximum likelihood using the natural parameter (the log-odds ratio) to contrast the relative changes in the risk of the outcome per unit difference in the predictor. This is assuming, of course, a binomial probability model for the outcome. That means that the consistency and robustness properties of logistic regression extend directly from maximum likelihood: robust to missing at random data, root-n consistency, and existence and uniqueness of solutions to estimating equations. This is assuming the solutions are not on the boundaries of parameter space (where log odds ratios are $\pm \infty$). Because logistic regression is maximum likelihood, the loss function is related to the likelihood, since they're equivalent optimization problems. With quasilikelihood or estimating equations (semiparametric inference), existence, uniqueness properties still hold but the assumption that the mean model holds is not relevant and the inference and standard errors are consistent regardless of model misspecification. So in this case, it's not a matter of whether the sigmoid is the correct function, but one that gives us a trend that we can believe in and is parameterized by parameters that have an extensible interpretation. The sigmoid, however, is not the only such binary modeling function around. The most commonly contrasted probit function has similar properties. It doesn't estimate log-odds ratios, but functionally they look very similar and tend to give very similar approximations to the exact same thing. One need not use boundness properties in the mean model function either. Simply using a log curve with a binomial variance function gives relative risk regression, an identity link with binomial variance gives additive risk models. All this is determined by the user. The popularity of logistic regression is, sadly, why it's so commonly used. However, I have my reasons (the ones that I stated) why I think it's well justified for it's use in most binary outcome modeling circumstances. In the inference world, for rare outcomes, the odds ratio can be roughly interpreted as a "relative risk", i.e. a "percent relative change in the risk of outcome comparing X+1 to X". This isn't always the case and, in general, an odds ratio cannot and should not be interpreted as such. However, that parameters have interpretation and can be easily communicated to other researchers is an important point, something sadly missing from the machine learnists' didactic materials. The logistic regression model also provides the conceptual foundations for more sophisticated approaches such as hierarchical modeling, as well as mixed modelling and conditional likelihood approaches which are consistent and robust to exponentially growing numbers of nuisance parameters. GLMMs and conditional logistic regression are very important concepts in high dimensional statistics.
Intuition behind logistic regression The logistic regression model is maximum likelihood using the natural parameter (the log-odds ratio) to contrast the relative changes in the risk of the outcome per unit difference in the predictor. T
10,107
Intuition behind logistic regression
One way to think about logistic regression is as a threshold response model. In these models, you have a binary dependent variable, $Y$, which is influenced by the values of a vector of independent variables $X$. The dependent variable $Y$ can only take on the values 0 and 1, so you can't model the dependence of $Y$ on $X$ with a typical linear regression equation like $Y_i=X_i\beta+\epsilon_i$. But we really, really like linear equations. Or, at least, I do. To model this situation, we introduce an unobservable, latent variable $Y^*$, and we say that $Y$ goes from equaling 0 to equaling 1 when $Y^*$ crosses a threshold: \begin{align} Y^*_i &= X_i \beta + \epsilon_i\\ &\\ Y_i &= 0 \;\textrm{if}\; Y_i^*<0\\ Y_i &= 1 \; \textrm{if} \; Y_i^*>0 \end{align} As I have written it, the threshold is at 0. This is an illusion, however. Generally, the model includes an intercept (i.e. one of the columns of $X$ is a column of 1s). This allows the threshold to be anything. To motivate this model, think of killing bugs with a nerve-toxin pesticide. $Y^*$ is how many nerve cells are killed, and $X$ includes the dose of pesticide delivered to some bug. $Y$ is then 1 if the insect dies and 0 if it lives. That is, if enough nerve cells are killed (and $Y^*$ crosses the threshold), then the bug dies. This is not actually how neurotoxic pesticide work, by the way, but it's fun to pretend. So, you get a linear regression equation you can't see and a binary outcome you can see. The parameters, $\beta$ are usually estimated via maximum likelihood. If $\epsilon$ is distributed with symmetric distribution function $F$, then $P\{Y_i=1\}=F(X_i\beta)$. Just as you say, you can use any symmetric distribution function you want. Actually, you can use an asymmetric distribution function if you like, it just makes the algebra a tiny bit harder, as $P\{Y_i=1\}=1-F(-X_i\beta)$. Now, the distribution function you pick for $\epsilon$ affects your estimation results. The two most common choices for $F$ are normal (yielding the probit model) and logistic (yielding the logit model). These two distributions are so similar that there are rarely important differences in the results between them. Since logit has a very convenient closed form for both cdf and density functions, it's usually easier to use it rather than probit. Again, just as you say, you could pick any distribution function for $F$ and which one you pick will affect your results.
Intuition behind logistic regression
One way to think about logistic regression is as a threshold response model. In these models, you have a binary dependent variable, $Y$, which is influenced by the values of a vector of independent v
Intuition behind logistic regression One way to think about logistic regression is as a threshold response model. In these models, you have a binary dependent variable, $Y$, which is influenced by the values of a vector of independent variables $X$. The dependent variable $Y$ can only take on the values 0 and 1, so you can't model the dependence of $Y$ on $X$ with a typical linear regression equation like $Y_i=X_i\beta+\epsilon_i$. But we really, really like linear equations. Or, at least, I do. To model this situation, we introduce an unobservable, latent variable $Y^*$, and we say that $Y$ goes from equaling 0 to equaling 1 when $Y^*$ crosses a threshold: \begin{align} Y^*_i &= X_i \beta + \epsilon_i\\ &\\ Y_i &= 0 \;\textrm{if}\; Y_i^*<0\\ Y_i &= 1 \; \textrm{if} \; Y_i^*>0 \end{align} As I have written it, the threshold is at 0. This is an illusion, however. Generally, the model includes an intercept (i.e. one of the columns of $X$ is a column of 1s). This allows the threshold to be anything. To motivate this model, think of killing bugs with a nerve-toxin pesticide. $Y^*$ is how many nerve cells are killed, and $X$ includes the dose of pesticide delivered to some bug. $Y$ is then 1 if the insect dies and 0 if it lives. That is, if enough nerve cells are killed (and $Y^*$ crosses the threshold), then the bug dies. This is not actually how neurotoxic pesticide work, by the way, but it's fun to pretend. So, you get a linear regression equation you can't see and a binary outcome you can see. The parameters, $\beta$ are usually estimated via maximum likelihood. If $\epsilon$ is distributed with symmetric distribution function $F$, then $P\{Y_i=1\}=F(X_i\beta)$. Just as you say, you can use any symmetric distribution function you want. Actually, you can use an asymmetric distribution function if you like, it just makes the algebra a tiny bit harder, as $P\{Y_i=1\}=1-F(-X_i\beta)$. Now, the distribution function you pick for $\epsilon$ affects your estimation results. The two most common choices for $F$ are normal (yielding the probit model) and logistic (yielding the logit model). These two distributions are so similar that there are rarely important differences in the results between them. Since logit has a very convenient closed form for both cdf and density functions, it's usually easier to use it rather than probit. Again, just as you say, you could pick any distribution function for $F$ and which one you pick will affect your results.
Intuition behind logistic regression One way to think about logistic regression is as a threshold response model. In these models, you have a binary dependent variable, $Y$, which is influenced by the values of a vector of independent v
10,108
Intuition behind logistic regression
Logistic regression is not originally developed by machine learning community but statistics community. There are a lot of probabilistic views behind it. You may search the following terms to get more information: odds, log odds, generalized linear model, binomial link function. But for machine learning, the goal is slightly different that we only want to get a higher accuracy (minimize the loss function), but not talking about these assumptions and how data is generated. You are asking very good questions. So, for machine learning, it is common to use other 'sigmoid function' and loss function to do the classification. See this question for details What are the impacts of choosing different loss functions in classification to approximate 0-1 loss
Intuition behind logistic regression
Logistic regression is not originally developed by machine learning community but statistics community. There are a lot of probabilistic views behind it. You may search the following terms to get more
Intuition behind logistic regression Logistic regression is not originally developed by machine learning community but statistics community. There are a lot of probabilistic views behind it. You may search the following terms to get more information: odds, log odds, generalized linear model, binomial link function. But for machine learning, the goal is slightly different that we only want to get a higher accuracy (minimize the loss function), but not talking about these assumptions and how data is generated. You are asking very good questions. So, for machine learning, it is common to use other 'sigmoid function' and loss function to do the classification. See this question for details What are the impacts of choosing different loss functions in classification to approximate 0-1 loss
Intuition behind logistic regression Logistic regression is not originally developed by machine learning community but statistics community. There are a lot of probabilistic views behind it. You may search the following terms to get more
10,109
Link between moment-generating function and characteristic function
As mentioned in the comments, characteristic functions always exist, because they require integration of a function of modulus $1$. However, the moment generating function doesn't need to exist because in particular it requires the existence of moments of any order. When we know that $E[e^{tX}]$ is integrable for all $t$, we can define $g(z):=E[e^{zX}]$ for each complex number $z$. Then we notice that $M_X(t)=g(t)$ and $\varphi_X(t)=g(it)$.
Link between moment-generating function and characteristic function
As mentioned in the comments, characteristic functions always exist, because they require integration of a function of modulus $1$. However, the moment generating function doesn't need to exist becaus
Link between moment-generating function and characteristic function As mentioned in the comments, characteristic functions always exist, because they require integration of a function of modulus $1$. However, the moment generating function doesn't need to exist because in particular it requires the existence of moments of any order. When we know that $E[e^{tX}]$ is integrable for all $t$, we can define $g(z):=E[e^{zX}]$ for each complex number $z$. Then we notice that $M_X(t)=g(t)$ and $\varphi_X(t)=g(it)$.
Link between moment-generating function and characteristic function As mentioned in the comments, characteristic functions always exist, because they require integration of a function of modulus $1$. However, the moment generating function doesn't need to exist becaus
10,110
Link between moment-generating function and characteristic function
From Proakis, Digital communication 5th ed., the straightforward relationship is $$ \varphi(\omega) = M(j\omega) $$ and $$ M_x(t) = \varphi_x(-j t) $$
Link between moment-generating function and characteristic function
From Proakis, Digital communication 5th ed., the straightforward relationship is $$ \varphi(\omega) = M(j\omega) $$ and $$ M_x(t) = \varphi_x(-j t) $$
Link between moment-generating function and characteristic function From Proakis, Digital communication 5th ed., the straightforward relationship is $$ \varphi(\omega) = M(j\omega) $$ and $$ M_x(t) = \varphi_x(-j t) $$
Link between moment-generating function and characteristic function From Proakis, Digital communication 5th ed., the straightforward relationship is $$ \varphi(\omega) = M(j\omega) $$ and $$ M_x(t) = \varphi_x(-j t) $$
10,111
Why is my derivation of a closed form lasso solution incorrect?
This is normally done with least angle regression, you can find the paper here. Sorry about my confusion in the beginning, I am going to make another attempt at this. So after the expansion of your function $f(\beta)$ you get $$ f(\beta)=\sum_{i=1}^n y_i^2 -2\sum_{i=1}^n y_i X_i \beta + \sum_{i=1}^n \beta^T X_i^T X_i \beta + \alpha \sum_{j=1}^p |\beta_j| $$ Then you calculate the partial derivative with respect to $\beta_j$. My concern is in your calculation of the partial derivative of the last term before the 1-norm, i.e. the quadratic term. Let's examine it further. We have that: $$ X_i\beta = \beta^T X_i^T = (\beta_1 X_{i1}+\beta_2 X_{i2}+\cdots+ \beta_p X_{ip}) $$ So you can essentially rewrite your quadratic term as: $$ \sum_{i=1}^n \beta^T X_i^T X_i \beta = \sum_{i=1}^n (X_i \beta)^2 $$ Now we can use the chain rule to calculate the derivative of this w.r.t. $\beta_j$: $$ \frac{\partial }{\partial \beta_j} \sum_{i=1}^n (X_i \beta)^2 = \sum_{i=1}^n \frac{\partial }{\partial \beta_j} (X_i \beta)^2 = \sum_{i=1}^n 2(X_i \beta)X_{ij} $$ So now your problem does not simplify as easily, because you have all the $\beta$ coefficients present in each equation. This does not answer your question of why there is no closed form solution of the Lasso, I might add something later on that.
Why is my derivation of a closed form lasso solution incorrect?
This is normally done with least angle regression, you can find the paper here. Sorry about my confusion in the beginning, I am going to make another attempt at this. So after the expansion of your fu
Why is my derivation of a closed form lasso solution incorrect? This is normally done with least angle regression, you can find the paper here. Sorry about my confusion in the beginning, I am going to make another attempt at this. So after the expansion of your function $f(\beta)$ you get $$ f(\beta)=\sum_{i=1}^n y_i^2 -2\sum_{i=1}^n y_i X_i \beta + \sum_{i=1}^n \beta^T X_i^T X_i \beta + \alpha \sum_{j=1}^p |\beta_j| $$ Then you calculate the partial derivative with respect to $\beta_j$. My concern is in your calculation of the partial derivative of the last term before the 1-norm, i.e. the quadratic term. Let's examine it further. We have that: $$ X_i\beta = \beta^T X_i^T = (\beta_1 X_{i1}+\beta_2 X_{i2}+\cdots+ \beta_p X_{ip}) $$ So you can essentially rewrite your quadratic term as: $$ \sum_{i=1}^n \beta^T X_i^T X_i \beta = \sum_{i=1}^n (X_i \beta)^2 $$ Now we can use the chain rule to calculate the derivative of this w.r.t. $\beta_j$: $$ \frac{\partial }{\partial \beta_j} \sum_{i=1}^n (X_i \beta)^2 = \sum_{i=1}^n \frac{\partial }{\partial \beta_j} (X_i \beta)^2 = \sum_{i=1}^n 2(X_i \beta)X_{ij} $$ So now your problem does not simplify as easily, because you have all the $\beta$ coefficients present in each equation. This does not answer your question of why there is no closed form solution of the Lasso, I might add something later on that.
Why is my derivation of a closed form lasso solution incorrect? This is normally done with least angle regression, you can find the paper here. Sorry about my confusion in the beginning, I am going to make another attempt at this. So after the expansion of your fu
10,112
Difference of two i.i.d. lognormal random variables
This is a difficult problem. I thought first about using (some approximation of) the moment generating function of the lognormal distribution. That doesn't work, as I will explain. But first some notation: Let $\phi$ be the standard normal density and $\Phi$ the corresponding cumulative distribution function. We will only analyze the case lognormal distribution $lnN(0,1)$, which has density function $$ f(x)=\frac1{\sqrt{2\pi}x} e^{-\frac12 (\ln x)^2} $$ and cumulative distribution function $$ F(x) =\Phi(\ln x) $$ Suppose $X$ and $Y$ are independent random variables with the above lognormal distribution. We are interested in the distribution of $D=X-Y$, which is a symmetric distribution with mean zero. Let $M(t) = \DeclareMathOperator{\E}{E} \E e^{tX} $ be the moment generating function of $X$. It is defined only for $t\in (-\infty,0]$, so not defined in an open interval containing zero. The moment generating function for $D$ is $M_D(t)=\E e^{t(X-Y)}= \E e^{tX} \E e^{-tY}= M(t)M(-t)$. So, the moment generating function for $D$ is only defined for $t=0$, so not very useful. That means we will need some more direct approach for finding approximations for the distribution of $D$. Suppose $t\ge 0$, calculate $$ \begin{align} P(D \le t) &= P(X-Y\le t) \\ &= \int_0^\infty P(X-y\le t | Y=y) f(y) \; dy \\ &= \int_0^\infty P(X\le t+y) f(y) \; dy \\ &= \int_0^\infty F(t+y) f(y) \; dy \end{align} $$ (and the case $t<0$ is solved by symmetry, we get $P(D\le t)=1-P(D\le |t|)$). This expression can be used for numerical integration or as a basis for simulation. First a test: integrate(function(y) plnorm(y)*dlnorm(y), lower=0, upper=+Inf) 0.5 with absolute error < 2.3e-06 which is clearly correct. Let us wrap this up inside a function: pDIFF <- function(t) { d <- t for (tt in seq(along=t)) { if (t[tt] >= 0.0) d[tt] <- integrate(function(y) plnorm(y+t[tt])*dlnorm(y), lower=0.0, upper=+Inf)$value else d[tt] <- 1-integrate(function(y) plnorm(y+abs(t[tt]))*dlnorm(y), lower=0.0, upper=+Inf)$value } return(d) } > plot(pDIFF, from=-5, to=5) which gives: Then we can find the density function by differentiating under the integral sign, obtaining dDIFF <- function(t) { d <- t; t<- abs(t) for (tt in seq(along=t)) { d[tt] <- integrate(function(y) dlnorm(y+t[tt])*dlnorm(y), lower=0.0, upper=+Inf)$value } return(d) } which we can test: > integrate(dDIFF, lower=-Inf, upper=+Inf) 0.9999999 with absolute error < 1.3e-05 And plotting the density we get: plot(dDIFF, from=-5, to=5) I did also try to get some analytic approximation, but so far didn't succeed, it is not an easy problem. But numerical integration as above, programmed in R is very fast on modern hardware, so is a good alternative which probably should be used much more.
Difference of two i.i.d. lognormal random variables
This is a difficult problem. I thought first about using (some approximation of) the moment generating function of the lognormal distribution. That doesn't work, as I will explain. But first some no
Difference of two i.i.d. lognormal random variables This is a difficult problem. I thought first about using (some approximation of) the moment generating function of the lognormal distribution. That doesn't work, as I will explain. But first some notation: Let $\phi$ be the standard normal density and $\Phi$ the corresponding cumulative distribution function. We will only analyze the case lognormal distribution $lnN(0,1)$, which has density function $$ f(x)=\frac1{\sqrt{2\pi}x} e^{-\frac12 (\ln x)^2} $$ and cumulative distribution function $$ F(x) =\Phi(\ln x) $$ Suppose $X$ and $Y$ are independent random variables with the above lognormal distribution. We are interested in the distribution of $D=X-Y$, which is a symmetric distribution with mean zero. Let $M(t) = \DeclareMathOperator{\E}{E} \E e^{tX} $ be the moment generating function of $X$. It is defined only for $t\in (-\infty,0]$, so not defined in an open interval containing zero. The moment generating function for $D$ is $M_D(t)=\E e^{t(X-Y)}= \E e^{tX} \E e^{-tY}= M(t)M(-t)$. So, the moment generating function for $D$ is only defined for $t=0$, so not very useful. That means we will need some more direct approach for finding approximations for the distribution of $D$. Suppose $t\ge 0$, calculate $$ \begin{align} P(D \le t) &= P(X-Y\le t) \\ &= \int_0^\infty P(X-y\le t | Y=y) f(y) \; dy \\ &= \int_0^\infty P(X\le t+y) f(y) \; dy \\ &= \int_0^\infty F(t+y) f(y) \; dy \end{align} $$ (and the case $t<0$ is solved by symmetry, we get $P(D\le t)=1-P(D\le |t|)$). This expression can be used for numerical integration or as a basis for simulation. First a test: integrate(function(y) plnorm(y)*dlnorm(y), lower=0, upper=+Inf) 0.5 with absolute error < 2.3e-06 which is clearly correct. Let us wrap this up inside a function: pDIFF <- function(t) { d <- t for (tt in seq(along=t)) { if (t[tt] >= 0.0) d[tt] <- integrate(function(y) plnorm(y+t[tt])*dlnorm(y), lower=0.0, upper=+Inf)$value else d[tt] <- 1-integrate(function(y) plnorm(y+abs(t[tt]))*dlnorm(y), lower=0.0, upper=+Inf)$value } return(d) } > plot(pDIFF, from=-5, to=5) which gives: Then we can find the density function by differentiating under the integral sign, obtaining dDIFF <- function(t) { d <- t; t<- abs(t) for (tt in seq(along=t)) { d[tt] <- integrate(function(y) dlnorm(y+t[tt])*dlnorm(y), lower=0.0, upper=+Inf)$value } return(d) } which we can test: > integrate(dDIFF, lower=-Inf, upper=+Inf) 0.9999999 with absolute error < 1.3e-05 And plotting the density we get: plot(dDIFF, from=-5, to=5) I did also try to get some analytic approximation, but so far didn't succeed, it is not an easy problem. But numerical integration as above, programmed in R is very fast on modern hardware, so is a good alternative which probably should be used much more.
Difference of two i.i.d. lognormal random variables This is a difficult problem. I thought first about using (some approximation of) the moment generating function of the lognormal distribution. That doesn't work, as I will explain. But first some no
10,113
Difference of two i.i.d. lognormal random variables
This does not strictly answer your question, but wouldn't it be easier to look at the ratio of the $X$ and $Y$? You then simply arrive at $$ \begin{align} \Pr\left(\frac{X}{Y} \leq t\right) &= \Pr\left(\log\left(\frac{X}{Y}\right) \leq \log(t) \right) \\ &= \Pr(\log(X) - \log(Y) \leq \log(t)) \\ &\sim \mathcal{N}(0, 2 \sigma^2) \end{align}$$ Depending on your application, this may serve your needs.
Difference of two i.i.d. lognormal random variables
This does not strictly answer your question, but wouldn't it be easier to look at the ratio of the $X$ and $Y$? You then simply arrive at $$ \begin{align} \Pr\left(\frac{X}{Y} \leq t\right) &= \Pr\lef
Difference of two i.i.d. lognormal random variables This does not strictly answer your question, but wouldn't it be easier to look at the ratio of the $X$ and $Y$? You then simply arrive at $$ \begin{align} \Pr\left(\frac{X}{Y} \leq t\right) &= \Pr\left(\log\left(\frac{X}{Y}\right) \leq \log(t) \right) \\ &= \Pr(\log(X) - \log(Y) \leq \log(t)) \\ &\sim \mathcal{N}(0, 2 \sigma^2) \end{align}$$ Depending on your application, this may serve your needs.
Difference of two i.i.d. lognormal random variables This does not strictly answer your question, but wouldn't it be easier to look at the ratio of the $X$ and $Y$? You then simply arrive at $$ \begin{align} \Pr\left(\frac{X}{Y} \leq t\right) &= \Pr\lef
10,114
Difference of two i.i.d. lognormal random variables
I have a feeling characteristic functions are the best option for handling this question. For basics, kindly see:https://en.wikipedia.org/wiki/Characteristic_function_(probability_theory) now, kindly CTRL+F "independen". you'll see the answer in brief: The characteristic function approach is particularly useful in analysis of linear combinations of independent random variables If X1, ..., Xn are independent random variables, and a1, ..., an are some constants, then the characteristic function of the linear combination of the Xi 's is φ a 1 X 1 + ⋯ + a n X n ( t ) = φ X 1 ( a 1 t ) ⋯ φ X n ( a n t ) . {\displaystyle \varphi _{a_{1}X_{1}+\cdots +a_{n}X_{n}}(t)=\varphi _{X_{1}}(a_{1}t)\cdots \varphi _{X_{n}}(a_{n}t).} One specific case is the sum of two independent random variables X1 and X2 in which case one has φ X 1 + X 2 ( t ) = φ X 1 ( t ) ⋅ φ X 2 ( t ) . {\displaystyle \varphi {X{1}+X_{2}}(t)=\varphi {X{1}}(t)\cdot \varphi {X{2}}(t).} Characteristic functions are particularly useful for dealing with linear functions of independent random variables. For example, if X1, X2, ..., Xn is a sequence of independent (and not necessarily identically distributed) random variables, and S n = ∑ i = 1 n a i X i , {\displaystyle S_{n}=\sum {i=1}^{n}a{i}X_{i},,!} S_{n}=\sum {i=1}^{n}a{i}X_{i},,! where the ai are constants, then the characteristic function for Sn is given by φ S n ( t ) = φ X 1 ( a 1 t ) φ X 2 ( a 2 t ) ⋯ φ X n ( a n t ) {\displaystyle \varphi _{S_{n}}(t)=\varphi _{X_{1}}(a_{1}t)\varphi _{X_{2}}(a_{2}t)\cdots \varphi _{X_{n}}(a_{n}t)\,\!} \varphi _{S_{n}}(t)=\varphi _{X_{1}}(a_{1}t)\varphi _{X_{2}}(a_{2}t)\cdots \varphi _{X_{n}}(a_{n}t)\,\! In particular, φX+Y(t) = φX(t)φY(t). To see this, write out the definition of characteristic function: φ X + Y ( t ) = E ⁡ [ e i t ( X + Y ) ] = E ⁡ [ e i t X e i t Y ] = E ⁡ [ e i t X ] E ⁡ [ e i t Y ] = φ X ( t ) φ Y ( t ) {\displaystyle \varphi _{X+Y}(t)=\operatorname {E} \left[e^{it(X+Y)}\right]=\operatorname {E} \left[e^{itX}e^{itY}\right]=\operatorname {E} \left[e^{itX}\right]\operatorname {E} \left[e^{itY}\right]=\varphi _{X}(t)\varphi _{Y}(t)} {\displaystyle \varphi _{X+Y}(t)=\operatorname {E} \left[e^{it(X+Y)}\right]=\operatorname {E} \left[e^{itX}e^{itY}\right]=\operatorname {E} \left[e^{itX}\right]\operatorname {E} \left[e^{itY}\right]=\varphi _{X}(t)\varphi _{Y}(t)} The independence of X and Y is required to establish the equality of the third and fourth expressions.
Difference of two i.i.d. lognormal random variables
I have a feeling characteristic functions are the best option for handling this question. For basics, kindly see:https://en.wikipedia.org/wiki/Characteristic_function_(probability_theory) now, kindly
Difference of two i.i.d. lognormal random variables I have a feeling characteristic functions are the best option for handling this question. For basics, kindly see:https://en.wikipedia.org/wiki/Characteristic_function_(probability_theory) now, kindly CTRL+F "independen". you'll see the answer in brief: The characteristic function approach is particularly useful in analysis of linear combinations of independent random variables If X1, ..., Xn are independent random variables, and a1, ..., an are some constants, then the characteristic function of the linear combination of the Xi 's is φ a 1 X 1 + ⋯ + a n X n ( t ) = φ X 1 ( a 1 t ) ⋯ φ X n ( a n t ) . {\displaystyle \varphi _{a_{1}X_{1}+\cdots +a_{n}X_{n}}(t)=\varphi _{X_{1}}(a_{1}t)\cdots \varphi _{X_{n}}(a_{n}t).} One specific case is the sum of two independent random variables X1 and X2 in which case one has φ X 1 + X 2 ( t ) = φ X 1 ( t ) ⋅ φ X 2 ( t ) . {\displaystyle \varphi {X{1}+X_{2}}(t)=\varphi {X{1}}(t)\cdot \varphi {X{2}}(t).} Characteristic functions are particularly useful for dealing with linear functions of independent random variables. For example, if X1, X2, ..., Xn is a sequence of independent (and not necessarily identically distributed) random variables, and S n = ∑ i = 1 n a i X i , {\displaystyle S_{n}=\sum {i=1}^{n}a{i}X_{i},,!} S_{n}=\sum {i=1}^{n}a{i}X_{i},,! where the ai are constants, then the characteristic function for Sn is given by φ S n ( t ) = φ X 1 ( a 1 t ) φ X 2 ( a 2 t ) ⋯ φ X n ( a n t ) {\displaystyle \varphi _{S_{n}}(t)=\varphi _{X_{1}}(a_{1}t)\varphi _{X_{2}}(a_{2}t)\cdots \varphi _{X_{n}}(a_{n}t)\,\!} \varphi _{S_{n}}(t)=\varphi _{X_{1}}(a_{1}t)\varphi _{X_{2}}(a_{2}t)\cdots \varphi _{X_{n}}(a_{n}t)\,\! In particular, φX+Y(t) = φX(t)φY(t). To see this, write out the definition of characteristic function: φ X + Y ( t ) = E ⁡ [ e i t ( X + Y ) ] = E ⁡ [ e i t X e i t Y ] = E ⁡ [ e i t X ] E ⁡ [ e i t Y ] = φ X ( t ) φ Y ( t ) {\displaystyle \varphi _{X+Y}(t)=\operatorname {E} \left[e^{it(X+Y)}\right]=\operatorname {E} \left[e^{itX}e^{itY}\right]=\operatorname {E} \left[e^{itX}\right]\operatorname {E} \left[e^{itY}\right]=\varphi _{X}(t)\varphi _{Y}(t)} {\displaystyle \varphi _{X+Y}(t)=\operatorname {E} \left[e^{it(X+Y)}\right]=\operatorname {E} \left[e^{itX}e^{itY}\right]=\operatorname {E} \left[e^{itX}\right]\operatorname {E} \left[e^{itY}\right]=\varphi _{X}(t)\varphi _{Y}(t)} The independence of X and Y is required to establish the equality of the third and fourth expressions.
Difference of two i.i.d. lognormal random variables I have a feeling characteristic functions are the best option for handling this question. For basics, kindly see:https://en.wikipedia.org/wiki/Characteristic_function_(probability_theory) now, kindly
10,115
Interpretation of Hartigans' dip test
Mr. Freeman (author of the paper I told you about) told me that he was actually looking only at the Pvalue of the dip test. This confusion comes from his sentence : "HDS values range from 0 to 1 with values less than .05 indicating significant bimodality, and values greater than .05 but less than .10 suggesting bimodality with marginal significance". HDS values corresponds to the Pvalue, and not the dip test statistics. It was unclear in the paper. My analysis is good : the dip test statistics increases when the distribution is deviant from a unimodal distribution. Bimodality test and Silverman's test can also be computed easily in R and do the job well.
Interpretation of Hartigans' dip test
Mr. Freeman (author of the paper I told you about) told me that he was actually looking only at the Pvalue of the dip test. This confusion comes from his sentence : "HDS values range from 0 to 1 with
Interpretation of Hartigans' dip test Mr. Freeman (author of the paper I told you about) told me that he was actually looking only at the Pvalue of the dip test. This confusion comes from his sentence : "HDS values range from 0 to 1 with values less than .05 indicating significant bimodality, and values greater than .05 but less than .10 suggesting bimodality with marginal significance". HDS values corresponds to the Pvalue, and not the dip test statistics. It was unclear in the paper. My analysis is good : the dip test statistics increases when the distribution is deviant from a unimodal distribution. Bimodality test and Silverman's test can also be computed easily in R and do the job well.
Interpretation of Hartigans' dip test Mr. Freeman (author of the paper I told you about) told me that he was actually looking only at the Pvalue of the dip test. This confusion comes from his sentence : "HDS values range from 0 to 1 with
10,116
Consequences of modeling a non-stationary process using ARMA?
My impression is that this question does not have a unique, fully general answer, so I will only explore the simplest case, and in a bit informal way. Assume that the true Data Generating Mechanism is $$y_t = y_{t-1} + u_t,\;\; t=1,...,T,\;\; y_0 =0 \tag{1}$$ with $u_t$ a usual zero-mean i.i.d. white noise component, $E(u_t^2)= \sigma^2_u$ . The above also imply that $$y_t = \sum_{i=1}^tu_i \tag{2}$$ We specify a model, call it model $A$ $$y_t = \beta y_{t-1} + u_t,\;\; t=1,...,T,\;\; y_0 =0 \tag{3}$$ and we obtain an estimate $\hat \beta$ for the postulated $\beta$ (let's discuss the estimation method only if need arises). So a $k$-steps-ahead prediction will be $$\hat y_{T+k} = \hat \beta^k y_T \tag{4}$$ and its MSE will be $$MSE_A[\hat y_{T+k}] = E\left(\hat \beta^k y_T-y_{T+k}\right)^2 $$ $$=E\left[(\hat \beta^k-1) y_T -\sum_{i=T+1}^{T+k}u_i \right]^2 = E\big[(\hat\beta^k-1)^2 y_T^2\big]+ k\sigma^2_u \tag{5}$$ (the middle term of the square vanishes, as well as the cross-products of future errors). Let's now say that we have differenced our data, and specified a model $B$ $$\Delta y_t = \gamma \Delta y_{t-1} + u_t \tag{6}$$ and obtained an estimate $\hat \gamma$. Our differenced model can be written $$y_t = y_{t-1} + \gamma (y_{t-1}-y_{t-2}) + u_t \tag{7}$$ so forecasting the level of the process, we will have $$\hat y_{T+1} = y_{T} + \hat \gamma (y_{T}-y_{T-1})$$ which in reality, given the true DGP will be $$\hat y_{T+1} = y_{T} + \hat \gamma u_T \tag {8}$$ It is easy to verify then that, for model $B$, $$\hat y_{T+k} = y_{T} + \big(\hat \gamma + \hat \gamma^2+...+\hat \gamma^k)u_T $$ Now, we reasonably expect that, given any "tested and tried" estimation procedure, we will obtain $|\hat \gamma|<1$ since its true value is $0$, except if we have too few data, or in very "bad" shape. So we can say that in most cases we will have $$\hat y_{T+k} = y_{T} + \frac {\hat \gamma - \hat \gamma ^{k+1}}{1-\hat \gamma}u_T \tag{9}$$ and so $$MSE_B[\hat y_{T+k}] = E\left[\left(\frac {\hat \gamma - \hat \gamma ^{k+1}}{1-\hat \gamma}\right)^2u_T^2\right] + k\sigma^2_u \tag{10}$$ while I repeat for convenience $$MSE_A[\hat y_{T+k} ] = E\big[(\hat\beta^k-1)^2 y_T^2\big]+ k\sigma^2_u \tag{5}$$ So, in order for the differenced model to perform better in terms of prediction MSE, we want $$MSE_B[\hat y_{T+k}] \leq MSE_A[\hat y_{T+k}]$$ $$\Rightarrow E\left[\left(\frac {\hat \gamma - \hat \gamma ^{k+1}}{1-\hat \gamma}\right)^2u_T^2\right] \leq E\big[(\hat\beta^k-1)^2 y_T^2\big] $$ As with the estimator in model $B$, we extend the same courtesy to the estimator in model $A$: we reasonably expect that $\hat \beta$ will be "close to unity". It is evident that if it so happens that $\hat \beta >1$, the quantity in the right-hand-side of the inequality will tend to increase without bound as $k$, the number of forecast-ahead steps, will increase. On the other hand, the quantity on the left-hand side of the desired inequality, may increase as $k$ increases, but it has an upper bound. So in this scenario, we expect the differenced model $B$ to fair better in terms of prediction MSE compared to model $A$. But assume the more advantageous to model $A$ case, where $\hat \beta <1$. Then the right-hand side quantity also has a bound. Then as $k \rightarrow \infty$ we have to examine whether $$E\left[\left(\frac {\hat \gamma}{1-\hat \gamma}\right)^2u_T^2\right] \leq E\big[y_T^2\big]= T\sigma^2_u\;\; ??$$ (the $k \rightarrow \infty$ is a convenience -in reality both magnitudes will be close to their suprema already for small values of $k$). Note that the term $ \left(\frac {\hat \gamma }{1-\hat \gamma}\right)^2$ is expected to be "rather close" to $0$, so model $B$ has an advantage from this aspect. We cannot separate the remaining expected value, because the estimator $\hat \gamma$ is not independent from $u_T$. But we can transform the inequality into $$\operatorname{Cov}\left[\left(\frac {\hat \gamma}{1-\hat \gamma}\right)^2,\,u_T^2\right] + E\left[\left(\frac {\hat \gamma}{1-\hat \gamma}\right)^2\right]\cdot \sigma^2_u \leq T\sigma^2_u\;\; ??$$ $$\Rightarrow \operatorname{Cov}\left[\left(\frac {\hat \gamma}{1-\hat \gamma}\right)^2,\,u_T^2\right] \leq \left (T-E\left[\left(\frac {\hat \gamma}{1-\hat \gamma}\right)^2\right]\right)\cdot \sigma^2_u \;\; ??$$ Now, the covariance on the left-hand side is expected to be small, since the estimator $\hat \gamma$ depends on all $T$ errors. On the other side of the inequality, $\hat \gamma$ comes from a stationary data set, and so the expected value of the above function of it is expected to be much less than the size of the sample (since more over this function will range in $(0,1)$). So in all, without discussing any specific estimation method, I believe that we were able to show informally that the differenced model should be expected to perform better in terms of prediction MSE.
Consequences of modeling a non-stationary process using ARMA?
My impression is that this question does not have a unique, fully general answer, so I will only explore the simplest case, and in a bit informal way. Assume that the true Data Generating Mechanism
Consequences of modeling a non-stationary process using ARMA? My impression is that this question does not have a unique, fully general answer, so I will only explore the simplest case, and in a bit informal way. Assume that the true Data Generating Mechanism is $$y_t = y_{t-1} + u_t,\;\; t=1,...,T,\;\; y_0 =0 \tag{1}$$ with $u_t$ a usual zero-mean i.i.d. white noise component, $E(u_t^2)= \sigma^2_u$ . The above also imply that $$y_t = \sum_{i=1}^tu_i \tag{2}$$ We specify a model, call it model $A$ $$y_t = \beta y_{t-1} + u_t,\;\; t=1,...,T,\;\; y_0 =0 \tag{3}$$ and we obtain an estimate $\hat \beta$ for the postulated $\beta$ (let's discuss the estimation method only if need arises). So a $k$-steps-ahead prediction will be $$\hat y_{T+k} = \hat \beta^k y_T \tag{4}$$ and its MSE will be $$MSE_A[\hat y_{T+k}] = E\left(\hat \beta^k y_T-y_{T+k}\right)^2 $$ $$=E\left[(\hat \beta^k-1) y_T -\sum_{i=T+1}^{T+k}u_i \right]^2 = E\big[(\hat\beta^k-1)^2 y_T^2\big]+ k\sigma^2_u \tag{5}$$ (the middle term of the square vanishes, as well as the cross-products of future errors). Let's now say that we have differenced our data, and specified a model $B$ $$\Delta y_t = \gamma \Delta y_{t-1} + u_t \tag{6}$$ and obtained an estimate $\hat \gamma$. Our differenced model can be written $$y_t = y_{t-1} + \gamma (y_{t-1}-y_{t-2}) + u_t \tag{7}$$ so forecasting the level of the process, we will have $$\hat y_{T+1} = y_{T} + \hat \gamma (y_{T}-y_{T-1})$$ which in reality, given the true DGP will be $$\hat y_{T+1} = y_{T} + \hat \gamma u_T \tag {8}$$ It is easy to verify then that, for model $B$, $$\hat y_{T+k} = y_{T} + \big(\hat \gamma + \hat \gamma^2+...+\hat \gamma^k)u_T $$ Now, we reasonably expect that, given any "tested and tried" estimation procedure, we will obtain $|\hat \gamma|<1$ since its true value is $0$, except if we have too few data, or in very "bad" shape. So we can say that in most cases we will have $$\hat y_{T+k} = y_{T} + \frac {\hat \gamma - \hat \gamma ^{k+1}}{1-\hat \gamma}u_T \tag{9}$$ and so $$MSE_B[\hat y_{T+k}] = E\left[\left(\frac {\hat \gamma - \hat \gamma ^{k+1}}{1-\hat \gamma}\right)^2u_T^2\right] + k\sigma^2_u \tag{10}$$ while I repeat for convenience $$MSE_A[\hat y_{T+k} ] = E\big[(\hat\beta^k-1)^2 y_T^2\big]+ k\sigma^2_u \tag{5}$$ So, in order for the differenced model to perform better in terms of prediction MSE, we want $$MSE_B[\hat y_{T+k}] \leq MSE_A[\hat y_{T+k}]$$ $$\Rightarrow E\left[\left(\frac {\hat \gamma - \hat \gamma ^{k+1}}{1-\hat \gamma}\right)^2u_T^2\right] \leq E\big[(\hat\beta^k-1)^2 y_T^2\big] $$ As with the estimator in model $B$, we extend the same courtesy to the estimator in model $A$: we reasonably expect that $\hat \beta$ will be "close to unity". It is evident that if it so happens that $\hat \beta >1$, the quantity in the right-hand-side of the inequality will tend to increase without bound as $k$, the number of forecast-ahead steps, will increase. On the other hand, the quantity on the left-hand side of the desired inequality, may increase as $k$ increases, but it has an upper bound. So in this scenario, we expect the differenced model $B$ to fair better in terms of prediction MSE compared to model $A$. But assume the more advantageous to model $A$ case, where $\hat \beta <1$. Then the right-hand side quantity also has a bound. Then as $k \rightarrow \infty$ we have to examine whether $$E\left[\left(\frac {\hat \gamma}{1-\hat \gamma}\right)^2u_T^2\right] \leq E\big[y_T^2\big]= T\sigma^2_u\;\; ??$$ (the $k \rightarrow \infty$ is a convenience -in reality both magnitudes will be close to their suprema already for small values of $k$). Note that the term $ \left(\frac {\hat \gamma }{1-\hat \gamma}\right)^2$ is expected to be "rather close" to $0$, so model $B$ has an advantage from this aspect. We cannot separate the remaining expected value, because the estimator $\hat \gamma$ is not independent from $u_T$. But we can transform the inequality into $$\operatorname{Cov}\left[\left(\frac {\hat \gamma}{1-\hat \gamma}\right)^2,\,u_T^2\right] + E\left[\left(\frac {\hat \gamma}{1-\hat \gamma}\right)^2\right]\cdot \sigma^2_u \leq T\sigma^2_u\;\; ??$$ $$\Rightarrow \operatorname{Cov}\left[\left(\frac {\hat \gamma}{1-\hat \gamma}\right)^2,\,u_T^2\right] \leq \left (T-E\left[\left(\frac {\hat \gamma}{1-\hat \gamma}\right)^2\right]\right)\cdot \sigma^2_u \;\; ??$$ Now, the covariance on the left-hand side is expected to be small, since the estimator $\hat \gamma$ depends on all $T$ errors. On the other side of the inequality, $\hat \gamma$ comes from a stationary data set, and so the expected value of the above function of it is expected to be much less than the size of the sample (since more over this function will range in $(0,1)$). So in all, without discussing any specific estimation method, I believe that we were able to show informally that the differenced model should be expected to perform better in terms of prediction MSE.
Consequences of modeling a non-stationary process using ARMA? My impression is that this question does not have a unique, fully general answer, so I will only explore the simplest case, and in a bit informal way. Assume that the true Data Generating Mechanism
10,117
Consequences of modeling a non-stationary process using ARMA?
That is a good question. As I realize, you just have considered pacf but that is not enough. ACF and PACF are both necessary to select the best model. On the other hand, stationary tests are weak and sensitive and need a large amount of lags to be tested. In addition, it is preferred to make time series stationary before applying any model. Roughly speaking, ARIMA models just consider a special case of being non-stationary (preferably in trend). About your questions, I am not sure about the auto.arima function but I am sure that the number of data points in your example is small. Simulating model using a high number of data points would answer your questions well. Also, I advise you to consider ACF of time series as well as PACF. About model selection the rule of thumb is choosing the simplest model(note that the simplest model after making the time series stationary). I refer you to this reference. This book does not answer all of your questions but gives you some clues. ----- complementary section ------- @nsw considering a trend in your data. If you consider a stationary model, it results in an upward/downward prediction but actually ARMA models are designed to predict flat data. I have changed your code to reflect this difference: require('forecast') require('tseries') controlData <- arima.sim(list(order = c(1,1,1), ar = .5, ma = .5), n = 1000) acf(controlData) ts.plot(controlData) naiveFit <- arima(controlData,order = c(2,0,1)) trueFit<- arima(controlData,order = c(1,1,1)) PrnaiveFit<-forecast.Arima(naiveFit,10) PrtrueFit<- forecast.Arima(trueFit,10) matplot(cbind(PrnaiveFit\$mean,PrtrueFit\$mean),type='b',col=c('red','green'),ylab=c('predict ion'),pch=c('n','t'))
Consequences of modeling a non-stationary process using ARMA?
That is a good question. As I realize, you just have considered pacf but that is not enough. ACF and PACF are both necessary to select the best model. On the other hand, stationary tests are weak and
Consequences of modeling a non-stationary process using ARMA? That is a good question. As I realize, you just have considered pacf but that is not enough. ACF and PACF are both necessary to select the best model. On the other hand, stationary tests are weak and sensitive and need a large amount of lags to be tested. In addition, it is preferred to make time series stationary before applying any model. Roughly speaking, ARIMA models just consider a special case of being non-stationary (preferably in trend). About your questions, I am not sure about the auto.arima function but I am sure that the number of data points in your example is small. Simulating model using a high number of data points would answer your questions well. Also, I advise you to consider ACF of time series as well as PACF. About model selection the rule of thumb is choosing the simplest model(note that the simplest model after making the time series stationary). I refer you to this reference. This book does not answer all of your questions but gives you some clues. ----- complementary section ------- @nsw considering a trend in your data. If you consider a stationary model, it results in an upward/downward prediction but actually ARMA models are designed to predict flat data. I have changed your code to reflect this difference: require('forecast') require('tseries') controlData <- arima.sim(list(order = c(1,1,1), ar = .5, ma = .5), n = 1000) acf(controlData) ts.plot(controlData) naiveFit <- arima(controlData,order = c(2,0,1)) trueFit<- arima(controlData,order = c(1,1,1)) PrnaiveFit<-forecast.Arima(naiveFit,10) PrtrueFit<- forecast.Arima(trueFit,10) matplot(cbind(PrnaiveFit\$mean,PrtrueFit\$mean),type='b',col=c('red','green'),ylab=c('predict ion'),pch=c('n','t'))
Consequences of modeling a non-stationary process using ARMA? That is a good question. As I realize, you just have considered pacf but that is not enough. ACF and PACF are both necessary to select the best model. On the other hand, stationary tests are weak and
10,118
Multivariate normal posterior
With the distributions on our random vectors: $\mathbf x_i | \mathbf \mu \sim N(\mu , \mathbf \Sigma)$ $\mathbf \mu \sim N(\mathbf \mu_0, \mathbf \Sigma_0)$ By Bayes's rule the posterior distribution looks like: $p(\mu| \{\mathbf x_i\}) \propto p(\mu) \prod_{i=1}^N p(\mathbf x_i | \mu)$ So: $\ln p(\mu| \{\mathbf x_i\}) = -\frac{1}{2}\sum_{i=1}^N(\mathbf x_i - \mu)'\mathbf \Sigma^{-1}(\mathbf x_i - \mu) -\frac{1}{2}(\mu - \mu_0)'\mathbf \Sigma_0^{-1}(\mu - \mu_0) + const$ $ = -\frac{1}{2} N \mu' \mathbf \Sigma^{-1} \mu + \sum_{i=1}^N \mu' \mathbf \Sigma^{-1} \mathbf x_i -\frac{1}{2} \mu' \mathbf \Sigma_0^{-1} \mu + \mu' \mathbf \Sigma_0^{-1} \mu_0 + const$ $ = -\frac{1}{2} \mu' (N \mathbf \Sigma^{-1} + \mathbf \Sigma_0^{-1}) \mu + \mu' (\mathbf \Sigma_0^{-1} \mu_0 + \mathbf \Sigma^{-1} \sum_{i=1}^N \mathbf x_i) + const$ $= -\frac{1}{2}(\mu - (N \mathbf \Sigma^{-1} + \mathbf \Sigma_0^{-1})^{-1}(\mathbf \Sigma_0^{-1} \mu_0 + \mathbf \Sigma^{-1} \sum_{i=1}^N \mathbf x_i))' (N \mathbf \Sigma^{-1} + \mathbf \Sigma_0^{-1}) (\mu - (N \mathbf \Sigma^{-1} + \mathbf \Sigma_0^{-1})^{-1}(\mathbf \Sigma_0^{-1} \mu_0 + \mathbf \Sigma^{-1} \sum_{i=1}^N \mathbf x_i)) + const$ Which is the log density of a Gaussian: $\mu| \{\mathbf x_i\} \sim N((N \mathbf \Sigma^{-1} + \mathbf \Sigma_0^{-1})^{-1}(\mathbf \Sigma_0^{-1} \mu_0 + \mathbf \Sigma^{-1} \sum_{i=1}^N \mathbf x_i), (N \mathbf \Sigma^{-1} + \mathbf \Sigma_0^{-1})^{-1})$ Using the Woodbury identity on our expression for the covariance matrix: $(N \mathbf \Sigma^{-1} + \mathbf \Sigma_0^{-1})^{-1} = \mathbf \Sigma(\frac{1}{N} \mathbf \Sigma + \mathbf \Sigma_0)^{-1} \frac{1}{N} \mathbf \Sigma_0$ Which provides the covariance matrix in the form the OP wanted. Using this expression (and its symmetry) further in the expression for the mean we have: $\mathbf \Sigma(\frac{1}{N} \mathbf \Sigma + \mathbf \Sigma_0)^{-1} \frac{1}{N} \mathbf \Sigma_0 \mathbf \Sigma_0^{-1} \mu_0 + \frac{1}{N} \mathbf \Sigma_0(\frac{1}{N} \mathbf \Sigma + \mathbf \Sigma_0)^{-1} \mathbf \Sigma \mathbf \Sigma^{-1} \sum_{i=1}^N \mathbf x_i$ $= \mathbf \Sigma(\frac{1}{N} \mathbf \Sigma + \mathbf \Sigma_0)^{-1} \frac{1}{N} \mu_0 + \mathbf \Sigma_0(\frac{1}{N} \mathbf \Sigma + \mathbf \Sigma_0)^{-1} \sum_{i=1}^N (\frac{1}{N} \mathbf x_i)$ Which is the form required by the OP for the mean.
Multivariate normal posterior
With the distributions on our random vectors: $\mathbf x_i | \mathbf \mu \sim N(\mu , \mathbf \Sigma)$ $\mathbf \mu \sim N(\mathbf \mu_0, \mathbf \Sigma_0)$ By Bayes's rule the posterior distribution
Multivariate normal posterior With the distributions on our random vectors: $\mathbf x_i | \mathbf \mu \sim N(\mu , \mathbf \Sigma)$ $\mathbf \mu \sim N(\mathbf \mu_0, \mathbf \Sigma_0)$ By Bayes's rule the posterior distribution looks like: $p(\mu| \{\mathbf x_i\}) \propto p(\mu) \prod_{i=1}^N p(\mathbf x_i | \mu)$ So: $\ln p(\mu| \{\mathbf x_i\}) = -\frac{1}{2}\sum_{i=1}^N(\mathbf x_i - \mu)'\mathbf \Sigma^{-1}(\mathbf x_i - \mu) -\frac{1}{2}(\mu - \mu_0)'\mathbf \Sigma_0^{-1}(\mu - \mu_0) + const$ $ = -\frac{1}{2} N \mu' \mathbf \Sigma^{-1} \mu + \sum_{i=1}^N \mu' \mathbf \Sigma^{-1} \mathbf x_i -\frac{1}{2} \mu' \mathbf \Sigma_0^{-1} \mu + \mu' \mathbf \Sigma_0^{-1} \mu_0 + const$ $ = -\frac{1}{2} \mu' (N \mathbf \Sigma^{-1} + \mathbf \Sigma_0^{-1}) \mu + \mu' (\mathbf \Sigma_0^{-1} \mu_0 + \mathbf \Sigma^{-1} \sum_{i=1}^N \mathbf x_i) + const$ $= -\frac{1}{2}(\mu - (N \mathbf \Sigma^{-1} + \mathbf \Sigma_0^{-1})^{-1}(\mathbf \Sigma_0^{-1} \mu_0 + \mathbf \Sigma^{-1} \sum_{i=1}^N \mathbf x_i))' (N \mathbf \Sigma^{-1} + \mathbf \Sigma_0^{-1}) (\mu - (N \mathbf \Sigma^{-1} + \mathbf \Sigma_0^{-1})^{-1}(\mathbf \Sigma_0^{-1} \mu_0 + \mathbf \Sigma^{-1} \sum_{i=1}^N \mathbf x_i)) + const$ Which is the log density of a Gaussian: $\mu| \{\mathbf x_i\} \sim N((N \mathbf \Sigma^{-1} + \mathbf \Sigma_0^{-1})^{-1}(\mathbf \Sigma_0^{-1} \mu_0 + \mathbf \Sigma^{-1} \sum_{i=1}^N \mathbf x_i), (N \mathbf \Sigma^{-1} + \mathbf \Sigma_0^{-1})^{-1})$ Using the Woodbury identity on our expression for the covariance matrix: $(N \mathbf \Sigma^{-1} + \mathbf \Sigma_0^{-1})^{-1} = \mathbf \Sigma(\frac{1}{N} \mathbf \Sigma + \mathbf \Sigma_0)^{-1} \frac{1}{N} \mathbf \Sigma_0$ Which provides the covariance matrix in the form the OP wanted. Using this expression (and its symmetry) further in the expression for the mean we have: $\mathbf \Sigma(\frac{1}{N} \mathbf \Sigma + \mathbf \Sigma_0)^{-1} \frac{1}{N} \mathbf \Sigma_0 \mathbf \Sigma_0^{-1} \mu_0 + \frac{1}{N} \mathbf \Sigma_0(\frac{1}{N} \mathbf \Sigma + \mathbf \Sigma_0)^{-1} \mathbf \Sigma \mathbf \Sigma^{-1} \sum_{i=1}^N \mathbf x_i$ $= \mathbf \Sigma(\frac{1}{N} \mathbf \Sigma + \mathbf \Sigma_0)^{-1} \frac{1}{N} \mu_0 + \mathbf \Sigma_0(\frac{1}{N} \mathbf \Sigma + \mathbf \Sigma_0)^{-1} \sum_{i=1}^N (\frac{1}{N} \mathbf x_i)$ Which is the form required by the OP for the mean.
Multivariate normal posterior With the distributions on our random vectors: $\mathbf x_i | \mathbf \mu \sim N(\mu , \mathbf \Sigma)$ $\mathbf \mu \sim N(\mathbf \mu_0, \mathbf \Sigma_0)$ By Bayes's rule the posterior distribution
10,119
What if your random sample is clearly not representative?
The answer given by MLS (use importance sampling) is only as good as the assumptions you can make about your distributions. The main strength of the finite population sampling paradigm is that it is non-parametric, as it does not make any assumptions about the distribution of the data to make (valid) inferences on the finite population parameters. An approach to correct for sample imbalances is called post-stratification. You need to break down the sample into non-overlapping classes (post-strata), and then reweight these classes according to the known population figures. If your population is known to have a median of 0, then you can reweight the positive and negative observations so that their weighted proportions become 50-50: if you had an unlucky SRS with 10 negative observations and 20 positive observations, you would give the negative ones the weight of 15/10 = 1.5 and the positive ones, 15/20 = 0.75. More subtle forms of the sample calibration do exist, in which you can calibrate your sample to satisfy more general constraints, such as having a mean of a continuous variable to be equal to the specific value. The symmetry constraint is pretty difficult to work with, although that might be doable, too. May be Jean Opsomer has something on this: he has been doing a lot of kernel estimation work for survey data.
What if your random sample is clearly not representative?
The answer given by MLS (use importance sampling) is only as good as the assumptions you can make about your distributions. The main strength of the finite population sampling paradigm is that it is n
What if your random sample is clearly not representative? The answer given by MLS (use importance sampling) is only as good as the assumptions you can make about your distributions. The main strength of the finite population sampling paradigm is that it is non-parametric, as it does not make any assumptions about the distribution of the data to make (valid) inferences on the finite population parameters. An approach to correct for sample imbalances is called post-stratification. You need to break down the sample into non-overlapping classes (post-strata), and then reweight these classes according to the known population figures. If your population is known to have a median of 0, then you can reweight the positive and negative observations so that their weighted proportions become 50-50: if you had an unlucky SRS with 10 negative observations and 20 positive observations, you would give the negative ones the weight of 15/10 = 1.5 and the positive ones, 15/20 = 0.75. More subtle forms of the sample calibration do exist, in which you can calibrate your sample to satisfy more general constraints, such as having a mean of a continuous variable to be equal to the specific value. The symmetry constraint is pretty difficult to work with, although that might be doable, too. May be Jean Opsomer has something on this: he has been doing a lot of kernel estimation work for survey data.
What if your random sample is clearly not representative? The answer given by MLS (use importance sampling) is only as good as the assumptions you can make about your distributions. The main strength of the finite population sampling paradigm is that it is n
10,120
What if your random sample is clearly not representative?
I'm the Junior Member here, but I'd say that discarding and starting over is always the best answer, if you know that your sample is significantly unrepresentative, and if you have an idea of how the unrepresentative sampling arose in the first place and how to avoid it if possible the second time around. What good will it do to sample a second time if you'll probably end up in the same boat? If doing the data gathering again doesn't make sense or is prohibitively costly, you have to work with what you have, attempting to compensate for the unrepresentativeness via stratification, imputation, fancier modeling, or whatever. You need to clearly note that you compensated in this way, why you think it's necessary, and why you think it worked. Then work the uncertainty that arose from your compensation all the way through your analysis. (It will make your conclusions less certain, right?) If you can't do that, you need to drop the project entirely.
What if your random sample is clearly not representative?
I'm the Junior Member here, but I'd say that discarding and starting over is always the best answer, if you know that your sample is significantly unrepresentative, and if you have an idea of how the
What if your random sample is clearly not representative? I'm the Junior Member here, but I'd say that discarding and starting over is always the best answer, if you know that your sample is significantly unrepresentative, and if you have an idea of how the unrepresentative sampling arose in the first place and how to avoid it if possible the second time around. What good will it do to sample a second time if you'll probably end up in the same boat? If doing the data gathering again doesn't make sense or is prohibitively costly, you have to work with what you have, attempting to compensate for the unrepresentativeness via stratification, imputation, fancier modeling, or whatever. You need to clearly note that you compensated in this way, why you think it's necessary, and why you think it worked. Then work the uncertainty that arose from your compensation all the way through your analysis. (It will make your conclusions less certain, right?) If you can't do that, you need to drop the project entirely.
What if your random sample is clearly not representative? I'm the Junior Member here, but I'd say that discarding and starting over is always the best answer, if you know that your sample is significantly unrepresentative, and if you have an idea of how the
10,121
What if your random sample is clearly not representative?
This is a partial answer that assumes we know both the distribution $q$ from which was sampled, and the true (or desired) distribution $p$. Additionally, I assume that these distributions are different. If the samples were actually obtained through $p$, but they look wrong: the samples are still unbiased and any adaptation (such as removing outliers) will likely add bias. I assume you want to find some statistic $s_p = E \{ f(X) | X \sim p \}$. For instance, $s(p)$ might be the mean of the distribution, in which case $f$ is the identity function. If you had samples $\{ x_1, \ldots, x_n \}$ obtained through $p$, you could simply use $$ s_p \approx \frac{1}{n} \sum_{i=1}^n f(x_i) \enspace. $$ However, suppose you only have samples that were obtained (from the same domain) with a sampling distribution $x_i \sim q$. Then, we can still get an unbiased estimate of $s_p$ by weighting each of the samples according to the relative probability of it occuring under each distribution: $$ s_p \approx \frac{1}{n} \sum_{i=1}^n \frac{p(x_i)}{q(x_i)} f(x_i) \enspace. $$ The reason this works is that $$ E \left\{ \frac{p(X)}{q(X)} f(X) \middle| X \sim q \right\} = \int p(X) f(X) dx \enspace, $$ as desired. This is called importance sampling.
What if your random sample is clearly not representative?
This is a partial answer that assumes we know both the distribution $q$ from which was sampled, and the true (or desired) distribution $p$. Additionally, I assume that these distributions are differen
What if your random sample is clearly not representative? This is a partial answer that assumes we know both the distribution $q$ from which was sampled, and the true (or desired) distribution $p$. Additionally, I assume that these distributions are different. If the samples were actually obtained through $p$, but they look wrong: the samples are still unbiased and any adaptation (such as removing outliers) will likely add bias. I assume you want to find some statistic $s_p = E \{ f(X) | X \sim p \}$. For instance, $s(p)$ might be the mean of the distribution, in which case $f$ is the identity function. If you had samples $\{ x_1, \ldots, x_n \}$ obtained through $p$, you could simply use $$ s_p \approx \frac{1}{n} \sum_{i=1}^n f(x_i) \enspace. $$ However, suppose you only have samples that were obtained (from the same domain) with a sampling distribution $x_i \sim q$. Then, we can still get an unbiased estimate of $s_p$ by weighting each of the samples according to the relative probability of it occuring under each distribution: $$ s_p \approx \frac{1}{n} \sum_{i=1}^n \frac{p(x_i)}{q(x_i)} f(x_i) \enspace. $$ The reason this works is that $$ E \left\{ \frac{p(X)}{q(X)} f(X) \middle| X \sim q \right\} = \int p(X) f(X) dx \enspace, $$ as desired. This is called importance sampling.
What if your random sample is clearly not representative? This is a partial answer that assumes we know both the distribution $q$ from which was sampled, and the true (or desired) distribution $p$. Additionally, I assume that these distributions are differen
10,122
What is behind Google Prediction API?
Google is using different machine learning techniques and algorithm for training and prediction. The strategies for large-scale supervised learning: 1. Sub-sample 2. Embarrassingly parallelize some algorithms 3. Distributed gradient descent 4. Majority Vote 5. Parameter mixture 6. Iterative parameter mixture They should train and predict the model with the different machine learning techniques and using an algorithm to decide the best model and prediction to return. Sub-sampling provides inferior performance Parameter mixture improves, but not as good as all data Distributed algorithms return better classifiers quicker Iterative parameter mixture achieves as good as all data But of course it is not really clear in the API documentation.
What is behind Google Prediction API?
Google is using different machine learning techniques and algorithm for training and prediction. The strategies for large-scale supervised learning: 1. Sub-sample 2. Embarrassingly parallelize some al
What is behind Google Prediction API? Google is using different machine learning techniques and algorithm for training and prediction. The strategies for large-scale supervised learning: 1. Sub-sample 2. Embarrassingly parallelize some algorithms 3. Distributed gradient descent 4. Majority Vote 5. Parameter mixture 6. Iterative parameter mixture They should train and predict the model with the different machine learning techniques and using an algorithm to decide the best model and prediction to return. Sub-sampling provides inferior performance Parameter mixture improves, but not as good as all data Distributed algorithms return better classifiers quicker Iterative parameter mixture achieves as good as all data But of course it is not really clear in the API documentation.
What is behind Google Prediction API? Google is using different machine learning techniques and algorithm for training and prediction. The strategies for large-scale supervised learning: 1. Sub-sample 2. Embarrassingly parallelize some al
10,123
What are some standard practices for creating synthetic data sets?
I'm not sure there are standard practices for generating synthetic data - it's used so heavily in so many different aspects of research that purpose-built data seems to be a more common and arguably more reasonable approach. For me, my best standard practice is not to make the data set so it will work well with the model. That's part of the research stage, not part of the data generation stage. Instead, the data should be designed to reflect the data generation process. For example, for simulation studies in Epidemiology, I always start from a large hypothetical population with a known distribution, and then simulate study sampling from that population, rather than generating "the study population" directly. For example, based on our discussion below, two examples of simulated data I've made: Somewhat similar to your SIR-model example below, I once used a mathematical model of the spread of disease over a network to show myself via simulation that a particular constant parameter didn't necessarily imply a constant hazard if you treated the results as the outcome of a cohort study. It was a useful proof of concept while I went digging for an analytical solution. I wanted to explore the impact of a certain sampling scheme for a case-control study. Rather than trying to generate the study outright, I walked through each step of the process. A population of 1,000,000 people, with a given known prevalence of disease and a known covariate pattern. Then from that simulating the sampling process - in this case, how cases and controls were drawn from the population. Only then did I throw an actual statistical model at the collected "simulated studies". Simulations like the latter are very common when examining the impact of study recruitment methods, statistical approaches to controlling for covariates, etc.
What are some standard practices for creating synthetic data sets?
I'm not sure there are standard practices for generating synthetic data - it's used so heavily in so many different aspects of research that purpose-built data seems to be a more common and arguably m
What are some standard practices for creating synthetic data sets? I'm not sure there are standard practices for generating synthetic data - it's used so heavily in so many different aspects of research that purpose-built data seems to be a more common and arguably more reasonable approach. For me, my best standard practice is not to make the data set so it will work well with the model. That's part of the research stage, not part of the data generation stage. Instead, the data should be designed to reflect the data generation process. For example, for simulation studies in Epidemiology, I always start from a large hypothetical population with a known distribution, and then simulate study sampling from that population, rather than generating "the study population" directly. For example, based on our discussion below, two examples of simulated data I've made: Somewhat similar to your SIR-model example below, I once used a mathematical model of the spread of disease over a network to show myself via simulation that a particular constant parameter didn't necessarily imply a constant hazard if you treated the results as the outcome of a cohort study. It was a useful proof of concept while I went digging for an analytical solution. I wanted to explore the impact of a certain sampling scheme for a case-control study. Rather than trying to generate the study outright, I walked through each step of the process. A population of 1,000,000 people, with a given known prevalence of disease and a known covariate pattern. Then from that simulating the sampling process - in this case, how cases and controls were drawn from the population. Only then did I throw an actual statistical model at the collected "simulated studies". Simulations like the latter are very common when examining the impact of study recruitment methods, statistical approaches to controlling for covariates, etc.
What are some standard practices for creating synthetic data sets? I'm not sure there are standard practices for generating synthetic data - it's used so heavily in so many different aspects of research that purpose-built data seems to be a more common and arguably m
10,124
What are some standard practices for creating synthetic data sets?
The R statistical package has a simulate function that will simulate data based on a model fit to existing data. This uses the fitted model as the "known" population relationship, then simulates new data based on that model. There is a method for this function in the lme4 package. These fitted objects can take into account random and fixed effects and correlation (including autocorrelation for time series). This may work do what you want.
What are some standard practices for creating synthetic data sets?
The R statistical package has a simulate function that will simulate data based on a model fit to existing data. This uses the fitted model as the "known" population relationship, then simulates new
What are some standard practices for creating synthetic data sets? The R statistical package has a simulate function that will simulate data based on a model fit to existing data. This uses the fitted model as the "known" population relationship, then simulates new data based on that model. There is a method for this function in the lme4 package. These fitted objects can take into account random and fixed effects and correlation (including autocorrelation for time series). This may work do what you want.
What are some standard practices for creating synthetic data sets? The R statistical package has a simulate function that will simulate data based on a model fit to existing data. This uses the fitted model as the "known" population relationship, then simulates new
10,125
How to get hyper parameters in nested cross validation?
(I'm sure I wrote most of this already in some answer - but can't find it right now. If anyone stumbles across that answer, please link it). I see 2 slightly different approaches here, which I think are both sensible. But first some terminology: Coming from an applied field, a (fitted/trained) model for me is a ready-to-use. I.e. the model contains all information needed to generate predictions for new data. Thus, the model contains also the hyperparameters. As you will see, this point of view is closely related to approach 2 below. OTOH, training algorithm in my experience is not well defined in the following sense: in order to get the (fitted) model, not only the - let's call it "primary fitting" - of the "normal" model parameters needs to be done, but also the hyperparameters need to be fixed. From my application perspective, there isn't really much difference between parameters and hyperparamers: both are part of the model, and need to be estimated/decided during training. I guess the difference between them is related to the difference between someone developing new training algorithms who'd usually describe a class of training algorithms together with some steering parameters (the hyperparameters) which are difficult/impossibe to fix (or at least to fix how they should be decided/estimated) without application/domain knowledge. Approach 1: require stable optimization results With this approach, "model training" is the fitting of the "normal" model parameters, and hyperparameters are given. An inner e.g. cross validation takes care of the hyperparameter optimization. The crucial step/assumption here to solve the dilemma of whose hyperparameter set should be chosen is to require the optimization to be stable. Cross validation for validation purposes assumes that all surrogate models are sufficiently similar to the final model (obtained by the same training algorithm applied to the whole data set) to allow treating them as equal (among themselves as well as to the final model). If this assumption breaks down and the surrogate models are still equal (or equivalent) among themselves but not to the final model, we are talking about the well-known pessimistic bias of cross validation. If also the surrogate model are not equal/equivalent to each other, we have problems with instability. For the optimization results of the inner loop this means that if the optimization is stable, there is no conflict in choosing hyperparameters. And if considerable variation is observed across the inner cross validation results, the optimization is not stable. Unstable training situations have far worse problems than just the decision which of the hyperparameter sets to choose, and I'd really recommend to step back in that case and start the modeling process all over. There's an exception, here, though: there may be several local minima in the optimization yielding equal performance for practical purposes. Requiring also the choice among them to be stable may be an unnecessary strong requirement - but I don't know how to get out of this dilemma. Note that if not all models yield the same winning parameter set, you should not use outer loop estimates as generalization error here: If you claim generalization error for parameters $p$, all surrogate models entering into the validation should actually use exactly these parameters. (Imagine someone told you they did a cross validation on model with C = 1 and linear kernel and you find out some splits were evaluated with rbf kernel!) But unless there is no decision involved as all splits yielded the same parameters, this will break independence in the outer loop: the test data of each split already entered the decision which parameter set wins as it was training data in all other splits and thus used to optimize the parameters. Approach 2: treat hyperparameter tuning as part of the model training This approach bridges the perspectives of the "training algorithm developer" and applied user of the training algorithm. The training algorithm developer provides a "naked" training algorithm model = train_naked (trainingdata, hyperparameters). As the applied user needs tunedmodel = train_tuned (trainingdata) which also takes care of fixing the hyperparameters. train_tuned can be implemented e.g. by wrapping a cross validation-based optimizer around the naked training algorithm train_naked. train_tuned can then be used like any other training algorithm that does not require hyperparameter input, e.g. its output tunedmodel can be subjected to cross validation. Now the hyperparameters are checked for their stability just like the "normal" parameters should be checked for stability as part of the evaluation of the cross validation. This is actually what you do and evaluate in the nested cross validation if you average performance of all winning models regardless of their individual parameter sets. What's the difference? We possibly end up with different final models taking those 2 approaches: the final model in approach 1 will be train_naked (all data, hyperparameters from optimization) whereas approach 2 will use train_tuned (all data) and - as that runs the hyperparameter optimization again on the larger data set - this may end up with a different set of hyperparameters. But again the same logic applies: if we find that the final model has substantially different parameters from the cross validation surrogate models, that's a symptom of assumption 1 being violated. So IMHO, again we do not have a conflict but rather a check on whether our (implicit) assumptions are justified. And if they aren't, we anyways should not bet too much on having a good estimate of the performance of that final model. I have the impression (also from seeing the number of similar questions/confusions here on CV) that many people think of nested cross validation doing approach 1. But generalization error is usually estimated according to approach 2, so that's the way to go for the final model as well. Iris example Summary: The optimization is basically pointless. The available sample size does not allow distinctions between the performance of any of the parameter sets here. From the application point of view, however, the conclusion is that it doesn't matter which of the 4 parameter sets you choose - which isn't all that bad news: you found a comparatively stable plateau of parameters. Here comes the advantage of the proper nested validation of the tuned model: while you're not able to claim that the it is the optimal model, your're still able to claim that the model built on the whole data using approach 2 will have about 97 % accuracy (95 % confidence interval for 145 correct out of 150 test cases: 92 - 99 %) Note that also approach 1 isn't as far off as it seems - see below: your optimization accidentally missed a comparatively clear "winner" because of ties (that's actually another very telltale symptom of the sample size problem). While I'm not deep enough into SVMs to "see" that C = 1 should be a good choice here, I'd go with the more restrictive linear kernel. Also, as you did the optimization, there's nothing wrong with choosing the winning parameter set even if you are aware that all parameter sets lead to practically equal performance. In future, however, consider whether your experience yields rough guesstimates of what performance you can expect and roughly what model would be a good choice. Then build that model (with manually fixed hyperparameters) and calculate a confidence interval for its performance. Use this to decide whether trying to optimize is sensible at all. (I may add that I'm mostly working with data where getting 10 more independent cases is not easy - if you are in a field with large independent sample sizes, things look much better for you) long version: As for the example results on the iris data set. iris has 150 cases, SVM with a grid of 2 x 2 parameters (2 kernels, 2 orders of magnitude for the penalty C) are considered. The inner loop has splits of 129 (2x) and 132 (6x) cases. The "best" parameter set is undecided between linear or rbf kernel, both with C = 1. However, the inner test accuracies are all (including the always loosing C = 10) within 94 - 98.5 % observed accuracy. The largest difference we have in one of the splits is 3 vs. 8 errors for rbf with C = 1 vs. 10. There's no way this is a significant difference. I don't know how to extract the predictions for the individual cases in the CV, but even assuming that the 3 errors were shared, and the C = 10 model made additional 5 errors: > table (rbf1, rbf10) rbf10 rbf1 correct wrong correct 124 5 wrong 0 3 > mcnemar.exact(rbf1, rbf10) Exact McNemar test (with central confidence intervals) data: rbf1 and rbf10 b = 5, c = 0, p-value = 0.0625 alternative hypothesis: true odds ratio is not equal to 1 Remember that there are 6 pairwise comparisons in the 2 x 2 grid, so we'd need to correct for multiple comparisons as well. Approach 1 In 3 of the 4 outer splits where rbf "won" over the linear kernel, they actually had the same estimated accuracy (I guess min in case of ties returns the first suitable index). Changing the grid to params = {'kernel':['linear', 'rbf'],'C':[1,10]} yields ({'kernel': 'linear', 'C': 1}, 0.95238095238095233, 0.97674418604651159) ({'kernel': 'rbf', 'C': 1}, 0.95238095238095233, 0.98449612403100772) ({'kernel': 'linear', 'C': 1}, 1.0, 0.97727272727272729) ({'kernel': 'linear', 'C': 1}, 0.94444444444444442, 0.98484848484848486) ({'kernel': 'linear', 'C': 1}, 0.94444444444444442, 0.98484848484848486) ({'kernel': 'linear', 'C': 1}, 1.0, 0.98484848484848486) ({'kernel': 'linear', 'C': 1}, 1.0, 0.96212121212121215) Approach 2: Here, clf is your final model. With random_state = 2, rbf with C = 1 wins: In [310]: clf.grid_scores_ [...snip warning...] Out[310]: [mean: 0.97333, std: 0.00897, params: {'kernel': 'linear', 'C': 1}, mean: 0.98000, std: 0.02773, params: {'kernel': 'rbf', 'C': 1}, mean: 0.96000, std: 0.03202, params: {'kernel': 'linear', 'C': 10}, mean: 0.95333, std: 0.01791, params: {'kernel': 'rbf', 'C': 10}] (happens about 1 in 5 times, 1 in 6 times linear and rbf with C = 1 are tied on rank 1)
How to get hyper parameters in nested cross validation?
(I'm sure I wrote most of this already in some answer - but can't find it right now. If anyone stumbles across that answer, please link it). I see 2 slightly different approaches here, which I think a
How to get hyper parameters in nested cross validation? (I'm sure I wrote most of this already in some answer - but can't find it right now. If anyone stumbles across that answer, please link it). I see 2 slightly different approaches here, which I think are both sensible. But first some terminology: Coming from an applied field, a (fitted/trained) model for me is a ready-to-use. I.e. the model contains all information needed to generate predictions for new data. Thus, the model contains also the hyperparameters. As you will see, this point of view is closely related to approach 2 below. OTOH, training algorithm in my experience is not well defined in the following sense: in order to get the (fitted) model, not only the - let's call it "primary fitting" - of the "normal" model parameters needs to be done, but also the hyperparameters need to be fixed. From my application perspective, there isn't really much difference between parameters and hyperparamers: both are part of the model, and need to be estimated/decided during training. I guess the difference between them is related to the difference between someone developing new training algorithms who'd usually describe a class of training algorithms together with some steering parameters (the hyperparameters) which are difficult/impossibe to fix (or at least to fix how they should be decided/estimated) without application/domain knowledge. Approach 1: require stable optimization results With this approach, "model training" is the fitting of the "normal" model parameters, and hyperparameters are given. An inner e.g. cross validation takes care of the hyperparameter optimization. The crucial step/assumption here to solve the dilemma of whose hyperparameter set should be chosen is to require the optimization to be stable. Cross validation for validation purposes assumes that all surrogate models are sufficiently similar to the final model (obtained by the same training algorithm applied to the whole data set) to allow treating them as equal (among themselves as well as to the final model). If this assumption breaks down and the surrogate models are still equal (or equivalent) among themselves but not to the final model, we are talking about the well-known pessimistic bias of cross validation. If also the surrogate model are not equal/equivalent to each other, we have problems with instability. For the optimization results of the inner loop this means that if the optimization is stable, there is no conflict in choosing hyperparameters. And if considerable variation is observed across the inner cross validation results, the optimization is not stable. Unstable training situations have far worse problems than just the decision which of the hyperparameter sets to choose, and I'd really recommend to step back in that case and start the modeling process all over. There's an exception, here, though: there may be several local minima in the optimization yielding equal performance for practical purposes. Requiring also the choice among them to be stable may be an unnecessary strong requirement - but I don't know how to get out of this dilemma. Note that if not all models yield the same winning parameter set, you should not use outer loop estimates as generalization error here: If you claim generalization error for parameters $p$, all surrogate models entering into the validation should actually use exactly these parameters. (Imagine someone told you they did a cross validation on model with C = 1 and linear kernel and you find out some splits were evaluated with rbf kernel!) But unless there is no decision involved as all splits yielded the same parameters, this will break independence in the outer loop: the test data of each split already entered the decision which parameter set wins as it was training data in all other splits and thus used to optimize the parameters. Approach 2: treat hyperparameter tuning as part of the model training This approach bridges the perspectives of the "training algorithm developer" and applied user of the training algorithm. The training algorithm developer provides a "naked" training algorithm model = train_naked (trainingdata, hyperparameters). As the applied user needs tunedmodel = train_tuned (trainingdata) which also takes care of fixing the hyperparameters. train_tuned can be implemented e.g. by wrapping a cross validation-based optimizer around the naked training algorithm train_naked. train_tuned can then be used like any other training algorithm that does not require hyperparameter input, e.g. its output tunedmodel can be subjected to cross validation. Now the hyperparameters are checked for their stability just like the "normal" parameters should be checked for stability as part of the evaluation of the cross validation. This is actually what you do and evaluate in the nested cross validation if you average performance of all winning models regardless of their individual parameter sets. What's the difference? We possibly end up with different final models taking those 2 approaches: the final model in approach 1 will be train_naked (all data, hyperparameters from optimization) whereas approach 2 will use train_tuned (all data) and - as that runs the hyperparameter optimization again on the larger data set - this may end up with a different set of hyperparameters. But again the same logic applies: if we find that the final model has substantially different parameters from the cross validation surrogate models, that's a symptom of assumption 1 being violated. So IMHO, again we do not have a conflict but rather a check on whether our (implicit) assumptions are justified. And if they aren't, we anyways should not bet too much on having a good estimate of the performance of that final model. I have the impression (also from seeing the number of similar questions/confusions here on CV) that many people think of nested cross validation doing approach 1. But generalization error is usually estimated according to approach 2, so that's the way to go for the final model as well. Iris example Summary: The optimization is basically pointless. The available sample size does not allow distinctions between the performance of any of the parameter sets here. From the application point of view, however, the conclusion is that it doesn't matter which of the 4 parameter sets you choose - which isn't all that bad news: you found a comparatively stable plateau of parameters. Here comes the advantage of the proper nested validation of the tuned model: while you're not able to claim that the it is the optimal model, your're still able to claim that the model built on the whole data using approach 2 will have about 97 % accuracy (95 % confidence interval for 145 correct out of 150 test cases: 92 - 99 %) Note that also approach 1 isn't as far off as it seems - see below: your optimization accidentally missed a comparatively clear "winner" because of ties (that's actually another very telltale symptom of the sample size problem). While I'm not deep enough into SVMs to "see" that C = 1 should be a good choice here, I'd go with the more restrictive linear kernel. Also, as you did the optimization, there's nothing wrong with choosing the winning parameter set even if you are aware that all parameter sets lead to practically equal performance. In future, however, consider whether your experience yields rough guesstimates of what performance you can expect and roughly what model would be a good choice. Then build that model (with manually fixed hyperparameters) and calculate a confidence interval for its performance. Use this to decide whether trying to optimize is sensible at all. (I may add that I'm mostly working with data where getting 10 more independent cases is not easy - if you are in a field with large independent sample sizes, things look much better for you) long version: As for the example results on the iris data set. iris has 150 cases, SVM with a grid of 2 x 2 parameters (2 kernels, 2 orders of magnitude for the penalty C) are considered. The inner loop has splits of 129 (2x) and 132 (6x) cases. The "best" parameter set is undecided between linear or rbf kernel, both with C = 1. However, the inner test accuracies are all (including the always loosing C = 10) within 94 - 98.5 % observed accuracy. The largest difference we have in one of the splits is 3 vs. 8 errors for rbf with C = 1 vs. 10. There's no way this is a significant difference. I don't know how to extract the predictions for the individual cases in the CV, but even assuming that the 3 errors were shared, and the C = 10 model made additional 5 errors: > table (rbf1, rbf10) rbf10 rbf1 correct wrong correct 124 5 wrong 0 3 > mcnemar.exact(rbf1, rbf10) Exact McNemar test (with central confidence intervals) data: rbf1 and rbf10 b = 5, c = 0, p-value = 0.0625 alternative hypothesis: true odds ratio is not equal to 1 Remember that there are 6 pairwise comparisons in the 2 x 2 grid, so we'd need to correct for multiple comparisons as well. Approach 1 In 3 of the 4 outer splits where rbf "won" over the linear kernel, they actually had the same estimated accuracy (I guess min in case of ties returns the first suitable index). Changing the grid to params = {'kernel':['linear', 'rbf'],'C':[1,10]} yields ({'kernel': 'linear', 'C': 1}, 0.95238095238095233, 0.97674418604651159) ({'kernel': 'rbf', 'C': 1}, 0.95238095238095233, 0.98449612403100772) ({'kernel': 'linear', 'C': 1}, 1.0, 0.97727272727272729) ({'kernel': 'linear', 'C': 1}, 0.94444444444444442, 0.98484848484848486) ({'kernel': 'linear', 'C': 1}, 0.94444444444444442, 0.98484848484848486) ({'kernel': 'linear', 'C': 1}, 1.0, 0.98484848484848486) ({'kernel': 'linear', 'C': 1}, 1.0, 0.96212121212121215) Approach 2: Here, clf is your final model. With random_state = 2, rbf with C = 1 wins: In [310]: clf.grid_scores_ [...snip warning...] Out[310]: [mean: 0.97333, std: 0.00897, params: {'kernel': 'linear', 'C': 1}, mean: 0.98000, std: 0.02773, params: {'kernel': 'rbf', 'C': 1}, mean: 0.96000, std: 0.03202, params: {'kernel': 'linear', 'C': 10}, mean: 0.95333, std: 0.01791, params: {'kernel': 'rbf', 'C': 10}] (happens about 1 in 5 times, 1 in 6 times linear and rbf with C = 1 are tied on rank 1)
How to get hyper parameters in nested cross validation? (I'm sure I wrote most of this already in some answer - but can't find it right now. If anyone stumbles across that answer, please link it). I see 2 slightly different approaches here, which I think a
10,126
How to get hyper parameters in nested cross validation?
I have read your question and the answer above 2 times (1st time 3 month ago). I'm interested and also want to find the absolute appropriate way to do cross-validation for my data. After a lot of thinking & reading, it seems that I find the holes and here is my fix: To explain my confusion, let me try to walk through the model selection with nested cross validation method step by step. Create an outer CV loop with K-Fold. This will be used to estimate the performance of the hyper-parameters that "won" each inner CV loops. Use GridSearchCV to create an inner CV loop where in each inner loop, GSCV goes through all possible combinations of the parameter space and comes up with the best set of parameters. (Note: here I assume: data for inner loop = training data for outer loop. You may ask: why ? Answer: https://stackoverflow.com/questions/42228735/scikit-learn-gridsearchcv-with-multiple-repetitions/42230764#42230764 read the answer section by Vivek Kumar step 4) After GSCV found the "best parameters" in the inner loop (let's call it inner winner), it is tested with the test set in the outer loop to get an estimation of performance (let's call it outer_fold_score1). The outer loop then updates to the next fold as the test set and the rest as training set (to evaluate the "inner winner" on outer loop), the "inner winner" is tested again with the new test set (outer_fold_score2). Then again the outer loop updates to the next fold until the loop is completed. Scores from each fold (outer_fold_score 1,2..) will be average to get the score of the "inner winner" for the outer loop (outer_score) The outer loop then updates to the next fold as the test set and the rest as training set (to find the next "inner winner" , and 1- 4 repeats (note that when we repeat 1 we don't create the new K-fold but we use the same outer Kfold every time). With each of 1-4 cycle, we get a "best parameters" (or "inner winner") with an outer_score. The one with the best outer_score will be the winner of the winners Reasoning: Basically your question concerns that there are many "winning parameters" for the outer loop. The thing is u didn't complete the outer loop to evaluate and find the "outer winner". Your 4th step only evaluate the "inner winner" in 1 fold in the outer loop, but u didn't "loop it". Therefore I need to replace it with my 4th step - "loop" the evaluation step in the outer loop and get the outer score (by averaging) Your 5th step did do the "looping" job in the outer loop, but it's just for building another "inner winner". It didn't loop the "evaluation" of this "inner winner" in the outer loop
How to get hyper parameters in nested cross validation?
I have read your question and the answer above 2 times (1st time 3 month ago). I'm interested and also want to find the absolute appropriate way to do cross-validation for my data. After a lot of thin
How to get hyper parameters in nested cross validation? I have read your question and the answer above 2 times (1st time 3 month ago). I'm interested and also want to find the absolute appropriate way to do cross-validation for my data. After a lot of thinking & reading, it seems that I find the holes and here is my fix: To explain my confusion, let me try to walk through the model selection with nested cross validation method step by step. Create an outer CV loop with K-Fold. This will be used to estimate the performance of the hyper-parameters that "won" each inner CV loops. Use GridSearchCV to create an inner CV loop where in each inner loop, GSCV goes through all possible combinations of the parameter space and comes up with the best set of parameters. (Note: here I assume: data for inner loop = training data for outer loop. You may ask: why ? Answer: https://stackoverflow.com/questions/42228735/scikit-learn-gridsearchcv-with-multiple-repetitions/42230764#42230764 read the answer section by Vivek Kumar step 4) After GSCV found the "best parameters" in the inner loop (let's call it inner winner), it is tested with the test set in the outer loop to get an estimation of performance (let's call it outer_fold_score1). The outer loop then updates to the next fold as the test set and the rest as training set (to evaluate the "inner winner" on outer loop), the "inner winner" is tested again with the new test set (outer_fold_score2). Then again the outer loop updates to the next fold until the loop is completed. Scores from each fold (outer_fold_score 1,2..) will be average to get the score of the "inner winner" for the outer loop (outer_score) The outer loop then updates to the next fold as the test set and the rest as training set (to find the next "inner winner" , and 1- 4 repeats (note that when we repeat 1 we don't create the new K-fold but we use the same outer Kfold every time). With each of 1-4 cycle, we get a "best parameters" (or "inner winner") with an outer_score. The one with the best outer_score will be the winner of the winners Reasoning: Basically your question concerns that there are many "winning parameters" for the outer loop. The thing is u didn't complete the outer loop to evaluate and find the "outer winner". Your 4th step only evaluate the "inner winner" in 1 fold in the outer loop, but u didn't "loop it". Therefore I need to replace it with my 4th step - "loop" the evaluation step in the outer loop and get the outer score (by averaging) Your 5th step did do the "looping" job in the outer loop, but it's just for building another "inner winner". It didn't loop the "evaluation" of this "inner winner" in the outer loop
How to get hyper parameters in nested cross validation? I have read your question and the answer above 2 times (1st time 3 month ago). I'm interested and also want to find the absolute appropriate way to do cross-validation for my data. After a lot of thin
10,127
How to get hyper parameters in nested cross validation?
You do not use nested cross validation to select the hyper parameters of the algorithm, this method is used for estimating the generalisation error of your model building procedure. Where by model building procedure I intend all the steps you applied to reach the final model you are going to be using on field. A model building procedure could be composed by the rules you applied to decide which preprocessing to apply to the data, which feature to use and finally which hyper parameters to use. Think of this as a sort of "meta-algorithm" that receives as input a particular dataset $D$ and produces as output an "algorithm", composed of a fixed set of preprocessing transformations, features and finally hyper parameters values. For example let's say you have $X , y$ as design matrix and target and you want to train a classifier: 1. that uses only the first $x$ features in $X$ that have highest correlation with $y$. 2. you choose the hyper parameters values by minimisation of a 10-fold cross validation error estimate. If you apply these two step to a particular pair of $X', y'$ you will obtain a specific algorithm with a definite set of features and fixed hyper parameters which will not necessarily be the same of the one you would obtain for $X, y$ although the model building procedure would be identical i.e.: steps 1 + 2 which are not tied to any particular dataset. Let's say you did all of the above without having split your data into train-test because you have a small dataset, how do you estimate the generalisation error of the classifier you just created? Can you use the best error you found in the cross validation at step 2 ? No, the first big problem is in step 1 where you use all the data to select the features to use. Therefore even when you do the cross validation in step 2, the features will already have seen and remember some information present in the test fold at every cross validation run. The result will be an overly optimistic estimate of the test error and this is called feature selection bias. To account for this in your estimation you would need to put the feature selection step inside the cross validation loop of step 2. Ok, now are we good? Is the best error found in the cross validation with feature selection step inside the loop a fair estimate of the generalisation error? In theory the answer is still no, the problem is that your hyper parameters have been chosen to minimise the cross validation error on the specific dataset at your disposal, so in a certain sense you are fitting the hyper parameters to your data with the risk of over-fitting them , and this is called model selection bias. But is this a concern in practice? It depends by the specific application: it is likely to become more severe, as overfitting in training, when dataset is small and the number of hyper parameters to be tuned is relatively large. To account for this when estimating the generalisation error you would apply a nested cross validation as you described, that would then give you a correct estimate of your generalisation error. Finally to answer your last question, after having a fair estimate of your “model building procedure” generalisation error with a nested cross validation, you would simply apply the procedure (step 1+2) to your entire dataset obtaining a model with a fixed set of feature and set hyper parameters values, but keeping in mind that the error we expect this model to have on unseen data is the nested cross validation estimate.
How to get hyper parameters in nested cross validation?
You do not use nested cross validation to select the hyper parameters of the algorithm, this method is used for estimating the generalisation error of your model building procedure. Where by model bui
How to get hyper parameters in nested cross validation? You do not use nested cross validation to select the hyper parameters of the algorithm, this method is used for estimating the generalisation error of your model building procedure. Where by model building procedure I intend all the steps you applied to reach the final model you are going to be using on field. A model building procedure could be composed by the rules you applied to decide which preprocessing to apply to the data, which feature to use and finally which hyper parameters to use. Think of this as a sort of "meta-algorithm" that receives as input a particular dataset $D$ and produces as output an "algorithm", composed of a fixed set of preprocessing transformations, features and finally hyper parameters values. For example let's say you have $X , y$ as design matrix and target and you want to train a classifier: 1. that uses only the first $x$ features in $X$ that have highest correlation with $y$. 2. you choose the hyper parameters values by minimisation of a 10-fold cross validation error estimate. If you apply these two step to a particular pair of $X', y'$ you will obtain a specific algorithm with a definite set of features and fixed hyper parameters which will not necessarily be the same of the one you would obtain for $X, y$ although the model building procedure would be identical i.e.: steps 1 + 2 which are not tied to any particular dataset. Let's say you did all of the above without having split your data into train-test because you have a small dataset, how do you estimate the generalisation error of the classifier you just created? Can you use the best error you found in the cross validation at step 2 ? No, the first big problem is in step 1 where you use all the data to select the features to use. Therefore even when you do the cross validation in step 2, the features will already have seen and remember some information present in the test fold at every cross validation run. The result will be an overly optimistic estimate of the test error and this is called feature selection bias. To account for this in your estimation you would need to put the feature selection step inside the cross validation loop of step 2. Ok, now are we good? Is the best error found in the cross validation with feature selection step inside the loop a fair estimate of the generalisation error? In theory the answer is still no, the problem is that your hyper parameters have been chosen to minimise the cross validation error on the specific dataset at your disposal, so in a certain sense you are fitting the hyper parameters to your data with the risk of over-fitting them , and this is called model selection bias. But is this a concern in practice? It depends by the specific application: it is likely to become more severe, as overfitting in training, when dataset is small and the number of hyper parameters to be tuned is relatively large. To account for this when estimating the generalisation error you would apply a nested cross validation as you described, that would then give you a correct estimate of your generalisation error. Finally to answer your last question, after having a fair estimate of your “model building procedure” generalisation error with a nested cross validation, you would simply apply the procedure (step 1+2) to your entire dataset obtaining a model with a fixed set of feature and set hyper parameters values, but keeping in mind that the error we expect this model to have on unseen data is the nested cross validation estimate.
How to get hyper parameters in nested cross validation? You do not use nested cross validation to select the hyper parameters of the algorithm, this method is used for estimating the generalisation error of your model building procedure. Where by model bui
10,128
How can one empirically demonstrate in R which cross-validation methods the AIC and BIC are equivalent to?
In an attempt to partially answer my own question, I read Wikipedia's description of leave-one-out cross validation involves using a single observation from the original sample as the validation data, and the remaining observations as the training data. This is repeated such that each observation in the sample is used once as the validation data. In R code, I suspect that that would mean something like this... resid <- rep(NA, Nobs) for (lcv in 1:Nobs) { data.loo <- data[-lcv,] #drop the data point that will be used for validation loo.model <- lm(y ~ a+b,data=data.loo) #construct a model without that data point resid[lcv] <- data[lcv,"y"] - (coef(loo.model)[1] + coef(loo.model)[2]*data[lcv,"a"]+coef(loo.model)[3]*data[lcv,"b"]) #compare the observed value to the value predicted by the loo model for each possible observation, and store that value } ... is supposed to yield values in resid that is related to the AIC. In practice the sum of squared residuals from each iteration of the LOO loop detailed above is a good predictor of the AIC for the notable.seeds, r^2 = .9776. But, elsewhere a contributor suggested that LOO should be asymptotically equivalent to the AIC (at least for linear models), so I'm a little disappointed that r^2 isn't closer to 1. Obviously this isn't really an answer - more like additional code to try to encourage someone to try to provide a better answer. Addendum: Since AIC and BIC for models of fixed sample size only vary by a constant, the correlation of BIC to squared residuals is the same as the correaltion of AIC to squared residuals, so the approach I took above appears to be fruitless.
How can one empirically demonstrate in R which cross-validation methods the AIC and BIC are equivale
In an attempt to partially answer my own question, I read Wikipedia's description of leave-one-out cross validation involves using a single observation from the original sample as the validation
How can one empirically demonstrate in R which cross-validation methods the AIC and BIC are equivalent to? In an attempt to partially answer my own question, I read Wikipedia's description of leave-one-out cross validation involves using a single observation from the original sample as the validation data, and the remaining observations as the training data. This is repeated such that each observation in the sample is used once as the validation data. In R code, I suspect that that would mean something like this... resid <- rep(NA, Nobs) for (lcv in 1:Nobs) { data.loo <- data[-lcv,] #drop the data point that will be used for validation loo.model <- lm(y ~ a+b,data=data.loo) #construct a model without that data point resid[lcv] <- data[lcv,"y"] - (coef(loo.model)[1] + coef(loo.model)[2]*data[lcv,"a"]+coef(loo.model)[3]*data[lcv,"b"]) #compare the observed value to the value predicted by the loo model for each possible observation, and store that value } ... is supposed to yield values in resid that is related to the AIC. In practice the sum of squared residuals from each iteration of the LOO loop detailed above is a good predictor of the AIC for the notable.seeds, r^2 = .9776. But, elsewhere a contributor suggested that LOO should be asymptotically equivalent to the AIC (at least for linear models), so I'm a little disappointed that r^2 isn't closer to 1. Obviously this isn't really an answer - more like additional code to try to encourage someone to try to provide a better answer. Addendum: Since AIC and BIC for models of fixed sample size only vary by a constant, the correlation of BIC to squared residuals is the same as the correaltion of AIC to squared residuals, so the approach I took above appears to be fruitless.
How can one empirically demonstrate in R which cross-validation methods the AIC and BIC are equivale In an attempt to partially answer my own question, I read Wikipedia's description of leave-one-out cross validation involves using a single observation from the original sample as the validation
10,129
Gaussian Ratio Distribution: Derivatives wrt underlying $\mu$'s and $\sigma^2$s
Some related papers: Wiki: `http://en.wikipedia.org/wiki/Ratio_distribution http://www.jstatsoft.org/v16/i04/ http://link.springer.com/article/10.1007/s00362-012-0429-2 http://mrvar.fdv.uni-lj.si/pub/mz/mz1.1/cedilnik.pdf
Gaussian Ratio Distribution: Derivatives wrt underlying $\mu$'s and $\sigma^2$s
Some related papers: Wiki: `http://en.wikipedia.org/wiki/Ratio_distribution http://www.jstatsoft.org/v16/i04/ http://link.springer.com/article/10.1007/s00362-012-0429-2 http://mrvar.fdv.uni-lj.si/pub
Gaussian Ratio Distribution: Derivatives wrt underlying $\mu$'s and $\sigma^2$s Some related papers: Wiki: `http://en.wikipedia.org/wiki/Ratio_distribution http://www.jstatsoft.org/v16/i04/ http://link.springer.com/article/10.1007/s00362-012-0429-2 http://mrvar.fdv.uni-lj.si/pub/mz/mz1.1/cedilnik.pdf
Gaussian Ratio Distribution: Derivatives wrt underlying $\mu$'s and $\sigma^2$s Some related papers: Wiki: `http://en.wikipedia.org/wiki/Ratio_distribution http://www.jstatsoft.org/v16/i04/ http://link.springer.com/article/10.1007/s00362-012-0429-2 http://mrvar.fdv.uni-lj.si/pub
10,130
Gaussian Ratio Distribution: Derivatives wrt underlying $\mu$'s and $\sigma^2$s
Consider using a symbolic math package like Mathematica ,if you have a license, or Sage if you don't. If your just doing numerical work, you might also just consider numerical differentiation. While tedious, it does look straight forward. That is, all of the functions involved have easy to compute derivatives. You might use numerical differentiation to test your result when you are done to be sure you have the right formula.
Gaussian Ratio Distribution: Derivatives wrt underlying $\mu$'s and $\sigma^2$s
Consider using a symbolic math package like Mathematica ,if you have a license, or Sage if you don't. If your just doing numerical work, you might also just consider numerical differentiation. Whil
Gaussian Ratio Distribution: Derivatives wrt underlying $\mu$'s and $\sigma^2$s Consider using a symbolic math package like Mathematica ,if you have a license, or Sage if you don't. If your just doing numerical work, you might also just consider numerical differentiation. While tedious, it does look straight forward. That is, all of the functions involved have easy to compute derivatives. You might use numerical differentiation to test your result when you are done to be sure you have the right formula.
Gaussian Ratio Distribution: Derivatives wrt underlying $\mu$'s and $\sigma^2$s Consider using a symbolic math package like Mathematica ,if you have a license, or Sage if you don't. If your just doing numerical work, you might also just consider numerical differentiation. Whil
10,131
Gaussian Ratio Distribution: Derivatives wrt underlying $\mu$'s and $\sigma^2$s
This is the sort of problem that is very easy numerically, and less error prone as well. Since you say you only need the signs, I assume that accurate numerical approximations are more than sufficient for your needs. Here is some code with an example of the derivative against $\mu_x$: pratio <- function(z, mu_x=1.0, mu_y=1.0,var_x=0.2, var_y=0.2) { sd_x <- sqrt(var_x) sd_y <- sqrt(var_y) a <- function(z) { sqrt(z*z/var_x+1/var_y) } b <- function(z) { mu_x*z/var_x + mu_y/var_y } c <- mu_x^2/var_x + mu_y^2/var_y d <- function(z) { exp((b(z)^2 - c*a(z)^2)/(2*a(z)^2)) } t1 <- (b(z)*d(z)/a(z)^3) t2 <- 1.0/(sqrt(2*pi)*sd_x*sd_y) t3 <- pnorm(b(z)/a(z)) - pnorm(-b(z)/a(z)) t4 <- 1.0/(a(z)^2*pi*sd_x*sd_y) t5 <- exp(-c/2.0) return(t1*t2*t3 + t4*t5) } # Integrates to 1, so probably no typos. print(integrate(pratio, lower=-Inf, upper=Inf)) cdf_ratio <- function(x, mu_x=1.0, mu_y=1.0,var_x=0.2, var_y=0.2) { integrate(function(x) {pratio(x, mu_x, mu_y, var_x, var_y)}, lower=-Inf, upper=x, abs.tol=.Machine$double.eps)$value } # Numerical differentiation here is very easy: derv_mu_x <- function(x, mu_x=1.0, mu_y=1.0,var_x=0.2, var_y=0.2) { eps <- sqrt(.Machine$double.eps) left <- cdf_ratio(x, mu_x+eps, mu_y, var_x, var_y) right <- cdf_ratio(x, mu_x-eps, mu_y, var_x, var_y) return((left - right)/(2*eps)) }
Gaussian Ratio Distribution: Derivatives wrt underlying $\mu$'s and $\sigma^2$s
This is the sort of problem that is very easy numerically, and less error prone as well. Since you say you only need the signs, I assume that accurate numerical approximations are more than sufficient
Gaussian Ratio Distribution: Derivatives wrt underlying $\mu$'s and $\sigma^2$s This is the sort of problem that is very easy numerically, and less error prone as well. Since you say you only need the signs, I assume that accurate numerical approximations are more than sufficient for your needs. Here is some code with an example of the derivative against $\mu_x$: pratio <- function(z, mu_x=1.0, mu_y=1.0,var_x=0.2, var_y=0.2) { sd_x <- sqrt(var_x) sd_y <- sqrt(var_y) a <- function(z) { sqrt(z*z/var_x+1/var_y) } b <- function(z) { mu_x*z/var_x + mu_y/var_y } c <- mu_x^2/var_x + mu_y^2/var_y d <- function(z) { exp((b(z)^2 - c*a(z)^2)/(2*a(z)^2)) } t1 <- (b(z)*d(z)/a(z)^3) t2 <- 1.0/(sqrt(2*pi)*sd_x*sd_y) t3 <- pnorm(b(z)/a(z)) - pnorm(-b(z)/a(z)) t4 <- 1.0/(a(z)^2*pi*sd_x*sd_y) t5 <- exp(-c/2.0) return(t1*t2*t3 + t4*t5) } # Integrates to 1, so probably no typos. print(integrate(pratio, lower=-Inf, upper=Inf)) cdf_ratio <- function(x, mu_x=1.0, mu_y=1.0,var_x=0.2, var_y=0.2) { integrate(function(x) {pratio(x, mu_x, mu_y, var_x, var_y)}, lower=-Inf, upper=x, abs.tol=.Machine$double.eps)$value } # Numerical differentiation here is very easy: derv_mu_x <- function(x, mu_x=1.0, mu_y=1.0,var_x=0.2, var_y=0.2) { eps <- sqrt(.Machine$double.eps) left <- cdf_ratio(x, mu_x+eps, mu_y, var_x, var_y) right <- cdf_ratio(x, mu_x-eps, mu_y, var_x, var_y) return((left - right)/(2*eps)) }
Gaussian Ratio Distribution: Derivatives wrt underlying $\mu$'s and $\sigma^2$s This is the sort of problem that is very easy numerically, and less error prone as well. Since you say you only need the signs, I assume that accurate numerical approximations are more than sufficient
10,132
How to understand degrees of freedom?
This is a subtle question. It takes a thoughtful person not to understand those quotations! Although they are suggestive, it turns out that none of them is exactly or generally correct. I haven't the time (and there isn't the space here) to give a full exposition, but I would like to share one approach and an insight that it suggests. Where does the concept of degrees of freedom (DF) arise? The contexts in which it's found in elementary treatments are: The Student t-test and its variants such as the Welch or Satterthwaite solutions to the Behrens-Fisher problem (where two populations have different variances). The Chi-squared distribution (defined as a sum of squares of independent standard Normals), which is implicated in the sampling distribution of the variance. The F-test (of ratios of estimated variances). The Chi-squared test, comprising its uses in (a) testing for independence in contingency tables and (b) testing for goodness of fit of distributional estimates. In spirit, these tests run a gamut from being exact (the Student t-test and F-test for Normal variates) to being good approximations (the Student t-test and the Welch/Satterthwaite tests for not-too-badly-skewed data) to being based on asymptotic approximations (the Chi-squared test). An interesting aspect of some of these is the appearance of non-integral "degrees of freedom" (the Welch/Satterthwaite tests and, as we will see, the Chi-squared test). This is of especial interest because it is the first hint that DF is not any of the things claimed of it. We can dispose right away of some of the claims in the question. Because "final calculation of a statistic" is not well-defined (it apparently depends on what algorithm one uses for the calculation), it can be no more than a vague suggestion and is worth no further criticism. Similarly, neither "number of independent scores that go into the estimate" nor "the number of parameters used as intermediate steps" are well-defined. "Independent pieces of information that go into [an] estimate" is difficult to deal with, because there are two different but intimately related senses of "independent" that can be relevant here. One is independence of random variables; the other is functional independence. As an example of the latter, suppose we collect morphometric measurements of subjects--say, for simplicity, the three side lengths $X$, $Y$, $Z$, surface areas $S=2(XY+YZ+ZX)$, and volumes $V=XYZ$ of a set of wooden blocks. The three side lengths can be considered independent random variables, but all five variables are dependent RVs. The five are also functionally dependent because the codomain (not the "domain"!) of the vector-valued random variable $(X,Y,Z,S,V)$ traces out a three-dimensional manifold in $\mathbb{R}^5$. (Thus, locally at any point $\omega\in\mathbb{R}^5$, there are two functions $f_\omega$ and $g_\omega$ for which $f_\omega(X(\psi),\ldots,V(\psi))=0$ and $g_\omega(X(\psi),\ldots,V(\psi))=0$ for points $\psi$ "near" $\omega$ and the derivatives of $f$ and $g$ evaluated at $\omega$ are linearly independent.) However--here's the kicker--for many probability measures on the blocks, subsets of the variables such as $(X,S,V)$ are dependent as random variables but functionally independent. Having been alerted by these potential ambiguities, let's hold up the Chi-squared goodness of fit test for examination, because (a) it's simple, (b) it's one of the common situations where people really do need to know about DF to get the p-value right and (c) it's often used incorrectly. Here's a brief synopsis of the least controversial application of this test: You have a collection of data values $(x_1, \ldots, x_n)$, considered as a sample of a population. You have estimated some parameters $\theta_1, \ldots, \theta_p$ of a distribution. For example, you estimated the mean $\theta_1$ and standard deviation $\theta_2 = \theta_p$ of a Normal distribution, hypothesizing that the population is normally distributed but not knowing (in advance of obtaining the data) what $\theta_1$ or $\theta_2$ might be. In advance, you created a set of $k$ "bins" for the data. (It may be problematic when the bins are determined by the data, even though this is often done.) Using these bins, the data are reduced to the set of counts within each bin. Anticipating what the true values of $(\theta)$ might be, you have arranged it so (hopefully) each bin will receive approximately the same count. (Equal-probability binning assures the chi-squared distribution really is a good approximation to the true distribution of the chi-squared statistic about to be described.) You have a lot of data--enough to assure that almost all bins ought to have counts of 5 or greater. (This, we hope, will enable the sampling distribution of the $\chi^2$ statistic to be approximated adequately by some $\chi^2$ distribution.) Using the parameter estimates, you can compute the expected count in each bin. The Chi-squared statistic is the sum of the ratios $$\frac{(\text{observed}-\text{expected})^2}{\text{expected}}.$$ This, many authorities tell us, should have (to a very close approximation) a Chi-squared distribution. But there's a whole family of such distributions. They are differentiated by a parameter $\nu$ often referred to as the "degrees of freedom." The standard reasoning about how to determine $\nu$ goes like this I have $k$ counts. That's $k$ pieces of data. But there are (functional) relationships among them. To start with, I know in advance that the sum of the counts must equal $n$. That's one relationship. I estimated two (or $p$, generally) parameters from the data. That's two (or $p$) additional relationships, giving $p+1$ total relationships. Presuming they (the parameters) are all (functionally) independent, that leaves only $k-p-1$ (functionally) independent "degrees of freedom": that's the value to use for $\nu$. The problem with this reasoning (which is the sort of calculation the quotations in the question are hinting at) is that it's wrong except when some special additional conditions hold. Moreover, those conditions have nothing to do with independence (functional or statistical), with numbers of "components" of the data, with the numbers of parameters, nor with anything else referred to in the original question. Let me show you with an example. (To make it as clear as possible, I'm using a small number of bins, but that's not essential.) Let's generate 20 independent and identically distributed (iid) standard Normal variates and estimate their mean and standard deviation with the usual formulas (mean = sum/count, etc.). To test goodness of fit, create four bins with cutpoints at the quartiles of a standard normal: -0.675, 0, +0.657, and use the bin counts to generate a Chi-squared statistic. Repeat as patience allows; I had time to do 10,000 repetitions. The standard wisdom about DF says we have 4 bins and 1+2 = 3 constraints, implying the distribution of these 10,000 Chi-squared statistics should follow a Chi-squared distribution with 1 DF. Here's the histogram: The dark blue line graphs the PDF of a $\chi^2(1)$ distribution--the one we thought would work--while the dark red line graphs that of a $\chi^2(2)$ distribution (which would be a good guess if someone were to tell you that $\nu=1$ is incorrect). Neither fits the data. You might expect the problem to be due to the small size of the data sets ($n$=20) or perhaps the small size of the number of bins. However, the problem persists even with very large datasets and larger numbers of bins: it is not merely a failure to reach an asymptotic approximation. Things went wrong because I violated two requirements of the Chi-squared test: You must use the Maximum Likelihood estimate of the parameters. (This requirement can, in practice, be slightly violated.) You must base that estimate on the counts, not on the actual data! (This is crucial.) The red histogram depicts the chi-squared statistics for 10,000 separate iterations, following these requirements. Sure enough, it visibly follows the $\chi^2(1)$ curve (with an acceptable amount of sampling error), as we had originally hoped. The point of this comparison--which I hope you have seen coming--is that the correct DF to use for computing the p-values depends on many things other than dimensions of manifolds, counts of functional relationships, or the geometry of Normal variates. There is a subtle, delicate interaction between certain functional dependencies, as found in mathematical relationships among quantities, and distributions of the data, their statistics, and the estimators formed from them. Accordingly, it cannot be the case that DF is adequately explainable in terms of the geometry of multivariate normal distributions, or in terms of functional independence, or as counts of parameters, or anything else of this nature. We are led to see, then, that "degrees of freedom" is merely a heuristic that suggests what the sampling distribution of a (t, Chi-squared, or F) statistic ought to be, but it is not dispositive. Belief that it is dispositive leads to egregious errors. (For instance, the top hit on Google when searching "chi squared goodness of fit" is a Web page from an Ivy League university that gets most of this completely wrong! In particular, a simulation based on its instructions shows that the chi-squared value it recommends as having 7 DF actually has 9 DF.) With this more nuanced understanding, it's worthwhile to re-read the Wikipedia article in question: in its details it gets things right, pointing out where the DF heuristic tends to work and where it is either an approximation or does not apply at all. A good account of the phenomenon illustrated here (unexpectedly high DF in Chi-squared GOF tests) appears in Volume II of Kendall & Stuart, 5th edition. I am grateful for the opportunity afforded by this question to lead me back to this wonderful text, which is full of such useful analyses. Edit (Jan 2017) Here is R code to produce the figure following "The standard wisdom about DF..." # # Simulate data, one iteration per column of `x`. # n <- 20 n.sim <- 1e4 bins <- qnorm(seq(0, 1, 1/4)) x <- matrix(rnorm(n*n.sim), nrow=n) # # Compute statistics. # m <- colMeans(x) s <- apply(sweep(x, 2, m), 2, sd) counts <- apply(matrix(as.numeric(cut(x, bins)), nrow=n), 2, tabulate, nbins=4) expectations <- mapply(function(m,s) n*diff(pnorm(bins, m, s)), m, s) chisquared <- colSums((counts - expectations)^2 / expectations) # # Plot histograms of means, variances, and chi-squared stats. The first # two confirm all is working as expected. # mfrow <- par("mfrow") par(mfrow=c(1,3)) red <- "#a04040" # Intended to show correct distributions blue <- "#404090" # To show the putative chi-squared distribution hist(m, freq=FALSE) curve(dnorm(x, sd=1/sqrt(n)), add=TRUE, col=red, lwd=2) hist(s^2, freq=FALSE) curve(dchisq(x*(n-1), df=n-1)*(n-1), add=TRUE, col=red, lwd=2) hist(chisquared, freq=FALSE, breaks=seq(0, ceiling(max(chisquared)), 1/4), xlim=c(0, 13), ylim=c(0, 0.55), col="#c0c0ff", border="#404040") curve(ifelse(x <= 0, Inf, dchisq(x, df=2)), add=TRUE, col=red, lwd=2) curve(ifelse(x <= 0, Inf, dchisq(x, df=1)), add=TRUE, col=blue, lwd=2) par(mfrow=mfrow)
How to understand degrees of freedom?
This is a subtle question. It takes a thoughtful person not to understand those quotations! Although they are suggestive, it turns out that none of them is exactly or generally correct. I haven't t
How to understand degrees of freedom? This is a subtle question. It takes a thoughtful person not to understand those quotations! Although they are suggestive, it turns out that none of them is exactly or generally correct. I haven't the time (and there isn't the space here) to give a full exposition, but I would like to share one approach and an insight that it suggests. Where does the concept of degrees of freedom (DF) arise? The contexts in which it's found in elementary treatments are: The Student t-test and its variants such as the Welch or Satterthwaite solutions to the Behrens-Fisher problem (where two populations have different variances). The Chi-squared distribution (defined as a sum of squares of independent standard Normals), which is implicated in the sampling distribution of the variance. The F-test (of ratios of estimated variances). The Chi-squared test, comprising its uses in (a) testing for independence in contingency tables and (b) testing for goodness of fit of distributional estimates. In spirit, these tests run a gamut from being exact (the Student t-test and F-test for Normal variates) to being good approximations (the Student t-test and the Welch/Satterthwaite tests for not-too-badly-skewed data) to being based on asymptotic approximations (the Chi-squared test). An interesting aspect of some of these is the appearance of non-integral "degrees of freedom" (the Welch/Satterthwaite tests and, as we will see, the Chi-squared test). This is of especial interest because it is the first hint that DF is not any of the things claimed of it. We can dispose right away of some of the claims in the question. Because "final calculation of a statistic" is not well-defined (it apparently depends on what algorithm one uses for the calculation), it can be no more than a vague suggestion and is worth no further criticism. Similarly, neither "number of independent scores that go into the estimate" nor "the number of parameters used as intermediate steps" are well-defined. "Independent pieces of information that go into [an] estimate" is difficult to deal with, because there are two different but intimately related senses of "independent" that can be relevant here. One is independence of random variables; the other is functional independence. As an example of the latter, suppose we collect morphometric measurements of subjects--say, for simplicity, the three side lengths $X$, $Y$, $Z$, surface areas $S=2(XY+YZ+ZX)$, and volumes $V=XYZ$ of a set of wooden blocks. The three side lengths can be considered independent random variables, but all five variables are dependent RVs. The five are also functionally dependent because the codomain (not the "domain"!) of the vector-valued random variable $(X,Y,Z,S,V)$ traces out a three-dimensional manifold in $\mathbb{R}^5$. (Thus, locally at any point $\omega\in\mathbb{R}^5$, there are two functions $f_\omega$ and $g_\omega$ for which $f_\omega(X(\psi),\ldots,V(\psi))=0$ and $g_\omega(X(\psi),\ldots,V(\psi))=0$ for points $\psi$ "near" $\omega$ and the derivatives of $f$ and $g$ evaluated at $\omega$ are linearly independent.) However--here's the kicker--for many probability measures on the blocks, subsets of the variables such as $(X,S,V)$ are dependent as random variables but functionally independent. Having been alerted by these potential ambiguities, let's hold up the Chi-squared goodness of fit test for examination, because (a) it's simple, (b) it's one of the common situations where people really do need to know about DF to get the p-value right and (c) it's often used incorrectly. Here's a brief synopsis of the least controversial application of this test: You have a collection of data values $(x_1, \ldots, x_n)$, considered as a sample of a population. You have estimated some parameters $\theta_1, \ldots, \theta_p$ of a distribution. For example, you estimated the mean $\theta_1$ and standard deviation $\theta_2 = \theta_p$ of a Normal distribution, hypothesizing that the population is normally distributed but not knowing (in advance of obtaining the data) what $\theta_1$ or $\theta_2$ might be. In advance, you created a set of $k$ "bins" for the data. (It may be problematic when the bins are determined by the data, even though this is often done.) Using these bins, the data are reduced to the set of counts within each bin. Anticipating what the true values of $(\theta)$ might be, you have arranged it so (hopefully) each bin will receive approximately the same count. (Equal-probability binning assures the chi-squared distribution really is a good approximation to the true distribution of the chi-squared statistic about to be described.) You have a lot of data--enough to assure that almost all bins ought to have counts of 5 or greater. (This, we hope, will enable the sampling distribution of the $\chi^2$ statistic to be approximated adequately by some $\chi^2$ distribution.) Using the parameter estimates, you can compute the expected count in each bin. The Chi-squared statistic is the sum of the ratios $$\frac{(\text{observed}-\text{expected})^2}{\text{expected}}.$$ This, many authorities tell us, should have (to a very close approximation) a Chi-squared distribution. But there's a whole family of such distributions. They are differentiated by a parameter $\nu$ often referred to as the "degrees of freedom." The standard reasoning about how to determine $\nu$ goes like this I have $k$ counts. That's $k$ pieces of data. But there are (functional) relationships among them. To start with, I know in advance that the sum of the counts must equal $n$. That's one relationship. I estimated two (or $p$, generally) parameters from the data. That's two (or $p$) additional relationships, giving $p+1$ total relationships. Presuming they (the parameters) are all (functionally) independent, that leaves only $k-p-1$ (functionally) independent "degrees of freedom": that's the value to use for $\nu$. The problem with this reasoning (which is the sort of calculation the quotations in the question are hinting at) is that it's wrong except when some special additional conditions hold. Moreover, those conditions have nothing to do with independence (functional or statistical), with numbers of "components" of the data, with the numbers of parameters, nor with anything else referred to in the original question. Let me show you with an example. (To make it as clear as possible, I'm using a small number of bins, but that's not essential.) Let's generate 20 independent and identically distributed (iid) standard Normal variates and estimate their mean and standard deviation with the usual formulas (mean = sum/count, etc.). To test goodness of fit, create four bins with cutpoints at the quartiles of a standard normal: -0.675, 0, +0.657, and use the bin counts to generate a Chi-squared statistic. Repeat as patience allows; I had time to do 10,000 repetitions. The standard wisdom about DF says we have 4 bins and 1+2 = 3 constraints, implying the distribution of these 10,000 Chi-squared statistics should follow a Chi-squared distribution with 1 DF. Here's the histogram: The dark blue line graphs the PDF of a $\chi^2(1)$ distribution--the one we thought would work--while the dark red line graphs that of a $\chi^2(2)$ distribution (which would be a good guess if someone were to tell you that $\nu=1$ is incorrect). Neither fits the data. You might expect the problem to be due to the small size of the data sets ($n$=20) or perhaps the small size of the number of bins. However, the problem persists even with very large datasets and larger numbers of bins: it is not merely a failure to reach an asymptotic approximation. Things went wrong because I violated two requirements of the Chi-squared test: You must use the Maximum Likelihood estimate of the parameters. (This requirement can, in practice, be slightly violated.) You must base that estimate on the counts, not on the actual data! (This is crucial.) The red histogram depicts the chi-squared statistics for 10,000 separate iterations, following these requirements. Sure enough, it visibly follows the $\chi^2(1)$ curve (with an acceptable amount of sampling error), as we had originally hoped. The point of this comparison--which I hope you have seen coming--is that the correct DF to use for computing the p-values depends on many things other than dimensions of manifolds, counts of functional relationships, or the geometry of Normal variates. There is a subtle, delicate interaction between certain functional dependencies, as found in mathematical relationships among quantities, and distributions of the data, their statistics, and the estimators formed from them. Accordingly, it cannot be the case that DF is adequately explainable in terms of the geometry of multivariate normal distributions, or in terms of functional independence, or as counts of parameters, or anything else of this nature. We are led to see, then, that "degrees of freedom" is merely a heuristic that suggests what the sampling distribution of a (t, Chi-squared, or F) statistic ought to be, but it is not dispositive. Belief that it is dispositive leads to egregious errors. (For instance, the top hit on Google when searching "chi squared goodness of fit" is a Web page from an Ivy League university that gets most of this completely wrong! In particular, a simulation based on its instructions shows that the chi-squared value it recommends as having 7 DF actually has 9 DF.) With this more nuanced understanding, it's worthwhile to re-read the Wikipedia article in question: in its details it gets things right, pointing out where the DF heuristic tends to work and where it is either an approximation or does not apply at all. A good account of the phenomenon illustrated here (unexpectedly high DF in Chi-squared GOF tests) appears in Volume II of Kendall & Stuart, 5th edition. I am grateful for the opportunity afforded by this question to lead me back to this wonderful text, which is full of such useful analyses. Edit (Jan 2017) Here is R code to produce the figure following "The standard wisdom about DF..." # # Simulate data, one iteration per column of `x`. # n <- 20 n.sim <- 1e4 bins <- qnorm(seq(0, 1, 1/4)) x <- matrix(rnorm(n*n.sim), nrow=n) # # Compute statistics. # m <- colMeans(x) s <- apply(sweep(x, 2, m), 2, sd) counts <- apply(matrix(as.numeric(cut(x, bins)), nrow=n), 2, tabulate, nbins=4) expectations <- mapply(function(m,s) n*diff(pnorm(bins, m, s)), m, s) chisquared <- colSums((counts - expectations)^2 / expectations) # # Plot histograms of means, variances, and chi-squared stats. The first # two confirm all is working as expected. # mfrow <- par("mfrow") par(mfrow=c(1,3)) red <- "#a04040" # Intended to show correct distributions blue <- "#404090" # To show the putative chi-squared distribution hist(m, freq=FALSE) curve(dnorm(x, sd=1/sqrt(n)), add=TRUE, col=red, lwd=2) hist(s^2, freq=FALSE) curve(dchisq(x*(n-1), df=n-1)*(n-1), add=TRUE, col=red, lwd=2) hist(chisquared, freq=FALSE, breaks=seq(0, ceiling(max(chisquared)), 1/4), xlim=c(0, 13), ylim=c(0, 0.55), col="#c0c0ff", border="#404040") curve(ifelse(x <= 0, Inf, dchisq(x, df=2)), add=TRUE, col=red, lwd=2) curve(ifelse(x <= 0, Inf, dchisq(x, df=1)), add=TRUE, col=blue, lwd=2) par(mfrow=mfrow)
How to understand degrees of freedom? This is a subtle question. It takes a thoughtful person not to understand those quotations! Although they are suggestive, it turns out that none of them is exactly or generally correct. I haven't t
10,133
How to understand degrees of freedom?
Or simply: the number of elements in a numerical array that you're allowed to change so that the value of the statistic remains unchanged. # for instance if: x + y + z = 10 you can change, for instance, x and y at random, but you cannot change z (you can, but not at random, therefore you're not free to change it - see Harvey's comment), 'cause you'll change the value of the statistic (Σ = 10). So, in this case df = 2.
How to understand degrees of freedom?
Or simply: the number of elements in a numerical array that you're allowed to change so that the value of the statistic remains unchanged. # for instance if: x + y + z = 10 you can change, for instan
How to understand degrees of freedom? Or simply: the number of elements in a numerical array that you're allowed to change so that the value of the statistic remains unchanged. # for instance if: x + y + z = 10 you can change, for instance, x and y at random, but you cannot change z (you can, but not at random, therefore you're not free to change it - see Harvey's comment), 'cause you'll change the value of the statistic (Σ = 10). So, in this case df = 2.
How to understand degrees of freedom? Or simply: the number of elements in a numerical array that you're allowed to change so that the value of the statistic remains unchanged. # for instance if: x + y + z = 10 you can change, for instan
10,134
How to understand degrees of freedom?
The concept is not at all difficult to make mathematical precise given a bit of general knowledge of $n$-dimensional Euclidean geometry, subspaces and orthogonal projections. If $P$ is an orthogonal projection from $\mathbb{R}^n$ to a $p$-dimensional subspace $L$ and $x$ is an arbitrary $n$-vector then $Px$ is in $L$, $x - Px$ and $Px$ are orthogonal and $x - Px \in L^{\perp}$ is in the orthogonal complement of $L$. The dimension of this orthogonal complement, $L^{\perp}$, is $n-p$. If $x$ is free to vary in an $n$-dimensional space then $x - Px$ is free to vary in an $n-p$ dimensional space. For this reason we say that $x - Px$ has $n-p$ degrees of freedom. These considerations are important to statistics because if $X$ is an $n$-dimensional random vector and $L$ is a model of its mean, that is, the mean vector $E(X)$ is in $L$, then we call $X-PX$ the vector of residuals, and we use the residuals to estimate the variance. The vector of residuals has $n-p$ degrees of freedom, that is, it is constrained to a subspace of dimension $n-p$. If the coordinates of $X$ are independent and normally distributed with the same variance $\sigma^2$ then The vectors $PX$ and $X - PX$ are independent. If $E(X) \in L$ the distribution of the squared norm of the vector of residuals $||X - PX||^2$ is a $\chi^2$-distribution with scale parameter $\sigma^2$ and another parameter that happens to be the degrees of freedom $n-p$. The sketch of proof of these facts is given below. The two results are central for the further development of the statistical theory based on the normal distribution. Note also that this is why the $\chi^2$-distribution has the parametrization it has. It is also a $\Gamma$-distribution with scale parameter $2\sigma^2$ and shape parameter $(n-p)/2$, but in the context above it is natural to parametrize in terms of the degrees of freedom. I must admit that I don't find any of the paragraphs cited from the Wikipedia article particularly enlightening, but they are not really wrong or contradictory either. They say in an imprecise, and in a general loose sense, that when we compute the estimate of the variance parameter, but do so based on residuals, we base the computation on a vector that is only free to vary in a space of dimension $n-p$. Beyond the theory of linear normal models the use of the concept of degrees of freedom can be confusing. It is, for instance, used in the parametrization of the $\chi^2$-distribution whether or not there is a reference to anything that could have any degrees of freedom. When we consider statistical analysis of categorical data there can be some confusion about whether the "independent pieces" should be counted before or after a tabulation. Furthermore, for constraints, even for normal models, that are not subspace constraints, it is not obvious how to extend the concept of degrees of freedom. Various suggestions exist typically under the name of effective degrees of freedom. Before any other usages and meanings of degrees of freedom is considered I will strongly recommend to become confident with it in the context of linear normal models. A reference dealing with this model class is A First Course in Linear Model Theory, and there are additional references in the preface of the book to other classical books on linear models. Proof of the results above: Let $\xi = E(X)$, note that the variance matrix is $\sigma^2 I$ and choose an orthonormal basis $z_1, \ldots, z_p$ of $L$ and an orthonormal basis $z_{p+1}, \ldots, z_n$ of $L^{\perp}$. Then $z_1, \ldots, z_n$ is an orthonormal basis of $\mathbb{R}^n$. Let $\tilde{X}$ denote the $n$-vector of the coefficients of $X$ in this basis, that is $$\tilde{X}_i = z_i^T X.$$ This can also be written as $\tilde{X} = Z^T X$ where $Z$ is the orthogonal matrix with the $z_i$'s in the columns. Then we have to use that $\tilde{X}$ has a normal distribution with mean $Z^T \xi$ and, because $Z$ is orthogonal, variance matrix $\sigma^2 I$. This follows from general linear transformation results of the normal distribution. The basis was chosen so that the coefficients of $PX$ are $\tilde{X}_i$ for $i= 1, \ldots, p$, and the coefficients of $X - PX$ are $\tilde{X}_i$ for $i= p+1, \ldots, n$. Since the coefficients are uncorrelated and jointly normal, they are independent, and this implies that $$PX = \sum_{i=1}^p \tilde{X}_i z_i$$ and $$X - PX = \sum_{i=p+1}^n \tilde{X}_i z_i$$ are independent. Moreover, $$||X - PX||^2 = \sum_{i=p+1}^n \tilde{X}_i^2.$$ If $\xi \in L$ then $E(\tilde{X}_i) = z_i^T \xi = 0$ for $i = p +1, \ldots, n$ because then $z_i \in L^{\perp}$ and hence $z_i \perp \xi$. In this case $||X - PX||^2$ is the sum of $n-p$ independent $N(0, \sigma^2)$-distributed random variables, whose distribution, by definition, is a $\chi^2$-distribution with scale parameter $\sigma^2$ and $n-p$ degrees of freedom.
How to understand degrees of freedom?
The concept is not at all difficult to make mathematical precise given a bit of general knowledge of $n$-dimensional Euclidean geometry, subspaces and orthogonal projections. If $P$ is an orthogonal p
How to understand degrees of freedom? The concept is not at all difficult to make mathematical precise given a bit of general knowledge of $n$-dimensional Euclidean geometry, subspaces and orthogonal projections. If $P$ is an orthogonal projection from $\mathbb{R}^n$ to a $p$-dimensional subspace $L$ and $x$ is an arbitrary $n$-vector then $Px$ is in $L$, $x - Px$ and $Px$ are orthogonal and $x - Px \in L^{\perp}$ is in the orthogonal complement of $L$. The dimension of this orthogonal complement, $L^{\perp}$, is $n-p$. If $x$ is free to vary in an $n$-dimensional space then $x - Px$ is free to vary in an $n-p$ dimensional space. For this reason we say that $x - Px$ has $n-p$ degrees of freedom. These considerations are important to statistics because if $X$ is an $n$-dimensional random vector and $L$ is a model of its mean, that is, the mean vector $E(X)$ is in $L$, then we call $X-PX$ the vector of residuals, and we use the residuals to estimate the variance. The vector of residuals has $n-p$ degrees of freedom, that is, it is constrained to a subspace of dimension $n-p$. If the coordinates of $X$ are independent and normally distributed with the same variance $\sigma^2$ then The vectors $PX$ and $X - PX$ are independent. If $E(X) \in L$ the distribution of the squared norm of the vector of residuals $||X - PX||^2$ is a $\chi^2$-distribution with scale parameter $\sigma^2$ and another parameter that happens to be the degrees of freedom $n-p$. The sketch of proof of these facts is given below. The two results are central for the further development of the statistical theory based on the normal distribution. Note also that this is why the $\chi^2$-distribution has the parametrization it has. It is also a $\Gamma$-distribution with scale parameter $2\sigma^2$ and shape parameter $(n-p)/2$, but in the context above it is natural to parametrize in terms of the degrees of freedom. I must admit that I don't find any of the paragraphs cited from the Wikipedia article particularly enlightening, but they are not really wrong or contradictory either. They say in an imprecise, and in a general loose sense, that when we compute the estimate of the variance parameter, but do so based on residuals, we base the computation on a vector that is only free to vary in a space of dimension $n-p$. Beyond the theory of linear normal models the use of the concept of degrees of freedom can be confusing. It is, for instance, used in the parametrization of the $\chi^2$-distribution whether or not there is a reference to anything that could have any degrees of freedom. When we consider statistical analysis of categorical data there can be some confusion about whether the "independent pieces" should be counted before or after a tabulation. Furthermore, for constraints, even for normal models, that are not subspace constraints, it is not obvious how to extend the concept of degrees of freedom. Various suggestions exist typically under the name of effective degrees of freedom. Before any other usages and meanings of degrees of freedom is considered I will strongly recommend to become confident with it in the context of linear normal models. A reference dealing with this model class is A First Course in Linear Model Theory, and there are additional references in the preface of the book to other classical books on linear models. Proof of the results above: Let $\xi = E(X)$, note that the variance matrix is $\sigma^2 I$ and choose an orthonormal basis $z_1, \ldots, z_p$ of $L$ and an orthonormal basis $z_{p+1}, \ldots, z_n$ of $L^{\perp}$. Then $z_1, \ldots, z_n$ is an orthonormal basis of $\mathbb{R}^n$. Let $\tilde{X}$ denote the $n$-vector of the coefficients of $X$ in this basis, that is $$\tilde{X}_i = z_i^T X.$$ This can also be written as $\tilde{X} = Z^T X$ where $Z$ is the orthogonal matrix with the $z_i$'s in the columns. Then we have to use that $\tilde{X}$ has a normal distribution with mean $Z^T \xi$ and, because $Z$ is orthogonal, variance matrix $\sigma^2 I$. This follows from general linear transformation results of the normal distribution. The basis was chosen so that the coefficients of $PX$ are $\tilde{X}_i$ for $i= 1, \ldots, p$, and the coefficients of $X - PX$ are $\tilde{X}_i$ for $i= p+1, \ldots, n$. Since the coefficients are uncorrelated and jointly normal, they are independent, and this implies that $$PX = \sum_{i=1}^p \tilde{X}_i z_i$$ and $$X - PX = \sum_{i=p+1}^n \tilde{X}_i z_i$$ are independent. Moreover, $$||X - PX||^2 = \sum_{i=p+1}^n \tilde{X}_i^2.$$ If $\xi \in L$ then $E(\tilde{X}_i) = z_i^T \xi = 0$ for $i = p +1, \ldots, n$ because then $z_i \in L^{\perp}$ and hence $z_i \perp \xi$. In this case $||X - PX||^2$ is the sum of $n-p$ independent $N(0, \sigma^2)$-distributed random variables, whose distribution, by definition, is a $\chi^2$-distribution with scale parameter $\sigma^2$ and $n-p$ degrees of freedom.
How to understand degrees of freedom? The concept is not at all difficult to make mathematical precise given a bit of general knowledge of $n$-dimensional Euclidean geometry, subspaces and orthogonal projections. If $P$ is an orthogonal p
10,135
How to understand degrees of freedom?
It's really no different from the way the term "degrees of freedom" works in any other field. For example, suppose you have four variables: the length, the width, the area, and the perimeter of a rectangle. Do you really know four things? No, because there are only two degrees of freedom. If you know the length and the width, you can derive the area and the perimeter. If you know the length and the area, you can derive the width and the perimeter. If you know the area and the perimeter you can derive the length and the width (up to rotation). If you have all four, you can either say that the system is consistent (all of the variables agree with each other), or inconsistent (no rectangle could actually satisfy all of the conditions). A square is a rectangle with a degree of freedom removed; if you know any side of a square or its perimeter or its area, you can derive all of the others because there's only one degree of freedom. In statistics, things get more fuzzy, but the idea is still the same. If all of the data that you're using as the input for a function are independent variables, then you have as many degrees of freedom as you have inputs. But if they have dependence in some way, such that if you had n - k inputs you could figure out the remaining k, then you've actually only got n - k degrees of freedom. And sometimes you need to take that into account, lest you convince yourself that the data are more reliable or have more predictive power than they really do, by counting more data points than you really have independent bits of data. (Taken from a post at http://www.reddit.com/r/math/comments/9qbut/could_someone_explain_to_me_what_degrees_of/c0dxtbq?context=3.) Moreover, all three definitions are almost trying to give a same message.
How to understand degrees of freedom?
It's really no different from the way the term "degrees of freedom" works in any other field. For example, suppose you have four variables: the length, the width, the area, and the perimeter of a rect
How to understand degrees of freedom? It's really no different from the way the term "degrees of freedom" works in any other field. For example, suppose you have four variables: the length, the width, the area, and the perimeter of a rectangle. Do you really know four things? No, because there are only two degrees of freedom. If you know the length and the width, you can derive the area and the perimeter. If you know the length and the area, you can derive the width and the perimeter. If you know the area and the perimeter you can derive the length and the width (up to rotation). If you have all four, you can either say that the system is consistent (all of the variables agree with each other), or inconsistent (no rectangle could actually satisfy all of the conditions). A square is a rectangle with a degree of freedom removed; if you know any side of a square or its perimeter or its area, you can derive all of the others because there's only one degree of freedom. In statistics, things get more fuzzy, but the idea is still the same. If all of the data that you're using as the input for a function are independent variables, then you have as many degrees of freedom as you have inputs. But if they have dependence in some way, such that if you had n - k inputs you could figure out the remaining k, then you've actually only got n - k degrees of freedom. And sometimes you need to take that into account, lest you convince yourself that the data are more reliable or have more predictive power than they really do, by counting more data points than you really have independent bits of data. (Taken from a post at http://www.reddit.com/r/math/comments/9qbut/could_someone_explain_to_me_what_degrees_of/c0dxtbq?context=3.) Moreover, all three definitions are almost trying to give a same message.
How to understand degrees of freedom? It's really no different from the way the term "degrees of freedom" works in any other field. For example, suppose you have four variables: the length, the width, the area, and the perimeter of a rect
10,136
How to understand degrees of freedom?
Want to improve this post? Provide detailed answers to this question, including citations and an explanation of why your answer is correct. Answers without enough detail may be edited or deleted. I really like first sentence from The Little Handbook of Statistical Practice. Degrees of Freedom Chapter One of the questions an instrutor dreads most from a mathematically unsophisticated audience is, "What exactly is degrees of freedom?" I think you can get really good understanding about degrees of freedom from reading this chapter.
How to understand degrees of freedom?
Want to improve this post? Provide detailed answers to this question, including citations and an explanation of why your answer is correct. Answers without enough detail may be edited or deleted.
How to understand degrees of freedom? Want to improve this post? Provide detailed answers to this question, including citations and an explanation of why your answer is correct. Answers without enough detail may be edited or deleted. I really like first sentence from The Little Handbook of Statistical Practice. Degrees of Freedom Chapter One of the questions an instrutor dreads most from a mathematically unsophisticated audience is, "What exactly is degrees of freedom?" I think you can get really good understanding about degrees of freedom from reading this chapter.
How to understand degrees of freedom? Want to improve this post? Provide detailed answers to this question, including citations and an explanation of why your answer is correct. Answers without enough detail may be edited or deleted.
10,137
How to understand degrees of freedom?
Wikipedia asserts that degrees of freedom of a random vector can be interpreted as the dimensions of the vector subspace. I want to go step-by-step, very basically through this as a partial answer and elaboration on the Wikipedia entry. The example proposed is that of a random vector corresponding to the measurements of a continuous variable for different subjects, expressed as a vector extending from the origin $[a\,b\,c]^T$. Its orthogonal projection on the vector $[1\,1\,1]^T$ results in a vector equal to the projection of the vector of measurement means ($\bar{x}=1/3(a+b+c)$), i.e. $[\bar x \, \bar x \, \bar x]^T$, dotted with the $\vec{1}$ vector, $[1\,1\,1]^T $ This projection onto the subspace spanned by the vector of ones has $1\,\text{degree of freedom}$. The residual vector (distance from the mean) is the least-squares projection onto the $(n − 1)$-dimensional orthogonal complement of this subspace, and has $n − 1\,\text{degrees of freedom}$, $n$ being the total number of components of the vector (in our case $3$ since we are in $\mathbb{R}^3$ in the example).This can be simply proven by obtaining the dot product of $[\bar{x}\,\bar{x}\,\bar{x}]^T$ with the difference between $[a\,b\,c]^T$ and $[\bar{x}\,\bar{x}\,\bar{x}]^T$: $$ [\bar{x}\, \bar{x}\,\bar{x}]\, \begin{bmatrix} a-\bar{x}\\b-\bar{x}\\c-\bar{x}\end{bmatrix}=$$ $$= \bigg[\tiny\frac{(a+b+c)}{3}\, \bigg(a-\frac{(a+b+c)}{3}\bigg)\bigg]+ \bigg[\tiny\frac{(a+b+c)}{3} \,\bigg(b-\frac{(a+b+c)}{3}\bigg)\bigg]+ \bigg[\tiny\frac{(a+b+c)}{3} \,\bigg(c-\frac{(a+b+c)}{3}\bigg)\bigg]$$ $$=\tiny \frac{(a+b+c)}{3}\bigg[ \bigg(\tiny a-\frac{(a+b+c)}{3}\bigg)+ \bigg(b-\frac{(a+b+c)}{3}\bigg)+ \bigg(c-\frac{(a+b+c)}{3}\bigg)\bigg]$$ $$= \tiny \frac{(a+b+c)}{3}\bigg[\tiny \frac{1}{3} \bigg(\tiny 3a-(a+b+c)+ 3b-(a+b+c)+3c-(a+b+c)\bigg)\bigg]$$ $$=\tiny\frac{(a+b+c)}{3}\bigg[\tiny\frac{1}{3} (3a-3a+ 3b-3b+3c-3c)\bigg]\large= 0$$. And this relationship extends to any point in a plane orthogonal to $[\bar{x}\,\bar{x}\,\bar{x}]^T$. This concept is important in understanding why $\frac 1 {\sigma^2} \Big((X_1-\bar X)^2 + \cdots + (X_n - \bar X)^2 \Big) \sim \chi^2_{n-1}$, a step in the derivation of the t-distribution(here and here). Let's take the point $[35\,50\,80]^T$, corresponding to three observations. The mean is $55$, and the vector $[55\,\,55\,\,55]^T$ is the normal (orthogonal) to a plane, $55x + 55y + 55z = D$. Plugging in the point coordinates into the plane equation, $D = -9075$. Now we can choose any other point in this plane, and the mean of its coordinates is going to be $55$, geometrically corresponding to its projection onto the vector $[1\,\,1\,\,1]^T$. Hence for every mean value (in our example, $55$) we can choose an infinite number of pairs of coordinates in $\mathbb{R}^2$ without restriction ($2\,\text{degrees of freedom}$); yet, since the plane is in $\mathbb{R}^3$, the third coordinate will come determined by the equation of the plane (or, geometrically the orthogonal projection of the point onto $[55\,\,55\,\,55]^T$. Here is representation of three points (in white) lying on the plane (cerulean blue) orthogonal to $[55\,\,55\,\,55]^T$ (arrow): $[35\,\,50\,\,80]^T$, $[80\,\,80\,\,5]$ and $[90\,\,15\,\,60]$ all of them on the plane (subspace with $2\,\text{df}$), and then with a mean of their components of $55$, and an orthogonal projection to $[1\,\,1\,\,1]^T$ (subspace with $1\,\text{df}$) equal to $[55\,\,55\,\,55]^T$:
How to understand degrees of freedom?
Wikipedia asserts that degrees of freedom of a random vector can be interpreted as the dimensions of the vector subspace. I want to go step-by-step, very basically through this as a partial answer and
How to understand degrees of freedom? Wikipedia asserts that degrees of freedom of a random vector can be interpreted as the dimensions of the vector subspace. I want to go step-by-step, very basically through this as a partial answer and elaboration on the Wikipedia entry. The example proposed is that of a random vector corresponding to the measurements of a continuous variable for different subjects, expressed as a vector extending from the origin $[a\,b\,c]^T$. Its orthogonal projection on the vector $[1\,1\,1]^T$ results in a vector equal to the projection of the vector of measurement means ($\bar{x}=1/3(a+b+c)$), i.e. $[\bar x \, \bar x \, \bar x]^T$, dotted with the $\vec{1}$ vector, $[1\,1\,1]^T $ This projection onto the subspace spanned by the vector of ones has $1\,\text{degree of freedom}$. The residual vector (distance from the mean) is the least-squares projection onto the $(n − 1)$-dimensional orthogonal complement of this subspace, and has $n − 1\,\text{degrees of freedom}$, $n$ being the total number of components of the vector (in our case $3$ since we are in $\mathbb{R}^3$ in the example).This can be simply proven by obtaining the dot product of $[\bar{x}\,\bar{x}\,\bar{x}]^T$ with the difference between $[a\,b\,c]^T$ and $[\bar{x}\,\bar{x}\,\bar{x}]^T$: $$ [\bar{x}\, \bar{x}\,\bar{x}]\, \begin{bmatrix} a-\bar{x}\\b-\bar{x}\\c-\bar{x}\end{bmatrix}=$$ $$= \bigg[\tiny\frac{(a+b+c)}{3}\, \bigg(a-\frac{(a+b+c)}{3}\bigg)\bigg]+ \bigg[\tiny\frac{(a+b+c)}{3} \,\bigg(b-\frac{(a+b+c)}{3}\bigg)\bigg]+ \bigg[\tiny\frac{(a+b+c)}{3} \,\bigg(c-\frac{(a+b+c)}{3}\bigg)\bigg]$$ $$=\tiny \frac{(a+b+c)}{3}\bigg[ \bigg(\tiny a-\frac{(a+b+c)}{3}\bigg)+ \bigg(b-\frac{(a+b+c)}{3}\bigg)+ \bigg(c-\frac{(a+b+c)}{3}\bigg)\bigg]$$ $$= \tiny \frac{(a+b+c)}{3}\bigg[\tiny \frac{1}{3} \bigg(\tiny 3a-(a+b+c)+ 3b-(a+b+c)+3c-(a+b+c)\bigg)\bigg]$$ $$=\tiny\frac{(a+b+c)}{3}\bigg[\tiny\frac{1}{3} (3a-3a+ 3b-3b+3c-3c)\bigg]\large= 0$$. And this relationship extends to any point in a plane orthogonal to $[\bar{x}\,\bar{x}\,\bar{x}]^T$. This concept is important in understanding why $\frac 1 {\sigma^2} \Big((X_1-\bar X)^2 + \cdots + (X_n - \bar X)^2 \Big) \sim \chi^2_{n-1}$, a step in the derivation of the t-distribution(here and here). Let's take the point $[35\,50\,80]^T$, corresponding to three observations. The mean is $55$, and the vector $[55\,\,55\,\,55]^T$ is the normal (orthogonal) to a plane, $55x + 55y + 55z = D$. Plugging in the point coordinates into the plane equation, $D = -9075$. Now we can choose any other point in this plane, and the mean of its coordinates is going to be $55$, geometrically corresponding to its projection onto the vector $[1\,\,1\,\,1]^T$. Hence for every mean value (in our example, $55$) we can choose an infinite number of pairs of coordinates in $\mathbb{R}^2$ without restriction ($2\,\text{degrees of freedom}$); yet, since the plane is in $\mathbb{R}^3$, the third coordinate will come determined by the equation of the plane (or, geometrically the orthogonal projection of the point onto $[55\,\,55\,\,55]^T$. Here is representation of three points (in white) lying on the plane (cerulean blue) orthogonal to $[55\,\,55\,\,55]^T$ (arrow): $[35\,\,50\,\,80]^T$, $[80\,\,80\,\,5]$ and $[90\,\,15\,\,60]$ all of them on the plane (subspace with $2\,\text{df}$), and then with a mean of their components of $55$, and an orthogonal projection to $[1\,\,1\,\,1]^T$ (subspace with $1\,\text{df}$) equal to $[55\,\,55\,\,55]^T$:
How to understand degrees of freedom? Wikipedia asserts that degrees of freedom of a random vector can be interpreted as the dimensions of the vector subspace. I want to go step-by-step, very basically through this as a partial answer and
10,138
How to understand degrees of freedom?
In my classes, I use one "simple" situation that might help you wonder and perhaps develop a gut feeling for what a degree of freedom may mean. It is kind of a "Forrest Gump" approach to the subject, but it is worth the try. Consider you have 10 independent observations $X_1, X_2, \ldots, X_{10}\sim N(\mu,\sigma^2)$ that came right from a normal population whose mean $\mu$ and variance $\sigma^2$ are unknown. Your observations bring to you collectively information both about $\mu$ and $\sigma^2$. After all, your observations tend to be spread around one central value, which ought to be close to the actual and unknown value of $\mu$ and, likewise, if $\mu$ is very high or very low, then you can expect to see your observations gather around a very high or very low value respectively. One good "substitute" for $\mu$ (in the absence of knowledge of its actual value) is $\bar X$, the average of your observation. Also, if your observations are very close to one another, that is an indication that you can expect that $\sigma^2$ must be small and, likewise, if $\sigma^2$ is very large, then you can expect to see wildly different values for $X_1$ to $X_{10}$. If you were to bet your week's wage on which should be the actual values of $\mu$ and $\sigma^2$, you would need to choose a pair of values in which you would bet your money. Let's not think of anything as dramatic as losing your paycheck unless you guess $\mu$ correctly until its 200th decimal position. Nope. Let's think of some sort of prizing system that the closer you guess $\mu$ and $\sigma^2$ the more you get rewarded. In some sense, your better, more informed, and more polite guess for $\mu$'s value could be $\bar X$. In that sense, you estimate that $\mu$ must be some value around $\bar X$. Similarly, one good "substitute" for $\sigma^2$ (not required for now) is $S^2$, your sample variance, which makes a good estimate for $\sigma$. If your were to believe that those substitutes are the actual values of $\mu$ and $\sigma 2$, you would probably be wrong, because very slim are the chances that you were so lucky that your observations coordinated themselves to get you the gift of $\bar X$ being equal to $\mu$ and $S^2$ equal to $\sigma^2$. Nah, probably it didn't happen. But you could be at different levels of wrong, varying from a bit wrong to really, really, really miserably wrong (a.k.a., "Bye-bye, paycheck; see you next week!"). Ok, let's say that you took $\bar X$ as your guess for $\mu$. Consider just two scenarios: $S^2=2$ and $S^2=20,000,000$. In the first, your observations sit pretty and close to one another. In the latter, your observations vary wildly. In which scenario you should be more concerned with your potential losses? If you thought of the second one, you're right. Having a estimate about $\sigma^2$ changes your confidence on your bet very reasonably, for the larger $\sigma^2$ is, the wider you can expect $\bar X$ to variate. But, beyond information about $\mu$ and $\sigma^2$, your observations also carry some amount of just pure random fluctuation that is not informative neither about $\mu$ nor about $\sigma^2$. How can you notice it? Well, let's assume, for sake of argument, that there is a God and that He has spare time enough to give Himself the frivolity of telling you specifically the real (and so far unknown) values of both $\mu$ and $\sigma$. And here is the annoying plot twist of this lysergic tale: He tells it to you after you placed your bet. Perhaps to enlighten you, perhaps to prepare you, perhaps to mock you. How could you know? Well, that makes the information about $\mu$ and $\sigma^2$ contained in your observations quite useless now. Your observations' central position $\bar X$ and variance $S^2$ are no longer of any help to get closer to the actual values of $\mu$ and $\sigma^2$, for you already know them. One of the benefits of your good acquaintance with God is that you actually know by how much you failed to guess correctly $\mu$ by using $\bar X$, that is, $(\bar X - \mu)$ your estimation error. Well, since $X_i\sim N(\mu,\sigma^2)$, then $\bar X\sim N(\mu,\sigma^2/10)$ (trust me in that if you will), also $(\bar X - \mu)\sim N(0,\sigma^2/10)$ (ok, trust me in that on too) and, finally, $$ \frac{\bar X - \mu}{\sigma/\sqrt{10}} \sim N(0,1) $$ (guess what? trust me in that one as well), which carries absolutely no information about $\mu$ or $\sigma^2$. You know what? If you took any of your individual observations as a guess for $\mu$, your estimation error $(X_i-\mu)$ would be distributed as $N(0,\sigma^2)$. Well, between estimating $\mu$ with $\bar X$ and any $X_i$, choosing $\bar X$ would be better business, because $Var(\bar X) = \sigma^2/10 < \sigma^2 = Var(X_i)$, so $\bar X$ was less prone to be astray from $\mu$ than an individual $X_i$. Anyway, $(X_i-\mu)/\sigma\sim N(0,1)$ is also absolutely non informative about neither $\mu$ nor $\sigma^2$. "Will this tale ever end?" you may be thinking. You also may be thinking "Is there any more random fluctuation that is non informative about $\mu$ and $\sigma^2$?". [I prefer to think that you are thinking of the latter.] Yes, there is! The square of your estimation error for $\mu$ with $X_i$ divided by $\sigma$, $$ \frac{(X_i-\mu)^2}{\sigma^2} = \left(\frac{X_i-\mu}{\sigma}\right)^2 \sim \chi^2 $$ has a Chi-squared distribution, which is the distribution of the square $Z^2$ of a standard Normal $Z\sim N(0,1)$, which I am sure you noticed has absolutely no information about either $\mu$ nor $\sigma^2$, but conveys information about the variability you should expect to face. That is a very well known distribution that arises naturally from the very scenario of you gambling problem for every single one of your ten observations and also from your mean: $$ \frac{(\bar X-\mu)^2}{\sigma^2/10} = \left(\frac{\bar X-\mu}{\sigma/\sqrt{10}}\right)^2 = \left(N(0,1)\right)^2 \sim\chi^2 $$ and also from the gathering of your ten observations' variation: $$ \sum_{i=1}^{10} \frac{(X_i-\mu)^2}{\sigma^2/10} =\sum_{i=1}^{10} \left(\frac{X_i-\mu}{\sigma/\sqrt{10}}\right)^2 =\sum_{i=1}^{10} \left(N(0,1)\right)^2 =\sum_{i=1}^{10} \chi^2. $$ Now that last guy doesn't have a Chi-squared distribution, because he is the sum of ten of those Chi-squared distributions, all of them independent from one another (because so are $X_1, \ldots, X_{10}$). Each one of those single Chi-squared distribution is one contribution to the amount of random variability you should expect to face, with roughly the same amount of contribution to the sum. The value of each contribution is not mathematically equal to the other nine, but all of them have the same expected behavior in distribution. In that sense, they are somehow symmetric. Each one of those Chi-square is one contribution to the amount of pure, random variability you should expect in that sum. If you had 100 observations, the sum above would be expected to be bigger just because it have more sources of contibutions. Each of those "sources of contributions" with the same behavior can be called degree of freedom. Now take one or two steps back, re-read the previous paragraphs if needed to accommodate the sudden arrival of your quested-for degree of freedom. Yep, each degree of freedom can be thought of as one unit of variability that is obligatorily expected to occur and that brings nothing to the improvement of guessing of $\mu$ or $\sigma^2$. The thing is, you start to count on the behavior of those 10 equivalent sources of variability. If you had 100 observations, you would have 100 independent equally-behaved sources of strictly random fluctuation to that sum. That sum of 10 Chi-squares gets called a Chi-squared distributions with 10 degrees of freedom from now on, and written $\chi^2_{10}$. We can describe what to expect from it starting from its probability density function, that can be mathematically derived from the density from that single Chi-squared distribution (from now on called Chi-squared distribution with one degree of freedom and written $\chi^2_1$), that can be mathematically derived from the density of the normal distribution. "So what?" --- you might be thinking --- "That is of any good only if God took the time to tell me the values of $\mu$ and $\sigma^2$, of all the things He could tell me!" Indeed, if God Almighty were too busy to tell you the values of $\mu$ and $\sigma^2$, you would still have that 10 sources, that 10 degrees of freedom. Things start to get weird (Hahahaha; only now!) when you rebel against God and try and get along all by yourself, without expecting Him to patronize you. You have $\bar X$ and $S^2$, estimators for $\mu$ and $\sigma^2$. You can find your way to a safer bet. You could consider calculating the sum above with $\bar X$ and $S^2$ in the places of $\mu$ and $\sigma^2$: $$ \sum_{i=1}^{10} \frac{(X_i-\bar X)^2}{S^2/10} =\sum_{i=1}^{10} \left(\frac{X_i-\bar X}{S/\sqrt{10}}\right)^2, $$ but that is not the same as the original sum. "Why not?" The term inside the square of both sums are very different. For instance, it is unlikely but possible that all your observations end up being larger than $\mu$, in which case $(X_i-\mu) > 0$, which implies $\sum_{i=1}^{10}(X_i-\mu) > 0$, but, by its turn, $\sum_{i=1}^{10}(X_i-\bar X) = 0$, because $\sum_{i=1}^{10}X_i-10 \bar X =10 \bar X - 10 \bar X = 0$. Worse, you can prove easily (Hahahaha; right!) that $\sum_{i=1}^{10}(X_i-\bar X)^2 \le \sum_{i=1}^{10}(X_i-\mu)^2$ with strict inequality when at least two observations are different (which is not unusual). "But wait! There's more!" $$ \frac{X_i-\bar X}{S/\sqrt{10}} $$ doesn't have standard normal distribution, $$ \frac{(X_i-\bar X)^2}{S^2/10} $$ doesn't have Chi-squared distribution with one degree of freedom, $$ \sum_{i=1}^{10} \frac{(X_i-\bar X)^2}{S^2/10} $$ doesn't have Chi-squared distribution with 10 degrees of freedom $$ \frac{\bar X-\mu}{S/\sqrt{10}} $$ doesn't have standard normal distribution. "Was it all for nothing?" No way. Now comes the magic! Note that $$ \sum_{i=1}^{10} \frac{(X_i-\bar X)^2}{\sigma^2} =\sum_{i=1}^{10} \frac{[X_i-\mu+\mu-\bar X]^2}{\sigma^2} =\sum_{i=1}^{10} \frac{[(X_i-\mu)-(\bar X-\mu)]^2}{\sigma^2} =\sum_{i=1}^{10} \frac{(X_i-\mu)^2-2(X_i-\mu)(\bar X-\mu)+(\bar X-\mu)^2}{\sigma^2} =\sum_{i=1}^{10} \frac{(X_i-\mu)^2-(\bar X-\mu)^2}{\sigma^2} =\sum_{i=1}^{10} \frac{(X_i-\mu)^2}{\sigma^2}-\sum_{i=1}^{10} \frac{(\bar X-\mu)^2}{\sigma^2} =\sum_{i=1}^{10} \frac{(X_i-\mu)^2}{\sigma^2}-10\frac{(\bar X-\mu)^2}{\sigma^2} =\sum_{i=1}^{10} \frac{(X_i-\mu)^2}{\sigma^2}-\frac{(\bar X-\mu)^2}{\sigma^2/10} $$ or, equivalently, $$ \sum_{i=1}^{10} \frac{(X_i-\mu)^2}{\sigma^2} =\sum_{i=1}^{10} \frac{(X_i-\bar X)^2}{\sigma^2} +\frac{(\bar X-\mu)^2}{\sigma^2/10}. $$ Now we get back to those known faces. The first term has Chi-squared distribution with 10 degrees of freedom and the last term has Chi-squared distribution with one degree of freedom(!). We simply split a Chi-square with 10 independent equally-behaved sources of variability in two parts, both positive: one part is a Chi-square with one source of variability and the other we can prove (leap of faith? win by W.O.?) to be also a Chi-square with 9 (= 10-1) independent equally-behaved sources of variability, with both parts independent from one another. This is already a good news, since now we have its distribution. Alas, it uses $\sigma^2$, to which we have no access (recall that God is amusing Himself on watching our struggle). Well, $$ S^2=\frac{1}{10-1}\sum_{i=1}^{10} (X_i-\bar X)^2, $$ so $$ \sum_{i=1}^{10} \frac{(X_i-\bar X)^2}{\sigma^2} =\frac{\sum_{i=1}^{10} (X_i-\bar X)^2}{\sigma^2} =\frac{(10-1)S^2}{\sigma^2} \sim\chi^2_{(10-1)} $$ therefore $$ \frac{\bar X-\mu}{S/\sqrt{10}} =\frac{\frac{\bar X-\mu}{\sigma/\sqrt{10}}}{\frac{S}{\sigma}} =\frac{\frac{\bar X-\mu}{\sigma/\sqrt{10}}}{\sqrt{\frac{S^2}{\sigma^2}}} =\frac{\frac{\bar X-\mu}{\sigma/\sqrt{10}}}{\sqrt{\frac{\frac{(10-1)S^2}{\sigma^2}}{(10-1)}}} =\frac{N(0,1)}{\sqrt{\frac{\chi^2_{(10-1)}}{(10-1)}}}, $$ which is a distribution that is not the standard normal, but whose density can be derived from the densities of the standard normal and the Chi-squared with $(10-1)$ degrees of freedom. One very, very smart guy did that math[^1] in the beginning of 20th century and, as an unintended consequence, he made his boss the absolute world leader in the industry of Stout beer. I am talking about William Sealy Gosset (a.k.a. Student; yes, that Student, from the $t$ distribution) and Saint James's Gate Brewery (a.k.a. Guinness Brewery), of which I am a devout. [^1]: @whuber told in the comments below that Gosset did not do the math, but guessed instead! I really don't know which feat is more surprising for that time. That, my dear friend, is the origin of the $t$ distribution with $(10-1)$ degrees of freedom. The ratio of a standard normal and the squared root of an independent Chi-square divided by its degrees of freedom, which, in an unpredictable turn of tides, wind up describing the expected behavior of the estimation error you undergo when using the sample average $\bar X$ to estimate $\mu$ and using $S^2$ to estimate the variability of $\bar X$. There you go. With an awful lot of technical details grossly swept behind the rug, but not depending solely on God's intervention to dangerously bet your whole paycheck.
How to understand degrees of freedom?
In my classes, I use one "simple" situation that might help you wonder and perhaps develop a gut feeling for what a degree of freedom may mean. It is kind of a "Forrest Gump" approach to the subject,
How to understand degrees of freedom? In my classes, I use one "simple" situation that might help you wonder and perhaps develop a gut feeling for what a degree of freedom may mean. It is kind of a "Forrest Gump" approach to the subject, but it is worth the try. Consider you have 10 independent observations $X_1, X_2, \ldots, X_{10}\sim N(\mu,\sigma^2)$ that came right from a normal population whose mean $\mu$ and variance $\sigma^2$ are unknown. Your observations bring to you collectively information both about $\mu$ and $\sigma^2$. After all, your observations tend to be spread around one central value, which ought to be close to the actual and unknown value of $\mu$ and, likewise, if $\mu$ is very high or very low, then you can expect to see your observations gather around a very high or very low value respectively. One good "substitute" for $\mu$ (in the absence of knowledge of its actual value) is $\bar X$, the average of your observation. Also, if your observations are very close to one another, that is an indication that you can expect that $\sigma^2$ must be small and, likewise, if $\sigma^2$ is very large, then you can expect to see wildly different values for $X_1$ to $X_{10}$. If you were to bet your week's wage on which should be the actual values of $\mu$ and $\sigma^2$, you would need to choose a pair of values in which you would bet your money. Let's not think of anything as dramatic as losing your paycheck unless you guess $\mu$ correctly until its 200th decimal position. Nope. Let's think of some sort of prizing system that the closer you guess $\mu$ and $\sigma^2$ the more you get rewarded. In some sense, your better, more informed, and more polite guess for $\mu$'s value could be $\bar X$. In that sense, you estimate that $\mu$ must be some value around $\bar X$. Similarly, one good "substitute" for $\sigma^2$ (not required for now) is $S^2$, your sample variance, which makes a good estimate for $\sigma$. If your were to believe that those substitutes are the actual values of $\mu$ and $\sigma 2$, you would probably be wrong, because very slim are the chances that you were so lucky that your observations coordinated themselves to get you the gift of $\bar X$ being equal to $\mu$ and $S^2$ equal to $\sigma^2$. Nah, probably it didn't happen. But you could be at different levels of wrong, varying from a bit wrong to really, really, really miserably wrong (a.k.a., "Bye-bye, paycheck; see you next week!"). Ok, let's say that you took $\bar X$ as your guess for $\mu$. Consider just two scenarios: $S^2=2$ and $S^2=20,000,000$. In the first, your observations sit pretty and close to one another. In the latter, your observations vary wildly. In which scenario you should be more concerned with your potential losses? If you thought of the second one, you're right. Having a estimate about $\sigma^2$ changes your confidence on your bet very reasonably, for the larger $\sigma^2$ is, the wider you can expect $\bar X$ to variate. But, beyond information about $\mu$ and $\sigma^2$, your observations also carry some amount of just pure random fluctuation that is not informative neither about $\mu$ nor about $\sigma^2$. How can you notice it? Well, let's assume, for sake of argument, that there is a God and that He has spare time enough to give Himself the frivolity of telling you specifically the real (and so far unknown) values of both $\mu$ and $\sigma$. And here is the annoying plot twist of this lysergic tale: He tells it to you after you placed your bet. Perhaps to enlighten you, perhaps to prepare you, perhaps to mock you. How could you know? Well, that makes the information about $\mu$ and $\sigma^2$ contained in your observations quite useless now. Your observations' central position $\bar X$ and variance $S^2$ are no longer of any help to get closer to the actual values of $\mu$ and $\sigma^2$, for you already know them. One of the benefits of your good acquaintance with God is that you actually know by how much you failed to guess correctly $\mu$ by using $\bar X$, that is, $(\bar X - \mu)$ your estimation error. Well, since $X_i\sim N(\mu,\sigma^2)$, then $\bar X\sim N(\mu,\sigma^2/10)$ (trust me in that if you will), also $(\bar X - \mu)\sim N(0,\sigma^2/10)$ (ok, trust me in that on too) and, finally, $$ \frac{\bar X - \mu}{\sigma/\sqrt{10}} \sim N(0,1) $$ (guess what? trust me in that one as well), which carries absolutely no information about $\mu$ or $\sigma^2$. You know what? If you took any of your individual observations as a guess for $\mu$, your estimation error $(X_i-\mu)$ would be distributed as $N(0,\sigma^2)$. Well, between estimating $\mu$ with $\bar X$ and any $X_i$, choosing $\bar X$ would be better business, because $Var(\bar X) = \sigma^2/10 < \sigma^2 = Var(X_i)$, so $\bar X$ was less prone to be astray from $\mu$ than an individual $X_i$. Anyway, $(X_i-\mu)/\sigma\sim N(0,1)$ is also absolutely non informative about neither $\mu$ nor $\sigma^2$. "Will this tale ever end?" you may be thinking. You also may be thinking "Is there any more random fluctuation that is non informative about $\mu$ and $\sigma^2$?". [I prefer to think that you are thinking of the latter.] Yes, there is! The square of your estimation error for $\mu$ with $X_i$ divided by $\sigma$, $$ \frac{(X_i-\mu)^2}{\sigma^2} = \left(\frac{X_i-\mu}{\sigma}\right)^2 \sim \chi^2 $$ has a Chi-squared distribution, which is the distribution of the square $Z^2$ of a standard Normal $Z\sim N(0,1)$, which I am sure you noticed has absolutely no information about either $\mu$ nor $\sigma^2$, but conveys information about the variability you should expect to face. That is a very well known distribution that arises naturally from the very scenario of you gambling problem for every single one of your ten observations and also from your mean: $$ \frac{(\bar X-\mu)^2}{\sigma^2/10} = \left(\frac{\bar X-\mu}{\sigma/\sqrt{10}}\right)^2 = \left(N(0,1)\right)^2 \sim\chi^2 $$ and also from the gathering of your ten observations' variation: $$ \sum_{i=1}^{10} \frac{(X_i-\mu)^2}{\sigma^2/10} =\sum_{i=1}^{10} \left(\frac{X_i-\mu}{\sigma/\sqrt{10}}\right)^2 =\sum_{i=1}^{10} \left(N(0,1)\right)^2 =\sum_{i=1}^{10} \chi^2. $$ Now that last guy doesn't have a Chi-squared distribution, because he is the sum of ten of those Chi-squared distributions, all of them independent from one another (because so are $X_1, \ldots, X_{10}$). Each one of those single Chi-squared distribution is one contribution to the amount of random variability you should expect to face, with roughly the same amount of contribution to the sum. The value of each contribution is not mathematically equal to the other nine, but all of them have the same expected behavior in distribution. In that sense, they are somehow symmetric. Each one of those Chi-square is one contribution to the amount of pure, random variability you should expect in that sum. If you had 100 observations, the sum above would be expected to be bigger just because it have more sources of contibutions. Each of those "sources of contributions" with the same behavior can be called degree of freedom. Now take one or two steps back, re-read the previous paragraphs if needed to accommodate the sudden arrival of your quested-for degree of freedom. Yep, each degree of freedom can be thought of as one unit of variability that is obligatorily expected to occur and that brings nothing to the improvement of guessing of $\mu$ or $\sigma^2$. The thing is, you start to count on the behavior of those 10 equivalent sources of variability. If you had 100 observations, you would have 100 independent equally-behaved sources of strictly random fluctuation to that sum. That sum of 10 Chi-squares gets called a Chi-squared distributions with 10 degrees of freedom from now on, and written $\chi^2_{10}$. We can describe what to expect from it starting from its probability density function, that can be mathematically derived from the density from that single Chi-squared distribution (from now on called Chi-squared distribution with one degree of freedom and written $\chi^2_1$), that can be mathematically derived from the density of the normal distribution. "So what?" --- you might be thinking --- "That is of any good only if God took the time to tell me the values of $\mu$ and $\sigma^2$, of all the things He could tell me!" Indeed, if God Almighty were too busy to tell you the values of $\mu$ and $\sigma^2$, you would still have that 10 sources, that 10 degrees of freedom. Things start to get weird (Hahahaha; only now!) when you rebel against God and try and get along all by yourself, without expecting Him to patronize you. You have $\bar X$ and $S^2$, estimators for $\mu$ and $\sigma^2$. You can find your way to a safer bet. You could consider calculating the sum above with $\bar X$ and $S^2$ in the places of $\mu$ and $\sigma^2$: $$ \sum_{i=1}^{10} \frac{(X_i-\bar X)^2}{S^2/10} =\sum_{i=1}^{10} \left(\frac{X_i-\bar X}{S/\sqrt{10}}\right)^2, $$ but that is not the same as the original sum. "Why not?" The term inside the square of both sums are very different. For instance, it is unlikely but possible that all your observations end up being larger than $\mu$, in which case $(X_i-\mu) > 0$, which implies $\sum_{i=1}^{10}(X_i-\mu) > 0$, but, by its turn, $\sum_{i=1}^{10}(X_i-\bar X) = 0$, because $\sum_{i=1}^{10}X_i-10 \bar X =10 \bar X - 10 \bar X = 0$. Worse, you can prove easily (Hahahaha; right!) that $\sum_{i=1}^{10}(X_i-\bar X)^2 \le \sum_{i=1}^{10}(X_i-\mu)^2$ with strict inequality when at least two observations are different (which is not unusual). "But wait! There's more!" $$ \frac{X_i-\bar X}{S/\sqrt{10}} $$ doesn't have standard normal distribution, $$ \frac{(X_i-\bar X)^2}{S^2/10} $$ doesn't have Chi-squared distribution with one degree of freedom, $$ \sum_{i=1}^{10} \frac{(X_i-\bar X)^2}{S^2/10} $$ doesn't have Chi-squared distribution with 10 degrees of freedom $$ \frac{\bar X-\mu}{S/\sqrt{10}} $$ doesn't have standard normal distribution. "Was it all for nothing?" No way. Now comes the magic! Note that $$ \sum_{i=1}^{10} \frac{(X_i-\bar X)^2}{\sigma^2} =\sum_{i=1}^{10} \frac{[X_i-\mu+\mu-\bar X]^2}{\sigma^2} =\sum_{i=1}^{10} \frac{[(X_i-\mu)-(\bar X-\mu)]^2}{\sigma^2} =\sum_{i=1}^{10} \frac{(X_i-\mu)^2-2(X_i-\mu)(\bar X-\mu)+(\bar X-\mu)^2}{\sigma^2} =\sum_{i=1}^{10} \frac{(X_i-\mu)^2-(\bar X-\mu)^2}{\sigma^2} =\sum_{i=1}^{10} \frac{(X_i-\mu)^2}{\sigma^2}-\sum_{i=1}^{10} \frac{(\bar X-\mu)^2}{\sigma^2} =\sum_{i=1}^{10} \frac{(X_i-\mu)^2}{\sigma^2}-10\frac{(\bar X-\mu)^2}{\sigma^2} =\sum_{i=1}^{10} \frac{(X_i-\mu)^2}{\sigma^2}-\frac{(\bar X-\mu)^2}{\sigma^2/10} $$ or, equivalently, $$ \sum_{i=1}^{10} \frac{(X_i-\mu)^2}{\sigma^2} =\sum_{i=1}^{10} \frac{(X_i-\bar X)^2}{\sigma^2} +\frac{(\bar X-\mu)^2}{\sigma^2/10}. $$ Now we get back to those known faces. The first term has Chi-squared distribution with 10 degrees of freedom and the last term has Chi-squared distribution with one degree of freedom(!). We simply split a Chi-square with 10 independent equally-behaved sources of variability in two parts, both positive: one part is a Chi-square with one source of variability and the other we can prove (leap of faith? win by W.O.?) to be also a Chi-square with 9 (= 10-1) independent equally-behaved sources of variability, with both parts independent from one another. This is already a good news, since now we have its distribution. Alas, it uses $\sigma^2$, to which we have no access (recall that God is amusing Himself on watching our struggle). Well, $$ S^2=\frac{1}{10-1}\sum_{i=1}^{10} (X_i-\bar X)^2, $$ so $$ \sum_{i=1}^{10} \frac{(X_i-\bar X)^2}{\sigma^2} =\frac{\sum_{i=1}^{10} (X_i-\bar X)^2}{\sigma^2} =\frac{(10-1)S^2}{\sigma^2} \sim\chi^2_{(10-1)} $$ therefore $$ \frac{\bar X-\mu}{S/\sqrt{10}} =\frac{\frac{\bar X-\mu}{\sigma/\sqrt{10}}}{\frac{S}{\sigma}} =\frac{\frac{\bar X-\mu}{\sigma/\sqrt{10}}}{\sqrt{\frac{S^2}{\sigma^2}}} =\frac{\frac{\bar X-\mu}{\sigma/\sqrt{10}}}{\sqrt{\frac{\frac{(10-1)S^2}{\sigma^2}}{(10-1)}}} =\frac{N(0,1)}{\sqrt{\frac{\chi^2_{(10-1)}}{(10-1)}}}, $$ which is a distribution that is not the standard normal, but whose density can be derived from the densities of the standard normal and the Chi-squared with $(10-1)$ degrees of freedom. One very, very smart guy did that math[^1] in the beginning of 20th century and, as an unintended consequence, he made his boss the absolute world leader in the industry of Stout beer. I am talking about William Sealy Gosset (a.k.a. Student; yes, that Student, from the $t$ distribution) and Saint James's Gate Brewery (a.k.a. Guinness Brewery), of which I am a devout. [^1]: @whuber told in the comments below that Gosset did not do the math, but guessed instead! I really don't know which feat is more surprising for that time. That, my dear friend, is the origin of the $t$ distribution with $(10-1)$ degrees of freedom. The ratio of a standard normal and the squared root of an independent Chi-square divided by its degrees of freedom, which, in an unpredictable turn of tides, wind up describing the expected behavior of the estimation error you undergo when using the sample average $\bar X$ to estimate $\mu$ and using $S^2$ to estimate the variability of $\bar X$. There you go. With an awful lot of technical details grossly swept behind the rug, but not depending solely on God's intervention to dangerously bet your whole paycheck.
How to understand degrees of freedom? In my classes, I use one "simple" situation that might help you wonder and perhaps develop a gut feeling for what a degree of freedom may mean. It is kind of a "Forrest Gump" approach to the subject,
10,139
How to understand degrees of freedom?
This particular issue is quite frustrating for students in statistics courses, since they often cannot get a straight answer on exactly what a degree-of-freedom is defined to be. I will try to clear that up here. Suppose we have a random vector $\mathbf{x} \in \mathbb{R}^n$ and we form a new random vector $\mathbf{t} = T(\mathbf{x})$ via the linear function $T$. Formally, the degrees-of-freedom of $\mathbf{t}$ is the dimension of the space of allowable values for this vector, which is: $$DF \equiv \dim \mathscr{T} \equiv \dim \{ \mathbf{t} = T(\mathbf{x}) | \mathbf{x} \in \mathbb{R}^n \}.$$ The initial random vector $\mathbf{x}$ has an allowable space of dimension $n$, so it has $n$ degrees of freedom. Often the function $T$ will reduce the dimension of the allowable space of outcomes, and so $\mathbf{t}$ may have a lower degrees-of-freedom than $\mathbf{x}$. For example, in an answer to a related question you can see this formal definition of the degrees-of-freedom being used to explain Bessel's correction in the sample variance formula. In that particular case, transforming an initial sample to obtain its deviations from the sample mean leads to a deviation vector that has $n-1$ degrees-of-freedom (i.e., it is a vector in an allowable space with dimension $n-1$). When you apply this formal definition to statistical problems, you will usually find that the imposition of a single "constraint" on the random vector (via a linear equation on that vector) reduces the dimension of its allowable values by one, and thus reduces the degrees-of-freedom by one. As such, you will find that the above formal definition corresponds with the informal explanations you have been given. In undergraduate courses on statistics, you will generally find a lot of hand-waving and informal explanation of degrees-of-freedom, often via analogies or examples. The reason for this is that the formal definition requires an understanding of vector algebra and the geometry of vector spaces, which may be lacking in introductory statistics courses at an undergraduate level.
How to understand degrees of freedom?
This particular issue is quite frustrating for students in statistics courses, since they often cannot get a straight answer on exactly what a degree-of-freedom is defined to be. I will try to clear
How to understand degrees of freedom? This particular issue is quite frustrating for students in statistics courses, since they often cannot get a straight answer on exactly what a degree-of-freedom is defined to be. I will try to clear that up here. Suppose we have a random vector $\mathbf{x} \in \mathbb{R}^n$ and we form a new random vector $\mathbf{t} = T(\mathbf{x})$ via the linear function $T$. Formally, the degrees-of-freedom of $\mathbf{t}$ is the dimension of the space of allowable values for this vector, which is: $$DF \equiv \dim \mathscr{T} \equiv \dim \{ \mathbf{t} = T(\mathbf{x}) | \mathbf{x} \in \mathbb{R}^n \}.$$ The initial random vector $\mathbf{x}$ has an allowable space of dimension $n$, so it has $n$ degrees of freedom. Often the function $T$ will reduce the dimension of the allowable space of outcomes, and so $\mathbf{t}$ may have a lower degrees-of-freedom than $\mathbf{x}$. For example, in an answer to a related question you can see this formal definition of the degrees-of-freedom being used to explain Bessel's correction in the sample variance formula. In that particular case, transforming an initial sample to obtain its deviations from the sample mean leads to a deviation vector that has $n-1$ degrees-of-freedom (i.e., it is a vector in an allowable space with dimension $n-1$). When you apply this formal definition to statistical problems, you will usually find that the imposition of a single "constraint" on the random vector (via a linear equation on that vector) reduces the dimension of its allowable values by one, and thus reduces the degrees-of-freedom by one. As such, you will find that the above formal definition corresponds with the informal explanations you have been given. In undergraduate courses on statistics, you will generally find a lot of hand-waving and informal explanation of degrees-of-freedom, often via analogies or examples. The reason for this is that the formal definition requires an understanding of vector algebra and the geometry of vector spaces, which may be lacking in introductory statistics courses at an undergraduate level.
How to understand degrees of freedom? This particular issue is quite frustrating for students in statistics courses, since they often cannot get a straight answer on exactly what a degree-of-freedom is defined to be. I will try to clear
10,140
How to understand degrees of freedom?
You can see the degree of freedom as the number of observations minus the number of necessary relations among these observations. By exemple if you have $n$ sample of independant normal distribution observations $X_1,\dots,X_n$. The random variable $\sum_{i=1}^n (X_i-\overline{X}_n)^2\sim \mathcal{X}^2_{n-1}$, where $\overline{X}_n = \frac{1}{n}\sum_{i=1}^n X_i$. The degree of freedom here is $n-1$ because, their is one necessary relation between theses observations $(\overline{X}_n = \frac{1}{n}\sum_{i=1}^n X_i)$. For more information see this
How to understand degrees of freedom?
You can see the degree of freedom as the number of observations minus the number of necessary relations among these observations. By exemple if you have $n$ sample of independant normal distribution o
How to understand degrees of freedom? You can see the degree of freedom as the number of observations minus the number of necessary relations among these observations. By exemple if you have $n$ sample of independant normal distribution observations $X_1,\dots,X_n$. The random variable $\sum_{i=1}^n (X_i-\overline{X}_n)^2\sim \mathcal{X}^2_{n-1}$, where $\overline{X}_n = \frac{1}{n}\sum_{i=1}^n X_i$. The degree of freedom here is $n-1$ because, their is one necessary relation between theses observations $(\overline{X}_n = \frac{1}{n}\sum_{i=1}^n X_i)$. For more information see this
How to understand degrees of freedom? You can see the degree of freedom as the number of observations minus the number of necessary relations among these observations. By exemple if you have $n$ sample of independant normal distribution o
10,141
How to understand degrees of freedom?
The clearest "formal" definition of degrees-of-freedom is that it is the dimension of the space of allowable values for a random vector. This generally arises in a context where we have a sample vector $\mathbf{x} \in \mathbb{R}^n$ and we form a new random vector $\mathbf{t} = T(\mathbf{x})$ via the linear function $T$. Formally, the degrees-of-freedom of $\mathbf{t}$ is the dimension of the space of allowable values for this vector, which is: $$DF \equiv \dim \mathscr{T} \equiv \dim \{ \mathbf{t} = T(\mathbf{x}) | \mathbf{x} \in \mathbb{R}^n \}.$$ If we represent this linear transformation by the matrix transformation $T(\mathbf{x}) = \mathbf{T} \mathbf{x}$ then we have: $$\begin{aligned} DF &= \dim \{ \mathbf{t} = T(\mathbf{x}) | \mathbf{x} \in \mathbb{R}^n \} \\[6pt] &= \dim \{ \mathbf{T} \mathbf{x} | \mathbf{x} \in \mathbb{R}^n \} \\[6pt] &= \text{rank} \ \mathbf{T} \\[6pt] &= n - \text{Ker} \ \mathbf{T}, \\[6pt] \end{aligned}$$ where the last step follows from the rank-nullity theorem. This means that when we transform $\mathbf{x}$ by the linear transformation $T$ we lose degrees-of-freedom equal to the kernel (nullspace) of $\mathbf{T}$. In statistical problems, there is a close relationship between the eigenvalues of $\mathbf{T}$ and the loss of degrees-of-freedom from the transformation. Often the loss of degrees-of-freedom is equivalent to the number of zero eigenvalues in the transformation matrix $\mathbf{T}$. For example, in this answer we see that Bessel's correction to the sample variance, adjusting for the degrees-of-freedom of the vector of deviations from the mean, is closely related to the eigenvalues of the centering matrix. An identical result occurs in higher dimensions in linear regression analysis. In other statistical problems, similar relationships occur between the eigenvalues of the transformation matrix and the loss of degrees-of-freedom. The above result also formalises the notation that one loses a degree-of-freedom for each "constraint" imposed on the observable vector of interest. Thus, in simple univariate sampling problems, when looking at the sample variance, one loses a degree-of-freedom from estimating the mean. In linear regression models, when looking at the MSE, one loses a degree-of-freedom for each model coefficient that was estimated.
How to understand degrees of freedom?
The clearest "formal" definition of degrees-of-freedom is that it is the dimension of the space of allowable values for a random vector. This generally arises in a context where we have a sample vect
How to understand degrees of freedom? The clearest "formal" definition of degrees-of-freedom is that it is the dimension of the space of allowable values for a random vector. This generally arises in a context where we have a sample vector $\mathbf{x} \in \mathbb{R}^n$ and we form a new random vector $\mathbf{t} = T(\mathbf{x})$ via the linear function $T$. Formally, the degrees-of-freedom of $\mathbf{t}$ is the dimension of the space of allowable values for this vector, which is: $$DF \equiv \dim \mathscr{T} \equiv \dim \{ \mathbf{t} = T(\mathbf{x}) | \mathbf{x} \in \mathbb{R}^n \}.$$ If we represent this linear transformation by the matrix transformation $T(\mathbf{x}) = \mathbf{T} \mathbf{x}$ then we have: $$\begin{aligned} DF &= \dim \{ \mathbf{t} = T(\mathbf{x}) | \mathbf{x} \in \mathbb{R}^n \} \\[6pt] &= \dim \{ \mathbf{T} \mathbf{x} | \mathbf{x} \in \mathbb{R}^n \} \\[6pt] &= \text{rank} \ \mathbf{T} \\[6pt] &= n - \text{Ker} \ \mathbf{T}, \\[6pt] \end{aligned}$$ where the last step follows from the rank-nullity theorem. This means that when we transform $\mathbf{x}$ by the linear transformation $T$ we lose degrees-of-freedom equal to the kernel (nullspace) of $\mathbf{T}$. In statistical problems, there is a close relationship between the eigenvalues of $\mathbf{T}$ and the loss of degrees-of-freedom from the transformation. Often the loss of degrees-of-freedom is equivalent to the number of zero eigenvalues in the transformation matrix $\mathbf{T}$. For example, in this answer we see that Bessel's correction to the sample variance, adjusting for the degrees-of-freedom of the vector of deviations from the mean, is closely related to the eigenvalues of the centering matrix. An identical result occurs in higher dimensions in linear regression analysis. In other statistical problems, similar relationships occur between the eigenvalues of the transformation matrix and the loss of degrees-of-freedom. The above result also formalises the notation that one loses a degree-of-freedom for each "constraint" imposed on the observable vector of interest. Thus, in simple univariate sampling problems, when looking at the sample variance, one loses a degree-of-freedom from estimating the mean. In linear regression models, when looking at the MSE, one loses a degree-of-freedom for each model coefficient that was estimated.
How to understand degrees of freedom? The clearest "formal" definition of degrees-of-freedom is that it is the dimension of the space of allowable values for a random vector. This generally arises in a context where we have a sample vect
10,142
How to understand degrees of freedom?
An intuitive explanation of degrees of freedom is that they represent the number of independent pieces of information available in the data for estimating a parameter (i.e., unknown quantity) of interest. As an example, in a simple linear regression model of the form: $$ Y_i=\beta_0 + \beta_1\cdot X_i + \epsilon_i,\quad i=1,\ldots, n $$ where the $\epsilon_i$'s represent independent normally distributed error terms with mean 0 and standard deviation $\sigma$, we use 1 degree of freedom to estimate the intercept $\beta_0$ and 1 degree of freedom to estimate the slope $\beta_1$. Since we started out with $n$ observations and used up 2 degrees of freedom (i.e., two independent pieces of information), we are left with $n-2$ degrees of freedom (i.e., $n-2$ independent pieces of information) available for estimating the error standard deviation $\sigma$.
How to understand degrees of freedom?
An intuitive explanation of degrees of freedom is that they represent the number of independent pieces of information available in the data for estimating a parameter (i.e., unknown quantity) of inter
How to understand degrees of freedom? An intuitive explanation of degrees of freedom is that they represent the number of independent pieces of information available in the data for estimating a parameter (i.e., unknown quantity) of interest. As an example, in a simple linear regression model of the form: $$ Y_i=\beta_0 + \beta_1\cdot X_i + \epsilon_i,\quad i=1,\ldots, n $$ where the $\epsilon_i$'s represent independent normally distributed error terms with mean 0 and standard deviation $\sigma$, we use 1 degree of freedom to estimate the intercept $\beta_0$ and 1 degree of freedom to estimate the slope $\beta_1$. Since we started out with $n$ observations and used up 2 degrees of freedom (i.e., two independent pieces of information), we are left with $n-2$ degrees of freedom (i.e., $n-2$ independent pieces of information) available for estimating the error standard deviation $\sigma$.
How to understand degrees of freedom? An intuitive explanation of degrees of freedom is that they represent the number of independent pieces of information available in the data for estimating a parameter (i.e., unknown quantity) of inter
10,143
How to understand degrees of freedom?
For me the first explanation I understood was: If you know some statistical value like mean or variation, how many variables of data you need to know before you can know the value of every variable? This is the same as aL3xa said, but without giving any data point a special role and close to the third case given in the answer. In this way the same example would be: If you know the mean of data, you need to know the values for all but one data point, to know the value to all data points.
How to understand degrees of freedom?
For me the first explanation I understood was: If you know some statistical value like mean or variation, how many variables of data you need to know before you can know the value of every variab
How to understand degrees of freedom? For me the first explanation I understood was: If you know some statistical value like mean or variation, how many variables of data you need to know before you can know the value of every variable? This is the same as aL3xa said, but without giving any data point a special role and close to the third case given in the answer. In this way the same example would be: If you know the mean of data, you need to know the values for all but one data point, to know the value to all data points.
How to understand degrees of freedom? For me the first explanation I understood was: If you know some statistical value like mean or variation, how many variables of data you need to know before you can know the value of every variab
10,144
How to understand degrees of freedom?
Think of it this way. Variances are additive when independent. For example, suppose we are throwing darts at a board and we measure the standard deviations of the $x$ and $y$ displacements from the exact center of the board. Then $V_{x,y}=V_x+V_y$. But, $V_x=SD_x^2$ if we take the square root of the $V_{x,y}$ formula, we get the distance formula for orthogonal coordinates, $SD_{x,y}=\sqrt{SD_x^2+SD_y^2}$. Now all we have to show is that standard deviation is a representative measure of displacement away from the center of the dart board. Since $SD_x=\sqrt{\dfrac{\sum_{i=1}^n(x_i-\bar{x})^2}{n-1}}$, we have a ready means of discussing df. Note that when $n=1$, then $x_1-\bar{x}=0$ and the ratio $\dfrac{\sum_{i=1}^n(x_i-\bar{x})^2}{n-1}\rightarrow \dfrac{0}{0}$. In other words, there is no deviation to be had between one dart's $x$-coordinate and itself. The first time we have a deviation is for $n=2$ and there is only one of them, a duplicate. That duplicate deviation is the squared distance between $x_1$ or $x_2$ and $\bar{x}=\dfrac{x_1+x_2}{2}$ because $\bar{x}$ is the midpoint between or average of $x_1$ and $x_2$. In general, for $n$ distances we remove 1 because $\bar{x}$ is dependent on all $n$ of those distances. Now, $n-1$ represents the degrees of freedom because it normalizes for the number of unique outcomes to make an expected square distance. when divided into the sum of those square distances.
How to understand degrees of freedom?
Think of it this way. Variances are additive when independent. For example, suppose we are throwing darts at a board and we measure the standard deviations of the $x$ and $y$ displacements from the ex
How to understand degrees of freedom? Think of it this way. Variances are additive when independent. For example, suppose we are throwing darts at a board and we measure the standard deviations of the $x$ and $y$ displacements from the exact center of the board. Then $V_{x,y}=V_x+V_y$. But, $V_x=SD_x^2$ if we take the square root of the $V_{x,y}$ formula, we get the distance formula for orthogonal coordinates, $SD_{x,y}=\sqrt{SD_x^2+SD_y^2}$. Now all we have to show is that standard deviation is a representative measure of displacement away from the center of the dart board. Since $SD_x=\sqrt{\dfrac{\sum_{i=1}^n(x_i-\bar{x})^2}{n-1}}$, we have a ready means of discussing df. Note that when $n=1$, then $x_1-\bar{x}=0$ and the ratio $\dfrac{\sum_{i=1}^n(x_i-\bar{x})^2}{n-1}\rightarrow \dfrac{0}{0}$. In other words, there is no deviation to be had between one dart's $x$-coordinate and itself. The first time we have a deviation is for $n=2$ and there is only one of them, a duplicate. That duplicate deviation is the squared distance between $x_1$ or $x_2$ and $\bar{x}=\dfrac{x_1+x_2}{2}$ because $\bar{x}$ is the midpoint between or average of $x_1$ and $x_2$. In general, for $n$ distances we remove 1 because $\bar{x}$ is dependent on all $n$ of those distances. Now, $n-1$ represents the degrees of freedom because it normalizes for the number of unique outcomes to make an expected square distance. when divided into the sum of those square distances.
How to understand degrees of freedom? Think of it this way. Variances are additive when independent. For example, suppose we are throwing darts at a board and we measure the standard deviations of the $x$ and $y$ displacements from the ex
10,145
Detecting outliers using standard deviations
Some outliers are clearly impossible. You mention 48 kg for baby weight. This is clearly an error. That's not a statistical issue, it's a substantive one. There are no 48 kg human babies. Any statistical method will identify such a point. Personally, rather than rely on any test (even appropriate ones, as recommended by @Michael) I would graph the data. Showing that a certain data value (or values) are unlikely under some hypothesized distribution does not mean the value is wrong and therefore values shouldn't be automatically deleted just because they are extreme. In addition, the rule you propose (2 SD from the mean) is an old one that was used in the days before computers made things easy. If N is 100,000, then you certainly expect quite a few values more than 2 SD from the mean, even if there is a perfect normal distribution. But what if the distribution is wrong? Suppose, in the population, the variable in question is not normally distributed but has heavier tails than that?
Detecting outliers using standard deviations
Some outliers are clearly impossible. You mention 48 kg for baby weight. This is clearly an error. That's not a statistical issue, it's a substantive one. There are no 48 kg human babies. Any statisti
Detecting outliers using standard deviations Some outliers are clearly impossible. You mention 48 kg for baby weight. This is clearly an error. That's not a statistical issue, it's a substantive one. There are no 48 kg human babies. Any statistical method will identify such a point. Personally, rather than rely on any test (even appropriate ones, as recommended by @Michael) I would graph the data. Showing that a certain data value (or values) are unlikely under some hypothesized distribution does not mean the value is wrong and therefore values shouldn't be automatically deleted just because they are extreme. In addition, the rule you propose (2 SD from the mean) is an old one that was used in the days before computers made things easy. If N is 100,000, then you certainly expect quite a few values more than 2 SD from the mean, even if there is a perfect normal distribution. But what if the distribution is wrong? Suppose, in the population, the variable in question is not normally distributed but has heavier tails than that?
Detecting outliers using standard deviations Some outliers are clearly impossible. You mention 48 kg for baby weight. This is clearly an error. That's not a statistical issue, it's a substantive one. There are no 48 kg human babies. Any statisti
10,146
Detecting outliers using standard deviations
Yes. It is a bad way to "detect" oultiers. For normally distributed data, such a method would call 5% of the perfectly good (yet slightly extreme) observations "outliers". Also when you have a sample of size n and you look for extremely high or low observations to call them outliers, you are really looking at the extreme order statistics. The maximum and minimum of a normally distributed sample is not normally distributed. So the test should be based on the distribution of the extremes. That is what Grubbs' test and Dixon's ratio test do as I have mention several times before. Even when you use an appropriate test for outliers an observation should not be rejected just because it is unusually extreme. You should investigate why the extreme observation occurred first.
Detecting outliers using standard deviations
Yes. It is a bad way to "detect" oultiers. For normally distributed data, such a method would call 5% of the perfectly good (yet slightly extreme) observations "outliers". Also when you have a sample
Detecting outliers using standard deviations Yes. It is a bad way to "detect" oultiers. For normally distributed data, such a method would call 5% of the perfectly good (yet slightly extreme) observations "outliers". Also when you have a sample of size n and you look for extremely high or low observations to call them outliers, you are really looking at the extreme order statistics. The maximum and minimum of a normally distributed sample is not normally distributed. So the test should be based on the distribution of the extremes. That is what Grubbs' test and Dixon's ratio test do as I have mention several times before. Even when you use an appropriate test for outliers an observation should not be rejected just because it is unusually extreme. You should investigate why the extreme observation occurred first.
Detecting outliers using standard deviations Yes. It is a bad way to "detect" oultiers. For normally distributed data, such a method would call 5% of the perfectly good (yet slightly extreme) observations "outliers". Also when you have a sample
10,147
Detecting outliers using standard deviations
When you ask how many standard deviations from the mean a potential outlier is, don't forget that the outlier itself will raise the SD, and will also affect the value of the mean. If you have N values, the ratio of the distance from the mean divided by the SD can never exceed (N-1)/sqrt(N). This matters the most, of course, with tiny samples. For example, if N=3, no outlier can possibly be more than 1.155*SD from the mean, so it is impossible for any value to ever be more than 2 SDs from the mean. (This assumes, of course, that you are computing the sample SD from the data at hand, and don't have a theoretical reason to know the population SD). The critical values for Grubbs test were computed to take this into account, and so depend on sample size.
Detecting outliers using standard deviations
When you ask how many standard deviations from the mean a potential outlier is, don't forget that the outlier itself will raise the SD, and will also affect the value of the mean. If you have N values
Detecting outliers using standard deviations When you ask how many standard deviations from the mean a potential outlier is, don't forget that the outlier itself will raise the SD, and will also affect the value of the mean. If you have N values, the ratio of the distance from the mean divided by the SD can never exceed (N-1)/sqrt(N). This matters the most, of course, with tiny samples. For example, if N=3, no outlier can possibly be more than 1.155*SD from the mean, so it is impossible for any value to ever be more than 2 SDs from the mean. (This assumes, of course, that you are computing the sample SD from the data at hand, and don't have a theoretical reason to know the population SD). The critical values for Grubbs test were computed to take this into account, and so depend on sample size.
Detecting outliers using standard deviations When you ask how many standard deviations from the mean a potential outlier is, don't forget that the outlier itself will raise the SD, and will also affect the value of the mean. If you have N values
10,148
Detecting outliers using standard deviations
I think context is everything. For the example given, yes clearly a 48 kg baby is erroneous, and the use of 2 standard deviations would catch this case. However, there is no reason to think that the use of 2 standard deviations (or any other multiple of SD) is appropriate for other data. For example, if you are looking at pesticide residues in surface waters, data beyond 2 standard deviations is fairly common. These particularly high values are not “outliers”, even if they reside far from the mean, as they are due to rain events, recent pesticide applications, etc. Of course, you can create other “rules of thumb” (why not 1.5 × SD, or 3.1415927 × SD?), but frankly such rules are hard to defend, and their success or failure will change depending on the data you are examining. I think using judgment and logic, despite the subjectivity, is a better method for getting rid of outliers, rather than using an arbitrary rule. In this case, you didn't need a 2 × SD to detect the 48 kg outlier - you were able to reason it out. Isn't that a superior method? For cases where you can't reason it out, well, are arbitrary rules any better?
Detecting outliers using standard deviations
I think context is everything. For the example given, yes clearly a 48 kg baby is erroneous, and the use of 2 standard deviations would catch this case. However, there is no reason to think that the u
Detecting outliers using standard deviations I think context is everything. For the example given, yes clearly a 48 kg baby is erroneous, and the use of 2 standard deviations would catch this case. However, there is no reason to think that the use of 2 standard deviations (or any other multiple of SD) is appropriate for other data. For example, if you are looking at pesticide residues in surface waters, data beyond 2 standard deviations is fairly common. These particularly high values are not “outliers”, even if they reside far from the mean, as they are due to rain events, recent pesticide applications, etc. Of course, you can create other “rules of thumb” (why not 1.5 × SD, or 3.1415927 × SD?), but frankly such rules are hard to defend, and their success or failure will change depending on the data you are examining. I think using judgment and logic, despite the subjectivity, is a better method for getting rid of outliers, rather than using an arbitrary rule. In this case, you didn't need a 2 × SD to detect the 48 kg outlier - you were able to reason it out. Isn't that a superior method? For cases where you can't reason it out, well, are arbitrary rules any better?
Detecting outliers using standard deviations I think context is everything. For the example given, yes clearly a 48 kg baby is erroneous, and the use of 2 standard deviations would catch this case. However, there is no reason to think that the u
10,149
Can two random variables have the same distribution, yet be almost surely different?
Let $X\sim N(0,1)$ and define $Y=-X$. It is easy to prove that $Y\sim N(0,1)$. But $$ P\{\omega : X(\omega)=Y(\omega)\} = P\{\omega : X(\omega)=0,Y(\omega)=0\} \leq P\{\omega : X(\omega)=0\} = 0 \, . $$ Hence, $X$ and $Y$ are different with probability one.
Can two random variables have the same distribution, yet be almost surely different?
Let $X\sim N(0,1)$ and define $Y=-X$. It is easy to prove that $Y\sim N(0,1)$. But $$ P\{\omega : X(\omega)=Y(\omega)\} = P\{\omega : X(\omega)=0,Y(\omega)=0\} \leq P\{\omega : X(\omega)=0\} = 0 \,
Can two random variables have the same distribution, yet be almost surely different? Let $X\sim N(0,1)$ and define $Y=-X$. It is easy to prove that $Y\sim N(0,1)$. But $$ P\{\omega : X(\omega)=Y(\omega)\} = P\{\omega : X(\omega)=0,Y(\omega)=0\} \leq P\{\omega : X(\omega)=0\} = 0 \, . $$ Hence, $X$ and $Y$ are different with probability one.
Can two random variables have the same distribution, yet be almost surely different? Let $X\sim N(0,1)$ and define $Y=-X$. It is easy to prove that $Y\sim N(0,1)$. But $$ P\{\omega : X(\omega)=Y(\omega)\} = P\{\omega : X(\omega)=0,Y(\omega)=0\} \leq P\{\omega : X(\omega)=0\} = 0 \,
10,150
Can two random variables have the same distribution, yet be almost surely different?
Any pair of independent random variables $X$ and $Y$ having the same continuous distribution provides a counterexample. In fact, two random variables having the same distribution are not even necessarily defined on the same probability space, hence the question makes no sense in general.
Can two random variables have the same distribution, yet be almost surely different?
Any pair of independent random variables $X$ and $Y$ having the same continuous distribution provides a counterexample. In fact, two random variables having the same distribution are not even necessar
Can two random variables have the same distribution, yet be almost surely different? Any pair of independent random variables $X$ and $Y$ having the same continuous distribution provides a counterexample. In fact, two random variables having the same distribution are not even necessarily defined on the same probability space, hence the question makes no sense in general.
Can two random variables have the same distribution, yet be almost surely different? Any pair of independent random variables $X$ and $Y$ having the same continuous distribution provides a counterexample. In fact, two random variables having the same distribution are not even necessar
10,151
Can two random variables have the same distribution, yet be almost surely different?
Just consider $X(x)=x$ and $Y(x)=1-x$ with $x \in [0,1]$ with Borel or Lebesgue measure. For both the accumulated probability is $F(x)=x$ and the probability distibution is $f(x)=1$. For the sum $X+Y$ the distribution is a Dirac unit mass at $x=1$.
Can two random variables have the same distribution, yet be almost surely different?
Just consider $X(x)=x$ and $Y(x)=1-x$ with $x \in [0,1]$ with Borel or Lebesgue measure. For both the accumulated probability is $F(x)=x$ and the probability distibution is $f(x)=1$. For the sum $X+Y$
Can two random variables have the same distribution, yet be almost surely different? Just consider $X(x)=x$ and $Y(x)=1-x$ with $x \in [0,1]$ with Borel or Lebesgue measure. For both the accumulated probability is $F(x)=x$ and the probability distibution is $f(x)=1$. For the sum $X+Y$ the distribution is a Dirac unit mass at $x=1$.
Can two random variables have the same distribution, yet be almost surely different? Just consider $X(x)=x$ and $Y(x)=1-x$ with $x \in [0,1]$ with Borel or Lebesgue measure. For both the accumulated probability is $F(x)=x$ and the probability distibution is $f(x)=1$. For the sum $X+Y$
10,152
"The total area underneath a probability density function is 1" - relative to what?
Probability density function is measured in percentages per unit of measure of your x-axis. Let's say at a given point $x_0$ your PDF is equal to 1000. This means that the probability of $x_0<x<x_0+dx$ is $1000\,dx$ where $dx$ is in meters. If you change the units to centimeters, then the probability should not change for the same interval, but the same interval has 100 more centimeters than meters, so $1000\,dx=PDF'(x_0')\cdot100\,dx'$ and solving we get $PDF'(x_0')=\frac{PDF(x_0)}{100}$. There's 100 times less units of probability (percentages) per centimeter than per meter.
"The total area underneath a probability density function is 1" - relative to what?
Probability density function is measured in percentages per unit of measure of your x-axis. Let's say at a given point $x_0$ your PDF is equal to 1000. This means that the probability of $x_0<x<x_0+dx
"The total area underneath a probability density function is 1" - relative to what? Probability density function is measured in percentages per unit of measure of your x-axis. Let's say at a given point $x_0$ your PDF is equal to 1000. This means that the probability of $x_0<x<x_0+dx$ is $1000\,dx$ where $dx$ is in meters. If you change the units to centimeters, then the probability should not change for the same interval, but the same interval has 100 more centimeters than meters, so $1000\,dx=PDF'(x_0')\cdot100\,dx'$ and solving we get $PDF'(x_0')=\frac{PDF(x_0)}{100}$. There's 100 times less units of probability (percentages) per centimeter than per meter.
"The total area underneath a probability density function is 1" - relative to what? Probability density function is measured in percentages per unit of measure of your x-axis. Let's say at a given point $x_0$ your PDF is equal to 1000. This means that the probability of $x_0<x<x_0+dx
10,153
"The total area underneath a probability density function is 1" - relative to what?
It might help you to realise that the vertical axis is measured as a probability density. So if the horizontal axis is measured in km, then the vertical axis is measured as a probability density "per km". Suppose we draw a rectangular element on such a grid, which is 5 "km" wide and 0.1 "per km" high (which you might prefer to write as "km$^{-1}$"). The area of this rectangle is 5 km x 0.1 km$^{-1}$ = 0.5. The units cancel out and we are left with just a probability of one half. If you changed the horizontal units to "metres", you'd have to change the vertical units to "per metre". The rectangle would now be 5000 metres wide, and would have a density (height) of 0.0001 per metre. You're still left with a probability of one half. You might get perturbed by how weird these two graphs will look on the page compared to each other (doesn't one have to be much wider and shorter than the other?), but when you're physically drawing the plots you can use whatever scale you like. Look below to see how little weirdness need be involved. You might find it helpful to consider histograms before you move on to probability density curves. In many ways they are analogous. A histogram's vertical axis is frequency density [per $x$ unit] and areas represent frequencies, again because horizontal and vertical units cancel out upon multiplication. The PDF curve is a sort of continuous version of a histogram, with total frequency equal to one. An even closer analogy is a relative frequency histogram - we say such a histogram has been "normalized", so that area elements now represent proportions of your original data set rather than raw frequencies, and the total area of all the bars is one. The heights are now relative frequency densities [per $x$ unit]. If a relative frequency histogram has a bar that runs along $x$ values from 20 km to 25 km (so the width of the bar is 5 km) and has a relative frequency density of 0.1 per km, then that bar contains a 0.5 proportion of the data. This corresponds exactly to the idea that a randomly chosen item from your data set has a 50% probability of lying in that bar. The previous argument about the effect of changes in units still applies: compare the proportions of data lying in the 20 km to 25 km bar to that in the 20,000 metres to 25,000 metres bar for these two plots. You might also confirm arithmetically that the areas of all bars sum to one in both cases. What might I have meant by my claim that the PDF is a "sort of continuous version of a histogram"? Let's take a small strip under a probability density curve, along $x$ values in the interval $[x, x + \delta x]$, so the strip is $\delta x$ wide, and the height of the curve is an approximately constant $f(x)$. We can draw a bar of that height, whose area $f(x) \, \delta x$ represents the approximate probability of lying in that strip. How might we find the area under the curve between $x=a$ and $x=b$? We could subdivide that interval into little strips and take the sum of the areas of the bars, $\sum f(x) \, \delta x$, which would correspond to the approximate probability of lying in the interval $[a,b]$. We see that the curve and the bars do not precisely align, so there is an error in our approximation. By making $\delta x$ smaller and smaller for each bar, we fill the interval with more and narrower bars, whose $\sum f(x) \, \delta x$ provides a better estimate of the area. To calculate the area precisely, rather than assuming $f(x)$ was constant across each strip, we evaluate the integral $\int_a^b f(x) dx$, and this corresponds to the true probability of lying in the interval $[a,b]$. Integrating over the whole curve gives a total area (i.e. total probability) one, for the same reason that summing up the areas of all the bars of a relative frequency histogram gives a total area (i.e. total proportion) of one. Integration is itself a sort of continuous version of taking a sum. R code for plots require(ggplot2) require(scales) require(gridExtra) # Code for the PDF plots with bars underneath could be easily readapted # Relative frequency histograms x.df <- data.frame(km=c(rep(12.5, 1), rep(17.5, 2), rep(22.5, 5), rep(27.5, 2))) x.df$metres <- x.df$km * 1000 km.plot <- ggplot(x.df, aes(x=km, y=..density..)) + stat_bin(origin=10, binwidth=5, fill="steelblue", colour="black") + xlab("Distance in km") + ylab("Relative frequency density per km") + scale_y_continuous(minor_breaks = seq(0, 0.1, by=0.005)) metres.plot <- ggplot(x.df, aes(x=metres, y=..density..)) + stat_bin(origin=10000, binwidth=5000, fill="steelblue", colour="black") + xlab("Distance in metres") + ylab("Relative frequency density per metre") + scale_x_continuous(labels = comma) + scale_y_continuous(minor_breaks = seq(0, 0.0001, by=0.000005), labels=comma) grid.arrange(km.plot, metres.plot, ncol=2) x11() # Probability density functions x.df <- data.frame(x=seq(0, 1, by=0.001)) cutoffs <- seq(0.2, 0.5, by=0.1) # for bars barHeights <- c(0, dbeta(cutoffs[1:(length(cutoffs)-1)], 2, 2), 0) # uses left of bar x.df$pdf <- dbeta(x.df$x, 2, 2) x.df$bar <- findInterval(x.df$x, cutoffs) + 1 # start at 1, first plotted bar is 2 x.df$barHeight <- barHeights[x.df$bar] x.df$lastBar <- ifelse(x.df$bar == max(x.df$bar)-1, 1, 0) # last plotted bar only x.df$lastBarHeight <- ifelse(x.df$lastBar == 1, x.df$barHeight, 0) x.df$integral <- ifelse(x.df$bar %in% 2:(max(x.df$bar)-1), 1, 0) # all plotted bars x.df$integralHeight <- ifelse(x.df$integral == 1, x.df$pdf, 0) cutoffsNarrow <- seq(0.2, 0.5, by=0.025) # for the narrow bars barHeightsNarrow <- c(0, dbeta(cutoffsNarrow[1:(length(cutoffsNarrow)-1)], 2, 2), 0) # uses left of bar x.df$barNarrow <- findInterval(x.df$x, cutoffsNarrow) + 1 # start at 1, first plotted bar is 2 x.df$barHeightNarrow <- barHeightsNarrow[x.df$barNarrow] pdf.plot <- ggplot(x.df, aes(x=x, y=pdf)) + geom_area(fill="lightsteelblue", colour="black", size=.8) + ylab("probability density") + theme(panel.grid = element_blank(), axis.text.x = element_text(colour="black", size=16)) pdf.lastBar.plot <- pdf.plot + scale_x_continuous(breaks=tail(cutoffs, 2), labels=expression(x, x+delta*x)) + geom_area(aes(x=x, y=lastBarHeight, group=lastBar), fill="steelblue", colour="black", size=.8) + annotate("text", x=0.73, y=0.22, size=6, label=paste("P(paste(x<=X)<=x+delta*x)%~~%f(x)*delta*x"), parse=TRUE) pdf.bars.plot <- pdf.plot + scale_x_continuous(breaks=cutoffs[c(1, length(cutoffs))], labels=c("a", "b")) + geom_area(aes(x=x, y=barHeight, group=bar), fill="steelblue", colour="black", size=.8) + annotate("text", x=0.73, y=0.22, size=6, label=paste("P(paste(a<=X)<=b)%~~%sum(f(x)*delta*x)"), parse=TRUE) pdf.barsNarrow.plot <- pdf.plot + scale_x_continuous(breaks=cutoffsNarrow[c(1, length(cutoffsNarrow))], labels=c("a", "b")) + geom_area(aes(x=x, y=barHeightNarrow, group=barNarrow), fill="steelblue", colour="black", size=.8) + annotate("text", x=0.73, y=0.22, size=6, label=paste("P(paste(a<=X)<=b)%~~%sum(f(x)*delta*x)"), parse=TRUE) pdf.integral.plot <- pdf.plot + scale_x_continuous(breaks=cutoffs[c(1, length(cutoffs))], labels=c("a", "b")) + geom_area(aes(x=x, y=integralHeight, group=integral), fill="steelblue", colour="black", size=.8) + annotate("text", x=0.73, y=0.22, size=6, label=paste("P(paste(a<=X)<=b)==integral(f(x)*dx,a,b)"), parse=TRUE) grid.arrange(pdf.lastBar.plot, pdf.bars.plot, pdf.barsNarrow.plot, pdf.integral.plot, ncol=2)
"The total area underneath a probability density function is 1" - relative to what?
It might help you to realise that the vertical axis is measured as a probability density. So if the horizontal axis is measured in km, then the vertical axis is measured as a probability density "per
"The total area underneath a probability density function is 1" - relative to what? It might help you to realise that the vertical axis is measured as a probability density. So if the horizontal axis is measured in km, then the vertical axis is measured as a probability density "per km". Suppose we draw a rectangular element on such a grid, which is 5 "km" wide and 0.1 "per km" high (which you might prefer to write as "km$^{-1}$"). The area of this rectangle is 5 km x 0.1 km$^{-1}$ = 0.5. The units cancel out and we are left with just a probability of one half. If you changed the horizontal units to "metres", you'd have to change the vertical units to "per metre". The rectangle would now be 5000 metres wide, and would have a density (height) of 0.0001 per metre. You're still left with a probability of one half. You might get perturbed by how weird these two graphs will look on the page compared to each other (doesn't one have to be much wider and shorter than the other?), but when you're physically drawing the plots you can use whatever scale you like. Look below to see how little weirdness need be involved. You might find it helpful to consider histograms before you move on to probability density curves. In many ways they are analogous. A histogram's vertical axis is frequency density [per $x$ unit] and areas represent frequencies, again because horizontal and vertical units cancel out upon multiplication. The PDF curve is a sort of continuous version of a histogram, with total frequency equal to one. An even closer analogy is a relative frequency histogram - we say such a histogram has been "normalized", so that area elements now represent proportions of your original data set rather than raw frequencies, and the total area of all the bars is one. The heights are now relative frequency densities [per $x$ unit]. If a relative frequency histogram has a bar that runs along $x$ values from 20 km to 25 km (so the width of the bar is 5 km) and has a relative frequency density of 0.1 per km, then that bar contains a 0.5 proportion of the data. This corresponds exactly to the idea that a randomly chosen item from your data set has a 50% probability of lying in that bar. The previous argument about the effect of changes in units still applies: compare the proportions of data lying in the 20 km to 25 km bar to that in the 20,000 metres to 25,000 metres bar for these two plots. You might also confirm arithmetically that the areas of all bars sum to one in both cases. What might I have meant by my claim that the PDF is a "sort of continuous version of a histogram"? Let's take a small strip under a probability density curve, along $x$ values in the interval $[x, x + \delta x]$, so the strip is $\delta x$ wide, and the height of the curve is an approximately constant $f(x)$. We can draw a bar of that height, whose area $f(x) \, \delta x$ represents the approximate probability of lying in that strip. How might we find the area under the curve between $x=a$ and $x=b$? We could subdivide that interval into little strips and take the sum of the areas of the bars, $\sum f(x) \, \delta x$, which would correspond to the approximate probability of lying in the interval $[a,b]$. We see that the curve and the bars do not precisely align, so there is an error in our approximation. By making $\delta x$ smaller and smaller for each bar, we fill the interval with more and narrower bars, whose $\sum f(x) \, \delta x$ provides a better estimate of the area. To calculate the area precisely, rather than assuming $f(x)$ was constant across each strip, we evaluate the integral $\int_a^b f(x) dx$, and this corresponds to the true probability of lying in the interval $[a,b]$. Integrating over the whole curve gives a total area (i.e. total probability) one, for the same reason that summing up the areas of all the bars of a relative frequency histogram gives a total area (i.e. total proportion) of one. Integration is itself a sort of continuous version of taking a sum. R code for plots require(ggplot2) require(scales) require(gridExtra) # Code for the PDF plots with bars underneath could be easily readapted # Relative frequency histograms x.df <- data.frame(km=c(rep(12.5, 1), rep(17.5, 2), rep(22.5, 5), rep(27.5, 2))) x.df$metres <- x.df$km * 1000 km.plot <- ggplot(x.df, aes(x=km, y=..density..)) + stat_bin(origin=10, binwidth=5, fill="steelblue", colour="black") + xlab("Distance in km") + ylab("Relative frequency density per km") + scale_y_continuous(minor_breaks = seq(0, 0.1, by=0.005)) metres.plot <- ggplot(x.df, aes(x=metres, y=..density..)) + stat_bin(origin=10000, binwidth=5000, fill="steelblue", colour="black") + xlab("Distance in metres") + ylab("Relative frequency density per metre") + scale_x_continuous(labels = comma) + scale_y_continuous(minor_breaks = seq(0, 0.0001, by=0.000005), labels=comma) grid.arrange(km.plot, metres.plot, ncol=2) x11() # Probability density functions x.df <- data.frame(x=seq(0, 1, by=0.001)) cutoffs <- seq(0.2, 0.5, by=0.1) # for bars barHeights <- c(0, dbeta(cutoffs[1:(length(cutoffs)-1)], 2, 2), 0) # uses left of bar x.df$pdf <- dbeta(x.df$x, 2, 2) x.df$bar <- findInterval(x.df$x, cutoffs) + 1 # start at 1, first plotted bar is 2 x.df$barHeight <- barHeights[x.df$bar] x.df$lastBar <- ifelse(x.df$bar == max(x.df$bar)-1, 1, 0) # last plotted bar only x.df$lastBarHeight <- ifelse(x.df$lastBar == 1, x.df$barHeight, 0) x.df$integral <- ifelse(x.df$bar %in% 2:(max(x.df$bar)-1), 1, 0) # all plotted bars x.df$integralHeight <- ifelse(x.df$integral == 1, x.df$pdf, 0) cutoffsNarrow <- seq(0.2, 0.5, by=0.025) # for the narrow bars barHeightsNarrow <- c(0, dbeta(cutoffsNarrow[1:(length(cutoffsNarrow)-1)], 2, 2), 0) # uses left of bar x.df$barNarrow <- findInterval(x.df$x, cutoffsNarrow) + 1 # start at 1, first plotted bar is 2 x.df$barHeightNarrow <- barHeightsNarrow[x.df$barNarrow] pdf.plot <- ggplot(x.df, aes(x=x, y=pdf)) + geom_area(fill="lightsteelblue", colour="black", size=.8) + ylab("probability density") + theme(panel.grid = element_blank(), axis.text.x = element_text(colour="black", size=16)) pdf.lastBar.plot <- pdf.plot + scale_x_continuous(breaks=tail(cutoffs, 2), labels=expression(x, x+delta*x)) + geom_area(aes(x=x, y=lastBarHeight, group=lastBar), fill="steelblue", colour="black", size=.8) + annotate("text", x=0.73, y=0.22, size=6, label=paste("P(paste(x<=X)<=x+delta*x)%~~%f(x)*delta*x"), parse=TRUE) pdf.bars.plot <- pdf.plot + scale_x_continuous(breaks=cutoffs[c(1, length(cutoffs))], labels=c("a", "b")) + geom_area(aes(x=x, y=barHeight, group=bar), fill="steelblue", colour="black", size=.8) + annotate("text", x=0.73, y=0.22, size=6, label=paste("P(paste(a<=X)<=b)%~~%sum(f(x)*delta*x)"), parse=TRUE) pdf.barsNarrow.plot <- pdf.plot + scale_x_continuous(breaks=cutoffsNarrow[c(1, length(cutoffsNarrow))], labels=c("a", "b")) + geom_area(aes(x=x, y=barHeightNarrow, group=barNarrow), fill="steelblue", colour="black", size=.8) + annotate("text", x=0.73, y=0.22, size=6, label=paste("P(paste(a<=X)<=b)%~~%sum(f(x)*delta*x)"), parse=TRUE) pdf.integral.plot <- pdf.plot + scale_x_continuous(breaks=cutoffs[c(1, length(cutoffs))], labels=c("a", "b")) + geom_area(aes(x=x, y=integralHeight, group=integral), fill="steelblue", colour="black", size=.8) + annotate("text", x=0.73, y=0.22, size=6, label=paste("P(paste(a<=X)<=b)==integral(f(x)*dx,a,b)"), parse=TRUE) grid.arrange(pdf.lastBar.plot, pdf.bars.plot, pdf.barsNarrow.plot, pdf.integral.plot, ncol=2)
"The total area underneath a probability density function is 1" - relative to what? It might help you to realise that the vertical axis is measured as a probability density. So if the horizontal axis is measured in km, then the vertical axis is measured as a probability density "per
10,154
"The total area underneath a probability density function is 1" - relative to what?
You already got two answers, with an excellent one by Silverfish, however I feel that an illustration could be useful in here since you asked about geometry and "imagining" yourself those functions. Lets start with a simple example of Bernoulli distribution: $$ f(x) = \begin{cases} p & \text{if }x=1, \\[6pt] 1-p & \text {if }x=0.\end{cases} $$ Since the values are discrete there is no "curve" but only two points, however the idea is similar: if you want to know total probability (area under the curve) you have to sum up probabilities of both possible outcomes: $$p + (1 - p) = 1$$ There is only $p$ and $1-p$ in this equation since we have only two possible point outcomes with a given probabilities. The same would be with Poisson distribution that is also a discrete probability distribution. There are more than two values, so you can imagine that there is a line that connects the points, however to compute the total probability you would have to sum up all the probabilities of $x$'s. Poisson distribution is often used to describe count data, so you can think of it as each $x$ is a number of certain events and $f(x)$ is a probability of this outcome. You could imagine that each point on the plot below is actually a height of a stack made of some outcomes: $x_1$ is a stack of all the "$x_1$" outcomes that you observed etc. The total "area under the curve" would be here all the stacks summed up (or a meta-stack of all the outcomes) but since we do not sum up numbers of occurrences but rather probabilities, they sum up to $1$. So you should not think of it as sum of counts $\sum \#\{x_i\}=N$, but rather as sum of probabilities: $\sum \#\{x_i\}/N=1$ where $N$ is a total number of all possible outcomes. Now let's consider a normal distribution that actually is a continuous distribution - so we don't have "points" since the values of $x$ are on continuous scale, i.e. there is infinitely many values of $x$. So if there were points you couldn't see them no matter how much would you "zoom in", since there always could be some an infinite number of smaller points between any given points. Because of that here we actually have a curve - you can imagine that it is made of infinitely many "points". You could ask yourself: how to compute a sum of infinite number of probabilities..? On the plot below red curve is a normal PDF and the black boxes is histogram of some values drawn from the distribution. So histogram plot has simplified our distribution to the finite number of "boxes" with a certain width and if you summed up the heights of the boxes multiplied by their width you would end up with an area under the curve - or area of all the boxes. We use areas rather points in here since each box is a summary of an infinite number of "points" that were packed up in the box. So to get total area we take the heights (i.e. $f(x)$) and widths (e.g. first box has width: $-2.5 - -3 = 0.5$, the same as all the other boxes). In the actual figure plotted the heights of the boxes are: 0.010 0.028 0.094 0.198 0.260 0.400 0.404 0.292 0.166 0.092 0.044 0.010 0.002 if you sum them up multiplying each by $0.5$ (width), they will sum up to $1$. In here you cannot count anything since there is infinitely many possible points that form the curve. On another hand, since we are talking about probabilities, the probability of all the possible outcomes has to be $1$. In this case we use "probability per unit" and the unit can have any width of your choice. Consider "all possible outcomes" on the continuous scale as a line that could be divided into the parts, and each part could be divided into some smaller parts up to infinitely small ones. The total probability of this line is $1$. If it would be flat than you could imagine that it's total length is $1$ and by dividing it you get probabilities of the parts. If the line is not flat, the probability per part is described by function $f(x)$. So the units actually doesn't matter since there is infinite number of possible "points" it is probability per unit, where unit is always the same: a fraction of "total" length. This approach illustrates in a simplified way a little bit more complicated issue - taking integrals. In continuous case you use integrals for calculating the area under the curve. Integral of the area of the curve between points $a$ and $b$ ($-3$ and $3$ on out plot) is: $$\int_a^b \! f(x)\,dx$$ where $f(x)$ is height and $dx$ is width and you could think of $\int$ as $\sum$ for continuous variables. For learning more on integrals and calculus you could check the Khan Academy lectures. You asked also about the "flat" (uniform) distribution: First notice that this is not a valid uniform distribution since it should have parameters such that $-\infty < a < b < \infty$, so to integrate to $1$. If you think of it, it is continuous and since it is flat, it is some kind of box with a width from $-\infty$ to $\infty$. If you wanted to calculate area of such box, you would be multiplying the height by width. Unfortunately, while the width is infinitely wide, for it to integrate to $1$ the height would have to be some $\varepsilon$ that is enormously small... So this is a complicated case and you could imagine it rather in abstract terms. Notice that, as Ilmari Karonen noticed in the comment, this is rather an abstract idea that is not really possible in practice (see the comment below). If using such distribution as a prior, it would be an improper prior. Notice that in the continuous case probability density function gives you density estimates rather then probabilities, so heights (or their sum) could exceed $1$ (see here for more).
"The total area underneath a probability density function is 1" - relative to what?
You already got two answers, with an excellent one by Silverfish, however I feel that an illustration could be useful in here since you asked about geometry and "imagining" yourself those functions. L
"The total area underneath a probability density function is 1" - relative to what? You already got two answers, with an excellent one by Silverfish, however I feel that an illustration could be useful in here since you asked about geometry and "imagining" yourself those functions. Lets start with a simple example of Bernoulli distribution: $$ f(x) = \begin{cases} p & \text{if }x=1, \\[6pt] 1-p & \text {if }x=0.\end{cases} $$ Since the values are discrete there is no "curve" but only two points, however the idea is similar: if you want to know total probability (area under the curve) you have to sum up probabilities of both possible outcomes: $$p + (1 - p) = 1$$ There is only $p$ and $1-p$ in this equation since we have only two possible point outcomes with a given probabilities. The same would be with Poisson distribution that is also a discrete probability distribution. There are more than two values, so you can imagine that there is a line that connects the points, however to compute the total probability you would have to sum up all the probabilities of $x$'s. Poisson distribution is often used to describe count data, so you can think of it as each $x$ is a number of certain events and $f(x)$ is a probability of this outcome. You could imagine that each point on the plot below is actually a height of a stack made of some outcomes: $x_1$ is a stack of all the "$x_1$" outcomes that you observed etc. The total "area under the curve" would be here all the stacks summed up (or a meta-stack of all the outcomes) but since we do not sum up numbers of occurrences but rather probabilities, they sum up to $1$. So you should not think of it as sum of counts $\sum \#\{x_i\}=N$, but rather as sum of probabilities: $\sum \#\{x_i\}/N=1$ where $N$ is a total number of all possible outcomes. Now let's consider a normal distribution that actually is a continuous distribution - so we don't have "points" since the values of $x$ are on continuous scale, i.e. there is infinitely many values of $x$. So if there were points you couldn't see them no matter how much would you "zoom in", since there always could be some an infinite number of smaller points between any given points. Because of that here we actually have a curve - you can imagine that it is made of infinitely many "points". You could ask yourself: how to compute a sum of infinite number of probabilities..? On the plot below red curve is a normal PDF and the black boxes is histogram of some values drawn from the distribution. So histogram plot has simplified our distribution to the finite number of "boxes" with a certain width and if you summed up the heights of the boxes multiplied by their width you would end up with an area under the curve - or area of all the boxes. We use areas rather points in here since each box is a summary of an infinite number of "points" that were packed up in the box. So to get total area we take the heights (i.e. $f(x)$) and widths (e.g. first box has width: $-2.5 - -3 = 0.5$, the same as all the other boxes). In the actual figure plotted the heights of the boxes are: 0.010 0.028 0.094 0.198 0.260 0.400 0.404 0.292 0.166 0.092 0.044 0.010 0.002 if you sum them up multiplying each by $0.5$ (width), they will sum up to $1$. In here you cannot count anything since there is infinitely many possible points that form the curve. On another hand, since we are talking about probabilities, the probability of all the possible outcomes has to be $1$. In this case we use "probability per unit" and the unit can have any width of your choice. Consider "all possible outcomes" on the continuous scale as a line that could be divided into the parts, and each part could be divided into some smaller parts up to infinitely small ones. The total probability of this line is $1$. If it would be flat than you could imagine that it's total length is $1$ and by dividing it you get probabilities of the parts. If the line is not flat, the probability per part is described by function $f(x)$. So the units actually doesn't matter since there is infinite number of possible "points" it is probability per unit, where unit is always the same: a fraction of "total" length. This approach illustrates in a simplified way a little bit more complicated issue - taking integrals. In continuous case you use integrals for calculating the area under the curve. Integral of the area of the curve between points $a$ and $b$ ($-3$ and $3$ on out plot) is: $$\int_a^b \! f(x)\,dx$$ where $f(x)$ is height and $dx$ is width and you could think of $\int$ as $\sum$ for continuous variables. For learning more on integrals and calculus you could check the Khan Academy lectures. You asked also about the "flat" (uniform) distribution: First notice that this is not a valid uniform distribution since it should have parameters such that $-\infty < a < b < \infty$, so to integrate to $1$. If you think of it, it is continuous and since it is flat, it is some kind of box with a width from $-\infty$ to $\infty$. If you wanted to calculate area of such box, you would be multiplying the height by width. Unfortunately, while the width is infinitely wide, for it to integrate to $1$ the height would have to be some $\varepsilon$ that is enormously small... So this is a complicated case and you could imagine it rather in abstract terms. Notice that, as Ilmari Karonen noticed in the comment, this is rather an abstract idea that is not really possible in practice (see the comment below). If using such distribution as a prior, it would be an improper prior. Notice that in the continuous case probability density function gives you density estimates rather then probabilities, so heights (or their sum) could exceed $1$ (see here for more).
"The total area underneath a probability density function is 1" - relative to what? You already got two answers, with an excellent one by Silverfish, however I feel that an illustration could be useful in here since you asked about geometry and "imagining" yourself those functions. L
10,155
"The total area underneath a probability density function is 1" - relative to what?
The following key idea was mentioned in a comment, but not in an existing answer... One way of intuiting about the properties of a PDF is to consider that the PDF and the CDF are related by integration (calculus) -- and that the CDF has a monotonic output representing a probability value between 0 and 1. The unitless integrated total area under the PDF curve is not affected by X-axis units. To put it simply... Area = Width x Height If the X-axis gets larger, numerically, due to a change in units, then the Y-axis must become smaller by a corresponding linear factor.
"The total area underneath a probability density function is 1" - relative to what?
The following key idea was mentioned in a comment, but not in an existing answer... One way of intuiting about the properties of a PDF is to consider that the PDF and the CDF are related by integratio
"The total area underneath a probability density function is 1" - relative to what? The following key idea was mentioned in a comment, but not in an existing answer... One way of intuiting about the properties of a PDF is to consider that the PDF and the CDF are related by integration (calculus) -- and that the CDF has a monotonic output representing a probability value between 0 and 1. The unitless integrated total area under the PDF curve is not affected by X-axis units. To put it simply... Area = Width x Height If the X-axis gets larger, numerically, due to a change in units, then the Y-axis must become smaller by a corresponding linear factor.
"The total area underneath a probability density function is 1" - relative to what? The following key idea was mentioned in a comment, but not in an existing answer... One way of intuiting about the properties of a PDF is to consider that the PDF and the CDF are related by integratio
10,156
Amoeba Interview Question
Cute problem. This is the kind of stuff that probabilists do in their heads for fun. The technique is to assume that there is such a probability of extinction, call it $P$. Then, looking at a one-deep decision tree for the possible outcomes we see--using the Law of Total Probability--that $P=\frac{1}{4} + \frac{1}{4}P + \frac{1}{4}P^2 + \frac{1}{4}P^3$ assuming that, in the cases of 2 or 3 "offspring" their extinction probabilities are IID. This equation has two feasible roots, $1$ and $\sqrt{2}-1$. Someone smarter than me might be able to explain why the $1$ isn't plausible. Jobs must be getting tight -- what kind of interviewer expects you to solve cubic equations in your head?
Amoeba Interview Question
Cute problem. This is the kind of stuff that probabilists do in their heads for fun. The technique is to assume that there is such a probability of extinction, call it $P$. Then, looking at a one-dee
Amoeba Interview Question Cute problem. This is the kind of stuff that probabilists do in their heads for fun. The technique is to assume that there is such a probability of extinction, call it $P$. Then, looking at a one-deep decision tree for the possible outcomes we see--using the Law of Total Probability--that $P=\frac{1}{4} + \frac{1}{4}P + \frac{1}{4}P^2 + \frac{1}{4}P^3$ assuming that, in the cases of 2 or 3 "offspring" their extinction probabilities are IID. This equation has two feasible roots, $1$ and $\sqrt{2}-1$. Someone smarter than me might be able to explain why the $1$ isn't plausible. Jobs must be getting tight -- what kind of interviewer expects you to solve cubic equations in your head?
Amoeba Interview Question Cute problem. This is the kind of stuff that probabilists do in their heads for fun. The technique is to assume that there is such a probability of extinction, call it $P$. Then, looking at a one-dee
10,157
Amoeba Interview Question
Some back of the envelope calculation (litterally - I had an envelope lying around on my desk) gives me a probability of 42/111 (38%) of never reaching a population of 3. I ran a quick Python simulation, seeing how many populations had died off by 20 generations (at which point they usually either died out or are in the thousands), and got 4164 dead out of 10000 runs. So the answer is 42%.
Amoeba Interview Question
Some back of the envelope calculation (litterally - I had an envelope lying around on my desk) gives me a probability of 42/111 (38%) of never reaching a population of 3. I ran a quick Python simulati
Amoeba Interview Question Some back of the envelope calculation (litterally - I had an envelope lying around on my desk) gives me a probability of 42/111 (38%) of never reaching a population of 3. I ran a quick Python simulation, seeing how many populations had died off by 20 generations (at which point they usually either died out or are in the thousands), and got 4164 dead out of 10000 runs. So the answer is 42%.
Amoeba Interview Question Some back of the envelope calculation (litterally - I had an envelope lying around on my desk) gives me a probability of 42/111 (38%) of never reaching a population of 3. I ran a quick Python simulati
10,158
Amoeba Interview Question
Like the answer from Mike Anderson says you can equate the probability for a lineage of an amoeba to become extinct to a sum of probabilities of the lineage of the children to become extinct. $$p_{parent} = \frac{1}{4} p_{child}^3 + \frac{1}{4} p_{child}^2 + \frac{1}{4} p_{child} + \frac{1}{4}$$ Then when you set equal the parents and childs probability for their lineage to become extinct, then you get the equation: $$p = \frac{1}{4} p^3 + \frac{1}{4} p^2 + \frac{1}{4} p + \frac{1}{4}$$ which has roots $p=1$, $p=\sqrt{2}-1$, and $p=-\sqrt{2}-1$. The question that remains is why the answer should be $p=\sqrt{2}-1$ and not $p=1$. This is for instance asked in this duplicate Amoeba Interview Question: Is the P(N=0) 1 or 1/2? . In the answer from shabbychef it is explained that one can look at, $E_k$, the expectation value of the size of the population after the $k$-th division, and see whether it is either shrinking or growing. To me, there is some indirectness in the argumentation behind that and it feels like it is not completely proven. For instance, in one of the comments, Whuber notes that you can have a growing expectation value $E_k$ and also have the probability for extinction in the $k$-th step approach 1. As an example, you could introduce a catastrophic event that wipes out the entire amoeba population and it occurs with some probability $x$ in each step. Then the amoeba lineage is almost certain to die. Yet, the expectation of the population size in step $k$ is growing. Furthermore, the answer leaves open what we have to think of the situation when $E_k = 1$ (e.g. when an amoeba splits or does not split with equal, 50%, probability, then the lineage of an amoeba becomes extinct with probability almost $1$ even though $E_k= 1$) Alternative derivation. Note that the solution $p=1$ can be a vacuous truth. We equate the probability for the parent's lineage to become extinct to the child's lineage to become extinct. If 'the probability for the child's lineage to become extinct is equal to $1$'. Then 'the probability for the parent's lineage to become extinct is equal to $1$'. But this does not mean that it is true that 'the probability for the child's lineage to become extinct is $1$'. This is especially clear when there would always be nonzero number of offspring. E.g. imagine the equation: $$p = \frac{1}{3} p^3 + \frac{1}{3} p^2 + \frac{1}{3} p$$ Could we arrive at a solution in a slightly different way? Let's call $p_k$ the probability for the lineage to get extinct before the $k$-th devision. Then we have: $$p_1 = \frac{1}{4}$$ and the recurrence relation $$p_{k+1} = \frac{1}{4} p_{k}^3 + \frac{1}{4} p_k^2 + \frac{1}{4} p_k + p_1$$ or $$\delta_k = p_{k+1} - p_k = \frac{1}{4} p_{k}^3 + \frac{1}{4} p_k^2 - \frac{3}{4} p_k + p_1 = f(p_k) $$ So wherever $f(p_k)>0$ the probability to get extinct before the $k$-th devision will increase with increasing $k$. Convergence to the root and the relation with the expectation value If the step is smaller than the distance to the root $f(p_k) < p_{\infty}-p_k$ then this increase of the $p_k$ as $k$ grows will not surpass the point where $f(p_\infty) = 0$. You could verify that this (not surpassing the root) is always the case when the slope/derivative of $f(p_k)$ is above or equal to $-1$, and this in it's turn is always the case for $0\leq p \leq 1$ and polynomials like $f(p) = -p + \sum_{k=0}^{\infty} a_k p^k$ with $a_k \geq 0$. With the derivative $$f^\prime(p) = -1 + \sum_{k=1}^{\infty} a_k k p^{k-1}$$ being in the extreme points equal to $f^\prime(0) = -1$ and $f^\prime(1) = -1 + E_1$ you can see that there must be a minimum between $p=0$ and $p=1$ if $E_1>1$ (and related there must be a root between $0$ and $1$, thus no certain extinction). And opposite when $E_1 \leq 1$ there will be no root between $0$ and $1$, thus certain extinction (except the case when $f(p) = 0$ which occurs when $a_1 = 1$).
Amoeba Interview Question
Like the answer from Mike Anderson says you can equate the probability for a lineage of an amoeba to become extinct to a sum of probabilities of the lineage of the children to become extinct. $$p_{par
Amoeba Interview Question Like the answer from Mike Anderson says you can equate the probability for a lineage of an amoeba to become extinct to a sum of probabilities of the lineage of the children to become extinct. $$p_{parent} = \frac{1}{4} p_{child}^3 + \frac{1}{4} p_{child}^2 + \frac{1}{4} p_{child} + \frac{1}{4}$$ Then when you set equal the parents and childs probability for their lineage to become extinct, then you get the equation: $$p = \frac{1}{4} p^3 + \frac{1}{4} p^2 + \frac{1}{4} p + \frac{1}{4}$$ which has roots $p=1$, $p=\sqrt{2}-1$, and $p=-\sqrt{2}-1$. The question that remains is why the answer should be $p=\sqrt{2}-1$ and not $p=1$. This is for instance asked in this duplicate Amoeba Interview Question: Is the P(N=0) 1 or 1/2? . In the answer from shabbychef it is explained that one can look at, $E_k$, the expectation value of the size of the population after the $k$-th division, and see whether it is either shrinking or growing. To me, there is some indirectness in the argumentation behind that and it feels like it is not completely proven. For instance, in one of the comments, Whuber notes that you can have a growing expectation value $E_k$ and also have the probability for extinction in the $k$-th step approach 1. As an example, you could introduce a catastrophic event that wipes out the entire amoeba population and it occurs with some probability $x$ in each step. Then the amoeba lineage is almost certain to die. Yet, the expectation of the population size in step $k$ is growing. Furthermore, the answer leaves open what we have to think of the situation when $E_k = 1$ (e.g. when an amoeba splits or does not split with equal, 50%, probability, then the lineage of an amoeba becomes extinct with probability almost $1$ even though $E_k= 1$) Alternative derivation. Note that the solution $p=1$ can be a vacuous truth. We equate the probability for the parent's lineage to become extinct to the child's lineage to become extinct. If 'the probability for the child's lineage to become extinct is equal to $1$'. Then 'the probability for the parent's lineage to become extinct is equal to $1$'. But this does not mean that it is true that 'the probability for the child's lineage to become extinct is $1$'. This is especially clear when there would always be nonzero number of offspring. E.g. imagine the equation: $$p = \frac{1}{3} p^3 + \frac{1}{3} p^2 + \frac{1}{3} p$$ Could we arrive at a solution in a slightly different way? Let's call $p_k$ the probability for the lineage to get extinct before the $k$-th devision. Then we have: $$p_1 = \frac{1}{4}$$ and the recurrence relation $$p_{k+1} = \frac{1}{4} p_{k}^3 + \frac{1}{4} p_k^2 + \frac{1}{4} p_k + p_1$$ or $$\delta_k = p_{k+1} - p_k = \frac{1}{4} p_{k}^3 + \frac{1}{4} p_k^2 - \frac{3}{4} p_k + p_1 = f(p_k) $$ So wherever $f(p_k)>0$ the probability to get extinct before the $k$-th devision will increase with increasing $k$. Convergence to the root and the relation with the expectation value If the step is smaller than the distance to the root $f(p_k) < p_{\infty}-p_k$ then this increase of the $p_k$ as $k$ grows will not surpass the point where $f(p_\infty) = 0$. You could verify that this (not surpassing the root) is always the case when the slope/derivative of $f(p_k)$ is above or equal to $-1$, and this in it's turn is always the case for $0\leq p \leq 1$ and polynomials like $f(p) = -p + \sum_{k=0}^{\infty} a_k p^k$ with $a_k \geq 0$. With the derivative $$f^\prime(p) = -1 + \sum_{k=1}^{\infty} a_k k p^{k-1}$$ being in the extreme points equal to $f^\prime(0) = -1$ and $f^\prime(1) = -1 + E_1$ you can see that there must be a minimum between $p=0$ and $p=1$ if $E_1>1$ (and related there must be a root between $0$ and $1$, thus no certain extinction). And opposite when $E_1 \leq 1$ there will be no root between $0$ and $1$, thus certain extinction (except the case when $f(p) = 0$ which occurs when $a_1 = 1$).
Amoeba Interview Question Like the answer from Mike Anderson says you can equate the probability for a lineage of an amoeba to become extinct to a sum of probabilities of the lineage of the children to become extinct. $$p_{par
10,159
Amoeba Interview Question
This sounds related to the Galton Watson process, originally formulated to study the survival of surnames. The probability depends on the expected number of sub-amoebas after a single division. In this case that expected number is $3/2,$ which is greater than the critical value of $1$, and thus the probability of extinction is less than $1$. By considering the expected number of amoeba after $k$ divisions, one can easily show that if the expected number after one division is less than $1$, the probability of extinction is $1$. The other half of the problem, I am not so sure about.
Amoeba Interview Question
This sounds related to the Galton Watson process, originally formulated to study the survival of surnames. The probability depends on the expected number of sub-amoebas after a single division. In thi
Amoeba Interview Question This sounds related to the Galton Watson process, originally formulated to study the survival of surnames. The probability depends on the expected number of sub-amoebas after a single division. In this case that expected number is $3/2,$ which is greater than the critical value of $1$, and thus the probability of extinction is less than $1$. By considering the expected number of amoeba after $k$ divisions, one can easily show that if the expected number after one division is less than $1$, the probability of extinction is $1$. The other half of the problem, I am not so sure about.
Amoeba Interview Question This sounds related to the Galton Watson process, originally formulated to study the survival of surnames. The probability depends on the expected number of sub-amoebas after a single division. In thi
10,160
Significance of categorical predictor in logistic regression
The following explanation is not limited to logistic regression but applies equally in normal linear regression and other GLMs. Usually, R excludes one level of the categorical and the coefficients denote the difference of each class to this reference class (or sometimes called baseline class) (this is called dummy coding or treatment contrasts in R, see here for an excellent overview of the different contrast options). To see the current contrasts in R, type options("contrasts"). Normally, R orders the levels of the categorical variable alphabetically and takes the first as reference class. This is not always optimal and can be changed by typing (here, we would set the reference class to "c" in the new variable) new.variable <- relevel(old.variable, ref="c"). For each coefficient of every level of the categorical variable, a Wald test is performed to test whether the pairwise difference between the coefficient of the reference class and the other class is different from zero or not. This is what the $z$ and $p$-values in the regression table are. If only one categorical class is significant, this does not imply that the whole variable is meaningless and should be removed from the model. You can check the overall effect of the variable by performing a likelihood ratio test: fit two models, one with and one without the variable and type anova(model1, model2, test="LRT") in R (see example below). Here is an example: mydata <- read.csv("https://stats.idre.ucla.edu/stat/data/binary.csv") mydata$rank <- factor(mydata$rank) my.mod <- glm(admit ~ gre + gpa + rank, data = mydata, family = "binomial") summary(my.mod) Coefficients: Estimate Std. Error z value Pr(>|z|) (Intercept) -3.989979 1.139951 -3.500 0.000465 *** gre 0.002264 0.001094 2.070 0.038465 * gpa 0.804038 0.331819 2.423 0.015388 * rank2 -0.675443 0.316490 -2.134 0.032829 * rank3 -1.340204 0.345306 -3.881 0.000104 *** rank4 -1.551464 0.417832 -3.713 0.000205 *** --- Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 The level rank1 has been omitted and each coefficient of rank denotes the difference between the coefficient of rank1 and the corresponding rank level. So the difference between the coefficient of rank1 and rank2 would be $-0.675$. The coefficient of rank1 is simply the intercept. So the true coefficient of rank2 would be $-3.99 - 0.675 = -4.67$. The Wald tests here test whether the difference between the coefficient of the reference class (here rank1) and the corresponding levels differ from zero. In this case, we have evidence that the coefficients of all classes differ from the coefficient of rank1. You could also fit the model without an intercept by adding - 1 to the model formula to see all coefficients directly: my.mod2 <- glm(admit ~ gre + gpa + rank - 1, data = mydata, family = "binomial") summary(my.mod2) # no intercept model Coefficients: Estimate Std. Error z value Pr(>|z|) gre 0.002264 0.001094 2.070 0.038465 * gpa 0.804038 0.331819 2.423 0.015388 * rank1 -3.989979 1.139951 -3.500 0.000465 *** rank2 -4.665422 1.109370 -4.205 2.61e-05 *** rank3 -5.330183 1.149538 -4.637 3.54e-06 *** rank4 -5.541443 1.138072 -4.869 1.12e-06 *** --- Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 Note that the intercept is gone now and that the coefficient of rank1 is exactly the intercept of the first model. Here, the Wald test checks not the pairwise difference between coefficients but the hypothesis that each individual coefficient is zero. Again, we have evidence that every coefficient of rank differs from zero. Finally, to check whether the whole variable rank improves the model fit, we fit one model with (my.mod1) and one without the variable rank (my.mod2) and conduct a likelihood ratio test. This tests the hypothesis that all coefficients of rank are zero: my.mod1 <- glm(admit ~ gre + gpa + rank, data = mydata, family = "binomial") # with rank my.mod2 <- glm(admit ~ gre + gpa, data = mydata, family = "binomial") # without rank anova(my.mod1, my.mod2, test="LRT") Analysis of Deviance Table Model 1: admit ~ gre + gpa + rank Model 2: admit ~ gre + gpa Resid. Df Resid. Dev Df Deviance Pr(>Chi) 1 394 458.52 2 397 480.34 -3 -21.826 7.088e-05 *** --- Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 The likelihood ratio test is highly significant and we would conclude that the variable rank should remain in the model. This post is also very interesting.
Significance of categorical predictor in logistic regression
The following explanation is not limited to logistic regression but applies equally in normal linear regression and other GLMs. Usually, R excludes one level of the categorical and the coefficients de
Significance of categorical predictor in logistic regression The following explanation is not limited to logistic regression but applies equally in normal linear regression and other GLMs. Usually, R excludes one level of the categorical and the coefficients denote the difference of each class to this reference class (or sometimes called baseline class) (this is called dummy coding or treatment contrasts in R, see here for an excellent overview of the different contrast options). To see the current contrasts in R, type options("contrasts"). Normally, R orders the levels of the categorical variable alphabetically and takes the first as reference class. This is not always optimal and can be changed by typing (here, we would set the reference class to "c" in the new variable) new.variable <- relevel(old.variable, ref="c"). For each coefficient of every level of the categorical variable, a Wald test is performed to test whether the pairwise difference between the coefficient of the reference class and the other class is different from zero or not. This is what the $z$ and $p$-values in the regression table are. If only one categorical class is significant, this does not imply that the whole variable is meaningless and should be removed from the model. You can check the overall effect of the variable by performing a likelihood ratio test: fit two models, one with and one without the variable and type anova(model1, model2, test="LRT") in R (see example below). Here is an example: mydata <- read.csv("https://stats.idre.ucla.edu/stat/data/binary.csv") mydata$rank <- factor(mydata$rank) my.mod <- glm(admit ~ gre + gpa + rank, data = mydata, family = "binomial") summary(my.mod) Coefficients: Estimate Std. Error z value Pr(>|z|) (Intercept) -3.989979 1.139951 -3.500 0.000465 *** gre 0.002264 0.001094 2.070 0.038465 * gpa 0.804038 0.331819 2.423 0.015388 * rank2 -0.675443 0.316490 -2.134 0.032829 * rank3 -1.340204 0.345306 -3.881 0.000104 *** rank4 -1.551464 0.417832 -3.713 0.000205 *** --- Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 The level rank1 has been omitted and each coefficient of rank denotes the difference between the coefficient of rank1 and the corresponding rank level. So the difference between the coefficient of rank1 and rank2 would be $-0.675$. The coefficient of rank1 is simply the intercept. So the true coefficient of rank2 would be $-3.99 - 0.675 = -4.67$. The Wald tests here test whether the difference between the coefficient of the reference class (here rank1) and the corresponding levels differ from zero. In this case, we have evidence that the coefficients of all classes differ from the coefficient of rank1. You could also fit the model without an intercept by adding - 1 to the model formula to see all coefficients directly: my.mod2 <- glm(admit ~ gre + gpa + rank - 1, data = mydata, family = "binomial") summary(my.mod2) # no intercept model Coefficients: Estimate Std. Error z value Pr(>|z|) gre 0.002264 0.001094 2.070 0.038465 * gpa 0.804038 0.331819 2.423 0.015388 * rank1 -3.989979 1.139951 -3.500 0.000465 *** rank2 -4.665422 1.109370 -4.205 2.61e-05 *** rank3 -5.330183 1.149538 -4.637 3.54e-06 *** rank4 -5.541443 1.138072 -4.869 1.12e-06 *** --- Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 Note that the intercept is gone now and that the coefficient of rank1 is exactly the intercept of the first model. Here, the Wald test checks not the pairwise difference between coefficients but the hypothesis that each individual coefficient is zero. Again, we have evidence that every coefficient of rank differs from zero. Finally, to check whether the whole variable rank improves the model fit, we fit one model with (my.mod1) and one without the variable rank (my.mod2) and conduct a likelihood ratio test. This tests the hypothesis that all coefficients of rank are zero: my.mod1 <- glm(admit ~ gre + gpa + rank, data = mydata, family = "binomial") # with rank my.mod2 <- glm(admit ~ gre + gpa, data = mydata, family = "binomial") # without rank anova(my.mod1, my.mod2, test="LRT") Analysis of Deviance Table Model 1: admit ~ gre + gpa + rank Model 2: admit ~ gre + gpa Resid. Df Resid. Dev Df Deviance Pr(>Chi) 1 394 458.52 2 397 480.34 -3 -21.826 7.088e-05 *** --- Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 The likelihood ratio test is highly significant and we would conclude that the variable rank should remain in the model. This post is also very interesting.
Significance of categorical predictor in logistic regression The following explanation is not limited to logistic regression but applies equally in normal linear regression and other GLMs. Usually, R excludes one level of the categorical and the coefficients de
10,161
Significance of categorical predictor in logistic regression
The $z$-value is just the test-statistic for a statistical test, so if you have trouble interpreting it your first step is to find out what the null hypothesis is. The null hypothesis for the test for CLASS0 is that its coefficient is 0. The coefficient for CLASS0 is the difference in log(odds) between CLASS0 and the reference class (CLASS3?) is zero, or equivalently, that the ratio of the odds for CLASS0 and the reference class is 1. In other words that there is no difference in the odds of success between CLASS0 and the reference class. So does a non-significant coefficient mean you can merge categories? No. First, non-significant means that we cannot reject the hypothesis that there is no difference, but that does not mean that no such differences exist. An absence of evidence is not the same thing as evidence of absence. Second, merging categories, especially the reference category, changes the interpretation of all other coefficients. Whether or not that makes sense depends on what those different classes stand for. Does that mean that the entire categorical variable is a "bad" (non-significant) predictor? No, for that you would need to perform a simultaneous test for all CLASS terms.
Significance of categorical predictor in logistic regression
The $z$-value is just the test-statistic for a statistical test, so if you have trouble interpreting it your first step is to find out what the null hypothesis is. The null hypothesis for the test for
Significance of categorical predictor in logistic regression The $z$-value is just the test-statistic for a statistical test, so if you have trouble interpreting it your first step is to find out what the null hypothesis is. The null hypothesis for the test for CLASS0 is that its coefficient is 0. The coefficient for CLASS0 is the difference in log(odds) between CLASS0 and the reference class (CLASS3?) is zero, or equivalently, that the ratio of the odds for CLASS0 and the reference class is 1. In other words that there is no difference in the odds of success between CLASS0 and the reference class. So does a non-significant coefficient mean you can merge categories? No. First, non-significant means that we cannot reject the hypothesis that there is no difference, but that does not mean that no such differences exist. An absence of evidence is not the same thing as evidence of absence. Second, merging categories, especially the reference category, changes the interpretation of all other coefficients. Whether or not that makes sense depends on what those different classes stand for. Does that mean that the entire categorical variable is a "bad" (non-significant) predictor? No, for that you would need to perform a simultaneous test for all CLASS terms.
Significance of categorical predictor in logistic regression The $z$-value is just the test-statistic for a statistical test, so if you have trouble interpreting it your first step is to find out what the null hypothesis is. The null hypothesis for the test for
10,162
Why not just dump the neural networks and deep learning? [closed]
Not being able to know what solution generalizes best is an issue, but it shouldn't deter us from otherwise using a good solution. Humans themselves often do not known what generalizes best (consider, for example, competing unifying theories of physics), but that doesn't cause us too many problems. It has been shown that it is extremely rare for training to fail because of local minimums. Most of the local minimums in a deep neural network are close in value to the global minimum, so this is not an issue. source But the broader answer is that you can talk all day about nonconvexity and model selection, and people will still use neural networks simply because they work better than anything else (at least on things like image classification). Of course there are also people arguing that we shouldn't get too focused on CNNs like the community was focused on SVMs a few decades ago, and instead keep looking for the next big thing. In particular, I think I remember Hinton regretting the effectiveness of CNNs as something which might hinder research. related post
Why not just dump the neural networks and deep learning? [closed]
Not being able to know what solution generalizes best is an issue, but it shouldn't deter us from otherwise using a good solution. Humans themselves often do not known what generalizes best (consider,
Why not just dump the neural networks and deep learning? [closed] Not being able to know what solution generalizes best is an issue, but it shouldn't deter us from otherwise using a good solution. Humans themselves often do not known what generalizes best (consider, for example, competing unifying theories of physics), but that doesn't cause us too many problems. It has been shown that it is extremely rare for training to fail because of local minimums. Most of the local minimums in a deep neural network are close in value to the global minimum, so this is not an issue. source But the broader answer is that you can talk all day about nonconvexity and model selection, and people will still use neural networks simply because they work better than anything else (at least on things like image classification). Of course there are also people arguing that we shouldn't get too focused on CNNs like the community was focused on SVMs a few decades ago, and instead keep looking for the next big thing. In particular, I think I remember Hinton regretting the effectiveness of CNNs as something which might hinder research. related post
Why not just dump the neural networks and deep learning? [closed] Not being able to know what solution generalizes best is an issue, but it shouldn't deter us from otherwise using a good solution. Humans themselves often do not known what generalizes best (consider,
10,163
Why not just dump the neural networks and deep learning? [closed]
As the comments to your question point out, there are a lot of people working on finding something better. I would though like to answer this question by expanding the comment left by @josh All models are wrong but some are useful (Wiki) The above statement is a general truth used to describe the nature of statistical models. Using data that we have available, we can create models that let us do useful things such as approximate a predicted value. Take for example Linear Regression Using a number of observations, we can fit a model to give us an approximate value for a dependent variable given any value(s) for the independent variable(s). Burnham, K. P.; Anderson, D. R. (2002), Model Selection and Multimodel > Inference: A Practical Information-Theoretic Approach (2nd ed.): "A model is a simplification or approximation of reality and hence will not reflect all of reality. ... Box noted that “all models are wrong, but some are useful.” While a model can never be “truth,” a model might be ranked from very useful, to useful, to somewhat useful to, finally, essentially useless." Deviations from our model (as can be seen in the image above) appear random, some observations are below the line and some are above, but our regression line shows a general correlation. Whilst deviations in our model appear random, in realistic scenarios there will be other factors at play which cause this deviation. For example, imagine watching cars as they drove through a junction where they must turn either left or right to continue, the cars turn in no particular pattern. Whilst we could say that the direction the cars turn is completely random, does every driver reach the junction and at that point make a random decision of which way to turn? In reality they are probably heading somewhere specific for a specific reason, and without attempting to stop each car to ask them about their reasoning, we can only describe their actions as random. Where we are able to fit a model with minimal deviation, how certain can we be that an unknown, unnoticed or immeasurable variable wont at some point throw our model? Does the flap of a butterfly’s wings in Brazil set off a tornado in Texas? The problem with using the Linear and SVN models you mention alone is that we are somewhat required to manually observe our variables and how they each affect each other. We then need to decide what variables are important and write a task-specific algorithm. This can be straight forward if we only have a few variables, but what if we had thousands? What if we wanted to create a generalised image recognition model, could this realistically be achieved with this approach? Deep Learning and Artificial Neural Networks (ANNs) can help us create useful models for huge data sets containing huge amounts of variables (e.g. image libraries). As you mention, there's an incomprehensible number of solutions which could fit the data using ANNs, but is this number really any different to the amount of solutions we would need to develop ourselves through trial and error? The application of ANNs do much of the work for us, we can specify our inputs and our desired outputs (and tweak them later to make improvements) and leave it up to the ANN to figure out the solution. This is why ANNs are often described as "black boxes". From a given input they output an approximation, however (in general terms) these approximations don't include details on how they were approximated. And so it really comes down to what problem you are trying to solve, as the problem will dictate what model approach is more useful. Models are not absolutely accurate and so there is always an element of being 'wrong', however the more accurate your results the more useful they are. Having more detail in the results on how the approximation was made may also be useful, depending on the problem it may even be more useful than increased accuracy. If for example you are calculating a persons credit score, using regression and SVMs provides calculations that can be better explored. Being able to both tweak the model directly and explain to customers the effect separate independent variables have on their overall score is very useful. An ANN may aid in processing larger amounts of variables to achieve a more accurate score, but would this accuracy be more useful?
Why not just dump the neural networks and deep learning? [closed]
As the comments to your question point out, there are a lot of people working on finding something better. I would though like to answer this question by expanding the comment left by @josh All model
Why not just dump the neural networks and deep learning? [closed] As the comments to your question point out, there are a lot of people working on finding something better. I would though like to answer this question by expanding the comment left by @josh All models are wrong but some are useful (Wiki) The above statement is a general truth used to describe the nature of statistical models. Using data that we have available, we can create models that let us do useful things such as approximate a predicted value. Take for example Linear Regression Using a number of observations, we can fit a model to give us an approximate value for a dependent variable given any value(s) for the independent variable(s). Burnham, K. P.; Anderson, D. R. (2002), Model Selection and Multimodel > Inference: A Practical Information-Theoretic Approach (2nd ed.): "A model is a simplification or approximation of reality and hence will not reflect all of reality. ... Box noted that “all models are wrong, but some are useful.” While a model can never be “truth,” a model might be ranked from very useful, to useful, to somewhat useful to, finally, essentially useless." Deviations from our model (as can be seen in the image above) appear random, some observations are below the line and some are above, but our regression line shows a general correlation. Whilst deviations in our model appear random, in realistic scenarios there will be other factors at play which cause this deviation. For example, imagine watching cars as they drove through a junction where they must turn either left or right to continue, the cars turn in no particular pattern. Whilst we could say that the direction the cars turn is completely random, does every driver reach the junction and at that point make a random decision of which way to turn? In reality they are probably heading somewhere specific for a specific reason, and without attempting to stop each car to ask them about their reasoning, we can only describe their actions as random. Where we are able to fit a model with minimal deviation, how certain can we be that an unknown, unnoticed or immeasurable variable wont at some point throw our model? Does the flap of a butterfly’s wings in Brazil set off a tornado in Texas? The problem with using the Linear and SVN models you mention alone is that we are somewhat required to manually observe our variables and how they each affect each other. We then need to decide what variables are important and write a task-specific algorithm. This can be straight forward if we only have a few variables, but what if we had thousands? What if we wanted to create a generalised image recognition model, could this realistically be achieved with this approach? Deep Learning and Artificial Neural Networks (ANNs) can help us create useful models for huge data sets containing huge amounts of variables (e.g. image libraries). As you mention, there's an incomprehensible number of solutions which could fit the data using ANNs, but is this number really any different to the amount of solutions we would need to develop ourselves through trial and error? The application of ANNs do much of the work for us, we can specify our inputs and our desired outputs (and tweak them later to make improvements) and leave it up to the ANN to figure out the solution. This is why ANNs are often described as "black boxes". From a given input they output an approximation, however (in general terms) these approximations don't include details on how they were approximated. And so it really comes down to what problem you are trying to solve, as the problem will dictate what model approach is more useful. Models are not absolutely accurate and so there is always an element of being 'wrong', however the more accurate your results the more useful they are. Having more detail in the results on how the approximation was made may also be useful, depending on the problem it may even be more useful than increased accuracy. If for example you are calculating a persons credit score, using regression and SVMs provides calculations that can be better explored. Being able to both tweak the model directly and explain to customers the effect separate independent variables have on their overall score is very useful. An ANN may aid in processing larger amounts of variables to achieve a more accurate score, but would this accuracy be more useful?
Why not just dump the neural networks and deep learning? [closed] As the comments to your question point out, there are a lot of people working on finding something better. I would though like to answer this question by expanding the comment left by @josh All model
10,164
Why not just dump the neural networks and deep learning? [closed]
The global minimum may as well as be useless, so we don't really care if we find it or not. The reason is that, for deep networks, not only the time to find it becomes exponentially longer as the network size increases, but also the global minimum often corresponds to overfitting the training set. Thus the generalization ability of the DNN (which is what we really care about) would suffer. Also, often we prefer flatter minima corresponding to a higher value of the loss function, than sharper minima corresponding to a lower value of the loss function, because the second one will deal very badly with uncertainty in the inputs. This is becoming increasingly clear with the development of Bayesian Deep Learning. Robust Optimization beats Determinist Optimization very often, when applied to real world problems where uncertainty is important. Finally, it's a fact that DNNs just kick the ass of methods such as XGBoost at image classification and NLP. A company which must make a profit out of image classification will correctly select them as models to be deployed in production (and invest a significant amount of money on feature engineering, data pipeline, etc. but I digress). This doesn't mean that they dominate all the ML environment: for example, they do worse than XGBoost on structured data (see the last winners of Kaggle competitions) and they seem to not still do as well as particle filters on time series modelling. However, some very recent innovations on RNNs may modify this situation.
Why not just dump the neural networks and deep learning? [closed]
The global minimum may as well as be useless, so we don't really care if we find it or not. The reason is that, for deep networks, not only the time to find it becomes exponentially longer as the netw
Why not just dump the neural networks and deep learning? [closed] The global minimum may as well as be useless, so we don't really care if we find it or not. The reason is that, for deep networks, not only the time to find it becomes exponentially longer as the network size increases, but also the global minimum often corresponds to overfitting the training set. Thus the generalization ability of the DNN (which is what we really care about) would suffer. Also, often we prefer flatter minima corresponding to a higher value of the loss function, than sharper minima corresponding to a lower value of the loss function, because the second one will deal very badly with uncertainty in the inputs. This is becoming increasingly clear with the development of Bayesian Deep Learning. Robust Optimization beats Determinist Optimization very often, when applied to real world problems where uncertainty is important. Finally, it's a fact that DNNs just kick the ass of methods such as XGBoost at image classification and NLP. A company which must make a profit out of image classification will correctly select them as models to be deployed in production (and invest a significant amount of money on feature engineering, data pipeline, etc. but I digress). This doesn't mean that they dominate all the ML environment: for example, they do worse than XGBoost on structured data (see the last winners of Kaggle competitions) and they seem to not still do as well as particle filters on time series modelling. However, some very recent innovations on RNNs may modify this situation.
Why not just dump the neural networks and deep learning? [closed] The global minimum may as well as be useless, so we don't really care if we find it or not. The reason is that, for deep networks, not only the time to find it becomes exponentially longer as the netw
10,165
Why not just dump the neural networks and deep learning? [closed]
I think the best way to think about this question is through the competitive market place. If you dump deep learning, and your competitors use it, AND it happens to work better than what you used, then you'll be beaten on the market place. I think that's what's happening, in part, today, i.e. deep learning seems to work better than anything for the whole lot of problems on market place. For instance, online language translators using deep learning are better than the purely linguistic approaches that were used before. Just a few years ago this was not the case, but advances in deep learning brought those who used to the leadership positions on the market. I keep repeating "the market" because that's what's driving the current surge in deep learning. The moment business finds something useful, that something will become wide spread. It's not that we, the committee, that decided that deep learning should be popular. It's business and competition. The second part, is that in addition to actual success of ML, there's also fear to miss the boat. A lot of businesses are paranoid that if they miss out on AI, they'll fail as businesses. This fear is being fed by all these consulting houses, Gartners etc., whispering to CEOs that they must do AI or die tomorrow. Nobody's forcing businesses to use deep learning. IT and R&D are excited with a new toy. Academia's cheering, so this party's going to last until the music stops, i.e. until deep learning stops delivering. In the meantime you can dump it and come up up with a better solution.
Why not just dump the neural networks and deep learning? [closed]
I think the best way to think about this question is through the competitive market place. If you dump deep learning, and your competitors use it, AND it happens to work better than what you used, the
Why not just dump the neural networks and deep learning? [closed] I think the best way to think about this question is through the competitive market place. If you dump deep learning, and your competitors use it, AND it happens to work better than what you used, then you'll be beaten on the market place. I think that's what's happening, in part, today, i.e. deep learning seems to work better than anything for the whole lot of problems on market place. For instance, online language translators using deep learning are better than the purely linguistic approaches that were used before. Just a few years ago this was not the case, but advances in deep learning brought those who used to the leadership positions on the market. I keep repeating "the market" because that's what's driving the current surge in deep learning. The moment business finds something useful, that something will become wide spread. It's not that we, the committee, that decided that deep learning should be popular. It's business and competition. The second part, is that in addition to actual success of ML, there's also fear to miss the boat. A lot of businesses are paranoid that if they miss out on AI, they'll fail as businesses. This fear is being fed by all these consulting houses, Gartners etc., whispering to CEOs that they must do AI or die tomorrow. Nobody's forcing businesses to use deep learning. IT and R&D are excited with a new toy. Academia's cheering, so this party's going to last until the music stops, i.e. until deep learning stops delivering. In the meantime you can dump it and come up up with a better solution.
Why not just dump the neural networks and deep learning? [closed] I think the best way to think about this question is through the competitive market place. If you dump deep learning, and your competitors use it, AND it happens to work better than what you used, the
10,166
Why not just dump the neural networks and deep learning? [closed]
There are excellent answers, mostly weighing in with the usefulness of DL and ANNs. But I would like to object the OP in a more fundamental way, since the question already takes for granted the mathematical inconsistency of neural networks. First of all, there is a mathematical theory behind (most models of) Neural Networks. You could likewise argue that linear regression does not generalize, unless the underlying model is... well, linear. In neural algorithms, a model is assumed (even if not explicitly) and the fitting error is computed. The fact that algorithms are modified with various heuristics does not void the original mathematical support. BTW, local optimization is also a mathematically consistent, let alone useful, theory. Along this line, if Neural Networks just constitute one class of methods within the whole toolbox of scientists, which is the line that separates Neural Networks from the rest of techniques? In fact, SVMs were once considered a class of NNs and they still appear in the same books. On the other hand, NNs could be regarded as a (nonlinear) regression technique, maybe with some simplification. I agree with the OP that we must search better, well founded, efficient algorithms, regardless you label them as NNs or not.
Why not just dump the neural networks and deep learning? [closed]
There are excellent answers, mostly weighing in with the usefulness of DL and ANNs. But I would like to object the OP in a more fundamental way, since the question already takes for granted the mathem
Why not just dump the neural networks and deep learning? [closed] There are excellent answers, mostly weighing in with the usefulness of DL and ANNs. But I would like to object the OP in a more fundamental way, since the question already takes for granted the mathematical inconsistency of neural networks. First of all, there is a mathematical theory behind (most models of) Neural Networks. You could likewise argue that linear regression does not generalize, unless the underlying model is... well, linear. In neural algorithms, a model is assumed (even if not explicitly) and the fitting error is computed. The fact that algorithms are modified with various heuristics does not void the original mathematical support. BTW, local optimization is also a mathematically consistent, let alone useful, theory. Along this line, if Neural Networks just constitute one class of methods within the whole toolbox of scientists, which is the line that separates Neural Networks from the rest of techniques? In fact, SVMs were once considered a class of NNs and they still appear in the same books. On the other hand, NNs could be regarded as a (nonlinear) regression technique, maybe with some simplification. I agree with the OP that we must search better, well founded, efficient algorithms, regardless you label them as NNs or not.
Why not just dump the neural networks and deep learning? [closed] There are excellent answers, mostly weighing in with the usefulness of DL and ANNs. But I would like to object the OP in a more fundamental way, since the question already takes for granted the mathem
10,167
Why not just dump the neural networks and deep learning? [closed]
I guess for some problem we care less for the mathematical rigor and simplicity but more for its utility, current status is neural network is better in performing certain task like pattern recognition in image processing.
Why not just dump the neural networks and deep learning? [closed]
I guess for some problem we care less for the mathematical rigor and simplicity but more for its utility, current status is neural network is better in performing certain task like pattern recognition
Why not just dump the neural networks and deep learning? [closed] I guess for some problem we care less for the mathematical rigor and simplicity but more for its utility, current status is neural network is better in performing certain task like pattern recognition in image processing.
Why not just dump the neural networks and deep learning? [closed] I guess for some problem we care less for the mathematical rigor and simplicity but more for its utility, current status is neural network is better in performing certain task like pattern recognition
10,168
Why not just dump the neural networks and deep learning? [closed]
There is a lot in this question. Lets go over what you've wrote one by one. The solutions that fit training data are infinite. We don't have precise mathematical equation that is satisfied by only a single one and that we can say generalizes best. The fact that there are infinite many solutions comes from learning problem being an ill-posed problem so there cannot be a single one that generalizes best. Also, by no free lunch theorem whichever method we use cannot guarantee that it is the best across all learning problems. Simply speaking we don't know which generalizes best. This statement is not really true. There are theorems on empirical risk minimization by Vapnik & Chervonenkis that connect the number of samples, VC dimension of the learning method and the generalization error. Note, that this only applies for a given dataset. So given a dataset and a learning procedure we know the bounds on generalization. Note that, for different datasets there are no and cannot be single best learning procedure due to no free lunch theorem. Optimizing weights is not a convex problem, so we never know we end up with a global or a local minimum. So why not just dump the neural networks and instead search for a better ML model? Here there are few things that you need to keep in mind. Optimizing non-convex problem is not as easy as convex one; that is true. However, the class of learning methods that are convex is limited (linear regression, SVMs) and in practice, they perform worse than the class of non-convex (boosting, CNNs) on a variety of problems. So the crucial part is that in practice neural nets work best. Although there are a number of very important elements that make neural nets work well: They can be applied on very large datasets due to stochastic gradient descent. Unlike SVMs, inference with deep nets does not depend on the dataset. This makes neural nets efficient at test time. With neural nets it is possible to directly control their learning capacity (think of number of parameters) simply by adding more layers or making them bigger. This is crucial since for different datasets you might want bigger or smaller models. Something that we understand, and something that is consistent with a set of mathematical equations? Linear and SVM do not have this mathematical drawbacks and are fully consistent with a a set of mathematical equations. Why not just think on same lines (need not be linear though) and come up with a new ML model better than Linear and SVM and neural networks and deep learning? Dumping things that work because of not understanding them is not a great research direction. Making an effort in understanding them is, on the other hand, great research direction. Also, I disagree that neural networks are inconsistent with mathematical equations. They are quite consistent. We know how to optimize them and perform inference.
Why not just dump the neural networks and deep learning? [closed]
There is a lot in this question. Lets go over what you've wrote one by one. The solutions that fit training data are infinite. We don't have precise mathematical equation that is satisfied by only a
Why not just dump the neural networks and deep learning? [closed] There is a lot in this question. Lets go over what you've wrote one by one. The solutions that fit training data are infinite. We don't have precise mathematical equation that is satisfied by only a single one and that we can say generalizes best. The fact that there are infinite many solutions comes from learning problem being an ill-posed problem so there cannot be a single one that generalizes best. Also, by no free lunch theorem whichever method we use cannot guarantee that it is the best across all learning problems. Simply speaking we don't know which generalizes best. This statement is not really true. There are theorems on empirical risk minimization by Vapnik & Chervonenkis that connect the number of samples, VC dimension of the learning method and the generalization error. Note, that this only applies for a given dataset. So given a dataset and a learning procedure we know the bounds on generalization. Note that, for different datasets there are no and cannot be single best learning procedure due to no free lunch theorem. Optimizing weights is not a convex problem, so we never know we end up with a global or a local minimum. So why not just dump the neural networks and instead search for a better ML model? Here there are few things that you need to keep in mind. Optimizing non-convex problem is not as easy as convex one; that is true. However, the class of learning methods that are convex is limited (linear regression, SVMs) and in practice, they perform worse than the class of non-convex (boosting, CNNs) on a variety of problems. So the crucial part is that in practice neural nets work best. Although there are a number of very important elements that make neural nets work well: They can be applied on very large datasets due to stochastic gradient descent. Unlike SVMs, inference with deep nets does not depend on the dataset. This makes neural nets efficient at test time. With neural nets it is possible to directly control their learning capacity (think of number of parameters) simply by adding more layers or making them bigger. This is crucial since for different datasets you might want bigger or smaller models. Something that we understand, and something that is consistent with a set of mathematical equations? Linear and SVM do not have this mathematical drawbacks and are fully consistent with a a set of mathematical equations. Why not just think on same lines (need not be linear though) and come up with a new ML model better than Linear and SVM and neural networks and deep learning? Dumping things that work because of not understanding them is not a great research direction. Making an effort in understanding them is, on the other hand, great research direction. Also, I disagree that neural networks are inconsistent with mathematical equations. They are quite consistent. We know how to optimize them and perform inference.
Why not just dump the neural networks and deep learning? [closed] There is a lot in this question. Lets go over what you've wrote one by one. The solutions that fit training data are infinite. We don't have precise mathematical equation that is satisfied by only a
10,169
Why not just dump the neural networks and deep learning? [closed]
How about viewing neural networks from an experimental point of view? Just because we created them doesn't mean that we're obligued to understand them intuitively. Or that we're not allowed to play with them in order to have a better grasp of what they're doing. Here's a couple of thoughts I have on them: Structure: they are hierarchies. They are like trees that share inputs. The roots are the inputs and the leafs are the output layer. The closer the layer is to the outputs, the more relevant it is to them, the greater level of abstraction It contains (it's more about the picture than the pixels). Functionality: they "play" with data, the modus operandi is to experiment with relationships in neurons (weights) until things "click" (the error margin is acceptable). This is consistent with how we think. It's even consistent with how the scientific method operates. So by cracking neural networks we may also be solving the general question of what knowledge represents.
Why not just dump the neural networks and deep learning? [closed]
How about viewing neural networks from an experimental point of view? Just because we created them doesn't mean that we're obligued to understand them intuitively. Or that we're not allowed to play wi
Why not just dump the neural networks and deep learning? [closed] How about viewing neural networks from an experimental point of view? Just because we created them doesn't mean that we're obligued to understand them intuitively. Or that we're not allowed to play with them in order to have a better grasp of what they're doing. Here's a couple of thoughts I have on them: Structure: they are hierarchies. They are like trees that share inputs. The roots are the inputs and the leafs are the output layer. The closer the layer is to the outputs, the more relevant it is to them, the greater level of abstraction It contains (it's more about the picture than the pixels). Functionality: they "play" with data, the modus operandi is to experiment with relationships in neurons (weights) until things "click" (the error margin is acceptable). This is consistent with how we think. It's even consistent with how the scientific method operates. So by cracking neural networks we may also be solving the general question of what knowledge represents.
Why not just dump the neural networks and deep learning? [closed] How about viewing neural networks from an experimental point of view? Just because we created them doesn't mean that we're obligued to understand them intuitively. Or that we're not allowed to play wi
10,170
Why not just dump the neural networks and deep learning? [closed]
Don't forget, there is a vast field of research that use LMs, GLM, multilevel modelling. Lately Bayesian techniques and Hamiltonian Monte Carlo(the STAN community is really at the forefront of this) have come of age and a number of problems that are solved by STAN really easily and don't really need NNs or deep nets. Social Science research, Microeconomics are two(large) examples of such fields adopting Stan rapidly. Stan models are very "readable". The coefficients actually have a posterior distributional interpretation and so do the predictions. The priors are part of the data generating process and don't need to be conjugate to be performant(like gibbs). The model fitting in stan is a delight, it actually tunes the pesky MCMC params automatically pretty darn well and warns you when the exploration is stuck with really nice visualizations. If you haven't tried it already see awesome stan demos here). At the end of the day I think people don't talk about this stuff so much because the research in this field and the problems are not so "sexy"/"cool" as with NNs.
Why not just dump the neural networks and deep learning? [closed]
Don't forget, there is a vast field of research that use LMs, GLM, multilevel modelling. Lately Bayesian techniques and Hamiltonian Monte Carlo(the STAN community is really at the forefront of this) h
Why not just dump the neural networks and deep learning? [closed] Don't forget, there is a vast field of research that use LMs, GLM, multilevel modelling. Lately Bayesian techniques and Hamiltonian Monte Carlo(the STAN community is really at the forefront of this) have come of age and a number of problems that are solved by STAN really easily and don't really need NNs or deep nets. Social Science research, Microeconomics are two(large) examples of such fields adopting Stan rapidly. Stan models are very "readable". The coefficients actually have a posterior distributional interpretation and so do the predictions. The priors are part of the data generating process and don't need to be conjugate to be performant(like gibbs). The model fitting in stan is a delight, it actually tunes the pesky MCMC params automatically pretty darn well and warns you when the exploration is stuck with really nice visualizations. If you haven't tried it already see awesome stan demos here). At the end of the day I think people don't talk about this stuff so much because the research in this field and the problems are not so "sexy"/"cool" as with NNs.
Why not just dump the neural networks and deep learning? [closed] Don't forget, there is a vast field of research that use LMs, GLM, multilevel modelling. Lately Bayesian techniques and Hamiltonian Monte Carlo(the STAN community is really at the forefront of this) h
10,171
Why not just dump the neural networks and deep learning? [closed]
What typically happens when there is no mathematical consistency (atleast in this case of neural networks)...when its not giving results as desired, on the test set, your boss will come back and say...Hey why don't you try Drop out (which weights,which layer, how many is your headache as there isn't mathematical way to determine), so after you try and hopefully got a marginal improvement but not the desired, your boss will come back and say, why not try weight decay(what factor?)? and later, why don't you try ReLU or some other activation on some layers, and still not, why not try 'max pooling'? still not, why not try batch normalization, still not, or atleast convergence, but not desired result, Oh you are in a local minimum, try different learning rate schedule, just change the network architecture? and repeat all above in different combinations! Keep it in a loop until you succeed! On the other hand, when you try a consistent SVM, after convergence, if the result is not good, then okay, the linear kernel we are using is not good enough as the data may not be linear, use a different shaped kernel, try a different shaped kernel if you have any hunch, if still not, just leave it, its a limitation of SVM. What I am saying is ,the neural networks being so inconsistent, that it is not even wrong! It never accepts its defeat! The engineer/designer takes the burden, in case it does not work as desired.
Why not just dump the neural networks and deep learning? [closed]
What typically happens when there is no mathematical consistency (atleast in this case of neural networks)...when its not giving results as desired, on the test set, your boss will come back and say..
Why not just dump the neural networks and deep learning? [closed] What typically happens when there is no mathematical consistency (atleast in this case of neural networks)...when its not giving results as desired, on the test set, your boss will come back and say...Hey why don't you try Drop out (which weights,which layer, how many is your headache as there isn't mathematical way to determine), so after you try and hopefully got a marginal improvement but not the desired, your boss will come back and say, why not try weight decay(what factor?)? and later, why don't you try ReLU or some other activation on some layers, and still not, why not try 'max pooling'? still not, why not try batch normalization, still not, or atleast convergence, but not desired result, Oh you are in a local minimum, try different learning rate schedule, just change the network architecture? and repeat all above in different combinations! Keep it in a loop until you succeed! On the other hand, when you try a consistent SVM, after convergence, if the result is not good, then okay, the linear kernel we are using is not good enough as the data may not be linear, use a different shaped kernel, try a different shaped kernel if you have any hunch, if still not, just leave it, its a limitation of SVM. What I am saying is ,the neural networks being so inconsistent, that it is not even wrong! It never accepts its defeat! The engineer/designer takes the burden, in case it does not work as desired.
Why not just dump the neural networks and deep learning? [closed] What typically happens when there is no mathematical consistency (atleast in this case of neural networks)...when its not giving results as desired, on the test set, your boss will come back and say..
10,172
Why do residuals in linear regression always sum to zero when an intercept is included?
This follows directly from the normal equations, i.e. the equations that the OLS estimator solves, $$\mathbf{X}^{\prime} \underbrace{\left( \mathbf{y} - \mathbf{X} \mathbf{b} \right)}_{\mathbf{e}} = 0 $$ The vector inside the parentheses is of course the residual vector or the projection of $\mathbf{y}$ onto the orthogonal complement of the column space of $X$, if you like linear algebra. Now including a vector of ones in the $\mathbf{X}$ matrix, which by the way doesn't have to be in the first column as is conventionally done, leads to $$\mathbf{1}^{\prime} \mathbf{e} = 0 \implies \sum_{i=1}^n e_i = 0$$ In the two-variable problem this is even simpler to see, as minimizing the sum of squared residuals brings us to $$\sum_{i=1}^n \left(y_i - a - b x_i \right) = 0$$ when we take the derivative with respect to the intercept. From this then we proceed to obtain the familiar estimator $$a = \bar{y} - b \bar{x}$$ where again we see that the construction of our estimators imposes this condition.
Why do residuals in linear regression always sum to zero when an intercept is included?
This follows directly from the normal equations, i.e. the equations that the OLS estimator solves, $$\mathbf{X}^{\prime} \underbrace{\left( \mathbf{y} - \mathbf{X} \mathbf{b} \right)}_{\mathbf{e}} = 0
Why do residuals in linear regression always sum to zero when an intercept is included? This follows directly from the normal equations, i.e. the equations that the OLS estimator solves, $$\mathbf{X}^{\prime} \underbrace{\left( \mathbf{y} - \mathbf{X} \mathbf{b} \right)}_{\mathbf{e}} = 0 $$ The vector inside the parentheses is of course the residual vector or the projection of $\mathbf{y}$ onto the orthogonal complement of the column space of $X$, if you like linear algebra. Now including a vector of ones in the $\mathbf{X}$ matrix, which by the way doesn't have to be in the first column as is conventionally done, leads to $$\mathbf{1}^{\prime} \mathbf{e} = 0 \implies \sum_{i=1}^n e_i = 0$$ In the two-variable problem this is even simpler to see, as minimizing the sum of squared residuals brings us to $$\sum_{i=1}^n \left(y_i - a - b x_i \right) = 0$$ when we take the derivative with respect to the intercept. From this then we proceed to obtain the familiar estimator $$a = \bar{y} - b \bar{x}$$ where again we see that the construction of our estimators imposes this condition.
Why do residuals in linear regression always sum to zero when an intercept is included? This follows directly from the normal equations, i.e. the equations that the OLS estimator solves, $$\mathbf{X}^{\prime} \underbrace{\left( \mathbf{y} - \mathbf{X} \mathbf{b} \right)}_{\mathbf{e}} = 0
10,173
Why do residuals in linear regression always sum to zero when an intercept is included?
In case you are looking for a rather intuitive explanation. In some sense, the linear regression model is nothing but a fancy mean. To find the arithmetic mean $\bar{x}$ over some values $x_1, x_2, \dots, x_n$, we find a value that is a measure of centrality in a sense that the sum of all deviations (where each deviation is defined as $u_i = x_i - \bar{x}$) to the right of the mean value are equal to the sum of all the deviations to the left of that mean. There is no inherent reason why this measure is good, let alone the best way to describe the mean of a sample, but it is certainly intuitive and practical. The important point is, that by defining the arithmetic mean in this way, it necessarily follows that once we constructed the arithmetic mean, all deviations from that mean must sum to zero by definition! In linear regression, this is no different. We fit the line such that the sum of all differences between our fitted values (which are on the regression line) and the actual values that are above the line is exactly equal to the sum of all differences between the regression line and all values below the line. Again, there is no inherent reason, why this is the best way to construct a fit, but it is straightforward and intuitively appealing. Just as with the arithmetic mean: by constructing our fitted values in this way, it necessarily follows, by construction, that all deviations from that line must sum to zero for otherwise this just wouldn't be an OLS regession.
Why do residuals in linear regression always sum to zero when an intercept is included?
In case you are looking for a rather intuitive explanation. In some sense, the linear regression model is nothing but a fancy mean. To find the arithmetic mean $\bar{x}$ over some values $x_1, x_2, \d
Why do residuals in linear regression always sum to zero when an intercept is included? In case you are looking for a rather intuitive explanation. In some sense, the linear regression model is nothing but a fancy mean. To find the arithmetic mean $\bar{x}$ over some values $x_1, x_2, \dots, x_n$, we find a value that is a measure of centrality in a sense that the sum of all deviations (where each deviation is defined as $u_i = x_i - \bar{x}$) to the right of the mean value are equal to the sum of all the deviations to the left of that mean. There is no inherent reason why this measure is good, let alone the best way to describe the mean of a sample, but it is certainly intuitive and practical. The important point is, that by defining the arithmetic mean in this way, it necessarily follows that once we constructed the arithmetic mean, all deviations from that mean must sum to zero by definition! In linear regression, this is no different. We fit the line such that the sum of all differences between our fitted values (which are on the regression line) and the actual values that are above the line is exactly equal to the sum of all differences between the regression line and all values below the line. Again, there is no inherent reason, why this is the best way to construct a fit, but it is straightforward and intuitively appealing. Just as with the arithmetic mean: by constructing our fitted values in this way, it necessarily follows, by construction, that all deviations from that line must sum to zero for otherwise this just wouldn't be an OLS regession.
Why do residuals in linear regression always sum to zero when an intercept is included? In case you are looking for a rather intuitive explanation. In some sense, the linear regression model is nothing but a fancy mean. To find the arithmetic mean $\bar{x}$ over some values $x_1, x_2, \d
10,174
Why do residuals in linear regression always sum to zero when an intercept is included?
When an intercept is included in multiple linear regression, $$ \hat{y}_i = \beta_0 + \beta_1x_{i,1} + \beta_2x_{i,2} +…+ \beta_px_{i,p} $$ In Least squares regression, the sum of the squares of the errors is minimized. $$ SSE=\displaystyle\sum\limits_{i=1}^n \left(e_i \right)^2= \sum_{i=1}^n\left(y_i - \hat{y_i} \right)^2= \sum_{i=1}^n\left(y_i -\beta_0- \beta_1x_{i,1}-\beta_2x_{i,2}-…- \beta_px_{i,p} \right)^2 $$ Take the partial derivative of SSE with respect to $\beta_0$ and setting it to zero. $$ \frac{\partial{SSE}}{\partial{\beta_0}} = \sum_{i=1}^n 2\left(y_i -\beta_0- \beta_1x_{i,1}-\beta_2x_{i,2}-…- \beta_px_{i,p} \right)^1 (-1) =-2\displaystyle\sum\limits_{i=1}^ne_i=0 $$ Hence, the residuals always sum to zero when an intercept is included in linear regression.
Why do residuals in linear regression always sum to zero when an intercept is included?
When an intercept is included in multiple linear regression, $$ \hat{y}_i = \beta_0 + \beta_1x_{i,1} + \beta_2x_{i,2} +…+ \beta_px_{i,p} $$ In Least squares regression, the sum of the squares of the e
Why do residuals in linear regression always sum to zero when an intercept is included? When an intercept is included in multiple linear regression, $$ \hat{y}_i = \beta_0 + \beta_1x_{i,1} + \beta_2x_{i,2} +…+ \beta_px_{i,p} $$ In Least squares regression, the sum of the squares of the errors is minimized. $$ SSE=\displaystyle\sum\limits_{i=1}^n \left(e_i \right)^2= \sum_{i=1}^n\left(y_i - \hat{y_i} \right)^2= \sum_{i=1}^n\left(y_i -\beta_0- \beta_1x_{i,1}-\beta_2x_{i,2}-…- \beta_px_{i,p} \right)^2 $$ Take the partial derivative of SSE with respect to $\beta_0$ and setting it to zero. $$ \frac{\partial{SSE}}{\partial{\beta_0}} = \sum_{i=1}^n 2\left(y_i -\beta_0- \beta_1x_{i,1}-\beta_2x_{i,2}-…- \beta_px_{i,p} \right)^1 (-1) =-2\displaystyle\sum\limits_{i=1}^ne_i=0 $$ Hence, the residuals always sum to zero when an intercept is included in linear regression.
Why do residuals in linear regression always sum to zero when an intercept is included? When an intercept is included in multiple linear regression, $$ \hat{y}_i = \beta_0 + \beta_1x_{i,1} + \beta_2x_{i,2} +…+ \beta_px_{i,p} $$ In Least squares regression, the sum of the squares of the e
10,175
Why do residuals in linear regression always sum to zero when an intercept is included?
Write the linear model in matrical form as \begin{align} y = X\beta + \varepsilon, \end{align} where $y \in \mathbb{R}^n$ is the response vector, $X \in \mathbb{R}^{n \times p}$ is the design matrix, $\varepsilon \in \mathbb{R}^n$ is the error vector. A key observation is that because the model has intercept, $1$, which is the first column of design matrix $X$, can be written as $$1 = Xe,$$ where $e$ is a column vector with all zeros but the first component one. Also note, in matrix notation, the sum of residuals is just $1^T(y - \hat{y})$, where $\hat{y} = Hy$ and $H$ is the projection matrix (i.e., "hat matrix") equals to $X(X^TX)^{-1}X^T$. Therefore, \begin{align} & 1^T(y - \hat{y}) = 1^T(I - H)y \\ = & e^TX^T(I - X(X^TX)^{-1}X^T)y \\ = & e^T(X^T - X^TX(X^TX)^{-1}X^T)y \\ = & e^T(X^T - X^T)y \\ = & 0. \end{align}
Why do residuals in linear regression always sum to zero when an intercept is included?
Write the linear model in matrical form as \begin{align} y = X\beta + \varepsilon, \end{align} where $y \in \mathbb{R}^n$ is the response vector, $X \in \mathbb{R}^{n \times p}$ is the design matrix
Why do residuals in linear regression always sum to zero when an intercept is included? Write the linear model in matrical form as \begin{align} y = X\beta + \varepsilon, \end{align} where $y \in \mathbb{R}^n$ is the response vector, $X \in \mathbb{R}^{n \times p}$ is the design matrix, $\varepsilon \in \mathbb{R}^n$ is the error vector. A key observation is that because the model has intercept, $1$, which is the first column of design matrix $X$, can be written as $$1 = Xe,$$ where $e$ is a column vector with all zeros but the first component one. Also note, in matrix notation, the sum of residuals is just $1^T(y - \hat{y})$, where $\hat{y} = Hy$ and $H$ is the projection matrix (i.e., "hat matrix") equals to $X(X^TX)^{-1}X^T$. Therefore, \begin{align} & 1^T(y - \hat{y}) = 1^T(I - H)y \\ = & e^TX^T(I - X(X^TX)^{-1}X^T)y \\ = & e^T(X^T - X^TX(X^TX)^{-1}X^T)y \\ = & e^T(X^T - X^T)y \\ = & 0. \end{align}
Why do residuals in linear regression always sum to zero when an intercept is included? Write the linear model in matrical form as \begin{align} y = X\beta + \varepsilon, \end{align} where $y \in \mathbb{R}^n$ is the response vector, $X \in \mathbb{R}^{n \times p}$ is the design matrix
10,176
Why do residuals in linear regression always sum to zero when an intercept is included?
A simple derivation using matrix algebra: $\sum e $ can be written as $1^Te$ Then $1^Te = 1^T(M_x y)$ where $M_x$ is the orthogonal matrix. Since $M_x$ is symmetric we can rearrange so that $(M_x1)^Ty$ which equals zero if $M_x$ and $1$ are orthogonal, which is the case if the matrix of the regressors $x$ contains the intercept (a vector of $1$, indeed).
Why do residuals in linear regression always sum to zero when an intercept is included?
A simple derivation using matrix algebra: $\sum e $ can be written as $1^Te$ Then $1^Te = 1^T(M_x y)$ where $M_x$ is the orthogonal matrix. Since $M_x$ is symmetric we can rearrange so that $(M_x1)^T
Why do residuals in linear regression always sum to zero when an intercept is included? A simple derivation using matrix algebra: $\sum e $ can be written as $1^Te$ Then $1^Te = 1^T(M_x y)$ where $M_x$ is the orthogonal matrix. Since $M_x$ is symmetric we can rearrange so that $(M_x1)^Ty$ which equals zero if $M_x$ and $1$ are orthogonal, which is the case if the matrix of the regressors $x$ contains the intercept (a vector of $1$, indeed).
Why do residuals in linear regression always sum to zero when an intercept is included? A simple derivation using matrix algebra: $\sum e $ can be written as $1^Te$ Then $1^Te = 1^T(M_x y)$ where $M_x$ is the orthogonal matrix. Since $M_x$ is symmetric we can rearrange so that $(M_x1)^T
10,177
Why do residuals in linear regression always sum to zero when an intercept is included?
$e_i = y_i - [1, X] [a, b] = y_i - Xb - a = v_i - a$ $\frac{d}{da} \sum e_i^2 \propto \sum e_i\cdot 1 = \sum v_i - a = 0$ so $\hat{a} = \frac{1}{n}\sum v_i$ $\sum e_i = \sum_i v_i - a = \sum_i v_i - \frac{n}{n}\sum_i v_i = 0$ ..
Why do residuals in linear regression always sum to zero when an intercept is included?
$e_i = y_i - [1, X] [a, b] = y_i - Xb - a = v_i - a$ $\frac{d}{da} \sum e_i^2 \propto \sum e_i\cdot 1 = \sum v_i - a = 0$ so $\hat{a} = \frac{1}{n}\sum v_i$ $\sum e_i = \sum_i v_i - a = \sum_i v_i - \
Why do residuals in linear regression always sum to zero when an intercept is included? $e_i = y_i - [1, X] [a, b] = y_i - Xb - a = v_i - a$ $\frac{d}{da} \sum e_i^2 \propto \sum e_i\cdot 1 = \sum v_i - a = 0$ so $\hat{a} = \frac{1}{n}\sum v_i$ $\sum e_i = \sum_i v_i - a = \sum_i v_i - \frac{n}{n}\sum_i v_i = 0$ ..
Why do residuals in linear regression always sum to zero when an intercept is included? $e_i = y_i - [1, X] [a, b] = y_i - Xb - a = v_i - a$ $\frac{d}{da} \sum e_i^2 \propto \sum e_i\cdot 1 = \sum v_i - a = 0$ so $\hat{a} = \frac{1}{n}\sum v_i$ $\sum e_i = \sum_i v_i - a = \sum_i v_i - \
10,178
Is a model fitted to data or is data fitted to a model?
Pretty much every source or person I've ever interacted with except the Wolfram source you linked refers to the process as fitting a model to data. This makes sense, since the model is the dynamic object and the data is static (a.k.a. fixed and constant). To put a point on it, I like Larry Wasserman's approach to this. In his telling, a statistical model is a collection of distributions. For example, the collection of all normal distributions: $$ \{ \text{Normal}(\mu, \sigma) : \mu, \sigma \in R, \sigma > 0 \} $$ or the set of all Poisson distributions: $$ \{ \text{Poisson}(\lambda) : \lambda \in R, \lambda > 0 \} $$ Fitting a distribution to data is any algorithm that combines a statistical model with a set of data (the data is fixed), and chooses exactly one of the distributions from the model as the one that "best" reflects the data. The model is the thing that changes (sort of): we are collapsing it from an entire collection of possibilities into a single best choice. The data is just the data; nothing happens to it at all.
Is a model fitted to data or is data fitted to a model?
Pretty much every source or person I've ever interacted with except the Wolfram source you linked refers to the process as fitting a model to data. This makes sense, since the model is the dynamic ob
Is a model fitted to data or is data fitted to a model? Pretty much every source or person I've ever interacted with except the Wolfram source you linked refers to the process as fitting a model to data. This makes sense, since the model is the dynamic object and the data is static (a.k.a. fixed and constant). To put a point on it, I like Larry Wasserman's approach to this. In his telling, a statistical model is a collection of distributions. For example, the collection of all normal distributions: $$ \{ \text{Normal}(\mu, \sigma) : \mu, \sigma \in R, \sigma > 0 \} $$ or the set of all Poisson distributions: $$ \{ \text{Poisson}(\lambda) : \lambda \in R, \lambda > 0 \} $$ Fitting a distribution to data is any algorithm that combines a statistical model with a set of data (the data is fixed), and chooses exactly one of the distributions from the model as the one that "best" reflects the data. The model is the thing that changes (sort of): we are collapsing it from an entire collection of possibilities into a single best choice. The data is just the data; nothing happens to it at all.
Is a model fitted to data or is data fitted to a model? Pretty much every source or person I've ever interacted with except the Wolfram source you linked refers to the process as fitting a model to data. This makes sense, since the model is the dynamic ob
10,179
Is a model fitted to data or is data fitted to a model?
In the field of Rasch modelling it is common to fit the data to the model. The model is assumed to be correct and it is the analyst's job to find data which conform to it. The Wikipedia article on Rasch contains more details about the how and the why. But I agree with others that in general in statistics we fit the model to the data because we can change the model but it is felt to be bad form to select or modify the data.
Is a model fitted to data or is data fitted to a model?
In the field of Rasch modelling it is common to fit the data to the model. The model is assumed to be correct and it is the analyst's job to find data which conform to it. The Wikipedia article on Ras
Is a model fitted to data or is data fitted to a model? In the field of Rasch modelling it is common to fit the data to the model. The model is assumed to be correct and it is the analyst's job to find data which conform to it. The Wikipedia article on Rasch contains more details about the how and the why. But I agree with others that in general in statistics we fit the model to the data because we can change the model but it is felt to be bad form to select or modify the data.
Is a model fitted to data or is data fitted to a model? In the field of Rasch modelling it is common to fit the data to the model. The model is assumed to be correct and it is the analyst's job to find data which conform to it. The Wikipedia article on Ras
10,180
Is a model fitted to data or is data fitted to a model?
Typically, the observed data are fixed while the model is mutable (e.g. because parameters are estimated), so it is the model that is made to fit the data, not the other way around. (Usually people mean this case when they say either expression.) When people say they fit data to a model I find myself trying to figure out what the heck did they do to the data?. [Now if you're transforming data, that would arguably be 'fitting data to a model', but people almost never say that for this case.]
Is a model fitted to data or is data fitted to a model?
Typically, the observed data are fixed while the model is mutable (e.g. because parameters are estimated), so it is the model that is made to fit the data, not the other way around. (Usually people me
Is a model fitted to data or is data fitted to a model? Typically, the observed data are fixed while the model is mutable (e.g. because parameters are estimated), so it is the model that is made to fit the data, not the other way around. (Usually people mean this case when they say either expression.) When people say they fit data to a model I find myself trying to figure out what the heck did they do to the data?. [Now if you're transforming data, that would arguably be 'fitting data to a model', but people almost never say that for this case.]
Is a model fitted to data or is data fitted to a model? Typically, the observed data are fixed while the model is mutable (e.g. because parameters are estimated), so it is the model that is made to fit the data, not the other way around. (Usually people me
10,181
Is a model fitted to data or is data fitted to a model?
Usually, we assume our data corresponds to the "real world" and making any modifications means we are moving away from modelling the "real world". For example, one needs to take care removing outliers since even if it makes computation nicer, outliers were still part of our data. When testing a model or estimating properties of an estimator using bootstrap or other resampling techniques, we may simulate new data using an estimated model and our original data. This makes the assumption that the model is correct, and we are not modifying our original data.
Is a model fitted to data or is data fitted to a model?
Usually, we assume our data corresponds to the "real world" and making any modifications means we are moving away from modelling the "real world". For example, one needs to take care removing outliers
Is a model fitted to data or is data fitted to a model? Usually, we assume our data corresponds to the "real world" and making any modifications means we are moving away from modelling the "real world". For example, one needs to take care removing outliers since even if it makes computation nicer, outliers were still part of our data. When testing a model or estimating properties of an estimator using bootstrap or other resampling techniques, we may simulate new data using an estimated model and our original data. This makes the assumption that the model is correct, and we are not modifying our original data.
Is a model fitted to data or is data fitted to a model? Usually, we assume our data corresponds to the "real world" and making any modifications means we are moving away from modelling the "real world". For example, one needs to take care removing outliers
10,182
Is a model fitted to data or is data fitted to a model?
I think 'fitting the model' sounds wrong to some because the model structure does not change as part of the fitting process. But the model parameters do, which is why it is correct. Fitting is still an awkward term and it vaguely sounds like some underhand manipulation is being done. I much prefer to just talk about parameter estimation.
Is a model fitted to data or is data fitted to a model?
I think 'fitting the model' sounds wrong to some because the model structure does not change as part of the fitting process. But the model parameters do, which is why it is correct. Fitting is still a
Is a model fitted to data or is data fitted to a model? I think 'fitting the model' sounds wrong to some because the model structure does not change as part of the fitting process. But the model parameters do, which is why it is correct. Fitting is still an awkward term and it vaguely sounds like some underhand manipulation is being done. I much prefer to just talk about parameter estimation.
Is a model fitted to data or is data fitted to a model? I think 'fitting the model' sounds wrong to some because the model structure does not change as part of the fitting process. But the model parameters do, which is why it is correct. Fitting is still a
10,183
Is a model fitted to data or is data fitted to a model?
This could also be seen from Bayesian perspective and goodness of fit. We might interpret "model fitted to data" as in finding out probability of parameters fits the given data well i.e, $p(\theta|X)$ a posterior and "data fitted to a model" as in finding out probability of observing the data given the model i.e., $p(X|\theta)$ likelihood.
Is a model fitted to data or is data fitted to a model?
This could also be seen from Bayesian perspective and goodness of fit. We might interpret "model fitted to data" as in finding out probability of parameters fits the given data well i.e, $p(\theta|X)$
Is a model fitted to data or is data fitted to a model? This could also be seen from Bayesian perspective and goodness of fit. We might interpret "model fitted to data" as in finding out probability of parameters fits the given data well i.e, $p(\theta|X)$ a posterior and "data fitted to a model" as in finding out probability of observing the data given the model i.e., $p(X|\theta)$ likelihood.
Is a model fitted to data or is data fitted to a model? This could also be seen from Bayesian perspective and goodness of fit. We might interpret "model fitted to data" as in finding out probability of parameters fits the given data well i.e, $p(\theta|X)$
10,184
Is a model fitted to data or is data fitted to a model?
Interesting topic here and I could not let it pass me by without saying a few words. Here is my take on this. From a scientific point of view, a model by definition is a conceptual representation (universally accepted as a reference) of an event or process. With that in mind, it is my understanding that any data out there is a dynamic entity, meaning it changes over time. Unlike statistical models that are static(reference) and were developed to describe certain phenomena. Having said that, the data at hand is also a representation of an event but that is yet to be validated due to its dynamic nature. The process by which the data is validated (compared with a model/reference already in existence) is what we call data modeling or model fitting of the data. In conclusion, we should rather be saying "FITTING the DATA to A MODEL."
Is a model fitted to data or is data fitted to a model?
Interesting topic here and I could not let it pass me by without saying a few words. Here is my take on this. From a scientific point of view, a model by definition is a conceptual representation (uni
Is a model fitted to data or is data fitted to a model? Interesting topic here and I could not let it pass me by without saying a few words. Here is my take on this. From a scientific point of view, a model by definition is a conceptual representation (universally accepted as a reference) of an event or process. With that in mind, it is my understanding that any data out there is a dynamic entity, meaning it changes over time. Unlike statistical models that are static(reference) and were developed to describe certain phenomena. Having said that, the data at hand is also a representation of an event but that is yet to be validated due to its dynamic nature. The process by which the data is validated (compared with a model/reference already in existence) is what we call data modeling or model fitting of the data. In conclusion, we should rather be saying "FITTING the DATA to A MODEL."
Is a model fitted to data or is data fitted to a model? Interesting topic here and I could not let it pass me by without saying a few words. Here is my take on this. From a scientific point of view, a model by definition is a conceptual representation (uni
10,185
Maximum Likelihood Estimation -- why it is used despite being biased in many cases
Unbiasedness isn't necessarily especially important on its own. Aside a very limited set of circumstances, most useful estimators are biased, however they're obtained. If two estimators have the same variance, one can readily mount an argument for preferring an unbiased one to a biased one, but that's an unusual situation to be in (that is, you may reasonably prefer unbiasedness, ceteris paribus -- but those pesky ceteris are almost never paribus). More typically, if you want unbiasedness you'll be adding some variance to get it, and then the question would be why would you do that? Bias is how far the expected value of my estimator will be too high on average (with negative bias indicating too low). When I'm considering a small sample estimator, I don't really care about that. I'm usually more interested in how far wrong my estimator will be in this instance - my typical distance from right... something like a root-mean-square error or a mean absolute error would make more sense. So if you like low variance and low bias, asking for say a minimum mean square error estimator would make sense; these are very rarely unbiased. Bias and unbiasedness is a useful notion to be aware of, but it's not an especially useful property to seek unless you're only comparing estimators with the same variance. ML estimators tend to be low-variance; they're usually not minimum MSE, but they often have lower MSE than than modifying them to be unbiased (when you can do it at all) would give you. As an example, consider estimating variance when sampling from a normal distribution $\hat{\sigma}^2_\text{MMSE} = \frac{S^2}{n+1}, \hat{\sigma}^2_\text{MLE} = \frac{S^2}{n}, \hat{\sigma}^2_\text{Unb} = \frac{S^2}{n-1}$ (indeed the MMSE for the variance always has a larger denominator than $n-1$).
Maximum Likelihood Estimation -- why it is used despite being biased in many cases
Unbiasedness isn't necessarily especially important on its own. Aside a very limited set of circumstances, most useful estimators are biased, however they're obtained. If two estimators have the same
Maximum Likelihood Estimation -- why it is used despite being biased in many cases Unbiasedness isn't necessarily especially important on its own. Aside a very limited set of circumstances, most useful estimators are biased, however they're obtained. If two estimators have the same variance, one can readily mount an argument for preferring an unbiased one to a biased one, but that's an unusual situation to be in (that is, you may reasonably prefer unbiasedness, ceteris paribus -- but those pesky ceteris are almost never paribus). More typically, if you want unbiasedness you'll be adding some variance to get it, and then the question would be why would you do that? Bias is how far the expected value of my estimator will be too high on average (with negative bias indicating too low). When I'm considering a small sample estimator, I don't really care about that. I'm usually more interested in how far wrong my estimator will be in this instance - my typical distance from right... something like a root-mean-square error or a mean absolute error would make more sense. So if you like low variance and low bias, asking for say a minimum mean square error estimator would make sense; these are very rarely unbiased. Bias and unbiasedness is a useful notion to be aware of, but it's not an especially useful property to seek unless you're only comparing estimators with the same variance. ML estimators tend to be low-variance; they're usually not minimum MSE, but they often have lower MSE than than modifying them to be unbiased (when you can do it at all) would give you. As an example, consider estimating variance when sampling from a normal distribution $\hat{\sigma}^2_\text{MMSE} = \frac{S^2}{n+1}, \hat{\sigma}^2_\text{MLE} = \frac{S^2}{n}, \hat{\sigma}^2_\text{Unb} = \frac{S^2}{n-1}$ (indeed the MMSE for the variance always has a larger denominator than $n-1$).
Maximum Likelihood Estimation -- why it is used despite being biased in many cases Unbiasedness isn't necessarily especially important on its own. Aside a very limited set of circumstances, most useful estimators are biased, however they're obtained. If two estimators have the same
10,186
Maximum Likelihood Estimation -- why it is used despite being biased in many cases
Maximum likelihood estimation (MLE) yields the most likely value of the model parameters, given the model and the data at hand -- which is a pretty attractive concept. Why would you choose parameter values that make the data observed less probable when you can choose the values that make the data observed the most probable across any set of values? Would you wish to sacrifice this feature for unbiasedness? I do not say the answer is always clear, but the motivation for MLE is pretty strong and intuitive. Also, MLE may be more widely applicable than method of moments, as far as I know. MLE seems more natural in cases of latent variables; for example, a moving average (MA) model or a generalized autoregressive conditional heteroskedasticity (GARCH) model can be directly estimated by MLE (by directly I mean it is enough to specify a likelihood function and submit it to an optimization routine) -- but not by method of moments (although indirect solutions utilizing the method of moments may exist).
Maximum Likelihood Estimation -- why it is used despite being biased in many cases
Maximum likelihood estimation (MLE) yields the most likely value of the model parameters, given the model and the data at hand -- which is a pretty attractive concept. Why would you choose parameter v
Maximum Likelihood Estimation -- why it is used despite being biased in many cases Maximum likelihood estimation (MLE) yields the most likely value of the model parameters, given the model and the data at hand -- which is a pretty attractive concept. Why would you choose parameter values that make the data observed less probable when you can choose the values that make the data observed the most probable across any set of values? Would you wish to sacrifice this feature for unbiasedness? I do not say the answer is always clear, but the motivation for MLE is pretty strong and intuitive. Also, MLE may be more widely applicable than method of moments, as far as I know. MLE seems more natural in cases of latent variables; for example, a moving average (MA) model or a generalized autoregressive conditional heteroskedasticity (GARCH) model can be directly estimated by MLE (by directly I mean it is enough to specify a likelihood function and submit it to an optimization routine) -- but not by method of moments (although indirect solutions utilizing the method of moments may exist).
Maximum Likelihood Estimation -- why it is used despite being biased in many cases Maximum likelihood estimation (MLE) yields the most likely value of the model parameters, given the model and the data at hand -- which is a pretty attractive concept. Why would you choose parameter v
10,187
Maximum Likelihood Estimation -- why it is used despite being biased in many cases
To answer your question of why the MLE is so popular, consider that although it can be biased, it is consistent under standard conditions. In addition, it is asymptotically efficient, so at least for large samples, the MLE is likely to do as well or better as any other estimator you may cook up. Finally, the MLE is found by a simple recipe; take the likelihood function and maximize it. In some cases, that recipe may be hard to follow, but for most problems, it is not. Plus, once you have this estimate, we can derive the asymptotic standard errors right away using Fisher's information. Without using the Fisher's information, it is often really hard to derive the error bounds. This is why MLE estimation is very often the go to estimator (unless you're a Bayesian); it's simple to implement and likely to be just as good if not better than anything else you need to do more work to cook up.
Maximum Likelihood Estimation -- why it is used despite being biased in many cases
To answer your question of why the MLE is so popular, consider that although it can be biased, it is consistent under standard conditions. In addition, it is asymptotically efficient, so at least for
Maximum Likelihood Estimation -- why it is used despite being biased in many cases To answer your question of why the MLE is so popular, consider that although it can be biased, it is consistent under standard conditions. In addition, it is asymptotically efficient, so at least for large samples, the MLE is likely to do as well or better as any other estimator you may cook up. Finally, the MLE is found by a simple recipe; take the likelihood function and maximize it. In some cases, that recipe may be hard to follow, but for most problems, it is not. Plus, once you have this estimate, we can derive the asymptotic standard errors right away using Fisher's information. Without using the Fisher's information, it is often really hard to derive the error bounds. This is why MLE estimation is very often the go to estimator (unless you're a Bayesian); it's simple to implement and likely to be just as good if not better than anything else you need to do more work to cook up.
Maximum Likelihood Estimation -- why it is used despite being biased in many cases To answer your question of why the MLE is so popular, consider that although it can be biased, it is consistent under standard conditions. In addition, it is asymptotically efficient, so at least for
10,188
Maximum Likelihood Estimation -- why it is used despite being biased in many cases
Actually, the scaling of the maximum likelihood estimates in order to obtain unbiased estimates is a standard procedure in many estimation problems. The reason for that is that the mle is a function of the sufficient statistics and so by the Rao-Blackwell theorem if you can find an unbiased estimator based on sufficient statistics, then you have a Minimum Variance Unbiased Estimator. I know that your question is more general than that but what I mean to emphasize is that key concepts are intimately related to the likelihood and estimates based on it. These estimates might not be unbiased in finite samples but they are asymptotically so and moreover they are asymptotically efficient, i.e. they attain the Cramer-Rao bound of variance for unbiased estimators, which might not always be the case for the MOM estimators.
Maximum Likelihood Estimation -- why it is used despite being biased in many cases
Actually, the scaling of the maximum likelihood estimates in order to obtain unbiased estimates is a standard procedure in many estimation problems. The reason for that is that the mle is a function o
Maximum Likelihood Estimation -- why it is used despite being biased in many cases Actually, the scaling of the maximum likelihood estimates in order to obtain unbiased estimates is a standard procedure in many estimation problems. The reason for that is that the mle is a function of the sufficient statistics and so by the Rao-Blackwell theorem if you can find an unbiased estimator based on sufficient statistics, then you have a Minimum Variance Unbiased Estimator. I know that your question is more general than that but what I mean to emphasize is that key concepts are intimately related to the likelihood and estimates based on it. These estimates might not be unbiased in finite samples but they are asymptotically so and moreover they are asymptotically efficient, i.e. they attain the Cramer-Rao bound of variance for unbiased estimators, which might not always be the case for the MOM estimators.
Maximum Likelihood Estimation -- why it is used despite being biased in many cases Actually, the scaling of the maximum likelihood estimates in order to obtain unbiased estimates is a standard procedure in many estimation problems. The reason for that is that the mle is a function o
10,189
Maximum Likelihood Estimation -- why it is used despite being biased in many cases
I'd add that sometimes (often) we use an MLE estimator because that's what we got, even if in an ideal world it wouldn't be what we want. (I often think of statistics as being like engineering, where we use what we got, not what we want.) In many cases it's easy to define and solve for the MLE, and then get a value using an iterative approach. Whereas for a given parameter in a given situation there may be a better estimator (for some value of "better"), but finding it may require being very clever; and when you're done being clever, you still only have the better estimator for that one particular problem.
Maximum Likelihood Estimation -- why it is used despite being biased in many cases
I'd add that sometimes (often) we use an MLE estimator because that's what we got, even if in an ideal world it wouldn't be what we want. (I often think of statistics as being like engineering, where
Maximum Likelihood Estimation -- why it is used despite being biased in many cases I'd add that sometimes (often) we use an MLE estimator because that's what we got, even if in an ideal world it wouldn't be what we want. (I often think of statistics as being like engineering, where we use what we got, not what we want.) In many cases it's easy to define and solve for the MLE, and then get a value using an iterative approach. Whereas for a given parameter in a given situation there may be a better estimator (for some value of "better"), but finding it may require being very clever; and when you're done being clever, you still only have the better estimator for that one particular problem.
Maximum Likelihood Estimation -- why it is used despite being biased in many cases I'd add that sometimes (often) we use an MLE estimator because that's what we got, even if in an ideal world it wouldn't be what we want. (I often think of statistics as being like engineering, where
10,190
Is a neural network essential for deep learning?
This is a good question. Is a neural network essential for deep learning? Yes, your teacher provided you with a correct definition of deep learning. You can still do machine learning (a broader category) without neural networks, but you need a neural network for it to qualify as 'deep learning'. Isn't it possible to do deep learning without a neural network by using PCA? (Example: PCANet) Based on the answer to the last part, no. It by definition wouldn't be 'deep' anymore. PCANet is actually a neural network, by the way. PCA, on the other hand, isn't 'deep'. If you stack several layers of PCA on top of each other, then there is an equivalent single-layer PCA you could have done, because composing those linear transforms will just give you another linear transform.
Is a neural network essential for deep learning?
This is a good question. Is a neural network essential for deep learning? Yes, your teacher provided you with a correct definition of deep learning. You can still do machine learning (a broader cate
Is a neural network essential for deep learning? This is a good question. Is a neural network essential for deep learning? Yes, your teacher provided you with a correct definition of deep learning. You can still do machine learning (a broader category) without neural networks, but you need a neural network for it to qualify as 'deep learning'. Isn't it possible to do deep learning without a neural network by using PCA? (Example: PCANet) Based on the answer to the last part, no. It by definition wouldn't be 'deep' anymore. PCANet is actually a neural network, by the way. PCA, on the other hand, isn't 'deep'. If you stack several layers of PCA on top of each other, then there is an equivalent single-layer PCA you could have done, because composing those linear transforms will just give you another linear transform.
Is a neural network essential for deep learning? This is a good question. Is a neural network essential for deep learning? Yes, your teacher provided you with a correct definition of deep learning. You can still do machine learning (a broader cate
10,191
Is a neural network essential for deep learning?
I'm going to disagree with the other answers. Fundamentally, I would say that deep learning is defined by a hierarchy of learned representations, and not by which particular model is used to define these representations. Indeed, this is how Goodfellow et al define it in the introductory section of their text Deep Learning (neural networks are not mentioned until later). In other words, the key with deep learning is that we are effectively learning a series of transformations of our data. Typically, these transformations define a neural network, with the activations of each layer serving as the transformed input data. However, this need not be the case. Deep Gaussian processes, for instance, have been gaining some attention in the research community. However, if I were teaching an introductory class, I would feel perfectly comfortable using your professor's definition: in practice, people overwhelmingly use neural networks for deep learning. You can do deep learning with basically any nonlinear model. PCA, being linear, does not qualify (though nonlinear analogues of PCA, such as kernel PCA, can qualify, see this article).
Is a neural network essential for deep learning?
I'm going to disagree with the other answers. Fundamentally, I would say that deep learning is defined by a hierarchy of learned representations, and not by which particular model is used to define th
Is a neural network essential for deep learning? I'm going to disagree with the other answers. Fundamentally, I would say that deep learning is defined by a hierarchy of learned representations, and not by which particular model is used to define these representations. Indeed, this is how Goodfellow et al define it in the introductory section of their text Deep Learning (neural networks are not mentioned until later). In other words, the key with deep learning is that we are effectively learning a series of transformations of our data. Typically, these transformations define a neural network, with the activations of each layer serving as the transformed input data. However, this need not be the case. Deep Gaussian processes, for instance, have been gaining some attention in the research community. However, if I were teaching an introductory class, I would feel perfectly comfortable using your professor's definition: in practice, people overwhelmingly use neural networks for deep learning. You can do deep learning with basically any nonlinear model. PCA, being linear, does not qualify (though nonlinear analogues of PCA, such as kernel PCA, can qualify, see this article).
Is a neural network essential for deep learning? I'm going to disagree with the other answers. Fundamentally, I would say that deep learning is defined by a hierarchy of learned representations, and not by which particular model is used to define th
10,192
Is a neural network essential for deep learning?
This answer depends on the definition of artificial neural network (ANN) you take to be true. See my question here: What *is* an Artificial Neural Network?. Therefore, no objective answer can be given since: To accommodate all definitions of ANNs, they are simply defined as arbitrary computational graphs, with tunable parameters (even if they are not tuned, random neural networks are still ANNs) Differentiability is not required (for example, genetic algorithms and other metaheuristics have been used to learn ANNs) I will however, propose a counterfactual approach here that, in my experience, at least makes some people to conclude that deep learning is not solely based on ANNs: Do you consider hierarchical hidden markov models (HHMM)/hierarchical Bayesian networks deep learning? Do you consider them to be neural networks? If you answered 'yes' and 'no', then the overall answer is definitely 'no', for you there is a deep learning model that is not a neural network. Other combinations of answer will lead to undefined overall answers.
Is a neural network essential for deep learning?
This answer depends on the definition of artificial neural network (ANN) you take to be true. See my question here: What *is* an Artificial Neural Network?. Therefore, no objective answer can be given
Is a neural network essential for deep learning? This answer depends on the definition of artificial neural network (ANN) you take to be true. See my question here: What *is* an Artificial Neural Network?. Therefore, no objective answer can be given since: To accommodate all definitions of ANNs, they are simply defined as arbitrary computational graphs, with tunable parameters (even if they are not tuned, random neural networks are still ANNs) Differentiability is not required (for example, genetic algorithms and other metaheuristics have been used to learn ANNs) I will however, propose a counterfactual approach here that, in my experience, at least makes some people to conclude that deep learning is not solely based on ANNs: Do you consider hierarchical hidden markov models (HHMM)/hierarchical Bayesian networks deep learning? Do you consider them to be neural networks? If you answered 'yes' and 'no', then the overall answer is definitely 'no', for you there is a deep learning model that is not a neural network. Other combinations of answer will lead to undefined overall answers.
Is a neural network essential for deep learning? This answer depends on the definition of artificial neural network (ANN) you take to be true. See my question here: What *is* an Artificial Neural Network?. Therefore, no objective answer can be given
10,193
Is a neural network essential for deep learning?
Deep learning is machine learning done using “deep” neural networks, i.e. such that have multiple (>2) layers. So you cannot do it without neural networks. For using other kinds of machine learning just use “machine learning” term, that includes neural networks as well.
Is a neural network essential for deep learning?
Deep learning is machine learning done using “deep” neural networks, i.e. such that have multiple (>2) layers. So you cannot do it without neural networks. For using other kinds of machine learning ju
Is a neural network essential for deep learning? Deep learning is machine learning done using “deep” neural networks, i.e. such that have multiple (>2) layers. So you cannot do it without neural networks. For using other kinds of machine learning just use “machine learning” term, that includes neural networks as well.
Is a neural network essential for deep learning? Deep learning is machine learning done using “deep” neural networks, i.e. such that have multiple (>2) layers. So you cannot do it without neural networks. For using other kinds of machine learning ju
10,194
Is a neural network essential for deep learning?
To answer from a different perspective, one philosophical point may help: the concept of learning in deep learning. In deep learning, there are multiple learning steps. In the first step, the data input is 'converted' (or learned) into a synthetic intermediate output (a bit higher abstraction, loosely speaking). Then in each step, the previous output is progressively learned (or 'transformed') into higher abstraction features, which may or may not be comprehensible to humans. Loosely speaking, the combination of these layers will approximate the 'model' for you, we don't need to specify any model or hypothesis beforehand. This is the same 'learning' concept as in cognitive science: find/construct higher abstraction from raw input. So, do we need NN for deep learning? Yes, in practice. With my limited knowledge, I would say this is the most convenient and efficient way to do it. In theory, it depends. If you build a 'learning' framework in which your model can create 'deep' abstraction (iteratively increasing) from raw input to achieve the task at hand, it may count as deep learning. In practice, it's a bit simplistic to view Deep Learning as just a vanilla multi-layer neural network. More than often, the workflow includes different NN-components and other transformation layers, each part can be wildly different from the next. I hope this answer provide some useful insights without the need to use technical terms.
Is a neural network essential for deep learning?
To answer from a different perspective, one philosophical point may help: the concept of learning in deep learning. In deep learning, there are multiple learning steps. In the first step, the data inp
Is a neural network essential for deep learning? To answer from a different perspective, one philosophical point may help: the concept of learning in deep learning. In deep learning, there are multiple learning steps. In the first step, the data input is 'converted' (or learned) into a synthetic intermediate output (a bit higher abstraction, loosely speaking). Then in each step, the previous output is progressively learned (or 'transformed') into higher abstraction features, which may or may not be comprehensible to humans. Loosely speaking, the combination of these layers will approximate the 'model' for you, we don't need to specify any model or hypothesis beforehand. This is the same 'learning' concept as in cognitive science: find/construct higher abstraction from raw input. So, do we need NN for deep learning? Yes, in practice. With my limited knowledge, I would say this is the most convenient and efficient way to do it. In theory, it depends. If you build a 'learning' framework in which your model can create 'deep' abstraction (iteratively increasing) from raw input to achieve the task at hand, it may count as deep learning. In practice, it's a bit simplistic to view Deep Learning as just a vanilla multi-layer neural network. More than often, the workflow includes different NN-components and other transformation layers, each part can be wildly different from the next. I hope this answer provide some useful insights without the need to use technical terms.
Is a neural network essential for deep learning? To answer from a different perspective, one philosophical point may help: the concept of learning in deep learning. In deep learning, there are multiple learning steps. In the first step, the data inp
10,195
Is a neural network essential for deep learning?
Deep learning is a subset of machine learning, which is a field dedicated to the study and development of machines that can learn, and the goal is of deep learning is to achieve eventually attain general artificial intelligence. Neural network is just one of the biological inspired model. In simple terms I would define deep learning a subset method in machine learning primarily using artificial neural networks which are inspired by human brain. See the following diagram. Classical machine learning uses classical statistics/mathematical modelling while deep learning use biological models aka neural networks.
Is a neural network essential for deep learning?
Deep learning is a subset of machine learning, which is a field dedicated to the study and development of machines that can learn, and the goal is of deep learning is to achieve eventually attain gen
Is a neural network essential for deep learning? Deep learning is a subset of machine learning, which is a field dedicated to the study and development of machines that can learn, and the goal is of deep learning is to achieve eventually attain general artificial intelligence. Neural network is just one of the biological inspired model. In simple terms I would define deep learning a subset method in machine learning primarily using artificial neural networks which are inspired by human brain. See the following diagram. Classical machine learning uses classical statistics/mathematical modelling while deep learning use biological models aka neural networks.
Is a neural network essential for deep learning? Deep learning is a subset of machine learning, which is a field dedicated to the study and development of machines that can learn, and the goal is of deep learning is to achieve eventually attain gen
10,196
How to easily determine the results distribution for multiple dice?
Exact solutions The number of combinations in $n$ throws is of course $6^n$. These calculations are most readily done using the probability generating function for one die, $$p(x) = x + x^2 + x^3 + x^4 + x^5 + x^6 = x \frac{1-x^6}{1-x}.$$ (Actually this is $6$ times the pgf--I'll take care of the factor of $6$ at the end.) The pgf for $n$ rolls is $p(x)^n$. We can calculate this fairly directly--it's not a closed form but it's a useful one--using the Binomial Theorem: $$p(x)^n = x^n (1 - x^6)^n (1 - x)^{-n}$$ $$= x^n \left( \sum_{k=0}^{n} {n \choose k} (-1)^k x^{6k} \right) \left( \sum_{j=0}^{\infty} {-n \choose j} (-1)^j x^j\right).$$ The number of ways to obtain a sum equal to $m$ on the dice is the coefficient of $x^m$ in this product, which we can isolate as $$\sum_{6k + j = m - n} {n \choose k}{-n \choose j}(-1)^{k+j}.$$ The sum is over all nonnegative $k$ and $j$ for which $6k + j = m - n$; it therefore is finite and has only about $(m-n)/6$ terms. For example, the number of ways to total $m = 14$ in $n = 3$ throws is a sum of just two terms, because $11 = 14-3$ can be written only as $6 \cdot 0 + 11$ and $6 \cdot 1 + 5$: $$-{3 \choose 0} {-3 \choose 11} + {3 \choose 1}{-3 \choose 5}$$ $$= 1 \frac{(-3)(-4)\cdots(-13)}{11!} + 3 \frac{(-3)(-4)\cdots(-7)}{5!}$$ $$= \frac{1}{2} 12 \cdot 13 - \frac{3}{2} 6 \cdot 7 = 15.$$ (You can also be clever and note that the answer will be the same for $m = 7$ by the symmetry 1 <--> 6, 2 <--> 5, and 3 <--> 4 and there's only one way to expand $7 - 3$ as $6 k + j$; namely, with $k = 0$ and $j = 4$, giving $$ {3 \choose 0}{-3 \choose 4} = 15 \text{.}$$ The probability therefore equals $15/6^3$ = $5/36$, about 14%. By the time this gets painful, the Central Limit Theorem provides good approximations (at least to the central terms where $m$ is between $\frac{7 n}{2} - 3 \sqrt{n}$ and $\frac{7 n}{2} + 3 \sqrt{n}$: on a relative basis, the approximations it affords for the tail values get worse and worse as $n$ grows large). I see that this formula is given in the Wikipedia article Srikant references but no justification is supplied nor are examples given. If perchance this approach looks too abstract, fire up your favorite computer algebra system and ask it to expand the $n^{\text{th}}$ power of $x + x^2 + \cdots + x^6$: you can read the whole set of values right off. E.g., a Mathematica one-liner is With[{n=3}, CoefficientList[Expand[(x + x^2 + x^3 + x^4 + x^5 + x^6)^n], x]]
How to easily determine the results distribution for multiple dice?
Exact solutions The number of combinations in $n$ throws is of course $6^n$. These calculations are most readily done using the probability generating function for one die, $$p(x) = x + x^2 + x^3 + x^
How to easily determine the results distribution for multiple dice? Exact solutions The number of combinations in $n$ throws is of course $6^n$. These calculations are most readily done using the probability generating function for one die, $$p(x) = x + x^2 + x^3 + x^4 + x^5 + x^6 = x \frac{1-x^6}{1-x}.$$ (Actually this is $6$ times the pgf--I'll take care of the factor of $6$ at the end.) The pgf for $n$ rolls is $p(x)^n$. We can calculate this fairly directly--it's not a closed form but it's a useful one--using the Binomial Theorem: $$p(x)^n = x^n (1 - x^6)^n (1 - x)^{-n}$$ $$= x^n \left( \sum_{k=0}^{n} {n \choose k} (-1)^k x^{6k} \right) \left( \sum_{j=0}^{\infty} {-n \choose j} (-1)^j x^j\right).$$ The number of ways to obtain a sum equal to $m$ on the dice is the coefficient of $x^m$ in this product, which we can isolate as $$\sum_{6k + j = m - n} {n \choose k}{-n \choose j}(-1)^{k+j}.$$ The sum is over all nonnegative $k$ and $j$ for which $6k + j = m - n$; it therefore is finite and has only about $(m-n)/6$ terms. For example, the number of ways to total $m = 14$ in $n = 3$ throws is a sum of just two terms, because $11 = 14-3$ can be written only as $6 \cdot 0 + 11$ and $6 \cdot 1 + 5$: $$-{3 \choose 0} {-3 \choose 11} + {3 \choose 1}{-3 \choose 5}$$ $$= 1 \frac{(-3)(-4)\cdots(-13)}{11!} + 3 \frac{(-3)(-4)\cdots(-7)}{5!}$$ $$= \frac{1}{2} 12 \cdot 13 - \frac{3}{2} 6 \cdot 7 = 15.$$ (You can also be clever and note that the answer will be the same for $m = 7$ by the symmetry 1 <--> 6, 2 <--> 5, and 3 <--> 4 and there's only one way to expand $7 - 3$ as $6 k + j$; namely, with $k = 0$ and $j = 4$, giving $$ {3 \choose 0}{-3 \choose 4} = 15 \text{.}$$ The probability therefore equals $15/6^3$ = $5/36$, about 14%. By the time this gets painful, the Central Limit Theorem provides good approximations (at least to the central terms where $m$ is between $\frac{7 n}{2} - 3 \sqrt{n}$ and $\frac{7 n}{2} + 3 \sqrt{n}$: on a relative basis, the approximations it affords for the tail values get worse and worse as $n$ grows large). I see that this formula is given in the Wikipedia article Srikant references but no justification is supplied nor are examples given. If perchance this approach looks too abstract, fire up your favorite computer algebra system and ask it to expand the $n^{\text{th}}$ power of $x + x^2 + \cdots + x^6$: you can read the whole set of values right off. E.g., a Mathematica one-liner is With[{n=3}, CoefficientList[Expand[(x + x^2 + x^3 + x^4 + x^5 + x^6)^n], x]]
How to easily determine the results distribution for multiple dice? Exact solutions The number of combinations in $n$ throws is of course $6^n$. These calculations are most readily done using the probability generating function for one die, $$p(x) = x + x^2 + x^3 + x^
10,197
How to easily determine the results distribution for multiple dice?
Yet another way to quickly compute the probability distribution of a dice roll would be to use a specialized calculator designed just for that purpose. Torben Mogensen, a CS professor at DIKU has an excellent dice roller called Troll. The Troll dice roller and probability calculator prints out the probability distribution (pmf, histogram, and optionally cdf or ccdf), mean, spread, and mean deviation for a variety of complicated dice roll mechanisms. Here are a few examples that show off Troll's dice roll language: Roll 3 6-sided dice and sum them: sum 3d6. Roll 4 6-sided dice, keep the highest 3 and sum them: sum largest 3 4d6. Roll an "exploding" 6-sided die (i.e., any time a "6" comes up, add 6 to your total and roll again): sum (accumulate y:=d6 while y=6). Troll's SML source code is available, if you want to see how its implemented. Professor Morgensen also has a 29-page paper, "Dice Rolling Mechanisms in RPGs," in which he discusses many of the dice rolling mechanisms implemented by Troll and some of the mathematics behind them. A similar piece of free, open-source software is Dicelab, which works on both Linux and Windows.
How to easily determine the results distribution for multiple dice?
Yet another way to quickly compute the probability distribution of a dice roll would be to use a specialized calculator designed just for that purpose. Torben Mogensen, a CS professor at DIKU has an e
How to easily determine the results distribution for multiple dice? Yet another way to quickly compute the probability distribution of a dice roll would be to use a specialized calculator designed just for that purpose. Torben Mogensen, a CS professor at DIKU has an excellent dice roller called Troll. The Troll dice roller and probability calculator prints out the probability distribution (pmf, histogram, and optionally cdf or ccdf), mean, spread, and mean deviation for a variety of complicated dice roll mechanisms. Here are a few examples that show off Troll's dice roll language: Roll 3 6-sided dice and sum them: sum 3d6. Roll 4 6-sided dice, keep the highest 3 and sum them: sum largest 3 4d6. Roll an "exploding" 6-sided die (i.e., any time a "6" comes up, add 6 to your total and roll again): sum (accumulate y:=d6 while y=6). Troll's SML source code is available, if you want to see how its implemented. Professor Morgensen also has a 29-page paper, "Dice Rolling Mechanisms in RPGs," in which he discusses many of the dice rolling mechanisms implemented by Troll and some of the mathematics behind them. A similar piece of free, open-source software is Dicelab, which works on both Linux and Windows.
How to easily determine the results distribution for multiple dice? Yet another way to quickly compute the probability distribution of a dice roll would be to use a specialized calculator designed just for that purpose. Torben Mogensen, a CS professor at DIKU has an e
10,198
How to easily determine the results distribution for multiple dice?
$\newcommand{red}{\color{red}}$ $\newcommand{blue}{\color{blue}}$ Let the first die be red and the second be black. Then there are 36 possible results: \begin{array}{c|c|c|c|c|c|c} &1&2&3&4&5&6\\\hline \red{1}&\red{1},1&\red{1},2&\red{1},3&\red{1},4&\red{1},5&\red{1},6\\ &\blue{^2}&\blue{^3}&\blue{^4}&\blue{^5}&\blue{^6}&\blue{^7}\\\hline \red{2}&\red{2},1&\red{2},2&\red{2},3&\red{2},4&\red{2},5&\red{2},6\\ &\blue{^3}&\blue{^4}&\blue{^5}&\blue{^6}&\blue{^7}&\blue{^8}\\\hline \red{3}&\red{3},1&\red{3},2&\red{3},3&\red{3},4&\red{3},5&\red{3},6\\ &\blue{^4}&\blue{^5}&\blue{^6}&\blue{^7}&\blue{^8}&\blue{^9}\\\hline \red{4}&\red{4},1&\red{4},2&\red{4},3&\red{4},4&\red{4},5&\red{4},6\\ &\blue{^5}&\blue{^6}&\blue{^7}&\blue{^8}&\blue{^9}&\blue{^{10}}\\\hline \red{5}&\red{5},1&\red{5},2&\red{5},3&\red{5},4&\red{5},5&\red{5},6\\ &\blue{^6}&\blue{^7}&\blue{^8}&\blue{^9}&\blue{^{10}}&\blue{^{11}}\\\hline \red{6}&\red{6},1&\red{6},2&\red{6},3&\red{6},4&\red{6},5&\red{6},6\\ &\blue{^7}&\blue{^8}&\blue{^9}&\blue{^{10}}&\blue{^{11}}&\blue{^{12}}\\\hline \end{array} Each of these 36 ($\red{\text{red}},\text{black}$) results are equally likely. When you sum the numbers on the faces (total in $\blue{\text{blue}}$), several of the (red,black) results end up with the same total -- you can see this with the table in your question. So for example there's only one way to get a total of $2$ (i.e. only the event ($\red{1},1$)), but there's two ways to get $3$ (i.e. the elementary events ($\red{2},1$) and ($\red{1},2$)). So a total of $3$ is twice as likely to come up as $2$. Similarly there's three ways of getting $4$, four ways of getting $5$ and so on. Now since you have 36 possible (red,black) results, the total number of ways of getting all the different totals is also 36, so you should divide by 36 at the end. Your total probability will be 1, as it should be.
How to easily determine the results distribution for multiple dice?
$\newcommand{red}{\color{red}}$ $\newcommand{blue}{\color{blue}}$ Let the first die be red and the second be black. Then there are 36 possible results: \begin{array}{c|c|c|c|c|c|c} &1&2&3&4&5&6\\\hlin
How to easily determine the results distribution for multiple dice? $\newcommand{red}{\color{red}}$ $\newcommand{blue}{\color{blue}}$ Let the first die be red and the second be black. Then there are 36 possible results: \begin{array}{c|c|c|c|c|c|c} &1&2&3&4&5&6\\\hline \red{1}&\red{1},1&\red{1},2&\red{1},3&\red{1},4&\red{1},5&\red{1},6\\ &\blue{^2}&\blue{^3}&\blue{^4}&\blue{^5}&\blue{^6}&\blue{^7}\\\hline \red{2}&\red{2},1&\red{2},2&\red{2},3&\red{2},4&\red{2},5&\red{2},6\\ &\blue{^3}&\blue{^4}&\blue{^5}&\blue{^6}&\blue{^7}&\blue{^8}\\\hline \red{3}&\red{3},1&\red{3},2&\red{3},3&\red{3},4&\red{3},5&\red{3},6\\ &\blue{^4}&\blue{^5}&\blue{^6}&\blue{^7}&\blue{^8}&\blue{^9}\\\hline \red{4}&\red{4},1&\red{4},2&\red{4},3&\red{4},4&\red{4},5&\red{4},6\\ &\blue{^5}&\blue{^6}&\blue{^7}&\blue{^8}&\blue{^9}&\blue{^{10}}\\\hline \red{5}&\red{5},1&\red{5},2&\red{5},3&\red{5},4&\red{5},5&\red{5},6\\ &\blue{^6}&\blue{^7}&\blue{^8}&\blue{^9}&\blue{^{10}}&\blue{^{11}}\\\hline \red{6}&\red{6},1&\red{6},2&\red{6},3&\red{6},4&\red{6},5&\red{6},6\\ &\blue{^7}&\blue{^8}&\blue{^9}&\blue{^{10}}&\blue{^{11}}&\blue{^{12}}\\\hline \end{array} Each of these 36 ($\red{\text{red}},\text{black}$) results are equally likely. When you sum the numbers on the faces (total in $\blue{\text{blue}}$), several of the (red,black) results end up with the same total -- you can see this with the table in your question. So for example there's only one way to get a total of $2$ (i.e. only the event ($\red{1},1$)), but there's two ways to get $3$ (i.e. the elementary events ($\red{2},1$) and ($\red{1},2$)). So a total of $3$ is twice as likely to come up as $2$. Similarly there's three ways of getting $4$, four ways of getting $5$ and so on. Now since you have 36 possible (red,black) results, the total number of ways of getting all the different totals is also 36, so you should divide by 36 at the end. Your total probability will be 1, as it should be.
How to easily determine the results distribution for multiple dice? $\newcommand{red}{\color{red}}$ $\newcommand{blue}{\color{blue}}$ Let the first die be red and the second be black. Then there are 36 possible results: \begin{array}{c|c|c|c|c|c|c} &1&2&3&4&5&6\\\hlin
10,199
How to easily determine the results distribution for multiple dice?
There's a very neat way of computing the combinations or probabilities in a spreadsheet (such as excel) that computes the convolutions directly. I'll do it in terms of probabilities and illustrate it for six sided dice but you can do it for dice with any number of sides (including adding different ones). (btw it's also easy in something like R or matlab that will do convolutions) Start with a clean sheet, in a few columns, and move down a bunch of rows from the top (more than 6). put the value 1 in a cell. That's the probabilities associated with 0 dice. put a 0 to its left; that's the value column - continue down from there with 1,2,3 down as far as you need. move one column to the right and down a row from the '1'. enter the formula "=sum(" then left-arrow up-arrow (to highlight the cell with 1 in it), hit ":" (to start entering a range) and then up-arrow 5 times, followed by ")/6" and press Enter - so you end up with a formula like =sum(c4:c9)/6 (where here C9 is the cell with the 1 in it). Then copy the formula and paste it to the 5 cells below it. They should each contain 0.16667 (ish). Don't type anything into the empty cells these formulas refer to! move down 1 and to the right 1 from the top of that column of values and paste ... ... a total of another 11 values. These will be the probabilities for two dice. It doesn't matter if you paste a few too many, you'll just get zeroes. repeat step 3 for the next column for three dice, and again for four, five, etc dice. We see here that the probability of rolling $12$ on 4d6 is 0.096451 (if you multiply by $4^6$ you'll be able to write it as an exact fraction). If you're adept with Excel - things like copying a formula from a cell and pasting into many cells in a column, you can generate all tables up to say 10d6 in about a minute or so (possibly faster if you've done it a few times). If you want combination counts instead of probabilities, don't divide by 6. If you want dice with different numbers of faces, you can sum $k$ (rather than 6) cells and then divide by $k$. You can mix dice across columns (e.g. do a column for d6 and one for d8 to get the probability function for d6+d8):
How to easily determine the results distribution for multiple dice?
There's a very neat way of computing the combinations or probabilities in a spreadsheet (such as excel) that computes the convolutions directly. I'll do it in terms of probabilities and illustrate it
How to easily determine the results distribution for multiple dice? There's a very neat way of computing the combinations or probabilities in a spreadsheet (such as excel) that computes the convolutions directly. I'll do it in terms of probabilities and illustrate it for six sided dice but you can do it for dice with any number of sides (including adding different ones). (btw it's also easy in something like R or matlab that will do convolutions) Start with a clean sheet, in a few columns, and move down a bunch of rows from the top (more than 6). put the value 1 in a cell. That's the probabilities associated with 0 dice. put a 0 to its left; that's the value column - continue down from there with 1,2,3 down as far as you need. move one column to the right and down a row from the '1'. enter the formula "=sum(" then left-arrow up-arrow (to highlight the cell with 1 in it), hit ":" (to start entering a range) and then up-arrow 5 times, followed by ")/6" and press Enter - so you end up with a formula like =sum(c4:c9)/6 (where here C9 is the cell with the 1 in it). Then copy the formula and paste it to the 5 cells below it. They should each contain 0.16667 (ish). Don't type anything into the empty cells these formulas refer to! move down 1 and to the right 1 from the top of that column of values and paste ... ... a total of another 11 values. These will be the probabilities for two dice. It doesn't matter if you paste a few too many, you'll just get zeroes. repeat step 3 for the next column for three dice, and again for four, five, etc dice. We see here that the probability of rolling $12$ on 4d6 is 0.096451 (if you multiply by $4^6$ you'll be able to write it as an exact fraction). If you're adept with Excel - things like copying a formula from a cell and pasting into many cells in a column, you can generate all tables up to say 10d6 in about a minute or so (possibly faster if you've done it a few times). If you want combination counts instead of probabilities, don't divide by 6. If you want dice with different numbers of faces, you can sum $k$ (rather than 6) cells and then divide by $k$. You can mix dice across columns (e.g. do a column for d6 and one for d8 to get the probability function for d6+d8):
How to easily determine the results distribution for multiple dice? There's a very neat way of computing the combinations or probabilities in a spreadsheet (such as excel) that computes the convolutions directly. I'll do it in terms of probabilities and illustrate it
10,200
How to easily determine the results distribution for multiple dice?
This is actually a suprisingly complicated question. Luckily for you, there exist an exact solution which is very well explained here: http://mathworld.wolfram.com/Dice.html The probability you are looking for is given by equation (10): "The probability of obtaining p points (a roll of p) on n s-sided dice". In your case: p = the observed score (sum of all dice), n = the number of dice, s = 6 (6-sided dice). This gives you the following probability mass function: $$ P(X_n = p) = \frac{1}{s^n} \sum_{k=0}^{\lfloor(p-n)/6\rfloor} (-1)^k {n \choose k} {p-6k-1 \choose n-1} $$
How to easily determine the results distribution for multiple dice?
This is actually a suprisingly complicated question. Luckily for you, there exist an exact solution which is very well explained here: http://mathworld.wolfram.com/Dice.html The probability you are lo
How to easily determine the results distribution for multiple dice? This is actually a suprisingly complicated question. Luckily for you, there exist an exact solution which is very well explained here: http://mathworld.wolfram.com/Dice.html The probability you are looking for is given by equation (10): "The probability of obtaining p points (a roll of p) on n s-sided dice". In your case: p = the observed score (sum of all dice), n = the number of dice, s = 6 (6-sided dice). This gives you the following probability mass function: $$ P(X_n = p) = \frac{1}{s^n} \sum_{k=0}^{\lfloor(p-n)/6\rfloor} (-1)^k {n \choose k} {p-6k-1 \choose n-1} $$
How to easily determine the results distribution for multiple dice? This is actually a suprisingly complicated question. Luckily for you, there exist an exact solution which is very well explained here: http://mathworld.wolfram.com/Dice.html The probability you are lo