We therefore can explore our dataset after running some important
libraries that we shall use.
library(ggplot2) #Enhances plots
library(granova)
## Loading required package: car
## Loading required package: carData
library(Rcmdr) #Then close the R commander window that pops
## Loading required package: splines
## Loading required package: RcmdrMisc
## Loading required package: sandwich
## Loading required package: effects
## lattice theme set by effectsTheme()
## See ?effectsTheme for details.
## The Commander GUI is launched only in interactive sessions
##
## Attaching package: 'Rcmdr'
## The following object is masked from 'package:base':
##
## errorCondition
library(car) #Used for Levene's test
library(pastecs)
library(multcomp) #Used for post hoc test
## Loading required package: mvtnorm
## Loading required package: survival
## Loading required package: TH.data
## Loading required package: MASS
##
## Attaching package: 'TH.data'
## The following object is masked from 'package:MASS':
##
## geyser
library(compute.es) #Used for effect size
library(WRS2) #Tests for Robust
library(multcompView)
library(fastDummies)
library(dplyr)
##
## Attaching package: 'dplyr'
## The following object is masked from 'package:MASS':
##
## select
## The following objects are masked from 'package:pastecs':
##
## first, last
## The following object is masked from 'package:car':
##
## recode
## The following objects are masked from 'package:stats':
##
## filter, lag
## The following objects are masked from 'package:base':
##
## intersect, setdiff, setequal, union
library(flextable)
Freely can therefore explore our dataset for easy visualization
head(Dummy_2_) #Shows the first six rows of our dataset
## # A tibble: 6 × 6
## ...1 person dose symptoms dummy1 dummy2
## <dbl> <dbl> <chr> <dbl> <dbl> <dbl>
## 1 1 1 Placebo 3 0 0
## 2 2 2 Placebo 2 0 0
## 3 3 3 Placebo 1 0 0
## 4 4 4 Placebo 1 0 0
## 5 5 5 Placebo 4 0 0
## 6 6 6 Low Dose 5 0 1
tail(Dummy_2_) #Illustrates the last six rows of our dataset
## # A tibble: 6 × 6
## ...1 person dose symptoms dummy1 dummy2
## <dbl> <dbl> <chr> <dbl> <dbl> <dbl>
## 1 10 10 Low Dose 3 0 1
## 2 11 11 High Dose 7 1 0
## 3 12 12 High Dose 4 1 0
## 4 13 13 High Dose 5 1 0
## 5 14 14 High Dose 3 1 0
## 6 15 15 High Dose 6 1 0
dim(Dummy_2_) #Tells the total number of rows and columns
## [1] 15 6
summary(Dummy_2_) #Displays the more frequently properties of the data
## ...1 person dose symptoms
## Min. : 1.0 Min. : 1.0 Length:15 Min. :1.000
## 1st Qu.: 4.5 1st Qu.: 4.5 Class :character 1st Qu.:2.000
## Median : 8.0 Median : 8.0 Mode :character Median :3.000
## Mean : 8.0 Mean : 8.0 Mean :3.467
## 3rd Qu.:11.5 3rd Qu.:11.5 3rd Qu.:4.500
## Max. :15.0 Max. :15.0 Max. :7.000
## dummy1 dummy2
## Min. :0.0000 Min. :0.0000
## 1st Qu.:0.0000 1st Qu.:0.0000
## Median :0.0000 Median :0.0000
## Mean :0.3333 Mean :0.3333
## 3rd Qu.:1.0000 3rd Qu.:1.0000
## Max. :1.0000 Max. :1.0000
str(Dummy_2_) #Further describes more features of the dataset
## spc_tbl_ [15 × 6] (S3: spec_tbl_df/tbl_df/tbl/data.frame)
## $ ...1 : num [1:15] 1 2 3 4 5 6 7 8 9 10 ...
## $ person : num [1:15] 1 2 3 4 5 6 7 8 9 10 ...
## $ dose : chr [1:15] "Placebo" "Placebo" "Placebo" "Placebo" ...
## $ symptoms: num [1:15] 3 2 1 1 4 5 2 4 2 3 ...
## $ dummy1 : num [1:15] 0 0 0 0 0 0 0 0 0 0 ...
## $ dummy2 : num [1:15] 0 0 0 0 0 1 1 1 1 1 ...
## - attr(*, "spec")=
## .. cols(
## .. ...1 = col_double(),
## .. person = col_double(),
## .. dose = col_character(),
## .. symptoms = col_double(),
## .. dummy1 = col_double(),
## .. dummy2 = col_double()
## .. )
## - attr(*, "problems")=<externalptr>
Simple Anova
Suppose we tested the hypothesis that a new drug is superior by
taking three groups of participants and administering one group with a
Placebo(Sugar pill), one group with a low dose of drug and one with a
high dose.
By converting the above variables into factor factor levels we
obtain,
factor(dose)
## [1] Placebo Placebo Placebo Placebo Placebo Low dose Low dose
## [8] Low dose Low dose Low dose High dose High dose High dose High dose
## [15] High dose
## Levels: Placebo Low dose High dose
Therefore, we decided to create dummy variables to help us the
categorical data representation. Where we purpose to avoid collinearity
within our variables.
Collinearity reprents two or more independent variables in a
regression model which are highly correlated.
Therefore we can plot some graphs to help us more analyze our
dataset
line <- ggplot(DrugData, aes(dose, symptoms))
line + stat_summary(fun = mean, geom = "line", size = 1, aes(group=1), colour = "#FF6633") + stat_summary(fun.data = mean_cl_boot, geom = "errorbar", width = 0.2, size = 0.75, colour = "#990000") + stat_summary(fun = mean, geom = "point", size = 4, colour = "#990000") + stat_summary(fun = mean, geom = "point", size = 3, colour = "#FF6633") + labs(x = "Dose of Drug", y = "Mean symptoms")
## Warning: Using `size` aesthetic for lines was deprecated in ggplot2 3.4.0.
## ℹ Please use `linewidth` instead.
## This warning is displayed once every 8 hours.
## Call `lifecycle::last_lifecycle_warnings()` to see where this warning was
## generated.
