Statistics Data Project using Rstudio

profilemousasaleh8
ProjEx_Code.R

#### Project example code for Part 1 ######## require(lattice) ## Loading required package: lattice #Create a bar chart for a qualitative variable barchart(as.factor(mtcars$am), horizontal = FALSE, main = "Transmission", xlab = "Transmission Type", col = "darkgreen" ) #Create a frequency histogram for a quantitative variable. histogram(mtcars$mpg, type = "count", main = "Motor Trend Cars 1974", xlab = "Miles Per Gallon", col = "darkred") #Create a relative frequency histogram for a different quantitative variable. histogram(mtcars$wt, type = "percent", main = "Motor Trend Cars 1974", xlab = "Weight of Vehicle (1000 lbs)", col = "darkblue") #Mean mean(mtcars$wt) #Median median(mtcars$wt) #Standard deviation sd(mtcars$wt) #Variance var(mtcars$wt) #Range max(mtcars$wt) - min(mtcars$wt) #Q1 quantile(mtcars$wt, .25) #Q3 quantile(mtcars$wt, .75) #Interquartile Range quantile(mtcars$wt, .75) - quantile(mtcars$wt, .25) #n nrow(mtcars) #Make a boxplot for a quantitative variable. boxplot(mtcars$wt, main = "Motor Trend Cars 1974", ylab = "Weight (1000 lbs)") #Make a side-by-side boxplot for a different quantitative variable separated by a qualitative variable's classes. boxplot(mpg~am, data = mtcars, main = "Motor Trend Cars 1974", ylab = "Miles per Gallon", xlab = "Transmission Type") #Make a scatter plot of two quantitative variables. ##### Project Example Code for Part 2 ######### ##test of Hypothesis for mu <150 t.test(mtcars$hp, mu= 150,alternative = 'less' ) ## testing manual and automatic difference in MPG t.test(mtcars$mpg ~ mtcars$am, var.equal=TRUE, conf.level=0.95) ### Regression model Predict MPG with weight of a car#### plot(mpg~wt, data = mtcars, main = "Motor Trend Cars 1974", xlab = "Weight of Vehicle (1000 lbs)", ylab = "Miles per Gallon", pch = 19) Model_MPG = lm(mpg~wt, dat = mtcars) Model_MPG abline(Model_MPG) summary(Model_MPG) cor(mtcars$mpg, mtcars$wt)