R-Studio Midterm 2 Flashcards
regression
lm(dv ~ iv, data = dataset)
adding categorical variable to regression
lm(dv ~ iv, as.factor(variable), data = dataset)
adding binary variable to regression
lm(dv ~ iv + variable 1 + variable 2, data = dataset)
adding interaction to regression
lm(dv ~ iv, as.factor(variable), dv:as.factor(variable), data = dataset)
quadratic lm model
lm(dv ~ iv + I(iv^2), data = dataset)
generalized linear model
glm(dv ~ iv, data = dataset, family = binominal (link = “logit”))
adding a covariate to generalized linear model
glm(dv ~ iv + as.factor(variable), data - dataset, family = binominal (link = “logit”))
adding an interaction to generalized linear model
glm(dv ~ iv + as.factor(variable) + iv:as.factor(variable), data - dataset, family = binominal (link = “logit”))
MANOVA
MANOVA(cbind(dv1, dv2, data= dataset)
Linear Discriminant Analysis
lda(iv ~ dv1 + dv2 + dv3, data = dataset)
predicting for LDA
head(predict(lda)$posterior)
confusion matrix
table(predict(lda)$class, dataset$iv)