[R] set type of SS in anova()

2008-07-05 Thread jeroenooms

When you use the 'general linear model' analysis in SPSS, the first result is
a table with all terms with F-tests and significance values for all IV's. It
uses  http://joyx.joensuu.fi/~ek/anova/sstypes.txt SS Type III , which has
the advantage that the order in which the variables are added to the model
does not matter, and therefore it is relatively objective.

I would like to reproduce this output in R. However, when using
anova(glm.object, test=F), the F test shows Terms added sequentially
(first to last). Because of this, the F values and p values of the terms
depend on the sequence in which they were added. Eg: an anova() of
glm(a~b+c) will give other results than glm(a~c+b).

How can I specify the SS type of an anova in R, so that i can reproduce the
exact results as that i got in SPSS?
-- 
View this message in context: 
http://www.nabble.com/set-type-of-SS-in-anova%28%29-tp18287076p18287076.html
Sent from the R help mailing list archive at Nabble.com.

__
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] set type of SS in anova()

2008-07-05 Thread Prof Brian Ripley

drop1() in R meets both your objection and that to 'Type III'.

If you really want the so-called Type III, look at function Anova() in 
package car.  But also consider


library(fortunes); fortune(54); fortune((55); fortune(56)

On Fri, 4 Jul 2008, jeroenooms wrote:



When you use the 'general linear model' analysis in SPSS, the first result is
a table with all terms with F-tests and significance values for all IV's. It
uses  http://joyx.joensuu.fi/~ek/anova/sstypes.txt SS Type III , which has
the advantage that the order in which the variables are added to the model
does not matter, and therefore it is relatively objective.


No, as the terms may well have a natural hierachy in which case the order 
does matter.



I would like to reproduce this output in R. However, when using
anova(glm.object, test=F), the F test shows Terms added sequentially
(first to last). Because of this, the F values and p values of the terms
depend on the sequence in which they were added. Eg: an anova() of
glm(a~b+c) will give other results than glm(a~c+b).


Hmm: glm() is used for generalized linear models, and there sums of 
squares are only appropriate for those models where lm() is more 
appropriate.



How can I specify the SS type of an anova in R, so that i can reproduce the
exact results as that i got in SPSS?


--
Brian D. Ripley,  [EMAIL PROTECTED]
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford, Tel:  +44 1865 272861 (self)
1 South Parks Road, +44 1865 272866 (PA)
Oxford OX1 3TG, UKFax:  +44 1865 272595

__
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] synthax for R CMD INSTALL

2008-07-05 Thread Prof Brian Ripley

I do not know what 'the R Utils docs' are, but --configure-args is plural!

You are not using the correct shell syntax: you need to use quotes when 
arguments contain spaces.  E.g.


--configure-args='--args=val1 --arg2=val2'

(and note that quotes are used in error info you quote).

That said, the error you got suggests that the value of 
--with-proj-include is incorrect.


I think you would be better off asking questions about installing on Mac 
OS X on r-sig-mac.


On Fri, 4 Jul 2008, Naiara Pinto wrote:


Dear all,

I am trying to install rgdal from source on a Mac OS 10.4.11. I installed
GDAL and PROJ as frameworks so the installation does not work unless I
explicitly state where the GDAL and PROJ libraries are. I tried:

R CMD INSTALL rgdal_0.5-25
--configure-args=--with-proj-include=/Library/Frameworks/PROJ.framework/unix/include
--with-proj-lib=/Library/Frameworks/PROJ.framework/unix/lib

but I still get error messages saying it was not able to find the PROJ
include file:

