library(dplyr)
library(ggpubr)
library(rcompanion)
library(car)
Este archivo se encuentra en un folder con datos de Crawley (2003) que adjunto aquí (Crawley). No hemos visto en clase este procedimiento para importar bases de datos. Para que este método funcione el folder adjunto debe de estar en el directorio de trabajo de RStudio (veremos esto en la siguiente sesión).
read.table("Crawley/ipomopsis.txt", header=TRUE) -> ipo
names(ipo)
[1] "Root" "Fruit" "Grazing"
head(ipo)
tail(ipo)
plot(ipo$Fruit ~ ipo$Root, pch=20)
ggplot(aes(x = Grazing, y = Fruit, col= Grazing), data= ipo) +
geom_boxplot(outlier.colour = 2, orientation = "x") +
geom_point(position = position_dodge2(width = 0.2))
###
p <- ggplot(aes(x = Root, y = Fruit, color = Grazing), data= ipo)
p + geom_point() +
geom_smooth(method = "lm")
`geom_smooth()` using formula 'y ~ x'
p + geom_boxplot(outlier.colour = 2) +
geom_point() +
geom_smooth(method = "lm")
`geom_smooth()` using formula 'y ~ x'
ancova <- lm(ipo$Fruit ~ ipo$Grazing *
ipo$Root)
summary(ancova)
Call:
lm(formula = ipo$Fruit ~ ipo$Grazing * ipo$Root)
Residuals:
Min 1Q Median 3Q Max
-17.3177 -2.8320 0.1247 3.8511 17.1313
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) -125.173 12.811 -9.771 1.15e-11 ***
ipo$GrazingUngrazed 30.806 16.842 1.829 0.0757 .
ipo$Root 23.240 1.531 15.182 < 2e-16 ***
ipo$GrazingUngrazed:ipo$Root 0.756 2.354 0.321 0.7500
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
Residual standard error: 6.831 on 36 degrees of freedom
Multiple R-squared: 0.9293, Adjusted R-squared: 0.9234
F-statistic: 157.6 on 3 and 36 DF, p-value: < 2.2e-16
read.table("Crawley/species.txt", header= TRUE) -> sp
names(sp)
[1] "pH" "Biomass" "Species"
head(sp)
tail(sp)
ggdensity(sp$Species)
shapiro.test(sp$Species)
Shapiro-Wilk normality test
data: sp$Species
W = 0.97805, p-value = 0.1317
p <- ggplot(aes(x = Biomass, y = Species, color = pH), data= sp)
p + geom_point() +
geom_smooth(method = "lm")
ancova <- lm(sp$Species ~ sp$Biomass *
sp$pH)
summary(ancova)
Call:
lm(formula = sp$Species ~ sp$Biomass * sp$pH)
Residuals:
Min 1Q Median 3Q Max
-9.290 -2.554 -0.124 2.208 15.677
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 40.60407 1.36701 29.703 < 2e-16 ***
sp$Biomass -2.80045 0.23856 -11.739 < 2e-16 ***
sp$pHlow -22.75667 1.83564 -12.397 < 2e-16 ***
sp$pHmid -11.57307 1.86926 -6.191 2.1e-08 ***
sp$Biomass:sp$pHlow -0.02733 0.51248 -0.053 0.958
sp$Biomass:sp$pHmid 0.23535 0.38579 0.610 0.543
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
Residual standard error: 3.818 on 84 degrees of freedom
Multiple R-squared: 0.8531, Adjusted R-squared: 0.8444
F-statistic: 97.58 on 5 and 84 DF, p-value: < 2.2e-16
p + geom_point() +
geom_smooth(method ='glm',method.args = list(family = 'poisson'))
`geom_smooth()` using formula 'y ~ x'