Skip to content

Festus7-tech/Simulating-Nonlinear-Immune-Dynamics-Using-a-Lorenz-Attractor-Framework-in-R

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 

Repository files navigation

Simulating-Nonlinear-Immune-Dynamics Using a Lorenz-Attractor-Framework in R

This model uses a Lorenz attractor framework to simulate how pathogen levels, immune response, and cytokine activity interact through nonlinear feedback loops. It helps illustrate how small changes in immune regulation can lead to stable recovery or chaotic and uncontrolled inflammation.

Introduction

This project explores how nonlinear dynamics can describe complex interactions within the human immune system. Using a Lorenz-like mathematical model, it simulates the interplay between pathogen load, immune response and cytokine activity over time. The model demonstrates how small changes in immune regulation can lead to drastically different outcomes ; from controlled recovery to chaotic inflammation or cytokine storms. Implemented in R with the deSolve package for solving differential equations and plotly for interactive 3D visualization, this simulation provides insight into the dynamic and sometimes unpredictable nature of disease progression. The resulting butterfly-like pattern is characteristic of a chaotic system, indicating that the system may ascillate between low and high immunity.

The Code

#Lorenz attractor in Disease Progression and Immune Dynamic #Loading libraries library(deSolve) # Handling Ordinary differential Equations library(plotly) # Interactive and 3D visualizations

Parameters with sample data

sigma <- 10 # Immune activation rate beta <- 8/3 # Cytokine decay rate rho <- 28 # Pathogen growth rate

Lorenz-like immune system equations

immune_dynamics <- function(t, state, parameters) { with(as.list(c(state, parameters)), { dx <- sigma * (y - x) # Pathogen-immune activation feedback dy <- x * (rho - z) - y # Immune cell regulation dz <- x * y - beta * z # Cytokine-inflammation feedback list(c(dx, dy, dz)) }) }

Initial conditions and parameters

state <- c(x = 1, y = 1, z = 1) # Initial mild infection parameters <- c(sigma = sigma, beta = beta, rho = rho) #Creating sequence of times increasing by 0.01 steps times <- seq(0, 50, by = 0.01) # Start by 0 and ends with 50

Solve the system with Ordinary Differential Equation

out <- ode(y = state, times = times, func = immune_dynamics, parms = parameters) out <- as.data.frame(out) # Converting the data to dataframe

Plot 3D attractor (immune-pathogen-cytokine space)

fig <- plot_ly(out, x = ~x, y = ~y, z = ~z, type = "scatter3d", mode = "lines", line = list(color = 'teal', width = 2)) %>% layout(title = "Lorenz-like Model of Immune and Disease Dynamics", scene = list( xaxis = list(title = "Pathogen (x)"), yaxis = list(title = "Immune Response (y)"), zaxis = list(title = "Cytokine Level (z)") )) print(fig) # Display of the plot

#The Plot image

About

This model uses a Lorenz attractor framework to simulate how pathogen levels, immune response, and cytokine activity interact through nonlinear feedback loops. It helps illustrate how small changes in immune regulation can lead to stable recovery or chaotic, uncontrolled inflammation.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors