Instalar y llamar paquetes
if (!require("pacman"))
install.packages("pacman")
## Loading required package: pacman
library("pacman")
p_load("vroom",
"ggplot2",
"dplyr",
"tidyverse",
"scales")
llamar Base de datos
Datos_PCR <- vroom("https://raw.githubusercontent.com/ManuelLaraMVZ/resultados_PCR_practica/refs/heads/main/Cts1.csv")
## Rows: 32 Columns: 5
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (4): Well, Grupo, Practica, Fluor
## dbl (1): Cq
##
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
head(Datos_PCR)
## # A tibble: 6 × 5
## Well Grupo Practica Fluor Cq
## <chr> <chr> <chr> <chr> <dbl>
## 1 A01 G1 Relativa SYBR 30.8
## 2 B01 G1 Relativa SYBR 41
## 3 C01 G1 Relativa SYBR 26.1
## 4 D01 G1 Relativa SYBR 41
## 5 E01 G1 Relativa SYBR 41
## 6 F01 G1 Relativa SYBR 22.3
Datos Curva
Datos_Curva <- Datos_PCR %>%
filter(Practica == "Absoluta",
Grupo == "Curva") %>%
select ("Well", "Cq") %>%
mutate(Well = as.numeric(Well),
Curva = Well,
LogConc = log10(Curva)) %>% select(3, 4, 2)
Datos_Curva
## # A tibble: 7 × 3
## Curva LogConc Cq
## <dbl> <dbl> <dbl>
## 1 1000 3 12.4
## 2 100 2 15.6
## 3 10 1 18.8
## 4 1 0 22
## 5 0.1 -1 25.2
## 6 0.01 -2 28.4
## 7 0.001 -3 34.8
Grafica de datos
Grafica <- ggplot(Datos_Curva,
aes(x = LogConc,
y = Cq))+
geom_point(color = "#0505ff", size = 4)+
theme_classic()
Grafica
Ajuste lineal
modelo_lineal <- lm (data = Datos_Curva, Cq ~ LogConc)
modelo_lineal
##
## Call:
## lm(formula = Cq ~ LogConc, data = Datos_Curva)
##
## Coefficients:
## (Intercept) LogConc
## 22.457 -3.543
coefficientes <- coef(modelo_lineal)
m <- round(coefficientes [2], 2)
m
## LogConc
## -3.54
y0 <- round(coefficientes[1], 2)
y0
## (Intercept)
## 22.46
predicción y r2
prediccion <- data.frame(LogConc = seq(min(Datos_Curva$LogConc), max(Datos_Curva$LogConc), length.out = 100))
prediccion$Cq <- predict(modelo_lineal, newdata = prediccion)
head(prediccion)
## LogConc Cq
## 1 -3.000000 33.08571
## 2 -2.939394 32.87100
## 3 -2.878788 32.65628
## 4 -2.818182 32.44156
## 5 -2.757576 32.22684
## 6 -2.696970 32.01212
resum_modelo <- summary(modelo_lineal)
resum_modelo
##
## Call:
## lm(formula = Cq ~ LogConc, data = Datos_Curva)
##
## Residuals:
## 1 2 3 4 5 6 7
## 0.5714 0.2286 -0.1143 -0.4571 -0.8000 -1.1429 1.7143
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 22.4571 0.3959 56.73 3.22e-08 ***
## LogConc -3.5429 0.1979 -17.90 1.00e-05 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 1.047 on 5 degrees of freedom
## Multiple R-squared: 0.9846, Adjusted R-squared: 0.9816
## F-statistic: 320.3 on 1 and 5 DF, p-value: 9.997e-06
r2 <- round(resum_modelo$r.squared, 4)
r2
## [1] 0.9846
ecuacion_recta <- paste0("y = ", m, "x + ", y0, "\n r2 = ", r2)
cat("y = ", m, "x + ", y0, "\n r2 = ", r2)
## y = -3.54 x + 22.46
## r2 = 0.9846
Grafica de ajuste
Grafica_ajuste <- Grafica+
geom_smooth(data=prediccion,
aes(x = LogConc,
y = Cq),
color= "#ff00ff",
size = 1.5)+
labs(title = "Curva estandar de RT-PCR",
subtitle = "Equipo 2",
caption = "Diseño RDR",
x = "log10 (concentracion) [pg/uL)",
y = "Cycle Thershold (Ct)")+
theme_classic(base_size = 15)+
scale_y_continuous(labels = number_format(accuracy = 1))+
theme(plot.title = element_text(hjust = 0.5, face = "bold"), axis.title.x = element_text(face = "bold"),
axis.title.y = element_text(face = "bold"))+
annotate("text",
x = max(Datos_Curva$LogConc) -1.5,
y = min(Datos_Curva$Cq) +13,
label = ecuacion_recta,
color = "#4455ff",
size = 5,
fontface = "bold",
hjust = 0)
## Warning: Using `size` aesthetic for lines was deprecated in ggplot2 3.4.0.
## ℹ Please use `linewidth` instead.
## This warning is displayed once every 8 hours.
## Call `lifecycle::last_lifecycle_warnings()` to see where this warning was
## generated.
Grafica_ajuste
## `geom_smooth()` using method = 'loess' and formula = 'y ~ x'
preducción de concntración de la muestra
head(Datos_PCR)
## # A tibble: 6 × 5
## Well Grupo Practica Fluor Cq
## <chr> <chr> <chr> <chr> <dbl>
## 1 A01 G1 Relativa SYBR 30.8
## 2 B01 G1 Relativa SYBR 41
## 3 C01 G1 Relativa SYBR 26.1
## 4 D01 G1 Relativa SYBR 41
## 5 E01 G1 Relativa SYBR 41
## 6 F01 G1 Relativa SYBR 22.3
Dato_muestra <- Datos_PCR %>%
filter(Practica == "Absoluta",
Grupo == "G2",
Well == "A02") %>%
select( "Well", "Cq")
Dato_muestra
## # A tibble: 1 × 2
## Well Cq
## <chr> <dbl>
## 1 A02 12.1
Valor Ct
Ct_muestra <- round(Dato_muestra$Cq, 2)
Ct_muestra
## [1] 12.1
Ecuacion
LogCont_calculado <- (Ct_muestra-y0)/m
LogCont_calculado
## (Intercept)
## 2.926554
Valor real
Valor_real <- 10^LogCont_calculado
Valor_real
## (Intercept)
## 844.4106
dm <- data.frame(Concentración_real = Valor_real, LogConc = LogCont_calculado, Cq = Ct_muestra)
Grafica_Muestra <- Grafica_ajuste +
geom_point(data = dm,
aes(x = LogConc, y = Cq),
color = "red", size = 6, shape = 20) +
geom_segment(aes(x = min(Datos_Curva$LogConc), xend = LogCont_calculado,
y = Ct_muestra, yend = Ct_muestra),
linetype = "dotted", color = "grey", size = 1.5) + # Move linetype, color, size outside of aes()
geom_segment(aes(x = LogCont_calculado, xend = LogCont_calculado,
y = min(Datos_Curva$Cq), yend = Ct_muestra),
linetype = "dotted", color = "grey", size = 1.5)+
annotate("text",
x = LogCont_calculado,
y = Ct_muestra,
label = paste0("[Muestra] = ", round(Valor_real, 2), "pg/uL"),
color = "#000000",
fontface = "bold",
hjust = 2,
vjust = -2)
Grafica_Muestra
## Warning: Use of `Datos_Curva$LogConc` is discouraged.
## ℹ Use `LogConc` instead.
## Warning in geom_segment(aes(x = min(Datos_Curva$LogConc), xend = LogCont_calculado, : All aesthetics have length 1, but the data has 7 rows.
## ℹ Please consider using `annotate()` or provide this layer with data containing
## a single row.
## Warning: Use of `Datos_Curva$Cq` is discouraged.
## ℹ Use `Cq` instead.
## Warning in geom_segment(aes(x = LogCont_calculado, xend = LogCont_calculado, : All aesthetics have length 1, but the data has 7 rows.
## ℹ Please consider using `annotate()` or provide this layer with data containing
## a single row.
## `geom_smooth()` using method = 'loess' and formula = 'y ~ x'