Sung-en Chien
2016年12月12日
This presentation is to analyze the data in the manuscript “Identifying a role for executive function in the rubber hand illusion” with an hierarchical regression.
# settings
setwd("~/Dropbox/NTU exp/RHI/RHI_ANYI/Exp8_ACS&TS&MW") # switch directory to the file directory
library(xlsx)
# load and set data
data <- read.xlsx(file = "SwitchingRHI_n36.xlsx", sheetIndex = 3, header = TRUE)
mw.model <- lm(data$OnsetTime ~ data$Mind.Wandering, data=data)
mw.shift.model <- lm(data$OnsetTime ~ data$Mind.Wandering + data$Shift.Attention, data=data)
mw.shift.ts.model <- lm(data$OnsetTime ~ data$Mind.Wandering + data$Shift.Attention +
data$Switch.Cost, data=data)
mw.shift.ts.focus.model <- lm(data$OnsetTime ~ data$Mind.Wandering + data$Shift.Attention +
data$Switch.Cost+data$Focus.Attention, data=data)
summary(mw.model) # R square = 0.3859
##
## Call:
## lm(formula = data$OnsetTime ~ data$Mind.Wandering, data = data)
##
## Residuals:
## Min 1Q Median 3Q Max
## -100.10 -57.35 -14.98 48.14 127.68
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) -111.84 18.06 -6.194 4.83e-07 ***
## data$Mind.Wandering 98.68 36.98 2.668 0.0116 *
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 64.41 on 34 degrees of freedom
## Multiple R-squared: 0.1731, Adjusted R-squared: 0.1488
## F-statistic: 7.12 on 1 and 34 DF, p-value: 0.0116
summary(mw.shift.model) # R square = 0.3859
##
## Call:
## lm(formula = data$OnsetTime ~ data$Mind.Wandering + data$Shift.Attention,
## data = data)
##
## Residuals:
## Min 1Q Median 3Q Max
## -99.813 -53.434 0.479 37.229 104.579
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 51.09 70.38 0.726 0.473
## data$Mind.Wandering 59.75 38.32 1.559 0.128
## data$Shift.Attention -59.72 25.04 -2.385 0.023 *
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 60.38 on 33 degrees of freedom
## Multiple R-squared: 0.2947, Adjusted R-squared: 0.252
## F-statistic: 6.895 on 2 and 33 DF, p-value: 0.003147
summary(mw.shift.ts.model) # R square = 0.3859
##
## Call:
## lm(formula = data$OnsetTime ~ data$Mind.Wandering + data$Shift.Attention +
## data$Switch.Cost, data = data)
##
## Residuals:
## Min 1Q Median 3Q Max
## -112.877 -30.397 -2.512 35.169 119.799
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 1.347 70.489 0.019 0.9849
## data$Mind.Wandering 53.193 36.435 1.460 0.1541
## data$Shift.Attention -56.831 23.765 -2.391 0.0228 *
## data$Switch.Cost 99.999 45.886 2.179 0.0368 *
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 57.22 on 32 degrees of freedom
## Multiple R-squared: 0.3859, Adjusted R-squared: 0.3283
## F-statistic: 6.702 on 3 and 32 DF, p-value: 0.001227
summary(mw.shift.ts.focus.model)
##
## Call:
## lm(formula = data$OnsetTime ~ data$Mind.Wandering + data$Shift.Attention +
## data$Switch.Cost + data$Focus.Attention, data = data)
##
## Residuals:
## Min 1Q Median 3Q Max
## -115.68 -26.48 -11.11 33.55 125.90
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) -79.48 78.97 -1.007 0.3220
## data$Mind.Wandering 55.98 34.92 1.603 0.1191
## data$Shift.Attention -64.04 23.05 -2.778 0.0092 **
## data$Switch.Cost 89.60 44.26 2.024 0.0516 .
## data$Focus.Attention 37.91 19.22 1.973 0.0575 .
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 54.8 on 31 degrees of freedom
## Multiple R-squared: 0.4544, Adjusted R-squared: 0.384
## F-statistic: 6.454 on 4 and 31 DF, p-value: 0.0006721
anova(mw.model, mw.shift.model, mw.shift.ts.model, mw.shift.ts.focus.model)
## Analysis of Variance Table
##
## Model 1: data$OnsetTime ~ data$Mind.Wandering
## Model 2: data$OnsetTime ~ data$Mind.Wandering + data$Shift.Attention
## Model 3: data$OnsetTime ~ data$Mind.Wandering + data$Shift.Attention +
## data$Switch.Cost
## Model 4: data$OnsetTime ~ data$Mind.Wandering + data$Shift.Attention +
## data$Switch.Cost + data$Focus.Attention
## Res.Df RSS Df Sum of Sq F Pr(>F)
## 1 34 141072
## 2 33 120329 1 20743 6.9076 0.01323 *
## 3 32 104778 1 15550 5.1783 0.02993 *
## 4 31 93093 1 11685 3.8912 0.05752 .
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
mw.model2 <- lm(data$Ques.RHI ~ data$Mind.Wandering , data=data)
mw.shift.model2 <- lm(data$Ques.RHI ~ data$Mind.Wandering + data$Shift.Attention , data=data)
mw.shift.ts.model2 <- lm(data$Ques.RHI ~ data$Mind.Wandering + data$Shift.Attention
+data$Switch.Cost, data=data)
mw.shift.ts.focus.model2 <- lm(data$Ques.RHI ~ data$Mind.Wandering + data$Shift.Attention
+data$Switch.Cost+data$Focus.Attention, data=data)
summary(mw.model2) # mind wandering is negatively related to RHI , R suare =0.1217
##
## Call:
## lm(formula = data$Ques.RHI ~ data$Mind.Wandering, data = data)
##
## Residuals:
## Min 1Q Median 3Q Max
## -3.4827 -1.0193 0.2091 1.0258 3.9465
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 3.2358 0.4694 6.894 6.09e-08 ***
## data$Mind.Wandering -2.0864 0.9613 -2.170 0.037 *
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 1.674 on 34 degrees of freedom
## Multiple R-squared: 0.1217, Adjusted R-squared: 0.09586
## F-statistic: 4.711 on 1 and 34 DF, p-value: 0.03705
summary(mw.shift.model2) # R sqare =0.1705
##
## Call:
## lm(formula = data$Ques.RHI ~ data$Mind.Wandering + data$Shift.Attention,
## data = data)
##
## Residuals:
## Min 1Q Median 3Q Max
## -3.2364 -1.3156 0.0329 1.0337 3.9419
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 0.6330 1.9250 0.329 0.744
## data$Mind.Wandering -1.4646 1.0481 -1.397 0.172
## data$Shift.Attention 0.9541 0.6849 1.393 0.173
##
## Residual standard error: 1.652 on 33 degrees of freedom
## Multiple R-squared: 0.1705, Adjusted R-squared: 0.1202
## F-statistic: 3.391 on 2 and 33 DF, p-value: 0.04578
summary(mw.shift.ts.model2) # R sqared = 0.2029
##
## Call:
## lm(formula = data$Ques.RHI ~ data$Mind.Wandering + data$Shift.Attention +
## data$Switch.Cost, data = data)
##
## Residuals:
## Min 1Q Median 3Q Max
## -3.6100 -1.0424 0.0756 0.8746 4.1383
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 1.3810 2.0255 0.682 0.500
## data$Mind.Wandering -1.3660 1.0469 -1.305 0.201
## data$Shift.Attention 0.9106 0.6829 1.333 0.192
## data$Switch.Cost -1.5036 1.3185 -1.140 0.263
##
## Residual standard error: 1.644 on 32 degrees of freedom
## Multiple R-squared: 0.2029, Adjusted R-squared: 0.1281
## F-statistic: 2.715 on 3 and 32 DF, p-value: 0.06112
summary(mw.shift.ts.focus.model2) #R sqared = 0.2987
##
## Call:
## lm(formula = data$Ques.RHI ~ data$Mind.Wandering + data$Shift.Attention +
## data$Switch.Cost + data$Focus.Attention, data = data)
##
## Residuals:
## Min 1Q Median 3Q Max
## -2.7666 -0.8308 -0.0165 0.7380 4.2218
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 3.7923 2.2580 1.679 0.1031
## data$Mind.Wandering -1.4491 0.9985 -1.451 0.1568
## data$Shift.Attention 1.1257 0.6591 1.708 0.0977 .
## data$Switch.Cost -1.1933 1.2655 -0.943 0.3530
## data$Focus.Attention -1.1309 0.5495 -2.058 0.0481 *
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 1.567 on 31 degrees of freedom
## Multiple R-squared: 0.2987, Adjusted R-squared: 0.2082
## F-statistic: 3.301 on 4 and 31 DF, p-value: 0.02302
anova(mw.model2,mw.shift.model2,mw.shift.ts.model2,mw.shift.ts.focus.model2)
## Analysis of Variance Table
##
## Model 1: data$Ques.RHI ~ data$Mind.Wandering
## Model 2: data$Ques.RHI ~ data$Mind.Wandering + data$Shift.Attention
## Model 3: data$Ques.RHI ~ data$Mind.Wandering + data$Shift.Attention +
## data$Switch.Cost
## Model 4: data$Ques.RHI ~ data$Mind.Wandering + data$Shift.Attention +
## data$Switch.Cost + data$Focus.Attention
## Res.Df RSS Df Sum of Sq F Pr(>F)
## 1 34 95.321
## 2 33 90.027 1 5.2936 2.1560 0.15208
## 3 32 86.511 1 3.5159 1.4320 0.24051
## 4 31 76.113 1 10.3983 4.2351 0.04809 *
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
RHIcor <- lm(data$Ques.RHI ~ data$OnsetTime, data=data) # fit linear model
plot(data$OnsetTime, data$Ques.RHI, xlab = "onset time", ylab = "RHI", xlim=c(-200,100), ylim = c(-3,7))
abline(RHIcor, col = "black")
cor(data$OnsetTime, data$Ques.RHI)
## [1] -0.7312217
comments from JEPHP reviewers in data analysis