๐ŸŽฒ Week 4: Probability and Sampling

Master Probability Theory and Statistical Simulation ๐ŸŽฏ

Welcome to Week 4! This week, we explore probability theory and sampling techniques - essential foundations for statistical inference in agricultural research. Learn to simulate probability experiments, work with distributions, and understand randomness!

๐ŸŽฏ What You'll Learn This Week

๐Ÿ” Logical Variables - TRUE/FALSE operations and comparisons
๐Ÿ”„ Data Type Conversion - Transform between different R data types
๐ŸŽฏ Random Sampling - Use sample() function for population sampling
๐Ÿช™ Coin Toss Simulation - Model probability experiments programmatically
๐ŸŽฒ Dice Roll Simulation - Understand Central Limit Theorem effects
๐Ÿ“Š Normal Distributions - Use rnorm(), pnorm(), and qnorm() functions

๐Ÿš€ Getting Started: Step-by-Step Guide

Step 1: Launch Week 4 Binder Environment ๐ŸŒ

Click the "Launch Week 4" button above to start your R environment. This will take 2-5 minutes to load with all necessary packages for probability and sampling.

Step 2: Navigate to Class Activity ๐Ÿ“š

Once Binder loads, you'll see the Jupyter Notebook interface. In the left panel, you'll see:

Click on the class_activity folder to access this week's content.

Step 3: Open the Week 4 Lab Notebook ๐Ÿ“–

Inside the class_activity folder, double-click on Week4_Probability_Sampling.ipynb to open the interactive lab notebook.

Step 4: Explore Probability Concepts ๐ŸŽฒ

This week we'll work with simulated data and probability distributions! The notebook will guide you through:

๐ŸŽฏ Interactive Learning Tools

Practice with Probability Simulation Tools

Use these interactive tools to understand probability concepts before working with R code:

๐Ÿ’ก Tip: Use these tools to visualize probability concepts before applying them in your R notebook!

๐Ÿงฎ Key R Functions This Week

Probability and Sampling

sample(x, size, replace = TRUE/FALSE) # Random sampling
set.seed(number) # Reproducible results
table(data) # Frequency counts
sum(logical_vector) # Count TRUE values
length(data) # Total observations

Normal Distribution Functions

rnorm(n, mean = 0, sd = 1) # Generate random normal data
pnorm(q, mean = 0, sd = 1) # Calculate probabilities
qnorm(p, mean = 0, sd = 1) # Find quantiles
pnormGC(q, mean, sd, graph = TRUE) # Visual probability (tigerstats)

Data Type Conversion

as.numeric(x) # Convert to numeric
as.character(x) # Convert to character
as.factor(x) # Convert to factor
as.logical(x) # Convert to logical
data.frame(x) # Convert to data frame

๐Ÿ“ Assignment 4: Probability Simulation

Step 1: Access Assignment Folder ๐Ÿ“‹

From the main directory, click on the assignment folder to access Assignment 4.

Step 2: Open Assignment 4 Notebook ๐Ÿ“„

Double-click on Assignment4.ipynb to open your assignment on probability simulation.

Assignment Overview (20 points total)

๐ŸŽฒ

Part 1: Simulation (6 points)

Simulate 50 coin flips and 50 dice rolls

๐Ÿ“Š

Part 2: Probability Calculation (6 points)

Calculate experimental probabilities and compare to theoretical

๐Ÿ“ˆ

Part 3: Data Frames and Visualization (8 points)

Create probability distributions and bar plots

Step 3: Simulate Probability Experiments ๐ŸŽฏ

The assignment focuses on fundamental probability concepts:

Learn to work with discrete probability distributions and understand sampling variability!

๐ŸŒพ Why This Matters in Agriculture

๐ŸŒฑ Seed Germination Studies - Model probability of germination success
๐ŸŒง๏ธ Weather Risk Assessment - Simulate drought and frost probabilities
๐Ÿงช Quality Control Sampling - Random sampling of agricultural products
๐Ÿ”ฌ Field Trial Design - Understanding sampling variability
๐Ÿ› Pest Management - Model probability distributions of pest occurrence

Probability Skills Help You:

๐Ÿ’พ Saving Your Work

โš ๏ธ Important: Binder environments are temporary! Always save your work locally.

Download Your Notebook ๐Ÿ“ฅ

When you're done working, save your progress:

  1. Save your notebook: File โ†’ Save
  2. Download .ipynb file: File โ†’ Download
  3. Export HTML/PDF: File โ†’ Save and Export Notebook As โ†’ HTML

Continue Your Progress Later ๐Ÿ”„

To resume your work:

  1. Launch Binder again
  2. Click Upload button
  3. Upload your saved .ipynb file
  4. Continue where you left off!

๐Ÿ“ค Submission Requirements

For Assignment 4, submit TWO files to UC Davis Canvas:

๐Ÿ“„

HTML/PDF Report

Your completed assignment with all outputs and analysis

๐Ÿ’พ

.ipynb File

Your notebook code as backup

Due Date: Check Canvas for assignment deadline

๐ŸŽฏ Learning Objectives

By the end of this week, you will be able to:

โœ… Understand logical variables and data type conversions
โœ… Perform random sampling with and without replacement
โœ… Simulate probability experiments (coins, dice)
โœ… Work with normal distribution functions
โœ… Compare experimental and theoretical probabilities
โœ… Visualize probability distributions with bar plots

โ“ Need Help?

๐Ÿ“ง Contact Information

Mohammadreza Narimani
๐Ÿ“ง mnarimani@ucdavis.edu
๐Ÿซ Department of Biological and Agricultural Engineering, UC Davis

๐Ÿ”ง Common Issues

๐Ÿ“š Additional Resources

๐ŸŒŸ Tips for Success

๐Ÿ’ก Best Practices

โšก Keyboard Shortcuts

Shift + Enter Run current cell and move to next
Ctrl + Enter Run current cell and stay in place
Tab Auto-complete function names
?function Get help for any R function

๐ŸŽ‰ Ready to Start?

Click the Binder badge below to launch Week 4!

Happy probability exploring! ๐ŸŽฒ๐ŸŒพ