# Examples on Construction CI's. # Todo luego de signo de numero es un comentario # Alzheimer example. # n = 61 # The runif function generates n uniformly distributed random numbers # between min and max. The round function redondea. Note que el la # siguiente linea es como una composicion de funciones, recuerda MECU! n = round(runif(1,min=50,max=80)) Xbar = 48 sigma = 14 C = 0.95 pr = C + 0.025 # C + lower_tail_area z = qnorm(pr,mean=0,sd=1,lower.tail=TRUE) ME = z*sigma/sqrt(n) lb = Xbar - ME ub = Xbar + ME cat("For Alzheimer example:\n Critical z =",z) # to display on screen cat(". CI of level",C,"is [",lb,ub,"]\n") cat ("The sample size is",n,".\n\n") # Rents Example # X = c(650,600,505,450,550,515,495,650,395,620) # n = length(X) n = 10 # The runif function generates n uniformly distributed random numbers # between min and max. X = runif(n,min=395,max=650) Xbar = mean(X) s = sd(X) C = 0.95 pr = C + 0.025 t = qt(pr,df=n-1) SE = s/sqrt(n) ME = t*SE lb = Xbar - ME ub = Xbar + ME cat("For Rents example:\n Critical t =",t) cat(". CI of level",C,"is [",lb,ub,"]\n") cat("Data is:\n",X,"\n\n") # Example Periodicos n = 200 X = 35 C = 0.90 phat = X/n SE = sqrt((phat*(1-phat))/n) z = qnorm(C+0.05,mean=0,sd=1) ME = z*SE lb = phat - ME ub = phat + ME cat("For Periodicos example:\n Critical t =",t) cat(". CI of level",C,"is [",lb,ub,"]\n")