From 633425e73e86401fff96b67aacf96470d9b96e61 Mon Sep 17 00:00:00 2001
From: BenMazin <92589195+BenMazin1@users.noreply.github.com>
Date: Tue, 26 Mar 2024 22:20:47 -0400
Subject: [PATCH 01/13] Initial commit
---
README.md | 2 ++
1 file changed, 2 insertions(+)
create mode 100644 README.md
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..c9b75db
--- /dev/null
+++ b/README.md
@@ -0,0 +1,2 @@
+# RP4-ABM-Hamster
+RP4 Code for Agent Based Hamster Model
From 3a00e3052c1118e07554b201037011e3c7a07292 Mon Sep 17 00:00:00 2001
From: BenMazin <92589195+BenMazin1@users.noreply.github.com>
Date: Tue, 26 Mar 2024 22:21:52 -0400
Subject: [PATCH 02/13] Add files via upload
---
Netlogo analysis.py | 98 +
RP4 Hamster Model final.html | 80653 ++++++++++++++++++++++++++++++++
RP4 Hamster Model final.nlogo | 702 +
3 files changed, 81453 insertions(+)
create mode 100644 Netlogo analysis.py
create mode 100644 RP4 Hamster Model final.html
create mode 100644 RP4 Hamster Model final.nlogo
diff --git a/Netlogo analysis.py b/Netlogo analysis.py
new file mode 100644
index 0000000..6f2673d
--- /dev/null
+++ b/Netlogo analysis.py
@@ -0,0 +1,98 @@
+# RP4 - Agent Based Model Analysis
+# Ben Mazin
+# 03/26/2024
+# School of Interdisciplinary Science, McMaster University
+
+# This script reads in the csv files from the Netlogo model and analyzes the data to determine if the chemo treatment is effective
+# It then saves the results to a csv file
+
+import pandas as pd
+from scipy import stats
+
+# Set the number of trials and initial hamsters
+number_of_trials = 20000
+initial_hamsters = 100
+
+# Create an empty DataFrame with 4 columns
+all_data = []
+
+# Function to read CSV with inconsistent rows
+def read_inconsistent_csv(file_path, delimiter=','):
+ with open(file_path, 'r') as file:
+ lines = file.readlines()
+
+ # Determine the maximum number of columns by checking all rows
+ max_columns = max(len(line.split(delimiter)) for line in lines)
+
+ # Split each line into columns and pad with None if they are too short
+ data = [line.strip().split(delimiter) + [None] * (max_columns - len(line.split(delimiter))) for line in lines]
+
+ # Convert the list of lists into a DataFrame
+ df = pd.DataFrame(data, columns=range(max_columns)) # Set index to match column numbers
+ return df
+
+# Run for number_of_trials
+for i in range(1, number_of_trials + 1):
+
+ # Read in the csv file
+ file_path = f'/Users/benmazin/Movies/netlogo output/world{i}.csv'
+ data = read_inconsistent_csv(file_path, delimiter=',')
+
+ # Get the value of ChemoWork
+ chemowork = data.iat[6, 5]
+ if chemowork != '"true"' and chemowork != '"false"':
+ chemowork = data.iat[6, 3]
+
+ # Clean up the data
+ data = data.iloc[18:]
+ data = data.reset_index(drop=True)
+
+ # Get the total dead and max percent infected
+ total_dead = initial_hamsters - int(data.iloc[-1, 9].replace('"', ''))
+ max_percent_infect = int(data.iloc[2:, 1].str.replace('"', '').astype(int).max())
+
+ # Append the data to the proper list
+ if chemowork == '"true"':
+ all_data.append({
+ 'Trial': i,
+ 'ChemoTotalDead': total_dead,
+ 'ChemoPercentInfect': max_percent_infect,
+ 'NoChemoTotalDead': None,
+ 'NoChemoPercentInfect': None
+ })
+
+ elif chemowork == '"false"':
+ all_data.append({
+ 'Trial': i,
+ 'ChemoTotalDead': None,
+ 'ChemoPercentInfect': None,
+ 'NoChemoTotalDead': total_dead,
+ 'NoChemoPercentInfect': max_percent_infect
+ })
+
+ else:
+ print("Error: ChemoWork is not true or false")
+ print(i)
+
+#save dataframe to csv
+results = pd.DataFrame(all_data)
+
+# get the mean for each data column
+chemo_total_dead_mean = results['ChemoTotalDead'].mean()
+chemo_percent_infect_mean = results['ChemoPercentInfect'].mean()
+no_chemo_total_dead_mean = results['NoChemoTotalDead'].mean()
+no_chemo_percent_infect_mean = results['NoChemoPercentInfect'].mean()
+
+# run a t-test to determine if the means are significantly different for total dead and percent infect
+totalDeadTtest = stats.ttest_ind(results['ChemoTotalDead'], results['NoChemoTotalDead'] , nan_policy='omit')
+percentInfectTtest = stats.ttest_ind(results['ChemoPercentInfect'], results['NoChemoPercentInfect'], nan_policy='omit')
+
+# create a new dataframe with the means and t-test results
+resultSum = pd.DataFrame({
+ 'Category': ['ChemoTotalDeadMean', 'ChemoPercentInfectMean', 'NoChemoTotalDeadMean', 'NoChemoPercentInfectMean', 'TotalDeadTtest', 'PercentInfectTtest'],
+ 'Value': [chemo_total_dead_mean, chemo_percent_infect_mean, no_chemo_total_dead_mean, no_chemo_percent_infect_mean, totalDeadTtest, percentInfectTtest]
+})
+
+# save the summary and results to csv
+resultSum.to_csv('/Users/benmazin/Movies/netlogo results/summary.csv', index=False)
+results.to_csv('/Users/benmazin/Movies/netlogo results/results.csv', index=False)
\ No newline at end of file
diff --git a/RP4 Hamster Model final.html b/RP4 Hamster Model final.html
new file mode 100644
index 0000000..3b140bf
--- /dev/null
+++ b/RP4 Hamster Model final.html
@@ -0,0 +1,80653 @@
+
Welcome to the GitHub Repository for the Hamster Agent Based Model Group
-
This is a collection of our model and analysis code. Feel free to explore the files listed below:
+
Hamster Agent Based Model (ABM) Project
+
Welcome to the official repository of the RP4 Hamster Agent Based Model (ABM) Group. Here you will find our interactive model and analysis code used in this iSci Project. Dive into the links below to explore our work.
Welcome to the official repository of the RP4 Hamster Agent Based Model (ABM) Group. Here you will find our interactive model and analysis code used in this iSci Project. Dive into the links below to explore our work.