🦋 Ajout de la figure pour générer le MB

This commit is contained in:
Louis Lacoste 2024-03-17 23:12:51 +01:00
parent 43f35ce0f9
commit 4efecdc3ae
4 changed files with 56 additions and 34 deletions

View file

@ -211,10 +211,10 @@ pvalues_adj_dataframe_wide <- pvalues_adj_dataframe %>%
Une fois ces corrections appliquées, nous allons comparer les gènes sélectionnés,
c'est-à-dire différentiellement exprimés.
% TODO Développer ce que veut dire différentiellement exprimé
Ces résultats sont présentés dans le diagramme de Venn (figure~\ref{fig:venn-all-methods}).
On peut voir que la méthode de Satterthwaite sans REML a sélectionné énormément
de gènes,
$\Sexpr{sum(pvalues_adj_dataframe[pvalues_adj_dataframe$test_method == "SatterthwaiteAdj",]$selected)}$

View file

@ -179,14 +179,27 @@ On peut voir un exemple utilisé dans les slides de cours \cite{bastideContinuou
\includegraphics[width=0.7\textwidth]{matrix_K.png}
\end{center}
<<''>>=
<<'plot-MB', warnings = FALSE, message = FALSE, fig.cap = "Exemple d'un arbre phylogénétique généré selon un Mouvement Brownien", out.width = "75%", fig.height = 3.5, fig.align = "center", fig.pos = "H">>=
source(here("simulations","mouvement_brownien.R"))
set.seed(12)
df <- generate_phylo_tree(5,100, 0.1)
df$id_branche <- as.factor(df$id_branche)
ggplot(df) +
aes(x = time, y = traj, color = as.factor(id_branche))+
geom_line() +
geom_vline(data = df[df$is_spec_time,], aes(xintercept = time, color = .data$id_branche), linetype = "dashed")+
geom_point(data = df[df$is_spec_time,], aes(x = time, y = .data$traj, color = .data$id_branche), size = 4)+
labs(color = "Espèce", x = "Temps", y = "Trait") +
coord_fixed(ratio=0.75) +
theme_minimal()
@
% Besoin de le dire qu'on fait une régression linéaire matrice structurée,
% figure avec le Brownien sur l'arbre à reprendre dans le chapitre de livre
Etre assez concis sur l'histoire de la projection et le modèle et les différences avec l'ANOVA.
TODO Etre assez concis sur l'histoire de la projection et le modèle et les différences avec l'ANOVA.
\subsection{ANOVA phylogénétique avec erreur de mesure}
TODO transition

Binary file not shown.

View file

@ -1,8 +1,9 @@
library(ggplot2)
library(dplyr)
# Number of BM indep coordinates
N <- 1000
time_delta <- 0.5
# # Number of BM indep coordinates
# N <- 1000
# time_delta <- 0.5
generate_brownian_motion_traj <- function(N, time_delta, variance = 1) {
# BM indep vector
@ -15,28 +16,28 @@ generate_brownian_motion_traj <- function(N, time_delta, variance = 1) {
return(data.frame(time_serie = time_serie, bm_traj = bm_traj))
}
bm_traj_and_time <- generate_brownian_motion_traj(N, time_delta, 1)
# bm_traj_and_time <- generate_brownian_motion_traj(N, time_delta, 1)
# Plotting
ggplot(bm_traj_and_time) +
aes(x = time_serie, y = bm_traj) +
geom_hline(aes(yintercept = 0, color = "red")) +
geom_line()
# # Plotting
# ggplot(bm_traj_and_time) +
# aes(x = time_serie, y = bm_traj) +
# geom_hline(aes(yintercept = 0, color = "red")) +
# geom_line()
# Generate multiple BM
n <- 100
multiple_BM <- do.call(rbind, lapply(seq(1, n, 1), function(idx) {
data <- generate_brownian_motion_traj(N, time_delta)
data$id <- rep(idx, N)
data <- data[, c(3, 1:2)]
return(data)
}))
# # Generate multiple BM
# n <- 100
# multiple_BM <- do.call(rbind, lapply(seq(1, n, 1), function(idx) {
# data <- generate_brownian_motion_traj(N, time_delta)
# data$id <- rep(idx, N)
# data <- data[, c(3, 1:2)]
# return(data)
# }))
## Plotting multiple BMs
ggplot(multiple_BM) +
aes(x = time_serie, y = bm_traj, group = as.factor(id), alpha = 0.5) +
geom_hline(aes(yintercept = 0, color = "red")) +
geom_line()
# ## Plotting multiple BMs
# ggplot(multiple_BM) +
# aes(x = time_serie, y = bm_traj, group = as.factor(id), alpha = 0.5) +
# geom_hline(aes(yintercept = 0, color = "red")) +
# geom_line()
# For phylogenic tree
@ -45,12 +46,12 @@ generate_phylo_tree <- function(n_tips, N, time_delta) {
time_serie <- cumsum(rep(time_delta, N))
# Instants de spéciations
spec_times <- sort(sample(seq(1:N - 1), n_tips - 1, replace = TRUE))
spec_times <- sort(sample(seq(1:N - 10), n_tips, replace = TRUE))
# Choisir la branche dont on se sépare, au premier choix 1 seule, au second 2
branche_orig_spec <- sapply(
seq_len(length(spec_times)),
function(nb_choix) sample(seq(1, nb_choix), size = 1)
function(nb_choix) sample(seq(1, nb_choix - 1), size = 1)
)
# On ajoute alors la première espèce
@ -66,11 +67,11 @@ generate_phylo_tree <- function(n_tips, N, time_delta) {
phylo_tree_data <- data.frame(
id_branche = factor(),
time = numeric(), traj = numeric()
time = numeric(), traj = numeric(), is_spec_time = logical()
)
# Pour la construction récursive de l'arbre
for (idx in seq_len(length(liste_spec_traj))) {
for (idx in seq_len(length(liste_spec_traj)-1)) {
# Les k pas manquants
k <- spec_times[idx]
@ -80,21 +81,29 @@ generate_phylo_tree <- function(n_tips, N, time_delta) {
idx,
length(liste_spec_traj[[idx]])
),
time = time_serie, traj = liste_spec_traj[[idx]]
time = time_serie, traj = liste_spec_traj[[idx]], is_spec_time = rep(FALSE, N)
)
} else {
base <- phylo_tree_data[phylo_tree_data[["id_branche"]] == (branche_orig_spec[[idx]]),"traj"][1:k]
if(anyNA(base)){
print(spec_times[[idx]])
print(phylo_tree_data$id_branche)
print(branche_orig_spec[[idx]])
}
traj <-
# On prend la dernière valeur avant div qu'on ajoute à la
# trajectoire
base <- phylo_tree_data[which(phylo_tree_data[["id_branche"]] == branche_orig_spec[[idx]]),"traj"]
tail(, n = 1) + liste_spec_traj[[idx]]
c(base, tail(base, n = 1) + liste_spec_traj[[idx]])
current_data <- data.frame(
id_branche = rep(idx, length(liste_spec_traj[[idx]])),
time = time_serie[(k + 1):N], traj = traj
id_branche = rep(idx, N),
time = time_serie, traj = traj, is_spec_time = (time_serie == time_serie[k])
)
}
phylo_tree_data <- rbind(phylo_tree_data, current_data)
}
return(phylo_tree_data)
}
# debug(generate_phylo_tree)