Models - reference

Linear regression

lm(y ~ x1 + x2 + x3)     # multiple linear regression

lm(log(y) ~ x)           # log transformed
lm(sqrt(y) ~ x)          # sqrt transformed
lm( y ~ log(x))          # fields transformed
llm(log(y) ~ log(x))     # everything is transformed

lm(y ~ .)                # use all fields for regression model

lm(y ~ x + 0)            # forced zero intercept

lm(y ~ x*k)              # interaction of two variables

lm(y ~ x + k + x:k)      # product of xkl but without interaction

lm(y ~ (x + k + ... + l)^2) # all first order interactions

lm(y ~ I(x1 + x2))       # sum of variables
lm(y ~ I(x1^2))          # product of variables (not interation)

lm(y ~ x + I(x^2) + I(x^3)) # polynomial regression
lm(y ~ poly(x,3))           # same as previous

# Forward/backward stepwise regression
# improve model
fit <- lm(y ~ x1 + x2)
bwd.fit <- step(fit, direction = 'backward')
fwd.fit <- step(fit, direction = 'forward', scope( ~ x1 + x2))

Test linear moedel

plot(m)            # plot residuals
car::outlier.test(m)
dwtest(m)          # Durbin-Watson Test of the model residuals

One-way ANOVA

oneway.test(x ~ f)
aov(x ~ f)

anova(m1, m2)      # compair two models
Avatar
Mark Goldberg
Researcher

My research interests include epigenetics and computational biology.

Related

comments powered by Disqus