Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

R Question (RStudio): 3. The manager of the purchasing department of a large com

ID: 3276826 • Letter: R

Question

R Question (RStudio):
3. The manager of the purchasing department of a large company would like to develop a regression model to predict the average amount of time it takes to process a given number of invoices. Over a 30-day period, data are collected on the number of invoices processed and the total time taken (in hours). The data are available on the book web site in the file invoices.txt. The following model was fit to the data: Y = +A++ e where Y is the processing time and x is the number of invoices. A plot of the data and the fitted model can be found in Figure 2.7. Utilizing the output from the fit of this model provided below, com- plete the following tasks. (a) Find a 95% confidence interval for the start-up time, ie.A. (b) Suppose that a best practice benchmark for the average processing time for an additional invoice is 0.01 hours (or 0.6 minutes). Test the null hypothesis Ho : B = 0.01 against a two-sided alternative. Interpret your result. (c) Find a point estimate and a 95% prediction interval for the time taken to proc- ess 130 invoices.

Explanation / Answer

Answer:

Rcode:

y<-c(2.1,1.8,2.3,0.8,2.7,1,1.7,3.1,2.8,1,1.5,1.2,0.8,1,2,2.5,2.9,3.4,4.1,1.2,2.5,1.8,3.8,1.5,2.8,2.5,3.3,2,1.7,1.5)

x<- c(149,60,188,23,201,58,77,222,181,30,110,83,60,25,173,169,190,233,289,45,193,70,241,103,163,120,201,135,80,29)

mydata <- data.frame(x,y)

model <-lm(y~x, data = mydata)

summary(model)

anova(model)

confint(model)

new <- data.frame(x = c(130))

pred_interval <- predict(model,new, interval=" prediction",level = 0.95)

pred_interval

ttest1 <- function(model, coefnum, val){

co <- coef(summary(model))

tstat <- (co[coefnum,1]-val)/co[coefnum,2]

   2*pt(abs(tstat), model$df.residual,lower.tail = FALSE)

}

ttest1(model,2,0.01)

R output:

y<-c(2.1,1.8,2.3,0.8,2.7,1,1.7,3.1,2.8,1,1.5,1.2,0.8,1,2,2.5,2.9,3.4,4.1,1.2,2.5,1.8,3.8,1.5,2.8,2.5,3.3,2,1.7,1.5)

> x<- c(149,60,188,23,201,58,77,222,181,30,110,83,60,25,173,169,190,233,289,45,193,70,241,103,163,120,201,135,80,29)

> mydata <- data.frame(x,y)

> model <-lm(y~x, data = mydata)

> summary(model)

Call:

lm(formula = y ~ x, data = mydata)

Residuals:

     Min       1Q   Median       3Q      Max

-0.59516 -0.27851 0.03485 0.19346 0.53083

Coefficients:

             Estimate Std. Error t value Pr(>|t|)   

(Intercept) 0.6417099 0.1222707   5.248 1.41e-05 ***

x           0.0112916 0.0008184 13.797 5.17e-14 ***

---

Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

Residual standard error: 0.3298 on 28 degrees of freedom

Multiple R-squared: 0.8718,    Adjusted R-squared: 0.8672

F-statistic: 190.4 on 1 and 28 DF, p-value: 5.175e-14

> anova(model)

Analysis of Variance Table

Response: y

          Df Sum Sq Mean Sq F value    Pr(>F)   

x          1 20.702 20.7020 190.36 5.175e-14 ***

Residuals 28 3.045 0.1088                     

---

Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

> confint(model)

                  2.5 %     97.5 %

(Intercept) 0.391249620 0.89217014

x           0.009615224 0.01296806

95% CI for B = (0.3912, 0.8922)

> new <- data.frame(x = c(130))

> pred_interval <- predict(model,new, interval="prediction",level = 0.95)

> pred_interval

       fit      lwr    upr

1 2.109624 1.422947 2.7963

95% prediction interval when x=130 is (1.4229, 2.7963)

> ttest1 <- function(model, coefnum, val){

+   co <- coef(summary(model))

+   tstat <- (co[coefnum,1]-val)/co[coefnum,2]

+    2*pt(abs(tstat), model$df.residual,lower.tail = FALSE)

+ }

> ttest1(model,2,0.01)

[1] 0.1257402

Test for =0.01 , calculated P=0.1257 which is > 0.05 level.

Ho is not rejected.