----- Forwarded message from Philipp Gunz <[email protected]> -----
Date: Fri, 15 Nov 2013 05:31:19 -0500
From: Philipp Gunz <[email protected]>
Reply-To: Philipp Gunz <[email protected]>
Subject: Re: 3D confidence ellipsoids in R
To: [email protected]
Hi Andrea,
Here is one way: you will have to install two additional libraries: pls and
rgl. When you execute the code at the bottom of this message you should get a
3D interactive plot.
All the best from Leipzig,
Philipp
##
library(MASS)
library(pls)
library(rgl)
colors<-c("darkred","orange","blue")
# Just creates some fake data-matrix
vars=10
N=100
Sigma <- matrix(diag(vars),vars,vars)
random1<-mvrnorm(n=N, rep(0,vars), Sigma)
random2<-mvrnorm(n=N, rep(1,vars), Sigma)
random3<-mvrnorm(n=N, rep(2,vars), Sigma)
groups<-c(rep(1,N),rep(2,N),rep(3,N))
data<-rbind(random1, random2, random3)
# Compute Principal components
cov.matrix=cov(data)
eigendec<-eigen(cov.matrix)
scores<-stdize(data,scale=FALSE) %*% eigendec$vectors
# 3D Plot
rgl.open()
rgl.viewpoint(fov = 1, zoom = 1)
bg3d("black")
# Plots the first three PC scores
rgl.spheres(scores[,1],scores[,2],scores[,3],col=colors[groups],radius=0.1,alpha=c(1))
# Plots the 95 percent confidence ellipsoids; the transparency is set by the
ALPHA level
for (i in 1:3) {
sub<-groups==i
Sigma<-cov(cbind(scores[sub,1],scores[sub,2],scores[sub,3]))
c<-apply(cbind(scores[sub,1],scores[sub,2],scores[sub,3]),2,mean)
plot3d(ellipse3d(Sigma, centre=c), col=colors[i], alpha=0.4, add =
TRUE,subdivide=50,level = 0.95)
}
Am 15.11.2013 um 11:07 schrieb [email protected]:
>
> ----- Forwarded message from andrea cardini <[email protected]> -----
>
> Date: Wed, 13 Nov 2013 08:14:14 -0500
> From: andrea cardini <[email protected]>
> Reply-To: andrea cardini <[email protected]>
> Subject: 3D confidence ellipsoids in R
> To: [email protected]
>
> Dear All,
> I'd greatly appreciate any suggestion about how
> to draw 3D confidence ellipsoids in R (packages? scripts? examples?)?
> Thanks a lot in advance for your help.
>
> Cheers
>
> Andrea
>
> Dr. Andrea Cardini
> Researcher in Animal Biology, Dipartimento di
> Scienze Chimiche e Geologiche, Università di
> Modena e Reggio Emilia, l.go S. Eufemia 19, 41121 Modena, Italy
> Honorary Fellow, Centre for Anatomical and Human
> Sciences, University of Hull, Cottingham Road,
> Hull, HU6 7RX, UK & University of York, Heslington, York YO10 5DD, UK
> Adjunct Associate Professor, Centre for Forensic
> Science , The University of Western Australia, 35
> Stirling Highway, Crawley WA 6009, Australia
>
> E-mail address: [email protected], [email protected]
> WEBPAGE: http://sites.google.com/site/hymsfme/drandreacardini
> Summary of research interests at:
> http://www.dscg.unimore.it/site/home/ricerca/aree-di-ricerca/evolution-taxonomy-and-forensics.html
>
> FREE Yellow BOOK on Geometric Morphometrics:
> http://www.italian-journal-of-mammalogy.it/issue/view/405
> or full volume at:
> http://www.italian-journal-of-mammalogy.it/public/journals/3/issue_241_complete_100.pdf
>
> Editorial board for:
> Zoomorphology:
> http://www.springer.com/life+sciences/animal+sciences/journal/435
> Journal of Zoological Systematics and
> Evolutionary Research:
> http://www.wiley.com/bw/journal.asp?ref=0947-5745&site=1
> Hystrix, the Italian Journal of
> Mammalogy: http://www.italian-journal-of-mammalogy.it/
>
> ----- End forwarded message -----
>
>
----- End forwarded message -----