box-o-sand/elementary-statistics/.Rhistory

237 lines
6.3 KiB
R
Raw Normal View History

2011-07-11 08:54:45 +00:00
library(MASS)
painters
painters$School
school = painters$School
school.freq = table(school)
school.freq
cbind(school.freq)
head(painters)
composition = painters$Composition
composition.freq = table(composition)
cbind(composition.freq)
school
school.freq
school.freq[1]
help(max)
school[,][1]
school[1,][1]
school[1][1]
school[1]
school.freq[1,]
school.freq[1]
school.freq[1][1]
school.freq[1]
help(typeof)
typeof(school.freq[1])
max(school.freq)
max(school)
max(school.freq)
school.relfreq = school.freq / nrow(painters)
school.relfreq
settings = options(digits=1)
school.relfreq
options(settings)
cbind(school.relfreq)
composition.freq
composition.relfreq = composition.freq / nrow(composition)
composition.relfreq = composition.freq / nrow(painters)
composition.relfreq
cbind(composition.relfreq)
# bar graph exercise
library(MASS)
school = painters$School
school.freq = table(school)
barplot(school.freq)
colors = c("red", "yellow", "green", "violet", "orange", "blue", "pink", "cyan")
barplot(schools.freq, col=colors)
barplot(school.freq, col=colors)
composition = painters$Composition
composition.freq = table(composition)
count.fields(composition.freq)
ncol(composition.freq)
composition.freq
nrow(composition.freq)
nrow(school.freq)
colors
barplot(composition.freq, col=colors)
q()
2011-07-11 09:35:43 +00:00
library(MASS)
school = painters$school
school
school = painters$School
school
school.freq = table(school)
pip(school.freq)
pie(school.freq)
colors = c("red", "yellow", "green", "violet", "orange", "blue", "pink", "cyan")
pie(school.freq, col=colors)
composition = painters$Composition
composition.freq = table(composition)
pip(composition.freq, col=colors)
pie(composition.freq, col=colors)
library(MASS)
school = painters$School
c_school = school == "C"
c_painters = painters[c_school,]
mean(c_painters$Composition)
pie(tapply(painters$Composition, painters$School, mean)
pie(tapply(painters$Composition, painters$School, mean))
barchart(tapply(painters$Composition, painters$School, mean))
barplot(tapply(painters$Composition, painters$School, mean))
q()
head(faithful)
duration = faithful$eruptions
range(duration)
breaks = seq(1.5, 5.5, by=0.5)
breaks
duration.cut = cut(duration, breaks, right=FALSE)
duration.freq = table(duration.cut)
duration.freq
cbind(duration.freq)
barplot(duration.freq)
nrow(faithful)
faithful$eruptions / nrow(faithful)
help(hist)
hist(faithful$eruptions)
faithful)
head(faithful)
hist(faithful$waiting)
hist(faithful)
help(barplot)
VADeaths
help(demo)
demo()
demo("graphics")
hist(faithful$waiting)
interval = faithful$waiting
interval
range(interval)
breaks = seq(43, 96, by=1)
breaks
interval.cut = cut(interval, breaks, right=FALSE)
interval.freq = table(interval.cut)
barplot(interval.freq)
breaks = seq(43, 96, by=5)
breaks
interval.cut = cut(interval, breaks, right=FALSE)
interval.freq = table(interval.cut)
barplot(interval.freq)
help(points)
points(interval.freq)
barplot(interval.freq)
hist(faithful$eruptions, right=FALSE)
duration = faithful$eruptions
hist(duration, right=FALSE)
colors = c("red", "yellow", "green", "violet", "orange", "blue", "pink", "cyan")
hist(duration, right=FALSE, col=colors, main="Old Faithful Eruptions", xlab="Duration minutes")
waiting_period = faithful$waiting
waiting_period = faithful$waiting
hist(waiting_period, right=FALSE, col=colors, main="Old Faithful Eruptions", xlab="Interval")
hist(waiting_period, right=FALSE, col=colors, main="Old Faithful Eruptions", xlab="Interval in minutes")
q()
2011-07-13 01:32:36 +00:00
duration = faithful$eruptions
breaks = seq(1.5, 5.5, by=0.5)
duration.cut = cut(duration, breaks, right=FALSE)
duration.freq = table(duration.cut)
duration.relfreq = duration.freq / nrow(faithful)
duration.relfreq
pie(duration.relfreq)
hist(duration.relfreq)
hist(duration.relfreq)
duration.freq
duration = faithful$eruptions
breaks = seq(1.5, 5.5, by=0.5)
breaks
typeof(breaks)
duration.cut = cut(duration, breaks, right=FALSE)
duration.freq = table(duration.cut)
duration.cumfreq = cumsum(duration.freq)
duration.cumfreq
hist(cbind(duration.cumfreq))
interval = faithful$waiting
help(function)
help("function")
help("function")
calc_cumfreq <- function(records)
breaks = seq(1.5, 5.5, by=0.5)
records.cut = cut(duration, breaks, right=FALSE)
records.freq = table(duration.cut)
records.cumfreq = cumsum(records.freq)
return(records)
calc_cumfreq <- function(records)
breaks = seq(1.5, 5.5, by=0.5)
records.cut = cut(records, breaks, right=FALSE)
help("function")
duration.cumfreq
interval = faithful$eruptions
breaks
breaks.cut = cut(interval, breaks, right=FALSE)
interval.freq = table(interval.cut)
interval.cumfreq = cumsum(interval.freq)
hist(interval.cumfreq)
q()
2011-07-13 01:55:11 +00:00
duration = faithful$eruptions
breaks = seq(1.5, 5.5, by=0.5)
duration.cut = cut(duration, breaks, right=FALSE)
duration.freq = table(duration.cut)
cumfreq0 = c(0, cumsum(duration.freq))
plot(breaks, cumfreq0, main="Old Faithful Eruptions", xlab="Duration minutes", ylab="Cumulative Eruptions")
lines(breaks, cumfreq0)
intervals = faithful$waiting
faithful$waiting
cbind(faithful$waiting)
faithful$waiting / nrow(faithful)
faithful$waiting / nrow(faithful$waiting)
intervals
breaks
intervals.cut = cut(breaks, intervals)
help(cut)
intervals.cut = cut(intervals, breaks)
intervals.cut
intervals.cut
intervals.freq = table(intervals.cut)
intervals.cut = cut(intervals, breaks, right=FALSE)
intervals.freq = table(intervals.cut)
cumfreq0 = c(0, cumsum(intervals.freq))
cumfreq0
intervals
intervals.cut = cut(intervals, breaks, right=FALSE)
intervals.cut
intervals.freq = table(intervals.cut)
intervals.freq
cbind(intervals.freq)
plot(breaks, cumfreq0)
intervals
cut(intervals, breaks)
cut(intervals, breaks, right=FALSE)
duration
cut(duration, breaks)
breaks = seq(0, 100, by=10)
breaks
cut(intervals, breaks)
intervals.cut = cut(intervals, breaks)
intervals.cut = cut(intervals, breaks, right=FALSE)
intervals.cut
intervals.freq = table(intervals.cut)
cumfreq0 = c(0, cumsum(intervals.freq))
cumfreq0
plot(breaks, cumfreq0)
lines(breaks, cumfreq0)
intervals
min(intervals)
max(intervals)
breaks = seq(40.0, 100.0, by=5.0)
intervals.cut = cut(intervals, breaks, right=FALSE)
intervals.cut
floor?
help(floor)
intervals.freq = table(intervals.cut)
intervals.freq
cumfreq0 = c(0, cumsum(intervals.freq))
cumfreq0
plot(breaks, cumfreq0)
lines(breaks, cumfreq0)
plot(breaks, cumfreq0, main="Old Faithful Intervals", xlab="Interval minutes", ylab="Cumulative Intervals")
lines(breaks, cumfreq0)
q()