Domanda su come normalizzare il coefficiente di regressione


16

Non sono sicuro che normalizzare sia la parola corretta da usare qui, ma farò del mio meglio per illustrare ciò che sto cercando di chiedere. Lo stimatore utilizzato qui è il minimo dei quadrati.

Supponiamo di avere , puoi attorno alla media di dove e , quindi che non ha più influenza sulla stima .y=β0+β1x1y=β0+β1x1β0=β0+β1x¯1x1=xx¯β0β1

Con questo intendo che in equivale a in . Abbiamo ridotto l'equazione per un calcolo del minimo quadrato più semplice.β^1β 1y=β0+β1x1y=β1x1β^1y=β0+β1x1

Come si applica questo metodo in generale? Ora ho il modello , sto cercando di ridurlo a . y =y=β1ex1t+β2ex2ty=β1x


Che tipo di dati stai analizzando e perché vuoi rimuovere una covariata, ex1t , dal tuo modello. Inoltre, c'è un motivo per cui stai rimuovendo l'intercettazione? Se intendi centrare i dati, la pendenza sarà la stessa nel modello con / senza intercettazione, ma il modello con l'intercettazione si adatterà meglio ai tuoi dati.
Caburke,

@caburke Non mi preoccupo dell'adattamento del modello, perché dopo aver calcolato e posso rimetterli nel modello. Il punto di questo esercizio è stimare . Riducendo l'equazione originale a solo , il calcolo del minimo quadrato sarà più semplice (x' fa parte di ciò che sto cercando di scoprire, può includere ). Sto cercando di imparare i meccanismi, questa è una domanda tratta da un libro di Tukey. β1β2β1y=β1xex1t
Sabre CN,

@ca L'osservazione alla fine del tuo commento è sconcertante. Non può applicarsi alle espressioni non lineari - non contengono nulla che possa ragionevolmente essere considerato una "pendenza" - ma non è corretto nell'impostazione OLS: l'adattamento per i dati centrati sulla media è esattamente buono come il si adatta con un'intercettazione. Sabre, il tuo modello è ambiguo: quali di sono variabili e quali sono parametri? Qual è la struttura di errore prevista? (E quale dei libri di Tukey è la domanda?)β1,β2,x1,x2,t
whuber

1
@whuber Questo è tratto dal libro di Tukey "Analisi dei dati e regressione: un secondo corso di statistica" capitolo 14A. sono i parametri che stiamo cercando di stimare, sono le variabili ognuna con n osservazioni, presumo sia la variabile temporale associata alle osservazioni, tuttavia non ha specificato. L'errore dovrebbe essere normale e può essere ignorato per questa domanda. β1,β2x1,x2t
Sabre CN,

1
@whuber Mi riferivo principalmente alla prima parte del post, ma questo non era chiaro nel mio commento. Quello che intendevo dire era che se intendevi solo il centro x , e non y , come sembrava essere stato suggerito nell'OP, e quindi rimuovere l'intercettazione, allora l'adattamento sarebbe peggiore, dal momento che non è necessariamente il caso che y¯=0 . La pendenza non è ovviamente un buon termine per il coefficiente nel modello menzionato nell'ultima riga del PO.
Caburke,

Risposte:


38

Anche se non posso rendere giustizia alla domanda qui - ciò richiederebbe una piccola monografia - potrebbe essere utile ricapitolare alcune idee chiave.

La domanda

Cominciamo riformulando la domanda e usando una terminologia non ambigua. I dati consistono in un elenco di coppie ordinate (ti,yi) . Le costanti note α1 e α2 determinano i valori x1,i=exp(α1ti) e x2,i=exp(α2ti) . Abbiamo un modello in cui

yi=β1x1,i+β2x2,i+εi

per le costanti e β 2 da stimare, ε i sono casuali e - con buona approssimazione comunque - indipendenti e aventi una varianza comune (la cui stima è anche di interesse).β1β2εi

Sfondo: "abbinamento" lineare

Mosteller e Tukey si riferiscono alle variabili = ( x 1 , 1 , x 1 , 2 , ... ) e x 2 come "corrispondenti". Saranno usati per "abbinare" i valori di y = ( y 1 , y 2 , ... ) in un modo specifico, che illustrerò. Più in generale, sia y che x siano due vettori nello stesso spazio vettoriale euclideo, con y che svolga il ruolo di "target" e xx1(x1,1,x1,2,)x2y=(y1,y2,)yxyxquello di "matcher". Contempliamo variando sistematicamente un coefficiente per approssimare y per il multiplo λ x . La migliore approssimazione si ottiene quando λ x è il più vicino possibile a y . Equivalentemente, la lunghezza quadrata di y - λ x è ridotta al minimo.λyλxλxyyλx

Un modo per visualizzare questo processo di corrispondenza è di fare una dispersione di ed y su cui è disegnato il grafico di x À x . Le distanze verticali tra i punti del diagramma a dispersione e questo grafico sono i componenti del vettore residuo y - λ x ; la somma dei loro quadrati deve essere resa il più piccola possibile. Fino a una costante di proporzionalità, questi quadrati sono le aree dei cerchi centrati nei punti ( x i , y i ) con raggi pari ai residui: desideriamo ridurre al minimo la somma delle aree di tutti questi cerchi.xyxλx yλx(xi,yi)

Ecco un esempio che mostra il valore ottimale di nel pannello centrale:λ

Panel

I punti nel grafico a dispersione sono blu; il grafico di è una linea rossa. Questa illustrazione sottolinea che la linea rossa è costretta a passare attraverso l'origine ( 0 , 0 ) : è un caso molto particolare di adattamento della linea.xλx(0,0)

La regressione multipla può essere ottenuta mediante corrispondenza sequenziale

Ritornando all'impostazione della domanda, abbiamo un target e due matcher x 1 e x 2 . Cerchiamo numeri b 1 e b 2 per cui y è avvicini il più possibile da b 1 x 1 + b 2 x 2 , sempre nel senso minor distanza. A partire arbitrariamente da x 1 , Mosteller e Tukey corrispondono alle restanti variabili x 2 e da y a x 1yx1x2b1b2yb1x1+b2x2x1x2yx1. Scrivi i residui per queste corrispondenze rispettivamente come e y 1 : 1 indica che x 1 è stato "rimosso" dalla variabile.x21y11x1

Possiamo scrivere

y=λ1x1+y1 and x2=λ2x1+x21.

Dopo aver preso da x 2 e y , procediamo ad abbinare i residui target y 1 ai residui matcher x 2 1 . I residui finali sono y 12 . Algebricamente, abbiamo scrittox1x2yy1x21y12

y1=λ3x21+y12; whencey=λ1x1+y1=λ1x1+λ3x21+y12=λ1x1+λ3(x2λ2x1)+y12=(λ1λ3λ2)x1+λ3x2+y12.

This shows that the λ3 in the last step is the coefficient of x2 in a matching of x1 and x2 to y.

We could just as well have proceeded by first taking x2 out of x1 and y, producing x12 and y2, and then taking x12 out of y2, yielding a different set of residuals y21. This time, the coefficient of x1 found in the last step--let's call it μ3--is the coefficient of x1 in a matching of x1 and x2 to y.

Finally, for comparison, we might run a multiple (ordinary least squares regression) of y against x1 and x2. Let those residuals be ylm. It turns out that the coefficients in this multiple regression are precisely the coefficients μ3 and λ3 found previously and that all three sets of residuals, y12, y21, and ylm, are identical.

Depicting the process

None of this is new: it's all in the text. I would like to offer a pictorial analysis, using a scatterplot matrix of everything we have obtained so far.

Scatterplot

Because these data are simulated, we have the luxury of showing the underlying "true" values of y on the last row and column: these are the values β1x1+β2x2 without the error added in.

The scatterplots below the diagonal have been decorated with the graphs of the matchers, exactly as in the first figure. Graphs with zero slopes are drawn in red: these indicate situations where the matcher gives us nothing new; the residuals are the same as the target. Also, for reference, the origin (wherever it appears within a plot) is shown as an open red circle: recall that all possible matching lines have to pass through this point.

Much can be learned about regression through studying this plot. Some of the highlights are:

  • The matching of x2 to x1 (row 2, column 1) is poor. This is a good thing: it indicates that x1 and x2 are providing very different information; using both together will likely be a much better fit to y than using either one alone.

  • Once a variable has been taken out of a target, it does no good to try to take that variable out again: the best matching line will be zero. See the scatterplots for x21 versus x1 or y1 versus x1, for instance.

  • x1x2x12x21 have all been taken out of ylm.

  • Multiple regression of y against x1 and x2 can be achieved first by computing y1 and x21. These scatterplots appear at (row, column) = (8,1) and (2,1), respectively. With these residuals in hand, we look at their scatterplot at (4,3). These three one-variable regressions do the trick. As Mosteller & Tukey explain, the standard errors of the coefficients can be obtained almost as easily from these regressions, too--but that's not the topic of this question, so I will stop here.

Code

These data were (reproducibly) created in R with a simulation. The analyses, checks, and plots were also produced with R. This is the code.

#
# Simulate the data.
#
set.seed(17)
t.var <- 1:50                                    # The "times" t[i]
x <- exp(t.var %o% c(x1=-0.1, x2=0.025) )        # The two "matchers" x[1,] and x[2,]
beta <- c(5, -1)                                 # The (unknown) coefficients
sigma <- 1/2                                     # Standard deviation of the errors
error <- sigma * rnorm(length(t.var))            # Simulated errors
y <- (y.true <- as.vector(x %*% beta)) + error   # True and simulated y values
data <- data.frame(t.var, x, y, y.true)

par(col="Black", bty="o", lty=0, pch=1)
pairs(data)                                      # Get a close look at the data
#
# Take out the various matchers.
#
take.out <- function(y, x) {fit <- lm(y ~ x - 1); resid(fit)}
data <- transform(transform(data, 
  x2.1 = take.out(x2, x1),
  y.1 = take.out(y, x1),
  x1.2 = take.out(x1, x2),
  y.2 = take.out(y, x2)
), 
  y.21 = take.out(y.2, x1.2),
  y.12 = take.out(y.1, x2.1)
)
data$y.lm <- resid(lm(y ~ x - 1))               # Multiple regression for comparison
#
# Analysis.
#
# Reorder the dataframe (for presentation):
data <- data[c(1:3, 5:12, 4)]

# Confirm that the three ways to obtain the fit are the same:
pairs(subset(data, select=c(y.12, y.21, y.lm)))

# Explore what happened:
panel.lm <- function (x, y, col=par("col"), bg=NA, pch=par("pch"),
   cex=1, col.smooth="red",  ...) {
  box(col="Gray", bty="o")
  ok <- is.finite(x) & is.finite(y)
  if (any(ok))  {
    b <- coef(lm(y[ok] ~ x[ok] - 1))
    col0 <- ifelse(abs(b) < 10^-8, "Red", "Blue")
    lwd0 <- ifelse(abs(b) < 10^-8, 3, 2)
    abline(c(0, b), col=col0, lwd=lwd0)
  }
  points(x, y, pch = pch, col="Black", bg = bg, cex = cex)    
  points(matrix(c(0,0), nrow=1), col="Red", pch=1)
}
panel.hist <- function(x, ...) {
  usr <- par("usr"); on.exit(par(usr))
  par(usr = c(usr[1:2], 0, 1.5) )
  h <- hist(x, plot = FALSE)
  breaks <- h$breaks; nB <- length(breaks)
  y <- h$counts; y <- y/max(y)
  rect(breaks[-nB], 0, breaks[-1], y,  ...)
}
par(lty=1, pch=19, col="Gray")
pairs(subset(data, select=c(-t.var, -y.12, -y.21)), col="Gray", cex=0.8, 
   lower.panel=panel.lm, diag.panel=panel.hist)

# Additional interesting plots:
par(col="Black", pch=1)
#pairs(subset(data, select=c(-t.var, -x1.2, -y.2, -y.21)))
#pairs(subset(data, select=c(-t.var, -x1, -x2)))
#pairs(subset(data, select=c(x2.1, y.1, y.12)))

# Details of the variances, showing how to obtain multiple regression
# standard errors from the OLS matches.
norm <- function(x) sqrt(sum(x * x))
lapply(data, norm)
s <- summary(lm(y ~ x1 + x2 - 1, data=data))
c(s$sigma, s$coefficients["x1", "Std. Error"] * norm(data$x1.2)) # Equal
c(s$sigma, s$coefficients["x2", "Std. Error"] * norm(data$x2.1)) # Equal
c(s$sigma, norm(data$y.12) / sqrt(length(data$y.12) - 2))        # Equal

1
Could multiple regression of y against x1 and x2 still be achieved by first computing y.1 and x2.1 if x1 and x2 were correlated? Wouldn't it then make a big difference whether we sequentially regressed y on x1 and x2.1 or on x2 and x1.2 ? How does this relate to one regression equation with multiple explanatory variables?
miura

1
@miura, One of the leitmotifs of that chapter in Mosteller & Tukey is that when the xi are correlated, the partials xij have low variances; because their variances appear in the denominator of a formula for the estimation variance of their coefficients, this implies the corresponding coefficients will have relatively uncertain estimates. That's a fact of the data, M&T say, and you need to recognize that. It makes no difference whether you start the regression with x1 or x2: compare y.21 to y.12 in my code.
whuber

1
I came across this today, here is what I think on the question by @miura, Think of a 2 dimensional space where Y is to be projected as a combination of two vectors. y = ax1 + bx2 + res (=0). Now think of y as a combination of 3 variables, y = ax1 + bx2 + cx3. and x3 = mx1 + nx2. so certainly, the order in which you choose your variables is going to effect the coefficients. The reason for this is: the minimum error here can be obtained by various combinations. However, in few examples, the minimum error can be obtained by only one combination and that is where the order will not matter.
Gaurav Singhal

@whuber Can you elaborate on how this equation might be used for a multivariate regression that also has a constant term ? ie y = B1 * x1 + B2 * x2 + c ? It is not clear to me how the constant term can be derived. Also I understand in general what was done for the 2 variables, enough at least to replicate it in Excel. How can that be expanded to 3 variables ? x1, x2, x3. It seems clear that we would need to remove x3 first from y, x1, and x2. then remove x2 from x1 and y. But it is not clear to me how to then get the B3 term.
Fairly Nerdy

I have answered some of my questions I have in the comment above. For a 3 variable regression, we would have 6 steps. Remove x1 from x2, from x3, and from y. Then remove x2,1 from x3,1 and from y1. Then remove x3,21 from y21. That results in 6 equations, each of which is of the form variable = lamda * different variable + residual. One of those equations has a y as the first variable, and if you just keep substituting the other variables in, you get the equation you need
Fairly Nerdy
Utilizzando il nostro sito, riconosci di aver letto e compreso le nostre Informativa sui cookie e Informativa sulla privacy.
Licensed under cc by-sa 3.0 with attribution required.