3

I'm conducting a hypothesis test for the difference between two groups. The file dat1 contains all observations of measure for the first group; dat2 contains all observations of measure for the second group. Measures of both groups are normally distributed, so a parametric test is appropriate. The code for a student's t-test would look like this:

    ttest1 <- t.test(x = dat1$measure, y = dat2$measure, alternative 
                     = "two.sided", var.equal = TRUE)

But a Levene test indicates that the groups have differing variances, so the t-statistic needs to be adjusted. So the code looks like this:

    ttest2 <- t.test(x = dat1$measure, y = dat2$measure, alternative 
                     = "two.sided", var.equal = FALSE)

But I need to weight each observation. I can produce a weighted student's t-test using the wtd.t.test() function in the weights package:

    ttest3 <- wtd.t.test(x = dat1$measure, y = dat2$measure, 
                         weight = dat1$weight, weighty = 
         dat2$weight, alternative = "two.tailed")

But there is no var.equal argument that would allow me to use the Welch adjustment to correct for concerns about different variances. I have not been able to find another package that facilitates such a test.

Is there a package that allows for this? If not, I need to figure out how to write a function that has this feature.

JmQ
  • 135
  • 6
  • Please explain what you mean by 'weight each observation'. In the Welch version of the tests (default setting `var.eq=F`), it is not relevant whether $\sigma_1^2$ and $\sigma_2^2$ are the same. If you want to test for equality of variances anyway you can still use an F-test (normal data) or Levene's test. – BruceET Jan 28 '21 at 02:45
  • @BruceET - I mention in the post that I used a Levene test and determined the two groups have different variances. This violates the assumption of homogeneity in variance necessary for a student's t-test, and is why I plan to use the Welch test. Explaining what sample weights are may be out of scope, but it's a very standard procedure in survey research (thus the `wtd.t.test()` function in the popular `weights` package, which I use in my post). See documentation for `?weights::wtd.t.test()` or this link: https://www.aapor.org/Education-Resources/For-Researchers/Poll-Survey-FAQ/Weighting.aspx – JmQ Jan 28 '21 at 02:52
  • Where you able to find a solution for this? I am currently running through the exact same problem, but I have 5 groups to compare. I searched everywhere on the internet and nothing. – mimi Oct 08 '21 at 16:50

0 Answers0