library(readxl)
library(tidyr)
## Warning: package 'tidyr' was built under R version 3.6.2
data_wu <- read_excel("~/Desktop/data_wu.xls")
## New names:
## * `` -> ...1
## * `` -> ...5
data_wu<-data_wu[,c(2:4,6:8)]
data_wu
## # A tibble: 8 x 6
## Aé¢„çƒæ¸©åº¦ BåŠ ç†±é€Ÿåº¦ Cé¢„çƒæ—¶é—´ `1` `2` `3`
## <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
## 1 117 9 9 12.7 11.0 11.3
## 2 117 9 11 9.57 12.9 10.9
## 3 143 9 9 12.3 11.7 10.4
## 4 143 9 11 11.5 10.7 11.0
## 5 117 11 9 11.6 10.8 11.7
## 6 117 11 11 11.4 11.5 11.0
## 7 143 11 9 11.9 12.9 11.9
## 8 143 11 11 10.2 10.9 12.7
colnames(data_wu)<-c("temp","speed","time","y1","y2","y3")
data_long <- gather(data_wu, period, Y, y1:y3, factor_key=TRUE)
lm0<-lm(Y~ as.factor(speed) + as.factor(time)+ as.factor(temp) ,data = data_long)
lm1<-lm(Y~ as.factor(speed) * as.factor(time)*as.factor(temp) ,data = data_long)
Model 1, with all interactions
summary(lm1)
##
## Call:
## lm(formula = Y ~ as.factor(speed) * as.factor(time) * as.factor(temp),
## data = data_long)
##
## Residuals:
## Min 1Q Median 3Q Max
## -1.5353 -0.3633 -0.1453 0.3592 1.7827
##
## Coefficients:
## Estimate Std. Error
## (Intercept) 11.6933 0.5363
## as.factor(speed)11 -0.3233 0.7584
## as.factor(time)11 -0.5860 0.7584
## as.factor(temp)143 -0.2167 0.7584
## as.factor(speed)11:as.factor(time)11 0.5093 1.0725
## as.factor(speed)11:as.factor(temp)143 1.0767 1.0725
## as.factor(time)11:as.factor(temp)143 0.1827 1.0725
## as.factor(speed)11:as.factor(time)11:as.factor(temp)143 -1.0493 1.5168
## t value Pr(>|t|)
## (Intercept) 21.805 2.51e-13 ***
## as.factor(speed)11 -0.426 0.676
## as.factor(time)11 -0.773 0.451
## as.factor(temp)143 -0.286 0.779
## as.factor(speed)11:as.factor(time)11 0.475 0.641
## as.factor(speed)11:as.factor(temp)143 1.004 0.330
## as.factor(time)11:as.factor(temp)143 0.170 0.867
## as.factor(speed)11:as.factor(time)11:as.factor(temp)143 -0.692 0.499
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 0.9288 on 16 degrees of freedom
## Multiple R-squared: 0.1763, Adjusted R-squared: -0.1841
## F-statistic: 0.4891 on 7 and 16 DF, p-value: 0.8288
Model 0, without any interactions
summary(lm0)
##
## Call:
## lm(formula = Y ~ as.factor(speed) + as.factor(time) + as.factor(temp),
## data = data_long)
##
## Residuals:
## Min 1Q Median 3Q Max
## -1.43917 -0.43733 -0.04083 0.31567 1.87883
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 11.5135 0.3518 32.730 <2e-16 ***
## as.factor(speed)11 0.2073 0.3518 0.589 0.562
## as.factor(time)11 -0.5023 0.3518 -1.428 0.169
## as.factor(temp)143 0.1507 0.3518 0.428 0.673
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 0.8617 on 20 degrees of freedom
## Multiple R-squared: 0.1139, Adjusted R-squared: -0.01905
## F-statistic: 0.8567 on 3 and 20 DF, p-value: 0.4796
anova(lm0,lm1)
## Analysis of Variance Table
##
## Model 1: Y ~ as.factor(speed) + as.factor(time) + as.factor(temp)
## Model 2: Y ~ as.factor(speed) * as.factor(time) * as.factor(temp)
## Res.Df RSS Df Sum of Sq F Pr(>F)
## 1 20 14.850
## 2 16 13.804 4 1.0458 0.303 0.8717
plot(data_wu$y1,type = "l",ylim = c(9,13))
lines(data_wu$y2,col=2)
lines(data_wu$y3,col=3)
