Here is an example of importing a data set, performing a regression analysis, and creating a plot of the coefficients.

Importing the data

Let’s work with the “R_Workshop_data.csv” file. Recall that the file contains 52 individuals and 4 variables. The variables are: respondents id (“id”), a binary variable indicating whether the respondent is male or female (“male” where “1” is male), a measure of the respondent’s age (“age”), and a measure of risky behaviors engaged in by the respondent (“risky”).

Let’s go ahead and import it into R:

setwd("/…") #first, set the directory where the file is.
data <- read.csv(
  "https://www.jacobtnyoung.com/uploads/2/3/4/5/23459640/r_workshop_data.csv", #the url.
  header=TRUE, as.is=TRUE, na.strings="." #all the other arguments remain the same.
  )
data[1:20,] #look at the first 20 cases of the data.

Analyzing the data

Suppose we are interesting if whether there is a linear relationship between a respondent’s age and his/her risky behaviors. Let’s plot the relationship between the variables to visually inspect them: