Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add files via upload #1

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
81 changes: 81 additions & 0 deletions CRD and RBD.Rmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
---
title: "CRD and RBD"
author: "Ian Leboo"
date: "3/30/2022"
output: html_document
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE, message = FALSE,warning = TRUE)
```
#1. CRD
##Example 1
The data contains 4 tropical food stuffs A, B, C, and D tried on 20 chicks. Analyze the data at 5% level of significance.
```{r}
library(readxl)
chicks <- read_excel("chics.xlsx")
```

Set the treatment column into factors
```{r}
chicks$Treatment<-as.factor(chics$Treatment)
```

Performing ANOVA
##Method 1
```{r}
mod1<-aov(Weight~Treatment, data = chics)
summary(mod1)
```

##Method 2
```{r}
chicksmodel<-lm(Weight~Treatment, data = chics)
anova(chicksmodel)
```
##LSD Test
```{r}
library(agricolae)
LSD.test(chicksmodel,"Treatment", console = TRUE)
```
##Example 2
The data contains the amount of electricity used in KWh in three towns. Test at 5% significance whether the amount of electricity used is the same in the 3 towns.
The steps are as example 1

```{r}
library(readxl)
electricity <- read_excel("electricity.xlsx")

#Set the treatment variable to factor
electricity$Town<-as.factor(electricity$Town)
model2<-aov(Electricity_Used~Town, data=electricity)
summary(model2)
```

#2. RBD

In this data, there are 4 blocks and 6 treatments.
we are required to test whether treatments and blocks differ significantly at 5% significance level
```{r}
library(readxl)
RBD <- read_excel("RBD.xlsx")
```

We will need to reshape the data into long format
```{r}
library(reshape2)
library(dplyr)
RBD_new<-RBD %>%
melt() %>%
mutate(Block=variable,
Treatments=as.factor(Treatments)) %>%
select(-c(variable))
```

Performing ANOVA
```{r}
Model3<-aov(value~Treatments+Block, data=RBD_new)
summary(Model3)
```


Binary file added RBD.xlsx
Binary file not shown.
Binary file added chics.xlsx
Binary file not shown.
Binary file added electricity.xlsx
Binary file not shown.