weightchange <- read.csv("weight_change_data.csv")
xbar.lowcarb <- mean(weightchange$weightchange[weightchange$diet=="Low Carb"]) s.lowcarb <- sd(weightchange$weightchange[weightchange$diet=="Low Carb"]) n.lowcarb <- length(weightchange$weightchange[weightchange$diet=="Low Carb"]) xbar.lowcarb s.lowcarb n.lowcarb
lowcarb.dist <- curve(1-pt((xbar.lowcarb - mu)/(s.lowcarb/sqrt(n.lowcarb)), df = (n.lowcarb-1)), from = -20, to = 0, xname = 'mu')
?t.test t.test(weightchange$weightchange[weightchange$diet=="Low Carb"], alternative = "greater", mu=xbar.lowcarb)
curve(1-pt((xbar.lowcarb - mu)/(s.lowcarb/sqrt(n.lowcarb)), df = (n.lowcarb-1)), from = -20, to = 0, xname = 'mu') low.carb.t.test <- t.test(weightchange$weightchange[weightchange$diet=="Low Carb"], alternative = "greater", mu=-12.5) abline(h=low.carb.t.test$p.value, v=-12.5)
curve(1-pt((xbar.lowcarb - mu)/(s.lowcarb/sqrt(n.lowcarb)), df = (n.lowcarb-1)), from = -20, to = 0, xname = 'mu') for (mu in seq(from=-20, to= 0, by = 1)) { low.carb.t.test <- t.test(weightchange$weightchange[weightchange$diet=="Low Carb"], alternative = "greater", mu=mu) abline(h=low.carb.t.test$p.value, v=mu) }
lowcarb.func <- function(mu) abs(2*(1-pt((xbar.lowcarb - mu)/(s.lowcarb/sqrt(n.lowcarb)), df = (n.lowcarb-1)))-1) curve(lowcarb.func, from = -20, to = 0, xname = 'mu')
?t.test low.carb.t.test <- t.test(weightchange$weightchange[weightchange$diet=="Low Carb"], conf.level = .80)
curve(lowcarb.func, from = -20, to = 0, xname = 'mu') for (conf.int in seq(from=0, to= 1, by = .2)) { low.carb.t.test <- t.test(weightchange$weightchange[weightchange$diet=="Low Carb"], conf.level = conf.int) lowcarb.func <- function(mu) abs(2*(1-pt((xbar.lowcarb - mu)/(s.lowcarb/sqrt(n.lowcarb)), df = (n.lowcarb-1)))-1) abline(h=conf.int, v=low.carb.t.test$conf.int) }
lowcarb.dens.func <- function(mu) (1/(s.lowcarb/sqrt(n.lowcarb)))*(dt((xbar.lowcarb-mu)/((s.lowcarb/sqrt(n.lowcarb))), df=(n.lowcarb-1))) curve(lowcarb.dens.func(mu), from = -20, to = 0, xname = "mu")
?integrate integrate(lowcarb.dens.func, lower = -Inf, upper = xbar.lowcarb)
curve(1-pt((xbar.lowcarb - mu)/(s.lowcarb/sqrt(n.lowcarb)), df = (n.lowcarb-1)), from = -20, to = 0, xname = 'mu') for (mu in seq(from=-20, to= 0, by = .5)) { lowcarb.dens <- integrate(lowcarb.dens.func, lower = -Inf, upper = mu)$value abline(h=lowcarb.dens, v=mu) }
xbar.lowfat <- mean(weightchange$weightchange[weightchange$diet=="Low Fat"]) s.lowfat <- sd(weightchange$weightchange[weightchange$diet=="Low Fat"]) n.lowfat <- length(weightchange$weightchange[weightchange$diet=="Low Fat"]) xbar.lowfat s.lowfat n.lowfat
curve(1-pt((xbar.lowfat - mu)/(s.lowfat/sqrt(n.lowfat)), df = (n.lowfat-1)), from = -20, to = 0, xname = 'mu')
curve(1-pt((xbar.lowfat - mu)/(s.lowfat/sqrt(n.lowfat)), df = (n.lowfat-1)), from = -20, to = 0, xname = 'mu') for (mu in seq(from=-20, to= 0, by = 1)) { low.fat.t.test <- t.test(weightchange$weightchange[weightchange$diet=="Low Fat"], alternative = "greater", mu=mu) abline(h=low.fat.t.test$p.value, v=mu) }
lowfat.func <- function(mu) abs(2*(1-pt((xbar.lowfat - mu)/(s.lowfat/sqrt(n.lowfat)), df = (n.lowfat-1)))-1) curve(lowfat.func, from = -20, to = 0, xname = 'mu')
low.fat.t.test <- t.test(weightchange$weightchange[weightchange$diet=="Low Fat"], conf.level = .80)
curve(lowfat.func, from = -20, to = 0, xname = 'mu') for (conf.int in seq(from=0, to= 1, by = .2)) { low.fat.t.test <- t.test(weightchange$weightchange[weightchange$diet=="Low Fat"], conf.level = conf.int) lowcarb.func <- function(mu) abs(2*(1-pt((xbar.lowcarb - mu)/(s.lowcarb/sqrt(n.lowcarb)), df = (n.lowcarb-1)))-1) abline(h=conf.int, v=low.fat.t.test$conf.int) }
lowfat.dens.func <- function(mu) (1/(s.lowfat/sqrt(n.lowfat)))*(dt((xbar.lowfat-mu)/((s.lowfat/sqrt(n.lowfat))), df=(n.lowfat-1))) curve(lowfat.dens.func(mu), from = -20, to = 0, xname = "mu")
integrate(lowfat.dens.func, lower = -Inf, upper = xbar.lowfat)
curve(1-pt((xbar.lowfat - mu)/(s.lowfat/sqrt(n.lowfat)), df = (n.lowfat-1)), from = -20, to = 0, xname = 'mu') for (mu in seq(from=-20, to= 0, by = .5)) { lowfat.dens <- integrate(lowfat.dens.func, lower = -Inf, upper = mu)$value abline(h=lowfat.dens, v=mu) }
weightchange.welch <- t.test(weightchange$weightchange ~ weightchange$diet)
wc.df <- (((((s.lowcarb^2)/n.lowcarb)+(s.lowfat^2)/n.lowfat))^2)/((((s.lowcarb^2)/(n.lowcarb-1))^2)+(((s.lowfat^2)/(n.lowfat-1))^2)) wc.df # Weight Change Degrees of Freedom for Welch's t-test, should be 603.97 for this data
sample.diff <- xbar.lowcarb - xbar.lowfat
curve(1-pt((xbar.lowcarb - xbar.lowfat - delta)/(sqrt((((s.lowcarb)^2)/n.lowcarb)+((s.lowfat)^2)/n.lowfat)), df = 603.97), from = -10, to = 5, xname = 'delta')
curve(1-pt((xbar.lowcarb - xbar.lowfat - delta)/(sqrt((((s.lowcarb)^2)/n.lowcarb)+((s.lowfat)^2)/n.lowfat)), df = 603.97), from = -10, to = 5, xname = 'delta') abline(h=.5, v=sample.diff)
two.samp.func <- function(delta) abs(2*(1-pt((xbar.lowcarb - xbar.lowfat - delta)/(sqrt((((s.lowcarb)^2)/n.lowcarb)+((s.lowfat)^2)/n.lowfat)), df = 603.97))-1) curve(two.samp.func, from = -10, to = 5, xname = 'delta')
curve(two.samp.func, from = -10, to = 5, xname = 'delta') abline(h=.95, v = weightchange.welch$conf.int)
welch.dens.func <- function(delta) (1/sqrt((s.lowcarb^2/(n.lowcarb))+(s.lowfat^2/(n.lowfat)))*(dt((xbar.lowcarb- xbar.lowfat- delta)/sqrt((s.lowcarb^2/(n.lowcarb))+(s.lowfat^2/(n.lowfat))), df=(n.lowcarb-1)))) curve(lowcarb.dens.func(mu), from = -20, to = 0, xname = "mu")
integrate(welch.dens.func, lower = -Inf, upper = sample.diff)
curve(1-pt((xbar.lowcarb - xbar.lowfat - delta)/(sqrt((((s.lowcarb)^2)/n.lowcarb)+((s.lowfat)^2)/n.lowfat)), df = 603.97), from = -10, to = 5, xname = 'delta') for (delta in seq(from=-20, to= 0, by = .5)) { welch.dens <- integrate(welch.dens.func, lower = -Inf, upper = delta)$value abline(h=welch.dens, v=delta) }
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.