data(iris)
str(iris)
## 'data.frame': 150 obs. of 5 variables:
## $ Sepal.Length: num 5.1 4.9 4.7 4.6 5 5.4 4.6 5 4.4 4.9 ...
## $ Sepal.Width : num 3.5 3 3.2 3.1 3.6 3.9 3.4 3.4 2.9 3.1 ...
## $ Petal.Length: num 1.4 1.4 1.3 1.5 1.4 1.7 1.4 1.5 1.4 1.5 ...
## $ Petal.Width : num 0.2 0.2 0.2 0.2 0.2 0.4 0.3 0.2 0.2 0.1 ...
## $ Species : Factor w/ 3 levels "setosa","versicolor",..: 1 1 1 1 1 1 1 1 1 1 ...
library(psych)
describe(iris)
## vars n mean sd median trimmed mad min max range skew
## Sepal.Length 1 150 5.84 0.83 5.80 5.81 1.04 4.3 7.9 3.6 0.31
## Sepal.Width 2 150 3.06 0.44 3.00 3.04 0.44 2.0 4.4 2.4 0.31
## Petal.Length 3 150 3.76 1.77 4.35 3.76 1.85 1.0 6.9 5.9 -0.27
## Petal.Width 4 150 1.20 0.76 1.30 1.18 1.04 0.1 2.5 2.4 -0.10
## Species* 5 150 2.00 0.82 2.00 2.00 1.48 1.0 3.0 2.0 0.00
## kurtosis se
## Sepal.Length -0.61 0.07
## Sepal.Width 0.14 0.04
## Petal.Length -1.42 0.14
## Petal.Width -1.36 0.06
## Species* -1.52 0.07
by(iris, iris$Species, summary)
## iris$Species: setosa
## Sepal.Length Sepal.Width Petal.Length Petal.Width
## Min. :4.300 Min. :2.300 Min. :1.000 Min. :0.100
## 1st Qu.:4.800 1st Qu.:3.200 1st Qu.:1.400 1st Qu.:0.200
## Median :5.000 Median :3.400 Median :1.500 Median :0.200
## Mean :5.006 Mean :3.428 Mean :1.462 Mean :0.246
## 3rd Qu.:5.200 3rd Qu.:3.675 3rd Qu.:1.575 3rd Qu.:0.300
## Max. :5.800 Max. :4.400 Max. :1.900 Max. :0.600
## Species
## setosa :50
## versicolor: 0
## virginica : 0
##
##
##
## ------------------------------------------------------------
## iris$Species: versicolor
## Sepal.Length Sepal.Width Petal.Length Petal.Width Species
## Min. :4.900 Min. :2.000 Min. :3.00 Min. :1.000 setosa : 0
## 1st Qu.:5.600 1st Qu.:2.525 1st Qu.:4.00 1st Qu.:1.200 versicolor:50
## Median :5.900 Median :2.800 Median :4.35 Median :1.300 virginica : 0
## Mean :5.936 Mean :2.770 Mean :4.26 Mean :1.326
## 3rd Qu.:6.300 3rd Qu.:3.000 3rd Qu.:4.60 3rd Qu.:1.500
## Max. :7.000 Max. :3.400 Max. :5.10 Max. :1.800
## ------------------------------------------------------------
## iris$Species: virginica
## Sepal.Length Sepal.Width Petal.Length Petal.Width
## Min. :4.900 Min. :2.200 Min. :4.500 Min. :1.400
## 1st Qu.:6.225 1st Qu.:2.800 1st Qu.:5.100 1st Qu.:1.800
## Median :6.500 Median :3.000 Median :5.550 Median :2.000
## Mean :6.588 Mean :2.974 Mean :5.552 Mean :2.026
## 3rd Qu.:6.900 3rd Qu.:3.175 3rd Qu.:5.875 3rd Qu.:2.300
## Max. :7.900 Max. :3.800 Max. :6.900 Max. :2.500
## Species
## setosa : 0
## versicolor: 0
## virginica :50
##
##
##
plot(x = iris$Sepal.Width, y = iris$Sepal.Length,
xlab = 'Sepal Width',
ylab = 'Sepal Length',
col = iris$Species,
main = 'Iris Sepal Width by Length',
xlim = c(0,5),
ylim = c(0,10))
legend("topright",
legend = unique(iris$Species),
col = c('black', 'red', 'green'),
pch = 1)
plot(x = iris$Petal.Width,
y = iris$Petal.Length,
xlab = 'Petal Width',
ylab = 'Petal Length',
xlim = c(0,4),
col = unique(iris$Species))
legend("topleft",
legend = unique(iris$Species),
col = unique(iris$Species),
pch = 1)
Questions:
There are 150 total cases in the data. However, there is 50 cases for each specific species of iris flower; which there were 3 of.
5 numeric variables in the data
Discrete: ‘Observation Number’: measuring occurrences and has counted and finite value.
Continuous: Sepal.Width, Sepal.Length, Petal.Width, Petal.Length: these are continuous because these variables are on a continuous scale and have decimal places.
boxplot(iris, col = c('blue', 'green', 'red', 'yellow', 'purple'),
main = 'Iris Data Boxplot')
data(BOD)
plot(y = BOD$demand, x = BOD$Time, type = 'l',
xlab = 'Time', ylab = 'Oxygen Demand')
describe(BOD)
## vars n mean sd median trimmed mad min max range skew kurtosis se
## Time 1 6 3.67 2.16 3.5 3.67 2.22 1.0 7.0 6.0 0.26 -1.58 0.88
## demand 2 6 14.83 4.63 15.8 14.83 5.34 8.3 19.8 11.5 -0.29 -1.86 1.89
The dataset BOD shows Biochemical Oxygen Demand with ‘Time’ and ‘Oxygen Demand’ as the variables. This is a time series because it is tracking one entity (biochemical oxygen demand) over time.
plot.ts(BOD)