T-test in R between Scores for Regions and Years

I'm currently trying to run (what I believe is) an independent samples t-test to determine whether there are significant differences between scores, however I'm a little new to R and am in the process of trying to figure out the landscape.

Essentially, I have a dataset (a sample for which I've provided in the code below), of regions by year and their respective test scores for which I'm trying to gauge levels of significant differences

data <- read.table(text = 
     "Province       Score  Year
370   Alberta       549    2003   
333   Alberta       517    2012
371   BC            538    2003
444   BC            522    2012
372   Ontario       530    2003
445   Ontario       514    2012
555   PEI           500    2003
373   PEI           479    2012"    
, stringsAsFactors=F, header = T)

So far, I've tried:

pairwise.t.test(data$Score,data$Province, p.adjust="bonferroni")

However I'm not seeing any significant p-values, and I'm getting the feeling I might be overlooking something. I've also tried consulting the literature but have come up short. Just wanted to explore and consult some forums to make sure I'm covering my bases for my specific purposes. For instance, I'd want to know if the mean scores of Alberta were significant from 2003 to 2012, but right now I believe it's giving me a crosstabs of each province compared against other provinces.

Something like:

Saskatchewan 2003
Saskatchewan 2012
p-value = x

Ontario 2003
Ontario 2012
p-value = x

Would be what I'm looking for.

Thanks in advance for any guidance!


I think graphing your data may help you with your feeling of overlooking something; maybe there just isn't much difference.

You can graph the test scores over time, with separate graphs for each province, for instance. If the test scores are already aggregated by province you could use a line graph, or if you're lucky and have data at a, for instance, district level, you could do box plots.

Seeing as you said you're fairly new to R, I would recommend checking out R for Data Science (a free online book). It starts right off after the introduction with data visualization.

Hello everyone, I'm new to R studio too, I can't download the introductory book you mentioned here. Can anyone help with useful materials pls. My email address should you want to send it: ap.sotayo@gmail.com

It's a web site consisting of the book's contents, not an ebook to download.

1 Like

Thanks @pete. Much appreciated! I've been perusing the online ebook you recommended, and so far it's proving extremely useful.

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.