Skip to main content

Simulation de maladie (Petit exemple avec r)

Dans une population la probabilité de loccurrence d'une maladie (Y) depend du sexe  (S) et de la presence d'une mutation (M). en plus on sait qe sexe et mutation sont des fcteurs independants,

P(S=M) = 0.5
P(M=1) = 0.25,

on note      M = 1 quand la maladie est presente sinon M=0
                  Y = 1 si l'individu est malade Y=0 sinon
                   S = 1 si ll'individu est un male S=0 sinon

On suppose que la facon dont  probabilite de la maladie est relie aux autres variable peut s'ecrire

Logit(P(Y=1/ S=m,M=1) ) = log(1.1) + log(1.5) * s + log(2) * m

logit(p) = $\quad \log { \frac { p }{ 1-p }  } $

Nous allons coder sur r et obtenir un echantillon aleatoir de 1000 000  (Si. Mi. Yi )
 Nous allons obtenir des graphiques et verifier les resultats theoriques avec ca


CODE

set.seed(100)


n = 1000000

# le vecteur (1,0) est cree pour nous permettre de tirer ces valeurs
# On cree la matrice M avec 3 colonnes et n lignes

x = c(1,0)
M =  matrix (nrow = n, ncol = 3)






# on genere les valeurs de S  et m a l'aide la loi binomiale


s = rbinom(n,1,0.5)
m = rbinom(n,1,0.25)
#sachant ces 2 valeur on genere p et y


logit = log(1.1) + log(1.5) * s + log(2) * m

# p est la probabilite d etre malade sachant le sexe et m

p = exp(logit) / (1 + exp(logit))

y =  rbinom(n,1,p)


# bij  on cherce les lignes de M dont s = i et m = j
M= as.matrix(cbind(s,m,y))
b11 =which( M[,1] ==1 & M[,2] == 1 )
b10 =which( M[,1] ==1 & M[,2] == 0 )
b00 =which( M[,1] ==0 & M[,2] == 0 )
b01 =which( M[,1] ==0 & M[,2] == 1 )


# Mij sous matrice de M dont s = i et m = j

M11 = as.matrix(M [b11,])
M10 =as.matrix(M [b10,])
M00 =as.matrix(M [b00,])
M01 =as.matrix(M [b01,])

# on fait la somme des colonnes de nos sous matrices

nb11 = as.matrix(colSums(M11))
nb10 = as.matrix(colSums(M10))
nb00 = as.matrix(colSums(M00))
nb01 = as.matrix(colSums(M01))

# nbobsij donne le nombre de non malade dans chaque Mij

nbObs11 = length(M11[ ,3]) - nb11
nbObs10 = length(M10[ ,3]) - nb10
nbObs00 = length(M00[ ,3]) - nb00
nbObs01 = length(M01[ ,3]) - nb01

# proba est un vecteur qui donne la probabilite de tombe mlade ou pas sachant le couple s et m


proba = c(nb11[3,] /125710 ,nb10[3,] /374533,nb00[3,] /374804,nb01[3,] /124953,
          nbObs11[3,1]  /125710, nbObs10[3,1]  /374533,nbObs00[3,1]  /374804,nbObs01[3,1]  /124953)

#   SiMj est le label y = 1 / s=i,m=j, no est y = 0

classe = c("S1M1","S1M0","S2M0","S2M1","noS1M1","noS1M0","noS2M0","noS2M1")

barplot(proba,names.arg = classe)


proba
        y         y         y         y         y         y         y         y
0.7658818 0.6223964 0.5245355 0.6868823 0.2341182 0.3776036 0.4754645 0.3131177


Comments

Popular posts from this blog

FastAPI Instrumentalisation with prometheus and grafana Part1 [Counter]

welcome to this hands-on lab on API instrumentation using Prometheus and FastAPI! In the world of modern software development, real-time API monitoring is essential for understanding usage patterns, debugging issues, and ensuring optimal performance. In this lab, we’ll demonstrate how to enhance a FastAPI-based application with Prometheus metrics to monitor its behavior effectively. We’ve already set up the lab environment for you, complete with Grafana, Prometheus, and a PostgreSQL database. While FastAPI’s integration with databases is outside the scope of this lab, our focus will be entirely on instrumentation and monitoring. For those interested in exploring the database integration or testing , you can review the code in our repository: FastAPI Monitoring Repository . What You’ll Learn In this lab, we’ll walk you through: Setting up Prometheus metrics in a FastAPI application. Instrumenting API endpoints to track: Number of requests HTTP methods Request paths Using Grafana to vi...

Join Ubuntu 20.04 to Active Directory with SSSD and SSH Access

Join Ubuntu 20.04 to Active Directory with SSSD and SSH Access  Overview This guide walks you through joining an Ubuntu 20.04 machine to an Active Directory domain using SSSD, configuring PAM for AD user logins over SSH, and enabling automatic creation of home directories upon first login. We’ll also cover troubleshooting steps and verification commands. Environment Used Component Value Ubuntu Client       ubuntu-client.bazboutey.local Active Directory FQDN   bazboutey.local Realm (Kerberos)   BAZBOUTEY.LOCAL AD Admin Account   Administrator Step 1: Prerequisites and Package Installation 1.1 Update system and install required packages bash sudo apt update sudo apt install realmd sssd libnss-sss libpam-sss adcli \ samba-common-bin oddjob oddjob-mkhomedir packagekit \ libpam-modules openssh-server Step 2: Test DNS and Kerberos Configuration Ensure that the client can resolve the AD domain and discover services. 2.1 Test domain name resol...

Observability with grafana and prometheus (SSO configutation with active directory)

How to Set Up Grafana Single Sign-On (SSO) with Active Directory (AD) Grafana is a powerful tool for monitoring and visualizing data. Integrating it with Active Directory (AD) for Single Sign-On (SSO) can streamline access and enhance security. This tutorial will guide you through the process of configuring Grafana with AD for SSO. Prerequisites Active Directory Domain : Ensure you have an AD domain set up. Domain: bazboutey.local AD Server IP: 192.168.170.212 Users: grafana (for binding AD) user1 (to demonstrate SSO) we will end up with a pattern like this below Grafana Installed : Install Grafana on your server. Grafana Server IP: 192.168.179.185 Administrator Privileges : Access to modify AD settings and Grafana configurations. Step 1: Configure AD for LDAP Integration Create a Service Account in AD: Open Active Directory Users and Computers. Create a user (e.g., grafana ). Assign this user a strong password (e.g., Grafana 123$ ) and ensure it doesn’t expire. Gather Required AD D...