# Input Data
nilai =read.delim("normalitas.txt", header = TRUE)
nilai
##    Nomor Nama Nilai
## 1      1    A    40
## 2      2    B    50
## 3      3    C    50
## 4      4    D    60
## 5      5    F    60
## 6      6    G    60
## 7      7    H    70
## 8      8    I    70
## 9      9    J    70
## 10    10    K    70
## 11    11    L    80
## 12    12    M    80
## 13    13    N    80
## 14    14    O    90
## 15    15    P    90
## 16    16    Q   100
x = nilai$Nilai
summary(x)
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##      40      60      70      70      80     100
library(nortest)
lillie.test(x)
## 
##  Lilliefors (Kolmogorov-Smirnov) normality test
## 
## data:  x
## D = 0.125, p-value = 0.7235
library(tseries)
## Registered S3 method overwritten by 'quantmod':
##   method            from
##   as.zoo.data.frame zoo
JB = jarque.bera.test(x)
JB
## 
##  Jarque Bera Test
## 
## data:  x
## X-squared = 0.30827, df = 2, p-value = 0.8572
# Menghitung statistik
n <- length(x)
mean_x <- mean(x)
median_x <- median(x)
max_x <- max(x)
min_x <- min(x)
sd_x <- sd(x)

a <- mean((x - mean(x))^2)
b <- mean((x - mean(x))^3)
c <- mean((x - mean(x))^4)

skew <- b / (a^(3/2))
kurt <- c / (a^2)

JB <- tseries::jarque.bera.test(x)

# Membuat tampilan histogram dan statistik
layout(matrix(c(1,2), nrow=1), widths=c(2,1))

par(mar=c(4,4,3,1))
hist(x,
     main="Histogram Uji Normalitas",
     xlab="Nilai",
     ylab="Frequency",
     col="skyblue",
     border="black")

par(mar=c(1,1,2,1))
plot.new()
text(0, 0.95, "Descriptive Statistics", adj=0, font=2)
text(0, 0.85, paste("Mean:", round(mean_x, 4)), adj=0)
text(0, 0.75, paste("Median:", round(median_x, 4)), adj=0)
text(0, 0.65, paste("Maximum:", max_x), adj=0)
text(0, 0.55, paste("Minimum:", min_x), adj=0)
text(0, 0.45, paste("Std. Dev.:", round(sd_x, 4)), adj=0)
text(0, 0.35, paste("Skewness:", round(skew, 4)), adj=0)
text(0, 0.25, paste("Kurtosis:", round(kurt, 4)), adj=0)
text(0, 0.15, paste("Jarque-Bera:", round(as.numeric(JB$statistic), 4)), adj=0)
text(0, 0.05, paste("Probability:", round(JB$p.value, 4)), adj=0)

layout(1)

Uji Normalitas Populasi dengan Q-Q Plot

qqnorm(x)
qqline (x)