If the PROJ.4 library is installed in a non-standard location,
use --configure-args='--with-proj-include=/opt/local/include'
for example, replacing /opt/local/* with appropriate values
for your installation. If PROJ.4 is not installed, install it.
ERROR: configuration failed for package 'rgdal'

If I understood the R Utils docs correctly, --configure-args will accept one
argument only (so the first statement is always dropped). What should I do
if I need to specify the paths to several files?

Thank you,

Naiara.

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



--
Brian D. Ripley,  [EMAIL PROTECTED]
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford, Tel:  +44 1865 272861 (self)
1 South Parks Road, +44 1865 272866 (PA)
Oxford OX1 3TG, UKFax:  +44 1865 272595

__
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] trying to superimpose a line plot onto a histogram

2008-07-05 Thread Edwin Lei
Hello,

I'm trying to superimpose a line plot onto a histogram but I'm not having
any luck. I've attached the dataset. What I did was:

 hist(data,freq=F)

Now I'm trying to superimpose the following points with a line connecting
them onto the histogram:

 xy
100  0.535665393824959
200  0.212744329736556
300  0.0844933242968584
400  0.0335572838043417
500  0.0133275771274986
600  0.00529316714442912
700  0.0021022289461042
800  0.000834919136549392
900  0.000331595645597124
1000 0.000131696193518099
1100 5.2304327929049e-05
1200 2.07731343406939e-05

Basically, the x values correspond to the break points in the histogram.
Next I used the command

 points(x,y,type=l)

But for some reason, the line plot is shifted to the right and doesn't line
up with the histogram.

Thanks for the help!

Edwin Lei


data.pdf
Description: Adobe PDF document
__
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] lattice smooth

2008-07-05 Thread Troels Ring

Dear friends - I have a data.frame hh with columns
Na ID fit  time

135 13  134.7945   60
133 13  132.9084  120
131 13  131.0848  180
129 13  129.3372  240
127 13  127.5546  300
126 13  125.8162  360
124 13  124.1836  420
123 13  122.6077  480

When I use lattice
xyplot(Na+fit~time|ID,hh,type=c(smooth,g,p),
auto.key=list(lines=TRUE))

the curve for Na after time 240 takes some wild swings, and a warning is 
issued


Warning messages:
1: pseudoinverse used at 482.1
2: neighborhood radius 242.1
3: reciprocal condition number  0
4: at  360
5: radius  14400
6: all data on boundary of neighborhood. make span bigger
7: There are other near singularities as well. 14400
8: pseudoinverse used at 482.1
9: neighborhood radius 242.1
10: reciprocal condition number  0
11: at  360
12: radius  14400
13: all data on boundary of neighborhood. make span bigger
14: There are other near singularities as well. 14400

Otherwise for the whole dataset of 16 pigs it works quite OK - but only 
this pig number 13 makes troubles.

I wonder what occurs.
Best wishes
Troels

--

Troels Ring - -
Department of nephrology - - 
Aalborg Hospital 9100 Aalborg, Denmark - -

+45 99326629 - -
[EMAIL PROTECTED]

__
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] Bland-Altman method to measure agreement with repeated measures

2008-07-05 Thread kende jan

Dear all, 
 
I want to use the Bland-Altman method to measure agreement with repeated 
measures collected over period of time (seven periods).

How can I do this with R

 
Many thanks



  
_ 

o.fr
[[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.


Re: [R] update search path for attached data

2008-07-05 Thread Ulrich Leopold
On Fri, 2008-07-04 at 15:13 +0100, Prof Brian Ripley wrote:
 On Fri, 4 Jul 2008, Ulrich Leopold wrote:

  Dear list,
 
  is there a way of updating the search path when using attach() for a data
set.
 
  I am overwriting a variable in a data frame. To update teh search path I do
  the follwoing:
 
  attach(dataset)
  some data manipulation of dataset
  detach(dataset)
  attach(dataset) # to update the search path
 
  Is there a way to avoid the numerous detach() and attach() commands?

 Not if 'dataset' is that data frame (you didn't actually say).  From the
 help page:

   The database is not actually attached.  Rather, a new environment
   is created on the search path and the elements of a list
   (including columns of a data frame) or objects in a save file or
   an environment are _copied_ into the new environment.  If you use
   '-' or 'assign' to assign to an attached database, you only
   alter the attached copy, not the original object.

 So you can both change the data frame and assign the column to pos=2 to
 get the effect of what you appear to want.

How can I update directly the search path without using detach()
attach() or '-' assign()?
Maybe using attach() or assign methods is not so convenient anyway in my
case as it creates always a copy of each data set?

Is there a good practise in programming in R by using search paths but
keep memory as well as updating of the search path to a minimum?

Ulrich

-- 
__

Ulrich Leopold

Resource Centre for Environmental Technologies, Public Research Centre
Henri Tudor, Technoport Schlassgoart, 66 rue de Luxembourg, P.O. BOX
144, L-4002 Esch-sur-Alzette, Luxembourg

tel: +352 425991 618
fax: +352 425991 601
mobile: +352 691 304813
http://www.crte.lu


Computational Bio- and Physical Geography, Institute for Biodiversity
and Ecosystem Dynamics, University of Amsterdam, Nieuwe Achtergracht
166, NL-1018WV Amsterdam, The Netherlands

http://www.science.uva.nl/ibed

__
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] p-value for Nonmetric Multidimentional Scaling?

2008-07-05 Thread Gavin Simpson
On Fri, 2008-07-04 at 21:14 -0700, Michael Denslow wrote:
 Dear R-helpers,
 
 I am running metaMDS in the vegan package, which uses isoMDS in MASS,
 to perform Nonmetric Multidimentional Scaling (NMDS).
 
 I have seen some authors report a p-value for the NMDS ordination
 based on randomization of the dataset. As I understand it this is
 meant to compare the stress in your dataset to multiple runs of
 randomized data.
 I do not see a way to perform such a test in vegan or MASS.
 
 So my questions are:
 Is this necessary? and Does R have a function to do this?

No, but the following discussion on the r-forge repository for vegan
presents some ways that an analysis of this type could be done using
metaMDS:

http://r-forge.r-project.org/forum/forum.php?thread_id=586forum_id=194

But read Jari's comments carefully. If your data are species, then
consider whether permuting row, columns or both is appropriate when they
don't preserve the row or column totals. So a question to ask yourself
is, is permuting rows, columns or both going to derive the appropriate
Null hypothesis for the test you have in mind?

Please feel free to follow this up in the forum post I refer to.

All the best,

G

 
 Thanks in advance for your help,
 Michael
 
 __
 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-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] set type of SS in anova()

2008-07-05 Thread John Fox
Dear j.c.l.omms,

The Anova() function in the car package can compute so-called type-II and
type-III tests. When there are terms in the model that are marginal to
others (such as main effects marginal to interactions), type-III tests are
of questionable interest and have to be formulated carefully to test
sensible hypotheses. As well, since glm() with no family argument fits a
linear model with normal errors, it would be more usual in R to use lm().

Regards,
 John

--
John Fox, Professor
Department of Sociology
McMaster University
Hamilton, Ontario, Canada
web: socserv.mcmaster.ca/jfox

 -Original Message-
 From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]
On
 Behalf Of jeroenooms
 Sent: July-04-08 6:37 PM
 To: r-help@r-project.org
 Subject: [R] set type of SS in anova()
 
 
 When you use the 'general linear model' analysis in SPSS, the first result
is
 a table with all terms with F-tests and significance values for all IV's.
It
 uses  http://joyx.joensuu.fi/~ek/anova/sstypes.txt SS Type III , which has
 the advantage that the order in which the variables are added to the model
 does not matter, and therefore it is relatively objective.
 
 I would like to reproduce this output in R. However, when using
 anova(glm.object, test=F), the F test shows Terms added sequentially
 (first to last). Because of this, the F values and p values of the terms
 depend on the sequence in which they were added. Eg: an anova() of
 glm(a~b+c) will give other results than glm(a~c+b).
 
 How can I specify the SS type of an anova in R, so that i can reproduce
the
 exact results as that i got in SPSS?
 --
 View this message in context: http://www.nabble.com/set-type-of-SS-in-
 anova%28%29-tp18287076p18287076.html
 Sent from the R help mailing list archive at Nabble.com.
 
 __
 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-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] Test for multiple comparisons: Nonlinear model, autocorrelation?

2008-07-05 Thread J S

Thanks. Here is a similar example from a book by Pinheiro and Bates (2000, 
chapter 6):
 
library(nlme) data(Soybean) 
fm1Soy.lis - nlsList( weight ~ SSlogis(Time, Asym, xmid, scal),data = 
Soybean ) fm1Soy.nlme - nlme( fm1Soy.lis ) 
 
If we would like to make comparisons among the years we could just simply 
involve years as a covariate, and later we could use L argument to ANOVA to 
could compute contrasts. 
 
soyFix - fixef( fm1Soy.nlme )  fm2Soy.nlme - update( fm1Soy.nlme,fixed = 
Asym + xmid + scal ~ Year,start = c(soyFix[1], 0, 0, soyFix[2], 0, 0, 
soyFix[3], 0, 0) )
 
My question is: How can I compare variety of soybeans in a separate month, i.e. 
if there was a difference in weight of soybeans F and P in first month, …in 
twelve month?
 
The dataset “Soybean”:
  Plot Variety Year Timeweight
1   1988F1   F 1988   14  0.106000
2   1988F1   F 1988   21  0.261000
3   1988F1   F 1988   28  0.666000
4   1988F1   F 1988   35  2.11
5   1988F1   F 1988   42  3.56
….
407 1990P8   P 1990   30  1.478330
408 1990P8   P 1990   37  2.601667
409 1990P8   P 1990   43  6.343330
410 1990P8   P 1990   51  6.131670
411 1990P8   P 1990   64 16.411700
412 1990P8   P 1990   79 16.946700
 
1)  Involving months and variety as a covariates will probably create too 
many parameters for the model?
2)  Is it possible to use some test for comparisons, let’s say t test? 
Perhaps not in case the data are dependent (i.e. previous measurement is 
dependent on the next measurement, i.e. there is temporal correlation (as in my 
study of Soil temperature)? What is an alternative suggestion?
 
Thanks,
Julia Date: Fri, 4 Jul 2008 17:36:29 -0700 From: [EMAIL PROTECTED] To: 
[EMAIL PROTECTED] CC: r-help@r-project.org Subject: Re: [R] Test for multiple 
comparisons: Nonlinear model, autocorrelation?  The question seems too 
general for me to offer specific suggestions.  What problem are you trying to 
solve that you think 'multiple  comparisons' will answer?  Can you produce a 
similar problem that is completely self-contained  example that eliminates 
complexity that may not be needed to understand  your question (similar to the 
'Auxiliary Problem' technique in How to  Solve It, 
http://en.wikipedia.org/wiki/How_to_Solve_It)? If you can, it  may lead you to 
a solution. If you get such an example but still can't  see a solution, send 
that example to this list (following the advice in  the posting guide 
http://www.R-project.org/posting-guide.html). The  simpler the example, the 
more likely someone on this list will reply  quickly with a useful 
suggestion.  I know this doesn't solve your problem, but I hope it helps. 
Spencer  J S wrote:  Dear R community, I have a nonlinear model 
describing average daily soil temperature. What test should I use to compare 
differences in soil temperature of the two studied vegetation types depending 
upon month?Building linear contrasts for the developed nonlinear model 
does not help since this model does not include variable “Months” (only 
“Days”). 1) Just a Student’s test is not probably an option because I 
would violate an assumption of independency, since the daily soil temperature 
observations have high autocorrelation. Or maybe I could average the 
observations for each month and then use this test since I have observations 
for a few years, and it might overcome the problem of independency?2) 
Should I develop a second nonlinear model with months instead of days, but it 
would considerably increase a number of parameters in the model...Or: 
 3) ?Thanks for your help,  Julia  
_  It’s a 
talkathon – but it’s not just talk.   [[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.  
_
The i’m Talkaton. Can 30-days of conversation change the world?

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


Re: [R] trying to superimpose a line plot onto a histogram

2008-07-05 Thread milton ruser
How about the answer by Demitris?

Regards a lot,

miltinho

From: Dimitris Rizopoulos [EMAIL PROTECTED]
Date: Jun 16, 2008 4:05 AM
Subject: Re: [R] Superimposing Line over Histogram in Density Plot
To: Gundala Viswanath [EMAIL PROTECTED]
Cc: [EMAIL PROTECTED]

try something like this:

x - rnorm(200)
hist(x, col = blue, freq = FALSE)
lines(density(x), col = red, lwd = 2)





On 7/5/08, Edwin Lei [EMAIL PROTECTED] wrote:

 Hello,

 I'm trying to superimpose a line plot onto a histogram but I'm not having
 any luck. I've attached the dataset. What I did was:

  hist(data,freq=F)

 Now I'm trying to superimpose the following points with a line connecting
 them onto the histogram:

 xy
 100  0.535665393824959
 200  0.212744329736556
 300  0.0844933242968584
 400  0.0335572838043417
 500  0.0133275771274986
 600  0.00529316714442912
 700  0.0021022289461042
 800  0.000834919136549392
 900  0.000331595645597124
 1000 0.000131696193518099
 1100 5.2304327929049e-05
 1200 2.07731343406939e-05

 Basically, the x values correspond to the break points in the histogram.
 Next I used the command

  points(x,y,type=l)

 But for some reason, the line plot is shifted to the right and doesn't line
 up with the histogram.

 Thanks for the help!

 Edwin Lei

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




[[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] help about random generation of a Normal distribution of several variables

2008-07-05 Thread Arnau Mir
Hello.

Somebody knows how can I generate a set of n random vectors  of a normal
distribution of several variables?
For example, I want to generate n=100 random vectors of two dimensions for
a normal with mean c(0,1)  and  variance matrix:  matrix(c(2,1,1,3),2,2).

Thanks in advance,

Arnau.

__
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] help about random generation of a Normal distribution of several variables

2008-07-05 Thread Peng Jiang

Hi, Arnau,

 mvrnorm() in MASS library is what you need.
 ? mvrnorm to see the detail but first you need to load the MASS  
library, i.e,library(MASS)

 regards/
On 2008-7-6, at 上午12:21, Arnau Mir wrote:


Hello.

Somebody knows how can I generate a set of n random vectors  of a  
normal

distribution of several variables?
For example, I want to generate n=100 random vectors of two  
dimensions for
a normal with mean c(0,1)  and  variance matrix:  matrix(c(2,1,1,3), 
2,2).


Thanks in advance,

Arnau.

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


---
Peng Jiang 江鹏 ,Ph.D. Candidate
Antai College of Economics  Management
安泰经济管理学院
Department of Mathematics
数学系
Shanghai Jiaotong University (Minhang Campus)
800 Dongchuan Road
200240 Shanghai
P. R. China

__
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] help about random generation of a Normal distribution of several variables

2008-07-05 Thread Gavin Simpson
On Sat, 2008-07-05 at 18:21 +0200, Arnau Mir wrote:
 Hello.
 
 Somebody knows how can I generate a set of n random vectors  of a normal
 distribution of several variables?
 For example, I want to generate n=100 random vectors of two dimensions for
 a normal with mean c(0,1)  and  variance matrix:  matrix(c(2,1,1,3),2,2).

One is mvrnorm() in the MASS package, part of the VR bundle that comes
with R.

 require(MASS)
 mu - c(0,1)
 Sigma - matrix(c(2,1,1,3),2,2)
 res - mvrnorm(100, mu = mu, Sigma = Sigma)
 head(res)
   [,1][,2]
[1,]  2.7582876  1.04208798
[2,]  0.6364184 -0.08043244
[3,] -1.8897731  0.04051395
[4,]  2.6699881  0.83163661
[5,] -1.1942385 -1.17503716
[6,] -0.4303459 -0.80880649

HTH

G

__
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] Bland-Altman method to measure agreement with repeated measures

2008-07-05 Thread Marc Schwartz

on 07/05/2008 03:17 AM kende jan wrote:

Dear all,

I want to use the Bland-Altman method to measure agreement with
repeated measures collected over period of time (seven periods).

How can I do this with R


Many thanks




The following links should be helpful from a design/methodology perspective:

  Comparing within-subject variances in a study to compare two methods
  of measurement
  http://www-users.york.ac.uk/~mb55/meas/compsd.htm


  Agreement between methods of measurement with multiple observations
  per individual
  http://www-users.york.ac.uk/~mb55/meas/ba2007.htm


and perhaps more generally:

  http://www-users.york.ac.uk/~mb55/meas/comfaq.htm


You will need to provide more detail on your experimental design and 
data for any R specific guidance, which could feasibly include the use 
of mixed effects models where subject is a random effect. In the latter 
case, there is a R e-mail list focused on that approach:


  https://stat.ethz.ch/mailman/listinfo/r-sig-mixed-models

HTH,

Marc Schwartz

__
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] help about random generation of a Normal distribution of

2008-07-05 Thread Ted Harding
There is no need to load the MASS library, since the code for
mvrnorm therein is compact and self-contained:

mvrnorm - function (n=1, mu, Sigma, tol=1e-06, empirical=FALSE) 
{
  p - length(mu)
  if(!all(dim(Sigma) == c(p, p))) 
stop(incompatible arguments)
  eS - eigen(Sigma, symmetric = TRUE, EISPACK = TRUE)
  ev - eS$values
  if(!all(ev = -tol * abs(ev[1]))) 
stop('Sigma' is not positive definite)
  X - matrix(rnorm(p * n), n)
  if(empirical) {
X - scale(X, TRUE, FALSE)
X - X %*% svd(X, nu = 0)$v
X - scale(X, FALSE, TRUE)
  }
  X - drop(mu) +
   eS$vectors %*% diag(sqrt(pmax(ev, 0)), p) %*% t(X)
  nm - names(mu)
  if(is.null(nm)  !is.null(dn - dimnames(Sigma))) 
nm - dn[[1]]
  dimnames(X) - list(nm, NULL)
  if(n == 1) 
drop(X)
  else t(X)
}


Define that function as above, then proceed along the lines suggested
by Gavin Simpson below.

Ted.


On 05-Jul-08 16:43:46, Gavin Simpson wrote:
 On Sat, 2008-07-05 at 18:21 +0200, Arnau Mir wrote:
 Hello.
 
 Somebody knows how can I generate a set of n random vectors of a
 normal distribution of several variables?
 For example, I want to generate n=100 random vectors of two
 dimensions for a normal with mean c(0,1) and variance matrix: 
 matrix(c(2,1,1,3),2,2).
 
 One is mvrnorm() in the MASS package, part of the VR bundle that comes
 with R.
 
 require(MASS)
 mu - c(0,1)
 Sigma - matrix(c(2,1,1,3),2,2)
 res - mvrnorm(100, mu = mu, Sigma = Sigma)
 head(res)
[,1][,2]
 [1,]  2.7582876  1.04208798
 [2,]  0.6364184 -0.08043244
 [3,] -1.8897731  0.04051395
 [4,]  2.6699881  0.83163661
 [5,] -1.1942385 -1.17503716
 [6,] -0.4303459 -0.80880649
 
 HTH
 
 G


E-Mail: (Ted Harding) [EMAIL PROTECTED]
Fax-to-email: +44 (0)870 094 0861
Date: 05-Jul-08   Time: 18:09:23
-- XFMail --

__
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] SciViews GUI

2008-07-05 Thread Felipe Carrillo
HI:
After following all the instructions on how to install the SciViews package 
from CRAN I still can't make the GUI show. Can someone give me a hint on how to 
do this? I have tried library(svGUI), library(svDialogs) and so on with the 
rest of the packages. I have also placed all the 'sv' packages in my Rprofile 
but nothing works. Any help would be appreciated. Thanks

Felipe D. Carrillo 
Supervisory Fishery Biologist 
Department of the Interior 
US Fish  Wildlife Service
California, USA

__
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] SciViews GUI

2008-07-05 Thread Philippe Grosjean

Hello,

We need a little more information (which platform? which R version?).
Also, the GUI is NOT provided with the SciViews package. The version on 
CRAN is quite outdated and is designed to communicate with the old 
SciViews R Console GUI for Windows only. We are currently working on a 
new version that uses a new platform-independent GUI based on Komodo 
Edit. It will be uploaded to CRAN as soon as it will be finished, but 
for the moment, you can install alpha version from R-Forge. See detailed 
instructions on http://www.sciviews.org/SciViews-K. Note that alpha 
version is unsupported.

Best,

Philippe Grosjean

..°}))
 ) ) ) ) )
( ( ( ( (Prof. Philippe Grosjean
 ) ) ) ) )
( ( ( ( (Numerical Ecology of Aquatic Systems
 ) ) ) ) )   Mons-Hainaut University, Belgium
( ( ( ( (
..

Felipe Carrillo wrote:

HI:
After following all the instructions on how to install the SciViews package 
from CRAN I still can't make the GUI show. Can someone give me a hint on how to 
do this? I have tried library(svGUI), library(svDialogs) and so on with the 
rest of the packages. I have also placed all the 'sv' packages in my Rprofile 
but nothing works. Any help would be appreciated. Thanks

Felipe D. Carrillo 
Supervisory Fishery Biologist 
Department of the Interior 
US Fish  Wildlife Service

California, USA

__
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-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] using texmacs as front for R on windows xp sp2...

2008-07-05 Thread Brian Lunergan

Hi ho:

Has anybody made use of this 'editor' as a front for R v2.7.0? I'm running 
xp sp2. The texmacs website mentions the possibility of it but seems a 
little short on instruction or direction to explain the how of it.


--

Brian Lunergan
Nepean, Ontario
Canada



---

__
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] extracting values from a by function

2008-07-05 Thread Daniel Stahl
Hello,

I am trying to extract t and pvalues from a 1000 ttests using the by-function 
but everythinhg I tried did not work. Unfortunately googling by is not very 
helpful. Any help will be very appreciated. 
Cheers,
Danile Stall

*creating a data set
library(MASS)
dataset - mvrnorm(160, mu, Sigma)
dataset - as.data.frame(dataset)
dataset$GROUP - rep(1:10, each=16)
data.uni - reshape(df, varying = list(c(V1,V2)), 
v.names=Y,direction=long)
*the actual tests:
test-by(data.uni, data.uni$GROUP, function(x)t.test(Y ~ time, data = x, paired 
= TRUE))
*in case this will help you:
summary(test)
str(test)

 summary(test)
   Length Class Mode
1  9  htest list
2  9  htest list
3  9  htest list
4  9  htest list
5  9  htest list
6  9  htest list
7  9  htest list
8  9  htest list
9  9  htest list
10 9  htest list
 str(test)

List of 10
 $ 1 :List of 9
  ..$ statistic  : Named num -4.26
  .. ..- attr(*, names)= chr t
  ..$ parameter  : Named num 15
  .. ..- attr(*, names)= chr df
  ..$ p.value: num 0.000682
  ..$ conf.int   : atomic [1:2] -3.13 -1.04
  .. ..- attr(*, conf.level)= num 0.95
  ..$ estimate   : Named num -2.09
  .. ..- attr(*, names)= chr mean of the differences
  ..$ null.value : Named num 0
  .. ..- attr(*, names)= chr difference in means
  ..$ alternative: chr two.sided
  ..$ method : chr Paired t-test
  ..$ data.name  : chr Y by time
  ..- attr(*, class)= chr htest
 $ 2 :List of 9



-- 

__
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] Problem solved: extracting values from a by function

2008-07-05 Thread Daniel Stahl
Hi
I just discovered the answer thanks to a previous thread from Peter Daalgart
The command is: 
sapply(test, [[, statistic)

Cheers, Daniel

- Original Message -


To: r-help@r-project.org
Subject: extracting values from a by function
Date: Sun, 6 Jul 2008 05:59:04 +0800


Hello,

I am trying to extract t and pvalues from a 1000 ttests using the 
by-function but everythinhg I tried did not work. Unfortunately 
googling by is not very helpful. Any help will be very 
appreciated.
Cheers,
Danile Stall

*creating a data set
library(MASS)
dataset - mvrnorm(160, mu, Sigma)
dataset - as.data.frame(dataset)
dataset$GROUP - rep(1:10, each=16)
data.uni - reshape(df, varying = list(c(V1,V2)), 
v.names=Y,direction=long)
*the actual tests:
test-by(data.uni, data.uni$GROUP, function(x)t.test(Y ~ time, data 
= x, paired = TRUE))
*in case this will help you:
summary(test)
str(test)

 summary(test)
Length Class Mode
1  9  htest list
2  9  htest list
3  9  htest list
4  9  htest list
5  9  htest list
6  9  htest list
7  9  htest list
8  9  htest list
9  9  htest list
10 9  htest list
 str(test)

List of 10
  $ 1 :List of 9
   ..$ statistic  : Named num -4.26
   .. ..- attr(*, names)= chr t
   ..$ parameter  : Named num 15
   .. ..- attr(*, names)= chr df
   ..$ p.value: num 0.000682
   ..$ conf.int   : atomic [1:2] -3.13 -1.04
   .. ..- attr(*, conf.level)= num 0.95
   ..$ estimate   : Named num -2.09
   .. ..- attr(*, names)= chr mean of the differences
   ..$ null.value : Named num 0
   .. ..- attr(*, names)= chr difference in means
   ..$ alternative: chr two.sided
   ..$ method : chr Paired t-test
   ..$ data.name  : chr Y by time
   ..- attr(*, class)= chr htest
  $ 2 :List of 9



--
___










-- 

__
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] Error: cannot use PQL when using lmer

2008-07-05 Thread hpdutra

 library(MASS)
 attach(bacteria)
 table(y)
y
  n   y 
 43 177 
 y-1*(y==y)
 table(y,trt)
   trt
y   placebo drug drug+
  0  12   1813
  1  84   4449
 library(lme4)
 model1-lmer(y~trt+(week|ID),family=binomial,method=PQL)
Error in match.arg(method, c(Laplace, AGQ)) : 
  'arg' should be one of “Laplace”, “AGQ”

__
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] Error: cannot use PQL when using lmer

2008-07-05 Thread Ben Bolker
 hpdutra at yahoo.com writes:

 
 
  library(MASS)
  attach(bacteria)
  table(y)
 y
   n   y 
  43 177 
  y-1*(y==y)
  table(y,trt)
trt
 y   placebo drug drug+
   0  12   1813
   1  84   4449
  library(lme4)
  model1-lmer(y~trt+(week|ID),family=binomial,method=PQL)
 Error in match.arg(method, c(Laplace, AGQ)) : 
   'arg' should be one of “Laplace”, “AGQ”
 

  What is your question?
  Doug Bates warned a few weeks ago that the newer version
of lmer would no longer use PQL for GLMMs (he found that
it was unreliable, even as a starting method for Laplace fits).
I think you can still get the older version if you want
it, or you can use glmmPQL from the MASS package (glmmPQL
has some advantages anyway).
   It might be better to forward further discussion to
r-sig-mixed.

   Ben Bolker

__
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] Error: cannot use PQL when using lmer

2008-07-05 Thread hpdutra
I am trying to do an exercise on Crawley's book and I get this error message. I 
ran the same analysis in the past but now that I upgraded my R in my Macbook I 
get this message. Is this a bug or what is going on.
It doesn't make any sense

 library(MASS)
 attach(bacteria)
 table(y)
y
  n  y
43 177
 y-1*(y==y)
 table(y,trt)
  trt
y  placebo drug drug+
  0  12  1813
  1  84  4449
 library(lme4)
 model1-lmer(y~trt+(week|ID),family=binomial,method=PQL)
Error in match.arg(method, c(Laplace, AGQ)) :
  'arg' should be one of “Laplace”, “AGQ”

Humberto Dutra

__
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] interpreting mixed model anova results

2008-07-05 Thread Brooke LaFlamme
Hi, I am trying to do a repeated measures ANOVA to determine if there is a
significant difference between two sets of timecourse data. Each individual
was given a single treatment and then measured for one variable for 10 days.
Here is made-up example of what my data would look like:

data-data.frame(subject=rep(c(A1,A2,A3,B1,B2,B3),10),treatment=rep(c(A,B),each=3),
day=rep(c(1:10),each=6),response=rnorm(60))

This is the code I run to test for a difference between treatments A and B
over the course of the 10 days:

aov(response~day*treatment+Error(subject), data=data)

I believe this is the correct model to use, though I could definitely be
wrong.

Here is the output I get from my actual data (using summary(aov)):

Error: subject
  Df Sum Sq Mean Sq F value   Pr(F)
treatment  1 4258.1  4258.1  12.588 0.001344 **
Residuals 29 9810.2   338.3
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Error: Within
   Df Sum Sq Mean Sq F valuePr(F)
day 9  98345   10927 150.313  2.2e-16 ***
day:treatment   9   6844 760  10.461 8.374e-14 ***
Residuals 261  18974  73
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1


The p-value for treatment is the same as what I would get if I lumped the
data from all 10 days together, so I assume this is not what I want here.
However, am I correct in interpreting the p-value for day:treatment as what
I want? Does this tell me that there is a difference between the two groups
over the course of the 10 days (regardless of which days actually are
different) with respect to the fact that I am measuring the same subjects
each day?

Thanks for any help!
-- 
Brooke LaFlamme

[[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] help about random generation of a Normal distribution of several variables

2008-07-05 Thread Arnau Mir Torres

Hello.

Somebody knows how can I generate a set of n random vectors  of a  
normal distribution of several variables?
For example, I want to generate n=100 random vectors of two dimensions  
for a normal with mean c(0,1)  and  variance matrix:   
matrix(c(2,1,1,3),2,2).


Thanks in advance,

Arnau.

__
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] Random Forest %var(y)

2008-07-05 Thread David Katz

The verbose option gives a display like:

 rf.500 -
+   randomForest(new.x,trn.y,do.trace=20,ntree=100,nodesize=500,
+importance=T)
 |  Out-of-bag   |
Tree |  MSE  %Var(y) |
  20 |   0.9279   100.84 |


What is the meaning of %var(y)100%? I expected that to correspond to a
model that was worse than random, but the predictions seem much better than
that on the o-o-bag estimates from predict(rf.500).
-- 
View this message in context: 
http://www.nabble.com/Random-Forest--var%28y%29-tp18295412p18295412.html
Sent from the R help mailing list archive at Nabble.com.

__
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] trying to superimpose a line plot onto a histogram

2008-07-05 Thread Edwin Lei
Thanks for the quick response. But the points I'm trying to superimpose
isn't exactly the density of the data. Is there any other way to do it?

 

From: milton ruser [mailto:[EMAIL PROTECTED] 
Sent: July 5, 2008 6:56 AM
To: Edwin Lei
Cc: r-help@r-project.org
Subject: Re: [R] trying to superimpose a line plot onto a histogram

 

How about the answer by Demitris?

 

Regards a lot,

 

miltinho



From: Dimitris Rizopoulos [EMAIL PROTECTED]
Date: Jun 16, 2008 4:05 AM
Subject: Re: [R] Superimposing Line over Histogram in Density Plot
To: Gundala Viswanath [EMAIL PROTECTED]
Cc: [EMAIL PROTECTED]

try something like this:

x - rnorm(200)
hist(x, col = blue, freq = FALSE)
lines(density(x), col = red, lwd = 2)




 

On 7/5/08, Edwin Lei [EMAIL PROTECTED] wrote: 

Hello,

I'm trying to superimpose a line plot onto a histogram but I'm not having
any luck. I've attached the dataset. What I did was:

 hist(data,freq=F)

Now I'm trying to superimpose the following points with a line connecting
them onto the histogram:

xy
100  0.535665393824959
200  0.212744329736556
300  0.0844933242968584
400  0.0335572838043417
500  0.0133275771274986
600  0.00529316714442912
700  0.0021022289461042
800  0.000834919136549392
900  0.000331595645597124
1000 0.000131696193518099
1100 5.2304327929049e-05
1200 2.07731343406939e-05

Basically, the x values correspond to the break points in the histogram.
Next I used the command

 points(x,y,type=l)

But for some reason, the line plot is shifted to the right and doesn't line
up with the histogram.

Thanks for the help!

Edwin Lei

__
R-help@r-project.org mailing list

PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.



 


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


Re: [R] help about random generation of a Normal distribution of several variables

2008-07-05 Thread Peng Jiang
Hi , Arnau

Did you ever check your mailbox?  your question was answered last  
night  Beijing time. :)
Just read the following .
-

There is no need to load the MASS library, since the code for
mvrnorm therein is compact and self-contained:

mvrnorm - function (n=1, mu, Sigma, tol=1e-06, empirical=FALSE)
{
  p - length(mu)
  if(!all(dim(Sigma) == c(p, p)))
stop(incompatible arguments)
  eS - eigen(Sigma, symmetric = TRUE, EISPACK = TRUE)
  ev - eS$values
  if(!all(ev = -tol * abs(ev[1])))
stop('Sigma' is not positive definite)
  X - matrix(rnorm(p * n), n)
  if(empirical) {
X - scale(X, TRUE, FALSE)
X - X %*% svd(X, nu = 0)$v
X - scale(X, FALSE, TRUE)
  }
  X - drop(mu) +
   eS$vectors %*% diag(sqrt(pmax(ev, 0)), p) %*% t(X)
  nm - names(mu)
  if(is.null(nm)  !is.null(dn - dimnames(Sigma)))
nm - dn[[1]]
  dimnames(X) - list(nm, NULL)
  if(n == 1)
drop(X)
  else t(X)
}


Define that function as above, then proceed along the lines suggested
by Gavin Simpson below.

Ted.


On 05-Jul-08 16:43:46, Gavin Simpson wrote:
 On Sat, 2008-07-05 at 18:21 +0200, Arnau Mir wrote:
 Hello.

 Somebody knows how can I generate a set of n random vectors of a
 normal distribution of several variables?
 For example, I want to generate n=100 random vectors of two
 dimensions for a normal with mean c(0,1) and variance matrix:
 matrix(c(2,1,1,3),2,2).

 One is mvrnorm() in the MASS package, part of the VR bundle that comes
 with R.

 require(MASS)
 mu - c(0,1)
 Sigma - matrix(c(2,1,1,3),2,2)
 res - mvrnorm(100, mu = mu, Sigma = Sigma)
 head(res)
   [,1][,2]
 [1,]  2.7582876  1.04208798
 [2,]  0.6364184 -0.08043244
 [3,] -1.8897731  0.04051395
 [4,]  2.6699881  0.83163661
 [5,] -1.1942385 -1.17503716
 [6,] -0.4303459 -0.80880649

 HTH

 G


E-Mail: (Ted Harding) [EMAIL PROTECTED]
Fax-to-email: +44 (0)870 094 0861
Date: 05-Jul-08   Time: 18:09:23
-- XFMail --

__
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.
On 2008-7-6, at 上午12:13, Arnau Mir Torres wrote:

 Hello.

 Somebody knows how can I generate a set of n random vectors  of a  
 normal distribution of several variables?
 For example, I want to generate n=100 random vectors of two  
 dimensions for a normal with mean c(0,1)  and  variance matrix:   
 matrix(c(2,1,1,3),2,2).

 Thanks in advance,

 Arnau.

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

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


Re: [R] help about random generation of a Normal distribution ofseveral variables

2008-07-05 Thread Bill.Venables
 library(MASS)
 set.seed(22134)
 Y - mvrnorm(100, mu = c(0,1), Sigma = matrix(c(2,1,1,3),2,2))
 colMeans(Y)
[1] 0.06461359 1.08436419
 var(Y)
 [,1] [,2]
[1,] 1.683963 1.300363
[2,] 1.300363 3.280612
 


Bill Venables
CSIRO Laboratories
PO Box 120, Cleveland, 4163
AUSTRALIA
Office Phone (email preferred): +61 7 3826 7251
Fax (if absolutely necessary):  +61 7 3826 7304
Mobile: +61 4 8819 4402
Home Phone: +61 7 3286 7700
mailto:[EMAIL PROTECTED]
http://www.cmis.csiro.au/bill.venables/ 

-Original Message-
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]
On Behalf Of Arnau Mir Torres
Sent: Sunday, 6 July 2008 2:14 AM
To: r-help@r-project.org
Subject: [R] help about random generation of a Normal distribution
ofseveral variables

Hello.

Somebody knows how can I generate a set of n random vectors  of a  
normal distribution of several variables?
For example, I want to generate n=100 random vectors of two dimensions  
for a normal with mean c(0,1)  and  variance matrix:   
matrix(c(2,1,1,3),2,2).

Thanks in advance,

Arnau.

__
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-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] help about random generation of a Normal distribution ofseveral variables

2008-07-05 Thread Bill.Venables
What's the problem with loading the MASS library???  

The MASS library is one of the recommended packages, so should be universally 
available.

Pinching code like this and freezing it inside your personal scripts means that 
if ever we find bug fixes or improvements you miss out on them. 


Bill Venables
CSIRO Laboratories
AUSTRALIA
http://www.cmis.csiro.au/bill.venables/ 

-Original Message-
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Peng Jiang
Sent: Sunday, 6 July 2008 1:47 PM
To: Arnau Mir Torres
Cc: r-help@r-project.org
Subject: Re: [R] help about random generation of a Normal distribution 
ofseveral variables

Hi , Arnau

Did you ever check your mailbox?  your question was answered last  
night  Beijing time. :)
Just read the following .
-

There is no need to load the MASS library, since the code for
mvrnorm therein is compact and self-contained:

mvrnorm - function (n=1, mu, Sigma, tol=1e-06, empirical=FALSE)
{
  p - length(mu)
  if(!all(dim(Sigma) == c(p, p)))
stop(incompatible arguments)
  eS - eigen(Sigma, symmetric = TRUE, EISPACK = TRUE)
  ev - eS$values
  if(!all(ev = -tol * abs(ev[1])))
stop('Sigma' is not positive definite)
  X - matrix(rnorm(p * n), n)
  if(empirical) {
X - scale(X, TRUE, FALSE)
X - X %*% svd(X, nu = 0)$v
X - scale(X, FALSE, TRUE)
  }
  X - drop(mu) +
   eS$vectors %*% diag(sqrt(pmax(ev, 0)), p) %*% t(X)
  nm - names(mu)
  if(is.null(nm)  !is.null(dn - dimnames(Sigma)))
nm - dn[[1]]
  dimnames(X) - list(nm, NULL)
  if(n == 1)
drop(X)
  else t(X)
}


Define that function as above, then proceed along the lines suggested
by Gavin Simpson below.

Ted.


On 05-Jul-08 16:43:46, Gavin Simpson wrote:
 On Sat, 2008-07-05 at 18:21 +0200, Arnau Mir wrote:
 Hello.

 Somebody knows how can I generate a set of n random vectors of a
 normal distribution of several variables?
 For example, I want to generate n=100 random vectors of two
 dimensions for a normal with mean c(0,1) and variance matrix:
 matrix(c(2,1,1,3),2,2).

 One is mvrnorm() in the MASS package, part of the VR bundle that comes
 with R.

 require(MASS)
 mu - c(0,1)
 Sigma - matrix(c(2,1,1,3),2,2)
 res - mvrnorm(100, mu = mu, Sigma = Sigma)
 head(res)
   [,1][,2]
 [1,]  2.7582876  1.04208798
 [2,]  0.6364184 -0.08043244
 [3,] -1.8897731  0.04051395
 [4,]  2.6699881  0.83163661
 [5,] -1.1942385 -1.17503716
 [6,] -0.4303459 -0.80880649

 HTH

 G


E-Mail: (Ted Harding) [EMAIL PROTECTED]
Fax-to-email: +44 (0)870 094 0861
Date: 05-Jul-08   Time: 18:09:23
-- XFMail --

__
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.
On 2008-7-6, at 上午12:13, Arnau Mir Torres wrote:

 Hello.

 Somebody knows how can I generate a set of n random vectors  of a  
 normal distribution of several variables?
 For example, I want to generate n=100 random vectors of two  
 dimensions for a normal with mean c(0,1)  and  variance matrix:   
 matrix(c(2,1,1,3),2,2).

 Thanks in advance,

 Arnau.

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

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