[R] design matrix creation in R

2012-07-03 Thread mmstat

Hello, 

I want to create a design matrix using R. Can you explain the code which 
creates the following please? I understand the first part. 
b=g1(?) does what? 

dd <- data.frame(a = gl(3,4), b = gl(4,1,12)) # balanced 2-way 
dd 
a b 
1 1 1 
2 1 2 
3 1 3 
4 1 4 
5 2 1 
6 2 2 
7 2 3 
8 2 4 
9 3 1 
10 3 2 
11 3 3 
12 3 4 

I am using the tree dataset in R. I want to form a reparameterized design 
matrix in ones, zeroes and minus ones. The dataframe dd is very important here. 

Can anyone assist here? Thanks in advance. 

Mary A. Marion 




[[alternative HTML version deleted]]

__
R-help@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.


[R] 3-D ellipsoid equations update2. Error message when I run R code.

2011-11-05 Thread mmstat






+ 



Hello, 




I want to delete prior questions online but am getting an error message? 




Please see R code in enclosed file. I don't understand the error message. 






The parametric equations of an ellipsoid can be written in terms of spherical 
coordinates. The three spherical coordinates are converted to Cartesian 
coordinates by 






X=a cos (α) sin(θ) 

Y=b sin(α) sin(θ) 

Z=c cos(θ) 

The parameter α varies from 0 to 2 π and θ varies from 0 to π . Here ( X o , Y 
o ,Z o ) is the center of the ellipsoid, and θ is the angle of rotation. I need 
to come up with an expression for the ellipsoid expressed parametrically as the 
path of a point in 3- space. I think that it is something like the following: 



x (alpha)<- x0 + a * cos(theta) * cos(alpha) - b * sin(theta) * sin(alpha) 
y(alpha) <- y0 + a * cos(theta) * sin(alpha) + b * sin(theta) * cos(alpha) 
z (alpha)<- z0 + a * cos(theta) * sin(alpha) + c * sin(theta) * cos(alpha) 




Do I have these equations correct? 


Most of the books I have read use eigenvectors. The eigenvectors of course 
consist of the direction cosines. My difficulty is going from that approach to 
the approach that Alberto Monteiro took in his message on the 9 October 2006. I 
understand the R code and am using it for a two-dimensional ellipse problem. 
There does not seem to be allowance for the new coordinates of the center of 
the ellipsoid under the transformation when using direction cosines. By that I 
mean adding the centroid coordinates would not be necessary. 

I need to come up with an example where I do it both ways(as above and using 
direction cosines). 

My confusion lies in the fact that rather than one rotational angle theta there 
are 9 direction cosines. Can you assist with this. 



Sincerely, 
Mary A. Marion 




mat <- matrix(c(1,1,1,1,3,2,1,2,2), 3, 3)
eigens <- eigen(mat)
evs <- eigens$values
evecs <- eigens$vectors
a <- evs[1]
b <- evs[2]
c <- evs[3]
x0 <- 5
y0 <- 10
z0 <- 3
alpha <- atan(evecs[ , 1][2] / evecs[ , 1][1])
theta <- seq(0, 2 * pi, length=(1000))
# See Timm, Multivariate Analysis, page 62, Figure 1.6.2
# See Lay, Linear Algebra, third edition, page 84
x <- x0 + a * cos(theta) * cos(alpha) - b * sin(theta) * sin(alpha)
y <- y0 + a * cos(theta) * sin(alpha) + b * sin(theta) * cos(alpha)
z <- z0 + a * cos(theta) * sin(alpha) + c * sin(theta) * cos(alpha)
plot(x, y, z, type = "l", main = expression("x y z"), asp = 1, 
xlim=c(-5,20),ylim=c(-5,20), zlim=-5,20,xaxs = 'i', yaxs = 'i', zaxs='i')


error: Error in strsplit(log, NULL) : non-character argument

__
R-help@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.


Re: [R] 3-D ellipsoid equations

2011-11-05 Thread mmstat




+ 



Hello, 




The parametric equations of an ellipsoid can be written in terms of spherical 
coordinates. The three spherical coordinates are converted to Cartesian 
coordinates by 






X=a cos (α) sin(θ) 

Y=b sin(α) sin(θ) 

Z=c cos(θ) 



for α and θ 

The parameter α varies from 0 to 2 π and θ varies from 0 to π . Here ( X o 
, Y o ,Z o ) is the center of the ellipsoid, and θ is the angle of rotation. I 
need to come up with an expression for the ellipsoid expressed parametrically 
as the path of a point in 3- space. My first try is that it is something like 
the following: 



X(alpha)=Xo+a cos(α) cos( θ )-b sin(α) cos( θ ) + c cos( θ ) 
Y(alpha)=Yo+ cos (α) sin(θ)+b sin(α) cos (θ) 
Z(alpha)=Zo+a cos (α) sin(θ) +b sin(α) cos( θ ) 
Most of the books I have read use eigenvectors. The eigenvectors of course 
consist of the direction cosines. My difficulty is going from that approach to 
the approach that Alberto Monteiro took in his message on the 9 October 2006. I 
understand the R code and am using it for a two-dimensional ellipse problem. 
There does not seem to be allowance for the new coordinates of the center of 
the ellipsoid under the transformation when using direction cosines. By that I 
mean adding the centroid coordinates would not be necessary as is done in my 
"first try". 

