Friday, September 22, 2017

Pearson Correlation vs. Spearman Correlation

A correlation coefficient measures the extent to which two variables tend to change together. Two correlation coefficients are commonly used in statistical analysis: the Peason correlation and the Spearman correlation.

The Pearson correlation coefficient, also referred to as the Pearson's r, Pearson product-moment correlation coefficient (PPMCC) or bivariate correlation, is a measure of the linear correlation between two variables X and Y.

The Spearman's rank correlation coefficient is a nonparametric measure of rank correlation (statistical dependence between the ranking of two variables). It assesses how well the relationship between two variables can be described using a monotonic function.

The Pearson correlation measures linear relationships, while the Spearman correlation measures monotonic relationships. Compared to the Pearson correlation, the Spearman correlation ignores the actual values of the data but only use the rank order of the values. The Spearman correlation between two variables is therefore equal to the Pearson correlation between the rank values of those two variables.

Let's look at some examples to understand the relationship between the Pearson correlation and the Spearman correlation.

When a linear relationship exists between two variables, the absolute values of both correlation coefficients are equal to 1.





When a monotonic but nonlinear relationship exists between two variables, the absolute value of Spearman correlation is equal to 1 while the value of Pearson correlation is less than 1.












When the relationship between the two variables are not monotonic, the values of the two correlations are close to 0.



Note that the above figures also report the corresponding two-sided p-values of the correlations, which measures the probability for uncorrelated data exhibiting the same correlation. With a small p-value, we are more confident that the calculated correlation exists between the two variables. Note that the p-values of the Pearson correlation are only valid when the variables are normally distributed or the dataset is large enough so that the central limit theorem applies. The p-values of the Spearman correlation do not suffer from such an issue because as a nonparametric text, the Spearman correlation does not make assumptions about the distributions of the variables.

From the above examples, it seems that the (absolute) values of the Spearman correlation are always greater than the Pearson correlation. This is intuitive: because the Spearman correlation captures any monotonic relationships while the Pearson correlation only captures linear relationships, in the presence of monotonic relationships, the Spearman correlation is the same as the Pearson correlation when a linear relationship exists, and strictly greater when a nonlinear monotonic relationship exists. However, this conjecture is not true when the relationship between two variables are not strictly monotonic, as shown by some examples from Ascombe's quartet. In the second and the fourth examples, the Spearman correlation is less than the Pearson correlation.










Thursday, September 7, 2017

大城市的车比小城市便宜?要逆天?!

前些日子和朋友一起吃饭,提到北京新车的价格要比200多公里之外的唐山便宜上万块钱。赶上旧车型处理或者大型车展,价格差会更大。可是,为什么北京人薪资水平高那么多,车反而便宜?有人说中国之大无奇不有,不合理的事情太多让人认知崩溃?

其实,大城市车价便宜的现象不只存在于中国。笔者在美国印第安纳州上学的时候就经常有朋友到芝加哥去买车,同样也就200多公里的样子,连二手车的价钱都能便宜10%。

那么,为什么在物价其实要高很多的大城市,汽车的价格反而要便宜呢?

造成这种现象的有诸多因素,而所有的因素总结成一个词就是:市场。汽车市场的买卖双方的诸多因素决定了大城市的车要比小城市便宜。

1 供给方面的因素

首先,大城市供应商比较多,竞争更激烈。在大城市,一个品牌的4s店有好几家,在相同品牌的内部竞争就很激烈,更不用说品牌之间的竞争了。这种强烈的竞争导致汽车在大城市的价格弹性比较大。价格弹性,简而言之,就是消费者对价格的敏感程度。价格弹性比较低,以为着价格的变动对消费者的需求影响不大。当我们说大城市的车价格弹性比较大的时候,就是说一家4s店相对调低价格,能够招徕更多的顾客,从而提高销售量和利润。

另一方面,由于规模经济的影响,大城市4s店相对大的销售量会使进货渠道及价格方面比小城市的店有优势,所以能够提供更大的价格优惠。大城市一次进车上百辆,小城市也就十来辆,每辆的运输成本因此会小很多。相同的原因,虽然大城市的租金以及人力成本要比小城市高很多,但是由于销售量大,均摊到每辆车上的成本可能比小城市还要低。

2 需求方面的因素

你可能没有意识到,相同的车,在大城市给人带来的效用要比小城市低。由于大城市的拥堵问题更严重,停车更贵,油价也更贵,同样一辆车,在大城市使用的成本要高很多。尤其北京等城市的限号政策,买了车很多时间只能放在停车场,交着停车费却不能开。因此,虽然在大城市人的薪资高一些,但是买车的意愿以及一辆新车带来的效用并不比小城市的人高。购买意愿低就意味着需求底;在同的条件下,需求底就会导致商品的价格低。

更重要的是,作为开车替代品的公共交通以及共享出行在大城市更方便和普及。在替代品多的情况下,人们对一件商品需求的弹性就相对高一些。所以,需求方面的因素也会导致汽车在大城市的价格弹性比较高,所以对商家来说,相对的调低价格能够增加销售量和利润。

那么,你现在明白了为什么大城市的车要比小城市便宜了?

来,我们画一下重点:由于激烈的竞争以及替代品的存在,汽车在大城市的价格弹性更高,所以商家可以用相对调低价格的方式提高销售量以及利润。同时,由于销售量比较大,导致大城市的4s店每辆车的成本并不比大城市高,甚至会更低。这些因素综合在一起,促使大城市的4s店把车价定的更低,从而提高利润。

往期文章推荐

Monday, July 24, 2017

Factor Analysis

https://blog.dominodatalab.com/how-to-do-factor-analysis/


Factor Analysis and its difference from Principal Component Analysis (PCA)

Factor analysis aims to give insight into the latent variables that are behind people's behavior and the choices that they make. PCA, on the other hand, is all about the most compact representation of a dataset by picking dimensions that capture the most variance. This distinction can be subtle, but one notable difference is that PCA assumes no error of measurement or noise in the data: all of the 'noise' is folded into the variance capturing.

Another important difference is that the number of researcher degrees of freedom, or choices one has to make, is much greater than that of PCA. Not only does one have to choose the number of factors to extract (there are ~10 theoretical criteria which rarely converge), but then decide on the method of extraction (there are ~7), as well as the type of rotation (there are also 7), as well as whether to use a variance or covariance matrix, and so on.

More technically, running a factor analysis is the mathematical equivalent of asking a statistically savvy oracle the following: "Suppose there are N latent variables that are influencing people's choices –tell me how much each variable influence the responses for each item that I see, assuming that there is measurement error on everything". Often times, the 'behavior' or responses that are being analyzed comes in the form of how people answer questions on surveys.


Mathematically speaking, for person i, item j and behavior Yij, Factor analysis seeks to determine the following:

Yij = Wj1 * Fi1 + Wj2 * Fi2 + … + Uij

Where W's are the factor weights or loadings, F's are the factors, and U is the measurement error / the variance that can't be accounted for by the other terms in the equation. The insight of the people who created factor analysis was that this equation is actually a matrix reduction problem.

Types of Factor Analysis

Both exploratory factor analysis (EFA) and confirmatory factor analysis (CFA) are employed to understand shared variance of measured variables that is believed to be attributable to a factor or latent construct. The goal of EFA is to identify factors based on data and to maximize the amount of variance explained. The researcher is not required to have any specific hypotheses about how many factors will emerge, and what items or variables these factors will comprise. If these hypotheses exist, they are not incorporated into and do not affect the results of the statistical analyses.

By contrast, CFA evaluates a priori hypotheses and is largely driven by theory. CFA analyses require the researcher to hypothesize, in advance, the number of factors, whether or not these factors are correlated, and which items/measures load onto and reflect which factors. As such, in contrast to exploratory factor analysis, where all loadings are free to vary, CFA allows for the explicit constraint of certain loadings to be zero.



Checking all the possible correlations of a variable with the others in the set, you can discover that you may have two types of variance:

Unique variance: Some variance is unique to the variable under examination. It cannot be associated to what happens to any other variable.

Shared variance: Some variance is shared with one or more other variables, creating redundancy in the data. Redundancy implies that you can find the same information, with slightly different values, in various features and across many observations.