Question

In: Physics

This question uses the variables dis (the weighted mean of distances to five Boston employment centers)...

  1. This question uses the variables dis (the weighted mean of distances to five Boston employment centers) and nox(nitrogen oxides concentration in parts per 10 million) from the Boston data (library MASS). We will treat dis as the predictor and nox as the response.  

Use the ns() function to fit a natural cubic spline to predict nox using dis. Perform a 5-fold cross-validation in order to select the best degrees of freedom upto 10 degrees.

  • Plot degrees of freedom and its cross validation error.
  • Plot the resulting fits of the best degrees of freedom.

Please use set.seed(1) on the first line of your R code.

Solutions

Expert Solution

For cross-validation or another approach in order to select the best degrees of freedom for a regression spline on this data.

folds <- sample(1:10, size = 506, replace = TRUE) errors <- matrix(NA, 10, 9) models <- list() for (k in 1:10) { for (i in 1:9) { models[[i]] <- lm(nox ~ bs(nox, df = i), data = Boston[folds != k,]) pred <- predict(models[[i]], Boston[folds == k,]) errors[k, i] <- sqrt(mean((Boston$nox[folds == k] - pred)^2)) } } errors <- apply(errors, 2, mean) data_frame(RMSE = errors) %>% mutate(df = row_number()) %>% ggplot(aes(df, RMSE, fill = df == which.min(errors))) + geom_col() + theme_tufte() + guides(fill = FALSE) + scale_x_continuous(breaks = 1:9) + coord_cartesian(ylim = range(errors))

To plot degrees of freedom :

errors <- list() models <- list() pred_df <- data_frame(V1 = 1:506) for (i in 1:9) { models[[i]] <- lm(nox ~ bs(dis, df = i), data = Boston) preds <- predict(models[[i]]) pred_df[[i]] <- preds errors[[i]] <- sqrt(mean((Boston$nox - preds)^2)) } names(pred_df) <- paste(1:9, 'Degrees of Freedom') data_frame(RMSE = unlist(errors)) %>% mutate(df = row_number()) %>% ggplot(aes(df, RMSE, fill = df == which.min(errors))) + geom_col() + guides(fill = FALSE) + theme_tufte() + scale_x_continuous(breaks = 1:9) + coord_cartesian(ylim = range(errors))

Related Solutions

1. Consider the following weighted averages of independent random variables X1, X2, X3, all with mean...
1. Consider the following weighted averages of independent random variables X1, X2, X3, all with mean u and variance σ^2 θ1 = 1/3(X1) + 1/3(X2) + 1/3(X3) θ2 = 1/4(X1) + 2/4(X2) + 1/4(X3) θ3 = 2/5(X1) + 2/5(X2) + 2/5(X3) a) Find E[θ1], E[θ2], E[θ3] b) Are θ1, θ2 and θ3 unbiased for u? Explain c) Find the variance for θ1, θ2 and θ3 d) If you had to use one of the above estimators, which would you pick?...
/*Question 3: The following data contains five columns (variables) and five rows (observations). First, read the...
/*Question 3: The following data contains five columns (variables) and five rows (observations). First, read the data into SAS to create a data set. Notice that the first, third, and the fifth variable have missing values. Please replace the missing values of the first, third, and fifth variable with 30, 40, and 50, respectively. Next, for all the variables, if a value is at least 100, make an adjustment to the value such that its new value is equal to...
Question 1-Process Costing (Weighted-Average Method):  Partners in Crime Paint Company uses the weighted-average method to account for...
Question 1-Process Costing (Weighted-Average Method):  Partners in Crime Paint Company uses the weighted-average method to account for costs of production in its process costing system. Partners in Crime manufactures its base paint in two separate departments:  Mixing and Packaging.  The following information is for the Mixing Department (the first production department in its production process) for the month of March:            Units (gallons) Percent Complete with Respect to DM Percent Complete with Respect to Conversion Costs (DL+OH) Beginning work in process inventory 35,000 100%...
Question 1-Process Costing (Weighted-Average Method):  Partners in Crime Paint Company uses the weighted-average method to account for...
Question 1-Process Costing (Weighted-Average Method):  Partners in Crime Paint Company uses the weighted-average method to account for costs of production in its process costing system. Partners in Crime manufactures its base paint in two separate departments:  Mixing and Packaging.  The following information is for the Mixing Department (the first production department in its production process) for the month of March:            Units (gallons) Percent Complete with Respect to DM Percent Complete with Respect to Conversion Costs (DL+OH) Beginning work in process inventory 35,000 100%...
QUESTION 1 - Please show work for understanding of problem. New Image Sports uses a WEIGHTED...
QUESTION 1 - Please show work for understanding of problem. New Image Sports uses a WEIGHTED AVERAGE process-costing system. For March, the company had the following activities: Beginning work-in-process inventory    6,000 units Units placed in production      24,000 units Units completed  and Transferred Out   25,000 units Cost of beginning work in process -Materials    $ 3,000 Cost of beginning work in process- Conversion Costs    $ 2,000         Direct material costs added in March                                        $18,000 Conversion costs added in March                                             $13,750 Direct materials...
Note: This is one question (1) Highlands Company uses the weighted-average method in its process costing...
Note: This is one question (1) Highlands Company uses the weighted-average method in its process costing system. It processes wood pulp for various manufacturers of paper products. Data relating to tons of pulp processed during June are provided below:   Percent Completed Tons of Pulp Materials Labor and Overhead Work in process, June 1 81,900 81 % 26 % Work in process, June 30 51,000 43 % 12 % Started into production during June 302,000 Required:   1. Compute the number of...
Note: This is one question. Please answer completely. Superior Micro Products uses the weighted-average method in...
Note: This is one question. Please answer completely. Superior Micro Products uses the weighted-average method in its process costing system. During January, the Delta Assembly Department completed its processing of 25,400 units and transferred them to the next department. The cost of beginning work in process inventory and the costs added during January amounted to $669,528 in total. The ending work in process inventory in January consisted of 3,200 units, which were 80% complete with respect to materials and 60%...
Student ID: Question 1 Given are five observations for two variables, x and y. xi yi...
Student ID: Question 1 Given are five observations for two variables, x and y. xi yi 2 25 3 25 5 20 1 30 8 16 a. Develop the regression equation by computing the values of βˆ 0 and βˆ 1. b. Use the estimated regression equation to predict the value of y when x = 6. c. Compute SSE, SST, and SSR. d. Compute the coefficient of determination r 2 . Comment on the goodness of fit. e. Compute...
Topic: Process Costing Question 2 (10 marks) Super Systems Pte Ltd, which uses the weighted-average method...
Topic: Process Costing Question 2 Super Systems Pte Ltd, which uses the weighted-average method of process costing, reported the following: Direct materials ($) Conversion ($) Work-in-process, 1 September 42,000 20,000 September production costs 502,000 325,000 Conversations with the production supervisor revealed that materials are introduced at the start of the production process and conversion costs are incurred evenly throughout the process. The company started 29,000 units during the month of September. Work-in-process at the beginning and end of September totalled...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT