(this question I originally posted in stack overflow)
I want to know if I am interpreting the factor()
function in R correctly. Suppose I have a variable with 10 levels let's say these are the different exposures of a study plan. I make it a factor using either factor()
or as.factor()
. When seeing the summary of my lm() (making up an example):
I know by default factor1 is treated as a reference in r so it is not usually output.
intercept: 10 factor2 = 30 factor3 = 10 factor4 = 57 factor5 = 4 factor6 = 34 factor7 = 56 factor8 = 89 factor9 = 78 factor10 = 8
Additionally, since these are 10 factors (all of the factors are dichotomous, 0 is did not get the study type, 1 is that they did and each participant can only have one study type) this would mean that in the example if someone got factor4 as their treatment/study type, that their score is multiplied by the coefficient which is in this case is 1 (which would equal 57) and added to the intercept? Just want to make sure I am interpreting this correctly.
my model formula using lm() is: test scre = intercept + factor2 + ... + factor10
factor(x = df$StudyType, levels = c(1,2,3,4,5,6,7,8,9,10), labels = c("1","2","3","4","5","6","7","8","9,"10"))
but it was not working for some odd reason so instead I usedas.factor(df$StudyType)
$\endgroup$