cargar librerias
library(openxlsx)
library(dplyr)
Attaching package: 'dplyr'
The following objects are masked from 'package:stats':
filter, lag
The following objects are masked from 'package:base':
intersect, setdiff, setequal, union
library(ggplot2)
Fijar directorio de trabajo
setwd("D:/ACTIVIDAD DE TITULACION I (2023)/CONTROLES/PRUEBA_CORTA_2")
Cargar datos
df <- as.data.frame(read.xlsx("D:/ACTIVIDAD DE TITULACION I (2023)/CONTROLES/PRUEBA_CORTA_2/Ajoblanco.xlsx"))
Mostrar primeras filas del df
head(df)
Año perim peso
1 2016 21.3 98.2
2 2016 25.3 143.3
3 2016 27.6 150.0
4 2016 21.5 90.5
5 2016 22.0 98.3
6 2016 23.1 92.6
Seleccionar y filtar datos (peso para año 2016)
año_2016 <- df %>%
select(-perim) %>%
filter(Año==2016)
Seleccionar y filtrar datos (peso para año 2017)
año_2017 <- df %>%
select(-perim) %>%
filter(Año==2017)
Prueba t-Student para dos poblaciones
t.test(año_2016$peso, año_2017$peso, alternative = "two.sided", mu=0,
var.equal = FALSE, conf.level = 0.95, scipen=0)
Welch Two Sample t-test
data: año_2016$peso and año_2017$peso
t = 20.043, df = 1502.3, p-value < 0.00000000000000022
alternative hypothesis: true difference in means is not equal to 0
95 percent confidence interval:
21.33831 25.96815
sample estimates:
mean of x mean of y
64.42367 40.77044
Gráfico
ggplot(data=df,mapping=aes(x=perim,y=peso)) +
geom_point(aes(color=Año)) +
geom_smooth(method="lm") +
labs(title="Relación entre el perímetro y el peso en ajo blanco",
subtitle="Ajo blanco cosechado en 2016 y 2017",
x="Perimetro cabeza de ajo (cm)",
y="Peso cabeza de ajo (g)",
caption="Realizado con ggplot2 de R.") +
facet_wrap(~Año)
`geom_smooth()` using formula = 'y ~ x'
