### Linear scatterplot with best fitting line: Mostpain with Mobil and Educ
plot(Wk01a$Mobil,Wk01a$Mostpain, main="Mostpain and Mobil",
xlab="Mobil ", ylab="Mostpain", pch=16)
# Add fit lines
abline(lm(Wk01a$Mostpain~Wk01a$Mobil), col="red") # regression line (y~x)
plot(Wk01a$Educ,Wk01a$Mostpain, main="Mostpain and Educ",
xlab="Educ ", ylab="Mostpain", pch=16)
# Add fit lines
abline(lm(Wk01a$Mostpain~Wk01a$Educ), col="red") # regression line (y~x)
### 3. Linear + quadratic scatterplot of Mostpain with Mobil and Educ
### IV = Mobil
plot(Mostpain~Mobil, data=Wk01a, pch=16, col="orange")
# fit the model
curve.fit1 = lm(Mostpain~poly(Mobil,2), data=Wk01a)
# create 100 x-values based on min/max of plotted values
minMax1 = range(Wk01a$Mobil)
xVals1 = seq(minMax1[1], minMax1[2], len = 100)
# Use predict based on a dataframe containing 'Mobil'
yVals1 = predict(curve.fit1, newdata = data.frame(Mobil = xVals1))
lines(xVals1, yVals1,col="darkblue")
### IV = Educ
plot(Mostpain~Educ, data=Wk01a,pch=16,col="darkgreen")
# fit the model
curve.fit2 = lm(Mostpain~poly(Educ,2), data=Wk01a)
# create 100 x-values based on min/max of plotted values
minMax2 = range(Wk01a$Educ)
xVals2 = seq(minMax2[1], minMax2[2], len = 100)
# Use predict based on a dataframe containing 'Educ'
yVals2 = predict(curve.fit2, newdata = data.frame(Educ = xVals2))
lines(xVals2, yVals2,col="red")