# Scripting assignment 1: # Your task: load one of Fritz Günther's vector spaces # based on English (not "EN_100k.rda"), load data containing lexical # decision times for compounds, and check whether you can find a # correlation between the lexical decision times and the similarities # between the modifier and the compound and the head and the compound. # Note: below, the task is illustrated with the help of "EN_100k.rda" :) # We will also save the end product, please have the corresponding while at hand on your computers. # 1. Use a vector space of your choice from Fritz Günther's page (not "EN_100k.rda"); Load the dataset load("~/dataTeaching/EN_100k.rda") # Note: depending on your computer, loading to many huge data objects can be problematic # You can use rm() to remove data objects # 2. Download the LaDEC dataset: # Large database of English compounds (https://doi.org/10.7939/r3-dyqx-9b36) # You need the file "LADECv1-2019.csv" # 3. Load the data into R: # Use either of the following two lines (thereby storing the data in a dataframe named "ladec") # (recall that the second line will lead you to a drop-down menu for file section, select "LADECv1-2019.csv" in that menu) # ladec <- read.csv("YOURPATH/LADECv1-2019.csv") # ladec <- read.csv(file.choose()) ladec <- read.csv("~/dataTeaching/LADECv1-2019.csv") # 4. Get acquainted with the structure of the ladec data. For this # scripting assignment, the important variables are "c1", "c2", # "stim" and "elp_ld_rt" (= the modifier, the head, the compound, # and the lexical decision time from the ELP database) (all # variables are described in the guide to the variables on the # website) str(ladec) head(ladec) dim(ladec) # for simplicity's sake, we exclude all rows that don't have a lexical decision value # [we use a condition for indexing: we select only those rows for which it is not the case that the variable "elp_ld_rt" is NA, that is, without value] ladecELP <- ladec[!is.na(ladec$elp_ld_rt),] # 5. Check how many of the compounds in the ladecELP dataframe are also in the vectorspace you chose. Create a smaller subset of the dataset # containing only the rows which also occur in your vectorspace (cf. the procedure in the handsOn session) dim(ladecELP[is.element(ladecELP$stim,row.names(EN_100k)),]) compoundSet <- ladecELP[is.element(ladecELP$stim,row.names(EN_100k)),] dim(compoundSet) ladecELP[is.element(ladecELP$stim,row.names(EN_100k)),4] ladecELP[is.element(ladecELP$stim,row.names(EN_100k)),"stim"] # 6. Do the same for the two constituents, starting with the smaller subset from step 5. # Excursion: something crazy? compoundModSet <- compoundSet[is.element(ladecELP$c1,compoundSet$c1),] dim(compoundModSet) testvector <- c("flip","flop","top") testvector[c(TRUE,TRUE,TRUE,TRUE,FALSE)] # [1] "flip" "flop" "top" NA # End of excursion compoundModSet <- compoundSet[is.element(compoundSet$c1,row.names(EN_100k)),] dim(compoundModSet) compoundModHeadSet <- compoundModSet[is.element(compoundModSet$c2,row.names(EN_100k)),] dim(compoundModHeadSet) # We can combine the last three steps into one # Alternative 1: use "&" operator: targetSet <- ladecELP[is.element(ladecELP$stim,row.names(EN_100k)) & is.element(ladecELP$c1,row.names(EN_100k)) & is.element(ladecELP$c2,row.names(EN_100k)),] dim(targetSet) # Alternative 2: use "&" operator and "%in%" operator: targetSetAlt <- ladecELP[ladecELP$stim %in% row.names(EN_100k) & ladecELP$c1 %in% row.names(EN_100k) & ladecELP$c2 %in% row.names(EN_100k),] dim(targetSetAlt) # Is everything really the same? all.equal(compoundModHeadSet,targetSet) all.equal(compoundModHeadSet,targetSetAlt) # 7. Do the pairwise computations in order to get the cosine # similarities between modifier/compound and head/compound. Add the # results to your dataset (as two new columns). library(LSAfun) compoundModHeadSet$simModCompound <- pairwise(compoundModHeadSet$stim, compoundModHeadSet$c1, tvectors = EN_100k) compoundModHeadSet$simHeadCompound <- pairwise(compoundModHeadSet$stim, compoundModHeadSet$c2, tvectors = EN_100k) # 8. Check the correlations between the new similarity values and the RTs cor.test(compoundModHeadSet$simModCompound,compoundModHeadSet$elp_ld_rt) cor.test(compoundModHeadSet$simHeadCompound,compoundModHeadSet$elp_ld_rt) # 9. Do some analysis of your results, and of the dataset. Did you expect these results? What do you think could be next steps in exploring the results? # Weird stuff? # what happens if we do the pairwise comparison without ensuring that all constituents have vectors? compoundSet$simModCompound <- pairwise(compoundSet$stim, compoundSet$c1, tvectors = EN_100k) compoundSet$simHeadCompound <- pairwise(compoundSet$stim, compoundSet$c2, tvectors = EN_100k) cor.test(compoundSet$simModCompound,compoundSet$elp_ld_rt) cor.test(compoundSet$simHeadCompound,compoundSet$elp_ld_rt) # cor.test() by default omits NAs # note: cor.test(compoundModHeadSet$simModCompound,compoundModHeadSet$elp_ld_rt,na.action="omit") compoundSet[is.na(compoundSet$simModCompound),c("c1","stim")] # check which items result in NAs; note also the result for the column "correctParse" compoundSet[is.na(compoundSet$simModCompound),c("c1","stim","correctParse")] # for further inspection, ordering of the data is often helpful. # Below, we order in ascending order by modifier-compound similarity compoundModHeadSetOrdered <- compoundModHeadSet[order(compoundModHeadSet$simModCompound),] head(compoundModHeadSetOrdered[,c("stim","simModCompound")]) tail(compoundModHeadSetOrdered[,c("stim","simModCompound")]) compoundModHeadSetOrdered <- compoundModHeadSet[order(compoundModHeadSet$simModCompound,decreasing=TRUE),] head(compoundModHeadSetOrdered[,c("stim","c1","c2","simModCompound","correctParse")]) tail(compoundModHeadSetOrdered[,c("stim","c1","c2","simModCompound","correctParse")]) # Other potential factors: fequency of the compound # What else? compound length etc. # Difference between vectorspaces # For exploring the difference across to vectorspaces, we can first # check whether the differences persist when using exactly the same # subset of the data. If not, then the reasons for the differences lie # in the individual lexical items included and might not be so # interesting. If they persist, we can try to see whether this is # linked either to the textual basis on which the vectors where # created or the actual algorhitm used to create them. # Let's get rid of the rows that are based on parses that are not correct dim(compoundModHeadSet[compoundModHeadSet$correctParse == "no",c("stim","c1","c2")]) targetSetSmall <- compoundModHeadSet[compoundModHeadSet$correctParse == "yes",] dim(targetSetSmall) # Let's get rid of some columns (= select only those that we need!) targetSetSmall[,c("stim","c1","c2","stim_SLlg10wf","elp_ld_rt","stimlen","simModCompound","simHeadCompound")] ourFavoriteSubset <- targetSet[,c("stim","c1","c2","stim_SLlg10wf","elp_ld_rt","stimlen","simModCompound","simHeadCompound")] # Maybe it would be a good idea to save the dataset now :) # With explicit reference to the folder and filename (syntax might differ depending on your operating system): write.csv(ourFavoriteSubset,file="/home/martin/dataTeaching/mySuperSubset.csv",row.names=FALSE) # by using file.choos(), note the parameter "new=TRUE" write.csv(ourFavoriteSubset,file=file.choose(new=TRUE),row.names=FALSE) # read it back in test <- read.csv(file="/home/martin/dataTeaching/mySuperSubset.csv") test <- read.csv(file.choose()) str(ourFavoriteSubset) str(test) # we can easily plot the ordered dataset (we can just as easily plot the unordered dataset) plot(compoundModHeadSetOrdered$simModCompound,compoundModHeadSetOrdered$elp_ld_rt) plot(compoundModHeadSet$simModCompound,compoundModHeadSet$elp_ld_rt) # let's label the points plot(compoundModHeadSetOrdered$simModCompound,compoundModHeadSetOrdered$elp_ld_rt) text(compoundModHeadSetOrdered$simModCompound,compoundModHeadSetOrdered$elp_ld_rt - 15,labels=compoundModHeadSetOrdered$stim) # We stopped here :)