Advertisement
Guest User

Untitled

a guest
Jul 22nd, 2017
44
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.73 KB | None | 0 0
  1. n = 60 ; df = n - 1 ; d = .5 ; t = d*sqrt(n) ## some observed data
  2.  
  3. curve( dt(x*sqrt(n), df, t)*sqrt(n), -.2, 1.2) ## The sampling dist. of "d"
  4.  
  5.  
  6. f <- function (ncp, alpha, q, df) { ## Method 1 as stated in the stats TEXTS
  7. abs(suppressWarnings(pt(q = t, df = df, ncp, lower.tail = FALSE)) - alpha)
  8. }
  9.  
  10. CI1 = sapply(c(0.025, 0.975),
  11. function(x) optimize(f, interval = c(-37, 37), alpha = x, q = t, df = df, tol = 1e-10)[[1]]/sqrt(n))
  12.  
  13.  
  14. CI2 = qt( c(.025, .975), df, ncp = t) / sqrt(n) ## Method 2
  15.  
  16. text(CI1, 0, round(CI1, 4), font = 2)
  17. text(CI2, 0, round(CI2, 4), font = 2, pos = 3, col = 2)
  18.  
  19. integrate(function(x) dt(x*sqrt(n), df, t)*sqrt(n), -Inf, CI1[1])[[1]]
  20. 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