setwd("L:/Data/Teaching/MyCourse/105-1_Programming/Code")
ls()
iris
iris[ 1, 1 ]
iris[ 1, 2 ]
iris[ 1, 3 ]
iris[ 1, 4 ]
iris[ 1, 5 ]
iris[ 1, 1:5 ]
iris[ 2, 1:5 ]
iris[ 1:2, 1:5 ]
iris[ 1,  ]
iris[ 1, 2:4 ]
iris[ , 1 ]
iris[ , 2 ]
iris[ , 5 ]
mydata <- iris
mydata
mydata[ 1, ]
mydata[ 2, ]
mydata[ 1:2, ]
mydata[ 1:5, ]
str( mydata )
summary( mydata )
str( mydata[,5] )
summary( mydata[,5] )
summary( mydata[,3] )
head( mydata )
head( mydata, n=10 )
help("head")
tail( mydata )
tail( mydata, n = 10 )
mydata[ , 1]
mydata$Species
mydata[ mydata[ , 5] == "setosa", 1]
mydata[ mydata[ , 5] == "versicolor", 1]
mydata[ mydata[ , 5] == "virginica", 1]
mydata[ mydata[ , 5] == "virginica", 1:4]
mydata[ mydata[ , 5] == "sentosa", 1:4]
mydata[ mydata[ , 5] == "setosa", 1:4]
mydata$Species
mydata[ mydata$Species == "setosa", 1:4]
mydata[ mydata$Species == "versicolor", 1:4]
mydata$Sepal.Length
mydata[ mydata$Sepal.Length == 5.0, 1:4]
mydata[ mydata$Sepal.Length == 5.0, 1:5]
mydata[ mydata$Sepal.Length == 5.1, 1:5]
mydata[ mydata$Sepal.Length >= 5.1, 1:5]
mydata[ mydata$Sepal.Width >= 3.0, 1:5]
mydata[ mydata$Sepal.Width == 3.0, 1:5]
mydata[ mydata$Sepal.Width == 3.1, 1:5]
subset( mydata, Species == "setosa", select = Sepal.Length )
subset( mydata, Species == "setosa", select = c( Sepal.Length, Sepal.Width ) )
subset( mydata, Petal.Length == 4.0, select = c( Sepal.Length, Sepal.Width ) )
subset( mydata, Sepal.Length == 4.0, select = c( Sepal.Length, Sepal.Width ) )
subset( mydata, Sepal.Length == 5.0, select = c( Sepal.Length, Sepal.Width ) )
subset( mydata, Sepal.Length == 5.1, select = c( Sepal.Length, Sepal.Width ) )
subset( mydata, Sepal.Length >= 5.1, select = c( Sepal.Length, Sepal.Width ) )
subset( mydata, Sepal.Length >= 6.1, select = c( Sepal.Length, Sepal.Width ) )
subset( mydata, Sepal.Length >= 7.1, select = c( Sepal.Length, Sepal.Width ) )
subset( mydata, Sepal.Length >= 7.1, select = c( Sepal.Length, Petal.Length ) )
subset( mydata, Sepal.Length <= 4.1, select = c( Sepal.Length, Petal.Length ) )
subset( mydata, Sepal.Length <= 5.1, select = c( Sepal.Length, Petal.Length ) )
max(  mydata[ , 1 ] )
min(  mydata[ , 1 ] )
c( max( mydata[ ,1 ] ), min( mydata[ , 1]) )
c( max( mydata[ , 2 ] ), min( mydata[ , 2 ] ) )
c( max( mydata[ , 3 ] ), min( mydata[ , 3 ] ) )
c( max( mydata[ , 4 ] ), min( mydata[ , 4 ] ) )
summary( mydata )
MaxMin1 <- c( max( mydata[ , 1 ] ), min( mydata[ , 1]) )
MaxMin2 <- c( max( mydata[ , 2 ] ), min( mydata[ , 2 ]) )
MaxMin1
MinMax2
ManMin2
MaxMin2
range( mydata[ , 1 ] )
range( mydata[ , 2 ] )
mean( mydata[ , 1 ] )
sd( mydata[ , 1 ] )
median( mydata[ , 1 ] )
mystat <- c( max(mydata[,1], mean(mydata[,1]), median(mydata[,1]), min(mydata[,1]), sd(mydata[,1]))
)
mystat
mystat <- c( max(mydata[,1]), mean(mydata[,1]), median(mydata[,1]), min(mydata[,1]), sd(mydata[,1]) )
mystat
summary( mydata[,1] )
mydata[ 150*0.25,1]
mydata[ 150*0.5,1]
mydata[ ,1]
mydata_sort <- sort( mydata[,1] )
mydata_sort[ 150*0.5,1]
mydata_sort
mydata_sort[ 150*0.5 ]
mydata_sort[ 150*0.25 ]
mydata_sort[ 150*0.75 ]
mydata[ , 1 ]
plot( mydata[ , 1 ] )
plot( mydata[ , 2 ] )
plot( mydata[ , 3 ] )
plot( mydata[ , 4 ] )
plot( mydata[ , 5 ] )
hist( mydata[ , 1 ] )
hist( mydata[ , 2 ] )
hist( mydata[ , 3 ] )
hist( mydata[ , 4 ] )
hist( mydata[ , 5 ] )
layout( matrix( c( 1, 2, 3, 4) , 2, 2, byrow = T ), widths = c(1,1), heights = c(1,1) )
layout( matrix( c( 1, 2, 3, 4) , 2, 2, byrow = T ), widths = c(1,1), heights = c(1,1) )
plot( mydata[ , 1 ] )
plot( mydata[ , 2 ] )
plot( mydata[ , 3 ] )
plot( mydata[ , 4 ] )
layout( matrix( c( 1, 2, 3, 4) , 2, 2, byrow = T ), widths = c(1,2), heights = c(1,3) )
plot( mydata[ , 1 ] )
plot( mydata[ , 2 ] )
plot( mydata[ , 3 ] )
plot( mydata[ , 4 ] )
layout( matrix( c( 1, 2, 3, 4) , 2, 2, byrow = T ), widths = c(1,2), heights = c(2,1) )
hist( mydata[ , 1 ] )
hist( mydata[ , 2 ] )
hist( mydata[ , 3 ] )
hist( mydata[ , 4 ] )
layout( matrix( c( 1, 2, 0, 3) , 2, 2, byrow = T ), widths = c(1,2), heights = c(2,1) )
hist( mydata[ , 1 ] )
hist( mydata[ , 2 ] )
hist( mydata[ , 3 ] )
hist( mydata[ , 4 ] )
hist( mydata[ , 3 ] )
hist( mydata[ , 2 ] )
hist( mydata[ , 1 ] )
layout( matrix( c( 1, 0, 2, 3) , 2, 2, byrow = T ), widths = c(1,2), heights = c(2,1) )
hist( mydata[ , 1 ] )
hist( mydata[ , 2 ] )
hist( mydata[ , 3 ] )
hist( mydata[ , 4 ] )
hist( mydata[ , 1 ] )
hist( mydata[ , 2 ] )
layout( matrix( c( 1, 2, 3, 4, 5, 6, 7, 8) , 2, 4, byrow = T ), widths = c(1,1,1,1), heights = c(1,1) )
pot( mydata[ , 1 ] )
plot( mydata[ , 1 ] )
plot( mydata[ , 2 ] )
plot( mydata[ , 3 ] )
plot( mydata[ , 4 ] )
hist( mydata[ , 4 ] )
hist( mydata[ , 4 ] )
hist( mydata[ , 4 ] )
hist( mydata[ , 4 ] )
plot( mydata[ , 1 ] )
plot( mydata[ , 2 ] )
plot( mydata[ , 3 ] )
plot( mydata[ , 4 ] )
hist( mydata[ , 1 ] )
hist( mydata[ , 2 ] )
hist( mydata[ , 3 ] )
hist( mydata[ , 4 ] )
layout( matrix( c( 1, 2, 3, 4, 5, 6, 7, 8) , 2, 4 ), widths = c(1,1,1,1), heights = c(1,1) )
plot( mydata[ , 1 ] )
hist( mydata[ , 1 ] )
plot( mydata[ , 2 ] )
hist( mydata[ , 2 ] )
plot( mydata[ , 3 ] )
hist( mydata[ , 3 ] )
plot( mydata[ , 4 ] )
hist( mydata[ , 4 ] )
par( fig=c(   0, 0.8,   0, 0.7 ), new=TRUE )
plot( mydata[ , 1 ] )
plot
plot()
par( fig=c(   0, 0.8,   0, 0.7 ), new=TRUE )
plot( mydata[ , 1 ] )
par( fig=c(   0, 0.8,   0.7, 1 ), new=TRUE )
plot( mydata[ , 2 ] )
par( fig=c(   0.8, 1,   0, 0.7 ), new=TRUE )
plot( mydata[ , 3 ] )
par( fig=c(   0.8, 1,   0.7, 1 ), new=TRUE )
plot( mydata[ , 4 ] )
layout( matrix( c( 1, 2, 3, 4) , 2, 2, byrow = T ), widths = c(1,1), heights = c(1,1) )
plot( mydata )
plot( mydata[ , 1:4 ] )
boxplot( mydata[ ,1 ] )
rug( mydata[,1], side = 4)
boxplot( mydata[ ,1 ] )
rug( mydata[,1], side = 4)
rug( mydata[,1], side = 8)
rug( mydata[,1], side = 1)
rug( mydata[,1], side = 2)
help(rug)
boxplot( mydata[ ,1 ], horizontal = TRUE )
rug( mydata[,1], side = 1)
rug( mydata[,1], side = 3)
help(par)
par( mfrow = c(1,2), mex=0.8, mar=c(5,5,3,1) + 0.1 )
hist( mydata[ , 1 ], freq = TRUE, breaks = "Sturges" )
rug( mydata[ , 1],  side = 1 )
hist( mydata[ , 1 ], prob = TRUE, breaks = "Sturges", col = "lightblue", border = "magenta" )
rug( mydata[ , 1],  side = 1 )
help(par)
par( mfcol = c(1,2), mex=0.8, mar=c(5,5,3,1) + 0.1 )
hist( mydata[ , 1 ], freq = TRUE, breaks = "Sturges" )
hist( mydata[ , 1 ], prob = TRUE, breaks = "Sturges", col = "lightblue", border = "magenta" )
par( mfcol = c(1,2), mex=0.5, mar=c(5,5,3,1) + 0.1 )
hist( mydata[ , 1 ], freq = TRUE, breaks = "Sturges" )
hist( mydata[ , 1 ], prob = TRUE, breaks = "Sturges", col = "lightblue", border = "magenta" )
par( mfcol = c(1,2), mex=2, mar=c(5,5,3,1) + 0.1 )
hist( mydata[ , 1 ], freq = TRUE, breaks = "Sturges" )
hist( mydata[ , 1 ], prob = TRUE, breaks = "Sturges", col = "lightblue", border = "magenta" )
par( mfcol = c(1,2), mex=2, mar=c(5,5,5,5) + 0.1 )
hist( mydata[ , 1 ], freq = TRUE, breaks = "Sturges" )
hist( mydata[ , 1 ], prob = TRUE, breaks = "Sturges", col = "lightblue", border = "magenta" )
par( mfcol = c(1,2), mex=2, mar=c(2,2,2,2) + 0.1 )
hist( mydata[ , 1 ], freq = TRUE, breaks = "Sturges" )
hist( mydata[ , 1 ], prob = TRUE, breaks = "Sturges", col = "lightblue", border = "magenta" )
help(par)
par( mfcol = c(2,1), mex=2, mar=c(2,2,2,2) + 0.1 )
hist( mydata[ , 1 ], freq = TRUE, breaks = "Sturges" )
hist( mydata[ , 1 ], prob = TRUE, breaks = "Sturges", col = "lightblue", border = "magenta" )
par( mfcol = c(2,1), mex=2, mar=c(4,4,4,4) + 0.1 )
hist( mydata[ , 1 ], freq = TRUE, breaks = "Sturges" )
hist( mydata[ , 1 ], prob = TRUE, breaks = "Sturges", col = "lightblue", border = "magenta" )
hist( mydata[ , 1 ], freq = TRUE, breaks = "Scott" )
hist( mydata[ , 1 ], freq = TRUE, breaks = "freedman-Diaconis" )
par( mfcol = c(2,2), mex=2, mar=c(1,1,1,1) + 0.1 )
par( mfcol = c(2,2), mex=0.5, mar=c(1,1,1,1) + 0.1 )
hist( mydata[ , 1 ], freq = TRUE, breaks = "Sturges" )
hist( mydata[ , 1 ], freq = TRUE, breaks = "Scott" )
par( mfcol = c(2,2), mex=0.5, mar=c(3,3,3,3) + 0.1 )
hist( mydata[ , 1 ], freq = TRUE, breaks = "Scott" )
par( mfcol = c(2,2), mex=0.5, mar=c(5,5,3,1) + 0.1 )
hist( mydata[ , 1 ], freq = TRUE, breaks = "Scott" )
hist( mydata[ , 1 ], freq = TRUE, breaks = "Sturges" )
par( mfcol = c(2,2), mex=0.5, mar=c(5,5,3,1) + 0.1 )
hist( mydata[ , 1 ], freq = TRUE, breaks = "Sturges" )
hist( mydata[ , 1 ], freq = TRUE, breaks = "Scott" )
hist( mydata[ , 1 ], freq = TRUE, breaks = "freedman-Diaconis" )
hist( mydata[ , 1 ], freq = TRUE, breaks = 10 )
hist( mydata[ , 1 ], freq = TRUE, breaks = 20 )
hist( mydata[ , 1 ], freq = TRUE, breaks = seq( from = 4, to = 8, by = 0.2 ) )
stem( mydata[ ,1 ], scale = 1.0 )
stem( mydata[ ,1 ], scale = 0.5 )
help( stem )
stem( mydata[ ,1 ], scale = 2 )
stem( mydata[ ,1 ], scale = 1 )
sum( mydata[ ,1 ]  )
sum( mydata[ ,1 ] == 4.4 )
sum( mydata[ ,1 ] == 4.6 )
mydata[ ,1 ] == 4.6
stripchart( mydata[ ,1 ] )
stripchart( mydata[ ,1 ], method = "overplot" )
stripchart( mydata[ ,1 ], method = "overplot", at = 0.7 )
stripchart( mydata[ ,1 ], method = "stack", add = TRUE, at = 0.85 )
stripchart( mydata[ ,1 ], method = "jitter", add = TRUE, at = 1.2 )
text( 6, 0.8, "stack")
text( 6, 0.65, "overplot")
text( 6, 1.05, "jitter")
title( main = "Strip Chart")
x <- cut( mydata[ ,1 ], breaks = 6 )
y <- table(x)
x
y
pie( y )
par( mfrow = c( 2, 2 ) )
pie( y )
pie( y, clockwise = TRUE )
pie( y, col = terain.colors(6) )
pie( y, col = terrain.colors(6) )
pie( y, col = gray( seq( from = 0.4, to = 1.0, length = 6 ) ) )
par( mfrow = c( 2, 2 ) )
pie( y )
pie( y, clockwise = TRUE )
pie( y, col = terrain.colors(6) )
pie( y, col = gray( seq( from = 0.4, to = 1.0, length = 6 ) ) )
x <- mydata[ , 1 ]
par( mfrow = c( 1, 2 ) )
plot( density(x) )
plot( density(x), col = "red" )
plot( density(x), col = "red", main = "Kernel Density Estimate" )
rug( x, side = 1)
hist(x)
hist( x, prob = TRUE )
hist( x, prob = TRUE, breaks = "Sturges" )
hist( x, prob = TRUE, breaks = "Sturges", mian = "Histogram & KDE" )
hist( x, prob = TRUE, breaks = "Sturges", main = "Histogram & KDE" )
hist( x, prob = TRUE, breaks = "Sturges", main = "Histogram & KDE" )
hist( x, prob = TRUE, breaks = "Sturges" )
hist( x, prob = TRUE, breaks = "Sturges", main = "Histogram & KDE" )
line( density(x), col = "red")
line( density(x) )
lines( density(x) )
lines( density(x), col = "red" )
rug( x, side = 1)
plot.ecdf( x )
qqnorm(x)
qqline(x)
qqline( x,  col = "red" )
qqline( x,  col = "red", lwd = 4 )
plot( iris iris)
plot( iris )
plot( mydata )
plot( mydata[, 1:4] )
paris( mydata[ , 1:4 ])
pairs( mydata[ , 1:4 ])
pairs( mydata[ , 1:4 ])
pairs( mydata[ , 1:4 ], panel = panel.smooth )
iris
x <- iris[ , 1:4 ]
panel.hist <- function(x, ...) {
usr <- par("usr"); on.exit(par(usr))
par(usr = c(usr[1:2], 0, 1.5) )
h <- hist(x, plot = FALSE)
breaks <- h$breaks; nB <- length(breaks)
y <- h$counts; y <- y / max(y)
rect(breaks[-nB], 0, breaks[-1], y, col = "cyan", ...)
lines(density(x, na.rm = TRUE), col = "red")
}
pairs( x, panel = panel.smooth, pch = 1, bg = "lightcyan",
diag.panel = panel.hist, font.labels = 2, cex.labels = 1.2 )
pairs(iris[ , 1:4 ], pch = c(1, 2, 4)[iris$Species], col = c("red", "green", "blue")[iris$Species] )
setosa <- iris[ iris$Species == "setosa", 1:4 ]
boxplot( setosa, names = c( "sep.len", "sep.wid", "pet.len", "pet.wid" ), main = "Iris setosa" )
par( mfrow = c(1, 2), mex = 0.5, mar = c(5, 4, 4, 2) + 0.1)
with( iris, boxplot( Sepal.Length ~ Species, main = "Sepal length" ) )
with( iris, boxplot( Sepal.Length ~ Species, notch = TRUE, main = "Sepal length" ) )
par(mfrow = c(1, 2), mex = 0.5, mar = c(5, 4, 4, 2) + 0.1)
sx <- with( iris, split( Sepal.Length, Species ) )
boxplot( sx, main = "Sepal length" )
boxplot( sx, notch = TRUE, main = "Sepal length" )
par(mfrow = c(1, 2), mex = 0.5, mar = c(5, 4, 4, 2) + 0.1)
sx <- with( iris, split( Sepal.Length, Species ) )
boxplot( sx, main = "Sepal length" )
boxplot( sx, notch = TRUE, main = "Sepal length" )
par( mfrow = c(1, 2), mex = 0.5, mar = c(5, 4, 4, 2) + 0.1)
with( iris, boxplot( Sepal.Length ~ Species, main = "Sepal length" ) )
with( iris, boxplot( Sepal.Length ~ Species, notch = TRUE, main = "Sepal length" ) )
sx <- with( iris, split( Sepal.Length, Species ) )
sy <- with( iris, split( Sepal.Width, Species ) )
plot( 0, xlim = range(sx), ylim = range(sy), type = "n", xlab = "x", ylab = "y")
points( sx[[1]], sy[[1]], pch = 1, col = 1)
points( sx[[2]], sy[[2]], pch = 2, col = 2)
points( sx[[3]], sy[[3]], pch = 3, col = 3)
for (i in 1:3) abline( lm(sy[[i]] ~ sx[[i]]), col = i )
legend( "topright", legend = c("setosa", "versicolor", "virginica"), lty = 1, pch = 1:3, col = 1:3 )
x <- iris[[1]]
y <- iris[[2]]
species <- iris[[5]]
library(lattice)
xyplot( y ~ x, groups = species, type = c("g", "p", "r"), auto.key = TRUE)
x <- iris[[1]]
y <- iris[[2]]
species <- iris[[5]]
library(lattice)
xyplot( y ~ x | species, type = c("g", "p", "r"), auto.key = TRUE )
data(iris)
x <- iris[, 1]
y <- iris[, 2]
z <- iris[, 3]
library(lattice)
cloud( z ~ x * y, groups = iris$Spieces, pch = 1:3, col = 1:3,
scales = list(arrows = FALSE),
light.source = c(10, 0, 10) )
savehistory("L:/Data/Teaching/MyCourse/105-1_Programming/Code/data_160925_U03_IRIS.Rhistory")
