You are on page 1of 6

Plant_Growth_Analysis.

R
odimu_000

Sun Oct 08 09:49:24 2017


###################Importing Plant growth data and calculating summary
statistics######################################################

data("PlantGrowth")
PlantGrowth

## weight group
## 1 4.17 ctrl
## 2 5.58 ctrl
## 3 5.18 ctrl
## 4 6.11 ctrl
## 5 4.50 ctrl
## 6 4.61 ctrl
## 7 5.17 ctrl
## 8 4.53 ctrl
## 9 5.33 ctrl
## 10 5.14 ctrl
## 11 4.81 trt1
## 12 4.17 trt1
## 13 4.41 trt1
## 14 3.59 trt1
## 15 5.87 trt1
## 16 3.83 trt1
## 17 6.03 trt1
## 18 4.89 trt1
## 19 4.32 trt1
## 20 4.69 trt1
## 21 6.31 trt2
## 22 5.12 trt2
## 23 5.54 trt2
## 24 5.50 trt2
## 25 5.37 trt2
## 26 5.29 trt2
## 27 4.92 trt2
## 28 6.15 trt2
## 29 5.80 trt2
## 30 5.26 trt2

sapply(PlantGrowth[1], summary)

## weight
## Min. 3.590
## 1st Qu. 4.550
## Median 5.155
## Mean 5.073
## 3rd Qu. 5.530
## Max. 6.310

paste("Mean=", sapply(PlantGrowth[1], mean),"Standard Deviation=",


sapply(PlantGrowth[1], sd),"Variance=", sapply(PlantGrowth[1], var), "IQR=",
sapply(PlantGrowth[1], IQR))

## [1] "Mean= 5.073 Standard Deviation= 0.701191842508168 Variance= 0.49167


IQR= 0.98"

quantile(as.numeric(PlantGrowth$weight),seq(0,1,0.1))

## 0% 10% 20% 30% 40% 50% 60% 70% 80% 90% 100%
## 3.590 4.170 4.482 4.666 4.908 5.155 5.272 5.409 5.624 6.038 6.310

###################Separating into subsets and calculating summary


statistics##########################################################

print(ctrl<-subset(PlantGrowth, PlantGrowth$group == "ctrl"))

## weight group
## 1 4.17 ctrl
## 2 5.58 ctrl
## 3 5.18 ctrl
## 4 6.11 ctrl
## 5 4.50 ctrl
## 6 4.61 ctrl
## 7 5.17 ctrl
## 8 4.53 ctrl
## 9 5.33 ctrl
## 10 5.14 ctrl

sapply(ctrl[1], summary)

## weight
## Min. 4.170
## 1st Qu. 4.550
## Median 5.155
## Mean 5.032
## 3rd Qu. 5.292
## Max. 6.110

paste("Mean=", sapply(ctrl[1], mean),"Standard Deviation=", sapply(ctrl[1],


sd),"Variance=", sapply(ctrl[1], var), "IQR=", sapply(ctrl[1], IQR))

## [1] "Mean= 5.032 Standard Deviation= 0.583091378392406 Variance=


0.339995555555556 IQR= 0.742500000000001"

quantile(ctrl$weight,seq(0,1,0.1))
## 0% 10% 20% 30% 40% 50% 60% 70% 80% 90% 100%
## 4.170 4.467 4.524 4.586 4.928 5.155 5.174 5.225 5.380 5.633 6.110

print(trt1<-subset(PlantGrowth, PlantGrowth$group == "trt1"))

## weight group
## 11 4.81 trt1
## 12 4.17 trt1
## 13 4.41 trt1
## 14 3.59 trt1
## 15 5.87 trt1
## 16 3.83 trt1
## 17 6.03 trt1
## 18 4.89 trt1
## 19 4.32 trt1
## 20 4.69 trt1

sapply(trt1[1], summary)

## weight
## Min. 3.590
## 1st Qu. 4.208
## Median 4.550
## Mean 4.661
## 3rd Qu. 4.870
## Max. 6.030

paste("Mean=", sapply(trt1[1], mean),"Standard Deviation=", sapply(trt1[1],


sd),"Variance=", sapply(trt1[1], var), "IQR=", sapply(trt1[1], IQR))

## [1] "Mean= 4.661 Standard Deviation= 0.793675696434703 Variance=


0.629921111111111 IQR= 0.6625"

quantile(trt1$weight,seq(0,1,0.1))

## 0% 10% 20% 30% 40% 50% 60% 70% 80% 90% 100%
## 3.590 3.806 4.102 4.275 4.374 4.550 4.738 4.834 5.086 5.886 6.030

print(trt2<-subset(PlantGrowth, PlantGrowth$group == "trt2"))

## weight group
## 21 6.31 trt2
## 22 5.12 trt2
## 23 5.54 trt2
## 24 5.50 trt2
## 25 5.37 trt2
## 26 5.29 trt2
## 27 4.92 trt2
## 28 6.15 trt2
## 29 5.80 trt2
## 30 5.26 trt2
sapply(trt2[1], summary)

## weight
## Min. 4.920
## 1st Qu. 5.268
## Median 5.435
## Mean 5.526
## 3rd Qu. 5.735
## Max. 6.310

paste("Mean=", sapply(trt2[1], mean),"Standard Deviation=", sapply(trt2[1],


sd),"Variance=", sapply(trt2[1], var), "IQR=", sapply(trt2[1], IQR))

## [1] "Mean= 5.526 Standard Deviation= 0.442573283322786 Variance=


0.195871111111111 IQR= 0.467499999999999"

quantile(trt2$weight,seq(0,1,0.1))

## 0% 10% 20% 30% 40% 50% 60% 70% 80% 90% 100%
## 4.920 5.100 5.232 5.281 5.338 5.435 5.516 5.618 5.870 6.166 6.310

#####################Creating vector space for


plots########################################################################
###########

par(mfrow=c(3,4))

#############################################################################
##########################################################

######################Plotting
histograms###################################################################
###########################

hist(as.numeric(PlantGrowth$weight),col = "red", main = "All Plants", xlab =


"Weight", labels = T, ylim = c(0,10))
hist(ctrl$weight, col = "blue", main = "Control", xlab = "Weight", labels =
T, ylim = c(0,6))
hist(trt1$weight, col = "green", main = "Treatment 1", xlab = "Weight",
labels = T, ylim = c(0,4))
hist(trt2$weight, col = "yellow", main = "Treatment 2", xlab =
"Weight",labels = T, ylim = c(0,4))

######################Plotting
boxplots#####################################################################
###########################

boxplot(as.numeric(PlantGrowth$weight), col = "red", horizontal = T, main =


"All Plants", xlab = "Weight", labels = T)
sumall<-boxplot(as.numeric(PlantGrowth$weight), plot = F, range = 0)
text(x = sumall$stats, y = col(sumall$stats) - .25, labels = sumall$stats)
boxplot(ctrl$weight, col = "blue", horizontal = T, main = "Control", xlab =
"Weight", labels = T)
sumctrl<-boxplot(ctrl$weight, plot = F, range = 0)
text(x = sumctrl$stats, y = col(sumctrl$stats) - .25, labels = sumctrl$stats)

boxplot(trt1$weight, col = "green", horizontal = T, main = "Treatment 1",


xlab = "Weight", labels = T)
sumtrt1<-boxplot(trt1$weight, plot = F, range = 0)
text(x = sumtrt1$stats, y = col(sumtrt1$stats) - .25, labels = sumtrt1$stats)

boxplot(trt2$weight, col = "yellow", horizontal = T, main = "Treatment 2",


xlab = "Weight",labels = T)
sumtrt2<-boxplot(trt2$weight, plot = F, range = 0)
text(x = sumtrt2$stats, y = col(sumtrt2$stats) - .25, labels = sumtrt2$stats)

#############################################################################
############################################################

######################Plotting Q-Q
plots########################################################################
#########################

qqnorm(PlantGrowth$weight, main = "All Plants", col = "red", pch =19)


qqnorm(ctrl$weight, main = "Control", col = "blue", pch =19)
qqnorm(trt1$weight, main = "Treatment 1", col = "green", pch =19)
qqnorm(trt2$weight, main = "Treatment 2", col = "yellow", pch =19)
#############################################################################
#####################################################################

You might also like