1 / 18

Mastering Descriptive Statistics and Tables in R

Learn how to efficiently generate descriptive statistics and create frequency/contingency tables in R using key functions like summary(), sapply(), and table(). Enhance your data visualization skills!

joannk
Download Presentation

Mastering Descriptive Statistics and Tables in R

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. chapter 7 Descriptive StatisticsFrequency & Contingency Tables Instructor: Huang, Jia-Ping

  2. Contents • Descriptive statistics • Tables

  3. Descriptive statistics The summary() function

  4. Descriptive statistics The summary() does not provide enough information to understand a sample of data. Use a combination of sapply() and functions like mean(), sd(), var(), min(), max(), median(), length(), range(), quantile(), etc., to produce the statistics you need.

  5. sapply() apply() applies a function over the margins of an array sapply() applies a function over a list or vector.

  6. > mydata <- data.frame(x = rnorm(20, 2, 1), y = rnorm(20, 3, 2)) > apply(mydata, 2, sd) x y 0.9729847 1.6987539 > sapply(mydata, sd) x y 0.9729847 1.6987539

  7. Other useful functions describe() in the Hmics package stat.desc() in the pastecs package describe() in the psych package

  8. The aggregate() function We can divide our data set into groups and produce descriptive statistics for each group. This can be done by using the aggregate() function.

  9. The by() function aggregate() only allows you to use single-value functions such as mean(). With by(), you can return several statistics at once.

  10. Tables R provides several methods for creating frequency and contingency tables.

  11. One-way tables table() prop.table()

  12. Two-way tables

  13. Take row/column sums The index 1 refers to the first variable in the table() statement.

  14. Proportions of the overall sum

  15. Add marginal sums

  16. Summary Descriptive statistics is the first step of statistical analysis. Creating frequency/contingency tables is a useful way of data visualization. Important functions:summary(), sapply(), aggregate(), by(), table(), prop.table()

More Related