Re: [R] Loading same libraries (old version newest version) in r

2009-10-12 Thread Patrick Connolly
On Mon, 12-Oct-2009 at 10:54AM +1100, Steven Kang wrote:

| Hi all,
| 
| I require 2 RMySQL libraries in order to query from a database.

You mean you require 2 RMySQL packages.  We must be pedantic to answer
your question.

| 
| 'RMySQL_0.7-4' (newest version) results in an error when more than 1 field
| is queried.
| 
| ''RMySQL_0.5-11' (old version) resolves this issue where more than 1 field
| can be queried without any errors. However, other queries results in an
| error messeges (but no error messeges with 'RMySQL_0.7-4' package)
| 
| Thus, I require two scripts each with different 'RMySQL' packages loaded to
| query from a database.

If you put your *packages* in separate *libraries*, you can load the
one you require using the lib.loc parameter, e.g.

require(RMySQL, lib.loc = /path/to/oldPackage) 

When you wish to use the one in /path/to/newPackage, unload the old
one and change the lib.loc value.

HTH






| 
| Are there any commands that will do the job (i.e. loading 2 different
| libraries from different folder) without having to click 'Pakages' tool bar
| in th RGui console?
| 
| Your help in resolving this issue would be appreciated.
| 
| 
| 
| 
| 
| 
| Steven
| 
|  [[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.

-- 
~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.   
   ___Patrick Connolly   
 {~._.~}   Great minds discuss ideas
 _( Y )_ Average minds discuss events 
(:_~*~_:)  Small minds discuss people  
 (_)-(_)  . Eleanor Roosevelt
  
~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.

__
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] user input in R

2009-10-12 Thread Petr PIKAL
And try also search 

statsrus

The first hit shall be Paul Johnsons's howto's which helped me several 
years ago especially with basic issues.

Regards
Petr



r-help-boun...@r-project.org napsal dne 10.10.2009 18:00:19:

  I'm just learning R (I don't know any other programming languages),
and I have a question. I am trying to figure out how to ask for user
input (say, a set of 3 numbers) then put those numbers into an 
array.
I've looked around, but I haven't been able to find any answers that 
I
understand.
Thanks!
 
 Astoundingly, finding out how to load my own datasets was one of the 
hardest 
 things for me to find information on when I was new to R and I had 
 considerable programming experience.  Part of the problem was that I 
didn't 
 yet know exactly what R documentation was available or how to easily 
access 
 it.  Further, veteran users tend to assume loading datasets is easy, and 

 much documentation and sample code uses 'generated data'.  Thus, sample 
code 
 demonstrating 'loading datasets' is a little hard to find when you are 
 starting out!
 
 The official recommendation would go something like, You probably want 
to 
 read the Import/Export documentation.You can find this on Windows 
GUI 
 under help | manuals | Data Import/Export.  Of course you proably also 
need 
 to read chapter 7 of An Introduction to R which is also linked under 
manuals 
 in the help menu.  That said, I offer some beginner cheats you might 
find 
 useful below.  I particularly recommend the Verzzani Appendix.
 
 Things you could type at the command line to learn more about different 
ways 
 to enter data are:
 ?scan
 ?read.table
 ?read.delim
 ?read.csv
 
 Beginner cheats Suggestions
 
 If you want GUI data input (of dataframes), I'd suggest installing and 
 running the Rcmdr package.  It lets you load many types of datasets, 
 including Excel files.  These can be used within Rcmdr or from the 
command 
 line.
 
 If you are really new to R, I suggest looking at some of the contributed 

 documentation to get a feel for how things are done as well as how to 
load 
 user data
 http://cran.us.r-project.org/other-docs.html
 
 In particular, look at the appendix in John Verzzani's document to see a 

 pragmatic description of using scan to input user data.  (see Appendix: 
 Entering Data in R on p. 103 or so).
 http://cran.us.r-project.org/doc/contrib/Verzani-SimpleR.pdf
 
 __
 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] field index given name.

2009-10-12 Thread tdm

Hi,

How do I access the index number of a field given I only know the field
name?

eg - I want to set the probability of the field 'species' higher than the
other fields to use in sampling.

 colprob - array(dim=NCOL(iris))
 for(i in 1:NCOL(iris)){colprob[i]=0.5}
 colprob[iris$species] = 1 #this doesn't work
 colprob
[1] 0.5 0.5 0.5 0.5 0.5





-- 
View this message in context: 
http://www.nabble.com/field-index-given-name.-tp25851216p25851216.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] Loading same libraries (old version newest version) in r

2009-10-12 Thread Prof Brian Ripley

On Mon, 12 Oct 2009, Patrick Connolly wrote:


On Mon, 12-Oct-2009 at 10:54AM +1100, Steven Kang wrote:

| Hi all,
|
| I require 2 RMySQL libraries in order to query from a database.

You mean you require 2 RMySQL packages.  We must be pedantic to answer
your question.

|
| 'RMySQL_0.7-4' (newest version) results in an error when more than 1 field
| is queried.
|
| ''RMySQL_0.5-11' (old version) resolves this issue where more than 1 field
| can be queried without any errors. However, other queries results in an
| error messeges (but no error messeges with 'RMySQL_0.7-4' package)
|
| Thus, I require two scripts each with different 'RMySQL' packages loaded to
| query from a database.

If you put your *packages* in separate *libraries*, you can load the
one you require using the lib.loc parameter, e.g.

require(RMySQL, lib.loc = /path/to/oldPackage)


Or library(): require() is just a wrapper.


When you wish to use the one in /path/to/newPackage, unload the old
one and change the lib.loc value.


Unfortunately that will not work (but starting a new session and 
loading from a different lib.loc will).  First, RMySQL has a 
namespace, so you need to unload the namespace, not just the package. 
But when you do that, there is AFAICS no .onUnload hook so the DLL 
remains loaded and will not be reloaded when the other version is 
loaded.  You could try playing with library.dynam.unload, but my hazy 
recollection is that did not work either (something to do with 
libmysqlclient only getting initialized once in a process).


I don't see an OS mentioned here, but basically do not believe that 
two versions are really needed: my guess is that this is Windows and 
you need to install RMySQL *from the sources* against your 
installation of MySQL.  There is a long history of binary 
incompatibility between versions of MySQL, even those which differ 
only by one in the 'patchlevel'.




|
| Are there any commands that will do the job (i.e. loading 2 different
| libraries from different folder) without having to click 'Pakages' tool bar
| in th RGui console?
|
| Your help in resolving this issue would be appreciated.
|
|
|
|
|
|
| Steven



--
Brian D. Ripley,  rip...@stats.ox.ac.uk
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] field index given name.

2009-10-12 Thread Schalk Heunis
Hi Phil
Try the following
 which(names(iris)=='Species')
[1] 5

HTH
Schalk Heunis

On Mon, Oct 12, 2009 at 8:53 AM, tdm ph...@philbrierley.com wrote:


 Hi,

 How do I access the index number of a field given I only know the field
 name?

 eg - I want to set the probability of the field 'species' higher than the
 other fields to use in sampling.

  colprob - array(dim=NCOL(iris))
  for(i in 1:NCOL(iris)){colprob[i]=0.5}
  colprob[iris$species] = 1 #this doesn't work
  colprob
 [1] 0.5 0.5 0.5 0.5 0.5





 --
 View this message in context:
 http://www.nabble.com/field-index-given-name.-tp25851216p25851216.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.


