You are on page 1of 5

Applied Statistics – Descriptive Measures

Measures for Variation, the Range

 In R, the range() function returns a vector containing the minimum and maximum of all given values, so NOT our range
 To get our range, we need to subtract the 2 results (max – min)

range (c(7, 8, 9, 10, 11, 12)) r <- range (c(1, 2, 10, 30, 50, 99, 100))
[1] 7 12 Range <- r[2] - r[1]
Range
[1] 99
 The result is min value and max value
r <- range (c(NA, 8, 9, 10, 11, NA))
 Let´s define a vector for the results, and then it´s
[1] NA NA
possible to calculate the range: Range
[1] NA

Task r <- range (c(NA, 8, 9, 10, 11, NA), na.rm = TRUE)

?
Calculate the range of r
1. x <- c(NA, 1:3, -1:1/0) [1] 8 11
2. Cars93$Price Range <- r[2] - r[1]
3. Interruptions Range
[1] 3

Furtwangen University 2
Measures for Variation, the Range

Solutions
 

x <- c(NA, 1:3, -1:1/0) x <- Cars93$Price x <- interruptions$Interruptions
x r <- range(x) r <- range(x)
[1] NA 1 2 3 -Inf NaN Inf Range <- r[2] - r[1] Range <- r[2] - r[1]
r <- range(x) Range Range
Range <- r[2] - r[1] [1] 54.5 [1] 5
Range
[1] NA

Furtwangen University 3
Measures for Variation, Coefficient of Variation

install.packages("DescTools")
library(DescTools)

x <- c(2, 3, 5, 7, 8, 10, 16) CoefVar(Cars93$Price)


mean(x) [1] 0.4951096
[1] 7.285714
sd(x)
[1] 4.75094
CoefVar(x)
[1] 0.6520898

x <- c(102, 103, 105, 107, 108, 110, 116)


mean(x)
[1] 107.2857
sd(x)
[1] 4.75094
CoefVar(x)
Task
a) Calculate the coefficient of variation of interruptions$Interruptions
b) Take the data „restaurants“ from Ch03 and calculate the
?
[1] 0.04428306 coefficient of variation of the meal cost in cities and in suburbans as well

Furtwangen University 4
Measures for Variation, Coefficient of Variation

Solutions  

a) CoefVar(interruptions$Interruptions)
[1] 1.172689

b) tapply(Restaurants$Cost, Restaurants$Location, CoefVar)


City Suburban
0.3137344 0.1946984

Furtwangen University 5

You might also like