Difference between revisions of "Regression"
m (spelling error) |
(Fixed some errors having to do with treatment of sample noise) |
||
Line 15: | Line 15: | ||
= Secondary Statistics = | = Secondary Statistics = | ||
− | |||
− | |||
The Regression function computes the coefficients for the best-fit curve, but it does not compute secondary statistics such as parameter co-variances, R-value correlation, or goodness-of-fit. | The Regression function computes the coefficients for the best-fit curve, but it does not compute secondary statistics such as parameter co-variances, R-value correlation, or goodness-of-fit. | ||
− | |||
− | |||
In what follows, we'll assume that Variable C is the computed regression coefficients, e.g. | In what follows, we'll assume that Variable C is the computed regression coefficients, e.g. | ||
Variable C := Regression(Y,B,I,K) | Variable C := Regression(Y,B,I,K) | ||
− | In a generalized linear regression, the goodness of fit is often characterized using a Chi-squared statistic, computed as: | + | For each data point, the predicted value is given by |
− | [[Sum]]( (Y-[[Sum]](C*B,K))^2, I ) | + | Sum( C*B, I ) |
+ | |||
+ | Let ''S'' be the sample noise in your data. If you know the measurement noise in advance, then ''S'' is given and may (optionally) be indexed by I if the measurement noise varied by data point. If you do not know s in advance, then define Variable S defined as | ||
+ | var y2 := Sum(C*B,I); | ||
+ | Sqrt( Sum( (Y-Y2)^2,I ) / (size(I)-size(K)) ) | ||
+ | |||
+ | This variable S serves as an estimte for the measurement noise level. | ||
+ | |||
+ | In a generalized linear regression, the goodness of fit, or merit, is often characterized using a Chi-squared statistic, computed as: | ||
+ | [[Sum]]( (Y-[[Sum]](C*B,K))^2 / S^2, I ) | ||
− | + | Denoting the above as chi2, The probability that the data fit as poor as this would occur by chance is given as: | |
[[GammaI]]( [[Size]](I)/2 - 1, chi2 / 2 ) | [[GammaI]]( [[Size]](I)/2 - 1, chi2 / 2 ) | ||
Line 35: | Line 40: | ||
The co-variances are then computed as: | The co-variances are then computed as: | ||
− | [[Invert]]( [[Sum]](B * B[K=K2], I ), K, K2 ) | + | [[Invert]]( [[Sum]](B * B[K=K2] / S^2, I ), K, K2 ) |
The diagonal elements of this matrix give the variance in each parameter. Since there is only a finite number of samples, the parameter estimate may be off a bit due to random chance, even if the linear model assumption is correct; this variance indicates how much error exists from random chance at the given data set size. | The diagonal elements of this matrix give the variance in each parameter. Since there is only a finite number of samples, the parameter estimate may be off a bit due to random chance, even if the linear model assumption is correct; this variance indicates how much error exists from random chance at the given data set size. |
Revision as of 18:05, 20 April 2007
Regression( Y,B,I,K )
Generalized Linear Regression.
(see user guide)
Details
(too detailed for user guide)
Underconstrained Problems
When you do a regression fit, the number of data points, size(I), should be greater than the number of basis terms, size(K). When the number of data points is less than the number of basis terms, the problem is under-constrained. Provided that there are no two data points having the same basis values but different Y values, the fit curve in an underconstrained problem will perfectly pass through all data points, however, the co-efficients in that case are not unique. In the under-constrained case, Analytica will issue a warning, since this most likely indicates that the I and K index parameters were inadvertently swapped. If you ignore the warning, embed the call within an IgnoreWarnings function call, or have the "Show Result Warnings" preference disabled, a set of coefficients that passes through the existing data points is arbitrarily chosen and returned. The algorithm used is computational inefficient in the under-constrained case where size(I) << size(K) -- i.e., the number of basis terms is much larger than the number of data points. If you know your problem is highly underconstrained, then you probably do not intend to use a regression.
Secondary Statistics
The Regression function computes the coefficients for the best-fit curve, but it does not compute secondary statistics such as parameter co-variances, R-value correlation, or goodness-of-fit.
In what follows, we'll assume that Variable C is the computed regression coefficients, e.g.
Variable C := Regression(Y,B,I,K)
For each data point, the predicted value is given by
Sum( C*B, I )
Let S be the sample noise in your data. If you know the measurement noise in advance, then S is given and may (optionally) be indexed by I if the measurement noise varied by data point. If you do not know s in advance, then define Variable S defined as
var y2 := Sum(C*B,I); Sqrt( Sum( (Y-Y2)^2,I ) / (size(I)-size(K)) )
This variable S serves as an estimte for the measurement noise level.
In a generalized linear regression, the goodness of fit, or merit, is often characterized using a Chi-squared statistic, computed as:
Sum( (Y-Sum(C*B,K))^2 / S^2, I )
Denoting the above as chi2, The probability that the data fit as poor as this would occur by chance is given as:
GammaI( Size(I)/2 - 1, chi2 / 2 )
Another set of secondary statistics are the covariances of the fitted parameters. The covariance is an estimate of the amount of uncertainty in the parameter estimate given the available data. As the number of data points increases (for a given basis), the variances and covariances tend to decrease. To compute the covariances, a copy of Index K is required (since the covariance matrix is square in K); hence, you need to create a new index node defined as:
Index K2 := CopyIndex(K)
The co-variances are then computed as:
Invert( Sum(B * B[K=K2] / S^2, I ), K, K2 )
The diagonal elements of this matrix give the variance in each parameter. Since there is only a finite number of samples, the parameter estimate may be off a bit due to random chance, even if the linear model assumption is correct; this variance indicates how much error exists from random chance at the given data set size.
Enable comment auto-refresher