Database Reference
In-Depth Information
sales_table
small medium big
F 1726 2746 563
M 1656 2723 586
class(sales_table) # returns "table"
typeof(sales_table) # returns "integer"
dim(sales_table) # returns 2 3
# performs a chi-squared test
summary(sales_table)
Number of cases in table: 10000
Number of factors: 2
Test for independence of all factors:
Chisq = 1.516, df = 2, p-value = 0.4686
Based on the observed counts in the table, the summary() function performs a
chi-squared test on the independence of the two factors. Because the reported
p -value is greater than 0.05, the assumed independence of the two factors is not
rejected. Hypothesis testing and p -values are covered in more detail later in this
chapter. Next, applying descriptive statistics in R is examined.
3.1.4 Descriptive Statistics
It has already been shown that the summary() function provides several
descriptive statistics, such as the mean and median, about a variable such as the
sales data frame. The results now include the counts for the three levels of the
spender variable based on the earlier examples involving factors.
summary(sales)
cust_id sales_total num_of_orders gender spender
Min. :100001 Min. : 30.02 Min. : 1.000 F:5035 small :3382
1st Qu.:102501 1st Qu.: 80.29 1st Qu.: 2.000 M:4965
medium:5469
Median :105001 Median : 151.65 Median : 2.000 big :1149
Mean :105001 Mean : 249.46 Mean : 2.428
3rd Qu.:107500 3rd Qu.: 295.50 3rd Qu.: 3.000
Max. :110000 Max. :7606.09 Max. :22.000
The following code provides some common R functions that include descriptive
statistics. In parentheses, the comments describe the functions.
Search WWH ::




Custom Search