{"word_count": 2218, "character_count": 15406}
A regression towards mediocrityOriginally, the term regression means “going back”. It gained currency when Sir Francis Galton related the heights of children to the average height of their parents. Galton (1886) found that children whose parents were short were likely to be shorter than average, whereas children whose parents were tall tended to be taller than average. Galton also found that when the parents were “taller than mediocrity”, the children were in general shorter than their parents, while when the parents were “shorter than mediocrity”, the children tended to be slightly taller than their parents. Galton concluded that there was “a regression towards mediocrity” with regards to height.Regression methodsThe inventory of regression methods is vast. Its most popular members are: simple linear regression, multiple regression, Partial-Least-Squares regression, log-linear regression, and logistic regression. This post is the first of a series that covers simple, multiple and logistic regressions which are the most commonly found in linguistics papers.The very basicsLinear regression is the simplest form of regression. It models the linear relationship between two quantitative variables X and Y. X is the variable you are using to make the prediction and Y the variable you want to predict. In statistical parlance, X is the explanatory variable and Y the response variable. You use a linear relationship to predict the value of Y for a given value of X using a straight line called the regression line. A regression line is a single line that best fits the data. If you know the slope and the y-intercept of the regression line, (( The intercept is the parameter that corresponds to the expected value of the response variable when all the explanatory variables are zero. )) then you can input a value for X and predict the value for Y.A condition for the prediction to work is that there must be a statistically significant correlation and a linear relationship between X and Y. The stronger the relationship between X and Y the more accurate your predictions are likely to be.The basicsThe purpose of linear regression is twofold: it can explain one variable by means of another, and it can predict the value of one variable based on the value of the other variable.Let X be the predicting variable and Y the variable to explain. The linear model is defined by:[latex display="true"]Y = \beta_0 + \beta_{1} X + \epsilon[/latex]where [latex]\beta_0[/latex] is the intercept (the value at which the fitted line crosses the y-axis), [latex]\beta_1[/latex] is the slope, and [latex]\epsilon[/latex] the error component. I explain these concepts below.Case studyThe following simple linear regression is based on Desagulier (2016). In this paper, I adapt productivity measures implemented in morphology to a multiple-slot construction A as NP in the BNC-XML. The construction is exemplified in (1)–(3).  Oh you'll be, be as right as rain by that time. (BNC G42) He was a poor, meagre creature (...), thin as a rail from long starving in the woods (...) (BNC HGG) She was good as gold; I don't know what he would've done without her! (BNC GWB)We want to compare two measures. The first measure is what Baayen (2009) calls realized productivity: V(C,N). It is the type count V of a linguistic category C in a corpus of N tokens. Here, C is restricted to adjectives and N is the number of A as NP constructions. The second measure is [latex]\mathscr{P}[/latex], which measures “potential productivity”. It is based on V(1,C,N), which is the number of hapax legomena of a linguistic category C in a corpus of N tokens.[latex]\mathscr{P}[/latex] is the ratio of the number of hapax legomena for a given category and the sum of all tokens that display the category:[latex]\mathscr{P}=\frac{V(1,C,N)}{N(C)}[/latex].[latex]\mathscr{P}[/latex] corresponds to the probability of encountering new types. The larger the number of hapax legomena, the larger[latex]\mathscr{P}[/latex] and the productivity of the affix. One known issue with V is that it does not discriminate between established forms and new forms. Indeed, types are not distributed uniformly in a corpus, and the larger the corpus, the harder it is to find innovations. [latex]\mathscr{P}[/latex] is therefore considered a far more reliable measure. Out of curiosity, let us see to what extent V predicts[latex]\mathscr{P}[/latex].A simple linear regression in RWhat follows is an implementation inspired by Cornillon et al. (2012), a very clear textbook on statistics with R (in French). We use the data set linearreg_adjectives.rds, which is available for download from Nakala.rm(list=ls(all=TRUE))df &#60;- readRDS("/linearreg_adjectives.rds")In the data frame contains 402 observations (one for each type of adjective) of three variables: V, V1, and [latex]\mathscr{P}[/latex]. We ignore V1 for the time being. We plot the data.plot(P~V, data=df, cex=0.6)[caption id="attachment_594" align="aligncenter" width="500"] Potential productivity as a function of realized productivity[/caption]We observe that the higher V , the higher P , even though the correlation is not perfect. To create a linear model of[latex]\mathscr{P}[/latex] as a function of V , we use the lm() function and the following standard notation: Y ∼ X .reg.model &#60;- lm(P~V, data=df)summary(reg.model)R outputs the following:Call: lm(formula = P ~ V, data = df)Residuals:      Min         1Q       Median      3Q      Max-0.0116975 -0.0001844 -0.0001844 0.0003152 0.0096277Coefficients:              Estimate  Std. Error t value Pr(&#62;|t|) (Intercept)  6.840e-04 8.988e-05   7.61    1.98e-13 *** V            2.829e-04 9.566e-06  29.57     &#60; 2e-16 *** --- Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1Residual standard error: 0.001579 on 400 degrees of freedomMultiple R-squared: 0.6861,Adjusted R-squared: 0.6854F-statistic: 874.5 on 1 and 400 DF, p-value: &#60; 2.2e-16summary(reg.model) displays a description of the specified model. First, Residuals shows how the residuals are distributed. Second, the Coefficients matrix displays the two regression coefficients (also known as parameters, one per line). Each coefficient is described by four variables: the estimate, the estimated standard error (( It is a single summary number that tells you how accurate your predictions are going to be. )), the associated t-value (knowing that under [latex]H_{0}[/latex] [latex]\beta_{i} = 0[/latex], whereas under [latex]H_{1}[/latex] [latex]\beta_{i} \neq 0[/latex]), (( Before you collect corpus data, you must ask a theory-informed question, which you convert into a research hypothesis. Basically, you make a statement about something that you suppose to be the case and then collect corpus evidence based on this statement. (...) A hypothesis breaks down into two parts: the alternative hypothesis and the null hypothesis. The alternative hypothesis ([latex]H_{1}[/latex]) posits a relation of dependence between the response variable and the explanatory variables. The null hypothesis ([latex]H_{0}[/latex]) posits a relation of independence between them. (Desagulier 2017, 160)) the significance levels associated with the t-value (the more stars there are, the more significant).The coefficients [latex]\beta_0[/latex] (the intercept) and V are estimated by 0.000684 and 0.0002829 respectively. The associated significance levels are smaller than 5%, and are in fact very close to zero, which indicates that for each of those tests, [latex]H_{0}[/latex] can be rejected. This means that the intercept should appear in the model, and that the relationship between [latex]\mathscr{P}[/latex] and V is significant. The last three lines of the output display the residual standard error, the multiple [latex]R^2[/latex], the [latex]R^2[/latex] adjusted for the degrees of freedom, the F statistic for the model, and its associated p-value. In a linear regression, only multiple and adjusted [latex]R^2[/latex] values are relevant. The value of [latex]R^2[/latex] is 0.6861, which means that 68% of the variability of [latex]\mathscr{P}[/latex] is explained by V. There is indeed a linear relationship between these two variables.The fitted regression lineTo visualize this linear relation, we plot the fitted regression line with abline(). When abline() takes a linear model as an argument, the function extracts the intercept and the slope to plot the fitted line (That information is otherwise available by entering: reg.model$coef).plot(P~V, data=df, cex=0.6)abline(reg.model)[caption id="attachment_605" align="aligncenter" width="500"] Potential productivity as a function of realized productivity (with a fitted regression line)[/caption]The residualsThe next step consists in examining the residuals. If we want to use the model predictively, we need to make sure that there is a limited number of outliers and that 95% of residuals be found inside a reasonable interval. You normally extract the residuals with the residuals() function. However, because the variances of the residuals at different input variable values often differ (a phenomenon known as heteroscedasticity), mathematicians recommend that we use so-called “studentized” residuals (Cornillon and Matzner-Løber 2010). Such residuals are obtained with the function rstudent().studentized.res &#60;- rstudent(reg.model)We plot the studentized residuals for inspection.plot(studentized.res, pch=18, cex=0.6, ylab="studentized residuals", ylim=c(-3,3))abline(h=c(-2,0,2), lty=c(2,1,2), col=c("brown", "red", "brown"), lwd=2)[caption id="attachment_607" align="aligncenter" width="500"] Studentized residuals[/caption]A quick glance at the plot shows that 12 out of 402 residuals (3%) are beyond the [−2, 2] range. Therefore, 97% of the residuals are within a [−2, 2] range, which is good.PredictionWe can now predict a value of [latex]\mathscr{P}[/latex] based on a new value of V . Suppose we find an adjective whose type frequency in the construction is 32. First, we vectorize this value of V . Next, we convert the numeric vector into a data frame that consists of one observation and one variable. This is because prediction is done with the predict() function, which takes a data frame as input. Note that the name of the variable must be the same as the name of the same variable in our original data frame. Finally, we run predict(), whose arguments are the linear model, the data frame containing the new value, and a specification that the interval must be a prediction interval (as opposed to a confidence interval).newV &#60;- 32newV &#60;- as.data.frame(newV)colnames(newV) &#60;- "V"predict(reg.model, newV, interval="prediction")R outputs the following:      fit          lwr        upr1 0.009735763 0.006584295 0.01288723We see that if V = 32, the predicted value of [latex]\mathscr{P}[/latex] is 0.0097. The 95% prediction interval is [0.0066, 0.013].Rather than focus on a single value of V or the observed discret values in our data set, we can predict [latex]\mathscr{P}[/latex] over the full range of V . First, create a data frame that consists of a sequence of 100 equally-spaced values of V that range from its minimum to its maximum values.range.V.pred &#60;- data.frame(V = seq(min(df[,"V"]), max(df[,"V"]), length=100))With predict(), generate the prediction and confidence values based on the new range of values of V obtained above.CI.pred &#60;- predict(reg.model, interval = "prediction", newdata = range.V.pred)CI.confid &#60;- predict(reg.model, interval = "confidence", newdata = range.V.pred)Replicate the first plot from above making sure the y axis can accommodate the full range of the prediction interval thanks to the ylim argument.plot(df$V,      df$P,      xlab = "realized productivity (V)",      ylab = "potential productivity (P)",     ylim = range(df$P, CI.pred),     cex=0.6)With matlines(), plot six lines: the lower and upper limits of the prediction and confidence intervals and the fitted line (which is plotted twice). The limits of the prediction interval appears appear as dotted red lines. The limits of the confidence interval appear as dashed blue lines. The fitted line appears as a solid red line.# plot the prediction intervalmatlines(range.V.pred$V, CI.pred, lty = c(1,3,3), lwd=2, col = "red")# plot the confidence intervalmatlines(range.V.pred$V, CI.confid, lty = c(1,2,2), lwd=2, col = c("red", "blue", "blue"))Finally, we add a legend.legend("topleft", lty=1:3, lwd=2, col=c("red", "blue", "red"), c("fitted line", "confidence interval", "prediction interval"))We obtain the plot below, which allows us to evaluate both the quality of both the linear model and its predictive value.[caption id="attachment_612" align="aligncenter" width="500"] Potential productivity as a function of realized productivity (with confidence and prediction intervals)[/caption]Let us focus first on the fitted line and the confidence interval. The observations are distributed evenly on either side of the fitted line. The higher V , the further the observations are from the fitted line. The confidence interval is more reliable for adjectives with lower V values: the vast majority of these observations are found within the confidence interval. This is hardly surprising because there are fewer adjectives with a high type frequency. Consequently, the model is better for lower V values.The same conclusion can be made with respect to predictions. The higher V , the higher the number of errors. Most adjectives with high V values are plotted outside the prediction interval. If you make predictions of [latex]\mathscr{P}[/latex] based on the current linear model, the higher V, the more careful you should be when interpreting the values resulting from the fit.There are two reasons why this is the case. Firstly, although the model displays a fairly good fit (as evidenced by the output of summary(reg.model)), [latex]\mathscr{P}[/latex] is based on V1, not V. As opposed to V1, V does not discriminate between entrenched forms and new forms. Just because an adjective has a high type frequency does not mean that it is productive (i.e. used in novel constructions). It should therefore come as no surprise that the higher V, the worse the fit. Secondly, adjectives with a high type frequency are rare when compared to adjectives with a lower type frequency. The fewer the observations, the less reliable the predictions.ReferencesBaayen, Rolf Harald (2009). “Corpus linguistics in morphology: Morphological productivity.” In: Corpus Linguistics. An International Handbook. Ed. by Anke Lüdeling and Merja Kytö. Berlin: Mouton de Gruyter, pp. 899–919.Cornillon, Pierre-André and Éric Matzner-Løber (2010). Régression avec R. Paris, Berlin, Heidelberg, New York: Springer.Cornillon Pierre-André , Arnaud Guyader, François Husson, Nicolas Jégou, Julie Josse, Maela Kloareg, Éric Matzner-Løber and Laurent Rouvière (2012). Statistiques avec R. Rennes : Presses Universitaires de Rennes.Desagulier, Guillaume (2016). “A lesson from associative learning: asymmetry and productivity in multiple- slot constructions.” In: Corpus Linguistics and Linguistic Theory 12.1.Desagulier, Guillaume (2017). Corpus Linguistics and Statistics with R. Introduction to Quantitative Methods in Linguistics. New York: Springer.[cite]Cite this article as: {author}, "{title}," in {sitename}, {publication_date}, {permalink}.[/cite]