1. Load Data
printer_data <- read.csv("~/Archive/data.csv")
head(printer_data, 4)
## 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
## 4 0.02 4 70 honeycomb 240
## 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
## 4 75 40 abs 75 68 10
## elongation
## 1 1.2
## 2 1.4
## 3 0.8
## 4 0.5
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, 4)
## 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
## 4 0.02 4 70 honeycomb 240
## 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
## 4 75 40 abs 75 10
2. Missing Values
library(questionr)
freq.na(new_DF)
## 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
3. Descriptive Statistics
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
4. Distribution of Tension Strength
hist(new_DF$tension_strenght,
main = "Histogram of tension_strenght",
xlab = "tension_strenght",
ylab = "Tan so",
col = "pink",
border = "black",
labels = TRUE,
ylim = c(0, 15))

5. Boxplots
boxplot(tension_strenght ~ infill_pattern,
data = new_DF,
col = c("orange", "green"),
xlab = "Infill Pattern",
ylab = "Tension_Strenght",
main = "tension_strenght and infill_pattern")

boxplot(tension_strenght ~ material,
data = new_DF,
col = c("orange", "green"),
xlab = "material",
ylab = "Tension_Strenght",
main = "tension_strenght and material")

6. Scatter Plots
variables <- c("layer_height","wall_thickness",
"infill_density","fan_speed","nozzle_temperature",
"print_speed","bed_temperature")
par(mfrow = c(2, 4))
for(v in variables){
plot(new_DF[[v]], new_DF$tension_strenght,
xlab = v,
ylab = "tension_strenght",
main = paste(v, "& tension_strenght"),
pch = 1)
}
par(mfrow = c(1, 1))

7. Correlation Matrix
cor(continous_data)
## layer_height wall_thickness infill_density
## layer_height 1.00000000 -0.19257144 0.00349856
## wall_thickness -0.19257144 1.00000000 0.10257623
## infill_density 0.00349856 0.10257623 1.00000000
## nozzle_temperature 0.00000000 -0.11849286 0.23861372
## bed_temperature 0.00000000 -0.02932662 0.00000000
## print_speed -0.05550085 -0.41953069 -0.09430408
## fan_speed 0.00000000 -0.02932662 0.00000000
## tension_strenght 0.33822961 0.39984948 0.35846444
## nozzle_temperature bed_temperature print_speed fan_speed
## layer_height 0.0000000 0.00000000 -0.05550085 0.00000000
## wall_thickness -0.1184929 -0.02932662 -0.41953069 -0.02932662
## infill_density 0.2386137 0.00000000 -0.09430408 0.00000000
## nozzle_temperature 1.0000000 0.60245337 0.00000000 0.60245337
## bed_temperature 0.6024534 1.00000000 0.00000000 1.00000000
## print_speed 0.0000000 0.00000000 1.00000000 0.00000000
## fan_speed 0.6024534 1.00000000 0.00000000 1.00000000
## tension_strenght -0.4059076 -0.25288320 -0.26459046 -0.25288320
## tension_strenght
## layer_height 0.3382296
## wall_thickness 0.3998495
## infill_density 0.3584644
## nozzle_temperature -0.4059076
## bed_temperature -0.2528832
## print_speed -0.2645905
## fan_speed -0.2528832
## tension_strenght 1.0000000
library(corrplot)
## corrplot 0.95 loaded
bang_ma_tran <- cor(continous_data)
corrplot(bang_ma_tran,
method = "number",
tl.cex = 0.8,
number.cex = 0.7)

8. Normality Test – Tension Strength
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
9. Normality Test by Material
abs_data <- subset(new_DF, material == "abs")
qqnorm(abs_data$tension_strenght)
qqline(abs_data$tension_strenght)

shapiro.test(abs_data$tension_strenght)
##
## Shapiro-Wilk normality test
##
## data: abs_data$tension_strenght
## W = 0.90604, p-value = 0.02489
pla_data <- subset(new_DF, material == "pla")
qqnorm(pla_data$tension_strenght)
qqline(pla_data$tension_strenght)

shapiro.test(pla_data$tension_strenght)
##
## Shapiro-Wilk normality test
##
## data: pla_data$tension_strenght
## W = 0.92466, p-value = 0.06547
10. Two-Sample Test: ABS vs PLA
var.test(tension_strenght ~ material, data = new_DF, alternative = "greater")
##
## F test to compare two variances
##
## data: tension_strenght by material
## F = 1.3045, num df = 24, denom df = 24, p-value = 0.26
## alternative hypothesis: true ratio of variances is greater than 1
## 95 percent confidence interval:
## 0.6575797 Inf
## sample estimates:
## ratio of variances
## 1.30448
t.test(tension_strenght ~ material, data = new_DF, var.equal = TRUE)
##
## Two Sample t-test
##
## data: tension_strenght by material
## t = -2.0972, df = 48, p-value = 0.04126
## alternative hypothesis: true difference in means between group abs and group pla is not equal to 0
## 95 percent confidence interval:
## -10.028585 -0.211415
## sample estimates:
## mean in group abs mean in group pla
## 17.52 22.64
11. ANOVA – Nozzle Temperature Groups
new_DF$nozzle_temperature_2 <- ifelse(new_DF$nozzle_temperature < 220,
"Group_1",
ifelse(new_DF$nozzle_temperature > 230,
"Group_3", "Group_2"))
Group_1 <- subset(new_DF, new_DF$nozzle_temperature_2 == "Group_1")
Group_2 <- subset(new_DF, new_DF$nozzle_temperature_2 == "Group_2")
Group_3 <- subset(new_DF, new_DF$nozzle_temperature_2 == "Group_3")
par(mfrow = c(1, 3))
qqnorm(Group_1$tension_strenght, main = "QQ-Plot Group 1")
qqline(Group_1$tension_strenght)
qqnorm(Group_2$tension_strenght, main = "QQ-Plot Group 2")
qqline(Group_2$tension_strenght)
qqnorm(Group_3$tension_strenght, main = "QQ-Plot Group 3")
qqline(Group_3$tension_strenght)

