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. Thanks a lot (and thanks for your patience) Matej -- Matej Cepl, matej at ceplovi.cz, Finger: 89EF 4BC6 288A BF43 1BAB 25C3 E09F EF25 D964 84AC 138 Highland Ave. #10, Somerville, Ma 02143, (617) 623-1488 Q: Is vi an easy editor to learn, is it intuitive? A: Yes, some of us think so. But most people think that we are crazy. -- vi FAQ -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
You can't do linear regression with an ordered factor as a response. If you mean to code the levels you need to do so explicitly by codes(G5). 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. > > Thanks a lot (and thanks for your patience) > > Matej > > -- > Matej Cepl, matej at ceplovi.cz, > Finger: 89EF 4BC6 288A BF43 1BAB 25C3 E09F EF25 D964 84AC > 138 Highland Ave. #10, Somerville, Ma 02143, (617) 623-1488 > > Q: Is vi an easy editor to learn, is it intuitive? > A: Yes, some of us think so. But most people think that we are > crazy. > -- vi FAQ > > -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- > 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 > _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._ >-- Brian D. Ripley, ripley at stats.ox.ac.uk Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272860 (secr) Oxford OX1 3TG, UK Fax: +44 1865 272595 -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
Dear Matej, The response variable in a linear model fit by lm has to be a numeric variable. (The warnings are produced when lm tries to perform arithmetic operations on an ordered factor.) You could use as.numeric(G5) on the left hand side of the model, but you should probably think about whether you really want to fit a linear model to categorical data. I hope that this helps, John At 03:40 PM 11/26/2002 -0500, 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. > > Thanks a lot (and thanks for your patience) > > Matej----------------------------------------------------- John Fox Department of Sociology McMaster University Hamilton, Ontario, Canada L8S 4M4 email: jfox at mcmaster.ca phone: 905-525-9140x23604 web: www.socsci.mcmaster.ca/jfox ----------------------------------------------------- -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
Dear Matej, For your best information, you can read Draper and Smith, 1998 "Applied Regression Analysis", I think this is the most cited literature for regression analysis, or if you are facing with categorical data (like what you are doing now) go with Hosmer and Lemeshow , 2002 "Applied Logistic Regression" Hope this help, Eduwin INDONESIA -----Original Message----- From: owner-r-help at stat.math.ethz.ch [mailto:owner-r-help at stat.math.ethz.ch] On Behalf Of Matej Cepl Sent: Wednesday, November 27, 2002 8:16 AM To: r-help at stat.math.ethz.ch Subject: Re: [R] [NB] lm problems On Tue, 26 Nov 2002 ripley at stats.ox.ac.uk wrote:> You can't do linear regression with an ordered factor as a response. > If you mean to code the levels you need to do so explicitly by > codes(G5).Thanks to everybody who answered to my query. Just to justify myself in your eyes, let me tell you that a silly idea of doing regression analysis on nominal variables is not mine, but of my instructor in school. Thanks again, Matej -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-. -.-.-.- 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._. _._._._ -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._