#Add libraryR...
library(languageR)

#Question 1:
warl.xtabs = xtabs(~ AnimacyOfSubject + WordOrder + AgeGroup, data = warlpiri)
mosaicplot(warl.xtabs)

#Question 2:
#~logarithmically transformed DF
heid.exp = aggregate(exp(heid$RT), list(heid$Word, exp(heid$BaseFrequency)), mean)
colnames(heid.exp) = c("Word", "BaseFrequency", "MeanRT")
#logarithmically transformed DF
heid.log = aggregate(heid$RT, list(heid$Word, heid$BaseFrequency), mean)
colnames(heid.log) = c("Word", "BaseFrequency", "MeanRT")
#Set window to one row, two col plot
par(mfrow = c(1, 2))
#Scatter plots
plot(heid.exp$BaseFrequency, heid.exp$MeanRT, xlab = "Base Frequency", ylab = "MeanRT", main = "exp")
plot(heid.log$BaseFrequency, heid.log$MeanRT, xlab = "BaseFrequency", ylab = "MeanRT", main = "log")

#Question 3:
#Create word frequency table
moby.table = table(moby)
#Sort words by frequency, descending order
moby.table = sort(moby.table, decreasing = T)
#Create rank vector (from one to the number of words in moby.table)
ranks = 1:length(moby.table)
par(mfrow = c(1,1)) #Reset plot window
#Plot log freq vs log rank
plot(log(ranks), log(moby.table), xlab = "Rank", ylab = "Log Frequency")
#Question 4
xylowess.fnc(RT ~ Trial | Subject, data = lexdec, xlab = "Trial Number", ylab = "RT", main = "Trial Fatigue | Learning")

summary(cars)
##      speed           dist       
##  Min.   : 4.0   Min.   :  2.00  
##  1st Qu.:12.0   1st Qu.: 26.00  
##  Median :15.0   Median : 36.00  
##  Mean   :15.4   Mean   : 42.98  
##  3rd Qu.:19.0   3rd Qu.: 56.00  
##  Max.   :25.0   Max.   :120.00