#install.packages("tidyverse")
#install.packages("ggpubr")
#install.packages("readxl")
#install.packages("sp")

library(tidyverse)
## -- Attaching packages --------------------------------------- tidyverse 1.3.0 --
## v ggplot2 3.3.2     v purrr   0.3.4
## v tibble  3.0.4     v dplyr   1.0.2
## v tidyr   1.1.2     v stringr 1.4.0
## v readr   1.4.0     v forcats 0.5.0
## -- Conflicts ------------------------------------------ tidyverse_conflicts() --
## x dplyr::filter() masks stats::filter()
## x dplyr::lag()    masks stats::lag()
library(readxl)
library(agricolae)
library(ggpubr)
library(dplyr)
library(sp)


#import file excel
padi <- readxl::read_excel("soal 2 split plot.xlsx")
head(padi,10)
## # A tibble: 10 x 4
##    Pupuk   Genotipe Kelompok Hasil_Padi
##    <chr>   <chr>       <dbl>      <dbl>
##  1 Kontrol IR-64           1       20.7
##  2 Kontrol IR-64           2       32.1
##  3 Kontrol IR-64           3       29.5
##  4 Kontrol IR-64           4       37.7
##  5 Kontrol 5-969           1       27.7
##  6 Kontrol 5-969           2       33  
##  7 Kontrol 5-969           3       26.3
##  8 Kontrol 5-969           4       37.7
##  9 PK      IR-64           1       30  
## 10 PK      IR-64           2       30.7
#mengubah setiap faKtor dan ulangan ke dalam bentuk factor
padi <- padi %>% mutate_if(is.character,as.factor) %>% mutate(Kelompok=as.factor(Kelompok))

#Anova
anova_padi <- with(padi,sp.plot(block = Kelompok,
                                pplot = Pupuk,
                                splot = Genotipe,
                                Y = Hasil_Padi))
## 
## ANALYSIS SPLIT PLOT:  Hasil_Padi 
## Class level information
## 
## Pupuk    :  Kontrol PK N NP NK NPK 
## Genotipe     :  IR-64 5-969 
## Kelompok     :  1 2 3 4 
## 
## Number of observations:  48 
## 
## Analysis of Variance Table
## 
## Response: Hasil_Padi
##                Df  Sum Sq Mean Sq F value    Pr(>F)    
## Kelompok        3  197.11   65.70  3.6812  0.036212 *  
## Pupuk           5 1674.80  334.96 18.7668 5.616e-06 ***
## Ea             15  267.73   17.85                      
## Genotipe        1    0.04    0.04  0.0114  0.916217    
## Pupuk:Genotipe  5   78.59   15.72  5.0814  0.004444 ** 
## Eb             18   55.68    3.09                      
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## cv(a) = 10.6 %, cv(b) = 4.4 %, Mean = 39.71458