Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- n = 60 ; df = n - 1 ; d = .5 ; t = d*sqrt(n) ## some observed data
- curve( dt(x*sqrt(n), df, t)*sqrt(n), -.2, 1.2) ## The sampling dist. of "d"
- f <- function (ncp, alpha, q, df) { ## Method 1 as stated in the stats TEXTS
- abs(suppressWarnings(pt(q = t, df = df, ncp, lower.tail = FALSE)) - alpha)
- }
- CI1 = sapply(c(0.025, 0.975),
- function(x) optimize(f, interval = c(-37, 37), alpha = x, q = t, df = df, tol = 1e-10)[[1]]/sqrt(n))
- CI2 = qt( c(.025, .975), df, ncp = t) / sqrt(n) ## Method 2
- text(CI1, 0, round(CI1, 4), font = 2)
- text(CI2, 0, round(CI2, 4), font = 2, pos = 3, col = 2)
- integrate(function(x) dt(x*sqrt(n), df, t)*sqrt(n), -Inf, CI1[1])[[1]]
- integrate(function(x) dt(x*sqrt(n), df, t)*sqrt(n), -Inf, CI2[1])[[1]]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement