#Load libraries and functions
Here’s an overview of the packages we will need:
library(plyr) #for summary tables throughout
library(reshape2) #for other data wrangling
library(party) #for conditional inference trees
library(partykit) #for conditional inference trees
library(rpart) #for conditional inference trees
library(tidyverse) #for science
library(ggplot2) #for all plots
library(lme4) #for linear mixed regressions
library(lmerTest) #for pvalues from lmes
library(wesanderson) #for pleasing plot colors
library(cowplot) #for combining plots
library(plotly) #for interactive plots!
library(broom) #for tidy model outputs
library(ggdark) #convert themes to dark backgrounds
library(dplyr)
Most of this is for pretty plotting options
This takes 3 files. The repetitions, the item variables and the participant variables. We combine them into a single file with one row for every observation. This first section handles the import and merging the item variables
import <- read.csv("Libras movement repetition data - Movement data.csv")
item.vars <- read.csv("Libras movement repetition data - Item characteristics 6april.csv")
# head(item.vars)
item.vars <- subset(item.vars, select = -c(Sign))
# str(item.vars)
# str(import)
# item true has a space after it because of google spreadsheets stupidness
item.vars$item <- as.factor(item.vars$item)
import$item <- as.factor(import$item)
levels(item.vars$item)[levels(item.vars$item)=="true "] <- "true"
levels(import$item)[levels(import$item)=="true "] <- "true"
levels(item.vars$item)
levels(import$item)
# head(import)
# head(item.vars)
import2 <- merge(import, item.vars, by = "item")
# head(import2)
# str(import2)
# import2 <- subset(import2, select = -c(X))
# levels(import2$item)
# import2.trim <- subset(import2, !item %in% c("gold","glass","understand"))
# import2.trim$item <- factor(import2.trim$item)
# levels(import2.trim$item)
This section handles merging the participant variables
subj.vars <- read.csv("Libras movement repetition data - Signers charact.csv")
data_long <- melt(import2,
# ID variables - all the variables to keep but not split apart on
id.vars=c("item", "trial"),
# The source columns
measure.vars=c("Cristiane", "Daniel", "Cintia", "Cris", "Edu", "Erick","Felipe",
"Flor", "Karina", "Luiz", "Regiane" ,"Reinaldo"),
# Name of the destination column that will identify the original
# column that the measurement came from
variable.name="Signer",
value.name="repetitions")
data_long$trial <- as.factor(data_long$trial)
# str(data_long)
# head(data_long)
subj.vars <- subset(subj.vars, select = c("Signer","Gender", "Age", "Birth.place","Profession","Education","therapy2","Deaf.parents","Older.deaf.sibling","aoa"))
df0 <- merge(data_long, item.vars, by = "item")
# head(df0)
df <- merge(df0, subj.vars, by = "Signer")
# head(df)
#convert the strings to factors
df[sapply(df, is.character)] <- lapply(df[sapply(df, is.character)],as.factor)
# df
New motion column is now condenses into INTERNAL, PATH, or NONE movement based on Sandler
Note: DV: MovementTwo IV: repetitions
df$c.repetitions <- df$repetitions - mean(df$repetitions) #centered
df$z.repetitions <- df$c.repetitions / sd(df$repetitions) #standardized
df$Beats <- as.factor(df$Beats)
final <- subset(df, trial == "3")
# head(final)
summary(lm(z.repetitions~+MovementFour, final)) #main effect
##
## Call:
## lm(formula = z.repetitions ~ +MovementFour, data = final)
##
## Residuals:
## Min 1Q Median 3Q Max
## -1.6993 -0.3971 -0.3971 0.7051 2.9097
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 0.12288 0.07447 1.650 0.09941 .
## MovementFourhs -0.33298 0.14421 -2.309 0.02125 *
## MovementFournone -0.84966 0.25798 -3.294 0.00104 **
## MovementFouror 0.34446 0.11942 2.884 0.00405 **
## MovementFourpath -0.40660 0.08568 -4.746 2.53e-06 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 0.8556 on 679 degrees of freedom
## Multiple R-squared: 0.09552, Adjusted R-squared: 0.09019
## F-statistic: 17.93 on 4 and 679 DF, p-value: 5.27e-14
final.MovementFour <- final %>% mutate(MovementFour = fct_reorder(MovementFour, desc(repetitions)))
#Subset data frame based on number of rows per group
mov.final <- final.MovementFour[ave(final.MovementFour$repetitions, final.MovementFour$MovementFour, FUN = length) >25, ]
#rename HS.complexity
mov.final$MovementFour <- mapvalues(mov.final$MovementFour, from = c("or", "circular","hs","path"), to = c("ΔOrientation", "Circular","ΔHandshape", "Path"))
ggplot(mov.final,aes(x=MovementFour,y=repetitions,fill=MovementFour))+
# geom_flat_violin(aes(fill=Beats),position=position_nudge(x=.1,y=0),adjust=1.5,trim=T,alpha=.5,colour=NA)+
geom_point(aes(x=MovementFour,y=repetitions,colour=MovementFour),position=position_jitter(width=.2, height =.4),size=3,shape=20)+
geom_boxplot(aes(x=MovementFour,y=repetitions,fill=MovementFour),outlier.shape=NA,alpha=.5,width=.5,colour="white")+
# geom_line(data=df2,aes(x=as.numeric(Beats)+.1,y=repetitions,group=Beats,colour=Beats),linetype=4)+
scale_colour_brewer(palette="Accent")+
scale_fill_brewer(palette="Accent")+
# facet_wrap(~HS.complexity, nrow = 1, strip.position = "top") +
labs(title = "MovementFour", x="Movement type", y = "Number repetitions in 3rd trial", caption = "> 25 obs.") +
# coord_flip() +
dark_mode(theme_bw()) +
theme(text = element_text(size=16)) +
theme(legend.position = "none")
## Inverted geom defaults of fill and color/colour.
## To change them back, use invert_geom_defaults().
summary(lm(z.repetitions~MovementTwo, final)) #main effect
##
## Call:
## lm(formula = z.repetitions ~ MovementTwo, data = final)
##
## Residuals:
## Min 1Q Median 3Q Max
## -1.4544 -0.5135 -0.5135 0.5887 2.7933
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 0.22239 0.08499 2.617 0.009076 **
## MovementTwonone -0.94917 0.26876 -3.532 0.000441 ***
## MovementTwopath -0.38973 0.09277 -4.201 3.01e-05 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 0.8832 on 681 degrees of freedom
## Multiple R-squared: 0.03335, Adjusted R-squared: 0.03051
## F-statistic: 11.75 on 2 and 681 DF, p-value: 9.63e-06
final.MovementTwo <- final %>% mutate(MovementTwo = fct_reorder(MovementTwo, desc(repetitions)))
#Subset data frame based on number of rows per group
mov2.final <- final.MovementTwo[ave(final.MovementTwo$repetitions, final.MovementTwo$MovementTwo, FUN = length) >25, ]
# #rename
# mov.final$MovementTwo <- mapvalues(mov.final$MovementTwo, from = c("or", "circular","hs","path"), to = c("ΔOrientation", "Circular","ΔHandshape", "Path"))
ggplot(mov2.final,aes(x=MovementTwo,y=repetitions,fill=MovementTwo))+
# geom_flat_violin(aes(fill=Beats),position=position_nudge(x=.1,y=0),adjust=1.5,trim=T,alpha=.5,colour=NA)+
geom_point(aes(x=MovementTwo,y=repetitions,colour=MovementTwo),position=position_jitter(width=.2, height =.4),size=3,shape=20)+
geom_boxplot(aes(x=MovementTwo,y=repetitions,fill=MovementTwo),outlier.shape=NA,alpha=.5,width=.5,colour="white")+
# geom_line(data=df2,aes(x=as.numeric(Beats)+.1,y=repetitions,group=Beats,colour=Beats),linetype=4)+
scale_colour_brewer(palette="Accent")+
scale_fill_brewer(palette="Accent")+
# facet_wrap(~HS.complexity, nrow = 1, strip.position = "top") +
labs(title = "MovementTwo", x="Movement type", y = "Number repetitions in 3rd trial", caption = "> 25 obs.") +
# coord_flip() +
dark_mode(theme_bw()) +
theme(text = element_text(size=16)) +
theme(legend.position = "none")
one based on Wilbur and one based on heavy vs. light syllables a la Andre and Corrine’s understanding
Analysis 1: Wilbur DV: WilburSyllable IV: repetitions
levels(final$WilburSyllable)
## [1] "M" "P1" "P2" "z"
summary(lm(z.repetitions~WilburSyllable, final)) #main effect
##
## Call:
## lm(formula = z.repetitions ~ WilburSyllable, data = final)
##
## Residuals:
## Min 1Q Median 3Q Max
## -1.5769 -0.4133 -0.0201 0.1378 3.2867
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) -0.66077 0.04456 -14.829 <2e-16 ***
## WilburSyllableP1 0.94439 0.06920 13.648 <2e-16 ***
## WilburSyllableP2 1.00563 0.07185 13.997 <2e-16 ***
## WilburSyllablez -0.06602 0.22279 -0.296 0.767
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 0.7562 on 680 degrees of freedom
## Multiple R-squared: 0.2925, Adjusted R-squared: 0.2894
## F-statistic: 93.72 on 3 and 680 DF, p-value: < 2.2e-16
final.w.syl <- df %>% mutate(WilburSyllable = fct_reorder(WilburSyllable, desc(repetitions)))
w.syl.trim <- final.w.syl[ave(final.w.syl$repetitions, final.w.syl$WilburSyllable, FUN = length) >50, ]
ggplot(w.syl.trim,aes(x=WilburSyllable,y=repetitions,fill=WilburSyllable))+
# geom_flat_violin(aes(fill=Beats),position=position_nudge(x=.1,y=0),adjust=1.5,trim=T,alpha=.5,colour=NA)+
geom_point(aes(x=WilburSyllable,y=repetitions,colour=WilburSyllable),position=position_jitter(width=.2, height =.4),size=3,shape=20)+
geom_boxplot(aes(x=WilburSyllable,y=repetitions,fill=WilburSyllable),outlier.shape=NA,alpha=.5,width=.5,colour="white")+
# geom_line(data=df2,aes(x=as.numeric(Beats)+.1,y=repetitions,group=Beats,colour=Beats),linetype=4)+
scale_colour_brewer(palette="Accent")+
scale_fill_brewer(palette="Accent")+
facet_wrap(~trial, nrow = 1, strip.position = "top") +
labs(title = "", x="WilburSyllable", y = "Number repetitions in 3rd trial", caption = "> 50 obs.") +
# coord_flip() +
dark_mode(theme_bw()) +
theme(text = element_text(size=16)) +
theme(legend.position = "none")
Analysis 2: Syllable Weight DV: SyllableWeight IV: repetitions
final.s.w <- df %>% mutate(SyllableWeight = fct_reorder(WilburSyllable, desc(repetitions)))
s.w.trim <- final.w.syl[ave(final.w.syl$repetitions, final.w.syl$SyllableWeight, FUN = length) >50, ]
ggplot(s.w.trim,aes(x=SyllableWeight,y=repetitions,fill=SyllableWeight))+
# geom_flat_violin(aes(fill=Beats),position=position_nudge(x=.1,y=0),adjust=1.5,trim=T,alpha=.5,colour=NA)+
geom_point(aes(x=SyllableWeight,y=repetitions,colour=SyllableWeight),position=position_jitter(width=.2, height =.4),size=3,shape=20)+
geom_boxplot(aes(x=SyllableWeight,y=repetitions,fill=SyllableWeight),outlier.shape=NA,alpha=.5,width=.5,colour="white")+
# geom_line(data=df2,aes(x=as.numeric(Beats)+.1,y=repetitions,group=Beats,colour=Beats),linetype=4)+
scale_colour_brewer(palette="Set2")+
scale_fill_brewer(palette="Set2")+
facet_wrap(~trial, nrow = 1, strip.position = "top") +
labs(title = "", x="SyllableWeight", y = "Number repetitions in 3rd trial", caption = "> 50 obs.") +
# coord_flip() +
dark_mode(theme_bw()) +
theme(text = element_text(size=16)) +
theme(legend.position = "none")
# significant
syllableweight <- final
levels(syllableweight$SyllableWeight)
## [1] "MH" "ML" "PH" "PL"
sw.contr <- contrasts(syllableweight$SyllableWeight)
sw.contr <- contr.sum(4)
colnames(sw.contr) <- c("MH", "ML","PL") #intercept is PH
syllableweight[,"SyllableWeight"] <- C(syllableweight[,"SyllableWeight"],sw.contr)
summary(lm(z.repetitions~SyllableWeight, syllableweight)) #main effect
##
## Call:
## lm(formula = z.repetitions ~ SyllableWeight, data = syllableweight)
##
## Residuals:
## Min 1Q Median 3Q Max
## -1.5182 -0.4159 -0.0689 0.2196 3.2379
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) -0.21597 0.03207 -6.733 3.53e-11 ***
## SyllableWeightMH -0.52394 0.06830 -7.672 5.90e-14 ***
## SyllableWeightML -0.39600 0.05118 -7.737 3.67e-14 ***
## SyllableWeightPL 0.41779 0.05118 8.163 1.58e-15 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 0.7815 on 680 degrees of freedom
## Multiple R-squared: 0.2443, Adjusted R-squared: 0.241
## F-statistic: 73.27 on 3 and 680 DF, p-value: < 2.2e-16
#looks like PL does indeed get repeated less than PL
IV = SyllableMode DV = repetitions
df$SyllableMode <- as.factor(df$SyllableMode)
ggplot(df,aes(x=SyllableMode,y=repetitions,fill=SyllableMode))+
# geom_flat_violin(aes(fill=Beats),position=position_nudge(x=.1,y=0),adjust=1.5,trim=T,alpha=.5,colour=NA)+
geom_point(aes(x=SyllableMode,y=repetitions,colour=SyllableMode),position=position_jitter(width=.2, height =.4),size=3,shape=20)+
geom_boxplot(aes(x=SyllableMode,y=repetitions,fill=SyllableMode),outlier.shape=NA,alpha=.5,width=.5,colour="white")+
# geom_line(data=df2,aes(x=as.numeric(Beats)+.1,y=repetitions,group=Beats,colour=Beats),linetype=4)+
scale_colour_brewer(palette="Set2")+
scale_fill_brewer(palette="Set2")+
facet_wrap(~trial, nrow = 1, strip.position = "top") +
labs(title = "", x="SyllableMode", y = "Number repetitions in 3rd trial") +
# coord_flip() +
dark_mode(theme_bw()) +
theme(text = element_text(size=16)) +
theme(legend.position = "none")