I've been trying to make a univariate linear regression with two columns of my data imported from an csv file. However, the program does not seem to recognise the name of the columns whether I name them after their headers or the column's name in RStudio (V1, V2 etc.).
patient_data1 = read.csv("C:\\PATHWAY_PLACEHOLDER, header = TRUE")
patient_data2 = data.frame(patient_data1)
attach(patient_data)
names(patient_data)
class(HR)
## plot a x/y scatter plot with the data
plot(HR, RAZscor, main = "Scatterplot")
cor(HR, RAZscor)
## create a "linear model" = the regression
patient_regression <- lm(HR ~ RAZscor, data=patient_data)
## generate a summary of the regression
summary(patient_regression)
## add the regression line to x/y scatter plot
abline(patient_regression, col="blue")
When running the program, the error message "object 'HR' not found" shows up. I'm new to R and have been trying different things, but can't seem to figure out what I'm doing wrong.
I would expect the two columns named "HR" and "RAZscor" in the file to be used as x- and y-coordinates for data points in a scatter plot, in which a linear regression would be formed. I've tried using different techniques to save the columns in objects, and I've tried e.g. calling the objects with the method "patient_data2$HR" when plotting it, but then the object "patient_data2" cannot be found either.