[[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] field index given name.

2009-10-12 Thread tdm

Thanks - would never have guessed that. I eventually got the following to do
what I want...

 colprob - array(dim=NCOL(iris))
 for(i in 1:NCOL(iris)){
+ colprob[i]=
+ ifelse(names(iris)[i] == 'Species',1,0.5)
+ }
 colprob
[1] 0.5 0.5 0.5 0.5 1.0




Schalk Heunis-2 wrote:
 
 Hi Phil
 Try the following
 which(names(iris)=='Species')
 [1] 5
 
 HTH
 Schalk Heunis
 
 On Mon, Oct 12, 2009 at 8:53 AM, tdm ph...@philbrierley.com wrote:
 

 Hi,

 How do I access the index number of a field given I only know the field
 name?

 eg - I want to set the probability of the field 'species' higher than the
 other fields to use in sampling.

  colprob - array(dim=NCOL(iris))
  for(i in 1:NCOL(iris)){colprob[i]=0.5}
  colprob[iris$species] = 1 #this doesn't work
  colprob
 [1] 0.5 0.5 0.5 0.5 0.5





 --
 View this message in context:
 http://www.nabble.com/field-index-given-name.-tp25851216p25851216.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.

 
   [[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/field-index-given-name.-tp25851216p25851466.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 Error

2009-10-12 Thread Arif Chandra

Hi R-users,

I would like to ask question related to error output.
If an error comments come out, then the program will automatically stop. 
I want to ask , how I can still continue the program even though there is an 
error comment?

var=VAR(Canada,p=3,type=const)

for (j in 1:nrow(com))
{
mat=ma
{
for (i in 1:ncol(com))
{
y=which(mat==com[j,i])
  mat[y]=NA

}
  
z=which(mat!=0)
  mat[z]=0
hitt=SVAR(var , estmethod = scoring, Amat = mat, Bmat = NULL,max.iter = 
100, maxls = 1000, conv.crit = 1.0e-8) 
hit[j]=hitt$LR$statistic
   
}
}

There will be an error comment,e.g. : Error in solve.default(BinvA) : 
  Lapack routine dgesv: system is exactly singular

But I still want to continue to compute the SVAR.. How can I do it?

Thanks for answering it..
Regards,

Arif
  
_

 Facebook.

k-basics.aspx?ocid=PID23461::T:WLMTAGL:ON:WL:en-id:SI_SB_2:092009
[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Help Error

2009-10-12 Thread Schalk Heunis
This may be of some help:?try

On Mon, Oct 12, 2009 at 9:42 AM, Arif Chandra arif.chan...@hotmail.comwrote:


 Hi R-users,

 I would like to ask question related to error output.
 If an error comments come out, then the program will automatically stop.
 I want to ask , how I can still continue the program even though there is
 an error comment?

 var=VAR(Canada,p=3,type=const)

 for (j in 1:nrow(com))
 {
 mat=ma
 {
 for (i in 1:ncol(com))
 {
y=which(mat==com[j,i])
  mat[y]=NA

 }

z=which(mat!=0)
  mat[z]=0
hitt=SVAR(var , estmethod = scoring, Amat = mat, Bmat = NULL,max.iter
 = 100, maxls = 1000, conv.crit = 1.0e-8)
hit[j]=hitt$LR$statistic

 }
 }

 There will be an error comment,e.g. : Error in solve.default(BinvA) :
  Lapack routine dgesv: system is exactly singular

 But I still want to continue to compute the SVAR.. How can I do it?

 Thanks for answering it..
 Regards,

 Arif

 _

  Facebook.

 k-basics.aspx?ocid=PID23461::T:WLMTAGL:ON:WL:en-id:SI_SB_2:092009
[[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.


[R] Position of legend box

2009-10-12 Thread ogbos okike
Good morning to you. I have about 4 different lines in one plot. I have used
legend to indicate the colour of each plot. But the box contain the legend
covers part of the lines thereby blurring the legend. There are some spaces
in the plot that are empty and large enough to accommodate the legend box.
If there a command I could use to set the position of the legend myself.
I added the legend using:
legend(oo1$daymon[100],3600,c(2005,2006,2004,2003),col=c(4,2,3,1),lty=1)

Thank you.
Ogbos

[[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] package nlme

2009-10-12 Thread wenjun zheng
Hi R Users, When I use package nlme for linear model with random
effects, there exists errors and I don't know the data structure of lme.
 Here is my data:

  
Rice-data.frame(Yield=c(8,7,4,9,7,6,9,8,8,8,7,5,9,9,5,7,7,8,8,8,4,8,6,4,8,8,9),
 Variety=rep(rep(c(A1,A2,A3),each=3),3),
 Stand=rep(c(B1,B2,B3),9),
 Block=rep(1:3,each=9))
Rice.lme-lme(Yield ~ Variety + Stand  + Block,data=Rice)

And error will be like below:

Wrong at getGroups.data.frame(dataMix, groups) :
Invalid formula for groups

can you give me some advice and you will be appreciated. Thanks.

Wenjun.

[[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] package nlme

2009-10-12 Thread ONKELINX, Thierry
You did not specify the random effects. Try something like

Rice.lme-lme(Yield ~ Variety + Stand,data=Rice, random = ~1|Block)

HTH,

Thierry



ir. Thierry Onkelinx
Instituut voor natuur- en bosonderzoek / Research Institute for Nature
and Forest
Cel biometrie, methodologie en kwaliteitszorg / Section biometrics,
methodology and quality assurance
Gaverstraat 4
9500 Geraardsbergen
Belgium
tel. + 32 54/436 185
thierry.onkel...@inbo.be
www.inbo.be

To call in the statistician after the experiment is done may be no more
than asking him to perform a post-mortem examination: he may be able to
say what the experiment died of.
~ Sir Ronald Aylmer Fisher

The plural of anecdote is not data.
~ Roger Brinner

The combination of some data and an aching desire for an answer does not
ensure that a reasonable answer can be extracted from a given body of
data.
~ John Tukey

-Oorspronkelijk bericht-
Van: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org]
Namens wenjun zheng
Verzonden: maandag 12 oktober 2009 10:57
Aan: R-help@r-project.org
Onderwerp: [R] package nlme

Hi R Users, When I use package nlme for linear model with random
effects, there exists errors and I don't know the data structure of lme.
 Here is my data:


Rice-data.frame(Yield=c(8,7,4,9,7,6,9,8,8,8,7,5,9,9,5,7,7,8,8,8,4,8,6,4
,8,8,9),
 Variety=rep(rep(c(A1,A2,A3),each=3),3),
 Stand=rep(c(B1,B2,B3),9),
 Block=rep(1:3,each=9))
Rice.lme-lme(Yield ~ Variety + Stand  + Block,data=Rice)

And error will be like below:

Wrong at getGroups.data.frame(dataMix, groups) :
Invalid formula for groups

can you give me some advice and you will be appreciated. Thanks.

Wenjun.

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

Druk dit bericht a.u.b. niet onnodig af.
Please do not print this message unnecessarily.

Dit bericht en eventuele bijlagen geven enkel de visie van de schrijver weer 
en binden het INBO onder geen enkel beding, zolang dit bericht niet bevestigd is
door een geldig ondertekend document. The views expressed in  this message 
and any annex are purely those of the writer and may not be regarded as stating 
an official position of INBO, as long as the message is not confirmed by a duly 
signed document.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] Problem Fixed

2009-10-12 Thread ogbos okike
I write to thank all those who have helped me to fix this problem.
Best regards
Ogbos

2009/10/7 ogbos okike ogbos.ok...@gmail.com

 Good morning. I wish to plot two data on the same axis. I tried plot(x,y,
 type = l) for the first and tried to use lines or points(x,y, lty = 2, col
 = 4) to add or plot the second data on alongside the first. However, what I
 got was not encouraging.
 I have attached the two data and would be pleased if anybody could be of
 help.
 Thank you
 Best regards
 Ogbos


[[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] Error: cannot allocate vector of size 1.2 Gb

2009-10-12 Thread romunov
Dear List,

today I turn to you with a next problem. I'm trying to compare species
richness between various datasets (locations) using species accumulation
curves (Chapter 4, page 54 in Tree diversity
analysishttp://www.worldagroforestry.org/treesandmarkets/tree_diversity_analysis.aspby
Kindt  Coe). To accomplish this I'm using package
BiodiversityR. My data is comprised of species community (PoCom) (10
locations with 83 species) and environmental factors (PoEnv) (10 locations
with 17 factors).
In attempt to calculate the function (accumcomp) I receive the following
error. I can not imagine how a 10x83+10x17 matrix can grow to a GB or more.
Unless I'm missing something? How can I combat this?

 poacc2 - accumcomp(PoCom, y=PoEnv, factor1=HM_sprem, method=exact)
Error: cannot allocate vector of size 1.2 Gb
In addition: Warning messages:
1: In vector(integer, length) :
  Reached total allocation of 1023Mb: see help(memory.size)
2: In vector(integer, length) :
  Reached total allocation of 1023Mb: see help(memory.size)
3: In vector(integer, length) :
  Reached total allocation of 1023Mb: see help(memory.size)
4: In vector(integer, length) :
  Reached total allocation of 1023Mb: see help(memory.size)


Cheers,
Roman

[[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] Creating a Clustered-Stacked Column Chart

2009-10-12 Thread Jim Lemon

On 10/12/2009 01:53 AM, zhijie zhang wrote:

Thanks. I think there may be no easy method to achive it.
   library(lattice)
   barchart(Titanic, scales = list(x = free),auto.key = list(title
=Survived),layout=c(4,1),horizontal = FALSE)
The above method generates four graphs, two graphs in the left are for
children's male and female,respectively and the right two graphs are for
adult's male and female,respectively .
   Actually, i hope to generate two graphs finally. Say the right two graphs
for adult are overlaid with the left two graphs for children,respectively.
Take the  1st of x variable as an example, in the place of 1st, the
stacked bar for both children and adult should be displayed. Maybe the data
for children and adult should be first shifted certain values to different
directions and then applying the overlay function to get it.
   My above ideas to display a data may be bad. Anyway, thanks a lot.
   

Hi Zhijie,
This looked like an interesting challenge, so I bent the barp function a 
bit to do it. The barp3 function attached will accept a 3D array in 
which the rows represent groups, the columns subgroups and the files 
sub-subgroups. The arrangement of bars is that of the example you gave. 
In order to translate the 2D matrix of the example to the 3D array, I 
have written a little conversion function df2array. Try this:


clustack-structure(list(Country = structure(c(3L, 2L, 1L),
 .Label = c(Asia,Europe, N Amer), class = factor),
 Q1.pencils = c(16L, 14L,18L), Q1.pens = c(12L, 9L, 14L),
 Q2.pencils = c(18L, 15L, 18L), Q2.pens = c(14L, 11L, 15L),
 Q3.pencils = c(17L, 11L, 20L), Q3.pens = c(11L, 8L, 15L),
 Q4.pencils = c(20L, 14L, 21L), Q4.pens = c(14L, 12L, 16L)),
 .Names = c(Country, Q1.pencils,Q1.pens, Q2.pencils, Q2.pens, 
Q3.pencils, Q3.pens,Q4.pencils, Q4.pens),

 class = data.frame, row.names = c(NA,-3L))

# x is the original data frame with the group names in the
# first column and the column names as in the example
# I read it in as a CSV file.
# depth is the length of the files (3rd dimension)
df2array-function(x,depth) {
 dimx-dim(x)
 if(dimx[2]%%depth) stop(depth must divide number of columns without 
remainder)

 column.order-NULL
 for(d in 1:depth)
  column.order-c(column.order,seq(d,dimx[2]-(depth-d),by=depth))
 return(array(unlist(x[,column.order]),c(dimx[1],dimx[2]/depth,depth)))
}

# this converts the data frame to the array
pp.array-df2array(clustack[,2:9],2)

# this function is pretty much the same as barp
barp3-function(height,width=0.4,names.arg=NULL,
 legend.lab=NULL,legend.pos=e,col=NULL,border=par(fg),
 main=NULL,xlab=,ylab=,xlim=NULL,ylim=NULL,
 staxx=FALSE,staxy=FALSE,height.at=NULL,
 height.lab=NULL,cex.axis=par(cex.axis),
 do.first=NULL) {

 if(is.data.frame(height)) its_ok-is.numeric(unlist(height))
 else its_ok-is.numeric(height)
 if(!its_ok) stop(barp3 can only display bars with numeric heights)
 hdim-dim(height)
 if(is.null(hdim) || length(hdim) != 3)
  stop(barp3 can only plot 3 dimensional arrays)
 ngroups-hdim[1]
 if(length(col)==hdim[3])
  barcol-array(rep(col,each=hdim[1]*hdim[2]),hdim)
 else barcol-col
 if(is.null(xlim)) xlim-c(0.4,ngroups+0.6)
 if(any(height0,na.rm=TRUE))
  stop(Can't have negative bar heights in barp3)
 if(is.null(ylim)) {
  maxstack-0
  for(group in 1:hdim[1]) {
   for(subgroup in 1:hdim[2]) {
thistack-sum(height[group,subgroup,],na.rm=TRUE)
if(thistack  maxstack) maxstack-thistack
   }
  }
  ylim-c(0,maxstack*1.05)
 }
 plot(0,type=n,main=main,xlab=xlab,ylab=ylab,
  axes=FALSE,xlim=xlim,ylim=ylim,xaxs=i,yaxs=i)
 if(!is.null(do.first)) eval(do.first)
 if(is.null(names.arg)) names.arg-1:ngroups
 if(staxx) {
  axis(1,at=1:ngroups,labels=rep(,ngroups),
   cex.axis=cex.axis)
  staxlab(1,at=1:ngroups,labels=names.arg,cex=cex.axis)
 }
 else axis(1,at=1:ngroups,labels=names.arg,cex.axis=cex.axis)
 if(is.null(height.at)) height.at-pretty(ylim)
 if(is.null(height.lab)) height.lab-pretty(ylim)
 if(staxy) {
  axis(2,at=height.at,labels=rep(,length(height.lab)),
   cex.axis=cex.axis)
  staxlab(2,at=height.at,labels=height.lab,cex=cex.axis)
 }
 else axis(2,at=height.at,labels=height.lab,cex.axis=cex.axis)
 barwidth-2*width/hdim[2]
 for(group in 1:hdim[1]) {
  left-group-hdim[2]*barwidth/2
  for(subgroup in 1:hdim[2]) {
   bottom-0
   for(subsub in 1:hdim[3]) {
rect(left,bottom,left+barwidth,
 bottom+height[group,subgroup,subsub],
 col=barcol[group,subgroup,subsub],border=border)
bottom-bottom+height[group,subgroup,subsub]
   }
   left-left+barwidth
  }
 }
 if(!is.null(legend.lab)) {
  xjust-yjust-0.5
  if(is.null(legend.pos)) {
   cat(Click at the lower left corner of the legend\n)
   legend.pos-locator(1)
   xjust-yjust-0
  }
  if(legend.pos[1] == e)
   legend.pos-emptyspace(barpinfo,bars=TRUE)
  legend(legend.pos,legend=legend.lab,fill=col,
   xjust=xjust,yjust=yjust)
 }
 box()
}

# the colors should be an array of the same form as the data
barp3(pp.array,col=array(rep(1:8,each=3),c(3,4,2)),
 names.arg=clustack[,1])

Have 

Re: [R] plot the same types of graphics on the same R graphic device

2009-10-12 Thread carol white
one example is to plot two vectors against each other and then, to plot the CI 
(confidence interval) of each point on the same graphics. The first could be 
done by plot and the second by plotCI in gplots package but how to plot on the 
same R graphic device?

Look forward to your reply,

--- On Fri, 10/9/09, Sarah Goslee sarah.gos...@gmail.com wrote:

From: Sarah Goslee sarah.gos...@gmail.com
Subject: Re: [R] plot the same types of graphics on the same R graphic device
To: carol white wht_...@yahoo.com, r-help r-help@r-project.org
Date: Friday, October 9, 2009, 3:04 PM

Hi Carol,

It isn't at all clear exactly what you are trying to do, but you might want to
read the help for either points() and lines() [to put more than one data pair
on a single plot], or for par, specifically mfrow and mfcol, or for layout [to
put more than one plot on a single device window].

If none of those do it, then try again with a more detailed description of what
you are looking for.

Sarah

On Fri, Oct 9, 2009 at 5:10 PM, carol white wht_...@yahoo.com wrote:
 Hi,
 How to plot the same types of graphics on the same R graphic device? Suppose 
 that we want to plot a vector y against x (using plot for instance). How is 
 it possible to plot y against x for different values of these two vectors on 
 the same device so that the plots could be compared?

 Cheers,

 Carol




-- 
Sarah Goslee
http://www.functionaldiversity.org



  
[[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] plot the same types of graphics on the same R graphic device

2009-10-12 Thread Jim Lemon

On 10/12/2009 08:47 PM, carol white wrote:

one example is to plot two vectors against each other and then, to plot the CI 
(confidence interval) of each point on the same graphics. The first could be 
done by plot and the second by plotCI in gplots package but how to plot on the 
same R graphic device?
   

Hi Carol,
I would:

plot(the first vector)
dispersion(for the first vector)
points(the second vector)
dispersion(for the second vector)

There are a number of other functions to display CIs.

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.


Re: [R] Error: cannot allocate vector of size 1.2 Gb

2009-10-12 Thread joris meys
Dear Roman,

could you give us the trace given by traceback() ? I suspect the error
is resulting from the permutations and/or jackknife procedure in the
underlying functions specaccum and specpool.

You can take a look at the package R.huge, but that one is deprecated
already. There are other packages around too, but I have no experience
with them. You find some more tips here :
http://www.matthewckeller.com/html/memory.html

This should give you a place to start looking.
Kind regards
Joris

On Mon, Oct 12, 2009 at 11:39 AM, romunov romu...@gmail.com wrote:
 Dear List,

 today I turn to you with a next problem. I'm trying to compare species
 richness between various datasets (locations) using species accumulation
 curves (Chapter 4, page 54 in Tree diversity
 analysishttp://www.worldagroforestry.org/treesandmarkets/tree_diversity_analysis.aspby
 Kindt  Coe). To accomplish this I'm using package
 BiodiversityR. My data is comprised of species community (PoCom) (10
 locations with 83 species) and environmental factors (PoEnv) (10 locations
 with 17 factors).
 In attempt to calculate the function (accumcomp) I receive the following
 error. I can not imagine how a 10x83+10x17 matrix can grow to a GB or more.
 Unless I'm missing something? How can I combat this?

 poacc2 - accumcomp(PoCom, y=PoEnv, factor1=HM_sprem, method=exact)
 Error: cannot allocate vector of size 1.2 Gb
 In addition: Warning messages:
 1: In vector(integer, length) :
  Reached total allocation of 1023Mb: see help(memory.size)
 2: In vector(integer, length) :
  Reached total allocation of 1023Mb: see help(memory.size)
 3: In vector(integer, length) :
  Reached total allocation of 1023Mb: see help(memory.size)
 4: In vector(integer, length) :
  Reached total allocation of 1023Mb: see help(memory.size)


 Cheers,
 Roman

        [[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] Non linear fitting of 2 distributions with shared parameters

2009-10-12 Thread Etienne Toffin
Hi,

I need to compare non-linear fittings of 2 different experimental  
distributions. I use nls() to the fit the 2 distribution and it works  
pretty well.

The statistical comparison of 2 non linear fits is well described in  
the book Fitting Models to Biological Data using Linear and Nonlinear  
Regression from Harvey Motulsky and Arthur Christopoulos.
This test is based on the calculation of an F-value that compares the  
residuals of
1°) the global fit of both data sets (with one value for each  
parameter) on one hand,
2°) with the 2 fits of each separate data sets (with thus 2 values for  
each parameter) on the other hand.
This methods allows to decide wether the 2 data sets belong to the  
same curve. No problem this far.

But the next step is about comparing each parameter to decide wether  
or not they are different between each data set. The comparison still  
lies on the calculation of an F-value, but here I compare
1°) the residuals of the 2 fits of each separate data sets,
2°) with the residuals the 2 fits of each data sets which share a same  
value of the parameter that is compared (i.e. the 2 curve fits find  
the same value for the shared parameter).
This point is where I need some help : is there any function to make  
non-linear fitting of (at least) 2 data sets with shared parameters ?

Hope someone will have some good news for me…

Etienne Toffin
[[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] Error: cannot allocate vector of size 1.2 Gb

2009-10-12 Thread romunov
Hello joris,

this is the traceback() output. Hopefully you can make some sense out of it.
Thank you for the tips as well (R.huge looks promising)!

 traceback()
7: vector(integer, length)
6: integer(nbins)
5: tabulate(bin, pd)
4: as.vector(data)
3: array(tabulate(bin, pd), dims, dimnames = dn)
2: table(y[, factor])
1: accumcomp(PoCom, y = PoEnv, factor1 = HM_sprem, method = exact)

Cheers,
Roman



On Mon, Oct 12, 2009 at 12:52 PM, joris meys jorism...@gmail.com wrote:

 Dear Roman,

 could you give us the trace given by traceback() ? I suspect the error
 is resulting from the permutations and/or jackknife procedure in the
 underlying functions specaccum and specpool.

 You can take a look at the package R.huge, but that one is deprecated
 already. There are other packages around too, but I have no experience
 with them. You find some more tips here :
 http://www.matthewckeller.com/html/memory.html

 This should give you a place to start looking.
 Kind regards
 Joris

 On Mon, Oct 12, 2009 at 11:39 AM, romunov romu...@gmail.com wrote:
  Dear List,
 
  today I turn to you with a next problem. I'm trying to compare species
  richness between various datasets (locations) using species accumulation
  curves (Chapter 4, page 54 in Tree diversity
  analysis
 http://www.worldagroforestry.org/treesandmarkets/tree_diversity_analysis.asp
 by
  Kindt  Coe). To accomplish this I'm using package
  BiodiversityR. My data is comprised of species community (PoCom) (10
  locations with 83 species) and environmental factors (PoEnv) (10
 locations
  with 17 factors).
  In attempt to calculate the function (accumcomp) I receive the following
  error. I can not imagine how a 10x83+10x17 matrix can grow to a GB or
 more.
  Unless I'm missing something? How can I combat this?
 
  poacc2 - accumcomp(PoCom, y=PoEnv, factor1=HM_sprem, method=exact)
  Error: cannot allocate vector of size 1.2 Gb
  In addition: Warning messages:
  1: In vector(integer, length) :
   Reached total allocation of 1023Mb: see help(memory.size)
  2: In vector(integer, length) :
   Reached total allocation of 1023Mb: see help(memory.size)
  3: In vector(integer, length) :
   Reached total allocation of 1023Mb: see help(memory.size)
  4: In vector(integer, length) :
   Reached total allocation of 1023Mb: see help(memory.size)
 
 
  Cheers,
  Roman
 
 [[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] Error: cannot allocate vector of size 1.2 Gb

2009-10-12 Thread joris meys
Hi Roman,

that throws a different light on the problem. It goes wrong from the
start, so it has little to do with the bootstrap or jackknife
procedures. R.huge won't help you either.

Likely your error comes from the fact that factor1 is not an
argument of the function accumcomp. the argument is factor. As R
doesn't find this, it'll try to tabulate the complete environmental
dataset, and this gives the memory overflow.

Try :

poacc2 - accumcomp(PoCom, y=PoEnv, factor=HM_sprem, method=exact)

That should work. I can't try it out without dataset off course. If it
doesn't work, post the traceback again, I'll take another look.

Kind regards
Joris

On Mon, Oct 12, 2009 at 1:07 PM, romunov romu...@gmail.com wrote:
 Hello joris,

 this is the traceback() output. Hopefully you can make some sense out of it.
 Thank you for the tips as well (R.huge looks promising)!

 traceback()
 7: vector(integer, length)
 6: integer(nbins)
 5: tabulate(bin, pd)
 4: as.vector(data)
 3: array(tabulate(bin, pd), dims, dimnames = dn)
 2: table(y[, factor])
 1: accumcomp(PoCom, y = PoEnv, factor1 = HM_sprem, method = exact)

 Cheers,
 Roman



 On Mon, Oct 12, 2009 at 12:52 PM, joris meys jorism...@gmail.com wrote:

 Dear Roman,

 could you give us the trace given by traceback() ? I suspect the error
 is resulting from the permutations and/or jackknife procedure in the
 underlying functions specaccum and specpool.

 You can take a look at the package R.huge, but that one is deprecated
 already. There are other packages around too, but I have no experience
 with them. You find some more tips here :
 http://www.matthewckeller.com/html/memory.html

 This should give you a place to start looking.
 Kind regards
 Joris

 On Mon, Oct 12, 2009 at 11:39 AM, romunov romu...@gmail.com wrote:
  Dear List,
 
  today I turn to you with a next problem. I'm trying to compare species
  richness between various datasets (locations) using species accumulation
  curves (Chapter 4, page 54 in Tree diversity
 
  analysishttp://www.worldagroforestry.org/treesandmarkets/tree_diversity_analysis.aspby
  Kindt  Coe). To accomplish this I'm using package
  BiodiversityR. My data is comprised of species community (PoCom) (10
  locations with 83 species) and environmental factors (PoEnv) (10
  locations
  with 17 factors).
  In attempt to calculate the function (accumcomp) I receive the following
  error. I can not imagine how a 10x83+10x17 matrix can grow to a GB or
  more.
  Unless I'm missing something? How can I combat this?
 
  poacc2 - accumcomp(PoCom, y=PoEnv, factor1=HM_sprem, method=exact)
  Error: cannot allocate vector of size 1.2 Gb
  In addition: Warning messages:
  1: In vector(integer, length) :
   Reached total allocation of 1023Mb: see help(memory.size)
  2: In vector(integer, length) :
   Reached total allocation of 1023Mb: see help(memory.size)
  3: In vector(integer, length) :
   Reached total allocation of 1023Mb: see help(memory.size)
  4: In vector(integer, length) :
   Reached total allocation of 1023Mb: see help(memory.size)
 
 
  Cheers,
  Roman
 
         [[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] Error: cannot allocate vector of size 1.2 Gb

2009-10-12 Thread romunov
Hi Joris,

thanks for spotting that one. This little mistake has gotten in when I was
trying desperate things with the analysis (factor1 is used in diversitycomp).
Nevertheless, here is the result:

 poacc2 - accumcomp(PoCom, y=PoEnv, factor=HM_sprem, method=exact)
Error in if (p == 1) { : argument is of length zero

And the traceback():

 traceback()
3: specaccum(x, method = method, permutations = permutations, conditioned =
conditioned,
   gamma = gamma, ...)
2: accumresult(x, y, factor, level = levels[i], scale = scale, method =
method,
   permutations = permutations, conditioned = conditioned, gamma =
gamma)
1: accumcomp(PoCom, y = PoEnv, factor = HM_sprem, method = exact)

Best wishes,
Roman


On Mon, Oct 12, 2009 at 1:56 PM, joris meys jorism...@gmail.com wrote:

 Hi Roman,

 that throws a different light on the problem. It goes wrong from the
 start, so it has little to do with the bootstrap or jackknife
 procedures. R.huge won't help you either.

 Likely your error comes from the fact that factor1 is not an
 argument of the function accumcomp. the argument is factor. As R
 doesn't find this, it'll try to tabulate the complete environmental
 dataset, and this gives the memory overflow.

 Try :

 poacc2 - accumcomp(PoCom, y=PoEnv, factor=HM_sprem, method=exact)

 That should work. I can't try it out without dataset off course. If it
 doesn't work, post the traceback again, I'll take another look.

 Kind regards
 Joris

 On Mon, Oct 12, 2009 at 1:07 PM, romunov romu...@gmail.com wrote:
  Hello joris,
 
  this is the traceback() output. Hopefully you can make some sense out of
 it.
  Thank you for the tips as well (R.huge looks promising)!
 
  traceback()
  7: vector(integer, length)
  6: integer(nbins)
  5: tabulate(bin, pd)
  4: as.vector(data)
  3: array(tabulate(bin, pd), dims, dimnames = dn)
  2: table(y[, factor])
  1: accumcomp(PoCom, y = PoEnv, factor1 = HM_sprem, method = exact)
 
  Cheers,
  Roman
 
 
 
  On Mon, Oct 12, 2009 at 12:52 PM, joris meys jorism...@gmail.com
 wrote:
 
  Dear Roman,
 
  could you give us the trace given by traceback() ? I suspect the error
  is resulting from the permutations and/or jackknife procedure in the
  underlying functions specaccum and specpool.
 
  You can take a look at the package R.huge, but that one is deprecated
  already. There are other packages around too, but I have no experience
  with them. You find some more tips here :
  http://www.matthewckeller.com/html/memory.html
 
  This should give you a place to start looking.
  Kind regards
  Joris
 
  On Mon, Oct 12, 2009 at 11:39 AM, romunov romu...@gmail.com wrote:
   Dear List,
  
   today I turn to you with a next problem. I'm trying to compare species
   richness between various datasets (locations) using species
 accumulation
   curves (Chapter 4, page 54 in Tree diversity
  
   analysis
 http://www.worldagroforestry.org/treesandmarkets/tree_diversity_analysis.asp
 by
   Kindt  Coe). To accomplish this I'm using package
   BiodiversityR. My data is comprised of species community (PoCom) (10
   locations with 83 species) and environmental factors (PoEnv) (10
   locations
   with 17 factors).
   In attempt to calculate the function (accumcomp) I receive the
 following
   error. I can not imagine how a 10x83+10x17 matrix can grow to a GB or
   more.
   Unless I'm missing something? How can I combat this?
  
   poacc2 - accumcomp(PoCom, y=PoEnv, factor1=HM_sprem,
 method=exact)
   Error: cannot allocate vector of size 1.2 Gb
   In addition: Warning messages:
   1: In vector(integer, length) :
Reached total allocation of 1023Mb: see help(memory.size)
   2: In vector(integer, length) :
Reached total allocation of 1023Mb: see help(memory.size)
   3: In vector(integer, length) :
Reached total allocation of 1023Mb: see help(memory.size)
   4: In vector(integer, length) :
Reached total allocation of 1023Mb: see help(memory.size)
  
  
   Cheers,
   Roman
  
  [[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] field index given name.

2009-10-12 Thread David Winsemius


On Oct 12, 2009, at 3:22 AM, tdm wrote:



Thanks - would never have guessed that. I eventually got the  
following to do

what I want...


colprob - array(dim=NCOL(iris))
for(i in 1:NCOL(iris)){

+ colprob[i]=
+ ifelse(names(iris)[i] == 'Species',1,0.5)
+ }

colprob

[1] 0.5 0.5 0.5 0.5 1.0




This would be more in keeping with the approah in R of avoiding loops  
when possble:


 colprob - array(dim=NCOL(iris))
 colprob[] - 0.5
 colprob
[1] 0.5 0.5 0.5 0.5 0.5
 colprob[names(iris) == Species] - 1
 colprob
[1] 0.5 0.5 0.5 0.5 1.0


--
David



Schalk Heunis-2 wrote:


Hi Phil
Try the following

which(names(iris)=='Species')

[1] 5

HTH
Schalk Heunis

On Mon, Oct 12, 2009 at 8:53 AM, tdm ph...@philbrierley.com wrote:



Hi,

How do I access the index number of a field given I only know the  
field

name?

eg - I want to set the probability of the field 'species' higher  
than the

other fields to use in sampling.


colprob - array(dim=NCOL(iris))
for(i in 1:NCOL(iris)){colprob[i]=0.5}
colprob[iris$species] = 1 #this doesn't work
colprob

[1] 0.5 0.5 0.5 0.5 0.5





--
View this message in context:
http://www.nabble.com/field-index-given-name.-tp25851216p25851216.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.



[[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/field-index-given-name.-tp25851216p25851466.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.


David Winsemius, MD
Heritage Laboratories
West Hartford, CT

__
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] Position of legend box

2009-10-12 Thread David Winsemius


On Oct 12, 2009, at 4:07 AM, ogbos okike wrote:

Good morning to you. I have about 4 different lines in one plot. I  
have used
legend to indicate the colour of each plot. But the box contain the  
legend
covers part of the lines thereby blurring the legend. There are some  
spaces
in the plot that are empty and large enough to accommodate the  
legend box.
If there a command I could use to set the position of the legend  
myself.

I added the legend using:
legend(oo1$daymon[100],3600,c(2005,2006, 
2004,2003),col=c(4,2,3,1),lty=1)


This may be of help, courtesy of plotmeister Jim Lemon:

http://finzi.psych.upenn.edu/Rhelp08/2009-June/202740.html

There are also facilities in  Harrell's Hmisc that do something similar:
library(Hmisc)
?labcurve

__

David Winsemius, MD
Heritage Laboratories
West Hartford, CT

__
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] is that possible to graph 4 dimention plot

2009-10-12 Thread joris meys
I'm basically put off by the question itself. Plotting a 4-dimensional
graph is rather complicated if the world has only 3 dimensions. A
4-dimensional representation is typically a movie (with time as the
4th dimension). You could try to project a heatmap on a 3D surface
graph, but I doubt this will make things much more clear.

So the standard (and correct) way of solving this problem, is to think
about a clever way to represent the needed information in less
dimensions. Ryan gives some nice examples and tips of how to do that,
but those are dismissed as not helpful.

People on the list answer voluntarily. They do not like to be told
that you don't think it will really help. Did you actually try it
out? You certainly don't give that impression. Maybe you should have
another look at it, and question your own approach to the problem as
well.

Keep it in mind for next time, you're not making yourself popular this way.

Kind regards
Joris



On Sat, Oct 10, 2009 at 10:01 PM, Duncan Murdoch murd...@stats.uwo.ca wrote:
 On 07/10/2009 5:50 PM, gcheer3 wrote:

 Thanks for your reply.

 But I don't think it will really help. My problem is as follows:

 I have 20 observations
 y - rnorm(N,mean= rep(th[1:2],N/2),sd=th[3])

 I have a loglikelihood function for 3 variables mu-(mu1,mu2) and sig
        loglike - function(mu,sig){
        temp-rep(0,length(y))
        for (i in 1:(length(y)))
        {

 temp[i]-log((1/2)*dnorm(y[i],mu[1],sig)+(1/2)*dnorm(y[i],mu[2],sig))}
        return(sum(temp))
         }

 for example

 mu-c(1,1.5)
 sig-2
 loglike(mu,sig)

 [1] -34.1811

 I am interested how mu[1], mu[2], and sig changes, will effect the
 loglikelihood surface. At what values of mu and sig will make
 loglikelihood
 the maximum and at what values of mu and sig will make loglikelihood has
 local max (smaller hills) and at what values of mu and sig the
 loglikelihood
 is flat , etc.
 I tried contour3d also, seems doesn't work

 I haven't seen any replies to this.  One explanation would be that everyone
 was turned off (as I was) by the rude remark above.

 On this list, before saying that something doesn't work, it's polite to
 give a simple, nicely formatted, self-contained reproducible example of what
 went wrong, and to ask whether it is your error or an error in the package.
  Taking that approach will usually result in someone pointing out your error
 (and fixing your code); sometimes it will result in a package author
 agreeing it's a bug, and fixing it.

 Duncan Murdoch


 Thanks for any advice


 Ryan-50 wrote:

 Suppose there are 4 variables
 d is a function of a , b and c
 I want to know how a, b and c change will make d change
 It will be straightforward to see it if we can graph the d surface

 if d is only a function of a and b, I can use 'persp' to see the surface
 of
 d. I can easily see at what values of a and b, d will get the maxium or
 minium or multiple modes, etc

 But for 4 dimention graph, is there a way to show the surface of d
 Will use color help

 Thanks a lot

 Not sure what your data looks like, but you might also consider looking
 at a 2 dimensional version.  See ?coplot
 for example:

 coplot(lat ~ long | depth * mag, data = quakes)

 Or you can make 2 or 3-dimensional plots using the lattice package
 conditioning on some of the variables - e.g. d ~ a | b * c,
 etc.
 If a, b, and c are continuous, you can use equal.count.  Here is
 an uninteresting example, considering a, b, and c as points along
 a grid:

 a - b - c - seq(1:10)
 dat - data.frame(expand.grid(a, b, c))
 names(dat) - letters[1:3]

 dat$d - with(dat, -(a-5)^2 - (b-5)^2 - (c-5)^2)

 library(lattice)
 # 2-d:
 xyplot(d ~ a | equal.count(b)*equal.count(c), data=dat, type=l)
 # etc.

 # 3-d:
 contourplot(d ~ a * b | equal.count(c), data=dat)
 wireframe(d ~ a * b | equal.count(c), data=dat)

 __
 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-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] List mappings and variable creation

2009-10-12 Thread Michael Pearmain
Hi All,

I have a questions about associative list mappings in R, and if they are
possible?

I have data in the form show below, and want to make a new 'bucket' variable
called combined. Which is the sum of the control and the exposed metric
values
This combined variable is a many to many matching as values only appear in
the file if they have a value  0.

conversion.type   filteredIDbucketID  Metric   Value
countertrue  control   a  1
countertrue  control   b  1
countertrue  control   c  2
countertrue  control   d  3

countertrue  exposed a 4
countertrue  exposed e 1

ASIDE:

At the minute i read the data into my file and and then create all the
'missing' row values
(in this case,
countertrue  control e 0
countertrue  exposed   b  0
countertrue  exposed   c  0
countertrue  exposed   d  0)


and then run  a sort on the data, and count the number of times control
appears, and then use this as an index matcher.

saw.aggr.data - [order(saw.aggr.data$bucketID, saw.aggr.data$metric), ]
no.of.metrics - length(saw.aggr.data$bucketID[grep(control,
saw.aggr.data$bucketID)])

for (i in (1:no.of.metrics)) {
  assign(paste(combined, as.character(saw.aggr.data$metric[i])),
(saw.aggr.data$value[i] + saw.aggr.data$value[i + no.of.metrics]))
}

This does what i want it to but is very very weak and could be open to large
errors, ( error handling currently via grepping the names of the metric[i]
== name of metric [i + no.of.metrics])

Is there a more powerful way of doing this using some kind of list mapping?
I've looked at the older threads in this area and it looks like something
that should be possible but i can't figure out how to do this?
Ideally i'd like a final dataset  / list that is of the following form.

conversion.type   filteredIDbucketID  Metric   Value
countertrue  control   a  1
countertrue  control   b  1
countertrue  control   c  2
countertrue  control   d  3

countertrue  exposed a 4
countertrue  exposed e 1
countertrue  combineda 5
countertrue  combinedb 1
countertrue  combinedc 2
countertrue  combinedd 3
countertrue  combinede 1

So i dont have to create the dummy variables.

does this make sense?

Many thanks in advance

Mike



-- 
Michael Pearmain
I abhor averages.  I like the individual case.  A man may have six meals
one day and none the next, making an average of three meals per day, but
that is not a good way to live.  ~Louis D. Brandeis

f you received this communication by mistake, please don't forward it to
anyone else (it may contain confidential or privileged information), please
erase all copies of it, including all attachments, and please let the sender
know it went to the wrong person. Thanks.

[[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] R and computer size

2009-10-12 Thread Vibe Henriette Skov
Dear R-mailing list

Hope you can help me. I am using R for windows to analyze my 107
HGU133Plus2.0 chips, however, R chrash when I try to use ReadAffy(). I
want to buy a computer that can handle all these arrays, do you know how
big a computer I need to buy?

Best,
Skov, Denmark


[[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] svy / weighted regression

2009-10-12 Thread Laust
Dear Peter,

Thanks for the input. The zero rates in some strata occurs because
sampling depended on case status: In Finland only 50% of the non-cases
were sampled, while all others were sampled with 100% probability.

Best
Laust

On Sat, Oct 10, 2009 at 11:02 AM, Peter Dalgaard
p.dalga...@biostat.ku.dk wrote:
 Sorry, forgot to reply all...

 Laust wrote:

 Dear list,

 I am trying to set up a propensity-weighted regression using the
 survey package. Most of my population is sampled with a sampling
 probability of one (that is, I have the full population). However, for
 a subset of the data I have only a 50% sample of the full population.
 In previous work on the data, I analyzed these data using SAS and
 STATA. In those packages I used a propensity weight of 1/[sampling
 probability] in various generalized linear regression-procedures, but
 I am having trouble setting this up. I bet the solution is simple, but
 I’m a R newbie. Code to illustrate my problem below.

 Hi Laust,

 You probably need the package author to explain fully, but as far as I
 can see, the crux is that a dispersion parameter is being used, based on
 Pearson residuals, even in the Poisson case (i.e. you effectively get
 the same result as with quasipoisson()).

 I don't know what the rationale is for this, but it is clear that with
 your data, an estimated dispersion parameter is going to be large. E.g.
 the data has both 0 cases in 75 person-years and 1000 cases in 5000
 person-years for Denmark, and in your model they are supposed to have
 the same Poisson rate.

 summary.svyglm starts off with

    est.disp - TRUE

 and AFAICS there is no way it can get set to FALSE.  Knowing Thomas,
 there is probably a perfectly good reason not to just set the dispersion
 to 1, but I don't get it either...


 Thanks
 Laust

 # loading survey
 library(survey)

 # creating data
 listc -
 c(Denmark,Finland,Norway,Sweden,Denmark,Finland,Norway,Sweden)
 listw - c(1,2,1,1,1,1,1,1)
 listd - c(0,0,0,0,1000,1000,1000,2000)
 listt - c(75,50,90,190,5000,5000,5000,1)
 list.cwdt - c(listc, listw, listd, listt)
 country -
 data.frame(country=listc,weight=listw,deaths=listd,yrs_at_risk=listt)

 # running a frequency weighted regression to get the correct point
 estimates for comparison
 glm - glm(deaths ~ country + offset(log(yrs_at_risk)),
 weights=weight, data=country, family=poisson())
 summary(glm)
 regTermTest(glm, ~ country)

 # running survey weighted regression
 svy - svydesign(~0,,data=country, weight=~weight)
 svyglm - svyglm(deaths ~ country + offset(log(yrs_at_risk)),
 design=svy, data=country, family=poisson())
 summary(svyglm)
 # point estimates are correct, but standard error is way too large
 regTermTest(svyglm, ~ country)
 # test indicates no country differences

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


 --
   O__   Peter Dalgaard             Øster Farimagsgade 5, Entr.B
  c/ /'_ --- Dept. of Biostatistics     PO Box 2099, 1014 Cph. K
  (*) \(*) -- University of Copenhagen   Denmark      Ph:  (+45) 35327918
 ~~ - (p.dalga...@biostat.ku.dk)              FAX: (+45) 35327907



__
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] Nelder-Mead with output of simplex vertices

2009-10-12 Thread Terry Therneau
-- begin included 
Greetings!
I want to follow the evolution of a Nelder-Mead function
minimisation (a function of 2 variables). Hence each simplex
will have 3 vertices.

Therefore I would like to have a function which can output
the coordinates of the 3 vertices after each new simplex
is generated. However, there seems to be no way (which I can
detect) of extracting this information from optim() (the 'trace'
argument to 'control' does not seem to have provision for this,
according to '?optim', and I have tried it out without success).

--- end include -

 Why not put a cat() statement into fn, the function that you supply
which optim is calling?  That will give the vertices that it tries one
by one.

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.


Re: [R] svy / weighted regression

2009-10-12 Thread David Winsemius
I think you are missing the point. You have 4 zero death counts  
associated with much higher person years of exposure followed by 4  
death counts in the thousands associated with lower degrees of  
exposures. It seems unlikely that these are real data as there are not  
cohorts that would exhibit such lower death-rates. So it appears that  
in setting up your test case, you have created an impossibly  
unrealistic test problem.


--
David


On Oct 12, 2009, at 9:12 AM, Laust wrote:


Dear Peter,

Thanks for the input. The zero rates in some strata occurs because
sampling depended on case status: In Finland only 50% of the non-cases
were sampled, while all others were sampled with 100% probability.

Best
Laust

On Sat, Oct 10, 2009 at 11:02 AM, Peter Dalgaard
p.dalga...@biostat.ku.dk wrote:

Sorry, forgot to reply all...

Laust wrote:


Dear list,

I am trying to set up a propensity-weighted regression using the
survey package. Most of my population is sampled with a sampling
probability of one (that is, I have the full population). However,  
for
a subset of the data I have only a 50% sample of the full  
population.

In previous work on the data, I analyzed these data using SAS and
STATA. In those packages I used a propensity weight of 1/[sampling
probability] in various generalized linear regression-procedures,  
but
I am having trouble setting this up. I bet the solution is simple,  
but

I’m a R newbie. Code to illustrate my problem below.


Hi Laust,

You probably need the package author to explain fully, but as far  
as I
can see, the crux is that a dispersion parameter is being used,  
based on

Pearson residuals, even in the Poisson case (i.e. you effectively get
the same result as with quasipoisson()).

I don't know what the rationale is for this, but it is clear that  
with
your data, an estimated dispersion parameter is going to be large.  
E.g.
the data has both 0 cases in 75 person-years and 1000 cases in  
5000

person-years for Denmark, and in your model they are supposed to have
the same Poisson rate.

summary.svyglm starts off with

   est.disp - TRUE

and AFAICS there is no way it can get set to FALSE.  Knowing Thomas,
there is probably a perfectly good reason not to just set the  
dispersion

to 1, but I don't get it either...



Thanks
Laust

# loading survey
library(survey)

# creating data
listc -
c 
(Denmark 
,Finland,Norway,Sweden,Denmark,Finland,Norway,Sweden)

listw - c(1,2,1,1,1,1,1,1)
listd - c(0,0,0,0,1000,1000,1000,2000)
listt - c(75,50,90,190,5000,5000,5000,1)
list.cwdt - c(listc, listw, listd, listt)
country -
data 
.frame(country=listc,weight=listw,deaths=listd,yrs_at_risk=listt)


# running a frequency weighted regression to get the correct point
estimates for comparison
glm - glm(deaths ~ country + offset(log(yrs_at_risk)),
weights=weight, data=country, family=poisson())
summary(glm)
regTermTest(glm, ~ country)

# running survey weighted regression
svy - svydesign(~0,,data=country, weight=~weight)
svyglm - svyglm(deaths ~ country + offset(log(yrs_at_risk)),
design=svy, data=country, family=poisson())
summary(svyglm)
# point estimates are correct, but standard error is way too large
regTermTest(svyglm, ~ country)
# test indicates no country differences

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



--
  O__   Peter Dalgaard Øster Farimagsgade 5, Entr.B
 c/ /'_ --- Dept. of Biostatistics PO Box 2099, 1014 Cph. K
 (*) \(*) -- University of Copenhagen   Denmark  Ph:  (+45)  
35327918
~~ - (p.dalga...@biostat.ku.dk)  FAX: (+45)  
35327907





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


David Winsemius, MD
Heritage Laboratories
West Hartford, CT

__
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] Nelder-Mead with output of simplex vertices

2009-10-12 Thread Ted Harding
On 12-Oct-09 13:24:01, Terry Therneau wrote:
 -- begin included 
 Greetings!
 I want to follow the evolution of a Nelder-Mead function
 minimisation (a function of 2 variables). Hence each simplex
 will have 3 vertices.
 
 Therefore I would like to have a function which can output
 the coordinates of the 3 vertices after each new simplex
 is generated. However, there seems to be no way (which I can
 detect) of extracting this information from optim() (the 'trace'
 argument to 'control' does not seem to have provision for this,
 according to '?optim', and I have tried it out without success).
 
 --- end include -
 
  Why not put a cat() statement into fn, the function that you supply
 which optim is calling?  That will give the vertices that it tries one
 by one.
 
 Terry T.

That's neat and simple! It hadn't occurred to me. Thanks!
Ted.


E-Mail: (Ted Harding) ted.hard...@manchester.ac.uk
Fax-to-email: +44 (0)870 094 0861
Date: 12-Oct-09   Time: 14:32:08
-- XFMail --

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] R and computer size

2009-10-12 Thread Martin Morgan
Vibe Henriette Skov wrote:
 Dear R-mailing list
 
 Hope you can help me. I am using R for windows to analyze my 107
 HGU133Plus2.0 chips, however, R chrash when I try to use ReadAffy(). I
 want to buy a computer that can handle all these arrays, do you know how
 big a computer I need to buy?

Hi Skov -- this is a Bioconductor question, so ask on the Bioconductor
mailing list.

http://bioconductor.org/docs/mailList.html

There are alternatives to affy::ReadAffy that might work on your current
machine, including affy::justRMA, the aroma.affymetrix package, and the
xps package (which requires a system dependency that some find difficult
to install).

Others on the bioc list might have more guidance on memory requirements
on 64 bit linux systems, which is what you'll want for large data analysis.

Martin

 
 Best,
 Skov, Denmark
 
 
   [[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.


-- 
Martin Morgan
Computational Biology / Fred Hutchinson Cancer Research Center
1100 Fairview Ave. N.
PO Box 19024 Seattle, WA 98109

Location: Arnold Building M1 B861
Phone: (206) 667-2793

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Error: cannot allocate vector of size 1.2 Gb

2009-10-12 Thread joris meys
That's the file I needed, and the problem I expected. The factor you
specify is not a factor, but a numerical variable. Even more, if you
tabulate it, you have 2 times the values 1, 2 and 5, and all
other values only once. That's what gives you the error.

p is an internal variable of the function specaccum. It's the number
of columns in a  dataframe containing only locations with a certain
value for the specified factor. If there is only one location with
that factor level, you get only one row and thus a vector. The
function ncol() gives result NULL if you try it on a vector,  so p is
NULL, and has zero length.

You can for example convert HM_sprem to a factor, indicating low and
high values.

PoEnv$test 
-factor(ifelse(PoEnv$HM_sprem2.5,low,high),levels=c(low,high),ordered=T)
poacc2 - accumcomp(PoCom, y=PoEnv, factor=test, method=exact)

works like a charm for me.

In the future, check carefully which type of arguments are asked for,
and use the function str() to check if they really are what you think
they are.

Kind regards
Joris


-- Forwarded message --
From: romunov romu...@gmail.com
Date: Mon, Oct 12, 2009 at 3:14 PM
Subject: Re: [R] Error: cannot allocate vector of size 1.2 Gb
To: joris meys jorism...@gmail.com


I hope this workspace file attached is what you were looking for.

Cheers,
Roman


On Mon, Oct 12, 2009 at 2:07 PM, joris meys jorism...@gmail.com wrote:

 It's easier if you just load the data in R, save the workspace and
 send that one. I really don't have time to read in csv data and find
 my way trough it, sorry. It also makes it possible for me to find
 errors due to the wrong data format (factors that are not defined as
 factor and the likes).

 Kind regards
 Joris

 On Mon, Oct 12, 2009 at 2:04 PM, romunov romu...@gmail.com wrote:
  Hi again,
 
  thank you for your time, I really appreciate you taking time dealing with my
  problem. I am sending you my dataset (community (zdruzbe_analiza.csv) and
  environmental (okoljski_analiza.csv) factors) in case you want to try it out
  for yourself.
 
  Cheers,
  Roman
 
 
 
  On Mon, Oct 12, 2009 at 2:02 PM, romunov romu...@gmail.com wrote:
 
  Hi Joris,
 
  thanks for spotting that one. This little mistake has gotten in when I was
  trying desperate things with the analysis (factor1 is used in
  diversitycomp). Nevertheless, here is the result:
 
   poacc2 - accumcomp(PoCom, y=PoEnv, factor=HM_sprem, method=exact)
  Error in if (p == 1) { : argument is of length zero
 
  And the traceback():
 
   traceback()
  3: specaccum(x, method = method, permutations = permutations, conditioned
  = conditioned,
     gamma = gamma, ...)
  2: accumresult(x, y, factor, level = levels[i], scale = scale, method =
  method,
     permutations = permutations, conditioned = conditioned, gamma =
  gamma)
  1: accumcomp(PoCom, y = PoEnv, factor = HM_sprem, method = exact)
 
  Best wishes,
  Roman
 
 
  On Mon, Oct 12, 2009 at 1:56 PM, joris meys jorism...@gmail.com wrote:
 
  Hi Roman,
 
  that throws a different light on the problem. It goes wrong from the
  start, so it has little to do with the bootstrap or jackknife
  procedures. R.huge won't help you either.
 
  Likely your error comes from the fact that factor1 is not an
  argument of the function accumcomp. the argument is factor. As R
  doesn't find this, it'll try to tabulate the complete environmental
  dataset, and this gives the memory overflow.
 
  Try :
 
  poacc2 - accumcomp(PoCom, y=PoEnv, factor=HM_sprem, method=exact)
 
  That should work. I can't try it out without dataset off course. If it
  doesn't work, post the traceback again, I'll take another look.
 
  Kind regards
  Joris
 
  On Mon, Oct 12, 2009 at 1:07 PM, romunov romu...@gmail.com wrote:
   Hello joris,
  
   this is the traceback() output. Hopefully you can make some sense out
   of it.
   Thank you for the tips as well (R.huge looks promising)!
  
   traceback()
   7: vector(integer, length)
   6: integer(nbins)
   5: tabulate(bin, pd)
   4: as.vector(data)
   3: array(tabulate(bin, pd), dims, dimnames = dn)
   2: table(y[, factor])
   1: accumcomp(PoCom, y = PoEnv, factor1 = HM_sprem, method = exact)
  
   Cheers,
   Roman
  
  
  
   On Mon, Oct 12, 2009 at 12:52 PM, joris meys jorism...@gmail.com
   wrote:
  
   Dear Roman,
  
   could you give us the trace given by traceback() ? I suspect the error
   is resulting from the permutations and/or jackknife procedure in the
   underlying functions specaccum and specpool.
  
   You can take a look at the package R.huge, but that one is deprecated
   already. There are other packages around too, but I have no experience
   with them. You find some more tips here :
   http://www.matthewckeller.com/html/memory.html
  
   This should give you a place to start looking.
   Kind regards
   Joris
  
   On Mon, Oct 12, 2009 at 11:39 AM, romunov romu...@gmail.com wrote:
Dear List,
   
today I turn to you with a next problem. I'm trying to compare
species
 

[R] RPostgreSQL and needed .dlls

2009-10-12 Thread Josuah Rechtsteiner

Dear List,

I am trying to connect from R 2.9.2 on Win XP SP3 to a remotely  
installed PostgreSQL DB (8.3.7 on Ubuntu Server 9.04). Everything  
seems to be properly installed, as I can connect to the DB from within  
Excel and RKWard (running on another machine).
But regarding R on the Win XP, I cannot load RPostgreSQL. libpq.dll is  
missing. What can I do now, without having to install PostgreSQL on  
this Windows, where I do not need it as I have my remote DB?


Thanks in advance

__
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] need help

2009-10-12 Thread MOH MOHA







 
  
  Sample Size
  
  
  λ=5      α =
  4       β = 3
  
 
 
  
  Min.
  
  
  1St Qu.
  
  
  Median
  
  
  Mean
  
  
  3rd Qu.
  
  
  Max.
  
 
 
  
  100
  
  
  0.00
  
  
  1.740638
  
  
  4.040032
  
  
  4.433828
  
  
  5.607589
  
  
  22.450405
  
 
 
  
  500
  
  
  0.00
  
  
  2.212375
  
  
  3.915889
  
  
  4.750014
  
  
  6.356894
  
  
  22.860806
  
 
 
  
  1000
  
  
  0.00
  
  
  2.295969
  
  
  4.207002
  
  
  5.054784
  
  
  6.763213
  
  
  27.419783
  
 
 
  
  5000
  
  
  0.00
  
  
  2.288180
  
  
  4.060344
  
  
  4.997187
  
  
  6.747790
  
  
  53.890014
  
 
 
  
  1
  
  
  0.00
  
  
  2.323913
  
  
  4.165010
  
  
  5.055568
  
  
  6.787189
  
  
  45.338561
  
 
 
  
  Sample Size
  
  
  λ =10      α =
  4       β = 3
  
 
 
  
  Min.
  
  
  1St Qu.
  
  
  Median
  
  
  Mean
  
  
  3rd Qu.
  
  
  Max.
  
 
 
  
  100
  
  
  1.796326
  
  
  5.634923
  
  
  8.586495
  
  
  9.432652
  
  
  12.250539
  
  
  26.535398
  
 
 
  
  500
  
  
  0.1435474
  
  
  6.2096963
  
  
  9.352632
  
  
  9.9507770
  
  
  12.5914827
  
  
  39.0010363
  
 
 
  
  1000
  
  
  0.1491454
  
  
  5.9161795
  
  
  .6888265
  
  
  9.8011127
  
  
  2.7219316
  
  
  35.0477795
  
 
 
  
  5000
  
  
  0.1116321
  
  
  6.1443172
  
  
  9.072187
  
  
  10.0330122
  
  
  12.6700472
  
  
  65.7772109
  
 
 
  
  1
  
  
  0.00
  
  
  6.116205
  
  
  9.044711
  
  
  10.004620
  
  
  12.767728
  
  
  54.560908
  
 
 
  
  Sample Size
  
  
  λ =20      α =
  4       β = 3
  
 
 
  
  Min.
  
  
  1St Qu.
  
  
  Median
  
  
  Mean
  
  
  3rd Qu.
  
  
  Max.
  
 
 
  
  100
  
  
  4.825701
  
  
  14.720441
  
  
  17.41218
  
  
  19.743268
  
  
  23.279030
  
  
  63.946636
  
 
 
  
  500
  
  
  6.305691
  
  
  14.132502
  
  
  18.90554
  
  
  19.977387
  
  
  24.180544
  
  
  54.408182
  
 
 
  
  1000
  
  
  4.350899
  
  
  14.581057
  
  
  18.96924
  
  
  20.261373
  
  
  24.740963
  
  
  52.379454
  
 
 
  
  5000
  
  
  2.07920
  
  
  14.73828
  
  
  19.20401
  
  
  20.19534
  
  
  24.52991
  
  
  72.49832
  
 
 
  
  1
  
  
  2.070761
  
  
  14.458651
  
  
  19.12765
  
  
  20.035136
  
  
  24.329874
  
  
  138.388379
  
 
 
  
  Sample Size
  
  
  λ =30      α =
  4       β = 3
  
 
 
  
  Min.
  
  
  1St Qu.
  
  
  Median
  
  
  Mean
  
  
  3rd Qu.
  
  
  Max.
  
 
 
  
  100
  
  
  9.783008
  
  
  23.858371
  
  
  29.60942
  
  
  30.458481
  
  
  36.540193
  
  
  50.774556
  
 
 
  
  500
  
  
  9.686187
  
  
  24.006261
  
  
  29.14230
  
  
  30.520085
  
  
  35.921312
  
  
  69.158839
  
 
 
  
  1000
  
  
  8.78857
  
  
  23.50711
  
  
  28.47166
  
  
  29.69044
  
  
  34.83602
  
  
  72.65655
  
 
 
  
  5000
  
  
  8.248564
  
  
  23.094087
  
  
  28.75213
  
  
  29.722024
  
  
  35.276848
  
  
  90.079316
  
 
 
  
  1
  
  
  4.508184
  
  
  23.422685
  
  
  28.96963
  
  
  30.044882
  
  
  35.502004
  
  
  107.360714
  
 




 

 

My friends, group R . I hope you help me to comment on these
results? And how can compute the variance of  Fs.

 

model.freq=expression(data=rpois(30))

model.sev=expression(data=rpareto(30,30))

Fs=aggregateDist(simulation,nb.simul=1000,model.freq,model.sev)

 

Thanks

 

Mohd PhD Student

 

Malaysia




  
[[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] function: ploting an igraph object within lattice

2009-10-12 Thread Andrewjohnclose

Hi, I would like to be able to develop a function to plot an igraph object
with lattice (trellis type displays will be usefull for grouping etc).
Anyway, I mostly feeble 

Igraph requires that you convert two columns of data two an igraph object
and to be able to plot the graph...I have tried a very, very simplistic (if
not naive) approach and surprise, surprise, it didn't work.

First of all, does anyone know any good tutorial packages/books that will
help someone like me unused to programming develop their function writing
skills, and secondly, can anyone suggest a way to generate an igraph object
in lattice.

Thanks

Andrew

##generates the igraph plot
library(igraph)
LE-read.csv(LE.csv)
LG-graph.data.frame(LE, directed=F)
LG$layout-layout.kamada.kawai(LG)
plot(LG, vertex.size=4, vertex.label=NA, vertex.color=red,
vertex.shape=square, edge.color=blue4)
##
##
library(lattice)
##
##
xyplot.igraph - function(plot.igraph, ...) {

dat - graph.data.frame(x = object, directed=FALSE)
prepanel=prepanel.igraph

}

prepanel.igraph - function(x, axes=FALSE, xlab=, ylab=, add=FALSE,
  xlim=c(-1,1), ylim=c(-1,1), main=, sub=)



http://www.nabble.com/file/p25855220/LE.csv LE.csv 
-- 
View this message in context: 
http://www.nabble.com/function%3A-ploting-an-igraph-object-within-lattice-tp25855220p25855220.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] R commander.

2009-10-12 Thread Ilyas .
i have two RData files,,i want to print them to check the format of the
tables in these files,,,i can load both the files and can read it as well

 load('ann.RData')
 str(ann)
List of 4
 $ Name  : chr [1:561466] rs3094315 rs12562034 rs3934834
rs9442372 ...
 $ Position  : int [1:561466] 742429 758311 995669 1008567 1011278 1011521
1020428 1021403 1038818 1039813 ...
 $ Chromosome: chr(0)
 $ Chr.num   : num [1:561466] 1 1 1 1 1 1 1 1 1 1 ...

but when i try to display all the table by using the R commander.i have got
the display of 'pheno.RData' file,,but the other file 'ann.RData' show me an
error i.e.

 ann - as.data.frame(ann)
Error in data.frame(Name = c(rs3094315, rs12562034, rs3934834,
rs9442372,  :
  arguments imply differing number of rows: 561466, 0



i am sending you both files,,,hope u will help me solve this problm


Ilyas
__
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] how to output profile plots for groups using lattice package

2009-10-12 Thread George Kalema
Hi Peter (and anyone else willing to help me out),
Many thanks for your help. Having used your code plus a few other
modifications, I only get the points plotted but without the two lines. I
just cannot figure out what the problem is.

My code is as follows:

library(lattice)
datos2 - subset(datos, samplesize != 10  parm != Theta0)
unq - sort(unique(datos2$samplesize))
datos2$fsamplesize - factor(datos2$samplesize, labels = paste(Sample
size =, unq))
datos2$parm - factor(datos2$parm, levels = c(Intercept, time,
trt, time*trt))
tp1.sim - xyplot(MSE ~ ntimes | fsamplesize + parm, group = group, data
= datos2,
type = b, lty = 1:2, pch = 1:2,
scales = list(x = list(at = c(2, 4, 8, 16)), alternating = 1),
as.table = TRUE, key = list(text = list(c(GNA, PNA)), points =
list(pch = 1:2))
)
plot(tp1.sim)

I have attached my real dataset (called datos) as well.

Kind appreciations to your efforts.

George


On Wed, Oct 7, 2009 at 9:20 AM, Peter Ehlers ehl...@ucalgary.ca wrote:

 see below

 George Kalema wrote:

 Dear R users,
 I am trying to have an xyplot of a data set which has the following
 variables:
 case (n=10,20,30)
 parameter (parm=a,b)
 group (grp=g1,g2)
 y (y values)
 x (x=2,4,8)

 My plot should be parameter by case such that I have 2 rows (each row=
 each
 parameter) and 3 columns (each column=each case). My R-code is as follows
 but I am not able to get what I want to:

 tp1.sim - xyplot(y~ x | case + parm , group=group, data = data, lty = 1:4
 ,
 pch = 1:4)
 print(tp1.sim)

 How can I have two lines (for g1 and g2) in each plot (each box)?

 include the type=b argument

  How do I label the x-axis with only values 2, 4, 8?

 include the scales= argument or make x a factor

  How do I label each column with the corresponding case number?

 make 'case' a factor

 The following should do what you want:

 xyplot(y ~ x | factor(case) + parm, group=group, data=data,
type='b', lty=1:2, pch=1:2,
scales=list(x=list(at=c(2,4,8)))
 )

 I don't understand why you want 4 line types/point chars.

  -Peter Ehlers


 My hypothetical data set is as follows:

 parm x case y group
 a 2 10 0.03 g1
 b 2 10 0.02 g1
 a 4 10 0.03 g1
 b 4 10 0.02 g1
 a 8 10 0.03 g1
 b 8 10 0.02 g1
 a 2 20 0.03 g1
 b 2 20 0.02 g1
 a 4 20 0.03 g1
 b 4 20 0.02 g1
 a 8 20 0.03 g1
 b 8 20 0.02 g1
 a 2 30 0.03 g1
 b 2 30 0.02 g1
 a 4 30 0.03 g1
 b 4 30 0.02 g1
 a 8 30 0.03 g1
 b 8 30 0.02 g1
 a 2 10 0.13 g2
 b 2 10 0.12 g2
 a 4 10 0.13 g2
 b 4 10 0.12 g2
 a 8 10 0.13 g2
 b 8 10 0.12 g2
 a 2 20 0.13 g2
 b 2 20 0.12 g2
 a 4 20 0.13 g2
 b 4 20 0.12 g2
 a 8 20 0.13 g2
 b 8 20 0.12 g2
 a 2 30 0.13 g2
 b 2 30 0.12 g2
 a 4 30 0.13 g2
 b 4 30 0.12 g2
 a 8 30 0.13 g2
 b 8 30 0.12 g2

 Many thanks in advance for your response.

 George

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





-- 

George Williams KALEMA,

Schapenstraat 37/282,
3000 Leuven,
Belgium.

Cell: +32 495 33 13 02

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] Using diff, ifelse on zoo object

2009-10-12 Thread charliegenge

Hi,

I'm having an issue when using diff and ifelse on a zoo object.

x.Date - as.Date(2003-02-01) + c(1, 3, 7, 9, 14) - 1
x - zoo(rnorm(5), x.Date)
x.POS - c(0,0,0,1,1)
x- merge(x,x.POS)
x
x x.POS
2003-02-01   -0.1858136 0
2003-02-03   -1.3188533 0
2003-02-070.2709794  0
2003-02-09   -1.4915262 1
2003-02-140.5014170  1

When I create this new zoo object using the previous one (x) I don't get
exactly what I need..the traded rate is based on the lagged values,
rather than the present ones...

TradedRate - ifelse(abs(diff(x[,x.POS],lag= 1))0,ifelse(x[,x.POS]
!=1,-x[,x],x[,x]),NA) 
x - merge(x, TradedRate, all=TRUE)
x
x x.POS TradedRate
2003-02-01 -0.1858136 0 NA
2003-02-03 -1.3188533 0 NA
2003-02-07  0.2709794 0 NA
2003-02-09 -1.4915262 1 -0.2709794
2003-02-14  0.5014170 1 NA

The value for TradedRate on the 9th Feb should be -1.4945262 instead of
-0.2709794what am I doing wrong?

Thanks very much..
-- 
View this message in context: 
http://www.nabble.com/Using-diff%2C-ifelse-on-zoo-object-tp25852822p25852822.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] Vector Allocation -problem

2009-10-12 Thread premmad


When i tried running Zip-sqldf(select a.*,b.s_lv from Zip a inner join lin
b on a.S=B.S)
Error: cannot allocate vector of size 15.6 Mb
and with following warning
Warning messages:
1: In as.list.data.frame(X) :
  Reached total allocation of 1024Mb: see help(memory.size)
2: In as.list.data.frame(X) :
  Reached total allocation of 1024Mb: see help(memory.size)
3: In sqliteFetch(rs, n = -1, ...) :
  Reached total allocation of 1024Mb: see help(memory.size)
4: In sqliteFetch(rs, n = -1, ...) :
  Reached total allocation of 1024Mb: see help(memory.size)
5: In sqliteFetch(rs, n = -1, ...) :
  Reached total allocation of 1024Mb: see help(memory.size)
6: In sqliteFetch(rs, n = -1, ...) :
  Reached total allocation of 1024Mb: see help(memory.size)
7: In sqliteFetch(rs, n = -1, ...) :
  Reached total allocation of 1024Mb: see help(memory.size)
8: In sqliteFetch(rs, n = -1, ...) :
  Reached total allocation of 1024Mb: see help(memory.size)
9: In sqliteFetch(rs, n = -1, ...) :
  Reached total allocation of 1024Mb: see help(memory.size)
10: In sqliteFetch(rs, n = -1, ...) :
  Reached total allocation of 1024Mb: see help(memory.size)
11: In sqliteFetch(rs, n = -1, ...) :
  Reached total allocation of 1024Mb: see help(memory.size)
12: In sqliteFetch(rs, n = -1, ...) :
  Reached total allocation of 1024Mb: see help(memory.size)
 memory.size()
[1] 966.67
If i'm right the memory size shows 1Gb but it was not able to allocate
15mb.Help me to resolve this
-- 
View this message in context: 
http://www.nabble.com/Vector-Allocation--problem-tp25853258p25853258.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] tktext-window smaller than text

2009-10-12 Thread Anne Skoeries

Hi there,

I need to build up a  tktext-widget that contains a longer text than  
the tktext-widget actually is. So what I mean is, that the tktext  
window is of width=100 and the text in it has a length greater 100.  
But I don't want the window to just wrap the line, but to belong to  
scrollbar that is able to scroll to the end of the text.


tt - tktoplevel()
txt - tktext(tt, width=100, height=30)

scrergVert - tkscrollbar(tt, orient = vertical, repeatinterval = 1,  
command = function(...) tkyview(txt, ...))

tkconfigure(txt, yscrollcommand = function(...) tkset(scrergVert, ...))
scrergHor - tkscrollbar(tt, orient = horizontal, repeatinterval =  
1, command = function(...) tkxview(txt, ...))

tkconfigure(txt, xscrollcommand = function(...) tkset(scrergHor, ...))

tkgrid(txt, column=0, row=0, sticky=nwse)
tkgrid(scrergVert, column=1, row=0, sticky=ns)
tkgrid(scrergHor, column=0, row=1, sticky=we)

tkinsert(txt, 0.0, paste(capture.output(resultKmean), collapse=\n))

Trying the upper code would wrap the lines that are contain more than  
100 characters. How can I keep the size of the window, but make the  
text scrollable?


Thanks in advance,
--
Anne Skoeries

__
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] Ordinal response model

2009-10-12 Thread drlucyasher

I have been asked to analyse some questionnaire data- which is not data I'm
that used to dealing with. I'm hoping that I can make use of the nabble
expertise (again).

The questionnaire has a section which contains a particular issue and then
questions which are related to this issue (and potentially to each other):
1) importance of the issue (7 ordinal categories from -3 to +3)
2) impact of the impact (7 ordinal categroies from -3 to +3)
3) percentage affected by the issue (11 ordinal categories from 0, 0-10,
20-30, 30-40.90-100)
 
I also have three participant predictive factors:
Gender (M/F)
Age (continuous scale)
Sector (6 nominal categories)

So that my data looks like this:
genagesector impac importa percen
1 1 59  4 0  -3  2
2 2 64  3 2  -3  2
3 1 83  6 3  -3  2
4 1 66  5 2  -2  2
5 1 79  5 0  -1  2
6 2 63  4 0  -1  2

I have 2 questions I want my analysis to answer 
1) does gender/ age/ sector affect importance, impact, reponse
2) are importance/impact/response correlated in some way

I'm thinking I need some ordered logistic or probit model (possibly using
polr() command). The problem is the multivariate aspect- I need importance,
impact and perecentage in the same model to look at the covariance between
them and affects of gender, age and sector on these covariances.

It would be good to include a latent variable- at least for the perecentage
factor. 

Any help would be very much appreciated.
-- 
View this message in context: 
http://www.nabble.com/Ordinal-response-model-tp25856728p25856728.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 commander.

2009-10-12 Thread David Winsemius
You seem to have gotten an extraneous list item called Chromosome to  
which an empty string has been assigned. What happens if you issue  
this command:


ann2 - data.frame( Name=ann$Name, Position=ann$Position,  
Chr.num=factor(ann$Chr.num) )


(I took the liberty of making Chr.num into a factor.) And then print  
out smaller segments of ann2  (since what you have would take many  
hundreds of pages.


ann2[ , 1:60]


--
David

On Oct 12, 2009, at 2:29 AM, Ilyas . wrote:

i have two RData files,,i want to print them to check the format of  
the
tables in these files,,,i can load both the files and can read it as  
well



load('ann.RData')
str(ann)

List of 4
$ Name  : chr [1:561466] rs3094315 rs12562034 rs3934834
rs9442372 ...
$ Position  : int [1:561466] 742429 758311 995669 1008567 1011278  
1011521

1020428 1021403 1038818 1039813 ...
$ Chromosome: chr(0)
$ Chr.num   : num [1:561466] 1 1 1 1 1 1 1 1 1 1 ...

but when i try to display all the table by using the R commander.i  
have got
the display of 'pheno.RData' file,,but the other file 'ann.RData'  
show me an

error i.e.


ann - as.data.frame(ann)

Error in data.frame(Name = c(rs3094315, rs12562034, rs3934834,
rs9442372,  :
 arguments imply differing number of rows: 561466, 0



i am sending you both files,,,hope u will help me solve this  
problm



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


David Winsemius, MD
Heritage Laboratories
West Hartford, CT

__
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] field index given name.

2009-10-12 Thread William Dunlap
 -Original Message-
 From: r-help-boun...@r-project.org 
 [mailto:r-help-boun...@r-project.org] On Behalf Of tdm
 Sent: Monday, October 12, 2009 12:22 AM
 To: r-help@r-project.org
 Subject: Re: [R] field index given name.
 
 
 Thanks - would never have guessed that. I eventually got the 
 following to do
 what I want...
 
  colprob - array(dim=NCOL(iris))
  for(i in 1:NCOL(iris)){
 + colprob[i]=
 + ifelse(names(iris)[i] == 'Species',1,0.5)
 + }
  colprob
 [1] 0.5 0.5 0.5 0.5 1.0

I think a more direct way to do what that does
is to make vector with names, where the names
are the column names of 'iris' and then subscript
the vector by name instead of by number.   E.g.,

colprob - rep(0.5, length=ncol(iris)) # initialize probs
names(colprob) - colnames(iris) # initialize names
colprob[Species] - 1.0  # change prob for Species
colprob
   Sepal.Length  Sepal.Width Petal.Length  Petal.Width  Species 
0.5  0.5  0.5  0.5  1.0 
colprob[Sepal.Width] # example prob for Sepal.Width
   Sepal.Width 
   0.5

Bill Dunlap
Spotfire, TIBCO Software
wdunlap tibco.com 

 
 
 
 
 Schalk Heunis-2 wrote:
  
  Hi Phil
  Try the following
  which(names(iris)=='Species')
  [1] 5
  
  HTH
  Schalk Heunis
  
  On Mon, Oct 12, 2009 at 8:53 AM, tdm ph...@philbrierley.com wrote:
  
 
  Hi,
 
  How do I access the index number of a field given I only 
 know the field
  name?
 
  eg - I want to set the probability of the field 'species' 
 higher than the
  other fields to use in sampling.
 
   colprob - array(dim=NCOL(iris))
   for(i in 1:NCOL(iris)){colprob[i]=0.5}
   colprob[iris$species] = 1 #this doesn't work
   colprob
  [1] 0.5 0.5 0.5 0.5 0.5
 
 
 
 
 
  --
  View this message in context:
  
 http://www.nabble.com/field-index-given-name.-tp25851216p25851216.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.
 
  
  [[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/field-index-given-name.-tp25851216p25851466.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.


[R] xyplot does not find variable in data

2009-10-12 Thread Jacob Wegelin
When we call a lattice function such as xyplot, to what extent does
the data designation cause the function to look inside the data
for variables?

In the examples below, the subset argument understands that
Variety is a variable in the data.

But the scales argument does not understand that nitro is a
variable in the data.

What principle is at work?


library(MEMSS)

# The following works fine:

xyplot(
yield ~ nitro
, data=Oats
, scales=list(
x=list(
at=unique(Oats$nitro)
)
)
, subset=Variety==Victory
)

# But the following returns an error:

xyplot(
yield ~ nitro
, data=Oats
, scales=list(
x=list(
at=unique(nitro)
)
)
)

Thanks for any insight

Jacob A. Wegelin
Assistant Professor
Department of Biostatistics
Virginia Commonwealth University
730 East Broad Street Room 3006
P. O. Box 980032
Richmond VA 23298-0032
U.S.A.
E-mail: jwege...@vcu.edu
URL: http://www.people.vcu.edu/~jwegelin

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] combining/overlaying boxplot and barplot

2009-10-12 Thread Soenario, Ivan (KNMI)
Dear all,

I would like to visualise when days are rainy or dry in bar/boxplots.

Therefore I've tried to combine raingauge data (boxplots) and percentage
of raingauges with 0mm measurements (barplot). See attachment
mei2004.pdf (if it came through).

I've come this far:
barplot(dcp0[monthindex], col=gray, border=NA, axes=F)
boxplot(t(dcpn[monthindex,]), names=dates$day[monthindex], main=month,
outline=F, add=T, ylim=c(0,30), col=lightblue)

Both plots use different x-axis spacing, so May 31 of the barplot
extents further to the right than May 31 boxplot.

So, how do I get the x-axis of both plots aligned?? I've looked at par()
but can't see any parameters for plot size. Only for inner and outer
margins.

The strange thing is, when I plot the boxplot (add=F), it uses more
x-axis space (on the same device), the graph becomes wider (with add=T,
it does seem to take the numbers from the barplot in to account).

Thanks for the help!

Ivan Soenario
KNMI
Royal Netherlands Meteorological Institute


ps
dcpn: data.frame containing raingauge data for 310 stations (columns)
for 1991-2006 (each day is a row)
dcp0: calculation of % 0mm, based on dcpn.
monthindex: array with rownumbers, in this case representing month May
in 2004 (so length(monthindex) is 31)

ps 2
I cheated with percentage, I multiplied the fraction (number of
0mm)/(total number raingauges) with 30, to make it fit with the
boxplot's ylim of 30. It seldomly rains more than 30mm in 24hours.
To overcome this, I'd need to draw the barplot with it's own y-axis,
and, the boxplot shouldn't notice/use the ylim from the barplot.
__
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] spectral analysis

2009-10-12 Thread David Winsemius


On Oct 12, 2009, at 5:24 AM, sdlywjl666 wrote:


Dear all£¬
   Is there some functions to estimate the spectrum by the fft of  
autocorrelation?


The blindingly obvious search terms: fft spectrum  
autocorrelation   ... in two hops to what appears to be a function to  
this:


Auto And/Or Cross Correlations via FFT:
http://finzi.psych.upenn.edu/R/library/timsac/html/fftcor.html


Is there Parzen's lag window in R ?


Ditto for the search terms: Parzen window

http://finzi.psych.upenn.edu/R/library/sapa/html/SDF.html
http://finzi.psych.upenn.edu/R/library/cyclones/html/filters.html

and perhaps:
http://finzi.psych.upenn.edu/R/library/fracdiff/html/fdSperio.html

R-search is your friend:(Not to mention a Posting-Guide- 
recommended step before posting.)


http://search.r-project.org/nmz.html



--


David Winsemius, MD
Heritage Laboratories
West Hartford, CT

__
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 with the use of mtext to create main title over multiple plots

2009-10-12 Thread Mark Kimpel
I'm trying to use mtext to create a main title over multiple plots. Below is
a simple self-contained example and my sessionInfo (I should note I've also
tried this with R-2.8.1 with the same results). When I execute the code
chunk below, I get the plots, but no title. I've tried this using the screen
driver, pdf, and postscript. I've used different sizes of paper. I suspect I
am making an elementary error but searching the help files and help archives
hasn't provided me an answer.

Thanks for any help, Mark

#
setwd(~/Desktop)
pdf(my.test.plots.pdf, paper = letter)
par(mfrow=c(2,2))
for (i in 1:4){
  plot(1:6, 1:6)
}
mtext(text = my test plots, side = 3, outer = TRUE)
dev.off()
#

R version 2.10.0 Under development (unstable) (2009-09-21 r49771)
x86_64-unknown-linux-gnu

locale:
 [1] LC_CTYPE=en_US.UTF-8   LC_NUMERIC=C
 [3] LC_TIME=en_US.UTF-8LC_COLLATE=en_US.UTF-8
 [5] LC_MONETARY=C  LC_MESSAGES=en_US.UTF-8
 [7] LC_PAPER=en_US.UTF-8   LC_NAME=C
 [9] LC_ADDRESS=C   LC_TELEPHONE=C
[11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C

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

other attached packages:
[1] car_1.2-15

loaded via a namespace (and not attached):
[1] tools_2.10.0

Mark W. Kimpel MD  ** Neuroinformatics ** Dept. of Psychiatry
Indiana University School of Medicine

15032 Hunter Court, Westfield, IN  46074

(317) 490-5129 Work,  Mobile  VoiceMail
(317) 399-1219 Skype No Voicemail please

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] help with the use of mtext to create main title over multiple plots

2009-10-12 Thread Tony Plate

Try playing around with the oma setting in par() -- it sets the outer 
margins, which by default are zero.

The following shows the mtext label for me, using the windows device:


par(mfrow=c(2,2))
par(oma)

[1] 0 0 0 0

par(oma=c(0,0,2,0))
for (i in 1:4) plot(0:1,0:1)
mtext(text = my test plots, side = 3, outer = TRUE)



Mark Kimpel wrote:

I'm trying to use mtext to create a main title over multiple plots. Below is
a simple self-contained example and my sessionInfo (I should note I've also
tried this with R-2.8.1 with the same results). When I execute the code
chunk below, I get the plots, but no title. I've tried this using the screen
driver, pdf, and postscript. I've used different sizes of paper. I suspect I
am making an elementary error but searching the help files and help archives
hasn't provided me an answer.

Thanks for any help, Mark

#
setwd(~/Desktop)
pdf(my.test.plots.pdf, paper = letter)
par(mfrow=c(2,2))
for (i in 1:4){
  plot(1:6, 1:6)
}
mtext(text = my test plots, side = 3, outer = TRUE)
dev.off()
#

R version 2.10.0 Under development (unstable) (2009-09-21 r49771)
x86_64-unknown-linux-gnu

locale:
 [1] LC_CTYPE=en_US.UTF-8   LC_NUMERIC=C
 [3] LC_TIME=en_US.UTF-8LC_COLLATE=en_US.UTF-8
 [5] LC_MONETARY=C  LC_MESSAGES=en_US.UTF-8
 [7] LC_PAPER=en_US.UTF-8   LC_NAME=C
 [9] LC_ADDRESS=C   LC_TELEPHONE=C
[11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C

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

other attached packages:
[1] car_1.2-15

loaded via a namespace (and not attached):
[1] tools_2.10.0

Mark W. Kimpel MD  ** Neuroinformatics ** Dept. of Psychiatry
Indiana University School of Medicine

15032 Hunter Court, Westfield, IN  46074

(317) 490-5129 Work,  Mobile  VoiceMail
(317) 399-1219 Skype No Voicemail please

[[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] help with the use of mtext to create main title over multiple plots

2009-10-12 Thread David Winsemius


On Oct 12, 2009, at 1:41 PM, Tony Plate wrote:

Try playing around with the oma setting in par() -- it sets the  
outer margins, which by default are zero.


The following shows the mtext label for me, using the windows device:


par(mfrow=c(2,2))
par(oma)

[1] 0 0 0 0

par(oma=c(0,0,2,0))
for (i in 1:4) plot(0:1,0:1)
mtext(text = my test plots, side = 3, outer = TRUE)


Good advice. Works on a Mac, too:

setwd(~/Desktop)
pdf(my.test.plots.pdf, paper = letter)
opar - par(mfrow=c(2,2), oma=c(0,0,2,0))
for (i in 1:4){
 plot(1:6, 1:6);
}
mtext(text = my test plots, side = 3, outer = TRUE)
dev.off(); par(opar)






Mark Kimpel wrote:
I'm trying to use mtext to create a main title over multiple plots.  
Below is
a simple self-contained example and my sessionInfo (I should note  
I've also
tried this with R-2.8.1 with the same results). When I execute the  
code
chunk below, I get the plots, but no title. I've tried this using  
the screen
driver, pdf, and postscript. I've used different sizes of paper. I  
suspect I
am making an elementary error but searching the help files and help  
archives

hasn't provided me an answer.
Thanks for any help, Mark
#
setwd(~/Desktop)
pdf(my.test.plots.pdf, paper = letter)
par(mfrow=c(2,2))
for (i in 1:4){
 plot(1:6, 1:6)
}
mtext(text = my test plots, side = 3, outer = TRUE)
dev.off()
#
R version 2.10.0 Under development (unstable) (2009-09-21 r49771)
x86_64-unknown-linux-gnu
locale:
[1] LC_CTYPE=en_US.UTF-8   LC_NUMERIC=C
[3] LC_TIME=en_US.UTF-8LC_COLLATE=en_US.UTF-8
[5] LC_MONETARY=C  LC_MESSAGES=en_US.UTF-8
[7] LC_PAPER=en_US.UTF-8   LC_NAME=C
[9] LC_ADDRESS=C   LC_TELEPHONE=C
[11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C
attached base packages:
[1] stats graphics  grDevices utils datasets  methods   base
other attached packages:
[1] car_1.2-15
loaded via a namespace (and not attached):
[1] tools_2.10.0
Mark W. Kimpel MD  ** Neuroinformatics ** Dept. of Psychiatry
Indiana University School of Medicine
15032 Hunter Court, Westfield, IN  46074
(317) 490-5129 Work,  Mobile  VoiceMail
(317) 399-1219 Skype No Voicemail please
[[alternative HTML version deleted]]
__

--




David Winsemius, MD
Heritage Laboratories
West Hartford, CT

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] help with the use of mtext to create main title over multiple plots

2009-10-12 Thread Dieter Menne



Mark Kimpel wrote:
 
 I'm trying to use mtext to create a main title over multiple plots. Below
 is
 a simple self-contained example and my sessionInfo (I should note I've
 also
 tried this with R-2.8.1 with the same results). When I execute the code
 
 ...
 
 
 

Thanks for your nice example showing the problem clearly. I normally prefer
to test these things in a window first, it's faster, though.

You had forgotten to give the poor graphics a bit of outer margin. If you
look carefully, you could have seen a few tail in the plot. The example
overreacts a bit, but you get the idea.
You might also reduce your plot margins a bit (see par) to avoid to large
empty space.

Dieter

par(mfrow=c(2,2),oma=c(10,10,10,10)
for (i in 1:4){
  plot(1:6, 1:6)
}
mtext(text = my test plots, side = 1, outer = TRUE)

-- 
View this message in context: 
http://www.nabble.com/help-with-the-use-of-mtext-to-create-main-title-over-multiple-plots-tp25859951p25860178.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] help with the use of mtext to create main title over multiple plots

2009-10-12 Thread Simon Bonner
Hey Mark,

The text is actually there -- I can just see the bottom of the 'y' and
the 'p' in my plotting window. You can move the text down (into the
plot) with the argument line. E.g.:

mtext(text = my test plots, side = 3, outer = TRUE, line=-2)

Hope that helps...

-  
Simon Bonner
Post-Doctoral Fellow
Department of Statistics, UBC

www.simon.bonners.ca


On Mon, 2009-10-12 at 13:29 -0400, Mark Kimpel wrote:
 mtext(text = my test plots, side = 3, outer = TRUE)

__
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] add lines() to 1st plot in layout() after calling 2nd plot()?

2009-10-12 Thread Greg Snow
Since you are using LaTeX, you might consider creating the plots all in 1 step, 
but use the tikzdevice,  this provides LaTeX (pgf) commands to create the plot 
that you can then insert LaTeX commands to built up the plot bit by bit.

You could also look at using the subplot function in the TeachingDemos package, 
start with a blank plot without margins, then use subplot in place of layout to 
position your graphs, the examples in the help file for subplot show how to add 
to the subplot after creating it.

Another option is to create a function that creates each whole plot, but with 
an argument and some if statements that will skip certain steps, then just do a 
for loop calling the functions to build the plots in pieces.  This means 
replotting from scratch each step, but save these as graphics files and it is 
not overly complex.

Hope this helps,

-- 
Gregory (Greg) L. Snow Ph.D.
Statistical Data Center
Intermountain Healthcare
greg.s...@imail.org
801.408.8111


 -Original Message-
 From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-
 project.org] On Behalf Of Marianne Promberger
 Sent: Saturday, October 03, 2009 1:15 PM
 To: r-help
 Subject: [R] add lines() to 1st plot in layout() after calling 2nd
 plot()?
 
 Dear R users,
 
 I create a graphic with two plots side by side using layout(), like
 this:
 
 layout(matrix(c(1,2),1))
 plot(1:10,main=left plot)
 lines(c(3:7,7:3),col=red)
 plot(10:1,main=right plot)
 
 The lines() obivously get added to the left plot plot.
 
 Now, I'm trying to write a function that builds up a plot bit by bit to
 then include it in a LaTeX presentation with overlays. I'm using
 dev.copy(), and it would make my life much easier (because in fact I
 call all sorts of additional axis() etc after plot) if I could call
 the above commands in this order:
 
 layout(matrix(c(1,2),1))
 plot(1:10,main=left plot)
 plot(10:1,main=right plot)
 lines(c(3:7,7:3),col=red)
 
 but of course now lines() gets added to the right plot. I
 
 Is there any way to make the lines() go to the fist plot (left plot)?
 
 Marianne
 
 --
 Marianne Promberger PhD, King's College London
 http://promberger.info
 R version 2.9.2 (2009-08-24)
 Ubuntu 9.04
 
 __
 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] Ordinal response model

2009-10-12 Thread Dieter Menne



drlucyasher wrote:
 
 
 The questionnaire has a section which contains a particular issue and then
 questions which are related to this issue (and potentially to each other):
 1) importance of the issue (7 ordinal categories from -3 to +3)
 2) impact of the impact (7 ordinal categroies from -3 to +3)
 3) percentage affected by the issue (11 ordinal categories from 0, 0-10,
 20-30, 30-40.90-100)
  
 I also have three participant predictive factors:
 Gender (M/F)
 Age (continuous scale)
 Sector (6 nominal categories)
 
 

Gender and Sector are clear; convert these to factors, preferably giving
them meaningful names (m/f, east, west), and everything will be treated
correctly by most r function. Age is also clear, leave as is.

There will be considerably discussion how to code the scores. If these are
not heavily skewed (all -3), in some fields it is accepted to treat these as
continuous. Frank Harrell would argue against it.

I have revised too many manuscripts in both directions, so my opinion
depends on the paper where you publish it.

Anyway, Frank Harrel's lrm in Design might give you a starter. There is also
a well-known book by him on the subject.

Dieter



-- 
View this message in context: 
http://www.nabble.com/Ordinal-response-model-tp25856728p25860439.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] add lines() to 1st plot in layout() after calling 2nd plot()?

2009-10-12 Thread Greg Snow
This only works if all the plots are the same size and the defaults are used 
for the margins.  Try it with different sized figure regions in layout, the 
added lines don't match at the end.

-- 
Gregory (Greg) L. Snow Ph.D.
Statistical Data Center
Intermountain Healthcare
greg.s...@imail.org
801.408.8111


 -Original Message-
 From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-
 project.org] On Behalf Of baptiste auguie
 Sent: Sunday, October 04, 2009 3:33 AM
 To: r-help
 Subject: Re: [R] add lines() to 1st plot in layout() after calling 2nd
 plot()?
 
 Hi,
 
 Try this,
 
 dev.new()
 layout(matrix(1:4,2, by=T))
 
 plot(1:10,main=top left plot)
 plot(1:10,main=top right plot)
 plot(1:10,main=bottom left plot)
 plot(1:10,main=bottom right plot)
 
 for (ii in 1:2){
 for (jj in 1:2){
 par(mfg=c(ii,jj))
 text(5,2, lab=paste(plot #:,ii,,,jj,sep=))
 }
 }
 par(mfg=c(1,1))
 lines(c(3:7,7:3),col=red)
 
 HTH,
 
 baptiste
 2009/10/4 Marianne Promberger marianne.promber...@kcl.ac.uk:
  Thanks for the quick reply. However ...
 
  David Winsemius dwinsem...@comcast.net 03-Oct-09 20:50:
  MP layout(matrix(c(1,2),1))
  MP plot(1:10,main=left plot)
  MP plot(10:1,main=right plot)
  MP lines(c(3:7,7:3),col=red)
  MP
  MP but of course now lines() gets added to the right plot. I
  MP
  MP Is there any way to make the lines() go to the fist plot (left
  MP plot)?
 
  If you look at layout's help page there appears to be a worked
 example
  of an even more complex task. The answer appears to be assingning
  numbers to regions and then inserting par(mar=  with an
 appropriately
  constructed destination arguments prior to each added piece.
 
  Sorry, but I fail to find the solution in the page returned by
  ?layout, assuming that's what you mean.
 
  Yes, the numbers in the matrix given to layout() give the order of
  where plots will be put, so
 
  layout(matrix(c(2,1),1))
 
  then
 
  plot(1:10,main=left plot)
  plot(10:1,main=right plot)
  lines(c(3:7,7:3),col=red)
 
  puts left plot on the right hand side and right plot on the
  left. But the lines() still go to the right plot plot (now on the
  left hand side) which gets called last.
 
  The par(mar ... of the scatterplot with marginal histograms example
  just set the margins of the histogram plots, then they get plotted to
  the region with the next number given in the layout() matrix.
 
  Maybe I'm missing something.
 
  Thanks,
 
  Marianne
 
 
  --
  David
 
  On Oct 3, 2009, at 3:15 PM, Marianne Promberger wrote:
 
  Dear R users,
 
  I create a graphic with two plots side by side using layout(), like
  this:
 
  layout(matrix(c(1,2),1))
  plot(1:10,main=left plot)
  lines(c(3:7,7:3),col=red)
  plot(10:1,main=right plot)
 
  The lines() obivously get added to the left plot plot.
 
  Now, I'm trying to write a function that builds up a plot bit by
 bit
  to
  then include it in a LaTeX presentation with overlays. I'm using
  dev.copy(), and it would make my life much easier (because in fact
 I
  call all sorts of additional axis() etc after plot) if I could call
  the above commands in this order:
 
  layout(matrix(c(1,2),1))
  plot(1:10,main=left plot)
  plot(10:1,main=right plot)
  lines(c(3:7,7:3),col=red)
 
  but of course now lines() gets added to the right plot. I
 
  Is there any way to make the lines() go to the fist plot (left
  plot)?
 
  Marianne
 
 
  David Winsemius, MD
  Heritage Laboratories
  West Hartford, CT
 
  __
  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.
 
  --
  Marianne Promberger PhD, King's College London
  http://promberger.info
  R version 2.9.2 (2009-08-24)
  Ubuntu 9.04
 
  __
  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-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] Speed up and limit memory usage of lm()

2009-10-12 Thread Dieter Menne



gauti wrote:
 
 
 I have been doing series of linear regression models lm(). In this case
 the execution time and memory usage becomes a huge issue. I have therefore
 been trying to speed the process and limit the memory usage. 
 
 

Have a look at package biglm.

Dieter


-- 
View this message in context: 
http://www.nabble.com/Speed-up-and-limit-memory-usage-of-lm%28%29-tp25858939p25860485.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] mkdir in R?

2009-10-12 Thread Peng Yu
Hi,

Besides calling shell command mkdir by system(), I'm wondering if
there is a buildin command in R to make a new directory.

Regards,
Peng

__
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] add lines() to 1st plot in layout() after calling 2nd plot()?

2009-10-12 Thread baptiste auguie
Interesting, I hadn't tried this but it probably explains why
navigation to different regions of a layout is neither documented nor
advisable.

Yet another alternative is to use Grid graphics. In particular,

1- lattice or ggplot2 provide ways to arrange several plots in a
rectangular layout, with several options to add output to a specific
panel (but they do require quite a different approach to the creation
of plots)

2- for simple enough plots (or for brave users) you could also use
low-level grid commands, and navigate to different viewports
arbitrarily placed on a page.

3- the gridBase package provides a way to combine (with some
limitations) the power of grid layouts and the output produced with
base graphics.

Best,

baptiste



2009/10/12 Greg Snow greg.s...@imail.org:
 This only works if all the plots are the same size and the defaults are used 
 for the margins.  Try it with different sized figure regions in layout, the 
 added lines don't match at the end.

 --
 Gregory (Greg) L. Snow Ph.D.
 Statistical Data Center
 Intermountain Healthcare
 greg.s...@imail.org
 801.408.8111


 -Original Message-
 From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-
 project.org] On Behalf Of baptiste auguie
 Sent: Sunday, October 04, 2009 3:33 AM
 To: r-help
 Subject: Re: [R] add lines() to 1st plot in layout() after calling 2nd
 plot()?

 Hi,

 Try this,

 dev.new()
 layout(matrix(1:4,2, by=T))

 plot(1:10,main=top left plot)
 plot(1:10,main=top right plot)
 plot(1:10,main=bottom left plot)
 plot(1:10,main=bottom right plot)

 for (ii in 1:2){
 for (jj in 1:2){
 par(mfg=c(ii,jj))
 text(5,2, lab=paste(plot #:,ii,,,jj,sep=))
 }
 }
 par(mfg=c(1,1))
 lines(c(3:7,7:3),col=red)

 HTH,

 baptiste
 2009/10/4 Marianne Promberger marianne.promber...@kcl.ac.uk:
  Thanks for the quick reply. However ...
 
  David Winsemius dwinsem...@comcast.net 03-Oct-09 20:50:
  MP layout(matrix(c(1,2),1))
  MP plot(1:10,main=left plot)
  MP plot(10:1,main=right plot)
  MP lines(c(3:7,7:3),col=red)
  MP
  MP but of course now lines() gets added to the right plot. I
  MP
  MP Is there any way to make the lines() go to the fist plot (left
  MP plot)?
 
  If you look at layout's help page there appears to be a worked
 example
  of an even more complex task. The answer appears to be assingning
  numbers to regions and then inserting par(mar=  with an
 appropriately
  constructed destination arguments prior to each added piece.
 
  Sorry, but I fail to find the solution in the page returned by
  ?layout, assuming that's what you mean.
 
  Yes, the numbers in the matrix given to layout() give the order of
  where plots will be put, so
 
  layout(matrix(c(2,1),1))
 
  then
 
  plot(1:10,main=left plot)
  plot(10:1,main=right plot)
  lines(c(3:7,7:3),col=red)
 
  puts left plot on the right hand side and right plot on the
  left. But the lines() still go to the right plot plot (now on the
  left hand side) which gets called last.
 
  The par(mar ... of the scatterplot with marginal histograms example
  just set the margins of the histogram plots, then they get plotted to
  the region with the next number given in the layout() matrix.
 
  Maybe I'm missing something.
 
  Thanks,
 
  Marianne
 
 
  --
  David
 
  On Oct 3, 2009, at 3:15 PM, Marianne Promberger wrote:
 
  Dear R users,
 
  I create a graphic with two plots side by side using layout(), like
  this:
 
  layout(matrix(c(1,2),1))
  plot(1:10,main=left plot)
  lines(c(3:7,7:3),col=red)
  plot(10:1,main=right plot)
 
  The lines() obivously get added to the left plot plot.
 
  Now, I'm trying to write a function that builds up a plot bit by
 bit
  to
  then include it in a LaTeX presentation with overlays. I'm using
  dev.copy(), and it would make my life much easier (because in fact
 I
  call all sorts of additional axis() etc after plot) if I could call
  the above commands in this order:
 
  layout(matrix(c(1,2),1))
  plot(1:10,main=left plot)
  plot(10:1,main=right plot)
  lines(c(3:7,7:3),col=red)
 
  but of course now lines() gets added to the right plot. I
 
  Is there any way to make the lines() go to the fist plot (left
  plot)?
 
  Marianne
 
 
  David Winsemius, MD
  Heritage Laboratories
  West Hartford, CT
 
  __
  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.
 
  --
  Marianne Promberger PhD, King's College London
  http://promberger.info
  R version 2.9.2 (2009-08-24)
  Ubuntu 9.04
 
  __
  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] xyplot does not find variable in data

2009-10-12 Thread Bert Gunter
Deepayan will correct me if I'm wrong, but I'm pretty sure that the answer
is that it looks in the frame in the data argument only for variables in the
formula argument. Note that the fact that it also works for the subset
argument is explicitly mentioned therein:

subset:  logical or integer indexing vector **(can be specified in terms of
variables in data). **

FWIW, I agree that this is not as clearly documented as I think it could be:
I kind of intuited it after a bunch of trial and error.

Bert Gunter
Genentech Nonclinical Biostatistics


 
 -Original Message-
From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On
Behalf Of Jacob Wegelin
Sent: Monday, October 12, 2009 9:33 AM
To: r-h...@stat.math.ethz.ch
Subject: [R] xyplot does not find variable in data

When we call a lattice function such as xyplot, to what extent does
the data designation cause the function to look inside the data
for variables?

In the examples below, the subset argument understands that
Variety is a variable in the data.

But the scales argument does not understand that nitro is a
variable in the data.

What principle is at work?


library(MEMSS)

# The following works fine:

xyplot(
yield ~ nitro
, data=Oats
, scales=list(
x=list(
at=unique(Oats$nitro)
)
)
, subset=Variety==Victory
)

# But the following returns an error:

xyplot(
yield ~ nitro
, data=Oats
, scales=list(
x=list(
at=unique(nitro)
)
)
)

Thanks for any insight

Jacob A. Wegelin
Assistant Professor
Department of Biostatistics
Virginia Commonwealth University
730 East Broad Street Room 3006
P. O. Box 980032
Richmond VA 23298-0032
U.S.A.
E-mail: jwege...@vcu.edu
URL: http://www.people.vcu.edu/~jwegelin

__
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] mkdir in R?

2009-10-12 Thread Erik Iverson
?dir.create

 -Original Message-
 From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org]
 On Behalf Of Peng Yu
 Sent: Monday, October 12, 2009 1:01 PM
 To: r-h...@stat.math.ethz.ch
 Subject: [R] mkdir in R?
 
 Hi,
 
 Besides calling shell command mkdir by system(), I'm wondering if
 there is a buildin command in R to make a new directory.
 
 Regards,
 Peng
 
 __
 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] mkdir in R?

2009-10-12 Thread Henrique Dallazuanna
Try dir.create

On Mon, Oct 12, 2009 at 3:00 PM, Peng Yu pengyu...@gmail.com wrote:
 Hi,

 Besides calling shell command mkdir by system(), I'm wondering if
 there is a buildin command in R to make a new directory.

 Regards,
 Peng

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




-- 
Henrique Dallazuanna
Curitiba-Paraná-Brasil
25° 25' 40 S 49° 16' 22 O

__
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] xyplot does not find variable in data

2009-10-12 Thread Deepayan Sarkar
On Mon, Oct 12, 2009 at 9:32 AM, Jacob Wegelin jacob.wege...@gmail.com wrote:
 When we call a lattice function such as xyplot, to what extent does
 the data designation cause the function to look inside the data
 for variables?

 In the examples below, the subset argument understands that
 Variety is a variable in the data.

 But the scales argument does not understand that nitro is a
 variable in the data.

 What principle is at work?

A strange one called standard non-standard evaluation; see

http://developer.r-project.org/nonstandard-eval.pdf

for a nice overview by Thomas Lumley.


?xyplot says:

data: For the ‘formula’ method, a data frame containing values (or
  more precisely, anything that is a valid ‘envir’ argument in
  ‘eval’, e.g. a list or an environment) for any variables in
  the formula, as well as ‘groups’ and ‘subset’ if applicable.
  If not found in ‘data’, or if ‘data’ is unspecified, the
  variables are looked for in the environment of the formula.
  For other methods (where ‘x’ is not a formula), ‘data’ is
  usually ignored, often with a warning.

so the non-standard evaluation only applies to 'groups' and 'subset'.
The list may be different for other functions, e.g., densityplot()
also evaluates 'weights' in 'data'.

-Deepayan

__
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] crosstabulation and unlist function

2009-10-12 Thread eugen pircalabelu
Hello R-users,

My toy example:
 aa-c(1:5)
 bb-c(NA,2,NA,4,5)
 cc-c(1,2,NA,4,NA)
 dd-c(A,B,B,A,C)
 df-data.frame(aa,bb,cc,dd=as.factor(dd))
 table(unlist(df[,1:3]))

Can anyone point me to what function let's me do a crosstabulation between   
table(unlist(df[,1:3])) and df$dd?
I want to find out when dd==A (or B, or C) how many times do the values 1, 2 
,3,..  appear in df[,1:3]? 
Thank you very much!

 Eugen Pircalabelu

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] help with the use of mtext to create main title over multiple plots

2009-10-12 Thread Mark Kimpel
Thanks Tony (and others). Setting oma corrects the problem. Mark
Mark W. Kimpel MD  ** Neuroinformatics ** Dept. of Psychiatry
Indiana University School of Medicine

15032 Hunter Court, Westfield, IN  46074

(317) 490-5129 Work,  Mobile  VoiceMail
(317) 399-1219 Skype No Voicemail please


On Mon, Oct 12, 2009 at 1:41 PM, Tony Plate tpl...@acm.org wrote:

 Try playing around with the oma setting in par() -- it sets the outer
 margins, which by default are zero.

 The following shows the mtext label for me, using the windows device:

  par(mfrow=c(2,2))
 par(oma)

 [1] 0 0 0 0

 par(oma=c(0,0,2,0))
 for (i in 1:4) plot(0:1,0:1)
 mtext(text = my test plots, side = 3, outer = TRUE)


 Mark Kimpel wrote:

 I'm trying to use mtext to create a main title over multiple plots. Below
 is
 a simple self-contained example and my sessionInfo (I should note I've
 also
 tried this with R-2.8.1 with the same results). When I execute the code
 chunk below, I get the plots, but no title. I've tried this using the
 screen
 driver, pdf, and postscript. I've used different sizes of paper. I suspect
 I
 am making an elementary error but searching the help files and help
 archives
 hasn't provided me an answer.

 Thanks for any help, Mark

 #
 setwd(~/Desktop)
 pdf(my.test.plots.pdf, paper = letter)
 par(mfrow=c(2,2))
 for (i in 1:4){
  plot(1:6, 1:6)
 }
 mtext(text = my test plots, side = 3, outer = TRUE)
 dev.off()
 #

 R version 2.10.0 Under development (unstable) (2009-09-21 r49771)
 x86_64-unknown-linux-gnu

 locale:
  [1] LC_CTYPE=en_US.UTF-8   LC_NUMERIC=C
  [3] LC_TIME=en_US.UTF-8LC_COLLATE=en_US.UTF-8
  [5] LC_MONETARY=C  LC_MESSAGES=en_US.UTF-8
  [7] LC_PAPER=en_US.UTF-8   LC_NAME=C
  [9] LC_ADDRESS=C   LC_TELEPHONE=C
 [11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C

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

 other attached packages:
 [1] car_1.2-15

 loaded via a namespace (and not attached):
 [1] tools_2.10.0

 Mark W. Kimpel MD  ** Neuroinformatics ** Dept. of Psychiatry
 Indiana University School of Medicine

 15032 Hunter Court, Westfield, IN  46074

 (317) 490-5129 Work,  Mobile  VoiceMail
 (317) 399-1219 Skype No Voicemail please

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


[R] Using tabs in output instead of spaces

2009-10-12 Thread ws
Is there a way to have xtabs and friends use tabs in their output to separate 
columns rather than spaces?  It would be great for importing into other 
software.

TIA!

__
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] Using tabs in output instead of spaces

2009-10-12 Thread Erik Iverson
?write.table is probably a good starting point. 

 -Original Message-
 From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org]
 On Behalf Of ws
 Sent: Monday, October 12, 2009 1:39 PM
 To: r-h...@stat.math.ethz.ch
 Subject: [R] Using tabs in output instead of spaces
 
 Is there a way to have xtabs and friends use tabs in their output to
 separate
 columns rather than spaces?  It would be great for importing into other
 software.
 
 TIA!
 
 __
 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] xyplot does not find variable in data

