Complexity Explorer Santa Few Institute

Introduction to Agent-Based Modeling

Lead instructor:

This course is no longer in session.

Unit 6: Analyzing Agent-Based Models

Jerson Lizarazo
09 Aug 2024 8:17pm UTC
2
in 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

Jerson Lizarazo
09 Aug 2024 8:33pm UTC
in Unit 6: Analyzing Agent-Based Models

Or perhaps include a specific unit only to explain R if it is that necessary for ABM

Kasia Samson
12 Aug 2024 5:29am UTC
in Unit 6: Analyzing Agent-Based Models

Hi Jerson, thank you for the feedback, I've added it to my notes from this edition of the course.

Ananya Anandharaman
04 Aug 2024 2:16pm UTC
in Unit 6: Analyzing Agent-Based Models

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)

Alexander Tolley
17 Jul 2024 8pm UTC
1
in Unit 6: Analyzing Agent-Based Models

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.

Senerath de Silva
19 Jul 2024 3:47am UTC
in Unit 6: Analyzing Agent-Based Models

Alternative is to manually save plots: click on Export, then Save as Image to any location with a chosen name.

Alexander Tolley
16 Jul 2024 5:51pm UTC
7
in Unit 6: Analyzing Agent-Based Models

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.

Peter Muller
17 Jul 2024 3:17pm UTC
in Unit 6: Analyzing Agent-Based Models

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.

Alexander Tolley
17 Jul 2024 4:52pm UTC
in Unit 6: Analyzing Agent-Based Models

@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 NA

First 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
>

Peter Muller
17 Jul 2024 5pm UTC
in Unit 6: Analyzing Agent-Based Models

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.

Alexander Tolley
17 Jul 2024 5:34pm UTC
in Unit 6: Analyzing Agent-Based Models

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?

Peter Muller
17 Jul 2024 5:49pm UTC
in Unit 6: Analyzing Agent-Based Models

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?

Alexander Tolley
17 Jul 2024 7:52pm UTC
in Unit 6: Analyzing Agent-Based Models

@Peter,
Thank you. It does generate the summarized data. I now see that the instructor had the same warnings in his run of R.

Peter Muller
18 Jul 2024 1:40pm UTC
in Unit 6: Analyzing Agent-Based Models

No problem, I spent a lot of time troubleshooting, too.