This is a short memo. Describing the system dataset mtcars, showing some visuals, results, and text formatting. Put 2 spaces at end of line for output to go to next line.
Using system dataset “mtcars”. Column names of dataset included below. mpg, cyl, disp, hp, drat, wt, qsec, vs, am, gear, carb
Variable Descriptions
I am interested in variables for Miles Per Gallon(MPG) split by automatic and manual cars(am). Along with how Miles Per Gallon(MPG) is influenced by the weight of the vehicle.
Variable mpg has the following overall measure of mean and standard deviation.
mean = 20.090625
standard deviation = 6.0269481
Variable am has the following frequency counts and summary statistics in association with Miles per Gallon.
Characteristic
0
N = 191
1
N = 131
mpg
17.3 (14.7, 19.2)
22.8 (21.0, 30.4)
1 Median (Q1, Q3)
Results
I will display mpg and weight on a scatterplot and t-test results comparing mpg for automatic and manual cars values of 0(automatic) and 1(manual) cars. My null hypothesis comparing automatic and manual cars would be the mpg for both type of vehicle groups are equal. With the alternative hypothesis being that they are not equal.
Below are code and results of the T-test mentioned earlier. My null hypothesis would be the mpg for both automatic and manual cars are equal.
#Commands below to compare avg mpg for vs equal to 0 and equal to 1. am0 <-subset(mtcars, am ==0)am1 <-subset(mtcars, am ==1)testres <-t.test(am0$mpg, am1$mpg)#Print full t.test resultstestres
Welch Two Sample t-test
data: am0$mpg and am1$mpg
t = -3.7671, df = 18.332, p-value = 0.001374
alternative hypothesis: true difference in means is not equal to 0
95 percent confidence interval:
-11.280194 -3.209684
sample estimates:
mean of x mean of y
17.14737 24.39231
Above uses code chunk to show code used to create results. Also could do inline code just to show numbers. Inline code will make it appear a bit more organized. Numbers printed are t statistic and corresponding p-value. -3.7671231, 0.0013736
Analysis of TTest results
Based on such a low p-value of 0.0013736 I reject the null hypothesis. The data does not suggest that automatic and manual vehicles have the same mpg showing manual cars having an average mpg of 24.3923077 and automatic cars displaying 17.1473684. The data suggests manual cars have a higher MPG than automatic cars.
Regression equation Miles Per Gallon and Weight
Performing another result in the form of a correlation matrix and regression equation in the next section. As weight increases, the trend appears to result in a decreased mpg. Below is the correlation of mpg and weight. -0.8676594.
From the correlation matrix, a linear regression model is an appropriate fit. I will proceed with a regression equation to predict miles per gallon based on weight of the vehicle. Below is the scatterplot with line of best fit. Below that will display the regression results in the form of an equation.
plot(mtcars$wt, mtcars$mpg, ylab="Miles Per Gallon", xlab="weight in Thousand Pounds", main ="Miles per Gallon of Cars by weight of cars in Sample")abline(lm(mpg ~ wt))
From the regression equation. for every 1 unit increase in our weight variable, we expect the miles per gallon to decrease by 5.3 as shwon below in the equation. Following a linear model, it will have the following equation. With a correlation of -0.8676594 there is a moderately strong linear relationship with a negative slope. mpg = 37.2851262 + -5.3444716 x weight