Error message

  • Deprecated function: The each() function is deprecated. This message will be suppressed on further calls in book_prev() (line 775 of /home3/gardeoi3/public_html/iamrandom/modules/book/book.module).
  • Deprecated function: implode(): Passing glue string after array is deprecated. Swap the parameters in drupal_get_feeds() (line 394 of /home3/gardeoi3/public_html/iamrandom/includes/common.inc).

Weighted Regression

Here is a quick example of how to recreate weighted regression without needing the weights=... part of lm().  It also shows how to set up your own intercept in R. 


set.seed(50)
x0=rep(1,100)         #specify the intercept because they multiply by the weights
x=round(runif(100),2)*100
w=(runif(100,1,10))^2
y=round(3*x+rnorm(100,0,10),2)
plot(x,y)

X=cbind(x0,x)

summary(lm(y_x))  
summary(lm(y~0+X))   # this is to show a different way of setting up the intercept in R

summary(lm(y~0+X, weights=w))   #with weights=....
y2=sqrt(w)*y
X2=sqrt(w)*X
summary(lm(y2~0+X2))                 #without weights=...

 

Tags: