Master Custom Functions and Statistical Comparisons 🎯
Welcome to Week 7! This week, we explore custom functions in R and two-sample t-tests - essential skills for creating reusable code and comparing groups in agricultural research. Learn to write functions, perform statistical tests, and interpret results!
Click the "Launch Week 7" button above to start your R environment. This will take 2-5 minutes to load with all necessary packages for functions and t-tests.
Once Binder loads, you'll see the Jupyter Notebook interface. In the left panel, you'll see:
assignment/ - Assignment 7 on fertilizer treatment comparisonclass_activity/ - Week 7 lab tutorialClick on the class_activity folder to access this week's content.
Inside the class_activity folder, double-click on Week7_Regression_Analysis.ipynb to open the interactive lab notebook.
This week we'll work with custom functions and the iris dataset! The notebook will guide you through:
Use these interactive tools to understand function creation and t-test concepts before working with R code:
💡 Tip: Use these tools to practice function syntax and visualize t-test concepts before applying them in your R notebook!
myFunction <- function(arg1, arg2) { # Define function result <- arg1 + arg2 # Function body return(result) # Return value} # End function
calculate_sample_size <- function(prev, alpha, margin_error) { z <- qnorm(1 - alpha / 2) # Critical z-value n <- z^2 * prev * (1 - prev) / (margin_error^2) return(ceiling(n)) # Round up}
t.test(group1, group2, alternative = "two.sided") # Two-sided testt.test(group1, group2, var.equal = FALSE) # Welch's t-testt.test(group1, group2, alternative = "greater") # One-sided testdata %>% filter(Species == "setosa") # Data filtering
From the main directory, click on the assignment folder to access Assignment 7.
Double-click on Assignment7.ipynb to open your assignment on t-tests for agricultural data.
Load wheat yield data and create visualizations
Set up null and alternative hypotheses
Perform two-sample t-test and interpret results
Analyze p-values and draw conclusions
Test if nitrogen fertilizer yields are higher
The assignment focuses on agricultural research applications:
Learn to make evidence-based agricultural decisions using statistical testing!
⚠️ Important: Binder environments are temporary! Always save your work locally.
When you're done working, save your progress:
To resume your work:
.ipynb fileFor Assignment 7, submit TWO files to UC Davis Canvas:
Your completed assignment with all outputs and analysis
Your notebook code as backup
Due Date: Check Canvas for assignment deadline
By the end of this week, you will be able to:
Mohammadreza Narimani
📧 mnarimani@ucdavis.edu
🏫 Department of Biological and Agricultural Engineering, UC Davis
?function for help with R functionsClick the Binder badge below to launch Week 7!
Happy function building and testing! 🔧📊