library(UsingR)
## Warning: package 'UsingR' was built under R version 3.1.2
## Loading required package: MASS
## Loading required package: HistData
## Warning: package 'HistData' was built under R version 3.1.2
## Loading required package: Hmisc
## Warning: package 'Hmisc' was built under R version 3.1.2
## Loading required package: grid
## Loading required package: lattice
## Loading required package: survival
## Loading required package: splines
## Loading required package: Formula
## Warning: package 'Formula' was built under R version 3.1.2
##
## Attaching package: 'Hmisc'
##
## The following objects are masked from 'package:base':
##
## format.pval, round.POSIXt, trunc.POSIXt, units
##
## Loading required package: quantreg
## Warning: package 'quantreg' was built under R version 3.1.2
## Loading required package: SparseM
## Warning: package 'SparseM' was built under R version 3.1.2
##
## Attaching package: 'SparseM'
##
## The following object is masked from 'package:base':
##
## backsolve
##
##
## Attaching package: 'quantreg'
##
## The following object is masked from 'package:Hmisc':
##
## latex
##
## The following object is masked from 'package:survival':
##
## untangle.specials
##
##
## Attaching package: 'UsingR'
##
## The following object is masked from 'package:survival':
##
## cancer
data(age.universe)
head(age.universe)
## lower upper year
## 1 7.5e-05 NA 1760
## 2 2.4e-01 NA 1831
## 3 1.0e+00 10 1852
## 4 2.0e-02 NA 1897
## 5 2.0e+00 NA 1929
## 6 1.0e+01 15 1970
## source
## 1 Buffon. time of cooling from molten state. Earth
## 2 Lyell. age of mollusks. Earth
## 3 Bok. galactic clusters
## 4 Thomson. Thermodynamics of earth. Min is between 20-400million
## 5 E. Hubble. Redshift
## 6 various
View(age.universe)
pop<- span=""> rep(0:1,c(10000-5600,5600))
phat<- span=""> mean(sample(pop,100))
phat->->
## [1] 0.57
phat<- span=""> mean(sample(pop,100))
phat->
## [1] 0.63
res=c()
for(i in 1:1000) res[i]=mean(sample(pop,100))
quantile(res,c(.1,.9))
## 10% 90%
## 0.50 0.62
quantile(res,c(.1,.95))
## 10% 95%
## 0.50 0.64
quantile (res, c (0.025,0.975))
## 2.5% 97.5%
## 0.47 0.66
## [1] 1.311434
SE<- span=""> s/sqrt(n)
c(xbar-tstar*SE,xbar+tstar*SE)->
## [1] 65.04226 66.95774
ozs<- span=""> c(1.95, 1.80, 2.10, 1.82, 1.75, 2.01, 1.83,1.90)
qqnorm(ozs)->
t.test(ozs,conf.level=.80)
##
## One Sample t-test
##
## data: ozs
## t = 45.253, df = 7, p-value = 6.724e-10
## alternative hypothesis: true mean is not equal to 0
## 80 percent confidence interval:
## 1.835749 1.954251
## sample estimates:
## mean of x
## 1.895
x = c(175, 185, 170, 184, 175)
t.test(x,conf.level=.9,alt='less')
##
## One Sample t-test
##
## data: x
## t = 61.5671, df = 4, p-value = 1
## alternative hypothesis: true mean is less than 0
## 90 percent confidence interval:
## -Inf 182.2278
## sample estimates:
## mean of x
## 177.8
lstar<- span=""> qchisq(alpha/2,df=n-1)->