Update LocaScoreMC and sub-functions

This commit is contained in:
Paul-Corbalan 2022-04-12 09:29:10 +02:00
parent 8b192f36eb
commit e93e8ed57c
1 changed files with 36 additions and 17 deletions

View File

@ -184,8 +184,8 @@ for (i in 1:NbSeqH0){
#cat(paste("\nSimulation for the sequence", i, ", for lambda0=",lambda0, " ,lambda1=", lambda1, " , scan=", result[1] ,"p-value=",result[2])) #cat(paste("\nSimulation for the sequence", i, ", for lambda0=",lambda0, " ,lambda1=", lambda1, " , scan=", result[1] ,"p-value=",result[2]))
#print(length(ppi)) #print(length(ppi))
} }
ScS_H0=data.frame(num=1:NbSeqH0, scan_stat=scan, pvalue_scan=pvalue, class=(pvalue<0.05), begin_scan=index_scan) #ScS_H0=data.frame(num=1:NbSeqH0, scan_stat=scan, pvalue_scan=pvalue, class=(pvalue<0.05), begin_scan=index_scan)
sum(ScS_H0$class[which(ScS_H0$class==TRUE)])/NbSeqH0 #sum(ScS_H0$class[which(ScS_H0$class==TRUE)])/NbSeqH0
``` ```
```{r} ```{r}
@ -255,10 +255,19 @@ ComputeE <- function(lambda0, lambda1){
} }
``` ```
for (i in 2:(n_sample)){
pp=PoissonProcess(lambda,T)
scan=rbind(scan,ScanStat(pp,T, tau)[2])
index=rbind(index,ScanStat(pp,T, tau)[1])
}
```{r} ```{r}
ScoreDistrib <- function(lambda0, lambda1, T){ ScoreDistrib <- function(lambda0, lambda1, NbSeq, T){
E = ComputeE(lambda0, lambda1) E = ComputeE(lambda0, lambda1)
for (i in 1:NbSeq) {
selected
}
ppH0 = PoissonProcess(lambda0,T) ppH0 = PoissonProcess(lambda0,T)
n1 = length(ppH0) n1 = length(ppH0)
tbe0 = ppH0[2:n1]-ppH0[1:n1-1] tbe0 = ppH0[2:n1]-ppH0[1:n1-1]
@ -280,43 +289,53 @@ ScoreDistrib <- function(lambda0, lambda1, T){
### Local score calculation ### Local score calculation
```{r} ```{r}
LocaScoreMC <- function(lambda0, lambda1, E, T){ LocaScoreMC <- function(lambda0, lambda1, NbSeq, tbe0, T){
E = ComputeE(lambda0, lambda1)
pvalue = c() pvalue = c()
X = c() X = c()
Score = ScoreDistrib(lambda0, lambda1, T) Score = ScoreDistrib(lambda0, lambda1, NbSeq, T)
xp = Score$X xp = Score$X
P_X = Score$P_X P_X = Score$P_X
NbSeqH0 = length(tbe0)
min_X = min(xp) min_X = min(xp)
max_X = max(xp) max_X = max(xp)
for (i in 1:NbSeqH0){ for (i in 1:NbSeq){
x = floor(E*log(dexp(tbe0[[i]], rate = lambda1)/dexp(tbe0[[i]], rate = lambda0))) x = floor(E*log(dexp(tbe0[[i]], rate = lambda1)/dexp(tbe0[[i]], rate = lambda0)))
X = c(X,x) X = c(X,x)
LS = localScoreC(x)$localScore[1] LS = localScoreC(x)$localScore[1]
daudin_result = daudin(localScore = LS, score_probabilities = P_X, sequence_length = length(x), sequence_min = min_X, sequence_max = max_X) daudin_result = daudin(localScore = LS, score_probabilities = P_X, sequence_length = length(x), sequence_min = min_X, sequence_max = max_X)
options(warn = -1) # Disable warnings print
pvalue = c(pvalue, daudin_result) pvalue = c(pvalue, daudin_result)
} }
LS_H0=data.frame(num=1:NbSeqH0, pvalue_scan=pvalue, class=(pvalue<0.05)) print(NbSeqH0)
LS_H0=data.frame(num=1:NbSeq, pvalue_scan=pvalue, class=(pvalue<0.05))
return(LS_H0) return(LS_H0)
} }
``` ```
### Experience plan ### Experience plan
```{r} ```{r}
E = 10 NbSeq = 10**3
for (T in 10**(2:5)){ for (lambda0 in (1:5)){
for (lambda0 in c(1, 2, 10)){ for (lambda1 in c(2,4,6)){
for (lambda1 in c(4, 20, 100, 1000)){ if (lambda0 < lambda1){
if (lambda0 < lambda1){ cat("Nb = ", NbSeq, ", lambda0 = ", lambda0, ", lambda1 = ", lambda1, "\n", sep = "")
cat("T = ", T, ", lambda0 = ", lambda0, ", lambda1 = ", lambda1, "\n", sep = "")
LS_H0 = LocaScoreMC(lambda0, lambda1, E, T) ppH0 = PoissonProcess(lambda0,T)
print(summary(LS_H0)) n1 = length(ppH0)
cat("---\n") tbe0 = ppH0[2:n1]-ppH0[1:n1-1]
}
LS_H0 = LocaScoreMC(lambda0, lambda1, NbSeq, tbe0, T)
print(summary(LS_H0))
cat("---\n")
} }
} }
} }