Skip to content

Instantly share code, notes, and snippets.

View Harshit1694's full-sized avatar

HARSHIT GUPTA Harshit1694

View GitHub Profile
#Step 1 - Importing Data
#_______________________________________________________
#Importing the csv data
data<-read.csv(file.choose())
#Step 2 - Validate data for correctness
#______________________________________________________
#Count of Rows and columns
#Step 3 - Calculate the population mean and plot the observations
#___________________________________________________________________
#Calculate the population mean
mean(data$Wall.Thickness)
#Plot all the observations in the data
hist(data$Wall.Thickness,col = "pink",main = "Histogram for Wall Thickness",xlab = "wall thickness")
abline(v=12.8,col="red",lty=1)
#We will take sample size=10, samples=9000
#Calculate the arithmetice mean and plot the mean of sample 9000 times
s10<-c()
n=9000
for (i in 1:n) {
s10[i] = mean(sample(data$Wall.Thickness,10, replace = TRUE))}
hist(s10, col ="lightgreen", main="Sample size =10",xlab = "wall thickness")
abline(v = mean(s10), col = "Red")
abline(v = 12.8, col = "blue")
#We will take sample size=30, 50 & 500 samples=9000
#Calculate the arithmetice mean and plot the mean of sample 9000 times
s30 <- c()
s50 <- c()
s500 <- c()
n =9000
for ( i in 1:n){
s30[i] = mean(sample(data$Wall.Thickness,30, replace = TRUE))
s50[i] = mean(sample(data$Wall.Thickness,50, replace = TRUE))
#Step 3 - Check for assumptions
#______________________________________________________
#1. Data is continuous.
#2. Observations are randomly selected.
#3. To check the data is normally distributed, we will use the following codes:
qqnorm(data$Screen_size.in.cm.)
qqline(data$Screen_size.in.cm.,col="red")
#Step 5 - Conduct one-sample t-test
#Null Hypothesis: Mean screensize of sample does not differ from 10 cm
#Alternate Hypothesis: Mean screensize of sample differ from 10 cm
t.test(data$Screen_size.in.cm.,mu=10)
#Homogeneity of variance
var(data$screensize_sample1)
var(data$screensize_sample2)
#Step 4 - Conduct two-sample t-test
#Null Hypothesis: There is no difference between the mean of two samples
#Alternate Hypothesis: There is difference between the men of two samples
t.test(data$screensize_sample1,data$screensize_sample2,var.equal = T)
#Step 4 - Conduct two-sample t-test
#Null Hypothesis: There is no difference between the means of tyres before and after changing the rubber material.
#Alternate Hypothesis: There is a difference between the means of tyres before and after changing the rubber material.
t.test(data$tyre_1,data$tyre_2,paired = T)
#Step 3 - Calculate sample mean and sample standard deviation
#_______________________________________________________
#Sample mean
xbar<- mean(data$Life.of.LED.Bulbs)
xbar
#Sample standard deviation
s<- sd(data$Life.of.LED.Bulbs)
s