Welch/Satterthwaite in practice [General Statistics]
Dear all,
I am fiddling a bit with some spreadsheets and wish to construct a 90% CI from parallel designs and where I optionally wish to assume either equal or unequal variances. So Welch/Satterthwaite's equation for calculation of DF's come into play for the unequal situation. I further wish to get support for my calculation via R.
This causes a bit of grief.
Let's say the calculated df is 5.123. Yes, not an integer. Would you
1. Round up? (no, you would never do that because it is not conservative in nature!)
2. Round down?
3. Play the R game:
TINV in my spreadsheet (OpenOffice) will round down to 5. But, and this is the tricky part, if we in R use
You can take a look at the inner works of the
I am inclined to say it makes sense to round the df's down to nearest integer (option 2), in which case I do not see a way to pseudo-validate against R when the function
How would you think the df's should be treated?
Some random values I just made up:
Here's how the
Here's the reproduction using the function above:
Here's the alternative and conservative way with integer-rounded df:
I am fiddling a bit with some spreadsheets and wish to construct a 90% CI from parallel designs and where I optionally wish to assume either equal or unequal variances. So Welch/Satterthwaite's equation for calculation of DF's come into play for the unequal situation. I further wish to get support for my calculation via R.
This causes a bit of grief.
Let's say the calculated df is 5.123. Yes, not an integer. Would you
1. Round up? (no, you would never do that because it is not conservative in nature!)
2. Round down?
3. Play the R game:
TINV in my spreadsheet (OpenOffice) will round down to 5. But, and this is the tricky part, if we in R use
t.test
with var.equal=FALSE
to get our confidence interval then the confidence interval is calculated via the qt
function, and in R that function accepts non-integer df's:qt(1 - 0.05/2, 5.123)
[1] 2.552129
qt(1 - 0.05/2, 5)
[1] 2.570582
qt(1 - 0.05/2, 6)
[1] 2.446912
You can take a look at the inner works of the
t.test
function with:getAnywhere("t.test.default")
I am inclined to say it makes sense to round the df's down to nearest integer (option 2), in which case I do not see a way to pseudo-validate against R when the function
t.test
is used.How would you think the df's should be treated?
ElMaestros.Alternative=function(TEST,REF, Round.DF.Down=TRUE)
## constructs a 90% CI for test:ref using Welch-Satterthwaite's correction
## note: this function has not been partcularly smartified.
{
if (length(TEST)<4) stop("Too few observations for TEST.");
if (length(REF)<4) stop("Too few observations for REF.");
sx=sqrt(var(TEST)/length(TEST))
sy=sqrt(var(REF)/length(REF))
sd <- sqrt(sx^2 + sy^2)
df <- sd^4/(sx^4/(length(TEST) - 1) + sy^4/(length(REF) - 1))
if (Round.DF.Down==TRUE) df=floor(df)
alpha = 0.05
tstat=(mean(TEST)-mean(REF)) / sd
L=(tstat- qt(1 - alpha, df))*sd
U=(tstat+ qt(1 - alpha, df))*sd
cat("Lower 90% CI limit:", L, '\n');
cat("Upper 90% CI limit:", U, '\n');
if (Round.DF.Down==TRUE) cat ("Rounded DF =", df,"\n")
else cat ("Unrounded DF =", df, "\n")
}
Some random values I just made up:
TEST=c(30.5, 36.8, 39.2, 35.9)
REF=c(33.1, 37.1, 34.9, 35.0, 36.7)
Here's how the
t.test
function will do it:t.test(x=log(TEST), y=log(REF), var.equal=FALSE, conf.level=0.9)
Here's the reproduction using the function above:
ElMaestros.Alternative(log(TEST), log(REF), Round.DF.Down=FALSE)
Here's the alternative and conservative way with integer-rounded df:
ElMaestros.Alternative(log(TEST), log(REF), Round.DF.Down=TRUE)
—
Pass or fail!
ElMaestro
Pass or fail!
ElMaestro
Complete thread:
- Welch/Satterthwaite in practiceElMaestro 2011-09-21 17:04 [General Statistics]
- Not to round is the question d_labes 2011-09-22 09:11
- my problem ElMaestro 2011-09-22 12:34
- Ways out d_labes 2011-09-27 11:54
- my problem ElMaestro 2011-09-22 12:34
- Welch/Satterthwaite in practice yicaoting 2011-09-29 16:29
- Welch/Satterthwaite in practice ElMaestro 2011-09-29 17:39
- Spreadshit addiction Helmut 2011-09-30 16:52
- what a divine post! ElMaestro 2011-09-30 18:54
- what a divine post! Helmut 2011-09-30 19:41
- what a divine post! ElMaestro 2011-10-01 13:03
- what a divine post! Helmut 2011-10-01 13:20
- what a divine post! ElMaestro 2011-10-01 13:03
- what a divine post! Helmut 2011-09-30 19:41
- Spreadshit addiction yicaoting 2011-10-01 05:36
- Spreadshit addiction ElMaestro 2011-10-01 11:13
- GNU addiction Helmut 2011-10-02 03:20
- Spreadshit addiction Helmut 2011-10-01 13:03
- Spreadshit addiction yicaoting 2011-10-01 16:39
- Spreadshit addiction yicaoting 2011-10-03 07:23
- Spreadshit addiction Helmut 2011-10-03 15:59
- Spreadshit addiction yicaoting 2011-10-03 17:35
- Spreadshit addiction Helmut 2011-10-03 17:41
- Spreadshit addiction yicaoting 2011-10-03 17:35
- Spreadshit addiction Helmut 2011-10-03 15:59
- Spreadshit addiction ElMaestro 2011-10-01 11:13
- what a divine post! ElMaestro 2011-09-30 18:54
- Not to round is the question d_labes 2011-09-22 09:11