R studio assignment

profileJimmy22
Math211R-Assignment4.edited.docx

Running head: MATH 211 1

MATH 211 2

Math 211 R-Assignment 4

Name

Institutional Affiliation

Date of Submission

Math 211 R-Assignment 4

Questions: Q1. Create a data frame of the above table. Call the data frame old. You may call the variables anything you want but make them meaningful.

In The data frame, the state is denoted by the letter z, and the forms are represented by numbers, running from 1 to 8 as follows: Delaware=1, Florida=2, Georgia=3, Maryland=4, North Carolina=5, South Carolina =6, Virginia=7, West Virginia =8

The Percentage of No Natural Teeth is represented by x, and the Unemployment Rate is represented by y.

Z=State

Percentage of No Natural Teeth=x

Unemployment Rate=y

To Make a data frame, we run the following codes in R-Studio

Codes

z= c(1, 2, 3, 4, 5, 6, 7, 8)

x = c(16.4, 13.3, 21.0, 13.6, 21.5, 21.6, 15.0, 36.0)

y = c(4.9, 5.4, 5.9, 5.2, 5.7, 6.0, 4.4, 6.7)

df <- data.the frame(z, x, y)

Q2. If the goal is to learn whether the unemployment rate is based on the percentage of adults having no natural teeth, which of these two variables is the response variable, and which is the explanatory variable?

In this case,

The unemployment rate is the Response variable (y)

The percentage of adults having no natural teeth is the explanatory variable (x)

Q3. Make a scatterplot of the dataset and add the best fit line. Be sure to label the axes meaningfully.

To Make a scatterplot of the dataset, we run the following codes in R-Studio:

Code:

# Simple Scatterplot attach(mtcars) plot(x,y, main="Scatterplot",    xlab="x ", ylab="y ", pch=19)

To fit the best fit line, we run the following codes in R-Studio:

Code:

# Add regression line

plot(x, y, main = "scatterplot of % of no natural teeth vs unemployment rate",

xlab = "% of no natural teeth", ylab = "Unemployment rate",

pch = 19, frame = FALSE)

abline(lm(y ~ x, data = df), col = "blue")

Q4. Compute R-squared. You need to let R do the computation and show the code.

In this case, to Compute R-squared, we run the following codes in R-Studio

Code

mod <- lm (y ~ x)

summary (mod)

This gives us the value of R-squared (R2) as

R-squared (R2) =0.701 1

Q5. Interpret R-squared.

R-squared is a goodness-of-fit measure for linear regression models. It indicates the percentage of the variance in the dependent variable that the independent variable explains collectively. R-squared measures the strength of the relationship between the model and the dependent variable on a convenient 0 – 100% scale.

In this case, the R-squared (R2) =0.701, which means that about 70.1% of the variance in the dependent variable (Unemployment rate) is explained by the independent variable (percentage of No Natural Teeth).

Q6. Find the least-squares regression line calculating the Unemployment Rate based on Percentage of No Natural Teeth.

To find the least-squares regression line we run the following codes in R-Studio:

Codes

fit <- lm(y ~ x)
> fit
Call:
lm(formula = y ~ x)

This gives the following answer.

Coefficients:

(Intercept) x

3.93247 0.08043

Intercept = 3.93247

X coefficient= 0.08043

y=( slope) x+( intercept)

y= 0.08043X + 3.93247

Unemployment Rate= 0.08043(Percentage of No Natural Teeth) + 3.93247

Q7 . Explain what the slope means, understandable to a general audience.

In this case = 0.08043, this slope indicates that for every unit increase in the Percentage of No Natural Teeth, there is a corresponding 0.08043 rise/increase in the Unemployment rate.

Q8. Explain what the intercept means, understandable to a general audience.

The intercept in this case = 3.93247

This intercept means that When the Percentage of No Natural Teeth, x = 0, then the corresponding Unemployment Rate, y-value is equal to the y-intercept, which is 3.93247. In other words, holding everything constant, the unemployment rate is 3.93247

Q9. Does the intercept have practical value? Explain why or why not briefly.

Yes, the intercept has a practical value. This is because, under normal circumstances, the intercept means that the rate of Unemployment is 3.93247.

Q10. The scatterplot shows an outlier. What state is the outlier?

From the data frame, the state is denoted by the letter z, and the forms are represented by numbers, running from 1 to 8 as follows:

Delaware=1, Florida=2, Georgia=3, Maryland=4, North Carolina=5, South Carolina =6, Virginia=7, West Virginia =8

Looking at the scatterplot,

The outlier is on state number 8, which in this case, is the state of West Virginia.

Q11. Do you think the outlier is an influential point? Explain briefly why or why not.

In this case, I think that the outlier is an influential point because it dramatically affects the regression line's slope.

Q12. Make a new data frame with the outlier removed. Call this data frame new.

In order to Make a new data frame with the outlier removed, we use the following codes

Codes

z= c(1, 2, 3, 4, 5, 6, 7)

x = c(16.4, 13.3, 21.0, 13.6, 21.5, 21.6, 15.0)

y = c(4.9, 5.4, 5.9, 5.2, 5.7, 6.0, 4.4)

df <- data.frame(z, x, y)

Q13. Find the least-squares regression line of the new data frame.

To find the least-squares regression line, we run the following codes in R-Studio:

Codes

fit <- lm(y ~ x)
> fit
Call:
lm(formula = y ~ x)

This gives the following answer.

Coefficients:

(Intercept) x

3.4654 0.1082

Intercept = 3.4654

X coefficient= 0.1082

y=( slope) x+( intercept)

y= 0.1082 X + 3.4654

Unemployment Rate= 0.1082 (Percentage of No Natural Teeth) + 3.4654

        

Q14. Look at the new data frame slope and compare it to the old data frame's hill. Explain briefly why the new slope increased or decreased when the outlier was removed.

In this case, the new slope increased when the outlier has removed the line's angle relative to the x-axis gets smaller, so the hill's absolute value gets more significant in a positive direction.

References

Dalgaard, P. (2008). Introductory statistics with R. Springer Science & Business Media.

image1.png

image2.png