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