Re: [R] Prediction in discriminant analysis

From: Joris Meys <jorismeys_at_gmail.com>
Date: Sat, 05 Jun 2010 22:46:59 +0200

You use the function "predict" for that. You give a data frame with the new observations, and make sure the variables have exactly the same name.

# run example
library(MASS)
Class <- as.factor(rep(c("A","B","C"),each=30))

X1 <- c(rnorm(30),rnorm(30,3,2),rnorm(30,-3,1)) X2 <- c(rnorm(30,5,3),rnorm(30,-2,4),rnorm(30,2,2))

result <- lda(Class~X1+X2)

newdat <- data.frame(X1=rnorm(10),X2=rnorm(10,5,3))

predictions <- predict(result,newdat) # predictions$class # gives the class to which the new observation belongs predictions$posterior # gives the posterior probabilities for each observation and for all classes
# end example

Cheers
Joris

On Sat, Jun 5, 2010 at 6:37 AM, suman dhara <suman.dhara89_at_gmail.com> wrote:
> Sir,
> I am working with multiclass discriminant analysis.(say response variable
> has 3classes).In R, using lda(), I get 2 sets of coefficients for the
> discriminant function.Now, I want to put a new x-vector(vector of
> independent variables) and want to check it corresponds to which class of
> y.Is there any formula for doing this? or how can I do this?
>
>
>
> Regards,
> Suman Dhara
>
>        [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help_at_r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

-- 
Ghent University
Faculty of Bioscience Engineering
Department of Applied mathematics, biometrics and process control

tel : +32 9 264 59 87
Joris.Meys_at_Ugent.be
-------------------------------
Disclaimer : http://helpdesk.ugent.be/e-maildisclaimer.php

______________________________________________
R-help_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Received on Sat 05 Jun 2010 - 20:50:05 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Sat 05 Jun 2010 - 21:10:27 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive