Get startedGet started for free

Finding The Regression Coefficients in R

We can find the regression coefficients for our data using the lm() function, which takes our model as the first argument: first the y variable, followed by a ~ symbol, then the x variable. For instance: lm(y ~ x). The output labels the value of the intercept with 'intercept', and the value of the slope with the name of the independent variable. Let's try this out with our study that investigated how money (independent variable) predicted prosocial behavior (dependent variable).

This exercise is part of the course

Basic Statistics

View Course

Exercise instructions

  • In your script, write a line of code using the lm() function to find the regression coefficients for how much money predicts prosocial behavior
  • Take a look at the output

Hands-on interactive exercise

Have a go at this exercise by completing this sample code.

# Our data
money <- c(1,2,3,4,5,6,7,8,9,10)
prosocial <- c(3, 2, 1, 4, 5, 10, 8, 7, 6,9)
# Find the regression coefficients
Edit and Run Code