3
$\begingroup$

I have a set of data, basically measuring the running time of an algorithm against some gathered input. This is the summary of data:

  size           time       
Min.   :      0   Min.   :1.360e+04 
1st Qu.:   1006   1st Qu.:7.357e+05 
Median :   2410   Median :2.167e+06 
Mean   :  10565   Mean   :1.127e+07 
3rd Qu.:   7113   3rd Qu.:7.030e+06 
Max.   :1369374   Max.   :1.503e+09  

When I plot the data, I observe a linear dependency and this is the result of lm(time~size):

Residuals:
       Min         1Q     Median         3Q        Max 
-716682545   -1431468   -1129352    -521418 1228545549 

Coefficients:
              Estimate Std. Error t value Pr(>|t|)    
(Intercept)  1.043e+06  3.673e+05   2.839  0.00454 ** 
newdata$size 9.680e+02  9.013e+00 107.394  < 2e-16 ***
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Residual standard error: 27100000 on 5835 degrees of freedom
Multiple R-squared:  0.664, Adjusted R-squared:  0.664 
F-statistic: 1.153e+04 on 1 and 5835 DF,  p-value: < 2.2e-16

This is the output of lm((log(time) ~ log(size)):

Residuals:
    Min      1Q  Median      3Q     Max 
-2.9079 -0.1558  0.1037  0.2855  3.7981 

Coefficients:
                  Estimate Std. Error t value Pr(>|t|)    
(Intercept)       5.801648   0.035039   165.6   <2e-16 ***
log(newdata$size) 1.113745   0.004323   257.6   <2e-16 ***
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Residual standard error: 0.4673 on 5835 degrees of fr![enter image description here][1]eedom
Multiple R-squared:  0.9192,    Adjusted R-squared:  0.9192 
F-statistic: 6.638e+04 on 1 and 5835 DF,  p-value: < 2.2e-16

Is log-log or normal scatter plot a better way to show this linear dependency? Here are the images: normal, log-log

$\endgroup$
9
  • $\begingroup$ Could you post your plots here? That might help. Note that the coefficient of your log-log analysis is close to 1, suggesting close to proportionality (beyond the intercept) between your 2 variables. Technical issue is which presentation will minimize some relevant measure of residual error. $\endgroup$ – EdM Jul 16 '15 at 19:29
  • 1
    $\begingroup$ A graph that is linear on a log-log plot is not exponential: it's a power relationship. (Linear graphs on log-linear plots are exponential.) You are, in effect, asking why a power law with a power around $1.113\ldots \approx 1$ might look approximately linear. It is difficult to provide a specific answer because your regressions appear to involve completely different data: what are terminal_nodes (in the first regression) and how are they related to size (in the summary data and second regression)? $\endgroup$ – whuber Jul 16 '15 at 19:30
  • $\begingroup$ Perhaps it's notation (being a physicist here) but wouldn't a linear slope on a log-log plot mean $y\sim x^n$ (power-law) and not exponential? $\endgroup$ – Kyle Kanos Jul 16 '15 at 19:30
  • $\begingroup$ @whuber sorry, it was a mistake, I've updated the post $\endgroup$ – Wickoo Jul 16 '15 at 19:45
  • $\begingroup$ @EdM I added the plots $\endgroup$ – Wickoo Jul 16 '15 at 19:45
1
$\begingroup$

From these plots you almost certainly should be working on the log-log scale. It's best if the error is independent of the value of the variables, and by eye that is much more the case for the log-log plot than for the linear plot. Note for example how the big outlier in the upper left of the linear plot becomes much closer to the cloud of points in the log-log plot. Furthermore, the points fill the display much better in the log-log plot. As noted in the comments to the question, a power of 1.11 is pretty close to linear.

$\endgroup$
5
  • $\begingroup$ Thanks! for drawing a regression line should I use lm in R or lsfit? I also saw somewhere someone using LOWESS? how about that? $\endgroup$ – Wickoo Jul 16 '15 at 20:04
  • $\begingroup$ Before you consider your work done you should examine the distribution of residuals and determine whether the log-log fit is good enough for your purposes. If you want a standard single regression line you do not want LOWESS, which is a combination of several locally weighted fits. In R you can use the abline command with the coefficients fromlm to add a line to the plot. $\endgroup$ – EdM Jul 16 '15 at 20:23
  • $\begingroup$ thanks. Sorry if it sounds stupid, but how to know which distribution of residuals is good? And i don't remove outliers, is it necessary? $\endgroup$ – Wickoo Jul 16 '15 at 20:30
  • $\begingroup$ By eye it looks like there is a cloud of cases having x values between 200 and 2000 (2 x 10^2 to 2 x 10^3) that might end up substantially below your log-log linear regression line. You might want to pay attention to those points, depending on the purposes of your analysis. $\endgroup$ – EdM Jul 16 '15 at 20:30
  • 1
    $\begingroup$ Don't remove outliers unless you know they were erroneous data. Read the documentation for plot.lm for ways to display residuals and evaluate their relations to predicted values, the influence of individual observations, etc. You would like residuals (here, on the log scale) to be independent of the predicted value and evenly distributed above and below 0; ideally, some would argue they should have a normal distribution. Consider this an opportunity to learn about regression diagnostics. $\endgroup$ – EdM Jul 16 '15 at 20:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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