## Chapter 5 ## November 17, 2007 ## Alan T. Arnholt # # Example 5.2 library(adapt) # Only for R # part a. fxy <- function(v){1} fxy adapt(ndim=2,lower=c(0,0),upper=c(.6,.8),functn=fxy)$value # part b. adapt(ndim=2,lower=c(0.1,0.25),upper=c(0.9,0.75),functn=fxy)$value # # Example 5.8 # part f. ... similar to Figure 5.2 function.draw <- function(f, low=-1, hi=1, n=30){ r <- seq(low, hi, length=n) z <- outer (r,r,f) persp(r,r,z,xlab="X",ylab="Y",zlab="Z",theta=300,phi=20,ticktype="detailed")} f3 <- function(x,y) {ifelse(x >= y, 8*x*y, 0)} function.draw(f3,0,1,25) # # Example 5.12 X1 <- c(58,72,72,86,86,100,100,114,114,128) Y1 <- c(80,80,90,90,100,100,110,110,120,120) covar <- function(x,y,f){sum((x-mean(x))*(y-mean(y))*f)} covar(X1,Y1,1/10) # Example 5.13 cor(X1,Y1) # # Bivariate Normal Distribution # Ideas for Figure 5.4 function1.draw <- function(f, low = -1, hi = 1, n = 50){ r <- seq(low, hi, length = n) z <- outer(r, r, f) persp(r, r, z, axes=FALSE, box=TRUE)} par(mfrow=c(1,3), pty="s") f1 <- function(x,y){ exp( (x^2-2*0.5*x*y+y^2) / (-2*(1-0.5^2)) )/ (2*pi*sqrt(1-0.5^2))} x <- seq(-3,3,length=100) y <- x function1.draw(f1,-3,3,20) contour(x,y,outer(x,y,f1),nlevels=10) image(x,y,outer(x,y,f1),zlim=range(outer(x,y,f1)),add = FALSE) par(mfrow=c(1,1)) # # Example 5.18 # part a. pnorm(1.8,2.4,0.6) # part b. pnorm(1.8,1.77,0.48) # part c. 1 - pnorm(3, 2.4, 0.6) # part d. 1 - pnorm(3, 1.77, 0.48) ################################################################################