The beta_test function performs a hypothesis test for each coefficient when the reference value is different to zero.

beta_test(
  object,
  alternative = c("two.sided", "less", "greater"),
  parm,
  ref.value
)

Arguments

object

A lm object.

alternative

a character string specifying the alternative hypothesis, must be one of "two.sided" (default), "greater" or "less". You can specify just the initial letter.

parm

is a vector with the coefficient names.

ref.value

is a numeric vector with the reference values to perform the test \(Ho: \beta_j = \beta_{j0}\).

Value

The beta_test function returns a matrix with the estimated coefficient, standard error, t value and p-value.

Examples

# In simple linear regression
mod1 <- lm(dist ~ speed, data=cars)
coef(mod1)
#> (Intercept)       speed 
#>  -17.579095    3.932409 

# to test beta_speed = 3 vs beta_speed < 3
beta_test(object=mod1, parm='speed', ref.value=3, alternative='less')
#>       Estimate Std.Err t value Pr(>t)
#> speed  3.93241 0.41551   2.244 0.9853

# In multiple linear regression
mod2 <- lm(mpg ~ hp + wt, data=mtcars)

# to test separately
# beta_hp = -0.05 vs beta_hp < -0.05 and
# beta_wt = -3 vs beta_wt != -3
alternative <- c("less", "two.sided")
ref.value <- c(-0.05, -3)
parm <- c("hp", "wt")
beta_test(mod2, alternative, parm, ref.value)
#>      Estimate    Std.Err t value Pr(>t)
#> hp -0.0317729  0.0090297  2.0186 0.9736
#> wt -3.8778307  0.6327335 -1.3874 0.1759