Linear regression using OLS

regress(
  dataset,
  rvar,
  evar,
  int = "",
  check = "",
  form,
  data_filter = "",
  envir = parent.frame()
)

Arguments

dataset

Dataset

rvar

The response variable in the regression

evar

Explanatory variables in the regression

int

Interaction terms to include in the model

check

Use "standardize" to see standardized coefficient estimates. Use "stepwise-backward" (or "stepwise-forward", or "stepwise-both") to apply step-wise selection of variables in estimation. Add "robust" for robust estimation of standard errors (HC1)

form

Optional formula to use instead of rvar, evar, and int

data_filter

Expression entered in, e.g., Data > View to filter the dataset in Radiant. The expression should be a string (e.g., "price > 10000")

envir

Environment to extract data from

Value

A list of all variables used in the regress function as an object of class regress

Details

See https://radiant-rstats.github.io/docs/model/regress.html for an example in Radiant

See also

summary.regress to summarize results

plot.regress to plot results

predict.regress to generate predictions

Examples

regress(diamonds, "price", c("carat", "clarity"), check = "standardize") %>% summary()
#> Linear regression (OLS) #> Data : diamonds #> Response variable : price #> Explanatory variables: carat, clarity #> Null hyp.: the effect of x on price is zero #> Alt. hyp.: the effect of x on price is not zero #> **Standardized coefficients shown (2 X SD)** #> #> coefficient std.error t.value p.value #> (Intercept) -0.504 0.025 -20.379 < .001 *** #> carat 1.010 0.006 165.125 < .001 *** #> clarity|SI2 0.353 0.025 13.857 < .001 *** #> clarity|SI1 0.456 0.025 17.997 < .001 *** #> clarity|VS2 0.537 0.025 21.080 < .001 *** #> clarity|VS1 0.564 0.026 21.809 < .001 *** #> clarity|VVS2 0.646 0.027 24.307 < .001 *** #> clarity|VVS1 0.635 0.027 23.466 < .001 *** #> clarity|IF 0.665 0.030 22.534 < .001 *** #> #> Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 #> #> R-squared: 0.904, Adjusted R-squared: 0.904 #> F-statistic: 3530.024 df(8,2991), p.value < .001 #> Nr obs: 3,000 #>
regress(diamonds, "price", c("carat", "clarity")) %>% str()
#> List of 12 #> $ coeff :'data.frame': 9 obs. of 6 variables: #> ..$ label : chr [1:9] "(Intercept)" "carat" "clarity|SI2" "clarity|SI1" ... #> ..$ coefficient: num [1:9] -6781 8438 2791 3609 4250 ... #> ..$ std.error : num [1:9] 205 51.1 201.4 200.5 201.6 ... #> ..$ t.value : num [1:9] -33.1 165.1 13.9 18 21.1 ... #> ..$ p.value : num [1:9] 7.76e-205 0.00 2.28e-42 7.76e-69 4.38e-92 ... #> ..$ sig_star : chr [1:9] "***" "***" "***" "***" ... #> $ model :List of 13 #> ..$ coefficients : Named num [1:9] -6781 8438 2791 3609 4250 ... #> .. ..- attr(*, "names")= chr [1:9] "(Intercept)" "carat" "claritySI2" "claritySI1" ... #> ..$ residuals : Named num [1:3000] 199 954 630 -576 236 ... #> .. ..- attr(*, "names")= chr [1:3000] "1" "2" "3" "4" ... #> ..$ effects : Named num [1:3000] -214005 200946 -26340 -18929 7642 ... #> .. ..- attr(*, "names")= chr [1:3000] "(Intercept)" "carat" "claritySI2" "claritySI1" ... #> ..$ rank : int 9 #> ..$ fitted.values: Named num [1:3000] 381.133 -303.531 0.322 1281.793 844.125 ... #> .. ..- attr(*, "names")= chr [1:3000] "1" "2" "3" "4" ... #> ..$ assign : int [1:9] 0 1 2 2 2 2 2 2 2 #> ..$ qr :List of 5 #> .. ..$ qr : num [1:3000, 1:9] -54.7723 0.0183 0.0183 0.0183 0.0183 ... #> .. .. ..- attr(*, "dimnames")=List of 2 #> .. .. .. ..$ : chr [1:3000] "1" "2" "3" "4" ... #> .. .. .. ..$ : chr [1:9] "(Intercept)" "carat" "claritySI2" "claritySI1" ... #> .. .. ..- attr(*, "assign")= int [1:9] 0 1 2 2 2 2 2 2 2 #> .. .. ..- attr(*, "contrasts")=List of 1 #> .. .. .. ..$ clarity: chr "contr.treatment" #> .. ..$ qraux: num [1:9] 1.02 1.02 1 1.01 1.03 ... #> .. ..$ pivot: int [1:9] 1 2 3 4 5 6 7 8 9 #> .. ..$ tol : num 0.0000001 #> .. ..$ rank : int 9 #> .. ..- attr(*, "class")= chr "qr" #> ..$ df.residual : int 2991 #> ..$ contrasts :List of 1 #> .. ..$ clarity: chr "contr.treatment" #> ..$ xlevels :List of 1 #> .. ..$ clarity: chr [1:8] "I1" "SI2" "SI1" "VS2" ... #> ..$ call : language lm(formula = form_upper, data = dataset) #> ..$ terms :Classes 'terms', 'formula' language price ~ carat + clarity #> .. .. ..- attr(*, "variables")= language list(price, carat, clarity) #> .. .. ..- attr(*, "factors")= int [1:3, 1:2] 0 1 0 0 0 1 #> .. .. .. ..- attr(*, "dimnames")=List of 2 #> .. .. .. .. ..$ : chr [1:3] "price" "carat" "clarity" #> .. .. .. .. ..$ : chr [1:2] "carat" "clarity" #> .. .. ..- attr(*, "term.labels")= chr [1:2] "carat" "clarity" #> .. .. ..- attr(*, "order")= int [1:2] 1 1 #> .. .. ..- attr(*, "intercept")= int 1 #> .. .. ..- attr(*, "response")= int 1 #> .. .. ..- attr(*, ".Environment")=<environment: 0xb8682b0> #> .. .. ..- attr(*, "predvars")= language list(price, carat, clarity) #> .. .. ..- attr(*, "dataClasses")= Named chr [1:3] "numeric" "numeric" "factor" #> .. .. .. ..- attr(*, "names")= chr [1:3] "price" "carat" "clarity" #> ..$ model :'data.frame': 3000 obs. of 3 variables: #> .. ..$ price : int [1:3000] 580 650 630 706 1080 3082 3328 4229 1895 3546 ... #> .. ..$ carat : num [1:3000] 0.32 0.34 0.3 0.35 0.4 0.6 0.88 0.93 0.51 1.01 ... #> .. ..$ clarity: Factor w/ 8 levels "I1","SI2","SI1",..: 5 3 4 6 4 7 3 3 6 2 ... #> .. ..- attr(*, "terms")=Classes 'terms', 'formula' language price ~ carat + clarity #> .. .. .. ..- attr(*, "variables")= language list(price, carat, clarity) #> .. .. .. ..- attr(*, "factors")= int [1:3, 1:2] 0 1 0 0 0 1 #> .. .. .. .. ..- attr(*, "dimnames")=List of 2 #> .. .. .. .. .. ..$ : chr [1:3] "price" "carat" "clarity" #> .. .. .. .. .. ..$ : chr [1:2] "carat" "clarity" #> .. .. .. ..- attr(*, "term.labels")= chr [1:2] "carat" "clarity" #> .. .. .. ..- attr(*, "order")= int [1:2] 1 1 #> .. .. .. ..- attr(*, "intercept")= int 1 #> .. .. .. ..- attr(*, "response")= int 1 #> .. .. .. ..- attr(*, ".Environment")=<environment: 0xb8682b0> #> .. .. .. ..- attr(*, "predvars")= language list(price, carat, clarity) #> .. .. .. ..- attr(*, "dataClasses")= Named chr [1:3] "numeric" "numeric" "factor" #> .. .. .. .. ..- attr(*, "names")= chr [1:3] "price" "carat" "clarity" #> ..- attr(*, "class")= chr "lm" #> $ mmx :List of 2 #> ..$ min: tibble [1 × 2] (S3: tbl_df/tbl/data.frame) #> .. ..$ price: int 338 #> .. ..$ carat: num 0.2 #> ..$ max: tibble [1 × 2] (S3: tbl_df/tbl/data.frame) #> .. ..$ price: int 18791 #> .. ..$ carat: num 3 #> $ vars : chr [1:2] "carat" "clarity" #> $ not_vary : chr(0) #> $ df_name : chr "diamonds" #> $ rvar : chr "price" #> $ evar : chr [1:2] "carat" "clarity" #> $ int : chr "" #> $ check : chr "" #> $ form : symbol #> $ data_filter: chr "" #> - attr(*, "class")= chr [1:3] "regress" "model" "list"