Packages needed:
# install.packages ('doBy') install.packages ('ggplot2')
options(width = 320)
rm(list = ls(all = TRUE))
library(doBy)
## Loading required package: survival
## Loading required package: splines
## Loading required package: MASS
library(ggplot2)
file = "WankaLab ExperimentWanka-table.csv"
tx = read.csv(file, header = T, skip = 6)
names(tx) #check names!!
## [1] "X.run.number." "initial.sunlight" "percent.that.migrates." "water.infraestructure" "X.step." "sunlight" "Population.density" "UrbanPopulation" "RuralPopulation" "JunglePopulation" "LimaPopulationUrban" "LimaPopulationRural"
## [13] "global.temperature" "num.snow" "num.ice" "num.dry"
Effect of different percent that migrates in population density in HYO Table Summary
summaryBy(Population.density ~ percent.that.migrates., data = tx, FUN = function(x) {
c(mean = mean(x), sd = sd(x), me = median(x))
})
## percent.that.migrates. Population.density.mean Population.density.sd Population.density.me
## 1 0.1 0.2642 0.1242 0.2614
## 2 0.5 0.2313 0.1013 0.2451
## 3 1.0 0.2126 0.0980 0.2288
Boxplot
DensityPercentMigrateBox <- ggplot(tx, aes(factor(percent.that.migrates.), Population.density))
DensityPercentMigrateBox + geom_boxplot(fill = "yellow", colour = "#3366FF") + xlab("Percentage of Uncomfortable people that migrates") + ylab("Pop Density") + ggtitle("Percent Migrate vs Pop Density")
Effect of different infraestructure in population density in HYO Table Summary
summaryBy(Population.density ~ water.infraestructure, data = tx, FUN = function(x) {
c(mean = mean(x), sd = sd(x), me = median(x))
})
## water.infraestructure Population.density.mean Population.density.sd Population.density.me
## 1 1 0.1150 0.02552 0.1111
## 2 5 0.2442 0.04218 0.2516
## 3 10 0.3572 0.07332 0.3497
Boxplot
DensityInfrastructureBox <- ggplot(tx, aes(factor(water.infraestructure), Population.density))
DensityInfrastructureBox + geom_boxplot(fill = "yellow", colour = "#3366FF") + xlab("Infrastructure") + ylab("Pop Density") + ggtitle("Infrastructure vs Pop Density")
Effect of Initial sunlight in population density in HYO Table Summary
summaryBy(Population.density ~ initial.sunlight, data = tx, FUN = function(x) {
c(mean = mean(x), sd = sd(x), me = median(x))
})
## initial.sunlight Population.density.mean Population.density.sd Population.density.me
## 1 0.5 0.1728 0.1223 0.1422
## 2 1.5 0.2420 0.1092 0.2516
Boxplot
DensitySunlightBox <- ggplot(tx, aes(factor(initial.sunlight), Population.density))
DensitySunlightBox + geom_boxplot(fill = "yellow", colour = "#3366FF") + xlab("Sunlight") + ylab("Pop Density") + ggtitle("Sunlight vs Pop Density")
Combined effects in population density in HYO Table Summary
summaryBy(Population.density ~ water.infraestructure + initial.sunlight, tx, FUN = c(median))
## water.infraestructure initial.sunlight Population.density.median
## 1 1 0.5 0.1373
## 2 1 1.5 0.1095
## 3 5 0.5 0.1716
## 4 5 1.5 0.2533
## 5 10 0.5 0.2941
## 6 10 1.5 0.3497
Boxplot
DensityInfrastructureBox <- ggplot(tx, aes(factor(water.infraestructure), Population.density))
DensityInfrastructureBox + geom_boxplot(fill = "yellow", colour = "#3366FF") + xlab("Infrastructure") + ylab("Pop Density") + ggtitle("Infrastructure vs Pop Density") + facet_grid(. ~ initial.sunlight)
summaryBy(Population.density ~ percent.that.migrates. + initial.sunlight, tx, FUN = c(median))
## percent.that.migrates. initial.sunlight Population.density.median
## 1 0.1 0.5 0.14542
## 2 0.1 1.5 0.26471
## 3 0.5 0.5 0.09150
## 4 0.5 1.5 0.24673
## 5 1.0 0.5 0.08333
## 6 1.0 1.5 0.22876
DensityPercentMigrateBox <- ggplot(tx, aes(factor(percent.that.migrates.), Population.density))
DensityPercentMigrateBox + geom_boxplot(fill = "yellow", colour = "#3366FF") + xlab("Percentage of Uncomfortable people that migrates") + ylab("Pop Density") + ggtitle("Percent Migrate vs Pop Density") + facet_grid(. ~ initial.sunlight)
summaryBy(Population.density ~ percent.that.migrates. + water.infraestructure + initial.sunlight, tx, FUN = c(median))
## percent.that.migrates. water.infraestructure initial.sunlight Population.density.median
## 1 0.1 1 0.5 0.13725
## 2 0.1 1 1.5 0.13889
## 3 0.1 5 0.5 0.25817
## 4 0.1 5 1.5 0.26634
## 5 0.1 10 0.5 0.35621
## 6 0.1 10 1.5 0.42157
## 7 0.5 1 0.5 0.08824
## 8 0.5 1 1.5 0.10784
## 9 0.5 5 0.5 0.11601
## 10 0.5 5 1.5 0.24837
## 11 0.5 10 0.5 0.05556
## 12 0.5 10 1.5 0.34477
## 13 1.0 1 0.5 0.05065
## 14 1.0 1 1.5 0.09477
## 15 1.0 5 0.5 0.09804
## 16 1.0 5 1.5 0.23039
## 17 1.0 10 0.5 0.16176
## 18 1.0 10 1.5 0.32516
DensityPercentMigrateBox <- ggplot(tx, aes(factor(percent.that.migrates.), Population.density))
DensityPercentMigrateBox + geom_boxplot(fill = "yellow", colour = "#3366FF") + xlab("Percentage of Uncomfortable people that migrates") + ylab("Pop Density") + ggtitle("Percent Migrate vs Pop Density") + facet_grid(water.infraestructure ~ initial.sunlight)
summaryBy(X.step. ~ percent.that.migrates. + water.infraestructure + initial.sunlight, tx, FUN = c(max))
## percent.that.migrates. water.infraestructure initial.sunlight X.step..max
## 1 0.1 1 0.5 2000
## 2 0.1 1 1.5 2000
## 3 0.1 5 0.5 2000
## 4 0.1 5 1.5 2000
## 5 0.1 10 0.5 2000
## 6 0.1 10 1.5 2000
## 7 0.5 1 0.5 99
## 8 0.5 1 1.5 2000
## 9 0.5 5 0.5 123
## 10 0.5 5 1.5 2000
## 11 0.5 10 0.5 28
## 12 0.5 10 1.5 2000
## 13 1.0 1 0.5 13
## 14 1.0 1 1.5 2000
## 15 1.0 5 0.5 60
## 16 1.0 5 1.5 2000
## 17 1.0 10 0.5 64
## 18 1.0 10 1.5 2000
REGRESSION
preparing data
regreData = as.data.frame(summaryBy(X.step. ~ percent.that.migrates. + water.infraestructure + initial.sunlight, tx, FUN = c(max)))
computing model
reglin = lm(X.step..max ~ percent.that.migrates. + water.infraestructure + initial.sunlight, data = regreData)
Verifying which variables hav effect on time until 0 people in HYO
summary(reglin)
##
## Call:
## lm(formula = X.step..max ~ percent.that.migrates. + water.infraestructure +
## initial.sunlight, data = regreData)
##
## Residuals:
## Min 1Q Median 3Q Max
## -714.2 -451.4 -96.8 486.0 840.7
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 623.21 420.61 1.48 0.16058
## percent.that.migrates. -1042.79 376.71 -2.77 0.01510 *
## water.infraestructure -0.48 37.67 -0.01 0.99002
## initial.sunlight 1290.33 277.39 4.65 0.00037 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 588 on 14 degrees of freedom
## Multiple R-squared: 0.677, Adjusted R-squared: 0.607
## F-statistic: 9.77 on 3 and 14 DF, p-value: 0.000982