par(mfrow = c(1, 1))
shapiro.test(Group_1$tension_strenght)
##
## Shapiro-Wilk normality test
##
## data: Group_1$tension_strenght
## W = 0.91815, p-value = 0.09128
shapiro.test(Group_2$tension_strenght)
##
## Shapiro-Wilk normality test
##
## data: Group_2$tension_strenght
## W = 0.95684, p-value = 0.4829
shapiro.test(Group_3$tension_strenght)
##
## Shapiro-Wilk normality test
##
## data: Group_3$tension_strenght
## W = 0.87204, p-value = 0.1056
library(car)
## Loading required package: carData
leveneTest(tension_strenght ~ as.factor(nozzle_temperature_2), data = new_DF)
## Levene's Test for Homogeneity of Variance (center = median)
## Df F value Pr(>F)
## group 2 0.9575 0.3912
## 47
ANOVA_model <- aov(tension_strenght ~ as.factor(nozzle_temperature_2), data = new_DF)
summary(ANOVA_model)
## Df Sum Sq Mean Sq F value Pr(>F)
## as.factor(nozzle_temperature_2) 2 688 343.9 5.026 0.0105 *
## Residuals 47 3216 68.4
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
TukeyHSD(ANOVA_model)
## Tukey multiple comparisons of means
## 95% family-wise confidence level
##
## Fit: aov(formula = tension_strenght ~ as.factor(nozzle_temperature_2), data = new_DF)
##
## $`as.factor(nozzle_temperature_2)`
## diff lwr upr p adj
## Group_2-Group_1 -3.10 -9.430522 3.2305221 0.4678313
## Group_3-Group_1 -10.15 -17.903275 -2.3967255 0.0074607
## Group_3-Group_2 -7.05 -14.803275 0.7032745 0.0814970
par(mar = c(4, 4, 2, 1))
plot(TukeyHSD(ANOVA_model), las = 1)

12. Linear Regression
model_1 <- lm(tension_strenght ~ layer_height + wall_thickness + infill_density +
infill_pattern + nozzle_temperature + bed_temperature + print_speed +
material, data = new_DF)
summary(model_1)
##
## Call:
## lm(formula = tension_strenght ~ layer_height + wall_thickness +
## infill_density + infill_pattern + nozzle_temperature + bed_temperature +
## print_speed + material, data = new_DF)
##
## Residuals:
## Min 1Q Median 3Q Max
## -9.4101 -3.8491 0.0338 3.9073 13.5086
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 171.62809 54.21779 3.166 0.00292 **
## layer_height 55.59721 12.78771 4.348 8.87e-05 ***
## wall_thickness 1.06871 0.31942 3.346 0.00176 **
## infill_density 0.16286 0.03415 4.769 2.35e-05 ***
## infill_patternhoneycomb -1.14271 1.64581 -0.694 0.49140
## nozzle_temperature -1.04681 0.36901 -2.837 0.00705 **
## bed_temperature 1.00534 0.47426 2.120 0.04012 *
## print_speed -0.01559 0.03006 -0.519 0.60679
## materialpla -17.30508 8.51530 -2.032 0.04864 *
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 5.58 on 41 degrees of freedom
## Multiple R-squared: 0.673, Adjusted R-squared: 0.6092
## F-statistic: 10.55 on 8 and 41 DF, p-value: 6.91e-08
model_2 <- lm(tension_strenght ~ layer_height + wall_thickness + infill_density +
nozzle_temperature + bed_temperature + material, data = new_DF)
summary(model_2)
##
## Call:
## lm(formula = tension_strenght ~ layer_height + wall_thickness +
## infill_density + nozzle_temperature + bed_temperature + material,
## data = new_DF)
##
## Residuals:
## Min 1Q Median 3Q Max
## -9.4717 -4.1695 0.0914 3.8586 13.9581
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 167.02463 53.19880 3.140 0.003055 **
## layer_height 56.36695 12.44845 4.528 4.67e-05 ***
## wall_thickness 1.11169 0.28024 3.967 0.000271 ***
## infill_density 0.16643 0.03339 4.985 1.06e-05 ***
## nozzle_temperature -1.02890 0.36321 -2.833 0.006996 **
## bed_temperature 0.98346 0.46685 2.107 0.041026 *
## materialpla -17.10365 8.39202 -2.038 0.047722 *
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 5.501 on 43 degrees of freedom
## Multiple R-squared: 0.6667, Adjusted R-squared: 0.6201
## F-statistic: 14.33 on 6 and 43 DF, p-value: 6.783e-09
par(mfrow = c(2, 2))
plot(model_2, col = "steelblue", pch = 20)

shapiro.test(model_2$residuals)
##
## Shapiro-Wilk normality test
##
## data: model_2$residuals
## W = 0.97458, p-value = 0.3517
library(lmtest)
## Loading required package: zoo
##
## Attaching package: 'zoo'
## The following objects are masked from 'package:base':
##
## as.Date, as.Date.numeric
bptest(model_2)
##
## studentized Breusch-Pagan test
##
## data: model_2
## BP = 6.6773, df = 6, p-value = 0.3517
dwtest(model_2)
##
## Durbin-Watson test
##
## data: model_2
## DW = 1.5005, p-value = 0.01575
## alternative hypothesis: true autocorrelation is greater than 0