I have a dataset which has two variables. One is the measurement of the length (called Sepal.Length) and the other one is Species. Species has two categories (versicolor and setosa labeled as 1 and 2 respectively).
Here first I want to do a Levene's test for equality of variances for the variable Sepal.Length for the two categories of Species. Then I want to conduct a T-test for the equality of mean for Sepal.Length for the 2 categories of Species. The 1st part of the image shows the output that I want to create (These were done in SPSS).
Then I am trying to create a bar plot of mean with 95% confidence interval and a boxplot for Sepal.Length of both the categories. The second part of the image shows these two plots that I want to generate, which were again done on SPSS. I have given a link of my dataset also.
Can anybody please help me with the R codes to do the above stuffs?
# load packages
library(readxl)
library(ggplot2)
library(car)
# import the data
iris <- read_excel("Data.xlsx")
# make the species a factor
iris$Species <- factor(iris$Species)
# Levene's test for homogeneity of variance
leveneTest(data = iris, Sepal.Length ~ Species)
# t test not assuming equal variance
t.test(data = iris, Sepal.Length ~ Species)
# box plot
ggplot(data = iris, aes(y = Sepal.Length, x = Species)) +
geom_boxplot()
Thanks for the reply. Actually I tried to do the Levene's test before by using the package "car". However, somehow I can't install the package in R. Whenever, I try to install, it says -
package ‘car’ is not available (for R version 3.4.1)
car package requires R >=3.5 so you have to update R first, this is a good idea anyways because is going to save you a lot of installation troubles, latest R version is 3.6
Thank you very much @emma. I reinstalled R and things worked.
I was wondering, can you please help me with the R codes for generating the means with confidence interval for the two groups? For example, similar to the one that I showed in the lower left of the image.
My previous query was regarding confidence interval for a single variable. However, here I want to generate CI for a variable for 2 of its different groups. So in this context, it would be a 95% CI plot for Sepal.Length for Species category 1 and another 95% CI plot for Sepal.Length for Species category 2. I would like to have both the CI plots side by side, like in the lower left of the image.
I tries but somehow I am not getting the codes. Can you please help me again?