head(women)
## height weight
## 1 58 115
## 2 59 117
## 3 60 120
## 4 61 123
## 5 62 126
## 6 63 129
names(women)
## [1] "height" "weight"
attach(women)
These steps are to visiualize my data and see its general structure
plot(height,weight,ylab="Weight (lbs)", xlab= "Height (IN)", main = "Womens weight and Height")
This is giving me a general scatterplot of the data with the first variable named as the predictor. I have given the axis more appropriate and descriptive names.
womensmod<- lm(weight~height)
womensmod
##
## Call:
## lm(formula = weight ~ height)
##
## Coefficients:
## (Intercept) height
## -87.52 3.45
This regression is saying that for every increase of 1 pound we can expect a height increase of 3.45 inches. The intercept can’t really be interpreted in this case.
plot(height,weight,ylab="Weight (lbs)", xlab= "Height (IN)", main = "Womens weight and Height")
abline(-87.52,3.45)
head(women)
## height weight
## 1 58 115
## 2 59 117
## 3 60 120
## 4 61 123
## 5 62 126
## 6 63 129
For a person that is 58 inches tall we expect them to weigh 58*3.45 -87.52. 112.58 This is just over 2% off what we expected.
58*3.45 - 87.52
## [1] 112.58
(115-112.58)/115
## [1] 0.02104348
myresids <- womensmod$residuals
hist(myresids)
The data looks like it is not normal and skewwed left
qqnorm(myresids)
qqline(myresids)
The qq plot also shows the data is not very normal
summary(womensmod)
##
## Call:
## lm(formula = weight ~ height)
##
## Residuals:
## Min 1Q Median 3Q Max
## -1.7333 -1.1333 -0.3833 0.7417 3.1167
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) -87.51667 5.93694 -14.74 1.71e-09 ***
## height 3.45000 0.09114 37.85 1.09e-14 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 1.525 on 13 degrees of freedom
## Multiple R-squared: 0.991, Adjusted R-squared: 0.9903
## F-statistic: 1433 on 1 and 13 DF, p-value: 1.091e-14
This is most of the basic regression and the steps to do it in R