Can you help me extend this to 3 dimensions? 

Sincerely, 
Mary A. Marion 














+ 









[[alternative HTML version deleted]]

__
R-help@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.


[R] drawing ellipses in R

2011-10-31 Thread mmstat
Hello, 

I have been following the thread dated Monday, October 9, 2006 when Kamila 
Naxerova asked a question about plotting elliptical shapes. Can you explain the 
equations for X and Y. I believe they used the parametric form of x and y (x=r 
cos(theta), y=r sin(theta). I don't know what r is here ? Can you explain 1)the 
origin of these equations and 2) what is r? 

Sincerely, 
Mary A. Marion 

[[alternative HTML version deleted]]

__
R-help@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.


[R] extraction of element

2010-11-20 Thread mmstat
Hello, 

I want only the value of Beta so the statement  Power<-1-Beta[1] works right. 

How to do?  See code below 

Beta <- integrate(dnorm,mean=0,sd=1, 2.3552,Inf) 
Power<- 1-Beta[1] 

Sincerely, 
Mary A. Marion

__
R-help@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.


[R] combining plots (curve + Plot functions)

2010-10-31 Thread mmstat
Hello, 
  
What I really want to do is to add a rejection region in the 
form of a long rectangle to a density plot I have drawn. 
I am getting  2 plots.  

How can I add rectangle to first plot?  see code below. 
First section works fine.  It just is not quite what I want. 

# NORMAL DISTRIBUTION PLOT OF RAW DATA WITH UPPER CRITICAL LEVEL - ok 
xcrit=144.1 
# *** single-sample Upper one-tailed hypothesis Test, z statistic *** 
cord.x <- c(xcrit,seq(xcrit,200,0.01),200) 
cord.y <- c(0,dnorm(seq(xcrit,200,0.01),140,15),0) 
curve(dnorm(x,140,15),xlim=c(80,200),main='Normal PDF',ylab="Probability") 
polygon(cord.x,cord.y,col='orange') 

# NORMAL DISTRIBUTION PLOT OF RAW DATA WITH UPPER CRITICAL LEVEL - 2 plots? 
xcrit=144.1 
# *** single-sample Upper one-tailed hypothesis Test, z statistic *** 
curve(dnorm(x,140,15),xlim=c(80,200),main='Normal PDF',ylab="Probability") 
plot(c(144.1, 200), c(0, .03), type= "n") 

Thanks. 
Mary A. Marion 

__
R-help@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.


Re: [R] plot pdf

2010-10-30 Thread mmstat


Subject: plot 

Your recent reply has got me underway.  However the savePlot command is not 
working.   
I am following refman example. Any thoughts?  

I am on a new windows 7 os.  I am not sure how to open a new device (output 
graphic
 window).  I wonder if that could be the problem? 

R Code
xcrit=135.9 
cord.x <- c(80,seq(80,xcrit,.1),xcrit) 
 cord.y <- c(0, dnorm(seq(80, xcrit, .1), 140, 15), 0) 
 curve(dnorm(x,140,15),xlim=c(80,200),main='Normal PDF',ylab="Probability") 
 polygon(cord.x,cord.y,col='orange') 
 savePlot(filename="c:\\lower.emf",type=c("emf"), device = 
dev.cur(),restoreConsole = TRUE) 
Warning messages: 
1: In savePlot(filename = "c:\\lower.emf", type = c("emf"), device = 
dev.cur(),  : 
  Unable to open metafile 'c:\lower.emf' for writing 
2: In savePlot(filename = "c:\\lower.emf", type = c("emf"), device = 
dev.cur(),  : 
  opening device failed 

Sincerely, 
Mary A. Marion 


 

__
R-help@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.


[R] plot pdf

2010-10-29 Thread mmstat


I want to plot the unstadardized version of a normal plot.  Can you explain 
why that is not working? 



Dev.set(1) 



xcrit=-1.645 



cord.x <- c(-3,seq(-3,xcrit,0.01),xcrit) 



cord.y <- c(0,dnorm(seq(-3,xcrit,0.01)),0)            # what does 
final 0 do here? 



curve(dnorm(x,0,1),xlim=c(-3,3),main='Normal PDF') 



polygon(cord.x,cord.y,col='orange') 



savePlot(filename="c:\\ssl_z.emf",type="emf")          #unable to 
create metafile?  why?  



  

x=seq(80,200,1) 



plot(x,dnorm(x,140,15),type="l",ylab="Probability") 





  

dev.set(4) 



xcrit=135.9 



cord.x <- c(80,seq(80,xcrit,.1),xcrit) 



cord.y <- c(0,dnorm(seq(80,xcrit,.1)),0)              #final 0 
needs to be changed but to what? 

curve(dnorm(x,140,15),xlim=c(80,200),main='Normal PDF',ylab="Probability") 



polygon(cord.x,cord.y,col='orange') 



savePlot(filename="c:\\ssl_z.emf",type="emf")         #unable to create 
metafile?  why?  



  



  

Sincerely, 

Mary A. Marion 





[[alternative HTML version deleted]]

__
R-help@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.