Assume a Spherical Cow
In this activity, you will analyze some data using R
and interpret the output. The purpose is for you to know how to start an analysis in R
and interpret the output. It is also to have you understand the importance of control variables in your research.
Part O: Data Set Information
We will be working with a single data file today. It is the cattleData2 file located at
https://rfs.kvasaheim.com/data/cattleData2.csv
You will start a new script and import these data into R
in the usual way
dt = read.csv("https://rfs.kvasaheim.com/data/cattleData2.csv") attach(dt)
Note that it contains the following four variables measured on cattle.
- weight: The weight of the cow when taken to the slaughterhouse (in pounds).
- ranch: The ranch that raised the cow.
- feedType: The brand of feed that the cow ate throughout its life.
- age: The age of the cow when taken to slaughter (in months).
Each row corresponds to a different cow brought to the slaughterhouse. As an aside, a former student of mine at Oklahoma State gathered these data as a part of his master’s project. The project looked to model the weight of the cattle as they pass into the slaughterhouse.
Part I: Weight and Age
This part has us model the weight of the cattle using just the age of the cow.
mod1 = lm(weight ~ age) summary(mod1)
If you did everything correct, then the output will be:
Call: lm(formula = weight ~ age) Residuals: Min 1Q Median 3Q Max -233.475 -46.347 1.634 46.616 218.671 Coefficients: Estimate Std. Error t value Pr(>|t|) (Intercept) 305.862 26.603 11.50 <2e-16 *** age 49.927 1.329 37.57 <2e-16 *** --- Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 Residual standard error: 69.36 on 1350 degrees of freedom Multiple R-squared: 0.5111, Adjusted R-squared: 0.5107 F-statistic: 1411 on 1 and 1350 DF, p-value: < 2.2e-16
Note that there are four sections to the output. What do the four sections tell us and how do we interpret the results?
Part II: Weight and Feed Type
This part has you model the weight as a function of the type of feed the cattle ate. How many feed types are there? Perform the analysis.
mod2 = lm(weight ~ feedType) summary(mod2)
So, from this analysis, is there a difference in the average weights? If so, which gives the heaviest cattle? What is your evidence?
Part III: Weight and Ranch
Then, again, perhaps the weight difference depends on the ranch raising the cattle. It makes sense that some ranches are better at raising cattle than others.
Perform the appropriate analysis to determine if there is a difference among the ranches. Is there? How do you know? Provide the statistics that supports your conclusion.
Part IIII: Modeling Weight
Ultimately, the research question focuses on whether there is a preferred feed to make the cattle grow larger. From your analysis above, it appears as though age, feed type, and ranch affect the weight of the cattle.
Since we only care about the effect of feed type, that is our research variable. Since we know (or strongly suspect) that the other two variables also affect weight, they are our control variables. They must be included to help control for their effects in the cattle.
Run this additive model:
mod4 = lm(weight ~ age + feedType + ranch)
and determine if there is evidence that there is a best feed type. If there is, which is it? What is your evidence?
Submission
All of the above guided you through some analyses and asked you to contemplate the results (and why those steps were performed). When learning a new technique, this is the process you need to follow. Make sure you know why those steps are followed. Know what the process tells you. In other words: While the code will change with the times, the process you need to use to understand the procedure will not.
Answer the following and submit by the assigned date (remember that you need to use LaTeX and the fHomework style file).
- In Model IIII, you modeled weight with age, feed type, and ranch using an additive model.
- For your submission, model the same variables with an interaction model and determine if there is evidence that there is a best feed type.
- If there is, which is it? What is your evidence?
- As always, show your work.
The Aerodynamics of a Non-Spherical Cow