2009-10-12 Thread Romain Francois

On 10/12/2009 08:30 PM, Deepayan Sarkar wrote:

On Mon, Oct 12, 2009 at 9:32 AM, Jacob Wegelinjacob.wege...@gmail.com  wrote:

When we call a lattice function such as xyplot, to what extent does
the data designation cause the function to look inside the data
for variables?

In the examples below, the subset argument understands that
Variety is a variable in the data.

But the scales argument does not understand that nitro is a
variable in the data.

What principle is at work?


A strange one called standard non-standard evaluation; see

http://developer.r-project.org/nonstandard-eval.pdf

for a nice overview by Thomas Lumley.


?xyplot says:

 data: For the ‘formula’ method, a data frame containing values (or
   more precisely, anything that is a valid ‘envir’ argument in
   ‘eval’, e.g. a list or an environment) for any variables in
   the formula, as well as ‘groups’ and ‘subset’ if applicable.
   If not found in ‘data’, or if ‘data’ is unspecified, the
   variables are looked for in the environment of the formula.
   For other methods (where ‘x’ is not a formula), ‘data’ is
   usually ignored, often with a warning.

so the non-standard evaluation only applies to 'groups' and 'subset'.
The list may be different for other functions, e.g., densityplot()
also evaluates 'weights' in 'data'.

-Deepayan


In addition, you might want to use with, as in:

with( Oats, xyplot(
	yield ~ nitro,scales=list(x=list(at=unique(nitro))), 
subset=Variety==Victory

) )

Romain

--
Romain Francois
Professional R Enthusiast
+33(0) 6 28 91 30 30
http://romainfrancois.blog.free.fr
|- http://tr.im/BcPw : celebrating R commit #5
|- http://tr.im/ztCu : RGG #158:161: examples of package IDPmisc
`- http://tr.im/yw8E : New R package : sos

__
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] Using diff, ifelse on zoo object

2009-10-12 Thread Gabor Grothendieck
The problem is that ifelse does not work the way you might think (see
value section of ?ifelse) and basically should not be used with three
zoo objects unless the three arguments to ifelse have the same time
index.

We can get that effect by using na.pad = TRUE in your diff call:

   TradedRate - with(x, ifelse(abs(diff(x.POS, na.pad = TRUE))  0,
ifelse(x.POS != 1, -x, x), NA))

or alternately we can merge them together first:

   xm - merge(x, dif = abs(diff(x$x.POS)))
   TradedRate - with(xm, ifelse(dif  0, ifelse(x.POS != 1, -x, x), NA))

By the way, to ensure that your output is reproducible be sure to use
set.seed(...) before any call to a random number generator when
posting.


On Mon, Oct 12, 2009 at 5:30 AM, charliegenge charlie.ge...@sc.com wrote:

 Hi,

 I'm having an issue when using diff and ifelse on a zoo object.

 x.Date - as.Date(2003-02-01) + c(1, 3, 7, 9, 14) - 1
 x - zoo(rnorm(5), x.Date)
 x.POS - c(0,0,0,1,1)
 x- merge(x,x.POS)
 x
                        x         x.POS
 2003-02-01   -0.1858136     0
 2003-02-03   -1.3188533     0
 2003-02-07    0.2709794      0
 2003-02-09   -1.4915262     1
 2003-02-14    0.5014170      1

 When I create this new zoo object using the previous one (x) I don't get
 exactly what I need..the traded rate is based on the lagged values,
 rather than the present ones...

 TradedRate - ifelse(abs(diff(x[,x.POS],lag= 1))0,ifelse(x[,x.POS]
 !=1,-x[,x],x[,x]),NA)
 x - merge(x, TradedRate, all=TRUE)
 x
                    x x.POS TradedRate
 2003-02-01 -0.1858136     0         NA
 2003-02-03 -1.3188533     0         NA
 2003-02-07  0.2709794     0         NA
 2003-02-09 -1.4915262     1 -0.2709794
 2003-02-14  0.5014170     1         NA

 The value for TradedRate on the 9th Feb should be -1.4945262 instead of
 -0.2709794what am I doing wrong?

 Thanks very much..
 --
 View this message in context: 
 http://www.nabble.com/Using-diff%2C-ifelse-on-zoo-object-tp25852822p25852822.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.


[R] How to hide tick lines behind the box-and-whisker 's in a boxplot

2009-10-12 Thread Helmer Belbo
Dear R people,

I wonder how to hide tick lines behind other figures in a plot, e.g.
in a boxplot.

# Sample code:

x- c(rep(4,50),rep(5,20),rep(6,50),rnorm(20,5,1))
boxplot(x)
axis(2,tck=1,col.ticks='grey',lty=5 )

# end of sample code

The tick lines is put on top of the box-plot, but I would like to put
these lines behind the box and whiskers..

Regards
Helmer

__
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] Trendline for a subset of data

2009-10-12 Thread Greg Snow
Others have show how to use the segments function, but this can also be done 
using the original abline function along with the clip function.  Here is an 
example:

plot( iris$Petal.Width, iris$Petal.Length, 
col=c('red','green','blue')[iris$Species])

tmp - levels(iris$Species)
tmp2 - par('usr')

for(i in 1:3) {
fit - lm( Petal.Length ~ Petal.Width, data=iris, subset= 
Species==tmp[i] )
tmpx - with(iris, Petal.Width[ Species==tmp[i] ] )
clip( min(tmpx), max(tmpx), tmp2[3], tmp2[4] )
abline( fit, col=c('red','green','blue')[i] )
}


Hope this helps,

-- 
Gregory (Greg) L. Snow Ph.D.
Statistical Data Center
Intermountain Healthcare
greg.s...@imail.org
801.408.8111


 -Original Message-
 From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-
 project.org] On Behalf Of Steve Murray
 Sent: Friday, October 09, 2009 3:51 AM
 To: r-help@r-project.org
 Subject: [R] Trendline for a subset of data
 
 
 Dear all,
 
 I am using abline(lm ...) to insert a linear trendline through a
 portion of my data (e.g. dataset[,36:45]). However, I am finding that
 whilst the trendline is correctly displayed and representative of the
 data portion I've chosen, the line continues to run beyond this data
 segment and continues until it intersects the vertical axes at each
 side of the plot.
 
 How do I display the line so that it only runs between point 36 and 45
 (as shown in the example above) as doesn't continue to display a line
 throughout the rest of the plot space?
 
 Many thanks,
 
 Steve
 
 _
 View your other email accounts from your Hotmail inbox. Add them now.
 http://clk.atdmt.com/UKM/go/167688463/direct/01/
 __
 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] crosstabulation and unlist function

2009-10-12 Thread David Winsemius


On Oct 12, 2009, at 2:36 PM, eugen pircalabelu wrote:


Hello R-users,

My toy example:
aa-c(1:5)
bb-c(NA,2,NA,4,5)
cc-c(1,2,NA,4,NA)
dd-c(A,B,B,A,C)
df-data.frame(aa,bb,cc,dd=as.factor(dd))
table(unlist(df[,1:3]))

Can anyone point me to what function let's me do a crosstabulation  
between   table(unlist(df[,1:3])) and df$dd?
I want to find out when dd==A (or B, or C) how many times do the  
values 1, 2 ,3,..  appear in df[,1:3]?

Thank you very much!


One way would be to collect the row sums of those columns first, and  
then sum by index:


tapply(apply(df[,1:3],1,sum, na.rm=TRUE), df$dd, sum)
 A  B  C
14  9 10

--

David Winsemius, MD
Heritage Laboratories
West Hartford, CT

__
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] crosstabulation and unlist function

2009-10-12 Thread David Winsemius


On Oct 12, 2009, at 3:25 PM, David Winsemius wrote:



On Oct 12, 2009, at 2:36 PM, eugen pircalabelu wrote:


Hello R-users,

My toy example:
aa-c(1:5)
bb-c(NA,2,NA,4,5)
cc-c(1,2,NA,4,NA)
dd-c(A,B,B,A,C)
df-data.frame(aa,bb,cc,dd=as.factor(dd))
table(unlist(df[,1:3]))

Can anyone point me to what function let's me do a crosstabulation  
between   table(unlist(df[,1:3])) and df$dd?
I want to find out when dd==A (or B, or C) how many times do the  
values 1, 2 ,3,..  appear in df[,1:3]?

Thank you very much!


One way would be to collect the row sums of those columns first, and  
then sum by index:


tapply(apply(df[,1:3],1,sum, na.rm=TRUE), df$dd, sum)
A  B  C
14  9 10


This method is safer than working on table(unlist(df[, 1:3]) since it  
does not break when an entire row is empty.


 aa-c(1,2,NA,4,5)
 bb-c(NA,2,NA,4,5)
 cc-c(1,2,NA,4,NA)
 dd-c(A,B,B,A,C)
 df-data.frame(aa,bb,cc,dd=as.factor(dd))
 table(unlist(df[,1:3]))

1 2 4 5
2 3 3 2 # missing row willno longer be aligned with dd.
 tapply(table(unlist(df[,1:3])), df$dd, sum)
Error in tapply(table(unlist(df[, 1:3])), df$dd, sum) :
  arguments must have same length

 tapply(apply(df[,1:3],1,sum, na.rm=TRUE), df$dd, sum)
 A  B  C
14  6 10




--

David Winsemius, MD
Heritage Laboratories
West Hartford, CT

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


David Winsemius, MD
Heritage Laboratories
West Hartford, CT

__
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] crosstabulation and unlist function

2009-10-12 Thread eugen pircalabelu
Hello,
First of all, thank you David for your reply, but sadly this is not what i 
wanted (i am sorry for not being more specific about my problem!)
   
 aa-c(1:5)
 bb-c(NA,2,NA,4,5)
 cc-c(1,2,NA,4,NA)
 dd-c(A,B,B,A,C)
 table(unlist(df[,1:3]))

 df
  aa bb cc dd
1  1 NA  1  A
2  2  2  2  B
3  3 NA NA  B
4  4  4  4  A
5  5  5 NA  C

I do not want to get this:
 tapply(apply(df[,1:3],1,sum, na.rm=TRUE), df$dd, sum)
A  B  C
14  6 10

but a crosstabulation between  table(unlist(df[,1:3])) and df$dd, which should 
look something like this:

1   2   3   4  5
A  2   0   0   3  0
B  0   3   1   0  0
C  0   0   0   0  2

meaning that when dd is A 1 appears 2 times, 2 doesn't appear, 3 doesn't 
appear, 4 appears 3times, 5 doesn't appear; when dd is C only 5 appears 2 times 
(i am not really interested in the NA occurence).
Hopefully, this time my question was a lot more clear.
Thank you very much !

 

 




- Original Message 
From: David Winsemius dwinsem...@comcast.net
To: David Winsemius dwinsem...@comcast.net
Cc: eugen pircalabelu eugen_pircalab...@yahoo.com; R-help 
r-h...@stat.math.ethz.ch
Sent: Mon, October 12, 2009 9:36:39 PM
Subject: Re: [R] crosstabulation and unlist function


On Oct 12, 2009, at 3:25 PM, David Winsemius wrote:

 
 On Oct 12, 2009, at 2:36 PM, eugen pircalabelu wrote:
 
 Hello R-users,
 
 My toy example:
 aa-c(1:5)
 bb-c(NA,2,NA,4,5)
 cc-c(1,2,NA,4,NA)
 dd-c(A,B,B,A,C)
 df-data.frame(aa,bb,cc,dd=as.factor(dd))
 table(unlist(df[,1:3]))
 
 Can anyone point me to what function let's me do a crosstabulation between   
 table(unlist(df[,1:3])) and df$dd?
 I want to find out when dd==A (or B, or C) how many times do the values 1, 2 
 ,3,..  appear in df[,1:3]?
 Thank you very much!
 
 One way would be to collect the row sums of those columns first, and then sum 
 by index:
 
 tapply(apply(df[,1:3],1,sum, na.rm=TRUE), df$dd, sum)
 A  B  C
 14  9 10

This method is safer than working on table(unlist(df[, 1:3]) since it does not 
break when an entire row is empty.

 aa-c(1,2,NA,4,5)
 bb-c(NA,2,NA,4,5)
 cc-c(1,2,NA,4,NA)
 dd-c(A,B,B,A,C)
 df-data.frame(aa,bb,cc,dd=as.factor(dd))
 table(unlist(df[,1:3]))

1 2 4 5
2 3 3 2 # missing row willno longer be aligned with dd.
 tapply(table(unlist(df[,1:3])), df$dd, sum)
Error in tapply(table(unlist(df[, 1:3])), df$dd, sum) :
  arguments must have same length

 tapply(apply(df[,1:3],1,sum, na.rm=TRUE), df$dd, sum)
A  B  C
14  6 10


 
 --
 David Winsemius, MD
 Heritage Laboratories
 West Hartford, CT
 
 __
 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.

David Winsemius, MD
Heritage Laboratories
West Hartford, CT

__
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] Creating object referant from argument name

2009-10-12 Thread Maxwell Reback
Hi all. I'd like to define an object within a function based on an
argument to that function.
Specifically, I've got:

do.something-function(input){
id-substring(input,3,3)
j-list1
if(id==2)j-list2
if(id==3)j-list3
if(id==4)j-list4
...}

Instead of all these if() arguments, I was hoping to use something like:
j-paste(list,substring(input,3,3),sep=)
but this just assigns j the value of listx of _character_ mode,
instead of the actual object 'listx'.
Is there any way to get around this?
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] xyplot does not find variable in data

2009-10-12 Thread Bert Gunter
 What principle is at work?

 A strange one called standard non-standard evaluation; see

 http://developer.r-project.org/nonstandard-eval.pdf

 for a nice overview by Thomas Lumley.


 ?xyplot says:

  data: For the 'formula' method, a data frame containing values (or
more precisely, anything that is a valid 'envir' argument in
'eval', e.g. a list or an environment) for any variables in
the formula, as well as 'groups' and 'subset' if applicable.
If not found in 'data', or if 'data' is unspecified, the
variables are looked for in the environment of the formula.
For other methods (where 'x' is not a formula), 'data' is
usually ignored, often with a warning.

 so the non-standard evaluation only applies to 'groups' and 'subset'.
 The list may be different for other functions, e.g., densityplot()
 also evaluates 'weights' in 'data'.

 -Deepayan

In addition, you might want to use with, as in:

with( Oats, xyplot(
yield ~ nitro,scales=list(x=list(at=unique(nitro))), 
subset=Variety==Victory
) )

Romain

-- which standardizes the standard non-standardized evaluation I guess  :-).

  Bert

__
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] Creating object referant from argument name

2009-10-12 Thread Rolf Turner


On 13/10/2009, at 9:14 AM, Maxwell Reback wrote:


Hi all. I'd like to define an object within a function based on an
argument to that function.
Specifically, I've got:

do.something-function(input){
id-substring(input,3,3)
j-list1
if(id==2)j-list2
if(id==3)j-list3
if(id==4)j-list4
...}

Instead of all these if() arguments, I was hoping to use something  
like:

j-paste(list,substring(input,3,3),sep=)
but this just assigns j the value of listx of _character_ mode,
instead of the actual object 'listx'.
Is there any way to get around this?
Thanks.


?get

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] Creating object referant from argument name

2009-10-12 Thread jim holtman
try this:  (?get)

j- get(paste(list,substring(input,3,3),sep=))

On Mon, Oct 12, 2009 at 4:14 PM, Maxwell Reback mreb...@gmail.com wrote:
 Hi all. I'd like to define an object within a function based on an
 argument to that function.
 Specifically, I've got:

 do.something-function(input){
 id-substring(input,3,3)
 j-list1
 if(id==2)j-list2
 if(id==3)j-list3
 if(id==4)j-list4
 ...}

 Instead of all these if() arguments, I was hoping to use something like:
 j-paste(list,substring(input,3,3),sep=)
 but this just assigns j the value of listx of _character_ mode,
 instead of the actual object 'listx'.
 Is there any way to get around this?
 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.




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

What is the problem that 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] crosstabulation and unlist function

2009-10-12 Thread rmailbox

What you're really saying is that you don't care about the distinction between 
aa, bb and cc. In that case, a different arrangement of the data will be 
more useful:

library (reshape )
df.melt - melt ( df, id.var = dd)
with ( df.melt, table ( dd, value ) ) 

Eric


- Original message -
From: eugen pircalabelu eugen_pircalab...@yahoo.com
To: David Winsemius dwinsem...@comcast.net
Cc: R-help r-h...@stat.math.ethz.ch
Date: Mon, 12 Oct 2009 13:05:33 -0700 (PDT)
Subject: Re: [R] crosstabulation and unlist function

Hello,
First of all, thank you David for your reply, but sadly this is not what i 
wanted (i am sorry for not being more specific about my problem!)
   
 aa-c(1:5)
 bb-c(NA,2,NA,4,5)
 cc-c(1,2,NA,4,NA)
 dd-c(A,B,B,A,C)
 table(unlist(df[,1:3]))

 df
  aa bb cc dd
1  1 NA  1  A
2  2  2  2  B
3  3 NA NA  B
4  4  4  4  A
5  5  5 NA  C

I do not want to get this:
 tapply(apply(df[,1:3],1,sum, na.rm=TRUE), df$dd, sum)
A  B  C
14  6 10

but a crosstabulation between  table(unlist(df[,1:3])) and df$dd, which should 
look something like this:

1   2   3   4  5
A  2   0   0   3  0
B  0   3   1   0  0
C  0   0   0   0  2

meaning that when dd is A 1 appears 2 times, 2 doesn't appear, 3 doesn't 
appear, 4 appears 3times, 5 doesn't appear; when dd is C only 5 appears 2 times 
(i am not really interested in the NA occurence).
Hopefully, this time my question was a lot more clear.
Thank you very much !

 

 




- Original Message 
From: David Winsemius dwinsem...@comcast.net
To: David Winsemius dwinsem...@comcast.net
Cc: eugen pircalabelu eugen_pircalab...@yahoo.com; R-help 
r-h...@stat.math.ethz.ch
Sent: Mon, October 12, 2009 9:36:39 PM
Subject: Re: [R] crosstabulation and unlist function


On Oct 12, 2009, at 3:25 PM, David Winsemius wrote:

 
 On Oct 12, 2009, at 2:36 PM, eugen pircalabelu wrote:
 
 Hello R-users,
 
 My toy example:
 aa-c(1:5)
 bb-c(NA,2,NA,4,5)
 cc-c(1,2,NA,4,NA)
 dd-c(A,B,B,A,C)
 df-data.frame(aa,bb,cc,dd=as.factor(dd))
 table(unlist(df[,1:3]))
 
 Can anyone point me to what function let's me do a crosstabulation between   
 table(unlist(df[,1:3])) and df$dd?
 I want to find out when dd==A (or B, or C) how many times do the values 1, 2 
 ,3,..  appear in df[,1:3]?
 Thank you very much!
 
 One way would be to collect the row sums of those columns first, and then sum 
 by index:
 
 tapply(apply(df[,1:3],1,sum, na.rm=TRUE), df$dd, sum)
 A  B  C
 14  9 10

This method is safer than working on table(unlist(df[, 1:3]) since it does not 
break when an entire row is empty.

 aa-c(1,2,NA,4,5)
 bb-c(NA,2,NA,4,5)
 cc-c(1,2,NA,4,NA)
 dd-c(A,B,B,A,C)
 df-data.frame(aa,bb,cc,dd=as.factor(dd))
 table(unlist(df[,1:3]))

1 2 4 5
2 3 3 2 # missing row willno longer be aligned with dd.
 tapply(table(unlist(df[,1:3])), df$dd, sum)
Error in tapply(table(unlist(df[, 1:3])), df$dd, sum) :
  arguments must have same length

 tapply(apply(df[,1:3],1,sum, na.rm=TRUE), df$dd, sum)
A  B  C
14  6 10


 
 --
 David Winsemius, MD
 Heritage Laboratories
 West Hartford, CT
 
 __
 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.

David Winsemius, MD
Heritage Laboratories
West Hartford, CT

__
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] crosstabulation and unlist function

2009-10-12 Thread William Dunlap
 -Original Message-
 From: r-help-boun...@r-project.org 
 [mailto:r-help-boun...@r-project.org] On Behalf Of eugen pircalabelu
 Sent: Monday, October 12, 2009 1:06 PM
 To: David Winsemius
 Cc: R-help
 Subject: Re: [R] crosstabulation and unlist function
 
 Hello,
 First of all, thank you David for your reply, but sadly this 
 is not what i wanted (i am sorry for not being more specific 
 about my problem!)

  aa-c(1:5)
  bb-c(NA,2,NA,4,5)
  cc-c(1,2,NA,4,NA)
  dd-c(A,B,B,A,C)

You forget to say how you made 'df', which I assume is
   df - data.frame(aa,bb,cc,dd)
Having a self-contained way to reproduce your problem
makes much easier to solve!

  table(unlist(df[,1:3]))
 
  df
   aa bb cc dd
 1  1 NA  1  A
 2  2  2  2  B
 3  3 NA NA  B
 4  4  4  4  A
 5  5  5 NA  C
 
 I do not want to get this:
  tapply(apply(df[,1:3],1,sum, na.rm=TRUE), df$dd, sum)
 A  B  C
 14  6 10
 
 but a crosstabulation between  table(unlist(df[,1:3])) and 
 df$dd, which should look something like this:
 
 1   2   3   4  5
 A  2   0   0   3  0
 B  0   3   1   0  0
 C  0   0   0   0  2

Try

  with(df, table(rep(dd,3), c(aa,bb,cc)))

1 2 3 4 5
  A 2 0 0 3 0
  B 0 3 1 0 0
  C 0 0 0 0 2
or
 table(rep(df$dd, 3), unlist(df[,1:3]))

1 2 3 4 5
  A 2 0 0 3 0
  B 0 3 1 0 0
  C 0 0 0 0 2

You need the rep() to show how the 5 elements of dd
should correspond to the 15 elements of aa, bb, and cc.

Bill Dunlap
Spotfire, TIBCO Software
wdunlap tibco.com  

 
 meaning that when dd is A 1 appears 2 times, 2 doesn't 
 appear, 3 doesn't appear, 4 appears 3times, 5 doesn't appear; 
 when dd is C only 5 appears 2 times (i am not really 
 interested in the NA occurence).
 Hopefully, this time my question was a lot more clear.
 Thank you very much !
 
  
 
  
 
 
 
 
 - Original Message 
 From: David Winsemius dwinsem...@comcast.net
 To: David Winsemius dwinsem...@comcast.net
 Cc: eugen pircalabelu eugen_pircalab...@yahoo.com; R-help 
 r-h...@stat.math.ethz.ch
 Sent: Mon, October 12, 2009 9:36:39 PM
 Subject: Re: [R] crosstabulation and unlist function
 
 
 On Oct 12, 2009, at 3:25 PM, David Winsemius wrote:
 
  
  On Oct 12, 2009, at 2:36 PM, eugen pircalabelu wrote:
  
  Hello R-users,
  
  My toy example:
  aa-c(1:5)
  bb-c(NA,2,NA,4,5)
  cc-c(1,2,NA,4,NA)
  dd-c(A,B,B,A,C)
  df-data.frame(aa,bb,cc,dd=as.factor(dd))
  table(unlist(df[,1:3]))
  
  Can anyone point me to what function let's me do a 
 crosstabulation between   table(unlist(df[,1:3])) and df$dd?
  I want to find out when dd==A (or B, or C) how many times 
 do the values 1, 2 ,3,..  appear in df[,1:3]?
  Thank you very much!
  
  One way would be to collect the row sums of those columns 
 first, and then sum by index:
  
  tapply(apply(df[,1:3],1,sum, na.rm=TRUE), df$dd, sum)
  A  B  C
  14  9 10
 
 This method is safer than working on table(unlist(df[, 1:3]) 
 since it does not break when an entire row is empty.
 
  aa-c(1,2,NA,4,5)
  bb-c(NA,2,NA,4,5)
  cc-c(1,2,NA,4,NA)
  dd-c(A,B,B,A,C)
  df-data.frame(aa,bb,cc,dd=as.factor(dd))
  table(unlist(df[,1:3]))
 
 1 2 4 5
 2 3 3 2 # missing row willno longer be aligned with dd.
  tapply(table(unlist(df[,1:3])), df$dd, sum)
 Error in tapply(table(unlist(df[, 1:3])), df$dd, sum) :
   arguments must have same length
 
  tapply(apply(df[,1:3],1,sum, na.rm=TRUE), df$dd, sum)
 A  B  C
 14  6 10
 
 
  
  --
  David Winsemius, MD
  Heritage Laboratories
  West Hartford, CT
  
  __
  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.
 
 David Winsemius, MD
 Heritage Laboratories
 West Hartford, CT
 
 __
 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] how to plot a data by different group

2009-10-12 Thread Ista Zahn
Hi Catherine,
Assuming your variables are in a dataframe called myData, some
variation of the following may be what you want:

library(ggplot2)
myData.m - melt(myData, measure.vars=c(Y1, Y2))
qplot(X, value, colour=variable, shape=groupf3,
facets=groupf1~groupf2, geom=point, data=myData.m)

-Ista

On Mon, Oct 12, 2009 at 4:36 PM, catherineLF cath...@hotmail.com wrote:

 Dear everyone,
 sorry to bother you. I have a big data, suppose it has 200 groups and each
 group has 100 data. So the data have 2 observations in total. The
 variables are
 groupf1  groupf2 groupf3  X  Y1  Y2
 1                 1            1   1 0.5  0.5

 
 groupf1, groupf2 and groupf3 are defining the 200 groups.

 I want to make 200 graphs for each group. For each group, graph Y1 and Y2 vs
 X.
 Is there any easy way to do that?

 Thank you very much for your help!
 Catherine
 --
 View this message in context: 
 http://www.nabble.com/how-to-plot-a-data-by-different-group-tp25862739p25862739.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.




-- 
Ista Zahn
Graduate student
University of Rochester
Department of Clinical and Social Psychology
http://yourpsyche.org

__
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] lapply / mapply and assignments

2009-10-12 Thread Magnus Torfason
I have a list of isometric structures, and I want to change the same 
part of each structure in the list, assigning one element of a vector to 
each of these parts.


In other words, I want to achieve the following:

 l - list( list(a=1,b=2), list(a=3,b=4))
 unlist(lapply(l, [[, a))
[1] 1 3

 # This will not actually work
 l[[]][a] - 5:6

 unlist(lapply(l, [[, a))
[1] 5 6

I figure mapply is the solution to the problem, and I tried the following:

 mapply( [-, l, a, 5:6)

But the result is not the same shape as the original.

Any thoughts?

Best,
Magnus

__
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] lapply / mapply and assignments

2009-10-12 Thread Charles C. Berry

On Mon, 12 Oct 2009, Magnus Torfason wrote:

I have a list of isometric structures, and I want to change the same part of 
each structure in the list, assigning one element of a vector to each of 
these parts.


In other words, I want to achieve the following:


 l - list( list(a=1,b=2), list(a=3,b=4))
 unlist(lapply(l, [[, a))

[1] 1 3


 # This will not actually work
 l[[]][a] - 5:6

 unlist(lapply(l, [[, a))

[1] 5 6

I figure mapply is the solution to the problem, and I tried the following:


 mapply( [-, l, a, 5:6)


But the result is not the same shape as the original.

Any thoughts?


See

?relist

something like:

relist( unlist( mapply( [-, l, a, 5:6) ), l )


HTH,

Chuck



Best,
Magnus

__
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:cbe...@tajo.ucsd.edu   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] lapply / mapply and assignments

2009-10-12 Thread Charles C. Berry


Hmmm, after thinking about it, better see

?mapply

SIMPLIFY logical; attempt to reduce the result to a vector or
matrix?


Try mapply( ..., SIMPLIFY=FALSE )

HTH,

Chuck

On Mon, 12 Oct 2009, Magnus Torfason wrote:

I have a list of isometric structures, and I want to change the same part of 
each structure in the list, assigning one element of a vector to each of 
these parts.


In other words, I want to achieve the following:


 l - list( list(a=1,b=2), list(a=3,b=4))
 unlist(lapply(l, [[, a))

[1] 1 3


 # This will not actually work
 l[[]][a] - 5:6

 unlist(lapply(l, [[, a))

[1] 5 6

I figure mapply is the solution to the problem, and I tried the following:


 mapply( [-, l, a, 5:6)


But the result is not the same shape as the original.

Any thoughts?

Best,
Magnus

__
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:cbe...@tajo.ucsd.edu   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] lapply / mapply and assignments

2009-10-12 Thread Gabor Grothendieck
Try:  mapply(..., SIMPLIFY = FALSE)

On Mon, Oct 12, 2009 at 5:25 PM, Magnus Torfason zulutime@gmail.com wrote:
 I have a list of isometric structures, and I want to change the same part of
 each structure in the list, assigning one element of a vector to each of
 these parts.

 In other words, I want to achieve the following:

 l - list( list(a=1,b=2), list(a=3,b=4))
 unlist(lapply(l, [[, a))
 [1] 1 3

 # This will not actually work
 l[[]][a] - 5:6

 unlist(lapply(l, [[, a))
 [1] 5 6

 I figure mapply is the solution to the problem, and I tried the following:

 mapply( [-, l, a, 5:6)

 But the result is not the same shape as the original.

 Any thoughts?

 Best,
 Magnus

 __
 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] xyplot does not find variable in data

2009-10-12 Thread Peter Ehlers

One other way that is sometimes useful is to use the
tick.number argument as in:

 xyplot(yield ~ nitro, data=Oats,
   scales=list(x=list(tick.number=4)), subset=Variety==Victory
 )

This is especially handy if you want to just tick/label
every other value.

 -Peter Ehlers

Jacob Wegelin wrote:

When we call a lattice function such as xyplot, to what extent does
the data designation cause the function to look inside the data
for variables?

In the examples below, the subset argument understands that
Variety is a variable in the data.

But the scales argument does not understand that nitro is a
variable in the data.

What principle is at work?


library(MEMSS)

# The following works fine:

xyplot(
yield ~ nitro
, data=Oats
, scales=list(
x=list(
at=unique(Oats$nitro)
)
)
, subset=Variety==Victory
)

# But the following returns an error:

xyplot(
yield ~ nitro
, data=Oats
, scales=list(
x=list(
at=unique(nitro)
)
)
)

Thanks for any insight

Jacob A. Wegelin
Assistant Professor
Department of Biostatistics
Virginia Commonwealth University
730 East Broad Street Room 3006
P. O. Box 980032
Richmond VA 23298-0032
U.S.A.
E-mail: jwege...@vcu.edu
URL: http://www.people.vcu.edu/~jwegelin

__
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] how to output profile plots for groups using lattice package

2009-10-12 Thread Peter Ehlers

Hi George,

Your problem is not with xyplot, but with the NA occurrences in
your data. Try adding

  subset = {!is.na(MSE)},

to your xyplot call, or (better), subset the data before
calling xyplot.

 -Peter Ehlers

George Kalema wrote:

Hi Peter (and anyone else willing to help me out),
Many thanks for your help. Having used your code plus a few other
modifications, I only get the points plotted but without the two lines. I
just cannot figure out what the problem is.

My code is as follows:

library(lattice)
datos2 - subset(datos, samplesize != 10  parm != Theta0)
unq - sort(unique(datos2$samplesize))
datos2$fsamplesize - factor(datos2$samplesize, labels = paste(Sample
size =, unq))
datos2$parm - factor(datos2$parm, levels = c(Intercept, time,
trt, time*trt))
tp1.sim - xyplot(MSE ~ ntimes | fsamplesize + parm, group = group, data
= datos2,
type = b, lty = 1:2, pch = 1:2,
scales = list(x = list(at = c(2, 4, 8, 16)), alternating = 1),
as.table = TRUE, key = list(text = list(c(GNA, PNA)), points =
list(pch = 1:2))
)
plot(tp1.sim)

I have attached my real dataset (called datos) as well.

Kind appreciations to your efforts.

George


On Wed, Oct 7, 2009 at 9:20 AM, Peter Ehlers ehl...@ucalgary.ca wrote:


see below

George Kalema wrote:


Dear R users,
I am trying to have an xyplot of a data set which has the following
variables:
case (n=10,20,30)
parameter (parm=a,b)
group (grp=g1,g2)
y (y values)
x (x=2,4,8)

My plot should be parameter by case such that I have 2 rows (each row=
each
parameter) and 3 columns (each column=each case). My R-code is as follows
but I am not able to get what I want to:

tp1.sim - xyplot(y~ x | case + parm , group=group, data = data, lty = 1:4
,
pch = 1:4)
print(tp1.sim)

How can I have two lines (for g1 and g2) in each plot (each box)?


include the type=b argument

 How do I label the x-axis with only values 2, 4, 8?
include the scales= argument or make x a factor

 How do I label each column with the corresponding case number?
make 'case' a factor

The following should do what you want:

xyplot(y ~ x | factor(case) + parm, group=group, data=data,
   type='b', lty=1:2, pch=1:2,
   scales=list(x=list(at=c(2,4,8)))
)

I don't understand why you want 4 line types/point chars.

 -Peter Ehlers



My hypothetical data set is as follows:

parm x case y group
a 2 10 0.03 g1
b 2 10 0.02 g1
a 4 10 0.03 g1
b 4 10 0.02 g1
a 8 10 0.03 g1
b 8 10 0.02 g1
a 2 20 0.03 g1
b 2 20 0.02 g1
a 4 20 0.03 g1
b 4 20 0.02 g1
a 8 20 0.03 g1
b 8 20 0.02 g1
a 2 30 0.03 g1
b 2 30 0.02 g1
a 4 30 0.03 g1
b 4 30 0.02 g1
a 8 30 0.03 g1
b 8 30 0.02 g1
a 2 10 0.13 g2
b 2 10 0.12 g2
a 4 10 0.13 g2
b 4 10 0.12 g2
a 8 10 0.13 g2
b 8 10 0.12 g2
a 2 20 0.13 g2
b 2 20 0.12 g2
a 4 20 0.13 g2
b 4 20 0.12 g2
a 8 20 0.13 g2
b 8 20 0.12 g2
a 2 30 0.13 g2
b 2 30 0.12 g2
a 4 30 0.13 g2
b 4 30 0.12 g2
a 8 30 0.13 g2
b 8 30 0.12 g2

Many thanks in advance for your response.

George

   [[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] What is the correct way to define __hash__?

2009-10-12 Thread Peng Yu
On Mon, Oct 12, 2009 at 4:03 PM, Robert Kern robert.k...@gmail.com wrote:
 On 2009-10-12 15:45 PM, Peng Yu wrote:

 Hi,

 I'm wondering what is the general way to define __hash__. I could add
 up all the members. But I am wondering if this would cause a
 performance issue for certain classes.

 Unless if you are very familiar with the math of hash functions, I don't
 recommend that you try to implement one directly. Instead, make a tuple of
 the hashable content of your class and return the result of calling hash()
 on that tuple. Be sure to make your equality comparison do the right thing.

 class A(object):
  def __init__(self, a, b):
    self.a = a
    self.b = b

  def _key(self):
    # I include the name of the class so as to differentiate between other
    # classes that might also have a _key() method. If you have several
 classes
    # or subclasses that are allowed to compare equal to each other, use some
    # other common string here.
    return (type(self).__name__, a, b)

  def __hash__(self):
    return hash(self._key())

  # Coincidentally, the _key() method can usually be reused for comparisons.
  # I recommend doing this for the equality comparisons, at least, when you
 can
  # because of the requirement that two items that compare equal must have
 the
  # same hash value.
  def __eq__(self, other):
    return self._key() == other._key()

  def __ne__(self, other):
    return not (self == other)

  ...

Do I need to define other 4 comparison operators besides __eq__ and __ne__?

__
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] Invoking par(mfrow...) on an already subdivided plot

2009-10-12 Thread Maxwell Reback
I'd like to generate on a single device multiple plots, each of which
contains two plots. Essentially, I've got sub-plots which consist of
two tracks, the upper one displaying gene expression data, and the
lower one mapping position. I'd like to display four of these
two-track sub-plots on one device, but I can't seem to invoke the
par(mfrow=...) or layout(matrix(...)) functions at more than one
level.

I've got something like:

plot.gene-function(gene){
par(fig=c(0,1,0.3,1))  #expression: track 1
plot(...)
par(fig=c(0,1,0,0.4),new=TRUE) #position: track 2
plot(...)}

plot.multigene-function(gene,...){
pdf(paste(gene,.pdf,sep=))
par(mfrow=c(2,2))
tapply(gene,gene, plot.gene)
dev.off()}

The par(mfrow=) in plot.multigene, even when 'new=TRUE', is
disregarded and I just get one sub-plot per page. Suggestions?
(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] How to hide tick lines behind the box-and-whisker 's in a boxplot

2009-10-12 Thread Peter Ehlers

Helmer,

You can just place another boxplot on top of the first like this:

  boxplot(x)
  axis(2,tck=1,col.ticks='grey',lty=5 )
  boxplot(x, col=white, add=TRUE)

 -Peter Ehlers

Helmer Belbo wrote:

Dear R people,

I wonder how to hide tick lines behind other figures in a plot, e.g.
in a boxplot.

# Sample code:

x- c(rep(4,50),rep(5,20),rep(6,50),rnorm(20,5,1))
boxplot(x)
axis(2,tck=1,col.ticks='grey',lty=5 )

# end of sample code

The tick lines is put on top of the box-plot, but I would like to put
these lines behind the box and whiskers..

Regards
Helmer

__
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] Kolmogorov smirnov test

2009-10-12 Thread Roslina Zakaria

Hi r-users,
 
I would like to use Kolmogorov smirnov test but in my observed data(xobs) there 
are ties.  I got the warning message.  My question is can I do something about 
it?
 
ks.test(xobs, xsyn)
 
    Two-sample Kolmogorov-Smirnov test
data:  xobs and xsyn 
D = 0.0502, p-value = 0.924
alternative hypothesis: two-sided 

Warning message:
In ks.test(xobs, xsyn) : cannot compute correct p-values with ties
 
Thank you for all your help.



  
[[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 use objects from within a custom made function

2009-10-12 Thread Stropharia

Hi everyone,

i'm having a problem extracting objects out of functions i've created, so i
can use them for further analysis. Here's a small example:

# ---
test - function(i, j){
x - i:j
y - i*j
z - i/j
return(x,y,z)
}
# ---

This returns the 3 objects as $x, $y and $z. I cannot, however, access these
objects individually by typing for example:

test$x

I know i can do this by adding an extra arrow head to the assignment arrow
(-), but I am sure that is not how it is done in some of the established R
functions (like when calling lm$coef out of the lm function). Is there a
simple command i've omitted from the function that allows access to objects
inside it?

Thanks in advance,

Steve
-- 
View this message in context: 
http://www.nabble.com/Reuse-objects-from-within-a-custom-made-function-tp25864695p25864695.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 use objects from within a custom made function

2009-10-12 Thread Tony Plate

test$x doesn't evaluate the function, you want something like test(1,2)$x, e.g.:

test - function(i, j){
x - i:j
y - i*j
z - i/j
return(list(x=x,y=y,z=z))
}


test(1,2)$x

[1] 1 2

test(1,2)$y

[1] 2

test(1,2)$z

[1] 0.5




Or if you want to avoid evaluating your function multiple times:


res - test(1,2)
res$x

[1] 1 2

res$y

[1] 2

res$z

[1] 0.5

res

$x
[1] 1 2

$y
[1] 2

$z
[1] 0.5






Stropharia wrote:

Hi everyone,

i'm having a problem extracting objects out of functions i've created, so i
can use them for further analysis. Here's a small example:

# ---
test - function(i, j){
x - i:j
y - i*j
z - i/j
return(x,y,z)
}
# ---

This returns the 3 objects as $x, $y and $z. I cannot, however, access these
objects individually by typing for example:

test$x

I know i can do this by adding an extra arrow head to the assignment arrow
(-), but I am sure that is not how it is done in some of the established R
functions (like when calling lm$coef out of the lm function). Is there a
simple command i've omitted from the function that allows access to objects
inside it?

Thanks in advance,

Steve


__
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 use objects from within a custom made function

2009-10-12 Thread Daniel Nordlund
 -Original Message-
 From: r-help-boun...@r-project.org 
 [mailto:r-help-boun...@r-project.org] On Behalf Of Stropharia
 Sent: Monday, October 12, 2009 4:07 PM
 To: r-help@r-project.org
 Subject: [R] Re use objects from within a custom made function
 
 
 Hi everyone,
 
 i'm having a problem extracting objects out of functions i've 
 created, so i
 can use them for further analysis. Here's a small example:
 
 # ---
 test - function(i, j){
   x - i:j
   y - i*j
   z - i/j
   return(x,y,z)
 }
 # ---
 
 This returns the 3 objects as $x, $y and $z. I cannot, 
 however, access these
 objects individually by typing for example:
 
 test$x
 
 I know i can do this by adding an extra arrow head to the 
 assignment arrow
 (-), but I am sure that is not how it is done in some of 
 the established R
 functions (like when calling lm$coef out of the lm function). 
 Is there a
 simple command i've omitted from the function that allows 
 access to objects
 inside it?
 
 Thanks in advance,
 
 Steve
 -- 

Steve,

I see a couple of problems (at least from my perspective).  If you ever got
your function to run, you would see a warning stating that returning
multiple objects is deprecated.  In your example of using the function, you
don't call it with any parameters, and the definition has no default values.
I also would be inclined to assign the results of the function call to a
variable/object and access the values from there. 

So I would approach your problem as follows:

test - function(i, j){
x - i:j
y - i*j
z - i/j
list(x=x, y=y, z=z)
}

my.result - test(1,4)
 my.result$x
[1] 1 2 3 4


If you don't want to assign the output of test() to an object, then you will
need to do something like

test(1,4)$x

But this is inefficient because each time you access one of the components,
you need to rerun the function.

Hope this is helpful,

Dan

Daniel Nordlund
Bothell, WA USA

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] Lattice barchart-reordered

2009-10-12 Thread Veerappa Chetty
Hi,Can I use reorder function with barchart as in dotchart? Here are some
codes which do not work for  me. Thanks
Chetty
___
a1c.cast$bmi.cat.reordered[a1c.cast$eth!=Other]
-with(a1c.cast[a1c.cast$eth!=Other,],reorder(bmi.cat.ordered[a1c.cast$eth!=Other],
BP.FN.RATE,median ))
barchart(BP.FN.RATE~
gender|eth,data=a1c.cast[a1c.cast$eth!=Othera1c.cast$bmi.cat.reordered!=Other,],
groups =bmi.cat.reordered ,
par.settings = list(superpose.polygon =
list(col=c(blue,cyan,red,yellow )) ),
sub=  NHANES-99:06; n = 12,514  ,ylab= list(Error Rate (%),cex=1.5),
xlab=list(Gender,cex=1.25),auto.key=list(title= FPG VS A1C for DM
Diagnosis: Missed BP,columns=2,cex=1.25),
col=c(blue,cyan,red,yellow))

-- 
Chetty
Professor of Family Medicine
Boston University
Tel: 617-414-6221, Fax:617-414-3345
emails: chett...@gmail.com,vche...@bu.edu

[[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] vis.gam() contour plots

2009-10-12 Thread Jason Gasper

Greetings,

I have what I hope is a simple question.  I would like to change my 
contour interval on the vis.gam( plot.type=contour)  in the mgcv 
package.  Is this a situation where I need to modify the function or is 
there a default value I can change? 


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] splitting dataframe, assign to new dataframe, add new rows to new dataframe

2009-10-12 Thread wk y

Hi, all,

My objective is to split a dataframe named cmbine according to the value of 
classes. After the split, I will take the first instance from each class and 
bin them into a new dataframe, df1. In the 2nd iteration, I will take the 2nd 
available instance and bin them into another new dataframe, df2.


cmbine$names
apple tiger pencil chicken banana pear

cmbine$mass
0.50 100.00 0.01 1.00 0.15 0.30

cmbine$classes
1 2 3 2 1 1

These are the results which I want to obtain:

df1
classes  mass
apple  0.50
tiger  100.00
pencil  0.01

df2
classes  mass
banana  0.15
chicken  1.00

df3
classes  mass
pear  0.30

Below shows what I have tried. The main problem I have = I don't know how to 
assign the selected instance into a new dataframe with a name which is 
generated 'on-the-fly' based on the value of j (the jth row).


for (i in 1:3) {
same_cell - cmbine[cmbine$classes == i, ]
if (nrow(same_cell)!=0){
  for (j in 1:nrow(same_cell)){
picked - same_cell[j, ]
assign(paste(df, j, sep=), picked)
#assign(paste(df,j, sep=), paste(df, j, sep=))
  }
}

 
The problem is that the assign function overwrites the previous value of df and 
therefore the I have not been able to insert rows in the three df dataframes 
and always end up with only 1 (final) row in df1, df2 and df3. I have tried 
using rbind but was not able to assign values back to the on-the-fly variable 
names.
 
I really need your advice and assistance since I have stuck with this for some 
time now.
 
Thank you.

__
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] splitting dataframe, assign to new dataframe, add new rows to new dataframe

2009-10-12 Thread cls59



wk yeo wrote:
 
 
 Hi, all,
 
 My objective is to split a dataframe named cmbine according to the value
 of classes. After the split, I will take the first instance from each
 class and bin them into a new dataframe, df1. In the 2nd iteration, I
 will take the 2nd available instance and bin them into another new
 dataframe, df2.
 
 
cmbine$names
 apple tiger pencil chicken banana pear
 
cmbine$mass
 0.50 100.00 0.01 1.00 0.15 0.30
 
cmbine$classes
 1 2 3 2 1 1
 
 

If possible, it would be helpful to provide sample data in a form that could
be copied and pasted directly into an R session, like so:

cmbine - data.frame( names = c('apple', 'tiger', 'pencil', 'chicken',
'banana', 'pear' ) )
cmbine['mass'] - c(0.50, 100.00, 0.01, 1.00, 0.15, 0.30)
cmbine['classes'] - factor(c(1, 2, 3, 2,1 ,1))

It saves people on the list a bunch of coping/pasting/quote adding. Another
quick way to do this is to use  the dump() which spits out the structure of
your object in a way that can be copied and pasted:

dump( 'cmbine', file='' )



wk yeo wrote:
 
 
 These are the results which I want to obtain:
 
df1
 classes  mass
 apple  0.50
 tiger  100.00
 pencil  0.01
 
df2
 classes  mass
 banana  0.15
 chicken  1.00
 
df3
 classes  mass
 pear  0.30
 
 Below shows what I have tried. The main problem I have = I don't know how
 to assign the selected instance into a new dataframe with a name which is
 generated 'on-the-fly' based on the value of j (the jth row).
 
 
 for (i in 1:3) {
 same_cell - cmbine[cmbine$classes == i, ]
 if (nrow(same_cell)!=0){
   for (j in 1:nrow(same_cell)){
 picked - same_cell[j, ]
 assign(paste(df, j, sep=), picked)
 #assign(paste(df,j, sep=), paste(df, j, sep=))
   }
 }
 
 

I'm assuming you want the results grouped by class, i.e. all the 1s in one
data frame all the 2s in another. This can be done with a slight
modification of your loop:

for (i in 1:3) {
  same_cell - cmbine[cmbine$classes == i, ]

  if (nrow(same_cell)!=0){
assign(paste(df, i, sep=), same_cell)
  }

}

However, the results I get aren't the same as the results you said you
wanted:

 df1
   names mass classes
1  apple 0.50   1
5 banana 0.15   1
6   pear 0.30   1

 df2
names mass classes
2   tiger  100   2
4 chicken1   2

 df3
   names mass classes
3 pencil 0.01   3


The R way of doing this is to use the by() function, which breaks a data
frame into sub-data frames based on a column of factors-- such as the
classes. For your example, it would be used as:

by( cmbine, cmbine[['classes']], function( df ){

  # Lots of stuff can happen inside this function, in this case we are
really
  # just returning the subset that got passed in.

  return( df )

})

cmbine[[classes]]: 1
   names mass classes
1  apple 0.50   1
5 banana 0.15   1
6   pear 0.30   1
--- 
cmbine[[classes]]: 2
names mass classes
2   tiger  100   2
4 chicken1   2
--- 
cmbine[[classes]]: 3
   names mass classes
3 pencil 0.01   3

The by() function returns a fancy list, each component of which can be
accessed using the [] operator.

Hope this helps!

-Charlie


-
Charlie Sharpsteen
Undergraduate
Environmental Resources Engineering
Humboldt State University
-- 
View this message in context: 
http://www.nabble.com/splitting-dataframe%2C-assign-to-new-dataframe%2C-add-new-rows-to-new-dataframe-tp25865409p25865911.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] gee: suppress printout

2009-10-12 Thread joshua wells

I'm using the function gee from the library(gee)

 

gee(Y~X,id=clust.id,corstr=exchangeable,b=tmc$coef,family=binomial(link=logit),silent=T)

 

Every time it runs, it dutifully prints out

 

Beginning Cgee S-function, @(#) geeformula.q 4.13 98/01/27
user's initial regression estimate
   [,1]
[1,] -4.5278335
[2,] -0.2737999
[3,] -0.9528306
[4,]  0.9393861
[5,] -0.6618903


Unfortunately, i run thousands of these and the output gets extremely lengthy. 
Is there any way to suppress this printout in R?

 

Thank you,

Josh
  
_
Hotmail: Powerful Free email with security by Microsoft.

[[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] variable selection

2009-10-12 Thread Weiwei Shi
Hi there,

Can anyone suggest some packages in R doing variable selections in
predictive modeling besides randomForest? Faster, better.

Any also in clustering analysis?

Thanks,

Weiwei

-- 
Weiwei Shi, Ph.D
Research Scientist
GeneGO, Inc.

Did you always know?
No, I did not. But I believed...
---Matrix III

[[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] Re use objects from within a custom made function

2009-10-12 Thread Stropharia

Thanks a lot Tony and Daniel for making that clear.

best,

Steve



Stropharia wrote:
 
 Hi everyone,
 
 i'm having a problem extracting objects out of functions i've created, so
 i can use them for further analysis. Here's a small example:
 
 # ---
 test - function(i, j){
   x - i:j
   y - i*j
   z - i/j
   return(x,y,z)
 }
 # ---
 
 This returns the 3 objects as $x, $y and $z. I cannot, however, access
 these objects individually by typing for example:
 
 test$x
 
 I know i can do this by adding an extra arrow head to the assignment arrow
 (-), but I am sure that is not how it is done in some of the established
 R functions (like when calling lm$coef out of the lm function). Is there a
 simple command i've omitted from the function that allows access to
 objects inside it?
 
 Thanks in advance,
 
 Steve
 

-- 
View this message in context: 
http://www.nabble.com/Reuse-objects-from-within-a-custom-made-function-tp25864695p25866081.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 use objects from within a custom made function

2009-10-12 Thread David Winsemius


On Oct 12, 2009, at 7:06 PM, Stropharia wrote:



Hi everyone,

i'm having a problem extracting objects out of functions i've  
created, so i

can use them for further analysis. Here's a small example:

# ---
test - function(i, j){
x - i:j
y - i*j
z - i/j
return(x,y,z)
}
# ---

This returns the 3 objects as $x, $y and $z. I cannot, however,  
access these

objects individually by typing for example:

test$x



Generally one assigns the resutlts of a function to an object name:

 ll - test(1,2)
Warning message:
In return(x, y, z) : multi-argument returns are deprecated
 ll
$x
[1] 1 2

$y
[1] 2

$z
[1] 0.5

 str(ll)
List of 3
 $ x: int [1:2] 1 2
 $ y: num 2
 $ z: num 0.5


So you would not get the warnings if you instead ended the function  
with:


 return(list(x,y,z) )



I know i can do this by adding an extra arrow head to the assignment  
arrow
(-), but I am sure that is not how it is done in some of the  
established R
functions (like when calling lm$coef out of the lm function). Is  
there a
simple command i've omitted from the function that allows access to  
objects

inside it?

Thanks in advance,

Steve
--


--

David Winsemius, MD
Heritage Laboratories
West Hartford, CT

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


  1   2   >