library(tidyverse)
library(kableExtra)
library(psych)
library(PerformanceAnalytics)
library(corrplot)
A <- (sin(pi/7))^(1/2)
B <- log(1024, 2)
C <- c(A, 2:B, A^2*B^2)
D <- C * exp(1)
c(
średnia = mean(C),
mediana = median(C),
wariancja = var(C),
`odchylenie standardowe` = sd(C)
)
## średnia mediana wariancja
## 8.91337 6.00000 139.30550
## odchylenie standardowe
## 11.80278
c(
średnia = mean(D),
mediana = median(D),
wariancja = var(D),
`odchylenie standardowe` = sd(D)
)
## średnia mediana wariancja
## 24.22905 16.30969 1029.33617
## odchylenie standardowe
## 32.08327
rnorm(30, 50, 5)
## [1] 50.18435 52.32381 55.45341 53.14530 43.53808 51.25920 50.31289 45.97629
## [9] 40.43680 48.68092 48.97962 51.97129 57.19197 42.23191 43.96304 48.62074
## [17] 40.26700 51.17807 50.15069 40.17109 41.99990 48.45708 51.05802 49.32563
## [25] 47.74555 55.25466 43.49871 54.30240 48.91554 39.95377
dpois(0, 0.3)
## [1] 0.7408182
34.1%
qt(0.99, 5)
## [1] 3.36493
Data <- tibble(
Książka = Nks <- round(rnorm(200, 4, 1.5)),
TV = Ntv <- round(rnorm(200, 6, 2))
)
Data %>% ggplot(aes(TV)) +
geom_bar(stat = "count") +
scale_x_continuous(breaks = 0:100) +
ylab("Ilość osób")
Data %>% group_by(TV) %>%
summarise(`Ilość osób` = n(), Książka = mean(Książka)) %>%
ggplot(aes(TV)) +
geom_bar(aes(y = `Ilość osób`), stat = "identity") +
geom_line(aes(y = Książka*8)) +
geom_point(aes(y = Książka*8)) +
scale_x_continuous(breaks = 0:100) +
scale_y_continuous(sec.axis = sec_axis(~.*(1/8), name = "Średni czas poświęcony na czytanie książek")) +
ylab("Ilość osób")
## `summarise()` ungrouping output (override with `.groups` argument)
Data %>%
ggplot(aes(Książka, TV, group = Książka)) +
geom_boxplot() +
scale_x_continuous(breaks = 0:100)
iris %>% head(5) %>% kable()
| Sepal.Length | Sepal.Width | Petal.Length | Petal.Width | Species |
|---|---|---|---|---|
| 5.1 | 3.5 | 1.4 | 0.2 | setosa |
| 4.9 | 3.0 | 1.4 | 0.2 | setosa |
| 4.7 | 3.2 | 1.3 | 0.2 | setosa |
| 4.6 | 3.1 | 1.5 | 0.2 | setosa |
| 5.0 | 3.6 | 1.4 | 0.2 | setosa |
describe(iris[, -5], quant = c(0.25, 0.5, 0.75)) %>% select(min, max, Q0.25, Q0.5, Q0.75)
## min max Q0.25 Q0.5 Q0.75
## Sepal.Length 4.3 7.9 5.1 5.80 6.4
## Sepal.Width 2.0 4.4 2.8 3.00 3.3
## Petal.Length 1.0 6.9 1.6 4.35 5.1
## Petal.Width 0.1 2.5 0.3 1.30 1.8
####Poniżej przedstawiono histogram dla kolumny ‘sepal.width’ i naniesiono gęstość rozkładu zmiennej.
iris %>% ggplot(aes(Sepal.Width)) + geom_histogram(aes(y = ..density..)) + geom_density(col = 2)
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
chart.Correlation(iris %>% select(-Species))
corrplot.mixed(cor(iris[, -5]))
iris %>% ggplot(aes(Petal.Width, Petal.Length)) + geom_smooth(method = "lm") + geom_point()
## `geom_smooth()` using formula 'y ~ x'
Nie za bardzo wiem co znaczy, że mam uzasadnić wygląd tego wykresu. Ogólnie to chyba przedstawienie ‘reszt’ czyli odległość regresji od punktów jest sensownym przedstawieniem tej kwestii. Może jest jakaś inna, ale nie wiem jak.
apply(iris[, -5], 2, shapiro.test)
## $Sepal.Length
##
## Shapiro-Wilk normality test
##
## data: newX[, i]
## W = 0.97609, p-value = 0.01018
##
##
## $Sepal.Width
##
## Shapiro-Wilk normality test
##
## data: newX[, i]
## W = 0.98492, p-value = 0.1012
##
##
## $Petal.Length
##
## Shapiro-Wilk normality test
##
## data: newX[, i]
## W = 0.87627, p-value = 7.412e-10
##
##
## $Petal.Width
##
## Shapiro-Wilk normality test
##
## data: newX[, i]
## W = 0.90183, p-value = 1.68e-08
prop.test(x = 30, n = 300, p = 0.07, correct = F)
##
## 1-sample proportions test without continuity correction
##
## data: 30 out of 300, null probability 0.07
## X-squared = 4.1475, df = 1, p-value = 0.0417
## alternative hypothesis: true p is not equal to 0.07
## 95 percent confidence interval:
## 0.07094791 0.13916646
## sample estimates:
## p
## 0.1
Z tego co zrozumiałam, odrzucamy hipotezę zerową, ponieważ p value jest równa 0.0417.
chisq.test(c(6, 12, 9, 11, 15, 7), p = rep(1/6, 6))
##
## Chi-squared test for given probabilities
##
## data: c(6, 12, 9, 11, 15, 7)
## X-squared = 5.6, df = 5, p-value = 0.3471