Library

library(gtsummary)
library(dplyr)
## 
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
## 
##     filter, lag
## The following objects are masked from 'package:base':
## 
##     intersect, setdiff, setequal, union

Dataset

data("cars")
View(cars)

Correlation

r <- cor(cars$dist,cars$speed)
summary(r)
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##  0.8069  0.8069  0.8069  0.8069  0.8069  0.8069
r
## [1] 0.8068949
head(trial)

LM

model <- lm(dist~speed , data=cars)

summary(model)
## 
## Call:
## lm(formula = dist ~ speed, data = cars)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -29.069  -9.525  -2.272   9.215  43.201 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept) -17.5791     6.7584  -2.601   0.0123 *  
## speed         3.9324     0.4155   9.464 1.49e-12 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 15.38 on 48 degrees of freedom
## Multiple R-squared:  0.6511, Adjusted R-squared:  0.6438 
## F-statistic: 89.57 on 1 and 48 DF,  p-value: 1.49e-12

gtsummary

trial
modl <-  lm(marker ~ age + trt + grade + response + death, data = trial)
summary(modl)
## 
## Call:
## lm(formula = marker ~ age + trt + grade + response + death, data = trial)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -1.1389 -0.5954 -0.2520  0.3992  2.7081 
## 
## Coefficients:
##               Estimate Std. Error t value Pr(>|t|)    
## (Intercept)  1.0874113  0.2462034   4.417  1.8e-05 ***
## age          0.0001009  0.0045462   0.022   0.9823    
## trtDrug B   -0.1656895  0.1315334  -1.260   0.2096    
## gradeII     -0.3853005  0.1597109  -2.412   0.0169 *  
## gradeIII    -0.1063987  0.1588923  -0.670   0.5040    
## response     0.2152273  0.1466634   1.467   0.1441    
## death       -0.0016161  0.1380194  -0.012   0.9907    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.8564 on 166 degrees of freedom
##   (27 observations deleted due to missingness)
## Multiple R-squared:  0.05749,    Adjusted R-squared:  0.02342 
## F-statistic: 1.688 on 6 and 166 DF,  p-value: 0.1269
tbl_regression(modl)
Characteristic Beta 95% CI p-value
Age 0.00 -0.01, 0.01 >0.9
Chemotherapy Treatment


    Drug A
    Drug B -0.17 -0.43, 0.09 0.2
Grade


    I
    II -0.39 -0.70, -0.07 0.017
    III -0.11 -0.42, 0.21 0.5
Tumor Response 0.22 -0.07, 0.50 0.14
Patient Died 0.00 -0.27, 0.27 >0.9
Abbreviation: CI = Confidence Interval
trial$response <- as.factor(trial$response)

m <- glm(trial$response~trial$trt, family=binomial)

summary(m)
## 
## Call:
## glm(formula = trial$response ~ trial$trt, family = binomial)
## 
## Coefficients:
##                 Estimate Std. Error z value Pr(>|z|)    
## (Intercept)      -0.8725     0.2250  -3.877 0.000106 ***
## trial$trtDrug B   0.1946     0.3104   0.627 0.530641    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## (Dispersion parameter for binomial family taken to be 1)
## 
##     Null deviance: 240.81  on 192  degrees of freedom
## Residual deviance: 240.42  on 191  degrees of freedom
##   (7 observations deleted due to missingness)
## AIC: 244.42
## 
## Number of Fisher Scoring iterations: 4
exp(cbind(OR = coef(m), confint(m)))
## Waiting for profiling to be done...
##                        OR     2.5 %    97.5 %
## (Intercept)     0.4179104 0.2647887 0.6421547
## trial$trtDrug B 1.2148352 0.6617376 2.2413744