Skip to main content
added 2 characters in body
Source Link
Richard Hardy
  • 69.5k
  • 13
  • 126
  • 278

There is not much to it:

# Some data:
n       <- 1000
x       <- rnorm(n, mean = 7000, sd = 500)
y       <- 50 + x*50 + rnorm(100)
weights <- 1:1000/1000
# Regression:
ols     <- lm(y ~ x)
wls     <- lm(y ~ x, weights = weights)

You simply specify the weightsweights argument. R then applies the weights to each observation and the intercept.

There is not much to it:

# Some data:
n       <- 1000
x       <- rnorm(n, mean = 7000, sd = 500)
y       <- 50 + x*50 + rnorm(100)
weights <- 1:1000/1000
# Regression:
ols     <- lm(y ~ x)
wls     <- lm(y ~ x, weights = weights)

You simply specify the weights argument. R then applies the weights to each observation and the intercept.

There is not much to it:

# Some data:
n       <- 1000
x       <- rnorm(n, mean = 7000, sd = 500)
y       <- 50 + x*50 + rnorm(100)
weights <- 1:1000/1000
# Regression:
ols     <- lm(y ~ x)
wls     <- lm(y ~ x, weights = weights)

You simply specify the weights argument. R then applies the weights to each observation and the intercept.

Source Link
Repmat
  • 3.6k
  • 1
  • 21
  • 34

There is not much to it:

# Some data:
n       <- 1000
x       <- rnorm(n, mean = 7000, sd = 500)
y       <- 50 + x*50 + rnorm(100)
weights <- 1:1000/1000
# Regression:
ols     <- lm(y ~ x)
wls     <- lm(y ~ x, weights = weights)

You simply specify the weights argument. R then applies the weights to each observation and the intercept.