[NB] lm problems
On Tue, 26 Nov 2002, Matej Cepl wrote:
Hi, I have probably overlooked something obvious, but could anybody help me with following, please? Trying to make regression analysis. I have a huge dataframe with results from National Opinion Survey on Crime and Justice (www.abacon.com/fox/) with two variables G5 and N3 which are imported to R as ordered factors:
> levels(noscj$G5)
[1] "Strongly agree" "Agree" "Neither" [4] "Disagree" "Strongly disagree"
> levels(noscj$N3)
[1] "Serious problem" "Somewhat problem" "Minor problem" "Not a problem"
>
(missing values are duly recoded as NA). When I try linear regression I get a lot of warnings which I have not managed to parse succesfully:
> lm(G5 ~ N3,data=noscj)
Call: lm(formula = G5 ~ N3, data = noscj) Coefficients: (Intercept) N3.L N3.Q N3.C 3.38087 -0.05821 -0.15364 0.04367 Warning message: "-" not meaningful for ordered factors in: Ops.ordered(y, z$residuals)
> summary(lm(G5 ~ N3,data=noscj))
Call: lm(formula = G5 ~ N3, data = noscj) Residuals: [1] <NA> <NA> <NA> <NA> <NA> Levels: Strongly agree Agree Neither Disagree Strongly disagree Coefficients: Estimate Std. Error t value Pr(>|t|) (Intercept) 3.38087 N3.L -0.05821 N3.Q -0.15364 N3.C 0.04367 Residual standard error: NA on 980 degrees of freedom Multiple R-Squared: NA, Adjusted R-squared: NA F-statistic: NA on 3 and 980 DF, p-value: NA Warning messages: 1: "-" not meaningful for ordered factors in: Ops.ordered(y, z$residuals) 2: "^" not meaningful for ordered factors in: Ops.ordered(r, 2) 3: ">" not meaningful for factors in: Ops.factor(qs[i], -Inf) 4: "+" not meaningful for factors in: Ops.factor(qs[i], .minus(x[hi[i]], x[lo[i]]) * (index[i] - lo[i]))
>
Could anybody tell me, what's going on, please? I have no clue what "^", ">", etc. means.
Well, all the warnings are of the form " not meaningful for ordered factors". The problem is that lm is not meaningful for ordered factors. You appear to want a linear regression model where the response is 1,2,3,4,5 according to the levels of G5. You need to define a variable like that. You can probably just use numG5<-unclass(noscj$G5) -thomas -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._