[R] predicting non-numeric values

John Fox jfox at mcmaster.ca
Sun Jun 2 05:42:47 CEST 2002


Dear Saket,

Linear models, as fit by the lm function, require a quantitative response 
variable. I'm surprised that you didn't encounter a problem in fitting the 
model in the first place.

If the response variable is categorical (which seems to be implied by a 
non-numeric response), then other models should be used. For example, if 
the response is dichotomous, a linear logit model may be appropriate; 
binary and binomial logit models may be fit in R with the glm (generalized 
linear model) function. If the response is polytomous, then there are 
several other possibilities.

I hope that this helps,
  John

At 05:05 PM 6/1/2002 -0700, Saket Joshi wrote:

>I had asked a question a few days ago on this list. I did not receive an
>answer. Since it was important to me, I looked for the answer in some
>references but as I am not really a statistics guy, the jargon was
>overwhelming for me. I apologize if this question is too trivial.
>
>Here is the question again:
>
>I used the lm() function to fit a linear model to a set of items that I
>got from a file using the read.table() function.
>
>The response variable in this case is non-numeric.
>
>When I used some of the data in the same file and tried to predict the
>response variable for the first 5 rows by doing:
>
> > pred <- predict(model, newdata)
> > pred
>         1         2         3         4         5
>37.890006 82.584161 30.794062  3.796456 41.568923
>
>The predictions should have been those non-numeric values that were in the
>response variable field when I fitted the model. Now I want to compare and
>see if the predictions are correct. Can someone tell me how to extract
>those non-numeric values from this.


-----------------------------------------------------
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
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list