```{r} # Load the tidyverse and openintro libraries library(tidyverse) library(openintro)
data(fastfood) fastfood fastfood <- tbl_df(fastfood)
```{r}
resto <- (fastfood$restaurant)
cal <- (fastfood$)
```{r}
fastfood_1 <- tbl_df(fastfood)
## 1 scatterplot
When you click the **Render** button a document will be generated that includes both content and the output of embedded code. You can embed code like this:
```{r}
# Create a scatterplot
ggplot( fastfood, aes(x = sugar, y = calories)) +
geom_point() +
geom_smooth(method = "lm", se = FALSE) +
labs(x = "Sugar (g)", y = "Calories") +
ggtitle("Relationship between Sugar and Calories")
The predictor variable is sugar
The outcome variable is calories
```{r}
model <- lm(calories ~ sugar, data = fastfood)
summary(model)
calories = 398.130 + 18.284 x sugar
## 5 calories and total carbohydrates
```{r}
ggplot(fastfood, aes(x = calories, y = total_carb)) +
geom_point() +
geom_smooth(method = "lm", se = FALSE) +
labs(title = "Relationship between Calories and Total Carbohydrates",
x = "Calories",
y = "Total Carbohydrates (g)")
```{r}
model_calories_carbs <- lm(total_carb ~ calories, data = fastfood) summary(model_calories_carbs)
```{r}
plot(model_calories_carbs, 1:2)
The alignment of the points with the diagonal line on the Normal Q-Q plot suggests that the residuals conform to a normal distribution, thereby confirming the accuracy of the linear regression model.
Total_carb = 12.328 + 0.063 × calories
The intercept coefficient of 12.328 shows the predicted total carbs when the calories count is zero. However, this interpretation may not be relevant in this case, as it is improbable to encounter a scenario where calories are nonexistent.
The value of 0.063 indicates the increase in total carbs for each one-unit increase in calories. It indicates that for each extra calorie consumed, there is an expected rise of about 0.063 grams in total carbs.
The Adjusted R^2 value for this model is 0.507, which implies that the stregth of the model is relatively Strong.
```{r}
model2 <- lm(calories ~ sugar + total_fat + restaurant + protein, data = fastfood)
summary(model2)
The Adjusted R^2 value for the multiple linear regression model you provided is 0.91.
The model using these predictors demonstrates a strong fit to the data, including a significant amount of the variability in the calorie content of the fast food products.
## Suggestions
```{r}
# Create the multiple linear regression model with additional predictors
model_3 <- lm(calories ~ sugar + total_fat + total_carb + fiber + sodium + sat_fat, data = fastfood)
# Provide the summary of the model
summary(model_3)
The Adjusted R^2 value for the multiple linear regression model you provided is 0.9539.
The second model has stronger match to the data than the first Model, indicated by the higher adjusted R^2 value. This indicates that Model 2 could provide a more thorough comprehension of the elements that affect calorie content in fast food items.