R Tutorial: Counts vs. proportions

DataCamp · Beginner ·🎨 Image & Video AI ·6y ago

Key Takeaways

The video tutorial demonstrates how to compute proportions and conditional proportions in R using the prop.table function and visualize the results using bar charts with the ggplot function, specifically using the position = 'fill' option to display proportions.

Full Transcript

you may have noticed in the last exercises that sometimes raw accounts of cases can be useful but often it's the proportions that are more interesting we can do our best to compute those proportions in our head or we could do it explicitly let's return to our table of counts of cases by identity and alignment if we wanted to instead get a sense of the proportion of all cases that fell into each category we can take the original table of counts saved as tab underscore CNT and provided as input to the prop table function we see here that the single largest category is characters that are bad and secret at about 29 percent of characters also note that because these are all proportions out of the whole data set the sum of all these proportions is 1 if we're curious about the systematic associations between variables we should look to conditional proportions an example of a conditional proportion is the proportion of public identity characters that are good to build a table of these conditional proportions add a 1 as the second argument specifying that you'd like to condition on the rows we see here that around 57% of all secret characters are bad because we're conditioning on identity it's every road that now sums to 1 to condition on the columns instead you can change that argument to 2 now it's the columns that sum to 1 and we learn for example that the proportion of bad characters that are secret is around 63% as the number of cells in these tables gets large it becomes much easier to make sense of your data using graphics the bar chart is still a good choice but we're going to need to add some options here's the code for the bar chart based on comps we want to condition on whatever's on the x-axis and then stretch those bars to each add up to a total proportion of 1 so we add the position equals fill option to the Giambi our function let's add one additional layer it changed to our y-axis to indicate that we're looking at proportions when we run this code at the console we get a plot that reflects our table of proportions after we had conditioned on ID while the proportion of secret characters that are bad is still large it actually it's actually less than the proportion of bad care ders and those that are listed as unknown we get a very different picture if we condition instead on alignment the only change needed in the code is to swap the positions of the names of the variables this results in a plot where we've conditioned on alignment and we learned that within characters that are bad the greatest proportion of those are indeed secret this might seem paradoxical but it's just a result of having different numbers of cases in each level okay now you try experimenting with conditional proportions

Original Description

Want to learn more? Take the full course at https://learn.datacamp.com/courses/exploratory-data-analysis at your own pace. More than a video, you'll learn hands-on coding & quickly apply skills to your daily work. --- You may have noticed in the last exercises that sometimes raw counts of cases can be useful, but often it's the proportions that are more interesting. We can do our best to compute these proportions in our head or we could do it explicitly. Let's return to our table of counts of cases by identity and alignment. If we wanted to instead get a sense of the proportion of all cases that fell into each category, we can take the original table of counts, saved as tab underscore cnt, and provide it as input to the prop dot table function. We see here that the single largest category are characters that are bad and secret at about 29% of characters. Also note that because these are all proportions out of the whole dataset, the sum of all of these proportions is 1. If we're curious about systematic associations between variables, we should look to conditional proportions. An example of a conditional proportion is the proportion of public identity characters that are good. To build a table of these conditional proportions, add a 1 as the second argument, specifying that you'd like to condition on the rows. We see here that around 57% of all secret characters are bad. Because we're conditioning on identity, it's every row that now sums to one. To condition on the columns instead, change that argument to 2. Now it's the columns that sum to one and we learn, for example, that the proportion of bad characters that are secret is around 63%. As the number of cells in these tables gets large, it becomes much easier to make sense of your data using graphics. The bar chart is still a good choice, but we're going to need to add some options. Here is the code for the bar chart based on counts. We want to condition on whatever is on the x axis and stretch those bars to
Watch on YouTube ↗ (saves to browser)
Sign in to unlock AI tutor explanation · ⚡30

Playlist

Uploads from DataCamp · DataCamp · 0 of 60

← Previous Next →
1 SQL Server Tutorial: Date manipulation
SQL Server Tutorial: Date manipulation
DataCamp
2 R Tutorial: Intermediate Interactive Data Visualization with plotly in R
R Tutorial: Intermediate Interactive Data Visualization with plotly in R
DataCamp
3 R Tutorial: Adding aesthetics to represent a variable
R Tutorial: Adding aesthetics to represent a variable
DataCamp
4 R Tutorial: Moving Beyond Simple Interactivity
R Tutorial: Moving Beyond Simple Interactivity
DataCamp
5 Python Tutorial: Why use ML for marketing? Strategies and use cases
Python Tutorial: Why use ML for marketing? Strategies and use cases
DataCamp
6 Python Tutorial: Preparation for modeling
Python Tutorial: Preparation for modeling
DataCamp
7 Python Tutorial: Machine Learning modeling steps
Python Tutorial: Machine Learning modeling steps
DataCamp
8 R Tutorial: The prior model
R Tutorial: The prior model
DataCamp
9 R Tutorial: Data & the likelihood
R Tutorial: Data & the likelihood
DataCamp
10 R Tutorial: The posterior model
R Tutorial: The posterior model
DataCamp
11 R Tutorial: An Introduction to plotly
R Tutorial: An Introduction to plotly
DataCamp
12 R Tutorial: Plotting a single variable
R Tutorial: Plotting a single variable
DataCamp
13 R Tutorial: Bivariate graphics
R Tutorial: Bivariate graphics
DataCamp
14 Python Tutorial: Customer Segmentation in Python
Python Tutorial: Customer Segmentation in Python
DataCamp
15 Python Tutorial: Time cohorts
Python Tutorial: Time cohorts
DataCamp
16 Python Tutorial: Calculate cohort metrics
Python Tutorial: Calculate cohort metrics
DataCamp
17 Python Tutorial: Cohort analysis visualization
Python Tutorial: Cohort analysis visualization
DataCamp
18 R Tutorial: Building Dashboards with flexdashboard
R Tutorial: Building Dashboards with flexdashboard
DataCamp
19 R Tutorial: Anatomy of a flexdashboard
R Tutorial: Anatomy of a flexdashboard
DataCamp
20 R Tutorial: Layout basics
R Tutorial: Layout basics
DataCamp
21 R Tutorial: Advanced layouts
R Tutorial: Advanced layouts
DataCamp
22 Python Tutorial: Time Series Analysis in Python
Python Tutorial: Time Series Analysis in Python
DataCamp
23 Python Tutorial: Correlation of Two Time Series
Python Tutorial: Correlation of Two Time Series
DataCamp
24 Python Tutorial: Simple Linear Regressions
Python Tutorial: Simple Linear Regressions
DataCamp
25 Python Tutorial: Autocorrelation
Python Tutorial: Autocorrelation
DataCamp
26 R Tutorial: The gapminder dataset
R Tutorial: The gapminder dataset
DataCamp
27 R Tutorial: The filter verb
R Tutorial: The filter verb
DataCamp
28 R Tutorial: The arrange verb
R Tutorial: The arrange verb
DataCamp
29 R Tutorial: The mutate verb
R Tutorial: The mutate verb
DataCamp
30 R Tutorial: What is cluster analysis?
R Tutorial: What is cluster analysis?
DataCamp
31 R Tutorial: Distance between two observations
R Tutorial: Distance between two observations
DataCamp
32 R Tutorial: The importance of scale
R Tutorial: The importance of scale
DataCamp
33 R Tutorial: Measuring distance for categorical data
R Tutorial: Measuring distance for categorical data
DataCamp
34 Python Tutorial: Plotting multiple graphs
Python Tutorial: Plotting multiple graphs
DataCamp
35 Python Tutorial: Customizing axes
Python Tutorial: Customizing axes
DataCamp
36 Python Tutorial: Legends, annotations, & styles
Python Tutorial: Legends, annotations, & styles
DataCamp
37 Python Tutorial: Introduction to iterators
Python Tutorial: Introduction to iterators
DataCamp
38 Python Tutorial: Playing with iterators
Python Tutorial: Playing with iterators
DataCamp
39 Python Tutorial: Using iterators to load large files into memory
Python Tutorial: Using iterators to load large files into memory
DataCamp
40 SQL Tutorial: Introduction to Relational Databases in SQL
SQL Tutorial: Introduction to Relational Databases in SQL
DataCamp
41 SQL Tutorial: Tables: At the core of every database
SQL Tutorial: Tables: At the core of every database
DataCamp
42 SQL Tutorial: Update your database as the structure changes
SQL Tutorial: Update your database as the structure changes
DataCamp
43 Python Tutorial: Classification-Tree Learning
Python Tutorial: Classification-Tree Learning
DataCamp
44 Python Tutorial: Decision-Tree for Classification
Python Tutorial: Decision-Tree for Classification
DataCamp
45 Python Tutorial: Decision-Tree for Regression
Python Tutorial: Decision-Tree for Regression
DataCamp
46 Python Tutorial: Census Subject Tables
Python Tutorial: Census Subject Tables
DataCamp
47 Python Tutorial: Census Geography
Python Tutorial: Census Geography
DataCamp
48 Python Tutorial: Using the Census API
Python Tutorial: Using the Census API
DataCamp
49 R Tutorial: A/B Testing in R
R Tutorial: A/B Testing in R
DataCamp
50 R Tutorial: Baseline Conversion Rates
R Tutorial: Baseline Conversion Rates
DataCamp
51 R Tutorial: Designing an Experiment - Power Analysis
R Tutorial: Designing an Experiment - Power Analysis
DataCamp
52 R Tutorial: Introduction to qualitative data
R Tutorial: Introduction to qualitative data
DataCamp
53 R Tutorial: Understanding your qualitative variables
R Tutorial: Understanding your qualitative variables
DataCamp
54 R Tutorial: Making Better Plots
R Tutorial: Making Better Plots
DataCamp
55 SQL Tutorial: OLTP and OLAP
SQL Tutorial: OLTP and OLAP
DataCamp
56 SQL Tutorial: Storing data
SQL Tutorial: Storing data
DataCamp
57 SQL Tutorial: Database design
SQL Tutorial: Database design
DataCamp
58 Python Tutorial: Introduction to spaCy
Python Tutorial: Introduction to spaCy
DataCamp
59 Python Tutorial: Statistical Models
Python Tutorial: Statistical Models
DataCamp
60 Python Tutorial: Rule-based Matching
Python Tutorial: Rule-based Matching
DataCamp

