If you look back to the previous R post, the value of the intercept is the same as the mean environmental impact of beef. This tells us that the intercept b0 is equal to 353.6. So, to determine the environmental impact for beef, we set the independent variable to 0: While the assignment of 0 and 1 can be done manually, R recognizes the names variable we created as a factor and automatically assigns these values for us. These kind of variables are sometimes referred to as dummy variables. The simplest ways to code these two variables is to assign the value of 0 to one of the groups and 1 to the other. When a study has two conditions, beef and pork in our case, the independent variable has only two values. As a more concrete example, let’s write out the linear model for our sample dataset: The above generic formula is a little cryptic. Thinking about our dataset in terms of linear models The funny looking E, the Greek letter epsilon, represents the error term and is the variance in the data that cannot be explained by our model. In this equation, Ai represents the dependent variable (i.e., the outcome variable), b0 is the intercept, b1 is the weighting of the independent variable (i.e., predictor) and Gi is the independent variable. The structure of a basic linear model is: They are all versions of the following model: Linear model basicsĪll statistical procedures are pretty much the same. The key thing is that you obtain the same results using the t.test() function or the linear model approach. So don’t worry if your dataset and statistical results are different than mine. This is because we will be using a different sample of values. Because the data is generated using sample(), executing the code a second time will generate a different dataset. The dataset was created using the following R code: In our previous R post, we created a fictional dataset on the environmental impact (measured in kilograms of carbon dioxide) of pork and beef production. The dataset: Environmental impact of pork and beef A simple example like this one is a good place to start. Why bother with this? Linear models can be extended to perform more complex statistical analyses, but they can be confusing to newcomers. In the present post we will learn a little about linear models and figure out how to perform an independent t-test using a linear model approach. What you may not have realised is that both these statistical tests are actually linear models in disguise. For those of you who are familiar with statistics, you likely know that an independent t-test is equivalent to performing an one-way analysis of variance on the data. My last two posts have shown how to perform an independent t-test in the R programming language and the Python programming language.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |