[R] boxplot colors

2008-06-22 Thread Paul Adams
Hello everyone,


I am trying to color two boxplots on the same graph two 
different colors.
I have tried the following

boxplot(5,1:19,5,20:39,col=c(red,blue))
but all I get are two blue boxes.
Any help would be appreciated
Paul



  
[[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] Re move row.names column in dataframe

2008-06-22 Thread tonyxv


Hello,

aa-c(1,1,2,2,3,3,4,4,5,5,6,6)
bb-c(56,56,33,33,53,53,20,20,63,63,9,9) 
cc-data.frame(aa,bb) 
uniquedf - unique(cc)
View(uniquedf)


Why does the column row.names appear in the new dataframe and how do I get
rid of it.

uniquedf$row.names - NULL does not seem to work.

For what I'm doing this is a useless column and can cause confusion and/or
problems for subsequent merging/filtering etc.


Thanks.
-- 
View this message in context: 
http://www.nabble.com/Remove-row.names-column-in-dataframe-tp18050179p18050179.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] passing arguments to a function problem

2008-06-22 Thread Jiří Voller
Dear R-users,
is there some way how to pass various colnames to the following code for
sorting data.frames?

mydf.ordered-with(mydf, mydf[order(colname1,colname2, colnameX, decreasing
= TRUE), ])



I was trying something like

Afunction-function (mydf,colnames,decreasing=T){

 mydf.ordered-with(mydf, mydf[order(colnames, decreasing = decreasing),
])

 }

but it didnt work
please help
thank you


Jiri Voller

[[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] Adding columns of Aggregates to existing dataframe

2008-06-22 Thread tonyxv

Thanks. ave() is the exact function I was after.



tonyxv wrote:
 
 Hello,
 I have a dataframe 
 
 
 ID1   ID2
 A1B3
 A1B4
 A1B3
 A1B3
 A2B1
 A2B1
 A2B4
 A3B2
 A3B2
 A5B1
 A5B1
 A5B6
 A5B4
 A6B2
 
 
 
 I want to add extra columns to the dataframe CountID1 and CountID2 which
 is the actual count of values such as A1 etc
 ie
 
 
 
 ID1   ID2CountID1CountID2
 A1B3 4   3
 A1B4 4   4
 A1B3 4   3
 A1B3 4   3
 A2B1 3   4
 A2B1 3   4
 A2B4 3   3
 A3B2 2   3
 A3B2 2   3
 A5B1 4   4
 A5B1 4   4
 A5B6 4   1
 A5B4 4   4
 A6B2 1   3
 
 
 I know this can be done by first creating temporary aggregate dataframes
 then merging with the original.
 Is there an easier way if i want to calculate many aggregates without
 having to merge many temp tables.
 
 
 Thanks.
 

-- 
View this message in context: 
http://www.nabble.com/Adding-columns-of-Aggregates-to-existing-dataframe-tp18039838p18050190.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] Re move row.names column in dataframe

2008-06-22 Thread Bill.Venables
- There is no column in the data frame called row.names.  It only
looks that way when you use the viewer.

- All data frames must have row and column names.  This is not
negotiable.  Also, the row.names will not interfere with any merging
operation because they are not a column of the data frame: they are the
row names.


Bill Venables
CSIRO Laboratories
mailto:[EMAIL PROTECTED]
http://www.cmis.csiro.au/bill.venables/ 

-Original Message-
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]
On Behalf Of tonyxv
Sent: Sunday, 22 June 2008 11:15 AM
To: r-help@r-project.org
Subject: [R] Re move row.names column in dataframe



Hello,

aa-c(1,1,2,2,3,3,4,4,5,5,6,6)
bb-c(56,56,33,33,53,53,20,20,63,63,9,9) 
cc-data.frame(aa,bb) 
uniquedf - unique(cc)
View(uniquedf)


Why does the column row.names appear in the new dataframe and how do I
get
rid of it.

uniquedf$row.names - NULL does not seem to work.

For what I'm doing this is a useless column and can cause confusion
and/or
problems for subsequent merging/filtering etc.


Thanks.
-- 
View this message in context:
http://www.nabble.com/Remove-row.names-column-in-dataframe-tp18050179p18
050179.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] boxplot colors

2008-06-22 Thread HBaize


You are drawing four box plots, not two. Two of them are just the number 5.
The two box plots that are only 5 don't have a box, so you can't see that
they're red. Try this:

boxplot(1:19,20:39,col=c(red,blue))


Paul Adams-8 wrote:
 
 Hello everyone,
 
 
 I am trying to color two boxplots on the same graph two 
 different colors.
 I have tried the following
 
 boxplot(5,1:19,5,20:39,col=c(red,blue))
 but all I get are two blue boxes.
 Any help would be appreciated
 Paul
 
 
 
   
   [[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.
 
 

-- 
View this message in context: 
http://www.nabble.com/boxplot-colors-tp18051541p18052038.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] R vs. Bugs

2008-06-22 Thread Prof Brian Ripley
Your request is too vague for us to be very helpful.  However OpenBUGS 
runs without very frequent crashes only on some ix86 Linux machines -- and 
what those are is unclear and Uwe Ligges and I (working on BRugs) have 
been unable to find one recently.


There are dozens of Bayesian MCMC packages on CRAN (look at its Bayesian 
task view).  Most are less general and faster than BUGS.


There is no 'AMCMC package in R'.  There is at least one third-party 
effort of that name, not on CRAN and explicitly claiming


   The R function amcmc() will tend to run rather _slowly_,

(his emphasis) so perhaps that is not the one you mean.

On Sun, 22 Jun 2008, Peter Muhlberg wrote:


A naive question from a non-statistician:  I'm looking into running a
Bayesian analysis of a model with high dimensionality.  It's not a
standard model (the likelihood requires a lot of code to implement),


'code' in what language?  Note that MCMC does *not* require the likelihood 
to be calculated, and its renaissance in statistics ca 30 years ago was 
for models for which the likelihood is not even known completely.



and I'm using a Linux machine.  Was wondering if someone
has any thoughts on what the advantages of OpenBugs are as
opposed to just R (or should I be thinking WinBUGS under Wine?)?  The
AMCMC package in R promises to run MCMC's very rapidly.  Have read
that OpenBugs as a project was 'stalling' in 2007.

Peter


--
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] I can't see plots

2008-06-22 Thread Josep Lluís Figueras
Hi,

I use RSPerl on Ubuntu and Apache2 web server. It is my first experience
with R language :-)

I have the next code embedded into a Perl CGI:

use R;
use RReferences;

my @x;
R::initR(--silent,--no-save);
R::library(RSPerl);
@x = R::call(rnorm, 10);
R::call(plot, [EMAIL PROTECTED]);

The CGI works but no plot is shown.

Apache2 web server log

[[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] No HTML package list update in 2.7.0?

2008-06-22 Thread Jim Lemon
Hi all,
As I was uploading a couple of little fixes to prettyR, I remembered
that there was a question I wanted to ask. I remember the package list
being updated whenever I installed a new package (at least on Linux, oh
yes, Fedora Core 9 now), but not on Windows (I just used to unzip the
packages and manually update the package list). Since I have upgraded to
2.7.0, the HTML package list isn't updated. I couldn't find anything
about this in the install stuff for the new features (what is a tangled
vignette anyway?). Is this just something that has slipped beneath the
legendary radar of the team? Am I really the first to notice this?

Jim

__
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] I can't see plots

2008-06-22 Thread Josep Lluís Figueras
Hi,

I am using RSPerl package on Ubuntu and Apache2 web server. It is my first
experience with R language :-)

I have the next code embedded into a Perl CGI:

use R;
use RReferences;

my @x;
R::initR(--silent,--no-save);
R::library(RSPerl);
@x = R::call(rnorm, 10);
R::call(plot, [EMAIL PROTECTED]);

The CGI works but no plot is shown.

Apache2 web server log says:

[Sun Jun 22 12:01:41 2008] [error] [client 127.0.0.1] Error in pdf() :
unable to start device pdf, referer: http://localhost/html/proveta.html
[Sun Jun 22 12:01:41 2008] [error] [client 127.0.0.1] In addition: Warning
message:, referer: http://localhost/html/proveta.html
[Sun Jun 22 12:01:41 2008] [error] [client 127.0.0.1] In pdf() : cannot open
'pdf' file argument 'Rplots.pdf', referer:
http://localhost/html/proveta.html
[Sun Jun 22 12:01:41 2008] [error] [client 127.0.0.1] Caught error in
R::call(), referer: http://localhost/html/proveta.html

However, if I use R directly plots are correctly shown.

Can anybody help me?

Thanks!

Josep Lluís Figueras
(from Barcelona)

[[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] passing arguments to a function problem

2008-06-22 Thread Gabor Grothendieck
See orderBy in the doBy package.

On Sat, Jun 21, 2008 at 7:58 PM, Jiří Voller [EMAIL PROTECTED] wrote:
 Dear R-users,
 is there some way how to pass various colnames to the following code for
 sorting data.frames?

 mydf.ordered-with(mydf, mydf[order(colname1,colname2, colnameX, decreasing
 = TRUE), ])



 I was trying something like

 Afunction-function (mydf,colnames,decreasing=T){

 mydf.ordered-with(mydf, mydf[order(colnames, decreasing = decreasing),
 ])

  }

 but it didnt work
 please help
 thank you


 Jiri Voller

[[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] No HTML package list update in 2.7.0?

2008-06-22 Thread Jonathan Baron
See

https://bugzilla.redhat.com/show_bug.cgi?id=442727

Right now I seem to be using
/usr/share/doc/R-2.7.0/html
to get the list (on finzi.psych.upenn.edu)

On 06/22/08 20:43, Jim Lemon wrote:
 Hi all,
 As I was uploading a couple of little fixes to prettyR, I remembered
 that there was a question I wanted to ask. I remember the package list
 being updated whenever I installed a new package (at least on Linux, oh
 yes, Fedora Core 9 now), but not on Windows (I just used to unzip the
 packages and manually update the package list). Since I have upgraded to
 2.7.0, the HTML package list isn't updated. I couldn't find anything
 about this in the install stuff for the new features (what is a tangled
 vignette anyway?). Is this just something that has slipped beneath the
 legendary radar of the team? Am I really the first to notice this?
 
 Jim

-- 
Jonathan Baron, Professor of Psychology, University of Pennsylvania
Home page: http://www.sas.upenn.edu/~baron

__
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] Coloring Stripchart Points, or Better, Lattice Equivalent

2008-06-22 Thread Bryan Hanson
Below is a revised set of code that demonstrates my question a little more
clearly, I hope.

When plotting all the data (5th panel), col  sym don't seem to be passed
correctly, as the (random) first value for col  sym are used for all points
(run the code, then run it again, you'll see how the 5th panel changes
depending upon col  sym for the first data point).  The 5th panel should
ideally be the sum of the 4 panels above, keeping col  sym intact.

Also, I would rather have this in lattice or ggplot2, if anyone sees how to
convert it.

Thanks once again, several of you have made very useful suggestions off
list.  Bryan

samples - 100 # must be even
index - round(runif(samples, 1, 100)) # set up data
resp - rbinom(samples, 1, 0.5)
yr - rep(c(2005, 2006), samples/2)
all - data.frame(index, resp, yr)
all$sym - ifelse(all$resp == 1, 1, 3)
all$col - ifelse(all$yr == 2005, red, blue)
all$count - rep(1, length(all$index))
all - all[order(all$index, all$yr, all$resp),] # for easier inspection
row.names(all) - c(1:samples) # for easier inspection

one - all[(all$yr == 2005  all$resp == 0),] # First 2005/0 at top
two - all[(all$yr == 2005  all$resp == 1),] # Then 2005/1
three - all[(all$yr == 2006  all$resp == 0),] # Now 2006/0
four - all[(all$yr == 2006  all$resp == 1),] # Finally 2006/1

par(mfrow = c(5, 1))
par(plt = c(0.1, 0.9, 0.25, 0.75))
stripchart(one$index, method = stack, ylim = c(0,10), xlim = c(1,100), col
= one$col, pch = one$sym)
mtext(2005/0, side = 3)
stripchart(two$index, method = stack, ylim = c(0,10), xlim = c(1,100), col
= two$col, pch = two$sym)
mtext(2005/1, side = 3)
stripchart(three$index, method = stack, ylim = c(0,10), xlim = c(1,100),
col = three$col, pch = three$sym)
mtext(2006/0, side = 3)
stripchart(four$index, method = stack, ylim = c(0,10), xlim = c(1,100),
col = four$col, pch = four$sym)
mtext(2006/1, side = 3)
stripchart(all$index, method = stack, ylim = c(0,10), xlim = c(1,100), col
= all$col, pch = all$sym)
mtext(col  sym always taken from 1st data point when all data is
plotted!, side = 3)

__
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] I can't see plots

2008-06-22 Thread Duncan Murdoch

Josep Lluís Figueras wrote:

Hi,

I am using RSPerl package on Ubuntu and Apache2 web server. It is my first
experience with R language :-)

I have the next code embedded into a Perl CGI:

use R;
use RReferences;

my @x;
R::initR(--silent,--no-save);
R::library(RSPerl);
@x = R::call(rnorm, 10);
R::call(plot, [EMAIL PROTECTED]);

The CGI works but no plot is shown.

Apache2 web server log says:

[Sun Jun 22 12:01:41 2008] [error] [client 127.0.0.1] Error in pdf() :
unable to start device pdf, referer: http://localhost/html/proveta.html
[Sun Jun 22 12:01:41 2008] [error] [client 127.0.0.1] In addition: Warning
message:, referer: http://localhost/html/proveta.html
[Sun Jun 22 12:01:41 2008] [error] [client 127.0.0.1] In pdf() : cannot open
'pdf' file argument 'Rplots.pdf', referer:
http://localhost/html/proveta.html
[Sun Jun 22 12:01:41 2008] [error] [client 127.0.0.1] Caught error in
R::call(), referer: http://localhost/html/proveta.html

However, if I use R directly plots are correctly shown.

  
Because you aren't running R interactively, it's trying to open a pdf 
device.  This is failing (file permissions maybe?).


You should probably specify exactly what device to open, and if it's 
something that writes a file, where to write it.


Duncan Murdoch

Can anybody help me?

Thanks!

Josep Lluís Figueras
(from Barcelona)

[[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] I can't see plots

2008-06-22 Thread milton ruser
Hi there,

try to open a graphic device with x11(), may be.

cheers,

miltinho

On 6/22/08, Josep Lluís Figueras [EMAIL PROTECTED] wrote:

 Hi,

 I am using RSPerl package on Ubuntu and Apache2 web server. It is my first
 experience with R language :-)

 I have the next code embedded into a Perl CGI:

 use R;
 use RReferences;

 my @x;
 R::initR(--silent,--no-save);
 R::library(RSPerl);
 @x = R::call(rnorm, 10);
 R::call(plot, [EMAIL PROTECTED]);

 The CGI works but no plot is shown.

 Apache2 web server log says:

 [Sun Jun 22 12:01:41 2008] [error] [client 127.0.0.1] Error in pdf() :
 unable to start device pdf, referer: http://localhost/html/proveta.html
 [Sun Jun 22 12:01:41 2008] [error] [client 127.0.0.1] In addition: Warning
 message:, referer: http://localhost/html/proveta.html
 [Sun Jun 22 12:01:41 2008] [error] [client 127.0.0.1] In pdf() : cannot
 open
 'pdf' file argument 'Rplots.pdf', referer:
 http://localhost/html/proveta.html
 [Sun Jun 22 12:01:41 2008] [error] [client 127.0.0.1] Caught error in
 R::call(), referer: http://localhost/html/proveta.html

 However, if I use R directly plots are correctly shown.

 Can anybody help me?

 Thanks!

 Josep Lluís Figueras
 (from Barcelona)

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



[[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] I can't see plots

2008-06-22 Thread Daniel Cegielka
Maybe this help you

http://www.rforge.net/Cairo/index.html

http://www.rosuda.org/R/GDD/

daniel cegielka


-Original Message-
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On
Behalf Of milton ruser
Sent: Sunday, June 22, 2008 5:56 PM
To: Josep Lluís Figueras
Cc: r-help@r-project.org
Subject: Re: [R] I can't see plots

Hi there,

try to open a graphic device with x11(), may be.

cheers,

miltinho

On 6/22/08, Josep Llums Figueras [EMAIL PROTECTED] wrote:

 Hi,

 I am using RSPerl package on Ubuntu and Apache2 web server. It is my first
 experience with R language :-)

 I have the next code embedded into a Perl CGI:

 use R;
 use RReferences;

 my @x;
 R::initR(--silent,--no-save);
 R::library(RSPerl);
 @x = R::call(rnorm, 10);
 R::call(plot, [EMAIL PROTECTED]);

 The CGI works but no plot is shown.

 Apache2 web server log says:

 [Sun Jun 22 12:01:41 2008] [error] [client 127.0.0.1] Error in pdf() :
 unable to start device pdf, referer: http://localhost/html/proveta.html
 [Sun Jun 22 12:01:41 2008] [error] [client 127.0.0.1] In addition: Warning
 message:, referer: http://localhost/html/proveta.html
 [Sun Jun 22 12:01:41 2008] [error] [client 127.0.0.1] In pdf() : cannot
 open
 'pdf' file argument 'Rplots.pdf', referer:
 http://localhost/html/proveta.html
 [Sun Jun 22 12:01:41 2008] [error] [client 127.0.0.1] Caught error in
 R::call(), referer: http://localhost/html/proveta.html

 However, if I use R directly plots are correctly shown.

 Can anybody help me?

 Thanks!

 Josep Llums Figueras
 (from Barcelona)

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



[[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] Coloring Stripchart Points, or Better, Lattice Equivalent

2008-06-22 Thread Gabor Grothendieck
Try this:

library(lattice)
all$resp - as.factor(all$resp)
stripplot(~ index | resp * yr, all, col = all$col, pch = all$sym,
layout = c(1, 4))


On Sun, Jun 22, 2008 at 10:43 AM, Bryan Hanson [EMAIL PROTECTED] wrote:
 Below is a revised set of code that demonstrates my question a little more
 clearly, I hope.

 When plotting all the data (5th panel), col  sym don't seem to be passed
 correctly, as the (random) first value for col  sym are used for all points
 (run the code, then run it again, you'll see how the 5th panel changes
 depending upon col  sym for the first data point).  The 5th panel should
 ideally be the sum of the 4 panels above, keeping col  sym intact.

 Also, I would rather have this in lattice or ggplot2, if anyone sees how to
 convert it.

 Thanks once again, several of you have made very useful suggestions off
 list.  Bryan

 samples - 100 # must be even
 index - round(runif(samples, 1, 100)) # set up data
 resp - rbinom(samples, 1, 0.5)
 yr - rep(c(2005, 2006), samples/2)
 all - data.frame(index, resp, yr)
 all$sym - ifelse(all$resp == 1, 1, 3)
 all$col - ifelse(all$yr == 2005, red, blue)
 all$count - rep(1, length(all$index))
 all - all[order(all$index, all$yr, all$resp),] # for easier inspection
 row.names(all) - c(1:samples) # for easier inspection

 one - all[(all$yr == 2005  all$resp == 0),] # First 2005/0 at top
 two - all[(all$yr == 2005  all$resp == 1),] # Then 2005/1
 three - all[(all$yr == 2006  all$resp == 0),] # Now 2006/0
 four - all[(all$yr == 2006  all$resp == 1),] # Finally 2006/1

 par(mfrow = c(5, 1))
 par(plt = c(0.1, 0.9, 0.25, 0.75))
 stripchart(one$index, method = stack, ylim = c(0,10), xlim = c(1,100), col
 = one$col, pch = one$sym)
 mtext(2005/0, side = 3)
 stripchart(two$index, method = stack, ylim = c(0,10), xlim = c(1,100), col
 = two$col, pch = two$sym)
 mtext(2005/1, side = 3)
 stripchart(three$index, method = stack, ylim = c(0,10), xlim = c(1,100),
 col = three$col, pch = three$sym)
 mtext(2006/0, side = 3)
 stripchart(four$index, method = stack, ylim = c(0,10), xlim = c(1,100),
 col = four$col, pch = four$sym)
 mtext(2006/1, side = 3)
 stripchart(all$index, method = stack, ylim = c(0,10), xlim = c(1,100), col
 = all$col, pch = all$sym)
 mtext(col  sym always taken from 1st data point when all data is
 plotted!, side = 3)

 __
 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] R vs. Bugs

2008-06-22 Thread Peter Muhlberg
I've done some looking around in R and elsewhere to answer my question
on the value of R vs. Bugs for MCMC.  So, for anyone who is curious,
here's what I think I've found:  Bugs compiles its code, which should
make it much faster than a pure R program.  Packages such as AMCMC run
MCMC in R, potentially with a user-defined C function for the
density--which should make it comparable in speed to Bugs.  The
packages MCMCpack  (MCMCmetrop1R function) and mcmc seem designed to
run w/ a density function written in R.   MCMCpack does have functions
that use precompiled C code from the Scythe library (which looks
nice), but I see no simple way to add a C density function.  AMCMC and
Bugs seem to use adaptive MCMC, but the other R packages don't appear
to do so, which may mean another performance reduction.

I see no way to insert my own proposal density in the R functions.
JAG, a Java-based version of BUGS, apparently allows users to create
their own samplers, which might be a way to insert a different
proposal density.  Details about how to install a sampler are not
given in the manual, which, incidentally, is nevertheless much better
than the Bugs manual.  Also, the proposal density I'd want would
probably treat different variables differently, so I may need
Metropolis within Gibbs, not standard Gibbs sampling.  Can't get a
clear picture of what JAG's algorithm(s) are--the manual doesn't
mention Metropolis.

WinBugs and OpenBugs can't be made to run easily on Linux.  It looks
like WinBugs running under WINE might be the simplest viable
configuration, though I don't know how well or quickly it runs under
WINE or how much memory WINE ends up consuming.

Given all this, it may be easiest for my purposes to try to tweak the
AMCMC code to allow a different proposal density.  Maybe.

Peter

__
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] Coloring Stripchart Points, or Better, Lattice Equivalent

2008-06-22 Thread Bryan Hanson
Thanks Gabor, I'm getting closer.

Is there a way to spread out resp values vertically for a given value of
index?  In base graphics, stripchart does this with method = stack.  But
in lattice, stack = TRUE does something rather different, and I don't see a
combination of lattice arguments that does it like base graphics.

Thanks, Bryan


On 6/22/08 12:48 PM, Gabor Grothendieck [EMAIL PROTECTED] wrote:

 Actually I am not sure if my prior answer was correct.  I think its ok
 with one panel but
 you might have to use a panel function is there are several. With one
 panel it seems
 ok:
 
 stripplot(~ index, all, col = all$col, pch = all$sym)
 
 On Sun, Jun 22, 2008 at 12:28 PM, Gabor Grothendieck
 [EMAIL PROTECTED] wrote:
 Try this:
 
 library(lattice)
 all$resp - as.factor(all$resp)
 stripplot(~ index | resp * yr, all, col = all$col, pch = all$sym,
 layout = c(1, 4))
 
 
 On Sun, Jun 22, 2008 at 10:43 AM, Bryan Hanson [EMAIL PROTECTED] wrote:
 Below is a revised set of code that demonstrates my question a little more
 clearly, I hope.
 
 When plotting all the data (5th panel), col  sym don't seem to be passed
 correctly, as the (random) first value for col  sym are used for all points
 (run the code, then run it again, you'll see how the 5th panel changes
 depending upon col  sym for the first data point).  The 5th panel should
 ideally be the sum of the 4 panels above, keeping col  sym intact.
 
 Also, I would rather have this in lattice or ggplot2, if anyone sees how to
 convert it.
 
 Thanks once again, several of you have made very useful suggestions off
 list.  Bryan
 
 samples - 100 # must be even
 index - round(runif(samples, 1, 100)) # set up data
 resp - rbinom(samples, 1, 0.5)
 yr - rep(c(2005, 2006), samples/2)
 all - data.frame(index, resp, yr)
 all$sym - ifelse(all$resp == 1, 1, 3)
 all$col - ifelse(all$yr == 2005, red, blue)
 all$count - rep(1, length(all$index))
 all - all[order(all$index, all$yr, all$resp),] # for easier inspection
 row.names(all) - c(1:samples) # for easier inspection
 
 one - all[(all$yr == 2005  all$resp == 0),] # First 2005/0 at top
 two - all[(all$yr == 2005  all$resp == 1),] # Then 2005/1
 three - all[(all$yr == 2006  all$resp == 0),] # Now 2006/0
 four - all[(all$yr == 2006  all$resp == 1),] # Finally 2006/1
 
 par(mfrow = c(5, 1))
 par(plt = c(0.1, 0.9, 0.25, 0.75))
 stripchart(one$index, method = stack, ylim = c(0,10), xlim = c(1,100), col
 = one$col, pch = one$sym)
 mtext(2005/0, side = 3)
 stripchart(two$index, method = stack, ylim = c(0,10), xlim = c(1,100), col
 = two$col, pch = two$sym)
 mtext(2005/1, side = 3)
 stripchart(three$index, method = stack, ylim = c(0,10), xlim = c(1,100),
 col = three$col, pch = three$sym)
 mtext(2006/0, side = 3)
 stripchart(four$index, method = stack, ylim = c(0,10), xlim = c(1,100),
 col = four$col, pch = four$sym)
 mtext(2006/1, side = 3)
 stripchart(all$index, method = stack, ylim = c(0,10), xlim = c(1,100), col
 = all$col, pch = all$sym)
 mtext(col  sym always taken from 1st data point when all data is
 plotted!, side = 3)
 
 __
 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] Redefining the for loop

2008-06-22 Thread ast_shopping


Hi,

I have the following problem:

I want to redefine the for loop (or define a similar statement) to change its 
behavior under some circumstances. So, I would like sthg. like

For = function ( var, vec, statement ) {
 
  if ( ... ) {
/* my implementation of for */
  }
  else {
/* call R's for loop */
  }
}

I tried to manipulate the elements of the list one gets by

e = quote( for ( i in (1:10) ) print(*) )

That means, storing the variable in e[[2]] (my trials didn't work), and the 
statement in e[[4]], but I failed.

How can one do this in R? It would be best, if I could redefine for directly, 
so that one can use the same syntax, i.e., with the statement after the 
function call.

Can somebody help me?


Thanks!







{
-- 

Jetzt dabei sein: http://www.shortview.de/[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] readLines problem in iteration

2008-06-22 Thread Yasin Hajizadeh
Hi there
  My script at each iteration produces a .dat file which I save in a directory 
with write.table. Then I need to read each line of this file and create a 
directory for each line and put elements of that row in that directory. I do it 
with the following script which I have inserted somewhere between my outer 
iteration loop, it works fine for the first iteration, but the problem is that 
it does nothing at next iterations. How can I solve this problem, is there 
anything wrong with my code?
  Thanks in advance for your help.
   
   
write.table(X, file = model.dat, append = FALSE, sep =  , eol = \n, 
na = NA, dec = ., row.names = FALSE, col.names = FALSE, qmethod = 
c(escape, double)) 
  
  mother-getwd()
  
  
  count - 0;
  
  con- file(model.dat, open=r)

   
  while (length(line)  0) {
   
  line-readLines(con,n=1)
  count - count +1
  cat(read row no, count, ,\n, sep=);
  print(line)
  
  foldername - paste(Iteration,c, ant, count)
  dir.create (foldername)
  
  setwd(foldername)
  write.table(line, file = params.in, append = FALSE, sep =  , eol = \n, 
na = NA, dec = ., row.names = FALSE, col.names = FALSE, qmethod = 
c(escape, double))
  
  #system(run_misf_calc.py)
  
  setwd(mother)
   
   
  }
  
  
  close(con)

   
[[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] Coloring Stripchart Points, or Better, Lattice Equivalent

2008-06-22 Thread Gabor Grothendieck
I tried it with a simple example to make it easier to check the
result and it does seem we need a panel function, pnl:

library(lattice)
DF - data.frame(x = 1:5, col = c(1:4, 1), g = c(1, 1, 2, 2, 2), pch =
c(1:3, 2:1))
pnl - function(x, y, subscripts, col, pch, ...) panel.stripplot(x, y,
col = col[subscripts], pch = pch[subscripts], ...)
stripplot(~ x | g, DF, col = DF$col, pch = DF$pch, panel = pnl)

Using the same panel function, pnl, we can spread out resp into two different
panels like this:

all$resp - as.factor(all$resp) # as before
stripplot(~ index | resp, all, col = all$col, pch = all$sym, panel =
pnl, layout = 1:2)

On Sun, Jun 22, 2008 at 1:09 PM, Bryan Hanson [EMAIL PROTECTED] wrote:
 Thanks Gabor, I'm getting closer.

 Is there a way to spread out resp values vertically for a given value of
 index?  In base graphics, stripchart does this with method = stack.  But
 in lattice, stack = TRUE does something rather different, and I don't see a
 combination of lattice arguments that does it like base graphics.

 Thanks, Bryan


 On 6/22/08 12:48 PM, Gabor Grothendieck [EMAIL PROTECTED] wrote:

 Actually I am not sure if my prior answer was correct.  I think its ok
 with one panel but
 you might have to use a panel function is there are several. With one
 panel it seems
 ok:

 stripplot(~ index, all, col = all$col, pch = all$sym)

 On Sun, Jun 22, 2008 at 12:28 PM, Gabor Grothendieck
 [EMAIL PROTECTED] wrote:
 Try this:

 library(lattice)
 all$resp - as.factor(all$resp)
 stripplot(~ index | resp * yr, all, col = all$col, pch = all$sym,
 layout = c(1, 4))


 On Sun, Jun 22, 2008 at 10:43 AM, Bryan Hanson [EMAIL PROTECTED] wrote:
 Below is a revised set of code that demonstrates my question a little more
 clearly, I hope.

 When plotting all the data (5th panel), col  sym don't seem to be passed
 correctly, as the (random) first value for col  sym are used for all 
 points
 (run the code, then run it again, you'll see how the 5th panel changes
 depending upon col  sym for the first data point).  The 5th panel should
 ideally be the sum of the 4 panels above, keeping col  sym intact.

 Also, I would rather have this in lattice or ggplot2, if anyone sees how to
 convert it.

 Thanks once again, several of you have made very useful suggestions off
 list.  Bryan

 samples - 100 # must be even
 index - round(runif(samples, 1, 100)) # set up data
 resp - rbinom(samples, 1, 0.5)
 yr - rep(c(2005, 2006), samples/2)
 all - data.frame(index, resp, yr)
 all$sym - ifelse(all$resp == 1, 1, 3)
 all$col - ifelse(all$yr == 2005, red, blue)
 all$count - rep(1, length(all$index))
 all - all[order(all$index, all$yr, all$resp),] # for easier inspection
 row.names(all) - c(1:samples) # for easier inspection

 one - all[(all$yr == 2005  all$resp == 0),] # First 2005/0 at top
 two - all[(all$yr == 2005  all$resp == 1),] # Then 2005/1
 three - all[(all$yr == 2006  all$resp == 0),] # Now 2006/0
 four - all[(all$yr == 2006  all$resp == 1),] # Finally 2006/1

 par(mfrow = c(5, 1))
 par(plt = c(0.1, 0.9, 0.25, 0.75))
 stripchart(one$index, method = stack, ylim = c(0,10), xlim = c(1,100), 
 col
 = one$col, pch = one$sym)
 mtext(2005/0, side = 3)
 stripchart(two$index, method = stack, ylim = c(0,10), xlim = c(1,100), 
 col
 = two$col, pch = two$sym)
 mtext(2005/1, side = 3)
 stripchart(three$index, method = stack, ylim = c(0,10), xlim = c(1,100),
 col = three$col, pch = three$sym)
 mtext(2006/0, side = 3)
 stripchart(four$index, method = stack, ylim = c(0,10), xlim = c(1,100),
 col = four$col, pch = four$sym)
 mtext(2006/1, side = 3)
 stripchart(all$index, method = stack, ylim = c(0,10), xlim = c(1,100), 
 col
 = all$col, pch = all$sym)
 mtext(col  sym always taken from 1st data point when all data is
 plotted!, side = 3)

__
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] two newbie questions

2008-06-22 Thread Donald Braman
# I've tried to make this easy to paste into R, though it's probably
so simple you won't need to.
# I have some data (there are many more variables, but this is a
reasonable approximation of it)

# here's a fabricated data frame that is similar in form to mine:
my.df - data.frame(replicate(10, round(rnorm(100, mean=3.5, sd=1
var.list - c(dv1, dv2, dv3, iv1, iv2, iv3, iv4, iv5,
intv1, intv2)
names(my.df) - var.list

# I have some are DVs:
dvs - c(dv1, dv2, dv3)

# some IVs:
ivs - c(iv1, iv2, iv3, iv4, iv5)

# and some binary interaction variables:
intvs - c(intv1, intv2)
library(car)
my.df[intvs] - lapply(my.df[intvs], function(x)
 recode(x, recodes = lo:3.5=0; 3.5:hi=1; ,as.factor.result = FALSE))

# now I loop through a series of interactions using the vector numbers:
for(dv in 1:3) {
 for(iv in 4:8) {
  for (intv in 9:10) {
   jpeg(paste(names(my.df[iv]), names(my.df[dv]), names(my.df[intv]),
.jpg, sep=_))
   with(data.frame(my.df), {
my.fit - lm( my.df[[dv]] ~ my.df[[iv]] + my.df[[intv]] +
my.df[[iv]]:my.df[[intv]])
colors - ifelse (my.df[[intv]] == 1, black, grey)
plot(my.df[[iv]], my.df[[dv]], xlab=names(my.df[iv]),
ylab=names(my.df[dv]), col=colors, pch=.)
curve (cbind (1, 1, x, 1*x) %*% coef(my.fit), add=TRUE, col=black)
curve (cbind (1, 0, x, 0*x) %*% coef(my.fit), add=TRUE, col=gray)
   })
   dev.off()
  }
 }
}


# Question1: Works fine, but using the vector numbers feels kludgy --
especially if the variables in question aren't consecutive.
# Is there a more elegant way of doing this with my lists of variable
names? Something like this, for example:
for(dv in dvs) {
 for(iv in ivs) {
  for (intv in intvs) {
   jpeg(paste(dv, iv, intv, .jpg, sep=_))
   with(data.frame(my.df), {
my.fit - lm(my.df[dv] ~ my.df[iv] + my.df[intv] + my.df[iv]:my.df[intv])
colors - ifelse (my.df[[intv]] == 1, black, grey)
plot(my.df[iv], my.df[dv], xlab=iv, ylab=names(dv), col=colors, pch=.)
curve (cbind (1, 1, x, 1*x) %*% coef(my.fit), add=TRUE, col=black)
curve (cbind (1, 0, x, 0*x) %*% coef(my.fit), add=TRUE, col=gray)
   })
   dev.off()
  }
 }
}

# Clearly that's wrong -- why it's wrong is obscure to me, though!
Please educate me!

# Question2: Could this could be done by using apply rather than a loop?
# Or is looping better here bc there are several actions performed at
each iteration?
# I'm still trying to get my head around all the ways to ditch looping in R.


Donald Braman
http://www.law.gwu.edu/Faculty/profile.aspx?id=10123
http://research.yale.edu/culturalcognition
http://ssrn.com/author=286206

__
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] two newbie questions

2008-06-22 Thread jim holtman
This does away with the 'for' loops and uses 'expand.grid' to create
the combinations.  I think I got the right variables substituted:

my.df - data.frame(replicate(10, round(rnorm(100, mean=3.5, sd=1
var.list - c(dv1, dv2, dv3, iv1, iv2, iv3, iv4, iv5,
intv1, intv2)
names(my.df) - var.list

# I have some are DVs:
dvs - c(dv1, dv2, dv3)

# some IVs:
ivs - c(iv1, iv2, iv3, iv4, iv5)

# and some binary interaction variables:
intvs - c(intv1, intv2)
library(car)
my.df[intvs] - lapply(my.df[intvs], function(x)
 recode(x, recodes = lo:3.5=0; 3.5:hi=1; ,as.factor.result = FALSE))

# now I loop through a series of interactions using the vector numbers:
# create a dataframe of values to check
xpnd - expand.grid(dvs, ivs, intvs) # create combinations
invisible(apply(xpnd, 1, function(.row) {
  jpeg(paste(paste(.row, collapse=_),.jpg, sep=''))

   my.fit - lm( my.df[[.row[1]]] ~ my.df[[.row[2]]] + my.df[[.row[3]]] +
my.df[[.row[2]]]:my.df[[.row[3]]])
   colors - ifelse (my.df[[.row[3]]] == 1, black, grey)
   plot(my.df[[.row[2]]], my.df[[.row[1]]], xlab=.row[2],
ylab=.row[1], col=colors, pch=.)
   curve (cbind (1, 1, x, 1*x) %*% coef(my.fit), add=TRUE, col=black)
   curve (cbind (1, 0, x, 0*x) %*% coef(my.fit), add=TRUE, col=gray)

  dev.off()
 }
))


On Sun, Jun 22, 2008 at 6:26 PM, Donald Braman [EMAIL PROTECTED] wrote:
 # I've tried to make this easy to paste into R, though it's probably
 so simple you won't need to.
 # I have some data (there are many more variables, but this is a
 reasonable approximation of it)

 # here's a fabricated data frame that is similar in form to mine:
 my.df - data.frame(replicate(10, round(rnorm(100, mean=3.5, sd=1
 var.list - c(dv1, dv2, dv3, iv1, iv2, iv3, iv4, iv5,
 intv1, intv2)
 names(my.df) - var.list

 # I have some are DVs:
 dvs - c(dv1, dv2, dv3)

 # some IVs:
 ivs - c(iv1, iv2, iv3, iv4, iv5)

 # and some binary interaction variables:
 intvs - c(intv1, intv2)
 library(car)
 my.df[intvs] - lapply(my.df[intvs], function(x)
  recode(x, recodes = lo:3.5=0; 3.5:hi=1; ,as.factor.result = FALSE))

 # now I loop through a series of interactions using the vector numbers:
 for(dv in 1:3) {
  for(iv in 4:8) {
  for (intv in 9:10) {
   jpeg(paste(names(my.df[iv]), names(my.df[dv]), names(my.df[intv]),
 .jpg, sep=_))
   with(data.frame(my.df), {
my.fit - lm( my.df[[dv]] ~ my.df[[iv]] + my.df[[intv]] +
 my.df[[iv]]:my.df[[intv]])
colors - ifelse (my.df[[intv]] == 1, black, grey)
plot(my.df[[iv]], my.df[[dv]], xlab=names(my.df[iv]),
 ylab=names(my.df[dv]), col=colors, pch=.)
curve (cbind (1, 1, x, 1*x) %*% coef(my.fit), add=TRUE, col=black)
curve (cbind (1, 0, x, 0*x) %*% coef(my.fit), add=TRUE, col=gray)
   })
   dev.off()
  }
  }
 }


 # Question1: Works fine, but using the vector numbers feels kludgy --
 especially if the variables in question aren't consecutive.
 # Is there a more elegant way of doing this with my lists of variable
 names? Something like this, for example:
 for(dv in dvs) {
  for(iv in ivs) {
  for (intv in intvs) {
   jpeg(paste(dv, iv, intv, .jpg, sep=_))
   with(data.frame(my.df), {
my.fit - lm(my.df[dv] ~ my.df[iv] + my.df[intv] + my.df[iv]:my.df[intv])
colors - ifelse (my.df[[intv]] == 1, black, grey)
plot(my.df[iv], my.df[dv], xlab=iv, ylab=names(dv), col=colors, pch=.)
curve (cbind (1, 1, x, 1*x) %*% coef(my.fit), add=TRUE, col=black)
curve (cbind (1, 0, x, 0*x) %*% coef(my.fit), add=TRUE, col=gray)
   })
   dev.off()
  }
  }
 }

 # Clearly that's wrong -- why it's wrong is obscure to me, though!
 Please educate me!

 # Question2: Could this could be done by using apply rather than a loop?
 # Or is looping better here bc there are several actions performed at
 each iteration?
 # I'm still trying to get my head around all the ways to ditch looping in R.


 Donald Braman
 http://www.law.gwu.edu/Faculty/profile.aspx?id=10123
 http://research.yale.edu/culturalcognition
 http://ssrn.com/author=286206

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




-- 
Jim Holtman
Cincinnati, OH
+1 513 646 9390

What is the problem you are trying to solve?

__
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] readLines problem in iteration

2008-06-22 Thread jim holtman
What is the value of 'line' on the first iteration?  It appears to be
undefined.  You probably want something like this:

while (TRUE){
line - readLines(con, n=1)
if (length(line) == 0) break
.your normal statements.
}

On Sun, Jun 22, 2008 at 3:29 PM, Yasin Hajizadeh
[EMAIL PROTECTED] wrote:
 Hi there
  My script at each iteration produces a .dat file which I save in a directory 
 with write.table. Then I need to read each line of this file and create a 
 directory for each line and put elements of that row in that directory. I do 
 it with the following script which I have inserted somewhere between my outer 
 iteration loop, it works fine for the first iteration, but the problem is 
 that it does nothing at next iterations. How can I solve this problem, is 
 there anything wrong with my code?
  Thanks in advance for your help.


write.table(X, file = model.dat, append = FALSE, sep =  , eol = \n, 
 na = NA, dec = ., row.names = FALSE, col.names = FALSE, qmethod = 
 c(escape, double))

  mother-getwd()


  count - 0;

  con- file(model.dat, open=r)


  while (length(line)  0) {

  line-readLines(con,n=1)
  count - count +1
  cat(read row no, count, ,\n, sep=);
  print(line)

  foldername - paste(Iteration,c, ant, count)
  dir.create (foldername)

  setwd(foldername)
  write.table(line, file = params.in, append = FALSE, sep =  , eol = \n, 
 na = NA, dec = ., row.names = FALSE, col.names = FALSE, qmethod = 
 c(escape, double))

  #system(run_misf_calc.py)

  setwd(mother)


  }


  close(con)


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




-- 
Jim Holtman
Cincinnati, OH
+1 513 646 9390

What is the problem you are trying to solve?

__
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] two newbie questions

2008-06-22 Thread Donald Braman
Wow -- many thanks for the mind-*expanding* help!  I'm really impressed by
R's ability to handle this so concisely  It's going to take me a while to
get used to applying things to vectors, but the more I understand, the nicer
R looks.


On Sun, Jun 22, 2008 at 6:59 PM, jim holtman [EMAIL PROTECTED] wrote:

 This does away with the 'for' loops and uses 'expand.grid' to create
 the combinations.  I think I got the right variables substituted:

 my.df - data.frame(replicate(10, round(rnorm(100, mean=3.5, sd=1
 var.list - c(dv1, dv2, dv3, iv1, iv2, iv3, iv4, iv5,
 intv1, intv2)
 names(my.df) - var.list

 # I have some are DVs:
 dvs - c(dv1, dv2, dv3)

 # some IVs:
 ivs - c(iv1, iv2, iv3, iv4, iv5)

 # and some binary interaction variables:
 intvs - c(intv1, intv2)
 library(car)
 my.df[intvs] - lapply(my.df[intvs], function(x)
  recode(x, recodes = lo:3.5=0; 3.5:hi=1; ,as.factor.result = FALSE))

 # now I loop through a series of interactions using the vector numbers:
 # create a dataframe of values to check
 xpnd - expand.grid(dvs, ivs, intvs) # create combinations
 invisible(apply(xpnd, 1, function(.row) {
  jpeg(paste(paste(.row, collapse=_),.jpg, sep=''))

   my.fit - lm( my.df[[.row[1]]] ~ my.df[[.row[2]]] + my.df[[.row[3]]] +
my.df[[.row[2]]]:my.df[[.row[3]]])
   colors - ifelse (my.df[[.row[3]]] == 1, black, grey)
   plot(my.df[[.row[2]]], my.df[[.row[1]]], xlab=.row[2],
ylab=.row[1], col=colors, pch=.)
curve (cbind (1, 1, x, 1*x) %*% coef(my.fit), add=TRUE, col=black)
   curve (cbind (1, 0, x, 0*x) %*% coef(my.fit), add=TRUE, col=gray)

  dev.off()
  }
 ))


 On Sun, Jun 22, 2008 at 6:26 PM, Donald Braman [EMAIL PROTECTED]
 wrote:
  # I've tried to make this easy to paste into R, though it's probably
  so simple you won't need to.
  # I have some data (there are many more variables, but this is a
  reasonable approximation of it)
 
  # here's a fabricated data frame that is similar in form to mine:
  my.df - data.frame(replicate(10, round(rnorm(100, mean=3.5, sd=1
  var.list - c(dv1, dv2, dv3, iv1, iv2, iv3, iv4, iv5,
  intv1, intv2)
  names(my.df) - var.list
 
  # I have some are DVs:
  dvs - c(dv1, dv2, dv3)
 
  # some IVs:
  ivs - c(iv1, iv2, iv3, iv4, iv5)
 
  # and some binary interaction variables:
  intvs - c(intv1, intv2)
  library(car)
  my.df[intvs] - lapply(my.df[intvs], function(x)
   recode(x, recodes = lo:3.5=0; 3.5:hi=1; ,as.factor.result = FALSE))
 
  # now I loop through a series of interactions using the vector numbers:
  for(dv in 1:3) {
   for(iv in 4:8) {
   for (intv in 9:10) {
jpeg(paste(names(my.df[iv]), names(my.df[dv]), names(my.df[intv]),
  .jpg, sep=_))
with(data.frame(my.df), {
 my.fit - lm( my.df[[dv]] ~ my.df[[iv]] + my.df[[intv]] +
  my.df[[iv]]:my.df[[intv]])
 colors - ifelse (my.df[[intv]] == 1, black, grey)
 plot(my.df[[iv]], my.df[[dv]], xlab=names(my.df[iv]),
  ylab=names(my.df[dv]), col=colors, pch=.)
 curve (cbind (1, 1, x, 1*x) %*% coef(my.fit), add=TRUE, col=black)
 curve (cbind (1, 0, x, 0*x) %*% coef(my.fit), add=TRUE, col=gray)
})
dev.off()
   }
   }
  }
 
 
  # Question1: Works fine, but using the vector numbers feels kludgy --
  especially if the variables in question aren't consecutive.
  # Is there a more elegant way of doing this with my lists of variable
  names? Something like this, for example:
  for(dv in dvs) {
   for(iv in ivs) {
   for (intv in intvs) {
jpeg(paste(dv, iv, intv, .jpg, sep=_))
with(data.frame(my.df), {
 my.fit - lm(my.df[dv] ~ my.df[iv] + my.df[intv] +
 my.df[iv]:my.df[intv])
 colors - ifelse (my.df[[intv]] == 1, black, grey)
 plot(my.df[iv], my.df[dv], xlab=iv, ylab=names(dv), col=colors,
 pch=.)
 curve (cbind (1, 1, x, 1*x) %*% coef(my.fit), add=TRUE, col=black)
 curve (cbind (1, 0, x, 0*x) %*% coef(my.fit), add=TRUE, col=gray)
})
dev.off()
   }
   }
  }
 
  # Clearly that's wrong -- why it's wrong is obscure to me, though!
  Please educate me!
 
  # Question2: Could this could be done by using apply rather than a
 loop?
  # Or is looping better here bc there are several actions performed at
  each iteration?
  # I'm still trying to get my head around all the ways to ditch looping in
 R.
 
 
  Donald Braman
  http://www.law.gwu.edu/Faculty/profile.aspx?id=10123
  http://research.yale.edu/culturalcognition
  http://ssrn.com/author=286206
 
  __
  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.
 



 --
 Jim Holtman
 Cincinnati, OH
 +1 513 646 9390

 What is the problem you are trying to solve?


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

[R] ggplot2-barplot

2008-06-22 Thread Felipe Carrillo

Hi all:
I have been using ggplot2 graphics for quite some time now and I really like 
it. However, I haven't used barplots enough to understand the arquitecture 
behind it. Can someone show me how to make this simple barplot graph with 
ggplot2? I want PondName along the x axis and avgWt along the Y axis which 
represents the avgWt by each Pond. 

PondNameavgWt
Pond01  21.5
Pond02  17.8
Pond03  17.8
Pond04  17.8
Pond05  16.375
Pond06  21.5
Pond07  21.5

Using sigmaplot or Excel is a simple task but I can't get it to work with 
ggplot2. I was trying:

qplot(PondName,data=mydata,geom=bar) + geom_bar(fill=factor(PondName))
but I don't get the desired results. 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.


Re: [R] R vs. Bugs

2008-06-22 Thread Paul Johnson
Hey, good topic for a thread.  I've wrestled with this over the years.
I think there's some user confusion about what WinBUGS does.  People
who did not see BUGS before WinBUGS tend not to understand this in the
same way...

The unique / important contributions from WinBUGS  are the collection
of working examples and the Doodle code generator thing.  All of the
rest of it can be easily replaced by open source tools that exist or
could easily exist.


On Sun, Jun 22, 2008 at 11:34 AM, Peter Muhlberg
[EMAIL PROTECTED] wrote:
 I've done some looking around in R and elsewhere to answer my question
 on the value of R vs. Bugs for MCMC.  So, for anyone who is curious,
 here's what I think I've found:  Bugs compiles its code, which should
 make it much faster than a pure R program.  Packages such as AMCMC run
 MCMC in R, potentially with a user-defined C function for the
 density--which should make it comparable in speed to Bugs.  The
 packages MCMCpack  (MCMCmetrop1R function) and mcmc seem designed to
 run w/ a density function written in R.   MCMCpack does have functions
 that use precompiled C code from the Scythe library (which looks
 nice), but I see no simple way to add a C density function.  AMCMC and
 Bugs seem to use adaptive MCMC, but the other R packages don't appear
 to do so, which may mean another performance reduction.

Think of performance as a combination of development time and run time.

Andrew Martin's MCMCpack reduces development time by giving people
some pre-packaged Gibbs sampling fitters for standard models, such as
logistic regression.  It still uses the same iterative sampling
routines under the hood as most other MCMC approaches.  The only
difference there is that it has routines formatted in a way that will
be familiar to R users.  I do not believe a simulation model conducted
in MCMCpack will take a different amount of run time than a well
coded, custom version of the same that is prepared in WinBUGS or any
other GIBBS sampler.  The big difference is that MCMCpack offers
routines for familiar models, and if one wants to thrown in some
random parameter here or there, then MCMCpack won't be able to handle
it.

The U. Chicago professors provide the package bayesm which is roughly
the same kind of thing.  For pre-existing model types, an MCMC model
can be conducted.

Students ask Why learn BUGS when I can use MCMCpack (or bayesm)?
Answer: no reason, unless you want to propose a model that is not
already coded up by the package.


 I see no way to insert my own proposal density in the R functions.
 JAG, a Java-based version of BUGS, apparently allows users to create

If you mean to refer to Martyn Plummer's project JAGS:

http://www-ice.iarc.fr/~martyn/software/jags/

JAGS is Just Another Gibbs Sampler, and it is decidedly not written in Java.
It is, rather, written in C++.

JAGS is proposed as a more-or-less complete drop in replacement for
BUGS, so the user can write up a BUGS style model and then hand it
over to JAGS for processing, the same way we used BUGS before the
WinBugs came along and tried to make it a pointy-clicky experience.
JAGS has versions of the classic BUGS examples, and I think it is very
well done.   If you want to run a Gibbs Sampling exercise in Linux, I
suggest you seriously consider using JAGS.  You might use WinBUGS
Doodle thingie to sketch out the code for your model, but then
translate it to JAGS. (I put a bit of thought into packaging an RPM
for Fedora users a few months ago, but ran into a few little packaging
errors that put me off of it.  Now I'm running Ubuntu and packaging
for that is harder, at least for me...)

I notice there are some R packages that are providing pre-packaged
estimators for common models through JAGS.  Check witness:

bayescount  Bayesian analysis of count distributions with JAGS
bayesmixBayesian Mixture Models with JAGS

It is disappointing/frustrating to me that the source code for
WinBUGS/OpenBugs is kept in secret, because here's what I'd really
like.

1. Make a version of Doodle for sketching out models.  As far as I can
see, Doodle is the only truly uniquely valuable component in Win/Open
BUGS.  It helps people get started by providing a code template.

2. Create an avenue for that Doodle code to travel to JAGS.  rJAGS
exists as an interface between R and jags.


-- 
Paul E. Johnson
Professor, Political Science
1541 Lilac Lane, Room 504
University of Kansas

__
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] Simulating Gaussian Mixture Models

2008-06-22 Thread Peng Jiang



Hi,
  Is there any package that I can use to simulate the Gaussian  
Mixture Model , which is a mixture modeling method that is widely used  
in statistical learning theory.
 I know there is a mclust, however, I think it is a little bit  
different from my problem.

Thanks very much..

 regards.








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


[R] problem in R for Linear mixed model~

2008-06-22 Thread Manli Yan
   Dear R users:
  I just got confused some R code used in linear mixed model~
  example,two factors,A, B,C,A is fixed ,B,C are random,and B is nested in
C,if I wannt to use linear mixed model,are the following code correct for
each case?
case1:want to know random effect of B,
   case1-lme(y~A*B*C,random=~B|C) where B|C stand for what?,mean B is
nested in C?

case2: how to wirte random effect of C?
   case2-lme(y~A*B*C,random=~C)? this doesnt work out,it seem it must have
somehing like #|$

case3.omitting the random effect for B from case1
  case3-update(case1,random=~1|C),so I just type 1,so the random effect of
B will be removed from the model,there only left random effect of c ,the
random effect I removed ,which include both random intercept and slope
,correct??

   case4:omitting the random  intercept
  case4-update(case1,random=B-1|C)
  this code I got from some paper,it said by inputing B-1|C,then the random
intercept  is removed,so,if I want to remove random slode,I input B-2|C,it
doesnt work out.

   case5 :how to know the both random effect of B,and C,I dont know how to
wirtie this in R
.
  And I am a little confused of these R code,especially the #|#
part,what deos this syntax really mean in LME package,

  Thank you for your time~

[[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] Simulating Gaussian Mixture Models

2008-06-22 Thread Tatiana Benaglia

Take a look at mixtools.

Tatiana



On Jun 22, 2008, at 9:23 PM, Peng Jiang wrote:




Hi,
 Is there any package that I can use to simulate the Gaussian  
Mixture Model , which is a mixture modeling method that is widely  
used in statistical learning theory.
I know there is a mclust, however, I think it is a little bit  
different from my problem.

Thanks very much..

regards.








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


__
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] Simulating Gaussian Mixture Models

2008-06-22 Thread Wensui Liu
Hi, Peng,
I had a piece of SAS code for 2-class gaussian mixture from my blog.
You might convert it to R code.

2-Class Gaussian Mixture Model in SAS
data d1;
  do i = 1 to 100;
x = ranuni(1);
e = rannor(1);
y = 5 * x + e;
output;
  end;
run;

data d2;
  do i = 1 to 100;
x = ranuni(2);
e = rannor(2);
y = 15 + 10 * x - 5 * x ** 2 + e;
output;
  end;
run;

data data;
  set d1 d2;
run;

proc nlmixed data = data tech = quanew maxiter = 1000;
  parms b10 = 0 b11 = 5 b12 = 0 b20 = 15 b21 = 10 b22 = -5
prior = 0.1 to 0.9 by 0.01 sigma = 1;

  mu1 = b10 + b11 * x + b12 * x * x;
  mu2 = b20 + b21 * x + b22 * x * x;
  pi = constant('pi');

  P1 = 1 / (((2 * pi) ** 0.5) * sigma) * exp(-0.5 * ((y - mu1) / sigma) ** 2);
  P2 = 1 / (((2 * pi) ** 0.5) * sigma) * exp(-0.5 * ((y - mu2) / sigma) ** 2);

  LH = P1 * prior + P2 * (1 - prior);
  LL = log(LH);

  model y ~ general(LL);
run;

/*
  Parameter Estimates

  Standard
 Parameter  Estimate ErrorDF  t Value  Pr  |t|   Alpha
 b10 -0.17440.3450   200-0.510.61370.05
 b11  5.34261.5040   200 3.550.00050.05
 b12-0.064541.4334   200-0.050.96410.05
 b20 15.36520.3099   20049.57.00010.05
 b21  9.62971.4970   200 6.43.00010.05
 b22 -5.47951.4776   200-3.710.00030.05
 prior0.5000   0.03536   20014.14.00010.05
 sigma1.0049   0.05025   20020.00.00010.05
*/
On 6/22/08, Peng Jiang [EMAIL PROTECTED] wrote:


  Hi,
   Is there any package that I can use to simulate the Gaussian Mixture Model
 , which is a mixture modeling method that is widely used in statistical
 learning theory.
   I know there is a mclust, however, I think it is a little bit different
 from my problem.
  Thanks very much..

   regards.








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



-- 
===
WenSui Liu
Acquisition Risk, Chase
Email : [EMAIL PROTECTED]
Blog   : statcompute.spaces.live.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] Getting only label column of a data frame

2008-06-22 Thread Gundala Viswanath
Hi,

How can I extract the label only from a given data frame.

Fore example from this data frame.

 print(dataf)
  V1  V2  V3  V4  V5  V6  V7  V8  V9
1114514.317.131.241.745.849.868.670.672.9
3545 10.215.620.923.231.431.736.248.451.9
8951 15.217.520.021.432.449.751.358.358.9
1109759.565.9   117.5   118.0   118.9   122.5   126.3   156.5   157.0

I want to get the label (first) column only:

11145
3545
8951
11097

Is there a quick way to achieve that?
I tried this but fail:

mylable - dataf[,1]

Please advice.

- Gundala Viswanath
Jakarta - Indonesia

__
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] Getting only label column of a data frame

2008-06-22 Thread jim holtman
Wait.  The first column is really the rowname.  So you want this:

 row.names(x)
[1] 11145 3545  8951  11097


On Sun, Jun 22, 2008 at 10:16 PM, Gundala Viswanath [EMAIL PROTECTED] wrote:
 Hi,

 How can I extract the label only from a given data frame.

 Fore example from this data frame.

 print(dataf)
  V1  V2  V3  V4  V5  V6  V7  V8  V9
 1114514.317.131.241.745.849.868.670.672.9
 3545 10.215.620.923.231.431.736.248.451.9
 8951 15.217.520.021.432.449.751.358.358.9
 1109759.565.9   117.5   118.0   118.9   122.5   126.3   156.5   157.0

 I want to get the label (first) column only:

 11145
 3545
 8951
 11097

 Is there a quick way to achieve that?
 I tried this but fail:

 mylable - dataf[,1]

 Please advice.

 - Gundala Viswanath
 Jakarta - Indonesia

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




-- 
Jim Holtman
Cincinnati, OH
+1 513 646 9390

What is the problem you are trying to solve?

__
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] problem in R for Linear mixed model~

2008-06-22 Thread Daniel Malter
Hi,

random=~1|B/C
C is nested in B

##Example
data=Oats
regress=lme(yield~nitro*Variety,data=Oats,random=~1|Block/Variety)
##i.e. variety is nested in block
summary(regress)
##End of example

Best,
Daniel 


-
cuncta stricte discussurus
-

-Ursprüngliche Nachricht-
Von: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Im
Auftrag von Manli Yan
Gesendet: Sunday, June 22, 2008 9:30 PM
An: r-help@r-project.org
Betreff: [R] problem in R for Linear mixed model~

   Dear R users:
  I just got confused some R code used in linear mixed model~
  example,two factors,A, B,C,A is fixed ,B,C are random,and B is nested in
C,if I wannt to use linear mixed model,are the following code correct for
each case?
case1:want to know random effect of B,
   case1-lme(y~A*B*C,random=~B|C) where B|C stand for what?,mean B is
nested in C?

case2: how to wirte random effect of C?
   case2-lme(y~A*B*C,random=~C)? this doesnt work out,it seem it must have
somehing like #|$

case3.omitting the random effect for B from case1
  case3-update(case1,random=~1|C),so I just type 1,so the random effect of
B will be removed from the model,there only left random effect of c ,the
random effect I removed ,which include both random intercept and slope
,correct??

   case4:omitting the random  intercept
  case4-update(case1,random=B-1|C)
  this code I got from some paper,it said by inputing B-1|C,then the random
intercept  is removed,so,if I want to remove random slode,I input B-2|C,it
doesnt work out.

   case5 :how to know the both random effect of B,and C,I dont know how to
wirtie this in R .
  And I am a little confused of these R code,especially the #|# part,what
deos this syntax really mean in LME package,

  Thank you for your time~

[[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] One-to-one matching?

2008-06-22 Thread Alec.Zwart
Hi folks, 

Can anyone suggest an efficient way to do matching without
replacement, or one-to-one matching?  pmatch() doesn't quite provide
what I need...

For example, 

lookupTable - c(a,b,c,d,e,f)
matchSample - c(a,a,b,d)
##Normal match() behaviour:
match(matchSample,lookupTable)
[1] 1 1 2 4

My problem here is that both as in matchSample are matched to the same
a in the lookup table.  I need the elements of the lookup table to be
excluded from the table as they are matched, so that no match can be
found for the second a.  

Function pmatch() comes close to what I need:

pmatch(matchSample,lookupTable)
[1] 1 NA 2 4

Yep!  However, pmatch() incorporates partial matching, which I
definitely don't want:

lookupTable - c(a,b,c,d,e,f) 
matchSample - c(a,a,b,d)
pmatch(matchSample,lookupTable)
[1] 1 6 2 4
## i.e. the second a, matches f - I don't want this.

Of course, when identical items ARE duplicated in both sample and lookup
table, I need the matching to reflect this:

lookupTable - c(a,a,c,d,e,f)
matchSample - c(a,a,c,d)
##Normal match() behaviour
match(matchSample,lookupTable)
[1] 1 1 3 4

No good - pmatch() is better:

lookupTable - c(a,a,c,d,e,f)
matchSample - c(a,a,c,d)
pmatch(matchSample,lookupTable)
[1] 1 2 3 4

...but we still have the partial matching issue...

##And of course, as per the usual behaviour of match(), sample elements
missing from the lookup table should return NA:

matchSample - c(a,frog,e,d) ; print(matchSample)
match(matchSample,lookupTable)

Is there a nifty way to get what I'm after without resorting to a for
loop? (my code's already got too blasted many of those...)

Thanks, 

Alec Zwart
CMIS CSIRO
[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.


Re: [R] problem in R for Linear mixed model~

2008-06-22 Thread Manli Yan
  Hi:
  Thank you very much,and for your case
  if I wirte as
 regress=lme(yield~nitro*Variety,data=Oats,random=~Variety|Block)

what this mean?
 Regards


2008/6/22 Daniel Malter [EMAIL PROTECTED]:

 Hi,

 random=~1|B/C
 C is nested in B

 ##Example
 data=Oats
 regress=lme(yield~nitro*Variety,data=Oats,random=~1|Block/Variety)
 ##i.e. variety is nested in block
 summary(regress)
 ##End of example

 Best,
 Daniel


 -
 cuncta stricte discussurus
 -

 -Ursprüngliche Nachricht-
 Von: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Im
 Auftrag von Manli Yan
 Gesendet: Sunday, June 22, 2008 9:30 PM
 An: r-help@r-project.org
 Betreff: [R] problem in R for Linear mixed model~

   Dear R users:
  I just got confused some R code used in linear mixed model~
  example,two factors,A, B,C,A is fixed ,B,C are random,and B is nested in
 C,if I wannt to use linear mixed model,are the following code correct for
 each case?
 case1:want to know random effect of B,
   case1-lme(y~A*B*C,random=~B|C) where B|C stand for what?,mean B is
 nested in C?

 case2: how to wirte random effect of C?
   case2-lme(y~A*B*C,random=~C)? this doesnt work out,it seem it must have
 somehing like #|$

 case3.omitting the random effect for B from case1
  case3-update(case1,random=~1|C),so I just type 1,so the random effect of
 B will be removed from the model,there only left random effect of c ,the
 random effect I removed ,which include both random intercept and slope
 ,correct??

   case4:omitting the random  intercept
  case4-update(case1,random=B-1|C)
  this code I got from some paper,it said by inputing B-1|C,then the random
 intercept  is removed,so,if I want to remove random slode,I input B-2|C,it
 doesnt work out.

   case5 :how to know the both random effect of B,and C,I dont know how to
 wirtie this in R .
  And I am a little confused of these R code,especially the #|# part,what
 deos this syntax really mean in LME package,

  Thank you for your time~

[[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.htmlhttp://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] Columnwise Alternate Subsetting of a Data Frame

2008-06-22 Thread Gundala Viswanath
Hi,

Given this data frame:

 print(repo.dat)
   V1 V2  V3  V4
  V5    (can be more)
1  1007_s_at   DDR1  2865.1  2901.3  1978.3   300.2
2   1053_at  RFC2   103.681.6   108.0  101.3

I want to split them into two data frames yielding:

   V1 V2 V3  ... etc
1  1007_s_at   DDR1  2865.11978.3
2   1053_at  RFC2   103.6  108.0

(V2 and V3 is obtain from V2 and V4 of original repo.dat)

and

   V1V2   V3   ...etc
1  1007_s_at   DDR12901.3 300.2
2   1053_at  RFC2  81.6101.3


(V2 and V3 is obtain from V3 and V5 of original repo.dat)

In principle what we desire to do is to:
1. Given original data frame with V1, V2, V3, V4
2. Split the data frame into two based on V2,V4,V6 ... (even) and V3,
V5, V7 ..(odd) in the original data frame
3. Meanwhile keep row names and V1 in two newly formed data frames.

Is there a compact way to do it?

- Gundala Viswanath
Jakarta - Indonesia

__
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] Simulating Gaussian Mixture Models

2008-06-22 Thread Xiaohui Chen
First, simulate a uniform r.v on [0,1] and then cast it to binary label 
according to your underlying mixing probability;

Second, simulate a Gaussian r.v. in above selected component.

Of course, you can vecterize the two steps to simply your code.

X

Peng Jiang 写道:



Hi,
  Is there any package that I can use to simulate the Gaussian Mixture 
Model , which is a mixture modeling method that is widely used in 
statistical learning theory.
 I know there is a mclust, however, I think it is a little bit 
different from my problem.

Thanks very much..

 regards.








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


__
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] One-to-one matching?

2008-06-22 Thread Gabor Grothendieck
Try this.  apseq() sorts the input and appends a
sequence number: 0, 1, ... to successive
occurrences of each value.  Apply that to both
vectors transforms it into a problem that works
with ordinary match:

 lookupTable - c(a, a,b,c,d,e,f)
 matchSample - c(a, a,a,b,d)

 # sort and append sequence no
 apseq - function(x) {
+ x - sort(x)
+ s - cumsum(!duplicated(x))
+ paste(x, seq(s) - match(s, s))
+ }

 match(apseq(matchSample), apseq(lookupTable))
[1]  1  2 NA  3  5


On Sun, Jun 22, 2008 at 10:57 PM,  [EMAIL PROTECTED] wrote:
 Hi folks,

 Can anyone suggest an efficient way to do matching without
 replacement, or one-to-one matching?  pmatch() doesn't quite provide
 what I need...

 For example,

 lookupTable - c(a,b,c,d,e,f)
 matchSample - c(a,a,b,d)
 ##Normal match() behaviour:
 match(matchSample,lookupTable)
 [1] 1 1 2 4

 My problem here is that both as in matchSample are matched to the same
 a in the lookup table.  I need the elements of the lookup table to be
 excluded from the table as they are matched, so that no match can be
 found for the second a.

 Function pmatch() comes close to what I need:

 pmatch(matchSample,lookupTable)
 [1] 1 NA 2 4

 Yep!  However, pmatch() incorporates partial matching, which I
 definitely don't want:

 lookupTable - c(a,b,c,d,e,f)
 matchSample - c(a,a,b,d)
 pmatch(matchSample,lookupTable)
 [1] 1 6 2 4
 ## i.e. the second a, matches f - I don't want this.

 Of course, when identical items ARE duplicated in both sample and lookup
 table, I need the matching to reflect this:

 lookupTable - c(a,a,c,d,e,f)
 matchSample - c(a,a,c,d)
 ##Normal match() behaviour
 match(matchSample,lookupTable)
 [1] 1 1 3 4

 No good - pmatch() is better:

 lookupTable - c(a,a,c,d,e,f)
 matchSample - c(a,a,c,d)
 pmatch(matchSample,lookupTable)
 [1] 1 2 3 4

 ...but we still have the partial matching issue...

 ##And of course, as per the usual behaviour of match(), sample elements
 missing from the lookup table should return NA:

 matchSample - c(a,frog,e,d) ; print(matchSample)
 match(matchSample,lookupTable)

 Is there a nifty way to get what I'm after without resorting to a for
 loop? (my code's already got too blasted many of those...)

 Thanks,

 Alec Zwart
 CMIS CSIRO
 [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-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] One-to-one matching?

2008-06-22 Thread Moshe Olshansky
How about

x - lookupTable
x[!(x %in% matchSample)] - NA
pmatch(matchSample,x)


Regards,

Moshe.

--- On Mon, 23/6/08, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote:

 From: [EMAIL PROTECTED] [EMAIL PROTECTED]
 Subject: [R] One-to-one matching?
 To: r-help@r-project.org
 Received: Monday, 23 June, 2008, 12:57 PM
 Hi folks, 
 
 Can anyone suggest an efficient way to do matching
 without
 replacement, or one-to-one matching? 
 pmatch() doesn't quite provide
 what I need...
 
 For example, 
 
 lookupTable -
 c(a,b,c,d,e,f)
 matchSample -
 c(a,a,b,d)
 ##Normal match() behaviour:
 match(matchSample,lookupTable)
 [1] 1 1 2 4
 
 My problem here is that both as in matchSample
 are matched to the same
 a in the lookup table.  I need the elements of
 the lookup table to be
 excluded from the table as they are matched, so that no
 match can be
 found for the second a.  
 
 Function pmatch() comes close to what I need:
 
 pmatch(matchSample,lookupTable)
 [1] 1 NA 2 4
 
 Yep!  However, pmatch() incorporates partial matching,
 which I
 definitely don't want:
 
 lookupTable -
 c(a,b,c,d,e,f)
 
 matchSample -
 c(a,a,b,d)
 pmatch(matchSample,lookupTable)
 [1] 1 6 2 4
 ## i.e. the second a, matches
 f - I don't want this.
 
 Of course, when identical items ARE duplicated in both
 sample and lookup
 table, I need the matching to reflect this:
 
 lookupTable -
 c(a,a,c,d,e,f)
 matchSample -
 c(a,a,c,d)
 ##Normal match() behaviour
 match(matchSample,lookupTable)
 [1] 1 1 3 4
 
 No good - pmatch() is better:
 
 lookupTable -
 c(a,a,c,d,e,f)
 matchSample -
 c(a,a,c,d)
 pmatch(matchSample,lookupTable)
 [1] 1 2 3 4
 
 ...but we still have the partial matching issue...
 
 ##And of course, as per the usual behaviour of match(),
 sample elements
 missing from the lookup table should return NA:
 
 matchSample -
 c(a,frog,e,d)
 ; print(matchSample)
 match(matchSample,lookupTable)
 
 Is there a nifty way to get what I'm after without
 resorting to a for
 loop? (my code's already got too blasted many of
 those...)
 
 Thanks, 
 
 Alec Zwart
 CMIS CSIRO
 [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-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] One-to-one matching?

2008-06-22 Thread Charles C. Berry



Or use make.unique() in place of apseq()

On Sun, 22 Jun 2008, Gabor Grothendieck wrote:


Try this.  apseq() sorts the input and appends a
sequence number: 0, 1, ... to successive
occurrences of each value.  Apply that to both
vectors transforms it into a problem that works
with ordinary match:


lookupTable - c(a, a,b,c,d,e,f)
matchSample - c(a, a,a,b,d)

# sort and append sequence no
apseq - function(x) {

+ x - sort(x)
+ s - cumsum(!duplicated(x))
+ paste(x, seq(s) - match(s, s))
+ }


match(apseq(matchSample), apseq(lookupTable))

[1]  1  2 NA  3  5


On Sun, Jun 22, 2008 at 10:57 PM,  [EMAIL PROTECTED] wrote:

Hi folks,

Can anyone suggest an efficient way to do matching without
replacement, or one-to-one matching?  pmatch() doesn't quite provide
what I need...

For example,

lookupTable - c(a,b,c,d,e,f)
matchSample - c(a,a,b,d)
##Normal match() behaviour:
match(matchSample,lookupTable)
[1] 1 1 2 4

My problem here is that both as in matchSample are matched to the same
a in the lookup table.  I need the elements of the lookup table to be
excluded from the table as they are matched, so that no match can be
found for the second a.

Function pmatch() comes close to what I need:

pmatch(matchSample,lookupTable)
[1] 1 NA 2 4

Yep!  However, pmatch() incorporates partial matching, which I
definitely don't want:

lookupTable - c(a,b,c,d,e,f)
matchSample - c(a,a,b,d)
pmatch(matchSample,lookupTable)
[1] 1 6 2 4
## i.e. the second a, matches f - I don't want this.

Of course, when identical items ARE duplicated in both sample and lookup
table, I need the matching to reflect this:

lookupTable - c(a,a,c,d,e,f)
matchSample - c(a,a,c,d)
##Normal match() behaviour
match(matchSample,lookupTable)
[1] 1 1 3 4

No good - pmatch() is better:

lookupTable - c(a,a,c,d,e,f)
matchSample - c(a,a,c,d)
pmatch(matchSample,lookupTable)
[1] 1 2 3 4

...but we still have the partial matching issue...

##And of course, as per the usual behaviour of match(), sample elements
missing from the lookup table should return NA:

matchSample - c(a,frog,e,d) ; print(matchSample)
match(matchSample,lookupTable)

Is there a nifty way to get what I'm after without resorting to a for
loop? (my code's already got too blasted many of those...)

Thanks,

Alec Zwart
CMIS CSIRO
[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-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.



Charles C. Berry(858) 534-2098
Dept of Family/Preventive Medicine
E mailto:[EMAIL PROTECTED]  UC San Diego
http://famprevmed.ucsd.edu/faculty/cberry/  La Jolla, San Diego 92093-0901

__
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] Columnwise Alternate Subsetting of a Data Frame

2008-06-22 Thread Moshe Olshansky
You could do something like:

k - dim(repo.dat)[2]
odd - seq(from=1,to=k,by=2)
even - seq(from=2,to=k,by=2)
even-c(1,even)
df1 - repo.dat[,odd)
colnames(df1) - paste(V,odd,sep=)
df2 - repo.dat[,even)
colnames(df2) - paste(V,even,sep=)


--- On Mon, 23/6/08, Gundala Viswanath [EMAIL PROTECTED] wrote:

 From: Gundala Viswanath [EMAIL PROTECTED]
 Subject: [R] Columnwise Alternate Subsetting of a Data Frame
 To: [EMAIL PROTECTED]
 Received: Monday, 23 June, 2008, 1:03 PM
 Hi,
 
 Given this data frame:
 
  print(repo.dat)
V1 V2  V3   
   V4
   V5    (can be more)
 1  1007_s_at   DDR1  2865.1  2901.3  1978.3   300.2
 2   1053_at  RFC2   103.681.6   108.0 
 101.3
 
 I want to split them into two data frames yielding:
 
V1 V2 V3
  ... etc
 1  1007_s_at   DDR1  2865.11978.3
 2   1053_at  RFC2   103.6  108.0
 
 (V2 and V3 is obtain from V2 and V4 of original repo.dat)
 
 and
 
V1V2
   V3   ...etc
 1  1007_s_at   DDR12901.3 300.2
 2   1053_at  RFC2  81.6101.3
 
 
 (V2 and V3 is obtain from V3 and V5 of original repo.dat)
 
 In principle what we desire to do is to:
 1. Given original data frame with V1, V2, V3, V4
 2. Split the data frame into two based on V2,V4,V6 ...
 (even) and V3,
 V5, V7 ..(odd) in the original data frame
 3. Meanwhile keep row names and V1 in two newly formed data
 frames.
 
 Is there a compact way to do it?
 
 - Gundala Viswanath
 Jakarta - Indonesia
 
 __
 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] Columnwise Alternate Subsetting of a Data Frame

2008-06-22 Thread Charles C. Berry



See

?split

help.search() is (or should be) your friend.

HTH,

Chuck

On Mon, 23 Jun 2008, Gundala Viswanath wrote:


Hi,

Given this data frame:


print(repo.dat)

  V1 V2  V3  V4
 V5    (can be more)
1  1007_s_at   DDR1  2865.1  2901.3  1978.3   300.2
2   1053_at  RFC2   103.681.6   108.0  101.3

I want to split them into two data frames yielding:

  V1 V2 V3  ... etc
1  1007_s_at   DDR1  2865.11978.3
2   1053_at  RFC2   103.6  108.0

(V2 and V3 is obtain from V2 and V4 of original repo.dat)

and

  V1V2   V3   ...etc
1  1007_s_at   DDR12901.3 300.2
2   1053_at  RFC2  81.6101.3


(V2 and V3 is obtain from V3 and V5 of original repo.dat)

In principle what we desire to do is to:
1. Given original data frame with V1, V2, V3, V4
2. Split the data frame into two based on V2,V4,V6 ... (even) and V3,
V5, V7 ..(odd) in the original data frame
3. Meanwhile keep row names and V1 in two newly formed data frames.

Is there a compact way to do it?

- Gundala Viswanath
Jakarta - Indonesia

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



Charles C. Berry(858) 534-2098
Dept of Family/Preventive Medicine
E mailto:[EMAIL PROTECTED]  UC San Diego
http://famprevmed.ucsd.edu/faculty/cberry/  La Jolla, San Diego 92093-0901

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