x=c(3,5,2,3,1,4,6,4,3,0)
y=c(300,300,500,400,700,400,100,250,450,600)
plot(x,y,
xlab="Oil Changes Per Year",
ylab="Repair Costs",
main="Repair Costs Compared to Amount of Oil Changes")
lm.res=lm(y~x)
abline(lm.res)
lm.res
##
## Call:
## lm(formula = y ~ x)
##
## Coefficients:
## (Intercept) x
## 673.5 -88.2
yhat=673.53-88.24*x
yhat
## [1] 408.8 232.3 497.0 408.8 585.3 320.6 144.1 320.6 408.8 673.5
plot(x,y,
pch=20,col="red",
xlab="x=Oil Changes per Year",
ylab="y=Repair Costs",
main="Repair Costs Compared to Amount of Oil Changes")
abline(lm.res)
points(x,yhat,pch=15,col="green")
abline(h=0)
Based off of the plots shown the linear model does seem approproaite because the line of best fit matches the phat values.
data=read.delim("ldi13_4.dat",header=TRUE)
data
## Time Distance P Q RES_1
## 1 0.16 12.1 0.4000 75.62 42.283
## 2 0.24 29.8 0.4899 124.17 18.088
## 3 0.25 32.7 0.5000 130.80 15.751
## 4 0.30 42.8 0.5477 142.67 -0.334
## 5 0.30 44.2 0.5477 147.33 1.066
## 6 0.32 55.8 0.5657 174.38 2.192
## 7 0.36 63.5 0.6000 176.39 -11.056
## 8 0.36 65.1 0.6000 180.83 -9.456
## 9 0.50 124.6 0.7071 249.20 -23.273
## 10 0.50 129.7 0.7071 259.40 -18.173
## 11 0.57 150.2 0.7550 263.51 -34.332
## 12 0.61 182.2 0.7810 298.69 -23.280
## 13 0.61 189.4 0.7810 310.49 -16.080
## 14 0.68 220.4 0.8246 324.12 -21.739
## 15 0.72 254.0 0.8485 352.78 -9.086
## 16 0.72 261.0 0.8485 362.50 -2.086
## 17 0.83 334.6 0.9110 403.13 13.907
## 18 0.88 375.5 0.9381 426.70 28.622
## 19 0.89 399.1 0.9434 448.43 46.985
D=data$Distance
T=data$Time
plot(T,D,col="red",
xlab="Time",
ylab="Distance",
main="Distance Fallen Compared to Time")
lm.res=lm(D~T)
abline(lm.res)
lm.res
##
## Call:
## lm(formula = D ~ T)
##
## Coefficients:
## (Intercept) T
## -114 524
yhat=-114+523.7*x
yhat
## [1] 1457.1 2504.5 933.4 1457.1 409.7 1980.8 3028.2 1980.8 1457.1 -114.0
plot(x,y,
pch=20,col="blue",
xlab="x=Time",
ylab="y=Distance",
main="Distance Fallen Compared to Time")
abline(lm.res)
points(x,yhat,pch=15,col="purple")
P=sqrt(T)
plot(P,D)
lm.res=lm(D~P)
abline(lm.res)
Q=D/T
plot(T,Q)
lm.res=lm(Q~T)
abline(lm.res)
Based off of these plots a linear model doesn’t seem appropriate.
Q and T seem to have the closest to a linear relationship.