NITROGENO <- read_excel("NITROGENO.xlsx")
head(NITROGENO)
## # A tibble: 6 × 3
## REPETICION PROFUNDIDAD NITROGENO
## <dbl> <dbl> <dbl>
## 1 1 20 0.09
## 2 2 20 0.08
## 3 3 20 0.13
## 4 4 20 0.11
## 5 1 40 0.06
## 6 2 40 0.08
glimpse(NITROGENO)
## Rows: 12
## Columns: 3
## $ REPETICION <dbl> 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4
## $ PROFUNDIDAD <dbl> 20, 20, 20, 20, 40, 40, 40, 40, 60, 60, 60, 60
## $ NITROGENO <dbl> 0.09, 0.08, 0.13, 0.11, 0.06, 0.08, 0.09, 0.09, 0.04, 0.05…
nitro <- NITROGENO %>%
mutate(REPETICION = as.factor(REPETICION))
ggplot(nitro, aes(PROFUNDIDAD, NITROGENO, colour = REPETICION)) +
geom_point(shape = 16, size= 3, alpha= 1.5)
shapiro.test(nitro$NITROGENO)
##
## Shapiro-Wilk normality test
##
## data: nitro$NITROGENO
## W = 0.94544, p-value = 0.5716
cor.test(nitro$PROFUNDIDAD,
nitro$NITROGENO,
method = "pearson",
conf.level = 0.99)
##
## Pearson's product-moment correlation
##
## data: nitro$PROFUNDIDAD and nitro$NITROGENO
## t = -5.0034, df = 10, p-value = 0.0005346
## alternative hypothesis: true correlation is not equal to 0
## 99 percent confidence interval:
## -0.9703433 -0.3635037
## sample estimates:
## cor
## -0.8453206
REGRESION_nitro <- lm(nitro$NITROGENO ~ nitro$PROFUNDIDAD)
REGRESION_nitro
##
## Call:
## lm(formula = nitro$NITROGENO ~ nitro$PROFUNDIDAD)
##
## Coefficients:
## (Intercept) nitro$PROFUNDIDAD
## 0.131667 -0.001375
summary(REGRESION_nitro)
##
## Call:
## lm(formula = nitro$NITROGENO ~ nitro$PROFUNDIDAD)
##
## Residuals:
## Min 1Q Median 3Q Max
## -0.024167 -0.010417 0.002083 0.011458 0.025833
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 0.1316667 0.0118732 11.089 6.11e-07 ***
## nitro$PROFUNDIDAD -0.0013750 0.0002748 -5.003 0.000535 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 0.01555 on 10 degrees of freedom
## Multiple R-squared: 0.7146, Adjusted R-squared: 0.686
## F-statistic: 25.03 on 1 and 10 DF, p-value: 0.0005346
ggplot(nitro, aes(x = PROFUNDIDAD, y = NITROGENO)) +
geom_point(size = 2.5, alpha = 0.6) +
geom_smooth(method = "lm", se = FALSE, color = "blue") +
geom_text(x = 45, y = 0.11, label = "y = 0.1317 - 0.001375 x", size = 5)
#Usamos la función plot
par(mfrow=c(2,2)) # permite visualizar los gráficos de residuos en una sola imagen
plot(REGRESION_nitro)
Normalidad
H0: los residuos tienen distribución normal.
H1: los residuos NO tienen distribución normal.
shapiro.test(residuals(REGRESION_nitro))
##
## Shapiro-Wilk normality test
##
## data: residuals(REGRESION_nitro)
## W = 0.97087, p-value = 0.9197
Homocedasticidad
H0: Se cumple el supuesto de homocedasticidad
H1: No se cumple el supuesto de homocedasticidad
bptest(nitro$PROFUNDIDAD~nitro$NITROGENO, data = nitro)
##
## studentized Breusch-Pagan test
##
## data: nitro$PROFUNDIDAD ~ nitro$NITROGENO
## BP = 0.18172, df = 1, p-value = 0.6699
nitro_50cm <- 0.1317 - (0.001375 * 50)
nitro_50cm
## [1] 0.06295
ggplot(nitro, aes(PROFUNDIDAD, NITROGENO)) +
geom_point(size = 2.5, alpha = 0.6, color = "red") +
geom_smooth(method = "lm", se = TRUE, color = "black") +
geom_text(x = 45, y = 0.11, label = "NITROGENO = 0,1317 -0,001375 * PROFUNDIDAD", size = 4) +
geom_point(aes(x = 50, y = 0.06392), color = "yellow", size = 4) +
labs(
title = "Relación entre Profundidad del Suelo y Nitrógeno",
x = "Profundidad (cm)",
y = "Contenido de Nitrógeno (%)"
) +
theme_minimal(base_size = 14)