Unit 6: Analyzing Agent-Based Models
A message to the creators of this magnificent course: Perhaps it would be more useful if the data analysis is explained using excel. Not everybody has a background using R, perhaps it may seem easy for the people that have used it before, but for people who hasn't used it in a while or never used it at all, this explanations using R get more and more confusing to the point where you just decide to skip them. I think it is something that can be improved... besides this, I'm enjoying this course and learning a lot
Or perhaps include a specific unit only to explain R if it is that necessary for ABM
Hi Jerson, thank you for the feedback, I've added it to my notes from this edition of the course.
Hi, can someone please explain why in the Summary Graphs video, while calculating the number of runs for the standard error section, the following formula is used:
nruns = nrow(data) / nrow(agg.sd)
The quartz.save method in R is for macOS (and *nix?). It does not work for Windows.
Instead, use:
dev.copy(png,"path/filename.png")
dev.off()This will generate files of the chart images in the R Gui.
The more tedious way is to do each chart, a right mouse click in the chart, copy the image as a bitmap, and paste it into any application that can handle images, e.g. MS Paint, MS Word, etc.
The ultimate fallback is a screen/windows capture and edit in a graphics application like MS Paint.
Alternative is to manually save plots: click on Export, then Save as Image to any location with a chosen name.
Rather than trying to enter the script from the video, please just put the script in a text file so that the needed changes can be made from macOS to Windows. The video with overlapping screens makes this extremely difficult and frustratingly time-wasting.
Otherwise, the only way to do the analysis is to stick with a spreadsheet.
Below the video, there is a link to download the .R file used in the video. Using that, you basically only need to change the file paths to match your computer.
@Peter
I reinstalled R v4.4.1 (replacing v4.4.0)
I added the Hmisc package.
Note this is running on Windows 10, 64bit.But I still get errors starting with the aggregating data.
The following shows the 1st error warning, followed by the top of csv file and then the R head(data) output.
Can you help me find why this is not working?
## aggregate the data by num.people, once to compute mean, and once to compute sd
> agg.mean <- aggregate(data, by = list(init.num.people = data$num.people), FUN = mean)
Warning message:
In mean.default(X[[i]], ...) :
argument is not numeric or logical: returning NAFirst lines of csv file:
"BehaviorSpace results (NetLogo 6.4.0)","Table version 2.0"
"Spread of Disease.nlogo"
"Spread of Disease population-density"
"07/17/2024 09:19:23:479 -0700"
"min-pxcor","max-pxcor","min-pycor","max-pycor"
"-20","20","-20","20"
"[run number]","disease-decay","num-infected","connections-per-node","variant","num-people","[step]","ticks"
"4","10","3","1.2","mobile","50","309","309"
"2","10","3","1.2","mobile","50","210","210"
"5","10","3","1.2","mobile","50","278","278"
"1","10","3","1.2","mobile","50","358","358"
"7","10","3","1.2","mobile","50","318","318"
"3","10","3","1.2","mobile","50","306","306"
"6","10","3","1.2","mobile","50","272","272"
"10","10","3","1.2","mobile","50","366","366"
"9","10","3","1.2","mobile","50","298","298"
"11","10","3","1.2","mobile","50","337","337"
"8","10","3","1.2","mobile","50","321","321"
"12","10","3","1.2","mobile","50","419","419"
"14","10","3","1.2","mobile","50","269","269"
"13","10","3","1.2","mobile","50","291","291"R data :
head(data)
run variant degree num.people init.num.infected disease.decay step last.tick
1 4 10 3 1.2 mobile 50 309 309
2 2 10 3 1.2 mobile 50 210 210
3 5 10 3 1.2 mobile 50 278 278
4 1 10 3 1.2 mobile 50 358 358
5 7 10 3 1.2 mobile 50 318 318
6 3 10 3 1.2 mobile 50 306 306
>Those warnings are okay. It is because some of the data can't have a mean, such as "variant." He mentions this briefly in the videos. Everything else should work out. If you run all the lines of the R code, you should still get the plots and output as desired.
Addendum.
It looked liked the headers in the R data were incorrectly ordered, so I changed the order
FROM:
colnames(data) <- c("run", "variant", "degree", "num.people", "init.num.infected", "disease.decay", "step", "last.tick")TO:
colnames(data) <- c("run","disease.decay", "init.num.infected", "degree", "variant", "num.people", "step", "last.tick")This looks like the headers match the data columns:
head(data)
run disease.decay init.num.infected degree variant num.people step last.tick
1 4 10 3 1.2 mobile 50 309 309
2 2 10 3 1.2 mobile 50 210 210
3 5 10 3 1.2 mobile 50 278 278
4 1 10 3 1.2 mobile 50 358 358
5 7 10 3 1.2 mobile 50 318 318
6 3 10 3 1.2 mobile 50 306 306
>However, the same error appears indicating that the data in num.people is not numeric?
The warning you reported "Warning message:
In mean.default(X[[i]], ...) :
argument is not numeric or logical: returning NA" is not necessarily referring to num.people.
Run the next couple of lines. When you run cbind, do you still get an error or do you see a table that gives the means and sd for the various values of num.people?@Peter,
Thank you. It does generate the summarized data. I now see that the instructor had the same warnings in his run of R.No problem, I spent a lot of time troubleshooting, too.
Subforums
- Introduce Yourself
- Class Announcements
- Study Groups and Meetups
- Technical Issues
- General Discussion
- Course Feedback
- Course Materials to Share
- Unit 1: What is Agent-Based Modeling and Why Should You Use It?
- Unit 2: Building a Simple Model
- Unit 3: Extending Models
- Unit 4: Creating Agent-Based Models
- Unit 5: The Components of an Agent-Based Model
- Unit 6: Analyzing Agent-Based Models
- Unit 7: Verification, Validation, and Replication
- Unit 8: History of ABM and Classic Models
- Unit 9: Advanced ABM