This video tutorial teaches how to calculate and visualize proportions and conditional proportions in R, which is essential for exploratory data analysis. By following the steps, viewers can learn how to use the prop.table function and ggplot to create informative bar charts.

Key Takeaways
  1. Load the necessary R libraries
  2. Create a table of counts
  3. Compute proportions using prop.table
  4. Visualize proportions using ggplot with position = 'fill'
  5. Condition on rows or columns by specifying the second argument in prop.table
  6. Experiment with different variables and conditioning options
💡 Conditional proportions can reveal systematic associations between variables, and visualizing these proportions can help make sense of large datasets.

Related Reads

📰
How can I batch-generate 3D assets from prompts or images using an API, and which 3D generation APIs support batch generation?
Learn to batch-generate 3D assets from prompts or images using APIs for efficient pipeline creation
Reddit r/artificial
📰
How AI Head Swap Works: The Technology Behind Realistic AI Image Replacement
Learn how AI head swap technology works and its applications in image editing
Dev.to AI
📰
How I Built an AI Pet Portrait Generator That Turns Photos Into Art
Learn how to build an AI pet portrait generator that turns photos into art using deep learning techniques and Python libraries
Dev.to · William Li
📰
I Put Google’s Squoosh Codecs in the Browser — and Cut My Image Bill Before the Upload Even…
Learn how to use Google's Squoosh codecs in the browser to compress images before upload and reduce costs
Medium · Programming
Up next
Google Nano Banana AI Image Generator 🤯 Create & Edit Images in Seconds | Latest Google AI Tool 2026
Learn with Fatimah Gondal
Watch →