![]() You must use the Shift Key to access the "tilde. The symbol separating "height" and "age" in the syntax height~age is a "tilde." It is located on the key to the immediate left of the the #1 key on your keyboard. The syntax height~age is called a model equation and is a very sophisticated R construct. The command lm is a very sophisticated command with a host of options (type ?lm to view a full description), but in its simplest form, it is quite easy to usea. We will use R's lm command to compute a "linear model" that fits the data in Figure 1. Take two points, usually the beginning point and the last. Finding the line of best fit formula can be done using the point slope method. In this next activity, we will calculate and plot the Line of Best Fit, or the Least Squares Regression Line. The line of best fit formula is y mx + b. One could not fit a single line through each and every data point, but one could imagine a line that is fairly close to each data point, with some of the data points appearing above the line, others below for balance. ![]() As the age increases, the average height increases at an approximately constant rate. Note that the data in Figure 1 is approximately linear. Because the ages are incremented in months, we can use the command age=18:29, which uses R start:finish syntax to begin a vector at the number 18, then increment by 1 until the number 29 is reached.įigure 1. To build our scatter plot, we must first enter the data in R. The data is presented in the table that follows. ![]() The heights were averaged and recorded each month, with the study lasting several years. Researchers measured the heights of 161 children in Kalama, a village in Egypt. The data set in the table that follows is taken from The Data and Story Library. We will first learn to create a scatter plot for the given data, then we will learn how to craft a "Line of Best Fit" for our plot. In this activity we will explore the relationship between a pair of variables. ![]()
0 Comments
Leave a Reply. |