Qual é um exemplo de colinearidade perfeita em termos da matriz de design ?
Gostaria um exemplo onde β = ( X ' x ) - 1 X ' Y não pode ser calculado porque ( X ' X ) não pode ser invertida.
regression
multicollinearity
matrix
matrix-inverse
TsTeaTime
fonte
fonte
Respostas:
Aqui está um exemplo com 3 variáveis,y , x1 e x2 , relacionadas pela equação
ondeε∼N(0,1)
Os dados específicos são
Portanto, é evidente quex2 é um múltiplo de x1 portanto, temos uma colinearidade perfeita.
Podemos escrever o modelo como
Onde:
Então nós temos
Agora calculamos o determinante deXX′ :
Em R, podemos mostrar isso da seguinte maneira:
criar
x2
, um múltiplo dex1
crie y, uma combinação linear de
x1
,x2
e alguma aleatoriedadeobserve aquilo
falha ao estimar um valor para o
x2
coeficiente:A matriz do modeloX é:
EntãoXX′ é
que não é invertível, como mostra a
Ou:
fonte
Aqui estão alguns cenários bastante comuns que produzem multicolinearidade perfeita, ou seja, situações nas quais as colunas da matriz de design são linearmente dependentes. Lembre-se da álgebra linear que isso significa que existe uma combinação linear de colunas da matriz de design (cujos coeficientes não são todos zero) que é igual a zero. Incluí alguns exemplos práticos para ajudar a explicar por que essa armadilha ocorre com tanta frequência - encontrei quase todas!
Uma variável é um múltiplo de outra , independentemente de haver um termo de interceptação: talvez porque você tenha gravado a mesma variável duas vezes usando unidades diferentes (por exemplo, "comprimento em centímetros" é precisamente 100 vezes maior que "comprimento em metros") ou porque você registrou uma variável uma vez como número bruto e uma vez como proporção ou porcentagem, quando o denominador é fixo (por exemplo, "área de placa de Petri colonizada" e "porcentagem de placa de Petri colonizada" serão múltiplos exatos uns dos outros se a área de cada placa de Petri é o mesmo). Temos colinearidade porque se onde w e x são variáveis (colunas da sua matriz de design) e umwi=axi w x a é uma constante escalar,1(w⃗ )−a(x⃗ ) é uma combinação linear de variáveis que é igual a zero.
Há um termo de intercepto e um difere variáveis de outro por uma constante : isto irá acontecer se você centralizar uma variável ( ) e incluem tanto a matéria- x e centrado w em sua regressão. É também acontecerá se as variáveis são medidas em diferentes sistemas de unidades que diferem por uma constante, por exemplo, se w é "a temperatura em graus Kelvin" e X como "temperatura em ° C", em seguida, w i = x i + 273,15 . Se considerarmos o termo de interceptação como uma variável que é sempre 1 (representada como uma coluna de uns,wi=xi−x¯ x w w x wi=xi+273.15 1 1⃗ n , na matriz de desenho), em seguida, tendo para alguma constantewi=xi+k significa que 1 ( → w ) - 1 ( → x ) - k ( → 1 n ) é uma combinação linear de w , x e 1 colunas da matriz de design que são iguais a zero.k 1(w⃗ )−1(x⃗ )−k(1⃗ n) w x 1
Há um termo intercepção e uma variável é dada por uma transformação afim de outro : ou seja, tem variáveis e x , relacionadas por w i = um x i + b , onde um e b são constantes. Por exemplo, isso acontece se você padronizar uma variável como z i = x i - ˉ xw x wi=axi+b a b zi=xi−x¯sx and include both raw x and standardized z variables in your regression. It also happens if you record w as "temperature in °F" and x as "temperature in °C", since those unit systems do not share a common zero but are related by wi=1.8xi+32 . Or in a business context, suppose there is fixed cost b (e.g. covering delivery) for each order, as well as a cost $a per unit sold; then if $wi is the cost of order i and xi is the number of units ordered, we have wi=axi+b . The linear combination of interest is 1(w⃗ )−a(x⃗ )−b(1⃗ n)=0⃗ . Note that if a=1 , then (3) includes (2) as a special case; if b=0 , then (3) includes (1) as a special case.
There is an intercept term and the sum of several variables is fixed (e.g. in the famous "dummy variable trap"): for example if you have "percentage of satisfied customers", "percentage of dissatisfied customers" and "percentage of customers neither satisfied nor dissatisfied" then these three variables will always (barring rounding error) sum to 100. One of these variables — or alternatively, the intercept term — needs to be dropped from the regression to prevent collinearity. The "dummy variable trap" occurs when you use indicator variables (more commonly but less usefully called "dummies") for every possible level of a categorical variable. For instance, suppose vases are produced in red, green or blue color schemes. If you recorded the categorical variable "color" by three indicator variables (
red
,green
andblue
would be binary variables, stored as1
for "yes" and0
for "no") then for each vase only one of the variables would be a one, and hencered + green + blue = 1
. Since there is a vector of ones for the intercept term, the linear combination1(red) + 1(green) + 1(blue) - 1(1) = 0
. The usual remedy here is either to drop the intercept, or drop one of the indicators (e.g. leave outred
) which becomes a baseline or reference level. In this case, the regression coefficient forgreen
would indicate the change in the mean response associated with switching from a red vase to a green one, holding other explanatory variables constant.large + medium + small = 1
1(large) + 1(medium) + 1(small) - 1(red) - 1(green) - 1(blue) = 0
One variable is defined as a linear combination of several other variables: for instance, if you record the lengthl , width w and perimeter p of each rectangle, then pi=2li+2wi so we have the linear combination 1(p⃗ )−2(l⃗ )−2(w⃗ )=0⃗ . An example with an intercept term: suppose a mail-order business has two product lines, and we record that order i consisted of ui of the first product at unit cost $a and vi of the second at unit cost $b , with fixed delivery charge $c . If we also include the order cost $x as an explanatory variable, then xi=aui+bvi+c and so 1(x⃗ )−a(u⃗ )−b(v⃗ )−c(1⃗ n)=0⃗ . This is an obvious generalization of (3). It also gives us a different way of thinking about (4): once we know all bar one of the subset of variables whose sum is fixed, then the remaining one is their complement so can be expressed as a linear combination of them and their sum. If we know 50% of customers were satisfied and 20% were dissatisfied, then 100% - 50% - 20% = 30% must be neither satisfied nor dissatisfied; if we know the vase is not red (
red=0
) and it is green (green=1
) then we know it is not blue (blue = 1(1) - 1(red) - 1(green) = 1 - 0 - 1 = 0
).One variable is constant and zero, regardless of whether there is an intercept term: in an observational study, a variable will be constant if your sample does not exhibit sufficient (any!) variation. There may be variation in the population that is not captured in your sample, e.g. if there is a very common modal value: perhaps your sample size is too small and was therefore unlikely to include any values that differed from the mode, or your measurements were insufficiently accurate to detect small variations from the mode. Alternatively, there may be theoretical reasons for the lack of variation, particularly if you are studying a sub-population. In a study of new-build properties in Los Angeles, it would not be surprising that every data point hasx be both constant and zero, then we have immediately that the linear combination 1(x⃗ ) (with coefficient zero for any other variables) is 0⃗ .
AgeOfProperty = 0
andState = California
! In an experimental study, you may have measured an independent variable that is under experimental control. Should one of your explanatory variablesThere is an intercept term and at least one variable is constant: ifx is constant so that each xi=k≠0 , then the linear combination 1(x⃗ )−k(1⃗ n)=0⃗ .
At least two variables are constant, regardless of whether there is an intercept term: if eachwi=k1≠0 and xi=k2≠0 , then the linear combination k2(w⃗ )−k1(x⃗ )=0⃗ .
Number of columns of design matrix,k , exceeds number of rows, n : even when there is no conceptual relationship between your variables, it is mathematically necessitated that the columns of your design matrix will be linearly dependent when k>n . It simply isn't possible to have k linearly independent vectors in a space with a number of dimensions lower than k : for instance, while you can draw two independent vectors on a sheet of paper (a two-dimensional plane, R2 ) any further vector drawn on the page must lie within their span, and hence be a linear combination of them. Note that an intercept term contributes a column of ones to the design matrix, so counts as one of your k columns. (This scenario is often called the "large p , small n " problem: see also this related CV question.)
Data examples with R code
Each example gives a design matrixX , the matrix X′X (note this is always square and symmetrical) and det(X′X) . Note that if X′X is singular (zero determinant, hence not invertible) then we cannot estimate β^=(X′X)−1X′y . The condition that X′X be non-singular is equivalent to the condition that X has full rank so its columns are linearly independent: see this Math SE question, or this one and its converse.
(1) One column is multiple of another
(2) Intercept term and one variable differs from another by constant
(3) Intercept term and one variable is affine transformation of another
(4) Intercept term and sum of several variables is fixed
(4a) Intercept term with dummy variable trap
(5) Two subsets of variables with fixed sum
(6) One variable is linear combination of others
(7) One variable is constant and zero
(8) Intercept term and one constant variable
(9) Two constant variables
(10)k>n
fonte
Some trivial examples to help intuition:
There a multitude of ways such that one column of data will be a linear function of your other data. Some of them are obvious (eg. meters vs. centimeters) while others can be more subtle (eg. age and years of schooling for younger children).
Notational notes: Letx1 denote the first column of X , x2 the second column etc..., and 1 denotes a vector of ones, which is what's included in the design matrix X if you include a constant in your regression.
fonte