printer_data <- read.csv("C:/Users/hao/Desktop/BTL/XSTK/DATA XSTK/data.csv")
head(printer_data,3)
##   layer_height wall_thickness infill_density infill_pattern nozzle_temperature
## 1         0.02              8             90           grid                220
## 2         0.02              7             90      honeycomb                225
## 3         0.02              1             80           grid                230
##   bed_temperature print_speed material fan_speed roughness tension_strenght
## 1              60          40      abs         0        25               18
## 2              65          40      abs        25        32               16
## 3              70          40      abs        50        40                8
##   elongation
## 1        1.2
## 2        1.4
## 3        0.8
new_DF <- printer_data[,c("layer_height","wall_thickness","infill_density",
"infill_pattern","nozzle_temperature","bed_temperature","print_speed",
"material","fan_speed","tension_strenght")]
head(new_DF,3)
##   layer_height wall_thickness infill_density infill_pattern nozzle_temperature
## 1         0.02              8             90           grid                220
## 2         0.02              7             90      honeycomb                225
## 3         0.02              1             80           grid                230
##   bed_temperature print_speed material fan_speed tension_strenght
## 1              60          40      abs         0               18
## 2              65          40      abs        25               16
## 3              70          40      abs        50                8
library(questionr)
freq.na(new_DF) #in kết quả dữ liệu bị khuyết
##                    missing %
## layer_height             0 0
## wall_thickness           0 0
## infill_density           0 0
## infill_pattern           0 0
## nozzle_temperature       0 0
## bed_temperature          0 0
## print_speed              0 0
## material                 0 0
## fan_speed                0 0
## tension_strenght         0 0
new_function <- function(x){
  c(n=length(x),xtb=mean(x),sd=sd(x),Q1=quantile(x,probs=0.25),
  Q2=median(x),Q3=quantile(x,probs=0.75),min=min(x),max=max(x))
}

continous_data <- new_DF[,c("layer_height","wall_thickness","infill_density",
"nozzle_temperature","bed_temperature","print_speed","fan_speed","tension_strenght")]

apply(continous_data,2,new_function)
##        layer_height wall_thickness infill_density nozzle_temperature
## n       50.00000000      50.000000       50.00000           50.00000
## xtb      0.10600000       5.220000       53.40000          221.50000
## sd       0.06439673       2.922747       25.36348           14.82035
## Q1.25%   0.06000000       3.000000       40.00000          210.00000
## Q2       0.10000000       5.000000       50.00000          220.00000
## Q3.75%   0.15000000       7.000000       80.00000          230.00000
## min      0.02000000       1.000000       10.00000          200.00000
## max      0.20000000      10.000000       90.00000          250.00000
##        bed_temperature print_speed fan_speed tension_strenght
## n            50.000000     50.0000  50.00000        50.000000
## xtb          70.000000     64.0000  50.00000        20.080000
## sd            7.142857     29.6923  35.71429         8.925634
## Q1.25%       65.000000     40.0000  25.00000        12.000000
## Q2           70.000000     60.0000  50.00000        19.000000
## Q3.75%       75.000000     60.0000  75.00000        27.000000
## min          60.000000     40.0000   0.00000         4.000000
## max          80.000000    120.0000 100.00000        37.000000
table(new_DF$infill_pattern)
## 
##      grid honeycomb 
##        25        25
table(new_DF$material)
## 
## abs pla 
##  25  25
hist(new_DF$tension_strenght,breaks=10,col="darkred",xlab="tension strength",main="histogram tension strength",xlim=c(0,40),ylim=c(0,15),labels=T)

boxplot(tension_strenght~infill_pattern,new_DF,col=c("red","blue"),
        main="tension_strenght and infill_pattern")

par(mfrow=c(2,4))

plot(new_DF$layer_height,new_DF$tension_strenght,xlab="layer_height",ylab="tension_strenght",main="layer height & tension strenght")

plot(new_DF$wall_thickness,new_DF$tension_strenght,xlab="wall_thickness",ylab="tension_strenght",main="wall_thickness & tension strenght")


plot(new_DF$infill_density,new_DF$tension_strenght,xlab="infill_density",ylab="tension_strenght",main="infill_density & tension strenght")

plot(new_DF$nozzle_temperature,new_DF$tension_strenght,xlab="nozzle_temperature",ylab="tension_strenght",main="nozzle_temperature & tension strenght")

plot(new_DF$bed_temperature,new_DF$tension_strenght,xlab="bed_temperature",ylab="tension_strenght",main="bed_temperature & tension strenght")

plot(new_DF$print_speed,new_DF$tension_strenght,xlab="print_speed",ylab="tension_strenght",main="print_speed & tension strenght")

plot(new_DF$fan_speed,new_DF$tension_strenght,xlab="fan_speed",ylab="tension_strenght",main="fan_speed & tension strenght")

library(corrplot)
## Warning: package 'corrplot' was built under R version 4.5.3
## corrplot 0.95 loaded
corrplot(cor(continous_data),method="number")

n <- length(new_DF$tension_strenght)
xtb <- mean(new_DF$tension_strenght)
s <- sd(new_DF$tension_strenght)
data.frame(n,xtb,s)
##    n   xtb        s
## 1 50 20.08 8.925634
qqnorm(new_DF$tension_strenght)
qqline(new_DF$tension_strenght)

shapiro.test(new_DF$tension_strenght)
## 
##  Shapiro-Wilk normality test
## 
## data:  new_DF$tension_strenght
## W = 0.9566, p-value = 0.06404
epsilon <- qt(p=0.05/2,df=n-1,lower.tail=FALSE)*s/sqrt(n)
print(epsilon)
## [1] 2.536637
data.frame(u1=xtb-epsilon,u2=xtb+epsilon)
##         u1       u2
## 1 17.54336 22.61664