Merge branch 'main' of https://github.com/Paul-Corbalan/Scan-Statistics-Project-4Y-INSA
This commit is contained in:
		
						commit
						d79a2eaf59
					
				@ -133,16 +133,9 @@ Hence, we can see that, in the dataset `x`, wihtout any irregularities, there ar
 | 
				
			|||||||
Now we will use another method using the uniform distribution in order to implement a Poisson Process.
 | 
					Now we will use another method using the uniform distribution in order to implement a Poisson Process.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
```{r}
 | 
					```{r}
 | 
				
			||||||
 | 
					 | 
				
			||||||
PoissonProcess <- function(lambda,T) {
 | 
					PoissonProcess <- function(lambda,T) {
 | 
				
			||||||
  return(sort(runif(rpois(1,lambda*T),0,T)))
 | 
					  return(sort(runif(rpois(1,lambda*T),0,T)))
 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
lambda0=2
 | 
					 | 
				
			||||||
lambda1=3
 | 
					 | 
				
			||||||
Ti=10
 | 
					 | 
				
			||||||
pp1=PoissonProcess(lambda0,Ti)
 | 
					pp1=PoissonProcess(lambda0,Ti)
 | 
				
			||||||
print(pp1)
 | 
					print(pp1)
 | 
				
			||||||
plot(c(0,pp1),0:length(pp1),type="s",xlab="time t",ylab="number of events by time t")
 | 
					plot(c(0,pp1),0:length(pp1),type="s",xlab="time t",ylab="number of events by time t")
 | 
				
			||||||
@ -164,9 +157,6 @@ ks.test(tbe1,pexp,lambda0, alternative="two.sided")
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
ks.test(tbe2,pexp,lambda1, alternative="two.sided")
 | 
					ks.test(tbe2,pexp,lambda1, alternative="two.sided")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
```
 | 
					```
 | 
				
			||||||
The Kolmogorov-Smirnov test rejects the hypothesis that the time between events sequence is following an exponential distribution. 
 | 
					The Kolmogorov-Smirnov test rejects the hypothesis that the time between events sequence is following an exponential distribution. 
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -176,54 +166,73 @@ Je reprends votre code pour faire un data set :
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
```{r}
 | 
					```{r}
 | 
				
			||||||
 | 
					PoissonProcess <- function(lambda,T) {
 | 
				
			||||||
 | 
					  return(sort(runif(rpois(1,lambda*T),0,T)))
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
# Etape 1 : simu Poisson process sous H0
 | 
					# Etape 1 : simu Poisson process sous H0
 | 
				
			||||||
ppH0=PoissonProcess(lambda0,Ti)
 | 
					ppH0=PoissonProcess(lambda0,Ti)
 | 
				
			||||||
ppH0
 | 
					 | 
				
			||||||
length(ppH0)
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
# Etape 2 : creation d'un segment sous H1
 | 
					# Etape 2 : creation d'un segment sous H1
 | 
				
			||||||
tau= 2.5 # longeur de l'intervalle modifie, a fortiori tau < Ti
 | 
					tau= 3 # longeur de l'intervalle modifie, a fortiori tau < Ti
 | 
				
			||||||
ppH1.segt=PoissonProcess(lambda1,tau)
 | 
					ppH1.segt=PoissonProcess(lambda1,tau)
 | 
				
			||||||
ppH1.segt
 | 
					 | 
				
			||||||
length(ppH1.segt)
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
# Etape 3 : insertion du segment dans la sequence H0
 | 
					# Etape 3 : insertion du segment dans la sequence H0
 | 
				
			||||||
dbt=runif(1,0,Ti-tau) # choix de l'indice de  temps ou va commencer le segment modifie
 | 
					dbt=runif(1,0,Ti-tau) # choix de l'indice de  temps ou va commencer le segment modifié
 | 
				
			||||||
dbt
 | 
					ppH0bis=PoissonProcess(lambda0,Ti)
 | 
				
			||||||
ppH1.repo=dbt+ppH1.segt # repositionnement des observations dans le temps
 | 
					ppH1.repo=dbt+ppH1.segt # repositionnement des observations dans le temps
 | 
				
			||||||
ppH1.repo
 | 
					ppH0_avant=ppH0bis[which(ppH0bis<ppH1.repo[1])]
 | 
				
			||||||
ppH0_avant=ppH0[which(ppH0<ppH1.repo[1])]
 | 
					ppH0_apres=ppH0bis[which(ppH0bis>ppH1.repo[length(ppH1.repo)])]
 | 
				
			||||||
ppH0_apres=ppH0[which(ppH0>ppH1.repo[length(ppH1.repo)])]
 | 
					 | 
				
			||||||
ppH1=c(ppH0_avant,ppH1.repo,ppH0_apres)
 | 
					ppH1=c(ppH0_avant,ppH1.repo,ppH0_apres)
 | 
				
			||||||
ppH1
 | 
					 | 
				
			||||||
length(ppH1)
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#time between events 
 | 
					#time between events 
 | 
				
			||||||
n1=length(ppH1)
 | 
					n1=length(ppH1)
 | 
				
			||||||
tbe1=ppH1[2:n1]-ppH1[1:n1-1]
 | 
					tbe1=ppH1[2:n1]-ppH1[1:n1-1]
 | 
				
			||||||
 | 
					tbe1=c(0,tbe1)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
n0=length(ppH0)
 | 
					n0=length(ppH0)
 | 
				
			||||||
tbe0=ppH0[2:n0]-ppH0[1:n0-1]
 | 
					tbe0=ppH0[2:n0]-ppH0[1:n0-1]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
tbe1=c(0,tbe1)
 | 
					 | 
				
			||||||
tbe1
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
list1=data.frame(ProcessusPoissonH1=ppH1,
 | 
					list1=data.frame(ProcessusPoissonH1=ppH1,
 | 
				
			||||||
         TimeBetweenEventH1=tbe1)
 | 
					         TimeBetweenEventH1=tbe1)
 | 
				
			||||||
list1
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
tbe0=c(0,tbe0)
 | 
					tbe0=c(0,tbe0)
 | 
				
			||||||
tbe0
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
list0=data.frame(ProcessusPoissonH0=ppH0,
 | 
					list0=data.frame(ProcessusPoissonH0=ppH0,
 | 
				
			||||||
         TimeBetweenEventH0=tbe0)
 | 
					         TimeBetweenEventH0=tbe0)
 | 
				
			||||||
list0
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
poisson=list0[,1]
 | 
					list0
 | 
				
			||||||
poisson
 | 
					list1
 | 
				
			||||||
```
 | 
					```
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					```{r}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					lambda=2
 | 
				
			||||||
 | 
					Tps=10
 | 
				
			||||||
 | 
					tau=1
 | 
				
			||||||
 | 
					pp=PoissonProcess(lambda,Tps)
 | 
				
			||||||
 | 
					pp
 | 
				
			||||||
 | 
					n=length(pp)
 | 
				
			||||||
 | 
					n
 | 
				
			||||||
 | 
					which(pp>(Tps-tau))
 | 
				
			||||||
 | 
					stop=n-length(which(pp>(Tps-tau)))
 | 
				
			||||||
 | 
					stop
 | 
				
			||||||
 | 
					ScanStat=0
 | 
				
			||||||
 | 
					for (i in (1:stop)) {
 | 
				
			||||||
 | 
					  cat('\n i=',i)
 | 
				
			||||||
 | 
					  cat('\t ppi=',pp[i])
 | 
				
			||||||
 | 
					  x=which((pp>=pp[i])&(pp<=(pp[i]+tau)))
 | 
				
			||||||
 | 
					  x
 | 
				
			||||||
 | 
					  cat('\t which=',x)
 | 
				
			||||||
 | 
					  scan=length(x)
 | 
				
			||||||
 | 
					  cat(' scan=',scan)
 | 
				
			||||||
 | 
					  if (scan>ScanStat) ScanStat=scan
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					ScanStat
 | 
				
			||||||
 | 
					```
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
Import data of rainfall in France every 3 hours.
 | 
					Import data of rainfall in France every 3 hours.
 | 
				
			||||||
```{r}
 | 
					```{r}
 | 
				
			||||||
Rain_Dataset = read.csv("data/synop.202202.csv", sep = ";")
 | 
					Rain_Dataset = read.csv("data/synop.202202.csv", sep = ";")
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user