21.6.12

Some simple statistics in R

so, I'm currently running a series of simulations of my ABM to try and identify why my agents are not doing what I expect them to do (hardly surprising really, seeing as my model seems to be getting more and more complicated each time I try to improve things).

Anyway, this has led me down the statistics route for the first time in a long time actually as without it I'm struggling to tell if any of my results are *actually* different from each other. I've done an initial 30 runs of each set of parameter settings, taking 30 to be enough of a sample size to allow me to perform robust statistical analyses. *this is tedious by the way*

So I've had to re-learn R, as I tend to do each time I have some stats to do. It does get easier each time, but I tend to avoid using scripts so I struggle to remember how to do even the most simple of stats. Hence, the incentive to write this post as a reminder to me of how to do some simple functions in R.


data <- read.table("testSimulations.txt", header = T)
attach(data)
plot(data)
summary(data)

*this creates a single plot, over-writing one plot on top of the other onto the same axes*
par(mfrow=c(1,1))
plot(meanTerritory~pherValue, col = "green")
par(new = T)
plot(femaleTerritory~pherValue, axes = F, col = "red")

*this creates a side-by-side plot of individual graphs*
par(mfrow=c(1,2))
plot(meanTerritory~pherValuecol = "green")
plot(femaleTerritory~pherValuecol = "red")


*a simple linear model, the anova command gives a single p-value for the treatment, the summary command compares all separate groups to the first group*
territories <- lm(meanTerritory~pherValue)
anova(territories)
summary(territories)
plot(territories)

*a pairwise t-test analysis compares all groups to each other
tmales <- pairwise.t.test(maleTerritory, pherValue, p.adj="none")

some simple advice:
  • use .txt. files, rather than .csv files
  • use a script - in Mac, cmd-Enter runs a single line of the script
  • any statistical book should help with interpretation of the anova output

No comments:

Post a Comment