[R] PS to Taking Integral and Optimization using Integrate() and Optim()

2011-06-08 Thread MARYAM ZOLGHADR
Hello again.
Thank you for the comments. I have written these codes.

iy=function(x)
{
res=NULL
ress=0
for (i in (1:2))
{
for (xx in x[i])
{
fy=function(y) 
(exp(-exp(y+log(xx)))*(-exp(y+log(xx)))^2)/(1-exp(-exp(y+log(xx
res=c(res,integrate(fy,-6.907,-1.246)$value)
ress=ress+res
}
}
return(ress)
}
iy(c(1,1))
integrate(fy,-6.907,-1.246)$value

In 1D optimize() works perfectly on iy(). However the problem is in 2D and 
more, optimize() does not work and I need to apply optim(). I could not apply 
optim() on iy().

Beside, I tried to use Ryacas, I faced with this error:
[1] Starting Yacas!
Error in socketConnection(host = 127.0.0.1, port = 9734, server = FALSE, :
cannot open the connection
In addition: Warning message:
In socketConnection(host = 127.0.0.1, port = 9734, server = FALSE, :
127.0.0.1:9734 cannot be opened

Cheers,
Maryam

[[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] PS

2010-11-18 Thread Terry Therneau
 Note that there is NOT an intercept term in my pspline basis.  One of
the features of psplines is that \sum beta_i f_i(x) (where f_i are the
spline basis functions) is linear if and only if the coefficients beta
are a linear sequence.  This makes it easy to decompose the fit into
linear and non-linear effects.

Terry T

__
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] ps-output and LaTeX/DVIPS/PS2PDF - Greek letters disappear

2010-06-04 Thread Steffen Uhlig

Hello!

My graphs are produced using the postscript-option in R (R version 
2.10.1 (2009-12-14)). When Greek letters are used on the axis, 
everything looks fine in the *.ps-file. If included in a LaTeX-file and 
(on Ubuntu 10.04, fresh install), the Greek letters appear in the DVI- 
and PS-output, however, if converted with ps2pdf they suddenly 
disappear. Could anyone suggest a solution?


Best regards,
/steffen

--
Steffen Uhlig, PhD
Mechatronik und Sensortechnik
HTW des Saarlandes
Goebenstraße 40
66117 Saarbrücken

Tel.: +49 (0) 681 58 67 274

__
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] ps-output and LaTeX/DVIPS/PS2PDF - Greek letters disappear

2010-06-04 Thread Joris Meys
That's a problem of LateX and Ubuntu, not R :

https://bugs.launchpad.net/ubuntu/+source/poppler/+bug/319495

You'll have more luck on an Ubuntu list or forum.

Cheers
Joris

On Fri, Jun 4, 2010 at 11:47 AM, Steffen Uhlig
steffen.uh...@htw-saarland.de wrote:
 Hello!

 My graphs are produced using the postscript-option in R (R version 2.10.1
 (2009-12-14)). When Greek letters are used on the axis, everything looks
 fine in the *.ps-file. If included in a LaTeX-file and (on Ubuntu 10.04,
 fresh install), the Greek letters appear in the DVI- and PS-output, however,
 if converted with ps2pdf they suddenly disappear. Could anyone suggest a
 solution?

 Best regards,
 /steffen

 --
 Steffen Uhlig, PhD
 Mechatronik und Sensortechnik
 HTW des Saarlandes
 Goebenstraße 40
 66117 Saarbrücken

 Tel.: +49 (0) 681 58 67 274

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




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

tel : +32 9 264 59 87
joris.m...@ugent.be
---
Disclaimer : http://helpdesk.ugent.be/e-maildisclaimer.php

__
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] ps or pdf

2008-04-04 Thread Tribo Laboy
  The graphics devices are very similar (they share a lot of code).  One
  small difference is that PostScript has an arc primitive, and PDF does
  not.


Sorry for interjecting, but I have a burning question. It is a bit off
topic, so I apologize in advance.

What is the stance of the R Developers regarding this missing R
primitive in PDF? Because of the missing primitive all circles are
represented as O characters. I have run into problems when trying to
import R produced PDF plots into Inkscape for some additional post
processing and beautification. As a workaround I currently use the
Cairo device to export to PDF (and SVG). But this is a bit heavy. It
would be nice to be able to save Inkscape editable PDFs directly from
the plot window.

Some other far more important issues that could occur have been raised
in a past thread:
http://www.nabble.com/pdf%28%29-device-uses-fonts-to-represent-points---data-alteration--td13034770.html
For example the unintentional misrepresentation of data on the plot if
font substitution occurs and the points are shifted from their
original location.

Is this considered a bug or a feature?

Regards,
TL

__
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] ps or pdf

2008-04-01 Thread Joerg van den Hoff
have not followed the thread completely, but:

have you tried `bitmap' with `type = pdfwrite' (or psgrb)
for comparison? at least with `pdf' there are some issues which
can be avoided by using ghostscript via `bitmap'.

joerg

On Mon, Mar 31, 2008 at 04:17:50PM -0400, Francois Pepin wrote:
 Prof Brian Ripley wrote:
  Please see the footer of this message.  
 
 Sorry, here is an example. For some reason, I cannot reproduce it 
 without using actual gene names.
 
 set.seed(1)
 ##The row names were originally obtained using the hgug4112a library 
 ##from bioconductor. I set it manually for people who don't have it 
 ##installed.
 ##library(hgug4112a);row-sample(na.omit(unlist(as.list(hgug4112aSYMBOL))),50)
 row-c(BDNF, EMX2, ZNF207, HELLS, PWP1, PDXDC1,  BTD, 
 NETO1, SLCO4C1, FZD7, NICN1, TMSB4Y, PSMB7,  CADM2, 
 SIRT3, ADH6, TM6SF1, AARS, TMEM88, CP110,  ADORA2A, 
 ATAD3A, VAPA, NXPH3, IL27RA, NEBL, FANCF,  PTPRG, 
 HSU79275, CCDC34, EPDR1, FBLN1, PCAF, AP1B1,  TXNRD2, 
 MUC20, MBNL1, STAU2, STK32C, PPIAL4, TGFBR2,  DPY19L2P3, 
 TMEM50B, ENY2, MAN2A2, ZFYVE26, TECTA,  CD55, LOC400794, 
 SLC19A3)
 postscript('/tmp/heatmap.ps',paper='letter',horizontal=F)
 heatmap(matrix(rnorm(2500),50),labRow=row)
 dev.off()
 
  Neither postscript() nor pdf() 
  graphics devices split up strings they are passed (by e.g. text()), so 
  this is being done either by the code used to create the plot (and we 
  have no idea what that is) or by the viewer.  I suspect the problem is 
  rather in the viewer, but without the example we asked for it is 
  impossible to know.
 
 Example of row names that are truncated in Illustrator (* denoting 
 truncation):
 CCDC3*4 (2nd row)
 MUC2*0 (3rd row)
 MBNL*1 (8th row)
 ...
 
 It is likely that Illustrator (CS 3, OS X version) is at fault.  I do 
 not see any truncation if I look at the ps file by hand (lines 4801 and 
 4802):
 
 540.22 545.88 (MUC20) 0 0 0 t
 540.22 553.90 (CCDC34) 0 0 0 t
 
  There also seems to be somewhat arbitrary grouping of the last column
  cells in heatmaps in ps files.
  
  Again, we need an example.
 
 The top right cell (26, TXNRD2) is grouped with the cell just below it 
 (26, CCDC34). It's more of a curiosity than anything else.
 
  I used to prefer the ps because they embed more easily in latex
  documents (although pdf are not difficult and conversions are trivial
  anyhow), but I'm curious if there are other reasons why one format might
  be preferred over the other in this context.
  
  The graphics devices are very similar (they share a lot of code).  One 
  small difference is that PostScript has an arc primitive, and PDF does not.
 
 This is what I thought at first, which is why I found these differences 
 surprising. I think your idea of blaming the viewer is correct. I 
 thought that Adobe of all people could deal with Postscript files 
 properly, but I guess I was overly trusting.
 
 Thanks for the help,
 
 Francois
 
 __
 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] ps or pdf

2008-03-31 Thread Francois Pepin
Hi everyone,

I have been making a fair amount of figures in R recently that I've
been touching up with Illustrator and I've found a difference between
pdf and ps files and I was wondering if someone could enlighten me
about them.

While the figures look the same, the ps version tends to have
truncated strings. The last character of short strings tends to be on
a string of its own, located right beside the rest. This makes it a bit 
awkward to manipulate, especially if scaling is involved. Is there a 
reason for this differences?

There also seems to be somewhat arbitrary grouping of the last column 
cells in heatmaps in ps files.

I used to prefer the ps because they embed more easily in latex
documents (although pdf are not difficult and conversions are trivial
anyhow), but I'm curious if there are other reasons why one format might
be preferred over the other in this context.

This is with R 2.6 on linux, and I've seen this behavior with older R
version also.

Francois

sessionInfo()
R version 2.6.0 (2007-10-03)
x86_64-unknown-linux-gnu

locale:
LC_CTYPE=en_US.UTF-8;LC_NUMERIC=C;LC_TIME=en_US.UTF-8;LC_COLLATE=en_US.UTF-8;LC_MONETARY=en_US.UTF-8;LC_MESSAGES=en_US.UTF-8;LC_PAPER=en_US.UTF-8;LC_NAME=C;LC_ADDRESS=C;LC_TELEPHONE=C;LC_MEASUREMENT=en_US.UTF-8;LC_IDENTIFICATION=C

attached base packages:
[1] stats graphics  grDevices utils datasets  methods   base

loaded via a namespace (and not attached):
[1] rcompgen_0.1-15

__
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] ps or pdf

2008-03-31 Thread Prof Brian Ripley
On Mon, 31 Mar 2008, Francois Pepin wrote:

 Hi everyone,

 I have been making a fair amount of figures in R recently that I've
 been touching up with Illustrator and I've found a difference between
 pdf and ps files and I was wondering if someone could enlighten me
 about them.

 While the figures look the same, the ps version tends to have
 truncated strings. The last character of short strings tends to be on
 a string of its own, located right beside the rest. This makes it a bit
 awkward to manipulate, especially if scaling is involved. Is there a
 reason for this differences?

Please see the footer of this message.  Neither postscript() nor pdf() 
graphics devices split up strings they are passed (by e.g. text()), so 
this is being done either by the code used to create the plot (and we have 
no idea what that is) or by the viewer.  I suspect the problem is rather 
in the viewer, but without the example we asked for it is impossible to 
know.

 There also seems to be somewhat arbitrary grouping of the last column
 cells in heatmaps in ps files.

Again, we need an example.

 I used to prefer the ps because they embed more easily in latex
 documents (although pdf are not difficult and conversions are trivial
 anyhow), but I'm curious if there are other reasons why one format might
 be preferred over the other in this context.

The graphics devices are very similar (they share a lot of code).  One 
small difference is that PostScript has an arc primitive, and PDF does 
not.

 This is with R 2.6 on linux, and I've seen this behavior with older R
 version also.

Nothing has changed at that level for a long time -- not even in 
current versions of R (and 2.6.0 is obsolete).


 Francois

 sessionInfo()
 R version 2.6.0 (2007-10-03)
 x86_64-unknown-linux-gnu

 locale:
 LC_CTYPE=en_US.UTF-8;LC_NUMERIC=C;LC_TIME=en_US.UTF-8;LC_COLLATE=en_US.UTF-8;LC_MONETARY=en_US.UTF-8;LC_MESSAGES=en_US.UTF-8;LC_PAPER=en_US.UTF-8;LC_NAME=C;LC_ADDRESS=C;LC_TELEPHONE=C;LC_MEASUREMENT=en_US.UTF-8;LC_IDENTIFICATION=C

 attached base packages:
 [1] stats graphics  grDevices utils datasets  methods   base

 loaded via a namespace (and not attached):
 [1] rcompgen_0.1-15

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


Re: [R] ps or pdf

2008-03-31 Thread Francois Pepin
Prof Brian Ripley wrote:
 Please see the footer of this message.  

Sorry, here is an example. For some reason, I cannot reproduce it 
without using actual gene names.

set.seed(1)
##The row names were originally obtained using the hgug4112a library 
##from bioconductor. I set it manually for people who don't have it 
##installed.
##library(hgug4112a);row-sample(na.omit(unlist(as.list(hgug4112aSYMBOL))),50)
row-c(BDNF, EMX2, ZNF207, HELLS, PWP1, PDXDC1,  BTD, 
NETO1, SLCO4C1, FZD7, NICN1, TMSB4Y, PSMB7,  CADM2, 
SIRT3, ADH6, TM6SF1, AARS, TMEM88, CP110,  ADORA2A, 
ATAD3A, VAPA, NXPH3, IL27RA, NEBL, FANCF,  PTPRG, 
HSU79275, CCDC34, EPDR1, FBLN1, PCAF, AP1B1,  TXNRD2, 
MUC20, MBNL1, STAU2, STK32C, PPIAL4, TGFBR2,  DPY19L2P3, 
TMEM50B, ENY2, MAN2A2, ZFYVE26, TECTA,  CD55, LOC400794, 
SLC19A3)
postscript('/tmp/heatmap.ps',paper='letter',horizontal=F)
heatmap(matrix(rnorm(2500),50),labRow=row)
dev.off()

 Neither postscript() nor pdf() 
 graphics devices split up strings they are passed (by e.g. text()), so 
 this is being done either by the code used to create the plot (and we 
 have no idea what that is) or by the viewer.  I suspect the problem is 
 rather in the viewer, but without the example we asked for it is 
 impossible to know.

Example of row names that are truncated in Illustrator (* denoting 
truncation):
CCDC3*4 (2nd row)
MUC2*0 (3rd row)
MBNL*1 (8th row)
...

It is likely that Illustrator (CS 3, OS X version) is at fault.  I do 
not see any truncation if I look at the ps file by hand (lines 4801 and 
4802):

540.22 545.88 (MUC20) 0 0 0 t
540.22 553.90 (CCDC34) 0 0 0 t

 There also seems to be somewhat arbitrary grouping of the last column
 cells in heatmaps in ps files.
 
 Again, we need an example.

The top right cell (26, TXNRD2) is grouped with the cell just below it 
(26, CCDC34). It's more of a curiosity than anything else.

 I used to prefer the ps because they embed more easily in latex
 documents (although pdf are not difficult and conversions are trivial
 anyhow), but I'm curious if there are other reasons why one format might
 be preferred over the other in this context.
 
 The graphics devices are very similar (they share a lot of code).  One 
 small difference is that PostScript has an arc primitive, and PDF does not.

This is what I thought at first, which is why I found these differences 
surprising. I think your idea of blaming the viewer is correct. I 
thought that Adobe of all people could deal with Postscript files 
properly, but I guess I was overly trusting.

Thanks for the help,

Francois

__
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] [PS] vlookup in R

2008-03-24 Thread Ben Fairbank
Another way:

If x is a two column matrix, as suggested by Henrique D., 

   IDValue
1   7  0.000656733
2   6  0.201764789
3   1  0.671113391
4  10 -0.739727826
5   9 -1.111310154
6   5 -0.859455833
7   2 -1.408229877
8   8  0.993126295
9   3 -0.171906808
10  4 -0.140107677

And you are looking up the value corresponding to ID

 ID - 4

x[(1:dim(x)[1])[x[,1]==ID],2]

will also do it, and you can vary the value of the 2 in order to query
the column of interest, much as you can do with vlookup in the E
program.

Ben 

-Original Message-
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]
On Behalf Of Sachin J
Sent: Monday, March 24, 2008 9:25 AM
To: r-help@r-project.org
Subject: [PS] [R] vlookup in R

Hi,

Is there are function similar to excel vlookup in R. Please let me know.

Thanks,
Sachin

__
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] [PS] Re: vlookup in R

2008-03-24 Thread Ben Fairbank
Quite right, there is an optional 4th argument, and the table must be
sorted ascending on the first column in Excel.  Thus these functions
only approximately duplicate the Excel functions (improve on them IMHO).

BTW, I pasted the wrong formula in my reply; though it works, simpler is

ID - 4  #for example, find value corresponding to 4

x[x[,1]==ID,2]

Ben 

-Original Message-
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]
On Behalf Of David Winsemius
Sent: Monday, March 24, 2008 10:20 AM
To: [EMAIL PROTECTED]
Subject: [PS] Re: [R] vlookup in R

Sachin J [EMAIL PROTECTED] wrote in
news:[EMAIL PROTECTED]: 

 Is there are function similar to excel vlookup in R. Please let me
 know. 
 
Caveat: definition of VLOOKUP done from memory and by checking OO.o 
Calc function of same name. (Don't have Excel on this machine.)

VLOOKUP looks up a single value in the first column of an Excel range 
and returns a column value (offset by a given integer) from the first 
matching row in that range. The indexing functions (extract or 
[ ) can be used:

 df4
 V1 V2  V3
1  4.56  1 0.1
2  8.42  1 0.2
3  0.79  3 0.3
4  5.39  3 0.4
5  0.95  4 0.5
6  7.73  5 0.6
7  7.17  6 0.7
8  3.89  7 0.8
9  0.54 10 1.0
10 9.53  9 0.9

 df4[df4$V1==0.79,2]
[1] 3

vlookup - function(val, df, row){
   df[df[1] == val, row][1] }

 vlookup(0.79, df4, 2)
[1] 3

I thought there was an optional 4th argument to VLOOKUP that specifies 
the action to be taken if there is no exact match. You may need to 
change the equality in that function to an inequality and identify the 
first column value that is less than or equal to val. If I remember 
correctly, Excel assumes that the first column is ordered ascending.

-- 
David Winsemius

__
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] [PS] rmultinomial() function

2008-03-19 Thread Ben Fairbank
Mary --

The dmultinomial function (try ?Multinomial, noting that it is an upper
case M) has a log option, which, if set to TRUE, returns logarithms of
probabilities, but that is for computing probabilities, not generating
samples.  Perhaps the long you referred to is a misprint for log?

In any case, try ?Multinomial, and give rmultinom() another try.  Note,
however, that its output gives the _number_ of each of the sampled items
produced in a single sample, not the sequence of draws.  If you need the
sequence, then I think that the reply from Erik Iverson tells you how
best to proceed.

Ben 

-Original Message-
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]
On Behalf Of Mary Black
Sent: Tuesday, March 18, 2008 5:29 PM
To: r-help@r-project.org
Subject: [PS] [R] rmultinomial() function

After scouring the online R resources and help pages, I still need
clarification on the function rmultinomial().  I would like to create a
vector, say of 100 elements, where every element in the vector can take
on the value of 0, 1 or 2, and where each of those values have a
specific probability. ie. the probability a given element in the vector
= 0 is 0.06, 1 = 0.38, 2 = 0.56 (probabilities sum to 1). Can I use
rmultinomial() function to do this?  

The following code does not seem to produce the result I need, but this
sort of code is all I could find the R help pages:
 
 rmultinomial(100,c(0.06,0.38,0.56))
[1]  3 29 68
 rmultinomial(100,c(0.06,0.38,0.56),long=TRUE)
  [1] 3 3 2 2 3 2 3 3 2 3 2 3 3 3 2 2 3 3 2 3 1 2 3 3 3 3 3 3 2 3 3 2 3
3 3 2 3 2 2 3 2 3 2 3 3 3 2 1 3 3 1
 [52] 2 3 2 2 3 3 2 2 2 1 3 3 2 3 3 3 3 2 3 3 3 3 2 3 2 3 3 2 3 3 2 3 3
2 3 2 3 3 2 3 3 3 2 3 2 2 2 2 2

Also, I don't really understand the difference between the default
long=FALSE and long=TRUE.  The R help simply states that you use long
TRUE to choose one generator, FALSE to choose another one; however I
could not find any documentation that described what the difference
between those generators is.  Any clarification would be greatly
appreciated! 

Thanks,

Mary

__
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] [PS] rmultinomial() function

2008-03-19 Thread Mary Black
Thanks Ben and Eric.  I've already tried rmultinom(), and there is a 
rmultinomial() function as well (which is in the multinomRob package). The 
rmultinomial() is supposed to be a random number generator for the multinomial 
distribution.  There is an argument long which if set to TRUE or FALSE, 
utlize different generators, but the documentation doesn't explain any further. 
Thus, my confusion about the output.  If anyone can explain further how the two 
generators are different, I would love to know!  



- Original Message -
From: Ben Fairbank [EMAIL PROTECTED]
Date: Wednesday, March 19, 2008 7:36 am
Subject: RE: [PS]  [R] rmultinomial() function
To: Mary Black [EMAIL PROTECTED], r-help@r-project.org

 Mary --
 
 The dmultinomial function (try ?Multinomial, noting that it is an 
 uppercase M) has a log option, which, if set to TRUE, returns 
 logarithms of
 probabilities, but that is for computing probabilities, not generating
 samples.  Perhaps the long you referred to is a misprint for log?
 
 In any case, try ?Multinomial, and give rmultinom() another try.  
 Note,however, that its output gives the _number_ of each of the 
 sampled items
 produced in a single sample, not the sequence of draws.  If you 
 need the
 sequence, then I think that the reply from Erik Iverson tells you how
 best to proceed.
 
 Ben 
 
 -Original Message-
 From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]
 project.org]On Behalf Of Mary Black
 Sent: Tuesday, March 18, 2008 5:29 PM
 To: r-help@r-project.org
 Subject: [PS] [R] rmultinomial() function
 
 After scouring the online R resources and help pages, I still need
 clarification on the function rmultinomial().  I would like to 
 create a
 vector, say of 100 elements, where every element in the vector can 
 takeon the value of 0, 1 or 2, and where each of those values have a
 specific probability. ie. the probability a given element in the 
 vector= 0 is 0.06, 1 = 0.38, 2 = 0.56 (probabilities sum to 1). 
 Can I use
 rmultinomial() function to do this?  
 
 The following code does not seem to produce the result I need, but 
 thissort of code is all I could find the R help pages:
 
  rmultinomial(100,c(0.06,0.38,0.56))
 [1]  3 29 68
  rmultinomial(100,c(0.06,0.38,0.56),long=TRUE)
  [1] 3 3 2 2 3 2 3 3 2 3 2 3 3 3 2 2 3 3 2 3 1 2 3 3 3 3 3 3 2 3 
 3 2 3
 3 3 2 3 2 2 3 2 3 2 3 3 3 2 1 3 3 1
 [52] 2 3 2 2 3 3 2 2 2 1 3 3 2 3 3 3 3 2 3 3 3 3 2 3 2 3 3 2 3 3 
 2 3 3
 2 3 2 3 3 2 3 3 3 2 3 2 2 2 2 2
 
 Also, I don't really understand the difference between the default
 long=FALSE and long=TRUE.  The R help simply states that you use 
 longTRUE to choose one generator, FALSE to choose another one; 
 however I
 could not find any documentation that described what the difference
 between those generators is.  Any clarification would be greatly
 appreciated! 
 
 Thanks,
 
 Mary
 
 __
 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] [PS] Two Way ANOVA

2008-03-19 Thread David Mackovjak
Ben,
I would like to test the sulfur on the clover field, nitrogen on the clover 
field and then test for the presence of interaction.

Sorry about the last email, seems it really screwed itself over, here it is 
again, hopefully nicer:

  Nitrogen(0)  Nitrogen(20)
Sulfur(0)   4.54  5.73
Sulfur(3)4.647.05
Sulfur(6)5.275.81
Sulfur(9)5.816.30

Each of those is a cell mean of 3 values.

Would I simply do as follows?:

yield- c(4.54,4.64,5.27,5.81,5.73,7.05,5.81,6.30)
sulfur - c(1,2,3,4,1,2,3,4)
nitro - c(1,1,1,1,2,2,2,2)

summary(aov(yield~sulfur*nitro))


Thanks, DM

- Original Message 
From: Ben Fairbank [EMAIL PROTECTED]
To: David Mackovjak [EMAIL PROTECTED]
Sent: Wednesday, March 19, 2008 3:14:36 PM
Subject: RE: [PS]  [R] Two Way ANOVA

DM --

I think it would be helpful if you could also tell us what it is you are
hoping to find out from the analysis.  For example, a statement such as
I am seeking to find if there are any effects of the concentration (or
presence?) of nitrogen and/or sulfur on the (fill in your dependent
variable, such as 'cell division times' or 'changes in unbuffered pH' or
whatever it is).  That will help readers to see what design you need.
For example, do you want to look ONLY for an interaction, or do you want
to test for main effects of N and S also?

You might like to download Faraway's 2002 paper Practical Regression
and Anova Using R as start; google should find it for you.

Ben 

-Original Message-
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]
On Behalf Of David Mackovjak
Sent: Wednesday, March 19, 2008 5:02 PM
To: r-help@r-project.org
Subject: [PS] [R] Two Way ANOVA

First time using, the mailing list and I'm somewhat new to R, so excuse
me if I do anything wrong.

I was wondering how I would set up a two way ANOVA for the following
data:


  
  Nitrogen
  (0)
   
  Nitrogen
  (20)
   
   
 
   
  (cell
  means)
   
  (cell
  means)
  [Sulfur means]
Sulfur (0)
  4.48
   
  5.76
   
   
 
  4.52
  (4.54)
  5.64
  (5.73)
  [5.14]
 
  4.63
   
  5.78
   
   
 
   
   
   
   
   
Sulfur (3)
  4.70
   
  7.01
   
   
 
  4.65
  (4.64)
  7.11
  (7.05)
  [5.84]
 
  4.57
   
  7.02
   
   
 
   
   
   
   
   
Sulfur (6)
  5.21
   
  5.88
   
   
 
  5.23
  (5.27)
  5.82
  (5.81)
  [5.54]
 
  5.38
   
  5.73
   
   
 
   
   
   
   
   
Sulfur (9)
  5.88
   
  6.26
   
   
 
  5.98
  (5.81)
  6.26
  (6.30)
  [6.11]
 
  5.91
   
  6.37
   
   
 
   
   
   
   
   
[Nitrogen means]
  [5.10]
   
  [6.22]
   
  
 
   Source ofVariation SS

Sulfur3.15
Nitrogen  7.59
Sulfur x Nitrogen 3.84
Error 0.08

Total14.66


From googling I know I want to get it to the form:

 fit - aov(y ~ A*B, data=mydataframe)

But what would I set for A, B and y?




 


Looking for last minute shopping deals?

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





  

Be a better friend, newshound, and

__
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] [PS] Two Way ANOVA

2008-03-19 Thread David Mackovjak
I do have the values for each individual values for each cell. They are as 
follows:

N(0)N(20)
4.48  5.76
4.52  5.64
4.635.78

4.70  7.01
4.65  7.11
4.57  7.02

5.21  5.88
5.23  5.82
5.38  5.73

5.88  6.26
5.98  6.26
5.91  6.37

So how would I go about this then?

- Original Message 
From: Rolf Turner [EMAIL PROTECTED]
To: David Mackovjak [EMAIL PROTECTED]
Sent: Wednesday, March 19, 2008 4:36:47 PM
Subject: Re: [R] [PS]   Two Way ANOVA


With the given structure of your data you CANNOT test for interaction  
in the
general sense.  There are no degrees of freedom left for error.

If you have access to the (three) individual values in each cell,  
then you
can test for interaction.

If these individual values are lost to posterity [Expostulation:  Why  
the
expletive deleted do people ***do*** things like this?  Use your  
expletive deleted
data, not summary statistics!!!] then you can still test for a  
***particular form***
of interaction using Tukey's ``1 degree of freedom for non- 
additivity' test.
I don't know if it's implemented in R, but it wouldn't be hard to  
roll your own.

See ``Analysis of Messy Data'' volume 2 by George A. Milliken and  
Dallas E. Johnson,
van Nostrand Reinhold, 1989, page 7 ff.

On 20/03/2008, at 12:03 PM, David Mackovjak wrote:

 Ben,
 I would like to test the sulfur on the clover field, nitrogen on  
 the clover field and then test for the presence of interaction.

 Sorry about the last email, seems it really screwed itself over,  
 here it is again, hopefully nicer:

   Nitrogen(0)  Nitrogen(20)
 Sulfur(0)   4.54  5.73
 Sulfur(3)4.647.05
 Sulfur(6)5.275.81
 Sulfur(9)5.816.30

 Each of those is a cell mean of 3 values.

 Would I simply do as follows?:

 yield- c(4.54,4.64,5.27,5.81,5.73,7.05,5.81,6.30)
 sulfur - c(1,2,3,4,1,2,3,4)
 nitro - c(1,1,1,1,2,2,2,2)

Not quite; you need to make sulfur and nitro into ***factors***.

 summary(aov(yield~sulfur*nitro))

Better, I think, to use lm() directly rather than the aov() wrapper.

fit - lm(yield ~ sulfur*nitro)
anova(fit)

You see that you get no F-tests.  The model fits ``perfectly''
so there is no residual sum of squares (and no degrees of freedom for  
error).

cheers,

Rolf Turner

##
Attention:\ This e-mail message is privileged and confid...{{dropped:17}}

__
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] [PS] Two Way ANOVA

2008-03-19 Thread Daniel Malter
You put all the responses into one vector and the appropriate independents
Sulfur and nitrogen into the other. So your table would look like this (see
below). You would test.

summary(aov(Dependent~factor(Nitrogen)*factor(Sulfur))). And your output
would look likt this (see further below) from which you can start in-depth
analyses.

Dependent   NitrogenSulfur
4.481   1
4.521   1
4.631   1
4.7 1   2
4.651   2
4.571   2
5.211   3
5.231   3
5.381   3
5.881   4
5.981   4
5.911   4
5.762   1
5.642   1
5.782   1
7.012   2
7.112   2
7.022   2
5.882   3
5.822   3
5.732   3
6.262   4
6.262   4
6.372   4


Df Sum Sq Mean Sq F valuePr(F)
factor(Nitrogen) 1 7.5937  7.5937 1514.96  2.2e-16 ***
factor(Sulfur)   3 3.1543  1.0514  209.76 4.717e-13 ***
factor(Nitrogen):factor(Sulfur)  3 3.8358  1.2786  255.08 1.024e-13 ***
Residuals   16 0.0802  0.0050  
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 

 


-
cuncta stricte discussurus
-

-Ursprüngliche Nachricht-
Von: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Im
Auftrag von David Mackovjak
Gesendet: Wednesday, March 19, 2008 7:55 PM
An: Rolf Turner; R-help@r-project.org
Betreff: Re: [R] [PS] Two Way ANOVA

I do have the values for each individual values for each cell. They are as
follows:

N(0)N(20)
4.48  5.76
4.52  5.64
4.635.78

4.70  7.01
4.65  7.11
4.57  7.02

5.21  5.88
5.23  5.82
5.38  5.73

5.88  6.26
5.98  6.26
5.91  6.37

So how would I go about this then?

- Original Message 
From: Rolf Turner [EMAIL PROTECTED]
To: David Mackovjak [EMAIL PROTECTED]
Sent: Wednesday, March 19, 2008 4:36:47 PM
Subject: Re: [R] [PS]   Two Way ANOVA


With the given structure of your data you CANNOT test for interaction in the
general sense.  There are no degrees of freedom left for error.

If you have access to the (three) individual values in each cell, then you
can test for interaction.

If these individual values are lost to posterity [Expostulation:  Why the
expletive deleted do people ***do*** things like this?  Use your
expletive deleted data, not summary statistics!!!] then you can still test
for a ***particular form*** of interaction using Tukey's ``1 degree of
freedom for non- additivity' test.
I don't know if it's implemented in R, but it wouldn't be hard to roll your
own.

See ``Analysis of Messy Data'' volume 2 by George A. Milliken and Dallas E.
Johnson, van Nostrand Reinhold, 1989, page 7 ff.

On 20/03/2008, at 12:03 PM, David Mackovjak wrote:

 Ben,
 I would like to test the sulfur on the clover field, nitrogen on the 
 clover field and then test for the presence of interaction.

 Sorry about the last email, seems it really screwed itself over, here 
 it is again, hopefully nicer:

   Nitrogen(0)  Nitrogen(20)
 Sulfur(0)   4.54  5.73
 Sulfur(3)4.647.05
 Sulfur(6)5.275.81
 Sulfur(9)5.816.30

 Each of those is a cell mean of 3 values.

 Would I simply do as follows?:

 yield- c(4.54,4.64,5.27,5.81,5.73,7.05,5.81,6.30)
 sulfur - c(1,2,3,4,1,2,3,4)
 nitro - c(1,1,1,1,2,2,2,2)

Not quite; you need to make sulfur and nitro into ***factors***.

 summary(aov(yield~sulfur*nitro))

Better, I think, to use lm() directly rather than the aov() wrapper.

fit - lm(yield ~ sulfur*nitro)
anova(fit)

You see that you get no F-tests.  The model fits ``perfectly''
so there is no residual sum of squares (and no degrees of freedom for
error).

cheers,

Rolf Turner

##
Attention:\ This e-mail message is privileged and confid...{{dropped:17}}

__
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] [PS] Two Way ANOVA

2008-03-19 Thread Daniel Malter
Btw. you can plot the effect by looking at the following graph with using
either Sulfur or Nitrogen as the trace or x-axis:

interaction.plot(Sulfur,Nitrogen,Dependent)
interaction.plot(Nitrogen,Sulfur,Dependent)

Cheers,
Daniel


-
cuncta stricte discussurus
-

-Ursprüngliche Nachricht-
Von: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Im
Auftrag von David Mackovjak
Gesendet: Wednesday, March 19, 2008 7:55 PM
An: Rolf Turner; R-help@r-project.org
Betreff: Re: [R] [PS] Two Way ANOVA

I do have the values for each individual values for each cell. They are as
follows:

N(0)N(20)
4.48  5.76
4.52  5.64
4.635.78

4.70  7.01
4.65  7.11
4.57  7.02

5.21  5.88
5.23  5.82
5.38  5.73

5.88  6.26
5.98  6.26
5.91  6.37

So how would I go about this then?

- Original Message 
From: Rolf Turner [EMAIL PROTECTED]
To: David Mackovjak [EMAIL PROTECTED]
Sent: Wednesday, March 19, 2008 4:36:47 PM
Subject: Re: [R] [PS]   Two Way ANOVA


With the given structure of your data you CANNOT test for interaction in the
general sense.  There are no degrees of freedom left for error.

If you have access to the (three) individual values in each cell, then you
can test for interaction.

If these individual values are lost to posterity [Expostulation:  Why the
expletive deleted do people ***do*** things like this?  Use your
expletive deleted data, not summary statistics!!!] then you can still test
for a ***particular form*** of interaction using Tukey's ``1 degree of
freedom for non- additivity' test.
I don't know if it's implemented in R, but it wouldn't be hard to roll your
own.

See ``Analysis of Messy Data'' volume 2 by George A. Milliken and Dallas E.
Johnson, van Nostrand Reinhold, 1989, page 7 ff.

On 20/03/2008, at 12:03 PM, David Mackovjak wrote:

 Ben,
 I would like to test the sulfur on the clover field, nitrogen on the 
 clover field and then test for the presence of interaction.

 Sorry about the last email, seems it really screwed itself over, here 
 it is again, hopefully nicer:

   Nitrogen(0)  Nitrogen(20)
 Sulfur(0)   4.54  5.73
 Sulfur(3)4.647.05
 Sulfur(6)5.275.81
 Sulfur(9)5.816.30

 Each of those is a cell mean of 3 values.

 Would I simply do as follows?:

 yield- c(4.54,4.64,5.27,5.81,5.73,7.05,5.81,6.30)
 sulfur - c(1,2,3,4,1,2,3,4)
 nitro - c(1,1,1,1,2,2,2,2)

Not quite; you need to make sulfur and nitro into ***factors***.

 summary(aov(yield~sulfur*nitro))

Better, I think, to use lm() directly rather than the aov() wrapper.

fit - lm(yield ~ sulfur*nitro)
anova(fit)

You see that you get no F-tests.  The model fits ``perfectly''
so there is no residual sum of squares (and no degrees of freedom for
error).

cheers,

Rolf Turner

##
Attention:\ This e-mail message is privileged and confid...{{dropped:17}}

__
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] [PS] Two Way ANOVA

2008-03-19 Thread Rolf Turner

On 20/03/2008, at 12:54 PM, David Mackovjak wrote:

 I do have the values for each individual values for each cell. They  
 are as follows:

 N(0)N(20)
 4.48  5.76
 4.52  5.64
 4.635.78
 4.70  7.01
 4.65  7.11
 4.57  7.02
 5.21  5.88
 5.23  5.82
 5.38  5.73
 5.88  6.26
 5.98  6.26
 5.91  6.37

 So how would I go about this then?

(1) Assign to ``yield'' the foregoing 24 values.

(2) Set up a factor ``nitro'' giving the corresponding levels of  
nitrogen
 (e.g. with labels ``n0'' and ``n20'' --- rather than ``1'' and  
``2'' to
 be more evocative and to make it clear that the value of  
``nitro'' are
 ***not*** numeric!).

(3) Likewise set up a factor ``sulfur'' with labels, say ``s0'',  
``s3'', ``s6'', ``s9''.

 Note that yield is a numeric vector of length 24, nitro and  
sulfur are
 factors (with 2 and 4 levels respectively) also (of course!) of  
length 24.

(4) Fit your linear model:

fit - lm(yield ~ nitro*sulfur)

(5) Do your analysis of variance:

