Академический Документы
Профессиональный Документы
Культура Документы
Cell Contents
|-------------------------|
| N|
| Chi-square contribution |
| N / Row Total |
| N / Col Total |
| N / Table Total |
|-------------------------|
| mtcars$am
mtcars$cyl | 0| 1 | Row Total |
-------------|-----------|-----------|-----------|
4| 3| 8| 11 |
| 1.909 | 2.790 | |
| 0.273 | 0.727 | 0.344 |
| 0.158 | 0.615 | |
| 0.094 | 0.250 | |
-------------|-----------|-----------|-----------|
6| 4| 3| 7|
| 0.006 | 0.009 | |
| 0.571 | 0.429 | 0.219 |
| 0.211 | 0.231 | |
| 0.125 | 0.094 | |
-------------|-----------|-----------|-----------|
8| 12 | 2| 14 |
| 1.636 | 2.391 | |
| 0.857 | 0.143 | 0.438 |
| 0.632 | 0.154 | |
| 0.375 | 0.062 | |
-------------|-----------|-----------|-----------|
Column Total | 19 | 13 | 32 |
| 0.594 | 0.406 | |
-------------|-----------|-----------|-----------|
Descriptions:
The function library(help="datasets") calls the “datasets” package in R within which the
“mtcars” data set is available.
The mtcars data set has a dimension of 32 rows and 11 columns.
32 rows denotes the types of automobiles whereas the 11 columns list the features of the cars
that impacts its design and performance.
The 11 features or variables include- mpg:Miles/(US) gallon,cyl:Number of cylinders,
disp:Displacement (cu.in.), hp:Gross horsepower,drat:Rear axle ratio,wt:Weight (1000
lbs),qsec:1/4 mile time,vs:Engine (0 = V-shaped, 1 = straight),am:Transmission (0 =
automatic, 1 = manual),gear:Number of forward gears,carb:Number of carburetors.
The head(mtcars) lists the first six rows of the data set “mtcars”
The tail(mtcars) lists the last six rows of the dataset “mtcars”
names(mtcars) function returns the variable names of the dataset,11 variables for “mtcars”.
nrow(mtcars) & ncol(mtcars) returns the number of rows and columns of “mtcars” dataset
respectively.
str(mtcars) returns the data types of the variables. In “mtcars” dataset all the variables are of
numeric type.
mean (mtcars$mpg) returns the mean of all the values under “mpg” column.
summary(mtcars$mpg) returns the statistics of the variable “mpg”-mean,standard
deviation,1st quartile, median, minimum value, maximum value and 3rd quartile.
mtcars%>%count(am) uses the function from dplyr package where it counts the number of
vehicles with automatic transmission(0) are 19 and number of vehicles with manual
transmission(0) are 13.
“amt” is a new variable which is created to count the frequency of 0 and 1 values in
am(Transmission column) of “mtcars”.
names(amf) returns the variable names-variable and frequency of amf variable.
x$prot=(x$n)/32 returns the proportion of “am” variable frequencies that is ,19 and 13 by
dividing these two values by 32 which is the cumulative frequency of 19 and 13.
x$perp=(x$n)/32*100 function just returns the proportion value after multiplying it with
100.From the result it is evident that automatic transmission in vehicles are more preferred
by customers as it is higher in number than manual transmission.
x$cum=cumsum(x$n) just adds another column of cumulative frequency displaying the
summation of frequencies of “am” variable in each row,that is 19 and 13 which results in
32.
library(help="gmodels") function calls the “gmodels” package for running the crosstable
function.
CrossTable(mtcars$cyl,mtcars$am) lists the variables “am” and “cyl” with their
frequencies,chi-square contribution,proportion row wise,column wise proportion and total
proportion.
From the table it can be concluded that the vehicles with 8 cylinders and having automatic
transmission are most in demand out of the three cylinders.