Welch/Satterthwaite in practice [General Sta­tis­tics]

posted by ElMaestro  – Denmark, 2011-09-21 19:04 (4974 d 20:10 ago) – Posting: # 7383
Views: 18,031

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 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

Complete thread:

UA Flag
Activity
 Admin contact
23,424 posts in 4,927 threads, 1,671 registered users;
86 visitors (0 registered, 86 guests [including 8 identified bots]).
Forum time: 15:14 CEST (Europe/Vienna)

My doctor gave me six months to live,
but when I couldn’t pay the bill
he gave me six months more.    Walter Matthau

The Bioequivalence and Bioavailability Forum is hosted by
BEBAC Ing. Helmut Schütz
HTML5