Name:
library(rmarkdown); library(knitr); library(moments);
library(scatterplot3d); library(corrplot); library(pso)
library(psych); library(GPArotation); library(lavaan)
# Insert code or written answer here
(2 + 7 + 1 + 8) / 4
## [1] 4.5
# Insert code or written answer here
x1 <- 2; x2 <- 7; x3 <- 1; x4 <- 8
m <- (x1 + x2 + x3 + x4) / 4
SS <- (x1 - m)^2 + (x2 - m)^2 + (x3 - m)^2 + (x4 - m)^2
s <- sqrt( SS / (4 - 1) )
s
## [1] 3.511885
# Insert code or written answer here
x <- c(2,7,1,8)
m <- (2 + 7 + 1 + 8) / 4
m2 <- ((x[1]-m)^2 + (x[2]-m)^2 + (x[3]-m)^2 + (x[4]-m)^2) / 4
m3 <- ((x[1]-m)^3 + (x[2]-m)^3 + (x[3]-m)^3 + (x[4]-m)^3) / 4
g1 <- m3 / (m2^(3/2))
g1
## [1] 0
# Insert code or written answer here
m4 <- ((x[1]-m)^4 + (x[2]-m)^4 + (x[3]-m)^4 + (x[4]-m)^4) / 4
g2 <- m4 / (m2^2)
g2
## [1] 1.105186
# Insert code or written answer here
# Insert code or written answer here
# Insert code or written answer here
years <- c(1991,1994,1997,2000,2003,2006,2009,2012,2015,2020)
counts <- c(3100,4600,5600,7700,7800,7800,9700,10200,9300,10200)
# a) matrix with row and column names
Homelessness <- cbind(Year = years, Homelessness = counts)
rownames(Homelessness) <- as.character(years)
Homelessness
## Year Homelessness
## 1991 1991 3100
## 1994 1994 4600
## 1997 1997 5600
## 2000 2000 7700
## 2003 2003 7800
## 2006 2006 7800
## 2009 2009 9700
## 2012 2012 10200
## 2015 2015 9300
## 2020 2020 10200
# Insert code or written answer here
stripchart(counts, method = "stack",
main = "Homelessness in MN (counts)",
xlab = "People (rounded to nearest 100)")
#### Part (c) Skewed to the left (more high values, a longer tail toward
smaller numbers)
# Insert code or written answer here
Since it skewed to the left, it is negative skewed
# Insert code or written answer here
I think the kurtosis is likely to be smaller than 3 since the distribution of the data on the graph seems to be quite flat and the peak also not too significant as well
# Insert code or written answer here
# Insert code or written answer here
sk <- skewness(counts)
ku <- kurtosis(counts)
c(skewness = sk, kurtosis = ku)
## skewness kurtosis
## -0.6091741 2.1350015
# Insert code or written answer here
dates <- c("2017-05","2017-06","2017-07","2017-08","2017-09","2017-10","2017-11",
"2017-12","2018-01","2018-02","2018-03","2018-04","2018-05","2018-06",
"2018-07","2018-08","2018-09","2018-10","2018-11","2018-12","2019-01",
"2019-02","2019-03","2019-04","2019-05","2019-06","2019-07","2019-08",
"2019-09","2019-10","2019-11","2019-12","2020-01","2020-02","2020-03",
"2020-04","2020-05","2020-06","2020-07","2020-08")
price <- c(3.15,2.98,2.98,2.90,2.98,2.88,3.01,2.82,3.87,2.67,2.69,2.80,2.80,2.97,
2.83,2.96,3.00,3.28,4.09,4.04,3.11,2.69,2.95,2.65,2.64,2.40,2.37,2.22,
2.56,2.33,2.65,2.22,2.02,1.91,1.79,1.74,1.75,1.63,1.77,2.30)
NG <- cbind(Date = dates, Price = price)
rownames(NG) <- dates
NG
## Date Price
## 2017-05 "2017-05" "3.15"
## 2017-06 "2017-06" "2.98"
## 2017-07 "2017-07" "2.98"
## 2017-08 "2017-08" "2.9"
## 2017-09 "2017-09" "2.98"
## 2017-10 "2017-10" "2.88"
## 2017-11 "2017-11" "3.01"
## 2017-12 "2017-12" "2.82"
## 2018-01 "2018-01" "3.87"
## 2018-02 "2018-02" "2.67"
## 2018-03 "2018-03" "2.69"
## 2018-04 "2018-04" "2.8"
## 2018-05 "2018-05" "2.8"
## 2018-06 "2018-06" "2.97"
## 2018-07 "2018-07" "2.83"
## 2018-08 "2018-08" "2.96"
## 2018-09 "2018-09" "3"
## 2018-10 "2018-10" "3.28"
## 2018-11 "2018-11" "4.09"
## 2018-12 "2018-12" "4.04"
## 2019-01 "2019-01" "3.11"
## 2019-02 "2019-02" "2.69"
## 2019-03 "2019-03" "2.95"
## 2019-04 "2019-04" "2.65"
## 2019-05 "2019-05" "2.64"
## 2019-06 "2019-06" "2.4"
## 2019-07 "2019-07" "2.37"
## 2019-08 "2019-08" "2.22"
## 2019-09 "2019-09" "2.56"
## 2019-10 "2019-10" "2.33"
## 2019-11 "2019-11" "2.65"
## 2019-12 "2019-12" "2.22"
## 2020-01 "2020-01" "2.02"
## 2020-02 "2020-02" "1.91"
## 2020-03 "2020-03" "1.79"
## 2020-04 "2020-04" "1.74"
## 2020-05 "2020-05" "1.75"
## 2020-06 "2020-06" "1.63"
## 2020-07 "2020-07" "1.77"
## 2020-08 "2020-08" "2.3"
# Insert code or written answer here
p <- price
stripchart(p, method = "stack", main = "Natural Gas Price",
xlab = "Price")
library(moments)
sk_raw <- skewness(p)
sk_raw
## [1] 0.2754271
# Insert code or written answer here
sk_log <- skewness(log(p))
sk_log
## [1] -0.3551133
# Insert code or written answer here
sk_sq <- skewness(p^2)
sk_sq
## [1] 0.9737242
# Insert code or written answer here
sk_sqrt <- skewness(sqrt(p))
sk_sqrt
## [1] -0.05318914
I think the most effective transformation can be square-root since it’ll bring the skewness closer (or) to 0 (which is closer to symmetric)
# Insert code or written answer here
# Insert code or written answer here
countries <- c("Argentina","Bolivia","Brazil","Chile","Colombia",
"Ecuador","Paraguay","Peru","Uruguay")
Water <- c(0.3, 7.4, 1.7, 0.1, 2.4, 4.3, 2.1, 6.2, 0.5)
Electricity<- c(0.0, 4.9, 0.2, 0.3, 1.3, 1.4, 0.3, 4.1, 0.1)
Sanitation <- c(0.4,16.3,34.2,0.6, 8.2, 3.6, 9.0,12.1, 1.0)
Education <- c(1.5,13.2,16.0,4.0, 5.1, 3.9, 6.3, 5.4, 2.0)
MPM <- cbind(Water, Electricity, Sanitation, Education)
rownames(MPM) <- countries
MPM
## Water Electricity Sanitation Education
## Argentina 0.3 0.0 0.4 1.5
## Bolivia 7.4 4.9 16.3 13.2
## Brazil 1.7 0.2 34.2 16.0
## Chile 0.1 0.3 0.6 4.0
## Colombia 2.4 1.3 8.2 5.1
## Ecuador 4.3 1.4 3.6 3.9
## Paraguay 2.1 0.3 9.0 6.3
## Peru 6.2 4.1 12.1 5.4
## Uruguay 0.5 0.1 1.0 2.0
# Insert code or written answer here
library(moments)
apply(MPM, 2, skewness)
## Water Electricity Sanitation Education
## 0.682885 1.134367 1.382028 1.064040
# Insert code or written answer here
apply(MPM, 2, kurtosis)
## Water Electricity Sanitation Education
## 2.082099 2.641410 4.069517 2.738338
Sanitation with highest skewness (1.382) and kurtosis > 3 (4.0695), which illustrate strong right-tail and heavier tail
# Insert code or written answer here
# Insert code or written answer here
# Insert code or written answer here