Extracting power of a power law from data My question is more about the methodology. Assuming in some experiment we have measured quantity $y$ per each unit of time $x.$ So $y$ and $x$ form our data set here. Moreover, we know that they are related by a
power law type of relation, e.g., $y = D x^{\alpha},$ where $D$ is just a constant. 
Now to extract $\alpha$ from the data-set, I know two ways:


*

*a) Calculating the logs of our data, we can then compute the derivative of the $\ln(y)$ w.r.t $\ln(x),$ so $\frac{d\ln y}{d\ln x}=\alpha$ and extract the power. One problem with this is that the sampling may not have been done logarithmically, so the spacings between the log'ed values are different. That means numerically it is going to be hard to accurately compute such derivative.

*b) Another way would be: taking the logs again as in above, but then we just fit the log'ed data with a line, the slope of which should give us an average $\alpha,$ right? Assuming this is correct, one problem is that if $\alpha$ is changing during different time scales of the experiment, the above fit wouldn't capture it. Maybe one could perform the fits piece-wise.
Questions:


*

*Have I laid out the above methods correctly? (e.g., is b) correct?)

*Does one method come more recommended or it really depends on the context? (i.e., in view of the aforementioned difficulties) Finally, please feel free to suggest other ways of extracting $\alpha$ if you know of different methods, I'm very curious to find out.


(If you prefer explaining your method with an example, I have created dummy data for purposes of illustration, here's the link, first column is $x$ and second column $y.$)

Clarifications upon reading discussions in the comment section:
The aim here is only to tackle the problem of how to reasonably estimate (for instance by fitting) power laws that describe a given bivariate data set, and more precisely, finding power laws that correspond to each region of interest [*] (i.e., subsets of the data). With this in mind, what the user Nick Cox has proposed as answer, is precisely on point.
[*]: thus e.g., fitting subsets of the data, and more contextually, looking for different power laws at different time-scales, because for instance from a physical point of view we expect the data to exhibit different power laws.
 A: As in my first comment on the question I see this as being entirely about power laws for bivariate data. (The inclination to read it otherwise is puzzling.) 
Based on the posted data, I did local polynomial smoothing; the choices here are no more than not very smart defaults in the program used, but equally there doesn't seem much need to play with other choices. (The $R^2$ here is just the square of the correlation between observed and smoothed; 1 isn't even a target as interpolating the data could achieve that.) 

It seems clear that the slope stabilises fairly quickly and systematically in logarithmic space, so that numerical differentiation could give you estimates of slope as it changes. 
A: Edit: The question is actually about data in which $x$ and $y$ are allowed to vary. This answer is not relevant to that case, but only to the case when $x$ is a quantity and you want to fit a distribution of the form $f(x) \propto x^{\alpha}$ to it. However, I am leaving it up because it links to a paper which is state-of-the-art for this case, which may be useful for some readers who are confused (like I was) by the question title.
I suggest reading the following paper by Clauset, Shalizi and Newman. It recommends using maximum likelihood to fit a power law (so, not taking logs and fitting a straight line at all).
Even if you know that the data follow a power law and you are just trying to find an exponent, it might still not be appropriate to fit a straight line to the log-log plot with least squares. This is because, if you fit such a line, any statistical calculations are implicitly assuming that the errors in measuring $\log(y)$ are normally distributed, which may not be true, depending on circumstances. See Appendix A of the above paper.
