1
$\begingroup$

Stat noob programmer here. I have to predict the time taken to process an order based on the order size. The example data is like following

enter image description here

for example, in the last line there were a total of 7 products with a total of 22 units an an average of 100.9 minutes were taken to process the order.

Now, I need to find the correlation between these values and figure out a way to predict the time taken.

There is also a problem with the data where some of the values are unexpected, because the staff who process the order may pause the operation for a while so the time taken to process that order become unexpectedly large which affects the average time. I think somehow, I need to normalize this data (Normalization is the correct word I suppose) as well.

I have access to the raw data with time taken to process each order in case if something more useful can be made from the original data.

Kindly point me to the right direction.

$\endgroup$

1 Answer 1

2
$\begingroup$

Data: I have put your data ($\pm$ typing errors) into R.

x = c(1,2,3,3, 4,5,6,3, 10,11,12,19, 20,21,22)
y = c(20.5,25.3,29.3,26.0, 32.8,35.2,41.2,26.0, 
      46.7,68.2,62.8,81.6, 80.4,63.5,100.9)

Data summaries:

summary(x); sd(x)
   Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
  1.000   3.000   6.000   9.467  15.500  22.000 
[1] 7.633261  # SD x

summary(y); sd(y)
   Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
  20.50   27.65   41.20   49.36   65.85  100.90 
[1] 25.14068  # SD y

You asked about finding the correlation $r$ between x and y. Here it is:

cor(x,y)
[1] 0.9464411

plot(x,y, pch=20)

enter image description here

Basic regression procedures: The correlation is high and the scatterplot shows a linear association between x and y. So it seems worthwhile to do a linear regression of y on x. I will show some initial steps to get you started.

reg.out = lm(x ~ y)
summary(reg.out)

Call:
lm(formula = x ~ y)

Residuals:
    Min      1Q  Median      3Q     Max 
-3.8805 -0.9149 -0.3976  0.2575  7.4701 

Coefficients:
            Estimate Std. Error t value Pr(>|t|)    
(Intercept) -4.71743    1.49574  -3.154  0.00761 ** 
y            0.28736    0.02719  10.569 9.43e-08 ***
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

Residual standard error: 2.558 on 13 degrees of freedom
Multiple R-squared:  0.8958,    Adjusted R-squared:  0.8877 
F-statistic: 111.7 on 1 and 13 DF,  p-value: 9.434e-08

Both the intercept and slope of a regression model are significant. Here is a plot of the regression line through the scatterplot of the data. So finding the $Y$-value on the line corresponding to an $x$-value should get you started with prediction.

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

enter image description here

I will let you consult a statistics textbook, class notes, or one of many pages online fetched by googling regression r for interpretation and additional procedures. Perhaps start with this page if you need online help. Some of the 'Related' links on this site mentioned in the right margin beside your Question may also be helpful.

In particular, you should look at the residuals from the regression line because points toward the right side of the graph seem to vary more from the line than those toward the left.

$\endgroup$
3
  • $\begingroup$ Hey, Great thanks for your detailed writeup and help. Even though this didn't give me the direct answer I was looking for, but able to figure it out from your writeup. Thanks :) $\endgroup$
    – Shobi
    Commented May 17, 2020 at 16:38
  • 2
    $\begingroup$ Very good outcome then! Sometimes people are only looking for direct answers. So learning something and finishing for yourself shows promise. More important to me than reputation points (which, nevertheless, I do appreciate) $\endgroup$
    – BruceET
    Commented May 17, 2020 at 17:55
  • $\begingroup$ In this case, it is simple to see visually that the data has a linear association. Is there any way to mathematically determine this other than trying linear, exponential, log, etc.? $\endgroup$ Commented May 18, 2020 at 18:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.