R programming language resources › Forums › Statistical analyses › Linear Regression using Dummy Coding
- This topic has 0 replies, 1 voice, and was last updated 12 years, 9 months ago by happybananas.
- AuthorPosts
- December 27, 2011 at 2:09 pm #296happybananasMember
I am completely stumped and cannot find an answer to my problem anywhere.
My problem is that I want to carry out a linear regression on a factor variable with three variables that I have dummy coded in two new columns using “which” (see code 1)
I think I have done this correctly??
But when I go to carry out the linear regression on my category variable (see code 2) category 1 is being completely missed in the output (see code 3)The results for category2 & category3 are available but not category 1. It is a problem with category1 rather than just missing the first independent variable as I also put a few other IV’s into the equation to make a multiple regression and still only category1 wasn’t shown.
I have literally spent hours trying to figure this out and I am completely frustrated with the whole thing 🙁
I am fairly new to R so if I am being completely stupid then I apologise!!
So very very greatful for any help anyone can offer me.
CODE 1
pictures.nona$funct_wrd<-NA #create new column funct_wrd pictures.nona$funct_wrd[which(pictures.nona$category %in% "2")]<-0 pictures.nona$funct_wrd[which(pictures.nona$category %in% "3")]<-0 pictures.nona$funct_wrd[which(pictures.nona$category %in% "1")]<-1 #indexing to dummy code variables pictures.nona$noun<-NA #create new column noun pictures.nona$noun[which(pictures.nona$category %in% "2")]<-1 pictures.nona$noun[which(pictures.nona$category %in% "3")]<-0 pictures.nona$noun[which(pictures.nona$category %in% "1")]<-0 #indexing to dummy code variables
CODE 2
model1<- lm(RT ~category + length + freq) #multiple linear regression summary(model1)
CODE 3
Call:
lm(formula = RT ~ category)Residuals:
Min 1Q Median 3Q Max
-292.87 -87.11 -6.61 75.56 357.59Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 345.967 6.524 53.029 < 2e-16 *** category2 -32.061 9.234 -3.472 0.000539 *** category3 -24.258 9.344 -2.596 0.009573 ** --- Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 Residual standard error: 118.2 on 964 degrees of freedom Multiple R-squared: 0.01339, Adjusted R-squared: 0.01135 F-statistic: 6.544 on 2 and 964 DF, p-value: 0.001504 - AuthorPosts
- You must be logged in to reply to this topic.