plot.uncertain(mle)
if (option==0) print(mle)
else return(mle)
}
mle.parameter.binomial.n<- function(x,option=0){
p=0.4
a=fitit("binomialP",x,prob=p)
b=a$phat[1]
mle=un(kind="bunch", vals=b)
plot.uncertain(mle)
if (option==0) print(mle)
else return(mle)
}
#############################################
##  estimating parameters of x(exponential)##
#############################################
############### bayes #######################
bayes.parameter.exponential.lambda<- function(x,option=0){
a=bayes.exponential(x)
b=a[,1]
bayes=un(kind="bunch", vals=b)
plot.uncertain(bayes)
if (option==0) print(bayes)
else return(bayes)
}
bayes.parameter.exponential.mean<- function(x,option=0){
a=bayes.exponential(x)
b=1/a[,1]
bayes=un(kind="bunch", vals=b)
plot.uncertain(bayes)
if (option==0) print(bayes)
else return(bayes)
}
bayes.parameter.exponential.var<- function(x,option=0){
a=bayes.exponential(x)
b=(1/a[,1])^2
bayes=un(kind="bunch", vals=b)
plot.uncertain(bayes)
if (option==0) print(bayes)
else return(bayes)
}
###############  c_box ######################
c_box.parameter.exponential.lambda<-function(x,option=0){
a=Exp_ConfDistr(x)
c_box=un(kind="bunch", vals=a)
plot.uncertain(c_box)
if (option==0) print(c_box)
else return(c_box)
}
###############  momm #######################
momm.parameter.exponential.lambda<-function(x,option=0){
a=1/(mean(x))
momm=un(kind="bunch", vals=a)
plot.uncertain(momm)
if (option==0) print(momm)
else return(momm)
}
###############  mle  #######################
mle.parameter.exponential.lambda<-function(x,option=0){
a=fitit("exponential", x)
mle=un(kind="bunch", vals=1/a$phat[1])
plot.uncertain(mle)
if (option==0) print(mle)
else return(mle)
}
#############################################
##   estimating parameters of x(poisson)   ##
#############################################
############### bayes #######################
bayes.parameter.poisson.lambda<- function(x,option=0){
a=bayes.poisson(x)
b=a[,1]
bayes=un(kind="bunch", vals=b)
plot.uncertain(bayes)
if (option==0) print(bayes)
else return(bayes)
}
###############  c_box ######################
c_box.parameter.poisson.lambda<- function(x,option=0){
a=Poisson_ConfStrct(x)
c_box=un(kind="cbox", balch=a)
plot.uncertain(c_box)
if (option==0) print(c_box)
else return(c_box)
}
###############  momm #######################
momm.parameter.poisson.lambda<-function(x,option=0){
a=mean(x)
momm=un(kind="bunch", vals=a)
plot.uncertain(momm)
if (option==0) print(momm)
else return(momm)
}
###############  mle  #######################
mle.parameter.poisson.lambda<-function(x,option=0){
a=fitit("poisson", x)
b=a$phat[1]
mle=un(kind="bunch", vals=b)
plot.uncertain(mle)
if (option==0) print(mle)
else return(mle)
}
#############################################
##     estimating parameters of x(gamma)   ##
#############################################
############### bayes #######################
bayes.parameter.gamma.mean<-function(x,option=0){
jump=1
for (i in 1:10){
a=bayes.gamma(x,jump)
q=sum(a[,6][1:length(a[,6])-1]==a[,6][2:length(a[,6])])
if (    ( ((q)/length(a[,6]) < 0.4)  &  ((q)/length(a[,6]) > 0.2) )  == TRUE    ) jump=jump
if ( (q)/length(a[,6]) > 0.4 ) jump=jump/5
if ( (q)/length(a[,6]) < 0.2 ) jump=jump*5
}
b=a[,4]
bayes=un(kind="bunch", vals=b)
plot.uncertain(bayes)
if (option==0) print(bayes)
else return(bayes)
}
bayes.parameter.gamma.var<-function(x,option=0){
jump=1
for (i in 1:10){
a=bayes.gamma(x,jump)
q=sum(a[,6][1:length(a[,6])-1]==a[,6][2:length(a[,6])])
if (    ( ((q)/length(a[,6]) < 0.4)  &  ((q)/length(a[,6]) > 0.2) )  == TRUE    ) jump=jump
if ( (q)/length(a[,6]) > 0.4 ) jump=jump/5
if ( (q)/length(a[,6]) < 0.2 ) jump=jump*5
}
b=a[,5]
bayes=un(kind="bunch", vals=b)
plot.uncertain(bayes)
if (option==0) print(bayes)
else return(bayes)
}
###############  c_box ######################
###############  momm #######################
momm.parameter.gamma.mean<- function(x,option=0){
a=mean(x)
momm=un(kind="bunch", vals=a)
plot.uncertain(momm)
if (option==0) print(momm)
else return(momm)
}
momm.parameter.gamma.std<- function(x,option=0){
a=sd(x)
momm=un(kind="bunch", vals=a)
plot.uncertain(momm)
if (option==0) print(momm)
else return(momm)
}
###############  mle  ######################
mle.parameter.gamma.mean<- function(x,option=0){
a=fitit("gamma", x)
b=a$phat[,1]
mle=un(kind="bunch", vals=b)
plot.uncertain(mle)
if (option==0) print(mle)
else return(mle)
}
mle.parameter.gamma.std<- function(x,option=0){
a=fitit("gamma", x)
b=a$phat[,2]
mle=un(kind="bunch", vals=b)
plot.uncertain(mle)
if (option==0) print(mle)
else return(mle)
}
####################################################
## function list####################################
####################################################
ARRA.function.list<-function(){
return(list("bayes.nextvaluedistribution.normal(x)",
"c_box.nextvaluedistribution.normal(x)",
"momm.nextvaluedistribution.normal(x)",
"mle.nextvaluedistribution.normal(x)",
"bayes.nextvaluedistribution.lognormal(x)",
"c_box.nextvaluedistribution.lognormal(x)",
"momm.nextvaluedistribution.lognormal(x)",
"mle.nextvaluedistribution.lognormal(x)",
"bayes.nextvaluedistribution.bernoulli(x)",
"mle.nextvaluedistribution.bernoulli(x)",
"bayes.nextvaluedistribution.binomial(x,trials)",
"c_box.nextvaluedistribution.binomial(x,trials)",
"momm.nextvaluedistribution.binomial(x)",
"momm.nextvaluedistribution.binomial.known_n(x,n)",
"momm.nextvaluedistribution.binomial.known_p(x,p)",
"mle.nextvaluedistribution.binomial.known_n(x,n)",
"mle.nextvaluedistribution.binomial.known_p(x,p)",
"bayes.nextvaluedistribution.exponential(x)",
"c_box.nextvaluedistribution.exponential(x)",
"momm.nextvaluedistribution.exponential(x)",
"mle.nextvaluedistribution.exponential(x)",
"bayes.nextvaluedistribution.poisson(x)",
"c_box.nextvaluedistribution.poisson(x)",
"mom.nextvaluedistribution.poisson(x)",
"mle.nextvaluedistribution.poisson(x)",
"bayes.nextvaluedistribution.gamma(x,jump)",
"momm.nexvaluedistribution.gamma(x)",
"mle.nextvaluedistribution.gamma(x)",
"bayes.parameter.normal.mean(x)",
"bayes.parameter.normal.variance(x)",
"c_box.parameter.normal.mean(x)",
"c_box.parameter.normal.std(x)",
"momm.parameter.normal.mean(x)",
"momm.parameter.normal.std(x)",
"mle.parameter.normal.mean(x)",
"mle.parameter.normal.std(x)",
"bayes.parameter.lognormal.mean(x)",
"bayes.parameter.lognormal.variance(x)",
"c_box.parameter.lognormal.mean(x)",
"c_box.parameter.lognormal.std(x)",
"momm.parameter.lognormal.mean(x)",
"momm.parameter.lognormal.std(x)",
"mle.parameter.lognormal.mean(x)",
"mle.parameter.lognormal.std(x)",
"bayes.parameter.bernoulli.p(x)",
"mle.parameter.bernoulli.p(x)",
"bayes.parameter.binomial.p(x,size,new)",
"c_box.parameter.binomial.p(x)",
"momm.parameter.binomial.mean(x)",
"momm.parameter.binomial.std(x)",
"momm.parameter.binomial.p(x)",
"momm.parameter.binomial.n(x)",
"mle.parameter.binomial.p(x,n)",
"mle.parameter.binomial.n(x,p)",
"bayes.parameter.exponential.lambda(x)",
"bayes.parameter.exponential.mean(x)",
"bayes.parameter.exponential.var(x)",
"c_box.parameter.exponential.lambda(x)",
"momm.parameter.exponential.lambda(x)",
"mle.parameter.exponential.lambda(x)",
"bayes.parameter.poisson.lambda(x)",
"c_box.parameter.poisson.lambda(x)",
"momm.parameter.poisson.lambda(x)",
"mle.parameter.poisson.lambda(x)",
"bayes.parameter.gamma.mean(x,jump)",
"bayes.parameter.gamma.var(x,jump)",
"momm.parameter.gamma.mean(x)",
"momm.parameter.gamma.std(x)",
"mle.parameter.gamma.mean(x)",
"mle.parameter.gamma.std(x)"))
}
##########################################################################################
##########################################################################################
##########################################################################################
##########################################################################################
##########################################################################################
# Challenge problem data sets
# 1       x ~ Bernoulli(p)
x.bern <- c(0, 0, 0, 0, 0, 0)
x.Bern <- c(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0)
# 2       x ~ binomial(20,p)
x.binN <- c(4, 5, 2, 7, 6, 6, 5)
x.BinN <- c(4, 5, 2, 7, 6, 6, 5, 2, 2, 4, 3, 6, 4, 6, 4, 2, 4, 6, 3, 3, 3, 5, 5, 4, 7, 4, 5, 5, 4, 7, 4, 6, 8, 2, 5, 5, 5, 2, 4, 2, 4, 3, 6, 6, 3, 5, 4, 5)
# 3       x ~ binomial(n,0.4)
x.binp <- c(16, 11, 15, 8, 12, 13, 9, 12, 10, 9)
x.Binp <- c(16, 11, 15, 8, 12, 13, 9, 12, 10, 9, 8, 11, 11, 8, 14, 8, 9, 8, 12, 13, 14, 17, 10, 11, 7, 12, 13, 10, 14, 17, 16, 12, 12, 8, 13, 7, 8, 13, 12, 14, 9, 8, 11, 9, 9, 11, 12, 8, 13, 9, 10, 10, 9, 11, 9)
# 4       x ~ poisson(lambda)
x.pois <- c(0, 0, 0, 0, 0, 0, 0, 0, 1)
x.Pois <- c(0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0)
# 5       x ~ exponential(rate)
x.expo <- c(2.16, 0.447, 8.13, 0.006, 0.279)
x.Expo <- c(2.16, 0.447, 8.13, 0.006, 0.279, 6.371, 0.538, 0.805, 0.169, 1.165, 0.163, 3.933, 2.23, 1.191, 1.478, 6.728, 2.889, 1.264, 1.657, 0.892, 0.482, 5.79, 0.506, 1.079, 0.012, 3.533, 4.594, 1.969, 1.339, 4.967, 2.47, 2.412, 2.114, 0.441, 0.909)
# 6       x ~ binomial(N,p)
x.bin <- c(6, 7, 5, 7, 7, 5, 6, 5)
x.Bin <- c(6, 7, 5, 7, 7, 5, 6, 5, 7, 5, 7, 7, 8, 7, 8, 6, 8, 6, 7, 6, 6, 6, 4, 8, 8, 5, 4, 7, 6, 8, 5, 5, 8, 8, 8, 7, 9, 8, 8)
# 7       x ~ normal(mu, sigma)
x.norm <- c(24.544, 22.516, 21.081, 23.483, 22.342, 23.596, 22.449, 23.378)
x.Norm <- c(24.544, 22.516, 21.081, 23.483, 22.342, 23.596, 22.449, 23.378, 21.088, 22.021, 22.613, 19.792, 21.609, 23.337, 21.702, 20.07, 21.904, 21.794, 22.781, 21.22, 23.561, 24.694, 21.071, 24.69, 23.883, 22.283, 20.882, 23.513, 24.772, 22.543, 21.454, 23.535, 21.998, 22.294, 21.801, 22.407, 21.226, 21.99)
# 8       x ~ lognormal(mean, std)
x.logn <- c(11.08, 11.395, 7.992, 5.783, 11.469, 37.658, 15.579, 7.292, 7.022, 6.015, 5.55)
x.Logn <- c(11.08, 11.395, 7.992, 5.783, 11.469, 37.658, 15.579, 7.292, 7.022, 6.015, 5.55, 20.387, 8.708, 38.168, 9.357, 9.669, 9.846, 16.783, 19.259, 4.176, 4.096, 25.067, 10.053, 2.054, 14.015, 3.169, 9.452, 18.896, 2.655, 19.613, 12.783, 11.195, 7.208, 3.771, 82.279, 10.903, 18.067, 18.954, 3.478, 13.484, 25.211)
# 9       x ~ gamma(shape, scale)
x.gamma <- c(5.275, 3.295, 3.917, 2.628, 1.503, 0.429, 1.229, 2.898, 2.269, 3.588)
x.Gamma <- c(5.275, 3.295, 3.917, 2.628, 1.503, 0.429, 1.229, 2.898, 2.269, 3.588, 1.693, 4.888, 1.202, 3.07, 2.52, 7.564, 1.044, 2.13, 4.485, 1.301, 0.54, 3.42, 2.515, 1.453, 4.127, 1.911, 2.672, 0.884, 1.517, 2.095, 1.552, 5.622, 2.927, 2.752, 5.996, 2.247)
# 10       x ~ continuousdistribution
x.nonparam <- c(140.2, 121.2, 154, 162.6, 136.9, 215.9, 117.5, 166.7, 165.2, 128.9, 150.6, 214.3)
x.Nonparam <- c(140.2, 121.2, 154, 162.6, 136.9, 215.9, 117.5, 166.7, 165.2, 128.9, 150.6, 214.3, 169.5, 178.1, 163.3, 131.7, 464.4, 133.3, 169.6, 144.3, 152.4, 119.2, 181.9, 161.6, 181.9, 92.6, 191.3, 117.6, 139.9, 181.1, 163.5, 149.5, 104.5, 230.7, 167.2, 125.1, 175, 219.8, 196.3, 168.4, 158, 177.6, 238, 130.8, 187.2, 151.8, 247.1, 192.6, 87.4, 164, 144.7, 187.8, 182, 290.9, 146, 202.9, 154.8, 140.6, 123.5, 202.6, 162.3, 177.4, 239.7, 144.9, 172.9, 189.7)
# 11       x ~ distribution with known mean and standard deviation, and maybe range
x.meanstd <- list(mean=154.8, std=7.3)
x.Meanstd <- list(min=150, max=200, mean=154.8, std=7.3)
# 12       x ~ unimodal distribution with constrained range and mode
x.uniminmaxmode <- list(min=0, max=1, mode=c(0, 0.35))        # the mode is given as an interval
x.Uniminmaxmode <- list(min=0, max=1, mode=c(0.25, 0.35))        # the mode is given as an interval
# 13       x ~ unimodal distribution with several constrained parameters
x.parameters <- list(min=0, max=1, mode=0.1, mean=c(0.2,0.4))        # the mean is given as an interval
x.Parameters <- list(min=0, max=1, mode=0.1, mean=0.4, std=0.3)
##########################################################################################
##########################################################################################
##########################################################################################
##########################################################################################
##########################################################################################
# Excecution and HTML generation
errors = NULL
doit = function(f,a,app='',tit='') {
annot = paste(f,'(',a,',option=1',')',sep='')
#cat(annot,'\n')
answer = try(do.call(f, list(get(a),',option=1')))
if (class(answer) == "try-error") { errors <<- c(errors,f) } else {
filename = paste(annot, app, '.png',sep='')
png(filename)
plot.uncertain(answer)
title(tit)
mtext(annot, 1, adj=0, line=4)
dev.off()
cat(paste('<p><a href="', folder, filename, '" imageanchor="1"><img src="', folder, filename, '" border="0" height="240" width="320"></a></p>', sep=''),'\n')
}
}
for (how in hows) {
cat('\n\n\n\n\n', '<!--', how, '-->\n')
for (i in 1:length(datas)) {
cat('<p style="color:rgb(180,95,6)">Answer for challenge problem ',i,'a\n',sep='')
d = datas[[i]]
f = paste(how, '.nextvaluedistribution.', maps[[i]], sep='')
a = paste('x.', d, sep='')
doit(f,a,'','Next value')
parm = parms[[i]]
for (p in parm) {
f = paste(how, '.parameter.', maps[[i]], '.', p, sep='')
doit(f,a,'',p)
}
cat('<p style="color:rgb(180,95,6)">Answer for challenge problem ',i,'b\n',sep='')
d = datas[[i]]
d = paste(toupper(substr(d,1,1)), substr(d,2,255), sep='')
f = paste(how, '.nextvaluedistribution.', maps[[i]], sep='')
a = paste('x.', d, sep='')
doit(f,a,'2','Next value')
parm = parms[[i]]
for (p in parm) {
f = paste(how, '.parameter.', maps[[i]], '.', p, sep='')
doit(f,a,'2',p)
}
}
}
cat('There were',length(errors),'errors\n')
errors
x.bern <- c(0, 0, 0, 0, 0, 0)
x.Bern <- c(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0,
0, 0, 0, 0, 1, 0)
n = length(x.bern)
s = sum(x.bern)
N = n
if(s==0){
c_1=0
c_2=0
}else{
c_1 = log(3) - lgamma(s) - lgamma(N-s) - (2/3)*lgamma(s) - (1/3)*lgamma(N-s) +
lgamma(s + (2/3)) + lgamma(N-s + (1/3))
c_2 = log(3) - lgamma(s) - lgamma(N-s) - (1/3)*lgamma(s) - (2/3)*lgamma(N-s) +
lgamma(s + (1/3)) + lgamma(N-s + (2/3))
c_1 = exp(c_1)
c_2 = exp(c_2)
}
dist_draw_1 = rbeta(10000, shape1 = s+1, shape2 = N-s)
dist_draw_2 = rbeta(10000, shape1 = s, shape2 = N-s+1)
dist_draw_3 = rbeta(floor(10000*c_1), shape1 = s+(2/3), shape2 = N-s+(1/3))
dist_draw_4 = rbeta(floor(10000*c_2), shape1 = s+(1/3), shape2 = N-s+(2/3))
full_dist = c(dist_draw_1,dist_draw_2,dist_draw_3,dist_draw_4)
plot(full_dist)
plot(density(full_dist))
max(full_dist)
histogram(full_dish)
histogram(full_dist)
hist(full_dist)
hist(full_dist, freq = F)
hist(full_dist, freq = FALSE)
?hist
hist(full_dist, prbability = T)
?hist
hist(full_dist, freq = FALSE, density = density(full_dist))
hist(full_dist, freq = FALSE, density = 1)
hist(full_dist, freq = FALSE, density = 2)
hist(full_dist, freq = FALSE, density = 5)
hist(full_dist, freq = FALSE, density = 10)
hist(full_dist, freq = FALSE)
density(full_dist)
plot(density(full_dist))
my_data = data.frame(p = full_dist)
densityplot(~ p, data = my_data)
library(lattice)
densityplot(~ p, data = my_data)
plot(density(my_data$p, bw = 0.05))
rug(jitter(my_data$p))
plot(density(my_data$p, bw = 0.05), main = "Fiducial Distribution of p")
rug(jitter(my_data$p))
plot(density(my_data$p, bw = 0.05), main = "Fiducial Distribution of p")
rug(jitter(my_data$p))
plot(density(my_data$p, bw = 0.05), main = "Fiducial Distribution of p")
plot(density(my_data$p, bw = 0.05), main = "Fiducial Distribution of p")
rug(jitter(my_data$p))
plot(full_dist)
plot(density(my_data$p, bw = 0.05), main = "Fiducial Distribution of p")
rug(jitter(my_data$p))
?plot
plot(density(my_data$p, bw = 0.05), main = title("Fiducial Distribution of p"))
?plot
plot(density(my_data$p), main = "Fiducial Distribution of p")
plot(density(my_data$p, bw = 0.05), main = "Fiducial Distribution of p")
plot(density(my_data$p, bw = 0.05), main = "Fiducial Distribution of p")
rug(jitter(my_data$p))
install.packages("diagram")
dat.1 = read.table("http://www.unc.edu/%7Ejameswd/data/dat1.txt")
dat.2 = read.table("http://www.unc.edu/%7Ejameswd/data/dat2.txt")
dat.3 = read.table("http://www.unc.edu/%7Ejameswd/data/dat3.txt")
dat.4 = read.table("http://www.unc.edu/%7Ejameswd/data/dat4.txt")
dat.5 = read.table("http://www.unc.edu/%7Ejameswd/data/dat5.txt")
dat.6 = read.table("http://www.unc.edu/%7Ejameswd/data/dat6.txt")
setwd("~/Documents/565ML/Computing_assignments/CA2")
mtcars
setwd("~/Documents/565ML/Computing_assignments/CA2")
?write.csv
write.csv(mtcars, file = "mtcars.csv")
my.dat = read.csv("mtcars.csv")
my.dat = read.table("mtcars.csv")
# plot the ecdf of dat.1 and color it green
plot(ecdf(my.dat$mpg), col = "green")
my.dat
read.table
?read.table
my.dat = read.table("mtcars.csv", sep = ",")
my.dat
my.dat = read.table("mtcars.csv", sep = ",", header = TRUE)
my.dat
my.dat = read.table("mtcars.csv", sep = ",", header = TRUE)
# Just a bit of cleaning up:
names(my.dat) = my.dat$X
my.dat = my.dat[,-1]
# Just a bit of cleaning up:
names(my.dat) = my.dat$X
my.dat = read.table("mtcars.csv", sep = ",", header = TRUE)
# Just a bit of cleaning up:
names(my.dat) = my.dat$X
# Just a bit of cleaning up:
row.names(my.dat) = my.dat$X
my.dat = read.table("mtcars.csv", sep = ",", header = TRUE)
# Just a bit of cleaning up:
row.names(my.dat) = my.dat$X
my.dat = my.dat[,-1]
my.dat
# plot the ecdf of dat.1 and color it green
plot(ecdf(my.dat$mpg), col = "green")
# plot the ecdf of dat.2, color it blue, and add this plot to the previous figure
plot(ecdf(my.dat$disp), col = "blue", add = TRUE)
# plot the ecdf of dat.1 and color it green
plot(ecdf(my.dat$mpg), col = "green")
# plot the ecdf of dat.2, color it blue, and add this plot to the previous figure
plot(ecdf(my.dat$disp), col = "blue", add = TRUE)
# plot the ecdf of dat.3, color it red, and add this plot to the previous figure
plot(ecdf(my.dat$wt), col = "red" , add = TRUE)
# add a legend to this plot (place it in the bottomright of the figure)
#the first argument gives location, the second gives the names
#the third gives the line type, and the fourth is the color of each label
legend("bottomright", c("dat.1","dat.2","dat.3"), lty = c(1,1,1), col = c("green","blue","red"))
my.dat$disp
my.dat
# plot the ecdf of dat.1 and color it green
plot(ecdf(my.dat$mpg), col = "green")
# plot the ecdf of dat.2, color it blue, and add this plot to the previous figure
plot(ecdf(my.dat$disp), col = "blue")
# plot the ecdf of dat.3, color it red, and add this plot to the previous figure
plot(ecdf(my.dat$wt), col = "red")
?mtcars
# plot the ecdf of car miles per gallon and color it green
plot(ecdf(my.dat$mpg), col = "green")
# plot the ecdf of car displacement, color it blue
plot(ecdf(my.dat$disp), col = "blue")
# plot the ecdf of car weight, color it red
plot(ecdf(my.dat$wt), col = "red")
# plot the ecdf of car miles per gallon and color it green
plot(ecdf(my.dat$mpg), col = "green")
# plot the ecdf of car displacement, color it blue
plot(ecdf(my.dat$disp), col = "blue")
# plot the ecdf of car weight, color it red
plot(ecdf(my.dat$wt), col = "red")
my.dat
mean(my.dat$drat)
mean(my.dat$wt)
# plot the ecdf of car weight, color it red
plot(ecdf(my.dat$wt), col = "red")
# plot the ecdf of car weight, color it red
plot(ecdf(my.dat$wt), col = "red")
plot(ecdf(my.dat$drat), col = "red")
mean(my.dat$hp)
mean(my.dat$disp)
plot(ecdf(my.dat$hp), col = "red")
plot(ecdf(my.dat$disp), col = "red")
?mtcars
my.dat
# calculate pairwise covariances
attach(my.dat)
cov.45 = cov(hp,drat)
cov.46 = cov(hp,wt)
cov.56 = cov(drat,wt)
# calculate pairwise correlations
cor.45 = cor(hp,drat)
cor.46 = cor(hp,wt)
cor.56 = cor(drat,wt)
detach(my.dat)
cov.46
attach(my.dat)
var(drat)
var(wt)
var(hp)
my.dat
summary(my.dat)
var(my.dat)
?table
load(url('https://stat.duke.edu/~mc301/data/movies.Rdata'))
head(movies)
