# NOT RUN {
set.seed(1234)
n <- 1000
## Compute the statistic only for data drawn from same distribution
x <- rnorm(n)
y <- rnorm(n)
npunitest(x,y,bootstrap=FALSE)
Sys.sleep(5)
## Conduct the test for this data
npunitest(x,y,boot.num=99)
Sys.sleep(5)
## Conduct the test for data drawn from different distributions having
## the same mean and variance
x <- rchisq(n,df=5)
y <- rnorm(n,mean=5,sd=sqrt(10))
mean(x)
mean(y)
sd(x)
sd(y)
npunitest(x,y,boot.num=99)
Sys.sleep(5)
## Two sample t-test for equality of means
t.test(x,y)
## F test for equality of variances and asymptotic
## critical values
F <- var(x)/var(y)
qf(c(0.025,0.975),df1=n-1,df2=n-1)
## Plot the nonparametric density estimates on the same axes
fx <- density(x)
fy <- density(y)
xlim <- c(min(fx$x,fy$x),max(fx$x,fy$x))
ylim <- c(min(fx$y,fy$y),max(fx$y,fy$y))
plot(fx,xlim=xlim,ylim=ylim,xlab="Data",main="f(x), f(y)")
lines(fy$x,fy$y,col="red")
Sys.sleep(5)
## Test for equality of log(wage) distributions
data(wage1)
attach(wage1)
lwage.male <- lwage[female=="Male"]
lwage.female <- lwage[female=="Female"]
npunitest(lwage.male,lwage.female,boot.num=99)
Sys.sleep(5)
## Plot the nonparametric density estimates on the same axes
f.m <- density(lwage.male)
f.f <- density(lwage.female)
xlim <- c(min(f.m$x,f.f$x),max(f.m$x,f.f$x))
ylim <- c(min(f.m$y,f.f$y),max(f.m$y,f.f$y))
plot(f.m,xlim=xlim,ylim=ylim,
xlab="log(wage)",
main="Male/Female log(wage) Distributions")
lines(f.f$x,f.f$y,col="red",lty=2)
rug(lwage.male)
legend(-1,1.2,c("Male","Female"),lty=c(1,2),col=c("black","red"))
detach(wage1)
Sys.sleep(5)
## Conduct the test for data drawn from different discrete probability
## distributions
x <- factor(rbinom(n,2,.5))
y <- factor(rbinom(n,2,.1))
npunitest(x,y,boot.num=99)
# }
# NOT RUN {
# }
# NOT RUN {
<!-- % enddontrun -->
# }
Run the code above in your browser using DataLab