anova(fit)

(6) Check that the anova assumptions seem to be OK:

plot(fitted(fit),resid(fit)) # Looks pretty good to me.

(7) An interaction plot might be illuminating:

interaction.plot(sulfur,nitro,yield) # The (n20,s3) cell sticks out  
like a sore toe.


Since there *is* interaction you might want to treat the modelling  
exercise as a one-way
anova on an 8-level factor (one level for each cell).  You can create  
the appropriate
factor using ``interaction()''.  You could fit the one-way model (use  
aov() this time;
TukeyHSD demands it!) and then do TukeyHSD() to the result to find  
out what really
differs from what.

cheers,

Rolf Turner

##
Attention:\ This e-mail message is privileged and confid...{{dropped: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.


Re: [R] [PS] Re: Table of basic descriptive statistics like SPSS

2008-03-18 Thread Frank E Harrell Jr
Ben Fairbank wrote:
 tiny high-resolution histograms
 
 Could you say a bit more on that topic?  How achieved?  Where

latex(describe()) uses LaTeX's picture environment after binning into 
101 bins.

 documented?  Similar to Tufte's sparklines?  

yes, a bit

See the link from http://biostat.mc.vanderbilt.edu/Hmisc

Frank

 
 Maybe the list as a whole would be interested.
 
 Thank you,
 
 Ben 
 
 If you use LaTeX you'll get more (and better) output including tiny 
 high-resolution histograms of continuous variables.
 
 Frank
 
 


-- 
Frank E Harrell Jr   Professor and Chair   School of Medicine
  Department of Biostatistics   Vanderbilt University

__
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] [PS] Re: a more elegant way to get percentages? (now R books)

2008-03-13 Thread Ben Fairbank
Monica --

There has been a virtual population explosion of R books in recent years
and we all have our favorites.  You may wish to pick one oriented toward
your specialty, but the absolute minimum lowest common denominator (by
which I mean that it has the ground zero essential information that all
users must share, not that it is minimal or incomplete) is the manual
An Introduction to R, available by download from the Cran website.
Beyond that, my favorite introduction is Peter Dalgaard's Introductory
Statistics with R.  He has an elegance and clarity of style, as well as
a feel for what is necessary to include in an introduction, that some
others lack.  Others may disagree, but I find myself returning to
Dalgaard again and again. 

Ben 

-Original Message-
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]
On Behalf Of Monica Pisica
Sent: Thursday, March 13, 2008 9:05 AM
To: Gabor Grothendieck; [EMAIL PROTECTED];
[EMAIL PROTECTED]
Cc: r-help@r-project.org
Subject: [PS] Re: [R] a more elegant way to get percentages?



Hi everybody,


I am amazed how quick i got my answer ;-) I have to recognize that
Gabor's code really puts to shame my skills in doing any programming in
R. Is there any book or documentation which really explains in details
all these neat tricks from {stats} like ave (i even didn't know this
function existed), apply and all its friends (sapply, tapply, etc) ? To
be honest it took me quite a while to come up with the fancy
subscripting to get my persantages ;-))

thank you so much, i really appreciate your help,

Monica

 Date: Thu, 13 Mar 2008 09:45:05 -0400
 From: [EMAIL PROTECTED]
 To: [EMAIL PROTECTED]
 Subject: Re: [R] a more elegant way to get percentages?
 CC: r-help@r-project.org

 Assuming your x is as follows:

 x - data.frame(locat = c(a, b, b, c, c, c, c, d, d,
d),
 val = c(5, 5, 15, 5, 20, 5, 10, 5, 15, 10))

 Try this:

 x$percent1 - ave(x$val, x$locat, FUN = function(x) 100*x/sum(x))

 On Thu, Mar 13, 2008 at 9:36 AM, Monica Pisica  wrote:

 Hi,

 I am trying to get percentages in a more elegant way. I have a
data.frame with locations and values (counts) of species at that
location. Each location is repeated for each species i have values for
and i would like to get percentages of each species at that location. I
am not sure if i am clear in my explanations so i will paste my code
below:

 #

 x
 locat val
 1 a 5
 2 b 5
 3 b 15
 4 c 5
 5 c 20
 6 c 5
 7 c 10
 8 d 5
 9 d 15
 10 d 10
 loc1 - x$locat
 n - length(loc1)
 locuniq1 - unique(loc1)
 m - length(locuniq1)
 counts - seq(1:m)

 for (i in 1:m) {
 + count - 0
 + for (j in 1:n) {
 + if (loc1[j]==locuniq1[i]) count - count+1
 + counts[i] - count
 + }
 + }

 percent1 - rep(0,n)
 j - 0
 for (i in 1:m) {
 +
 + b - x[(j+1):(j+counts[i]),]
 + total - sum(b$val)
 + percent1[(j+1):(j+counts[i])] - round(apply(as.matrix(b$val), 1,
function(x) {x*100/total}),2)
 + j = j+counts[i]
 + }
 x1 - cbind(x, percent1) # this is the result i want
 x1
 locat val percent1
 1 a 5 100.00
 2 b 5 25.00
 3 b 15 75.00
 4 c 5 12.50
 5 c 20 50.00
 6 c 5 12.50
 7 c 10 25.00
 8 d 5 16.67
 9 d 15 50.00
 10 d 10 33.33

 

 I am wondering if there is any way to do it more efficiently, much
more that the first loop which gives how many times each location is
present in the data.frame is slow if you have a larger data.frame and
not only 10 rows.

 Thanks for any input and sorry if the email is on the long side,

 Monica


 _
 [[elided Hotmail spam]]

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


_


08
__
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] [PS] How to manipulate data according to groups ?

2008-03-13 Thread Ben Fairbank
Look at ?tapply, based on your description, it is what you want.

Ben 

-Original Message-
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]
On Behalf Of Ng Stanley
Sent: Thursday, March 13, 2008 9:25 AM
To: r-help
Subject: [PS] [R] How to manipulate data according to groups ?

Hi,

I have a two columns data, the first column are values, and second
column
are the groups. For this example, there are 3 groups 1,2,3.

How can I manipulate the values in the first column according to groups,
say
I would like to find mean, sum, and standard deviation for the different
groups ? How do I plot data according to groups ?

 t - matrix(c(rnorm(10), 1,1,2,2,1,3,3,3,3,2), ncol=2)

[[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@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] [PS] Re: a more elegant way to get percentages? (now R books)

2008-03-13 Thread hadley wickham
  There has been a virtual population explosion of R books in recent years
  and we all have our favorites.  You may wish to pick one oriented toward
  your specialty, but the absolute minimum lowest common denominator (by
  which I mean that it has the ground zero essential information that all
  users must share, not that it is minimal or incomplete) is the manual
  An Introduction to R, available by download from the Cran website.

I don't mean to pick on you in particular, or on the authors of An
introduction to R, but I really don't see how anyone in good
conscience can recommend this to a new user of R.  I think it does a
great job of covering the basics, and is probably a good read after
you've been using R for a year or so, but in goes into a lot of depth
into things that you really don't need to know for doing practical,
day-to-day data analysis.

For example, you don't find out how to actually load data into R until
page 30, while you get 3 page on the mode and length of objects at
page 12.  Do we really need to know that an empty (zero length) vector
still has a mode?

These comments are based on my experience teaching R to undergrad stat
majors, and so may not apply to your audience.  If you teach R in the
same order as an introduction to R it takes you about 4 weeks before
you can actually do anything useful with R, by which time the students
are bored to tears.  If you start with getting data into R and
displaying the data with graphics, you can do useful things very
quickly, providing interest and motivation, and then you can gradually
introduce a more rigourous description of the components as needed.

Hadley

-- 
http://had.co.nz/

__
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] [PS] Generating a new matrix using rbinom and a matrix of probabilities.

2008-03-11 Thread Ben Fairbank
I tried your code and could not get it to run on my installation of R,
so I may be missing something.  But if you have a matrix of
probabilities (call it probs) and want to simulate random binomial
draws, can you not simply create a matrix of the same size of uniform
random numbers (runif()) (call it rands), then do comparisons, thus,

draws - 0 + (rands  probs)

Ben Fairbank


-Original Message-
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]
On Behalf Of Economics Guy
Sent: Tuesday, March 11, 2008 10:16 AM
To: [EMAIL PROTECTED]
Subject: [PS] [R] Generating a new matrix using rbinom and a matrix of
probabilities.

I am having a little trouble getting R to do something without writing
a couple of very awkward loops.

I have a matrix of probabilities and I want to generate a new matrix
of ones and zeros where each element in the new matrix is the result
of a draw from a binomial distribution where the probability of
getting a 1 is the corresponding element in the matrix of
probabilities.

Example Code:


## First I generate the matrix of probabilities for example purposes.

probMatrix - matrix(NA,5,5){

for (i in 1:5)

probVectorI - runif(5,0,1)

probMatrix[i,] - probVectorI

}

# Now I want to take each element in probMatrix and use it as the
probability parameter in rbinom draw and generate a new matrix.
Something like this:

binomialMatrix - rbinom(1,1,probMatrix)

# But that does not work. I know I can run a loop across each vector
of the matrix, but this seems like an bad way to do this.

---End Code

So any help would be appreciated.

Thanks,

EG

__
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] [PS] discrete variable

2008-03-02 Thread Ben Fairbank
Try table(), with the name of your vector inside the parentheses.

Ben 

-Original Message-
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]
On Behalf Of Pete Dorothy
Sent: Sunday, March 02, 2008 2:27 PM
To: r-help@r-project.org
Subject: [PS] [R] discrete variable

Hello,

I am sorry for asking such a basic question. I could not find an answer
to
it using google.

I have a discrete variable (a vector x) taking for example the following
values : 0, 3, 4, 3, 15, 5, 6, 5

Is it possible to know how many different values (modalities) it takes ?
Here it takes 6 different values but the length of the vector is 8.

I would like to know if there is a way to get the set of the
modalities {0,3,4,15,5,6} with the number of times each one is taken
{1,2,1,1,2,1}

Thank you very much

P.S. : is there some useful functions for discrete variables ?

[[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@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] [PS] Column sums from a data frame (without the headers)

2008-02-29 Thread Ben Fairbank
as.vector(col.Sums())

Ben 

-Original Message-
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]
On Behalf Of Jason Horn
Sent: Friday, February 29, 2008 11:03 AM
To: [EMAIL PROTECTED]
Subject: [PS] [R] Column sums from a data frame (without the headers)

Does anyone know how to get a vector of column sum from a data frame?   
You can use colSums(), but this gives you a object of type numeric  
with the column labels in the first row, and the sums in the second  
row.  I just want a vector of the sums, and I can't figure out a way  
to index the numeric object.

Thanks!

__
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] [PS] Different results in calculating SD of 2 numbers

2008-01-16 Thread Ben Fairbank
And another problem, in addition to the points made by others, is that
the formula for the SD gives a biased estimate (it underestimates it) of
the population SD for small n when sampling from a normal distribution.
When n is about twelve or so or more, the bias can usually be ignored
(it is about 2.2%), but when you have only two numbers, the correction
factor is about 1.25.

The approximate correction formula, as I understand it, is
(n-.75)/(n-1), so if n = 2, then it is 1.25/1, but this is not exact.
The real formula is more complex (not difficult, but involves the
gamma function) and my reference to it is not at this office, or I would
give it.

HTH,

Ben 

-Original Message-
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]
On Behalf Of Ron Michael
Sent: Wednesday, January 16, 2008 2:15 AM
To: [EMAIL PROTECTED]
Subject: [PS] [R] Different results in calculating SD of 2 numbers

Hi all,

Can anyone tell me why I am getting different results in calculating SD
of 2 numbers ?

 (1.25-0.95)/2
[1] 0.15
 sd(c(1.25, 0.95))
[1] 0.2121320  # why it is different from 0.15?

Regards,

Send instant messages to your online friends
http://uk.messenger.yahoo.com 
[[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@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] PS graphs in R 2.6.0

2007-10-11 Thread Jorge Ivan Velez Valbuena

Dear R-users:

I have been working in R for few years and never I'd been the problems like 
this. I'm running the last R version and when I try to save a graph in PS 
format I have the next error

Error: Invalid font type
In addition: Warning messages:
1: font family not found in PostScript font database 
2: font family not found in PostScript font database 

I thinks it's curious because using R 2.5.1 I didn't have this result. Could 
somebody please explain me what happen? 


Thanks in advance,

Jorge Ivan Velez
Industrial Engineer
Master in Sciences (Candidate)
Faculty of Sciences
School of Statistics
National University of Colombia at Medellin
Medellin, Antioquia, Colombia 
e-mail: [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.