Question

In: Statistics and Probability

Generate a scatter plot of this data, and include a smoothed function using smooth.spline function in...

Generate a scatter plot of this data, and include a smoothed function using smooth.spline function in R. Use predict function in R to calculate the 95% bounds (confidence band) for the mean, and plot them on the same scatterplot (use lty=2, and col=3).

How would I go about writing this code in R?

Solutions

Expert Solution

 

ggplot(mpg, aes(displ, hwy)) + geom_point() + geom_smooth()

#> `geom_smooth()` using method = 'loess' and formula 'y ~ x'

# Use span to control the "wiggliness" of the default loess smoother # The span is the fraction of points used to fit each local regression: # small numbers make a wigglier curve, larger numbers make a smoother curve. ggplot(mpg, aes(displ, hwy)) + geom_point() + geom_smooth(span = 0.3)

#> `geom_smooth()` using method = 'loess' and formula 'y ~ x'

# Instead of a loess smooth, you can use any other modelling function: ggplot(mpg, aes(displ, hwy)) + geom_point() + geom_smooth(method = lm, se = FALSE)

ggplot(mpg, aes(displ, hwy)) + geom_point() + geom_smooth(method = lm, formula = y ~ splines::bs(x, 3), se = FALSE)

# Smoothes are automatically fit to each group (defined by categorical # aesthetics or the group aesthetic) and for each facet ggplot(mpg, aes(displ, hwy, colour = class)) + geom_point() + geom_smooth(se = FALSE, method = lm)

ggplot(mpg, aes(displ, hwy)) + geom_point() + geom_smooth(span = 0.8) + facet_wrap(~drv)

#> `geom_smooth()` using method = 'loess' and formula 'y ~ x'


Related Solutions

What is the purpose of a scatter diagram (Scatter plot)? (Please provide Scatter plot examples)
What is the purpose of a scatter diagram (Scatter plot)? (Please provide Scatter plot examples)
Below are four bivariate data sets and the scatter plot for each. (Note that each scatter...
Below are four bivariate data sets and the scatter plot for each. (Note that each scatter plot is displayed on the same scale.) Each data set is made up of sample values drawn from a population. x y 1.0 10.0 2.0 9.0 3.0 8.0 4.0 7.0 5.0 6.0 6.0 5.0 7.0 4.0 8.0 3.0 9.0 2.0 10.0 1.0 x 1 2 3 4 5 6 7 8 9 10 11 y 1 2 3 4 5 6 7 8 9...
a. Construct a scatter plot of the data. Determine the order of the polynomial that is represented by this data.
  Consider the following data: x 1 4 5 7 8 12 11 14 19 20 y 1 54 125 324 512 5,530 5,331 5,740 7,058 7,945 Use Excel to resolve: a. Construct a scatter plot of the data. Determine the order of the polynomial that is represented by this data. b. Obtain an estimate of the model identified in part a. c. Conduct a test of hypothesis to determine if a third- order, as opposed to a first-order, polynomial...
For the following data​ (a) display the data in a scatter​ plot, (b) calculate the correlation...
For the following data​ (a) display the data in a scatter​ plot, (b) calculate the correlation coefficient​ r, and​ (c) make a conclusion about the type of correlation. The ages​ (in years) of 6 children and the number of words in their vocabulary ​ Age, x 1 2 3 4 5 6 Vocabulary​ size, y 150 1100 1150 1800 2050 2700 A] The correlation coefficient r is
For the following problems, construct a scatter plot using excel. After the plot is drawn, analyze...
For the following problems, construct a scatter plot using excel. After the plot is drawn, analyze it to determine which type of relationship, if any, exists. Enter data in the excel worksheet (let’s say in column A you enter x data, in B you enter y data)à Select Data --> CLICK Insert --> Click Scatter --> Click the first case that contains unconnected points -->release the mouse                                     If you choose layout 9, you get the regression equation that can...
Find the equation of the regression line for the given data. Then construct a scatter plot...
Find the equation of the regression line for the given data. Then construct a scatter plot of the data and draw the regression line. (The pair of variables have a significant correlation.) Then use the regression equation to predict the value of y for each of the given x-values, if meaningful. The table below shows the heights (in feet) and the number of stories of six notable buildings in a city. Height : 772, 628, 518, 508, 496, 483, y:...
Find the equation of the regression line for the given data. Then construct a scatter plot...
Find the equation of the regression line for the given data. Then construct a scatter plot of the data and draw the regression line.​ (The pair of variables have a significant​ correlation.) Then use the regression equation to predict the value of y for each of the given​ x-values, if meaningful. The table below shows the heights​ (in feet) and the number of stories of six notable buildings in a city. Height comma x 762 621 515 508 491 480...
Find the equation of the regression line for the given data. Then construct a scatter plot...
Find the equation of the regression line for the given data. Then construct a scatter plot of the data and draw the regression line.​ (The pair of variables have a significant​ correlation.) Then use the regression equation to predict the value of y for each of the given​ x-values, if meaningful. The table below shows the heights​ (in feet) and the number of stories of six notable buildings in a city. Height comma xHeight, x 766766 620620 520520 508508 494494...
Find the equation of the regression line for the given data. Then construct a scatter plot...
Find the equation of the regression line for the given data. Then construct a scatter plot of the data and draw the regression line.​ (Each pair of variables has a significant​ correlation.) Then use the regression equation to predict the value of y for each of the given​ x-values, if meaningful. The caloric content and the sodium content​ (in milligrams) for 6 beef hot dogs are shown in the table below. font size decreased by 1 font size increased by...
Find the equation of the regression line for the given data. Then construct a scatter plot...
Find the equation of the regression line for the given data. Then construct a scatter plot of the data and draw the regression line.​ (Each pair of variables has a significant​ correlation.) Then use the regression equation to predict the value of y for each of the given​ x-values, if meaningful. The caloric content and the sodium content​ (in milligrams) for 6 beef hot dogs are shown in the table below. font size decreased by 1 font size increased by...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT