-1

I have just started my basic statistic course using R and we're studying using R for paired t-tests. I have come across questions where we're given two sets of data and we're asked to find whether the difference in mean is equal to 0 or greater than 0 so on so forth. The function we use for two samples x and y with an unknown variance is similar to the one below;

t.test(x, y, var.equal=TRUE, alternative="greater")

My question is, how would we to do this if we wanted to test the difference in mean is more than or equal to a specified number against the alternative that its less than a specific number and not 0.

For example, say we're given two datas for before and after weights of 10 people. How do we test that the mean difference in weight is more than or equal to say 3kg against the alternative where the mean difference in weight is less than 3kg. Is there a way to do this? Would really appreciate any guidance on this matter.

Jonny Phelps
  • 2,687
  • 1
  • 11
  • 20

2 Answers2

0

It might be worthwhile posting on https://stats.stackexchange.com/ as well if you're in need of more theoretical proof. Is it ok to add/subtract the 3kg from either x or y and then use the t-test to check for similarity? I think this would tell you at least which outcome is more likely, if that's the end goal. It would be good to get feedback on this

# number of obs, and rnorm dist for simulating
N <- 10
mu <- 70
sd <- 10
set.seed(1)
x <- round(rnorm(N, mu, sd), 1)

# three outcomes
# (1) no change
y_same <- x + round(rnorm(N, 0, 5), 1)
# (2) average increase of 3
y_imp <- x + rnorm(N, 3, 5)
# (3) average decrease of 3
y_dec <- x + rnorm(N, -3, 5)

# say y_imp is true
y_act <- y_imp
# can we test whether we're closer to the output by altering
# the original data? or conversely, altering y_imp
t_inc <- t.test(x+3, y_act, var.equal=TRUE, alternative="two.sided")
t_dec <- t.test(x-3, y_act, var.equal=TRUE, alternative="two.sided")

t_inc$p.value
[1] 0.8279801
t_dec$p.value
[1] 0.0956033

# one with the highest p.value has the closest distribution, so
# +3 kg more likely than -3kg
Jonny Phelps
  • 2,687
  • 1
  • 11
  • 20
  • i understand what is being done here thank you for that, however the x and y data is given to us already, i'm not sure as to if we have to use that or not, but the x and y data has been provided as in we have the 10 different weights before and 10 different weights after provided. How am i to use that? – Therealone Jun 22 '21 at 10:45
  • I'd substitute it so `x=weights_before` and `y_act=weights_after` (or can just call it `y`) or whatever your variables are called in R. You can ignore all the parts prior to `t_inc <- t.test(x+3, y_act, var.equal=TRUE, alternative="two.sided")` as that's just me creating some data to show how it works – Jonny Phelps Jun 22 '21 at 11:00
0

You can set mu=3 to change the null hypothesis from 0 to 3 assuming your x variables are in the units you describe above.

t.test(x, y, mu=3, alternative="greater", paired=TRUE)

More (general) information on Stack Exchange [here].(https://stats.stackexchange.com/questions/206316/can-a-paired-or-two-group-t-test-test-if-the-difference-between-two-means-is-l/206317#206317)

L. South
  • 141
  • 8