Code
# load library
library(tidyverse)
R is good in the stat, bio side.
Note that below is not fully developed.
Here are some examples of R codes:
Have all setups like loading library in one block of code
Calculating mean of a vector of length n
Fitting a simple linear regression model
(Intercept) x1 x2
-2.167242e-15 2.000000e+00 3.000000e+00
Plot the model
fit <- reg
p <- ggplot(fit$model, aes_string(x = names(fit$model)[2], y = names(fit$model)[1])) +
geom_point() +
stat_smooth(method = "lm", col = "red") +
labs(title = paste("Adj R2 = ",signif(summary(fit)$adj.r.squared, 5),
"Intercept =",signif(fit$coef[[1]],5 ),
" Slope =",signif(fit$coef[[2]], 5),
" P =",signif(summary(fit)$coef[2,4], 5)))
p
The Figure 1 shows the fitted regression line on the dummy data