[R] Alternative to extended recode sintax?

2010-12-18 Thread Luca Meyer
Dear R-users,

I have a factor variable within my data frame which I derive week after week 
from a POSIXct variable using the cut(var,weeks) command I have found in the 
chron package. The levels() command gives me:

[1] 2009-03-30 00:00:00 2009-04-06 00:00:00 2009-04-13 00:00:00 
2009-04-20 00:00:00 2009-04-27 00:00:00 2009-05-04 00:00:00 2009-05-11 
00:00:00 2009-05-18 00:00:00
 [9] 2009-05-25 00:00:00 2009-06-01 00:00:00 2009-06-08 00:00:00 
2009-06-15 00:00:00 2009-06-22 00:00:00 2009-06-29 00:00:00 2009-07-06 
00:00:00 2009-07-13 00:00:00
[17] 2009-07-20 00:00:00 2009-07-27 00:00:00 2009-08-03 00:00:00 
2009-08-10 00:00:00 2009-08-17 00:00:00 2009-08-24 00:00:00 2009-08-31 
00:00:00 2009-09-07 00:00:00
[25] 2009-09-14 00:00:00 2009-09-21 00:00:00 2009-09-28 00:00:00 
2009-10-05 00:00:00 2009-10-12 00:00:00 2009-10-19 00:00:00 2009-10-25 
23:00:00 2009-11-01 23:00:00
[33] 2009-11-08 23:00:00 2009-11-15 23:00:00 2009-11-22 23:00:00 
2009-11-29 23:00:00 2009-12-06 23:00:00 2009-12-13 23:00:00 2009-12-20 
23:00:00 2009-12-27 23:00:00
[41] 2010-01-03 23:00:00 2010-01-10 23:00:00 2010-01-17 23:00:00 
2010-01-24 23:00:00 2010-01-31 23:00:00 2010-02-07 23:00:00 2010-02-14 
23:00:00 2010-02-21 23:00:00
[49] 2010-02-28 23:00:00 2010-03-07 23:00:00 2010-03-14 23:00:00 
2010-03-21 23:00:00 2010-03-29 00:00:00 2010-04-05 00:00:00 2010-04-12 
00:00:00 2010-04-19 00:00:00
[57] 2010-04-26 00:00:00 2010-05-03 00:00:00 2010-05-10 00:00:00 
2010-05-17 00:00:00 2010-05-24 00:00:00 2010-05-31 00:00:00 2010-06-07 
00:00:00 2010-06-14 00:00:00
[65] 2010-06-21 00:00:00 2010-06-28 00:00:00 2010-07-05 00:00:00 
2010-07-12 00:00:00 2010-07-19 00:00:00 2010-07-26 00:00:00 2010-08-02 
00:00:00 2010-08-09 00:00:00
[73] 2010-08-16 00:00:00 2010-08-23 00:00:00 2010-08-30 00:00:00 
2010-09-06 00:00:00 2010-09-13 00:00:00 2010-09-20 00:00:00 2010-09-27 
00:00:00 2010-10-04 00:00:00
[81] 2010-10-11 00:00:00 2010-10-18 00:00:00 2010-10-25 00:00:00 
2010-10-31 23:00:00 2010-11-07 23:00:00 2010-11-14 23:00:00 2010-11-21 
23:00:00 2010-11-28 23:00:00
[89] 2010-12-05 23:00:00 2010-12-12 23:00:00

Now what I would like is to have more readable labels, such as 2010-W01 for the 
first week of 2010, 2009-W34 for the 34th week in 2009, etcis there an 
easier way to achieve that than having to write out the all recode sintax:

library(car)
dataset$newvar - recode(dataset$oldvar, 
c('2009-03-30 00:00:00')='2009-W13';
c('2009-04-06 00:00:00')='2009-W14';
# etc...
c('2010-12-05 23:00:00')='2009-W48';
c('2010-12-12 23:00:00')='2009-W49';
# etc...this part should be updated with time unless I'll find some automatic 
procedure 
)

Thanks,
Luca


Luca Meyer
www.lucameyer.com
IBM SPSS Statistics release 19.0.0
R version 2.12.1 (2010-12-16)
Mac OS X 10.6.5 (10H574) - kernel Darwin 10.5.0

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Compare two dataframes

2010-12-18 Thread Petr Savicky
Hi Mark:

 However, if the dataframe contains non-unique rows (two rows with
 exactly the same values in each column) then the unique function will
 delete one of them and that may not be desirable.

In order to get information about equal rows between two dataframes
without removing duplicated rows in each of them, it is possible to
use sorting. For example

  n - ncol(cars)
  cars1 - cbind(cars[1:35, ], df=df1)
  cars2 - cbind(cars[16:50, ], df=df2)
  cars.all - rbind(cars1, cars2) # all cases together, column df indicates 
origin of each case
  row.names(cars.all) - seq(nrow(cars.all))
  cars.sorted - cars.all[do.call(order, cars.all), ]
  # compute an index, which is the same for rows, which are equal except of the 
df component.
  index - cumsum(1 - duplicated(cars.sorted[, 1:n]))
  # for each index of a unique row, compute the number of occurrences in both 
dataframes
  out - table(index, cars.sorted$df)
  out[15:20, ]
 
  index df1 df2
 15   1   0
 16   1   1
 17   2   2
 18   1   1
 19   1   1
 20   1   1

This shows, for example, that the row with index 17 has 2 occurrences in both
dataframes. These rows can be obtained using

  cars.sorted[index == 17, ]

 speed dist  df
  1713   34 df1
  1813   34 df1
  3713   34 df2
  3813   34 df2

See also ?rle.

Petr.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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 function

2010-12-18 Thread Iain Gallagher
Ok - used browser to step through the function. Thanks for the nod towards that 
Chuck.

 tf2 - cumulMetric(tf1, deMirs$up)
Called from: cumulMetric(tf1, deMirs$up)
Browse[1] fcVector - as.numeric(with (deMirs, FC[match(deMirPresGenes[,4], 
Probe)] ) )

Browse[1] metric - fcVector * as.numeric(deMirPresGenes[,11])

Browse[1] geneMetric - cbind(deMirPresGenes[,2], metric) 

Browse[1] ls()
[1] deMirPresGenes deMirs fcVector   geneMetric
[5] metric   

Browse[1] listMetric - unstack(geneMetric, 
as.numeric(geneMetric[,2])~geneMetric[,1])
Error in eval(expr, envir, enclos) : object 'geneMetric' not found

Browse[1] ls()
[1] deMirPresGenes deMirs fcVector   geneMetric
[5] metric   

Browse[1] head(geneMetric)
 sym  metric
[1,] AAK1   -0.35505
[2,] ABCA1  -0.34979
[3,] ABCA2  -1.0329 
[4,] ABCB10 -1.22558
[5,] ABCE1  -0.61348
[6,] ABCF3  -0.86584


So geneMetric is there. It looks right but for some reason the call to unstack 
cannot find it. Yet if I go through this line by line but not as a function the 
call to unstack works fine:

 fcVector - as.numeric(with (deMirs$up, FC[match(tf1[,4], Probe)] ) )
 metric - fcVector * as.numeric(tf1[,11])
  geneMetric - cbind(tf1[,2], metric)
 head(geneMetric)
  metric
[1,] AAK1   -0.35505
[2,] ABCA1  -0.34979
[3,] ABCA2  -1.0329 
[4,] ABCB10 -1.22558
[5,] ABCE1  -0.61348
[6,] ABCF3  -0.86584

 colnames(geneMetric) - c('sym', 'metric')

 listMetric - unstack(geneMetric, as.numeric(geneMetric[,2])~geneMetric[,1])
 head(listMetric)
$AAK1
[1] -0.35505

$ABCA1
[1] -0.34979

$ABCA2
[1] -1.0329

$ABCB10
[1] -1.22558

$ABCE1
[1] -0.61348

$ABCF3
[1] -0.86584

Any further advice would be much appreciated.

Thanks

i

 sessionInfo()
R version 2.12.0 (2010-10-15)
Platform: x86_64-pc-linux-gnu (64-bit)

locale:
 [1] LC_CTYPE=en_GB.utf8   LC_NUMERIC=C 
 [3] LC_TIME=en_GB.utf8LC_COLLATE=en_GB.utf8
 [5] LC_MONETARY=C LC_MESSAGES=en_GB.utf8   
 [7] LC_PAPER=en_GB.utf8   LC_NAME=C
 [9] LC_ADDRESS=C  LC_TELEPHONE=C   
[11] LC_MEASUREMENT=en_GB.utf8 LC_IDENTIFICATION=C  

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


--- On Sat, 18/12/10, Charles C. Berry cbe...@tajo.ucsd.edu wrote:

 From: Charles C. Berry cbe...@tajo.ucsd.edu
 Subject: Re: [R] help with function
 To: Iain Gallagher iaingallag...@btopenworld.com
 Cc: r-help@r-project.org
 Date: Saturday, 18 December, 2010, 0:13
 On Fri, 17 Dec 2010, Iain Gallagher
 wrote:
 
  Hello List
 
  I'm moving this over from the bioC list as, although
 the problem I'm working on is biological, the current bottle
 neck is my poor understanding of R.
 
  I wonder if someone would help me with the following
 function.
 
 
 Here is how I'd take it apart.
 
 Either
 
   1) put browser() as the first line of the
 function,then feed lines to the
      browser one -by-one to see where
 it hangs,
 
   2) trace(cumulMetric) , then try to run it (much
 like 1, but it will
      handle feeding the lines of the
 function more easily)
 
   3) options( error = recover ), then run it till it
 hits the error, then
      browser thru the frames to see
 what is where
 
 See
 
      ?browser
      ?trace
      ?recover
 
 as background.
 
 HTH,
 
 Chuck
 
  cumulMetric - function(deMirPresGenes, deMirs){
     
  #need to match position of each miR in deMirPresGenes
 with its FC to form a vector of FC in correct order
      fc - deMirs
      fcVector - as.numeric(with (fc,
 FC[match(deMirPresGenes[,4], Probe)] ) )
 
      #multiply fc by context score for each
 interaction
      metric - fcVector *
 as.numeric(deMirPresGenes[,11])
      geneMetric - cbind(deMirPresGenes[,2],
 as.numeric(metric))
 
      #make cumul weighted score
      listMetric - unstack(geneMetric,
 as.numeric(geneMetric[,2])~geneMetric[,1])
      listMetric -
 as.data.frame(sapply(listMetric,sum)) #returns a dataframe
      colnames(listMetric) - c('cumulMetric')
 
      #return whole list
      return(listMetric)
  }
 
  deMirPresGenes looks like this:
 
  Gene.ID    Gene.Symbol    Species.ID    miRNA 
   Site.type    UTR_start    UTR_end   
 X3pairing_contr    local_AU_contr    position_contr   
 context_score    context_percentile
  22848    AAK1    9606    hsa-miR-183    2   
 1546    1552    -0.026    -0.047    0.099   
 -0.135    47
  19    ABCA1    9606    hsa-miR-183    2   
 1366    1372    -0.011    -0.048    0.087   
 -0.133    46
  20    ABCA2    9606    hsa-miR-495    2   
 666    672    -0.042    -0.092    -0.035   
 -0.33    93
  23456    ABCB10    9606    hsa-miR-183    3 
   1475    1481    0.003    -0.109    -0.05   
 -0.466    98
  6059    ABCE1    9606    hsa-miR-495    2   
 1474    1480    0.005    -0.046    0.006   
 -0.196    58
  55324    ABCF3    9606    hsa-miR-1275    3 
   90    96    0.007    0.042    -0.055   
 -0.316    94
 
  although it is much longer in 'real 

[R] dotchart for matrix data

2010-12-18 Thread e-letter
Readers,

I am trying to use the function dotchart. The data is:

 testdot
  category values1 values2 values3 values4
1a  10  27  56 709
2b   4  46  47 208
3c   5  17  18 109
4d   6  50  49 308

The following error occurs

 dotchart(testdot,groups=testdot[,2])
Error in dotchart(testdot, labels = testdot[, 1], groups = testdot[, 2]) :
'x' must be a numeric vector or matrix

According to my understanding (clearly wrong!) of the documentation
for dotchart (accessed from the manual in section 'graphics'), columns
of data can be selected by 'groups' for subsequent plotting. The
objective is to be able to create a dot chart where each row is
labelled according to the row names in the 'category' column and two
columns can be selected, e.g. 'values1' and 'values2'. Then I tried:

 testdot1-testdot[,1]
 testdot2-testdot[,2]
 testdot3-testdot[,3]
 dotchart(c(testdot2,testdot3),labels=testdot1)

A graph is produced, but not as expected. Instead of 4 rows labelled
(descending order from top row) a,b,c,d, and each row containing two
data points, the graph shows 8 rows (?) with the top 4 rows
un-labelled and the bottom 4 rows labelled (descending order) d,c,b,a
and each row shows only 1 datum point.

How do I specify the order of labelling of the rows?
How do I write correct commands to obtain a dot chart with 4 rows,
each row containing the two (or if required three) data points?

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.


Re: [R] system/system2 command

2010-12-18 Thread Duncan Murdoch

Gabor Grothendieck wrote:

On Fri, Dec 17, 2010 at 4:36 PM, Jeff Breiwick jeff.breiw...@noaa.gov wrote:

All,

I had a simple function call I used to open up a dos shell running R under
Win XP:
system(cmd.exe, wait=FALSE, invisible=FALSE).

This does not work with R 2.12.1 - I get a window that briefly flashes open
but then disappears. Does anyone know the method to open a DOS command
window in running R with Win XP? Thank you.



This works on my Vista system:

shell(start cmd)




Is start back in Vista?  There was a start.exe in Windows95, but I think 
it disappeared in XP and I had to write my own. (Or maybe it became an 
internal command?) Brian Ripley added a similar program open.exe 
(based on the OSX name, I think) to R, so if start cmd fails, open 
cmd might succeed.


Duncan Murdoch

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Alternative to extended recode sintax?

2010-12-18 Thread David Winsemius


On Dec 17, 2010, at 11:08 AM, Luca Meyer wrote:

x= factor(c(2009-03-30 00:00:00, 2009-04-06 00:00:00, 2009-04-13  
00:00:00, 2009-04-20 00:00:00, 2009-04-27 00:00:00, 2009-05-04  
00:00:00 ,2009-05-11 00:00:00, 2009-05-18 00:00:00))

require(lubridate)
xd=as.POSIXct(x)
week(xd)
# [1] 13 14 15 16 17 18 19 20
 year(xd)
# [1] 2009 2009 2009 2009 2009 2009 2009 2009
 paste(year(xd),  W,week(xd), sep=)
#[1] 2009 W13 2009 W14 2009 W15 2009 W16 2009 W17 2009 W18  
2009 W19 2009 W20




David Winsemius, MD
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] system/system2 command

2010-12-18 Thread Gabor Grothendieck
On Sat, Dec 18, 2010 at 8:07 AM, Duncan Murdoch
murdoch.dun...@gmail.com wrote:
 Gabor Grothendieck wrote:

 On Fri, Dec 17, 2010 at 4:36 PM, Jeff Breiwick jeff.breiw...@noaa.gov
 wrote:

 All,

 I had a simple function call I used to open up a dos shell running R
 under
 Win XP:
 system(cmd.exe, wait=FALSE, invisible=FALSE).

 This does not work with R 2.12.1 - I get a window that briefly flashes
 open
 but then disappears. Does anyone know the method to open a DOS command
 window in running R with Win XP? Thank you.


 This works on my Vista system:

 shell(start cmd)



 Is start back in Vista?  There was a start.exe in Windows95, but I think it
 disappeared in XP and I had to write my own. (Or maybe it became an internal
 command?) Brian Ripley added a similar program open.exe (based on the OSX
 name, I think) to R, so if start cmd fails, open cmd might succeed.


Yes its in Vista and its at least in XP Pro according to:
   
http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/ntcmds.mspx

Note that its internal to cmd so if you are using some other command
line shell then you will need to do:
   cmd /c start

-- 
Statistics  Software Consulting
GKX Group, GKX Associates Inc.
tel: 1-877-GKX-GROUP
email: ggrothendieck at gmail.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] dotchart for matrix data

2010-12-18 Thread David Winsemius


On Dec 18, 2010, at 7:01 AM, e-letter wrote:


Readers,

I am trying to use the function dotchart. The data is:


testdot

 category values1 values2 values3 values4
1a  10  27  56 709
2b   4  46  47 208
3c   5  17  18 109
4d   6  50  49 308

The following error occurs


dotchart(testdot,groups=testdot[,2])
Error in dotchart(testdot, labels = testdot[, 1], groups = testdot[,  
2]) :

   'x' must be a numeric vector or matrix

According to my understanding (clearly wrong!) of the documentation
for dotchart (accessed from the manual in section 'graphics'), columns
of data can be selected by 'groups' for subsequent plotting.


The misunderstanding is in how you see the grouping information versus  
how R expects it. R generally expects such data in what is called  
long format, i.e. there will be one values columns and a category  
column. There are various ways to change the arrangement of your data.  
The function stack(), the function reshape(), or probably most  
commonly the function melt from reshape2 being the typical chosen  
routes.



The
objective is to be able to create a dot chart where each row is
labelled according to the row names in the 'category' column and two
columns can be selected, e.g. 'values1' and 'values2'. Then I tried:


testdot1-testdot[,1]
testdot2-testdot[,2]
testdot3-testdot[,3]
dotchart(c(testdot2,testdot3),labels=testdot1)


See if this is more to your liking:

require(reshape)   # I'm not sure why I have reshape_0.8.3 rather than  
reshape2 loaded
   # I'm pretty sure Hadley would prefer that people  
use pkg:reshape2

 mdot - melt(dot)
dotchart(mdot$value, groups=mdot$category, labels=mdot$variable)
# OR more readable
with(mdot, dotchart(value, groups=category, labels=variable)  )

I'm not sure I got the roles of values and category correct, but  
it should be a simple matter to switch them in the dotcghart call if  
that is your pleasuRe.





A graph is produced, but not as expected. Instead of 4 rows labelled
(descending order from top row) a,b,c,d, and each row containing two
data points, the graph shows 8 rows (?) with the top 4 rows
un-labelled and the bottom 4 rows labelled (descending order) d,c,b,a
and each row shows only 1 datum point.

How do I specify the order of labelling of the rows?
How do I write correct commands to obtain a dot chart with 4 rows,
each row containing the two (or if required three) data points?


David Winsemius, MD
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] Subarray specification problem

2010-12-18 Thread Roy Shimizu
On Fri, Dec 17, 2010 at 8:58 AM, Michael Friendly frien...@yorku.ca wrote:
 Use aperm() to make time the first dimension
 Reshape to a matrix (all other dimensions combined)
 Do your selection on X[1,]
 aperm() to Permute back

To Michael, thanks!

I copy my implementation of Michael's idea at the end of this post.

My implementation is long and labored, at least when compared to
Michael's succinct description of its strategy.

How much this is due to my inexperience with R, and how much is due to
R's intrinsic limitations for this kind of problem?  Could this be
done substantially more succinctly by a more expert programmer?  In
particular, are there some features of R that I'm not using in my
implementation, and that would greatly simplify it?

Also, I wonder about the scalability of such a solution, since it
requires the wholesale reshaping of the array, which doubles the
memory requirement, and maybe would be costly in time as well.

I generalized my implementation to a function called select.subarray,
that takes three arguments: an array, the name of some dimension in
the array, and an predicate to apply to the dimnames in this
dimension; it returns the subarray of the original array in which all
the dimnames in the named dimension satisfy the predicate.

When applied to my original problem, it seems to work.  First a recap of x:

 x
, , 1

  time
  846961 1677
  [1,] 0.4020976 0.8250189 0.3402749 0.09754860 0.2189114
  [2,] 0.5309967 0.5414850 0.9431449 0.08716723 0.5819100

, , 2

  time
  8469611677
  [1,] 0.6238213 0.1210083 0.7823269 0.5004058 0.5474356
  [2,] 0.2491087 0.7449411 0.9561074 0.6685954 0.3871533


And now, applying select.subarray to solve my original problem:

 select.subarray(x, time, function(x) { i - as.integer(x); 20  i  i  80 
 })
, , 1

  time
  696177
  [1,] 0.8250189 0.3402749 0.2189114
  [2,] 0.5414850 0.9431449 0.5819100

, , 2

  time
  696177
  [1,] 0.1210083 0.7823269 0.5474356
  [2,] 0.7449411 0.9561074 0.3871533



OK, here's the beast.  It does no error checking, both for the sake of
simplicity, and because I really don't know enough R yet to handle
errors intelligently.

select.subarray - function(an.array, dim.name, predicate) {
dim.index - which(names(dimnames(an.array)) == dim.name)
reordering.perm - c(dim.index, seq(along=dim(an.array))[-dim.index])

permuted.array - aperm(an.array, reordering.perm)

# save the dim and dimnames of permuted.array for reuse later
d.permuted.array - dim(permuted.array)
dn.permuted.array - dimnames(permuted.array)

dim.dimnames - as.integer(dn.permuted.array[[1]])
permuted.array.matrix -
array(permuted.array,
  dim=c(d.permuted.array[1], sum(d.permuted.array[-1])),
  dimnames=list(dim.dimnames, NULL))

indices.to.keep - which(predicate(dim.dimnames))

new.dimnames.permuted - c(list(dim.dimnames[indices.to.keep]),
   dn.permuted.array[-1])
names(new.dimnames.permuted)[1] - dim.name

desired.subarray.permuted -
array(permuted.array.matrix[indices.to.keep,],
  dim=c(length(indices.to.keep), d.permuted.array[-1]),
  dimnames=new.dimnames.permuted)

# the desired subarray
aperm(desired.subarray.permuted, order(reordering.perm))
}


As I said, I'm very new to R, and would more than welcome any
comments/suggestions/constructive criticism on this code.


Roy

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Colours for 3-way probabilities

2010-12-18 Thread Barry Rowlingson
Are there any R functions for creating palettes for three-way data?
For example, election maps for three parties where pure red, blue, and
green show 100% for the Red, Blue, and Green parties respectively,
magenta shows a 50-50 Red-Blue split with 0 for the Greens, cyan a
50-50 Blue/Green split with no Red votes and so on, with grey, black
or white at a 1/3,1/3,1/3 split vote.

I've spent a couple of half hours knocking out a function to do
various versions of that, including using Red/Yellow/Blue for the
primaries with Orange/Green/Purple for the 50/50s. I'm wondering if

 a) There's existing functionality in one of the packages on CRAN
(I've had a look and googled)

 b) Anyone can point me to information about colour perception of this
kind of three-way colour scheme.

Thanks muchly.

Barry

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] dotchart for matrix data

2010-12-18 Thread Ben Bolker
David Winsemius dwinsemius at comcast.net writes:

 
 
 On Dec 18, 2010, at 7:01 AM, e-letter wrote:
 
  Readers,
 
  I am trying to use the function dotchart. The data is:
 
  testdot
   category values1 values2 values3 values4
  1a  10  27  56 709
  2b   4  46  47 208
  3c   5  17  18 109
  4d   6  50  49 308
 
  The following error occurs
 
  dotchart(testdot,groups=testdot[,2])
  Error in dotchart(testdot, labels = testdot[, 1], groups = testdot[,  
  2]) :
 'x' must be a numeric vector or matrix
 
  According to my understanding (clearly wrong!) of the documentation
  for dotchart (accessed from the manual in section 'graphics'), columns
  of data can be selected by 'groups' for subsequent plotting.
 

  Following up on David's response:


d - read.table(textConnection(category values1 values2 values3 values4
1a  10  27  56 709
2b   4  46  47 208
3c   5  17  18 109
4d   6  50  49 308),
header=TRUE)

## Something like this is probably as close as you can get with
## stock 'dotchart' -- it does *not* (as far as I can tell) put
## different points on the same line, just groups lines

dotchart(as.matrix(d[,-1]),labels=as.character(d[,1]))
dotchart(as.matrix(d[,c(values1,values2)]),labels=as.character(d[,1]))

## reshaping data:
library(reshape)
mdot - melt(d)

## using the lattice package

library(lattice)
dotplot(value~category,groups=variable,data=mdot)
dotplot(value~variable,groups=category,data=mdot,auto.key=TRUE,
scales=list(y=list(log=10)))

## you could also use ggplot2 ...

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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's wrong with these mail headers?

2010-12-18 Thread Ted Harding
When moderating this message just now I forwarded it to
r-help-owner, for discussion.

In reply to Roy's question, there is indeed nothing obvious
which should match a filter rule. However, the ETHZ spam
filter is somewhat sensitive about gmail, regardless of true
content, and there are 4 occurrences of gmail.com, which
may have been responsible for it.

Looking at the headers of the original message (which was
sent out to R-help after moderation), the only indication
of problems is in the following:

X-Tag-Only: YES
X-Filter-Node: phil3.ethz.ch
X-USF-Spam-Level: **
X-USF-Spam-Status: hits=2.1 tests=DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU,
FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FROM,
T_TO_NO_BRKTS_FREEMAIL
X-USF-Spam-Flag: NO
X-Virus-Scanned: by amavisd-new at stat.math.ethz.ch

in which the occurrences of FREEMAIL (associated with gmail,
nabble, yahoo etc.) may carry the clue, though they are too
cryptic for me to interpret! However, the Spam-Level was
not particularly high.

To Roy: Try not to worry about this. It happens from time to
time (including to people who are not mailing via gmail but
happen to be replying to a message that was mailed via gmail
and therefore their reply has gmail in ite header, e.g.
References: as in your headers below), and there is probably
nothing you can do about it! It does not happen every time even
to people who mail via gmail.

Comments from others would also be welcome!
Ted.

On 18-Dec-10 14:07:38, Roy Shimizu wrote:
 A message I posted recently was quarantined (pending moderator
 approval) because its headers matched a filter rule.
 
 I would like to avoid this sort of delay in the future, but as I
 examine these headers, I can't see what could have been the problem.
 
 Here they are:
 
 MIME-Version: 1.0
 Received: by 10.231.145.141 with HTTP; Sat, 18 Dec 2010 05:54:16 -0800
 (PST)
 In-Reply-To: 4d0b6c82.1030...@yorku.ca
 References:
 aanlkti=9j-xwd4r+lbjsbq9h+2d9pobxwrg5cgwhn...@mail.gmail.com
   4d0b6c82.1030...@yorku.ca
 Date: Sat, 18 Dec 2010 08:54:16 -0500
 Delivered-To: rshm...@gmail.com
 Message-ID:
 aanlktikhjt8t+ao4qnj8zracubnk+hspga+jqg3o4...@mail.gmail.com
 Subject: Re: Subarray specification problem
 From: Roy Shimizu rshm...@gmail.com
 To: r-help@r-project.org
 Content-Type: text/plain; charset=ISO-8859-1
 
 
 If anyone can tell what set off the filter, please let me know.
 
 Thanks!
 
 Hoping that this message doesn't get filtered too,
 
 Roy
 


E-Mail: (Ted Harding) ted.hard...@wlandres.net
Fax-to-email: +44 (0)870 094 0861
Date: 18-Dec-10   Time: 15:18:26
-- 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] dotchart for matrix data

2010-12-18 Thread e-letter
On 18/12/2010, David Winsemius dwinsem...@comcast.net wrote:

 On Dec 18, 2010, at 7:01 AM, e-letter wrote:

 Readers,

 I am trying to use the function dotchart. The data is:

 testdot
  category values1 values2 values3 values4
 1a  10  27  56 709
 2b   4  46  47 208
 3c   5  17  18 109
 4d   6  50  49 308

 The following error occurs

 dotchart(testdot,groups=testdot[,2])
 Error in dotchart(testdot, labels = testdot[, 1], groups = testdot[,
 2]) :
'x' must be a numeric vector or matrix

 According to my understanding (clearly wrong!) of the documentation
 for dotchart (accessed from the manual in section 'graphics'), columns
 of data can be selected by 'groups' for subsequent plotting.

 The misunderstanding is in how you see the grouping information versus
 how R expects it. R generally expects such data in what is called
 long format, i.e. there will be one values columns and a category
 column. There are various ways to change the arrangement of your data.
 The function stack(), the function reshape(), or probably most
 commonly the function melt from reshape2 being the typical chosen
 routes.


Reshape and melt are not installed (version251) so for this task
manual rearrangement data is easier.

 require(reshape)
Loading required package: reshape
[1] FALSE
Warning message:
there is no package called 'reshape' in: library(package, lib.loc =
lib.loc, character.only = TRUE, logical = TRUE,
 library(reshape)
Error in library(reshape) : there is no package called 'reshape'
 mdot-melt(dot)
Error: could not find function melt

However before doing so why this is relevant because of the
alternative creation objects 'testdot1'. Aren't these objects
suitable, since a (undesireable) graph was produced?

 The
 objective is to be able to create a dot chart where each row is
 labelled according to the row names in the 'category' column and two
 columns can be selected, e.g. 'values1' and 'values2'. Then I tried:

 testdot1-testdot[,1]
 testdot2-testdot[,2]
 testdot3-testdot[,3]
 dotchart(c(testdot2,testdot3),labels=testdot1)

 See if this is more to your liking:

 require(reshape)   # I'm not sure why I have reshape_0.8.3 rather than
 reshape2 loaded
 # I'm pretty sure Hadley would prefer that people
 use pkg:reshape2
   mdot - melt(dot)
 dotchart(mdot$value, groups=mdot$category, labels=mdot$variable)
 # OR more readable
 with(mdot, dotchart(value, groups=category, labels=variable)  )

 I'm not sure I got the roles of values and category correct, but
 it should be a simple matter to switch them in the dotcghart call if
 that is your pleasuRe.


I don't have dotcghart either.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] association analysis with multiple outcome variables

2010-12-18 Thread Giambartolomei, Claudia
Hi,

I am using the package snpMatrix to do a genetic association analysis, but my 
problem is I think a simple R trick (sorry...I am an R newbie so I apologize in 
advance if I am not using the correct terms...)
I am trying to figure out a way to loop through different dependent variables 
without having to repeat the analysis for each.

My genotype data is stored in a raw object of class snp.matrix (called 
snp.matrix), in which the column names are the SNP names and the row names 
are the subject identifiers:

 snp.mat...@.datamailto:snp.mat...@.data[1:5,1:5[1:5,1:5mailto:snp.mat...@.data[1:5,1:5]
   Broad10449636 Broad10450135 Broad10459352 Broad10462884
P16001211703030303
P16001446603030303
P16002112303010303
P16005210703030303
P16005390503030303
   Broad10468812
P16001211703
P16001446603
P16002112303
P16005210703
P16005390503
My phenotype data is stored in data frame called pheno and it contains my 
dependent variables that I want to use the loop with, and also some important 
variables that I want to keep constant in the model as covariates (age and sex).

 head(pheno)

   IDOUT  SEX   ETHN  AGE BMI APO_A  CHOL 
LDL
P160012117   P160012117   2   1 59   NA NA  NA 
NA
P160014466   P160014466   2   1 6026.880921.927.38 5.59
P160021123   P160021123   2   1 5428.685832.395.80 3.63
P160052107   P160052107   2   1 4822.597572.517.25 5.03
P160053905   P160053905   2   1 4620.331012.526.40 4.39
P160076582   P160076582   2   1 5023.840642.194.47 2.74
The association works for the single terms when I do this: (using the formula 
snp.rhs.test):


BMI-snp.rhs.tests(BMI~SEX+AGE,family=gaussian,snp.data=snp.matrix)

And then changing the result file which is an S4 object into a matrix doing 
this:

res - data.frame (SNPs= names(BMI), pvalues = p.value(BMI))



But when I try to create a loop through the other independent variables it does 
not work anymore.

This is what I am doing:



#Created a file with only the variables to use in the loop:

pheno2-subset(pheno, select=c(IDOUT, BMI, APO_A, CHOL, LDL))



for (cov in names(pheno2)) {

res-snp.rhs.tests(as.formula(paste(pheno2$cov, 
~pheno$SEX+pheno$AGE)),family=gaussian,snp.data=snp.matrix)

res - data.frame (SNPs= names(HDL.reg.rhs), pvalues = p.value(HDL.reg.rhs))

output.file - paste('myres_', cov, '.tab', sep = '')

write.table(res, file = output.file, sep = '\t', quote = FALSE, row.names = 
FALSE)

print(output.file)

}



But I get the following error:

Error in snp.rhs.tests(as.formula(paste(pheno3$cov, 
~pheno2$SEX+pheno2$XAGE_C)),  :
  Argument error - Y



I have been looking for this error but I cannot find anything on the help 
pages...If you could help me figure this out it would be great!!



Thank you very much in advance!

- claudia

[[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] dotchart for matrix data

2010-12-18 Thread e-letter
Ben Bolker
Sat, 18 Dec 2010 07:07:24 -0800
David Winsemius dwinsemius at comcast.net writes:



 On Dec 18, 2010, at 7:01 AM, e-letter wrote:

  Readers,
 
  I am trying to use the function dotchart. The data is:
 
  testdot
   category values1 values2 values3 values4
  1a  10  27  56 709
  2b   4  46  47 208
  3c   5  17  18 109
  4d   6  50  49 308
 
  The following error occurs
 
  dotchart(testdot,groups=testdot[,2])
  Error in dotchart(testdot, labels = testdot[, 1], groups = testdot[,
  2]) :
 'x' must be a numeric vector or matrix
 
  According to my understanding (clearly wrong!) of the documentation
  for dotchart (accessed from the manual in section 'graphics'), columns
  of data can be selected by 'groups' for subsequent plotting.


  Following up on David's response:


d - read.table(textConnection(category values1 values2 values3 values4
1a  10  27  56 709
2b   4  46  47 208
3c   5  17  18 109
4d   6  50  49 308),
header=TRUE)

## Something like this is probably as close as you can get with
## stock 'dotchart' -- it does *not* (as far as I can tell) put
## different points on the same line, just groups lines


I am trying to create a chart like this
(http://www.b-eye-network.com/images/content/Fig4_3.jpg); so this is
not possible using R?

dotchart(as.matrix(d[,-1]),labels=as.character(d[,1]))
dotchart(as.matrix(d[,c(values1,values2)]),labels=as.character(d[,1]))

## reshaping data:
library(reshape)
mdot - melt(d)

## using the lattice package

library(lattice)
dotplot(value~category,groups=variable,data=mdot)
dotplot(value~variable,groups=category,data=mdot,auto.key=TRUE,
scales=list(y=list(log=10)))

## you could also use ggplot2 ...

 ?ggplot2

No documentation for 'ggplot2' in specified packages and libraries:
you could try 'help.search(ggplot2)'; seems I need to retrieve this
package first. Thanks for the suggestion.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] [BioC] problem with function

2010-12-18 Thread Iain Gallagher
Hi Christian, Chuck (and lists)

It seems that the problem may be the strange behaviour of 'unstack' inside a 
function. 

See this thread in the R mailing list:

http://tolstoy.newcastle.edu.au/R/help/04/03/1160.html

Anyway, I got round the problem by using 'aggregate' instead of converting to a 
list and then tapply to sum values of metric. Probably more efficient as well.

Thanks for the help offered.

My function now looks like this (for the record!) and behaves as it should.

makeMetric - function(deMirPresGenes, deMirs){
    
#need to match position of each miR in deMirPresGenes with its FC to form a 
vector of FC in correct order
    
    fcVector - as.numeric(with (deMirs, FC[match(deMirPresGenes[,4], Probe)] ) 
)

    #multiply fc by context score for each interaction    
    metric - fcVector * as.numeric(deMirPresGenes[,11])

    geneMetric - cbind(deMirPresGenes[,2], metric)
    colnames(geneMetric) - c('sym', 'metric')
    


    #make cumul by aggregate
    listMetric - aggregate(as.numeric(geneMetric[,2]), list(geneMetric[,1]), 
sum)#returns a dataframe
    colnames(listMetric) - c('symbol','cumulMetric')
    
    #return whole list
    return(listMetric)# dataframe
}

Cheers

i

--- On Sat, 18/12/10, cstrato cstr...@aon.at wrote:

 From: cstrato cstr...@aon.at
 Subject: Re: [BioC] problem with function
 To: Iain Gallagher iaingallag...@btopenworld.com
 Cc: bioconductor bioconduc...@stat.math.ethz.ch
 Date: Saturday, 18 December, 2010, 14:40
 You need to do:
 
 cumulMetric - function(deMirPresGenes, deMirs){
     fc - deMirs
     fcVector - as.numeric(with (fc,
 FC[match(deMirPresGenes[,4], Probe)] ) )
 
     metric - fcVector *
 as.numeric(deMirPresGenes[,11])
     geneMetric -
 as.data.frame(cbind(deMirPresGenes[,2],
 as.numeric(metric)))
     colnames(geneMetric) - c('y', 'x')
 
     listMetric - unstack(geneMetric, x ~
 y)
     listMetric -
 as.data.frame(sapply(listMetric,sum)) #returns a dataframe
     colnames(listMetric) -
 c('cumulMetric')
 
     return(listMetric)
 }
 
 Regards
 Christian
 
 On 12/17/10 11:52 PM, Iain Gallagher wrote:
  ok... done. Not really any further forward here.
 
  print statements after creating fcVector, metric and
 geneMetric (see output below). They all look ok in terms of
 structure and length. But the error persists and listMetric
 is not made?!?! Odd.
 
  I have added some comments to the output below.
 
  tf2-cumulMetric(tf1, deMirs$up)#deMirs$up is a
 dataframe (see prev posts)
  [1] 2.63 2.63 3.13 2.63 3.13 2.74 # print fcVector -
 looks ok
  [1] -0.35505 -0.34979 -1.03290 -1.22558 -0.61348
 -0.86584 # print metric - looks ok
  [1] 1045 # lengthof metric - is correct
        sym     
 metric    # print geneMetric - looks ok
  [1,] AAK1   -0.35505
  [2,] ABCA1  -0.34979
  [3,] ABCA2  -1.0329
  [4,] ABCB10 -1.22558
  [5,] ABCE1  -0.61348
  [6,] ABCF3  -0.86584
  [1] 1045 # nrow of geneMetric - is correct
  Error in eval(expr, envir, enclos) : object
 'geneMetric' not found
 
 
  cheers
 
  i
  --- On Fri, 17/12/10, cstratocstr...@aon.at 
 wrote:
 
  From: cstratocstr...@aon.at
  Subject: Re: [BioC] problem with function
  To: Iain Gallagheriaingallag...@btopenworld.com
  Cc: bioconductorbioconduc...@stat.math.ethz.ch
  Date: Friday, 17 December, 2010, 22:38
  At the moment I have no idea, but
  what I would do in this case is to put
  print() statements after each line to see where it
 fails.
 
  Christian
 
  On 12/17/10 10:59 PM, Iain Gallagher wrote:
  Hi
 
  FC is the second column of the deMirs
 variable. deMirs
  is a dataframe with 2 columns - Probe (e.g.
 hsa-miR-145) and
  FC (e.g 1.45). Using 'with' allows me to use
 deMirs as an
  'environment'. I thus don't have to pass FC
 explicitly.
 
  Cheers
 
  i
 
  --- On Fri, 17/12/10, cstratocstr...@aon.at
  wrote:
 
  From: cstratocstr...@aon.at
  Subject: Re: [BioC] problem with function
  To: Iain Gallagheriaingallag...@btopenworld.com
  Cc: bioconductorbioconduc...@stat.math.ethz.ch
  Date: Friday, 17 December, 2010, 20:39
  What is FC[]?  It is not passed
  to the function. Christan
 
  On 12/17/10 8:11 PM, Iain Gallagher
 wrote:
  Sorry.
 
  That was a typo. In my script
  deMirPresGenes1[,4] is
  deMirPresGenes[,4].
 
  Just to be sure I'm going about this
 the right
  way
  though I should say that at the moment I
 assign
  the output
  of another function to a variable called
 'tf1' -
  this object
  is the same as the deMirPresGenes is my
 previous
  email.
 
  This is then fed to my problem
 function using
  positional matching.
 
  e.g. tf2- cumulMetric(tf1,
 deMirs)
 
  Which leads to:
 
  Error in eval(expr, envir, enclos) :
 object
  'geneMetric' not found
 
  Hey ho!
 
  i
 
  --- On Fri, 17/12/10, cstratocstr...@aon.at
  wrote:
 
  From: cstratocstr...@aon.at
  Subject: Re: [BioC] problem with
 function
  To: Iain Gallagheriaingallag...@btopenworld.com
  Cc: bioconductorbioconduc...@stat.math.ethz.ch
  Date: Friday, 17 December, 2010,
 18:40
  I am not sure but I would say
 

[R] association analysis with multiple outcome variables

2010-12-18 Thread Giambartolomei, Claudia
Hi,

I am using the package snpMatrix to do a genetic association analysis, but my 
problem is I think a simple R trick (sorry...I am an R newbie so I apologize in 
advance if I am not using the correct terms...)
I am trying to figure out a way to loop through different dependent variables 
without having to repeat the analysis for each.

My genotype data is stored in a raw object of class snp.matrix (called 
snp.matrix), in which the column names are the SNP names and the row names 
are the subject identifiers:

 snp.mat...@.datamailto:snp.mat...@.data[1:5,1:5[1:5,1:5mailto:snp.mat...@.data[1:5,1:5]
   Broad10449636 Broad10450135 Broad10459352 Broad10462884
P16001211703030303
P16001446603030303
P16002112303010303
P16005210703030303
P16005390503030303
   Broad10468812
P16001211703
P16001446603
P16002112303
P16005210703
P16005390503
My phenotype data is stored in data frame called pheno and it contains my 
dependent variables that I want to use the loop with, and also some important 
variables that I want to keep constant in the model as covariates (age and sex).

 head(pheno)

   IDOUT  SEX   ETHN  AGE BMI APO_A  CHOL 
LDL
P160012117   P160012117   2   1 59   NA NA  NA 
NA
P160014466   P160014466   2   1 6026.880921.927.38 5.59
P160021123   P160021123   2   1 5428.685832.395.80 3.63
P160052107   P160052107   2   1 4822.597572.517.25 5.03
P160053905   P160053905   2   1 4620.331012.526.40 4.39
P160076582   P160076582   2   1 5023.840642.194.47 2.74
The association works for the single terms when I do this: (using the formula 
snp.rhs.test):


BMI-snp.rhs.tests(BMI~SEX+AGE,family=gaussian,snp.data=snp.matrix)

And then changing the result file which is an S4 object into a matrix doing 
this:

res - data.frame (SNPs= names(BMI), pvalues = p.value(BMI))



But when I try to create a loop through the other independent variables it does 
not work anymore.

This is what I am doing:



#Created a file with only the variables to use in the loop:

pheno2-subset(pheno, select=c(IDOUT, BMI, APO_A, CHOL, LDL))



for (cov in names(pheno2)) {

res-snp.rhs.tests(as.formula(paste(pheno2$cov, 
~pheno$SEX+pheno$AGE)),family=gaussian,snp.data=snp.matrix)

res - data.frame (SNPs= names(HDL.reg.rhs), pvalues = p.value(HDL.reg.rhs))

output.file - paste('myres_', cov, '.tab', sep = '')

write.table(res, file = output.file, sep = '\t', quote = FALSE, row.names = 
FALSE)

print(output.file)

}



But I get the following error:

Error in snp.rhs.tests(as.formula(paste(pheno3$cov, 
~pheno2$SEX+pheno2$XAGE_C)),  :
  Argument error - Y



I have been looking for this error but I cannot find anything on the help 
pages...If you could help me figure this out it would be great!!



Thank you very much in advance!

- claudia

[[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] dotchart for matrix data

2010-12-18 Thread Peter Ehlers

On 2010-12-18 07:50, e-letter wrote:

Ben Bolker
Sat, 18 Dec 2010 07:07:24 -0800


[... snip ...]


I am trying to create a chart like this
(http://www.b-eye-network.com/images/content/Fig4_3.jpg); so this is
not possible using R?


That looks an awful lot like what lattice's dotplot would
produce. So: have you tried dotplot() as Ben has suggested?

Peter Ehlers




dotchart(as.matrix(d[,-1]),labels=as.character(d[,1]))
dotchart(as.matrix(d[,c(values1,values2)]),labels=as.character(d[,1]))

## reshaping data:
library(reshape)
mdot- melt(d)

## using the lattice package

library(lattice)
dotplot(value~category,groups=variable,data=mdot)
dotplot(value~variable,groups=category,data=mdot,auto.key=TRUE,
scales=list(y=list(log=10)))

## you could also use ggplot2 ...



?ggplot2


No documentation for 'ggplot2' in specified packages and libraries:
you could try 'help.search(ggplot2)'; seems I need to retrieve this
package first. Thanks for the suggestion.

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


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


[R] using ls() to find a function

2010-12-18 Thread Carl Witthoft

Oddly enough, I posted my little cutie recently:


lstype-function(type='closure'){
#   

inlist-ls(.GlobalEnv)
if (type=='function') type -'closure'
typelist-sapply(sapply(inlist,get),typeof)
return(names(typelist[typelist==type]))
}


And, not useful for functions, but to find the size of a pile of data 
objects,


thefloats-lstype('numeric')
sapply(sapply(sapply(sapply(thefloats,get),unlist),as.vector),length)

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Colours for 3-way probabilities

2010-12-18 Thread Carl Witthoft

There are a couple Venn Diagram functions out there.

But I would strongly recommend against making charts like this.  There 
are too many colors, and even non-colorblind people will find them to be 
a pain to discriminate, let alone remember what the coding means.


Assuming you want to show the distribution on a cartographic map,  maybe 
a mini-barchart in each state or county would be better, or three 
non-overlapping 'bubbles' whose diameter or area maps to votecount.


Tufte has written a bunch about this sort of problem.


quote
Are there any R functions for creating palettes for three-way data? For 
example, election maps for three parties where pure red, blue, and green 
show 100% for the Red, Blue, and Green parties respectively, magenta 
shows a 50-50 Red-Blue split with 0 for the Greens, cyan a 50-50 
Blue/Green split with no Red votes and so on, with grey, black or white 
at a 1/3,1/3,1/3 split vote.


I've spent a couple of half hours knocking out a function to do various 
versions of that, including using Red/Yellow/Blue for the primaries with 
Orange/Green/Purple for the 50/50s. I'm wondering if


   1. There's existing functionality in one of the packages on CRAN 
(I've had a look and googled)
   2. Anyone can point me to information about colour perception of 
this kind of three-way colour scheme.


Thanks muchly.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] use of 'apply' for 'hist'

2010-12-18 Thread casperyc

Hi all,

##
dof=c(1,2,4,8,16,32)
Q5=matrix(rt(100,dof),100,6,T,dimnames=list(NULL,dof))
par(mfrow=c(2,6))
apply(Q5,2,hist)
myf=function(x){ qqnorm(x);qqline(x) }
apply(Q5,2,myf)
##

These looks ok.
However, I would like to achieve more.

Apart from using a loop,
is there are fast way to 'add' the titles to be more informative?

that is, in the histograms, I want the titles to be 't distribution with
dof=' the degrees of freedom.

I have tried 
apply(Q5,2,hist,xnames=dof)
which does not work;
apply(Q5,2,hist(,xnames=dof));
does not work either

and similarly, how do I add titles to qqnorm plot 
to make them informative?

Thanks!

casper


-- 
View this message in context: 
http://r.789695.n4.nabble.com/use-of-apply-for-hist-tp3093811p3093811.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] using ls() to find a function

2010-12-18 Thread Henrique Dallazuanna
Try this:

ls.str(mode = 'function')

On Sat, Dec 18, 2010 at 2:39 PM, Carl Witthoft c...@witthoft.com wrote:

 Oddly enough, I posted my little cutie recently:


 lstype-function(type='closure'){
 #

inlist-ls(.GlobalEnv)
if (type=='function') type -'closure'
typelist-sapply(sapply(inlist,get),typeof)
return(names(typelist[typelist==type]))
 }


 And, not useful for functions, but to find the size of a pile of data
 objects,

 thefloats-lstype('numeric')
 sapply(sapply(sapply(sapply(thefloats,get),unlist),as.vector),length)

 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/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

[[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] dotchart for matrix data

2010-12-18 Thread e-letter
On 18/12/2010, Peter Ehlers ehl...@ucalgary.ca wrote:
 On 2010-12-18 07:50, e-letter wrote:
 Ben Bolker
 Sat, 18 Dec 2010 07:07:24 -0800

 [... snip ...]

 I am trying to create a chart like this
 (http://www.b-eye-network.com/images/content/Fig4_3.jpg); so this is
 not possible using R?

 That looks an awful lot like what lattice's dotplot would
 produce. So: have you tried dotplot() as Ben has suggested?


Unfortunately I have been unable to use the melt package; 3 mirrors
have failed to install. What I don't understand is why the objects
created are not in the correct format, otherwise how would the plot be
created?

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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 use paste in function for expression?

2010-12-18 Thread casperyc

Hi all,
##
dof=c(1,2,4,8,16,32)
Q5=matrix(rt(100,dof),100,6,T,dimnames=list(NULL,dof))
par(mfcol=c(2,6))
for (i in 1:6){
dof2=dof[i]
hist(Q5[,i],main=paste(t[,dof2,],sep=))
qqnorm(Q5[,i])
qqline(Q5[,i])
}
##

In this loop, I want to use
expression(t[1])
expression(t[2])
expression(t[4])
...

in the histogram as main title

how do I use expression and paste correctly?

I have tried 
hist(Q5[,i],main=expression(paste(t[,dof2,],sep=)))
does not work

Thanks.

casper
-- 
View this message in context: 
http://r.789695.n4.nabble.com/how-to-use-paste-in-function-for-expression-tp3093822p3093822.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] how to use paste in function for expression?

2010-12-18 Thread Dieter Menne


casperyc wrote:
 
 ... Expression in lattice  example
 
 hist(Q5[,i],main=expression(paste(t[,dof2,],sep=)))does not work
 

dof=c(1,2,4,8,16,32)
Q5=matrix(rt(100,dof),100,6,T,dimnames=list(NULL,dof))
par(mfcol=c(2,6))
for (i in 1:6){
dof2=dof[i]
hist(Q5[,i],main=bquote(t[.(dof2)]))
qqnorm(Q5[,i])
qqline(Q5[,i])
}

See
http://r-project.markmail.org/thread/ui3vztyvafyar76f


-- 
View this message in context: 
http://r.789695.n4.nabble.com/how-to-use-paste-in-function-for-expression-tp3093822p3093835.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] use of 'apply' for 'hist'

2010-12-18 Thread Sarah Goslee
Hi,

You can't access the column names from within apply, I'm afraid.
This has been covered previously:
http://www.mail-archive.com/r-help@stat.math.ethz.ch/msg51014.html

That's one of the cases where you actually need to use a for() loop,
though I suppose you could also write something vectorized on the
column names themselves rather than the data frame.

And also, you should check your colnames(Q5) - I don't think they
are what you expect.

Sarah

On Sat, Dec 18, 2010 at 11:49 AM, casperyc caspe...@hotmail.co.uk wrote:

 Hi all,

 ##
 dof=c(1,2,4,8,16,32)
 Q5=matrix(rt(100,dof),100,6,T,dimnames=list(NULL,dof))
 par(mfrow=c(2,6))
 apply(Q5,2,hist)
 myf=function(x){ qqnorm(x);qqline(x) }
 apply(Q5,2,myf)
 ##

 These looks ok.
 However, I would like to achieve more.

 Apart from using a loop,
 is there are fast way to 'add' the titles to be more informative?

 that is, in the histograms, I want the titles to be 't distribution with
 dof=' the degrees of freedom.

 I have tried
 apply(Q5,2,hist,xnames=dof)
 which does not work;
 apply(Q5,2,hist(,xnames=dof));
 does not work either

 and similarly, how do I add titles to qqnorm plot
 to make them informative?

 Thanks!

 casper


 --



-- 
Sarah Goslee
http://www.functionaldiversity.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] determine length of sequence of equal elements in a vector

2010-12-18 Thread Jannis

Dear list members,


I am seeking a function that returns me the length of a continous 
sequence of identical elements in a vector. Something like (or similar to):



example = c(1,1,1,2,2,3,3,3,3)


result = c(3,3,3,2,2,4,4,4,4)


I am quite sure there already exists a function to do this, I just cant 
figure out its name. Otherwise I would start programming my own function.




Best
Jannis

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] use of 'apply' for 'hist'

2010-12-18 Thread Dieter Menne


casperyc wrote:
 
 Hi all,
 
 ##
 dof=c(1,2,4,8,16,32)
 Q5=matrix(rt(100,dof),100,6,T,dimnames=list(NULL,dof))
 par(mfrow=c(2,6))
 apply(Q5,2,hist)
 myf=function(x){ qqnorm(x);qqline(x) }
 apply(Q5,2,myf)
 ##
 
 Apart from using a loop, is there are fast way to 'add' the titles to be
 more informative?
 
 

If you type apply (no ()) you will find that it is not much more than an
decorated generic loop. I believe that this is case where using a loop.
Otherwise, you could convert you matrix to a data frame, add the degrees of
freedom too much work for a loop where plotting anyway has the largest
overhead.

Others may disagree, but I believe the apply-wars have ended at the time
when browser wars ended.

Dieter

-- 
View this message in context: 
http://r.789695.n4.nabble.com/use-of-apply-for-hist-tp3093811p3093847.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] determine length of sequence of equal elements in a vector

2010-12-18 Thread Duncan Murdoch

On 18/12/2010 12:21 PM, Jannis wrote:

Dear list members,


I am seeking a function that returns me the length of a continous
sequence of identical elements in a vector. Something like (or similar to):


example = c(1,1,1,2,2,3,3,3,3)


result = c(3,3,3,2,2,4,4,4,4)


I am quite sure there already exists a function to do this, I just cant
figure out its name. Otherwise I would start programming my own function.


The rle() function produces the data in a different format.  Together 
with rep() you can get what you want:


x - rle(example)
rep(x$lengths, x$lengths)

Duncan Murdoch

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] dotchart for matrix data

2010-12-18 Thread David Winsemius


On Dec 18, 2010, at 11:58 AM, e-letter wrote:


On 18/12/2010, Peter Ehlers ehl...@ucalgary.ca wrote:

On 2010-12-18 07:50, e-letter wrote:

Ben Bolker
Sat, 18 Dec 2010 07:07:24 -0800


[... snip ...]


I am trying to create a chart like this
(http://www.b-eye-network.com/images/content/Fig4_3.jpg); so this is
not possible using R?


That looks an awful lot like what lattice's dotplot would
produce. So: have you tried dotplot() as Ben has suggested?



Unfortunately I have been unable to use the melt package; 3 mirrors
have failed to install. What I don't understand is why the objects
created are not in the correct format, otherwise how would the plot be
created?


There is no melt package. There is a reshape package and a reshape2  
package, either of which will have melt as a function.





__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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
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] determine length of sequence of equal elements in a vector

2010-12-18 Thread Jannis

Thanks a lot, Duncan.


Duncan Murdoch schrieb:

On 18/12/2010 12:21 PM, Jannis wrote:

Dear list members,


I am seeking a function that returns me the length of a continous
sequence of identical elements in a vector. Something like (or 
similar to):



example = c(1,1,1,2,2,3,3,3,3)


result = c(3,3,3,2,2,4,4,4,4)


I am quite sure there already exists a function to do this, I just cant
figure out its name. Otherwise I would start programming my own 
function.


The rle() function produces the data in a different format.  Together 
with rep() you can get what you want:


x - rle(example)
rep(x$lengths, x$lengths)

Duncan Murdoch



__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] use of 'apply' for 'hist'

2010-12-18 Thread casperyc

Thanks Dieter.

Casper
-- 
View this message in context: 
http://r.789695.n4.nabble.com/use-of-apply-for-hist-tp3093811p3093938.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] use of 'apply' for 'hist'

2010-12-18 Thread casperyc

HI Sarah,

I will just use a loop then.

I think my colnames are fine.

Thanks!

casper 
-- 
View this message in context: 
http://r.789695.n4.nabble.com/use-of-apply-for-hist-tp3093811p3093937.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-sig-DB Digest, Vol 74, Issue 2

2010-12-18 Thread Nilza BARROS
 Hi,
Your mistake is related with   read.table(n). I haven`t got what you want
but I put an example below (where I used loop to read many files). Hope it
helps. Anyway, I thougth should have sent your question to

r-help@r-project.org.
Bye
Nilza


=example 
nomesout - dir(dat.dir,pattern=^[s]) #obtem no diretorio de atual todos
arquivo iniciado com a letra s

OUT - read.table(paste(dat.dir,nomesout[1] ,sep = ),header = FALSE, sep =
,, na.strings = c(/,///,,/,//))

for(i in 2:length(nomesout)){

Y - read.table(paste(dat.dir,nomesout[i] ,sep = ),header = FALSE, sep =
,)

OUT - rbind(OUT, Y)

}

OUT - OUT[-1,] ## Remove linhas em branco


On Fri, Dec 17, 2010 at 9:00 AM, r-sig-db-requ...@r-project.org wrote:

 Send R-sig-DB mailing list submissions to
r-sig...@r-project.org

 To subscribe or unsubscribe via the World Wide Web, visit
https://stat.ethz.ch/mailman/listinfo/r-sig-db
 or, via email, send a message with subject or body 'help' to
r-sig-db-requ...@r-project.org

 You can reach the person managing the list at
r-sig-db-ow...@r-project.org

 When replying, please edit your Subject line so it is more specific
 than Re: Contents of R-sig-DB digest...


 Today's Topics:

   1. Help with loop (Daniel)


 --

 Message: 1
 Date: Thu, 16 Dec 2010 21:47:47 -0200
 From: Daniel dms...@gmail.com
 To: r-sig...@stat.math.ethz.ch
 Subject: [R-sig-DB] Help with loop
 Message-ID:
aanlktik0goa-khuoftqocj4uv-c81tlkcesgkdtf3...@mail.gmail.com
 Content-Type: text/plain

 Hello all,
 Is there a way to get each file from a website list and aggregate in a
 unique file?
 Otherwise I have to type 23 thousand web address into a long script like
 it:

 base1 - read.table(site 1, sep=;, header=T,
 fileEncoding=windows-1252)
 base2 - read.table(site 2, sep=;, header=T,
 fileEncoding=windows-1252)

 I need to download each .CSV file from each web address and rbind all
 them
 into one data frame.
 Also I need to translate each object to UTF-8. Of course many of address
 maybe be empty, so, my loop can't stops because this.

 I never type a loop before, so, in my first shot I get an error. Can
 somebody help me?

 myresult - NULL
 n -length(mysites)
 for (i in 1:n) {
  bases - read.table(n)
  bases[i]-read.table(mysites[[i]], sep=;, header=TRUE,
 fileEncoding=windows-1252)
 tudo - rbind(myresult, bases)
 }

 Error in read.table(n) : 'file' must be a character string or connection
 --
 Daniel Marcelino
 Skype: dmsilv
 www.sites.google.com/site/politicaevoce/ http://bit.ly/pol4vc

[[alternative HTML version deleted]]



 --

 ___
 R-sig-DB mailing list
 r-sig...@r-project.org
 https://stat.ethz.ch/mailman/listinfo/r-sig-db


 End of R-sig-DB Digest, Vol 74, Issue 2
 ***




-- 
Abraço,
Nilza Barros

[[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] use of 'apply' for 'hist'

2010-12-18 Thread Gabor Grothendieck
On Sat, Dec 18, 2010 at 11:49 AM, casperyc caspe...@hotmail.co.uk wrote:

 Hi all,

 ##
 dof=c(1,2,4,8,16,32)
 Q5=matrix(rt(100,dof),100,6,T,dimnames=list(NULL,dof))
 par(mfrow=c(2,6))
 apply(Q5,2,hist)
 myf=function(x){ qqnorm(x);qqline(x) }
 apply(Q5,2,myf)
 ##

 These looks ok.
 However, I would like to achieve more.

 Apart from using a loop,
 is there are fast way to 'add' the titles to be more informative?

 that is, in the histograms, I want the titles to be 't distribution with
 dof=' the degrees of freedom.

 I have tried
 apply(Q5,2,hist,xnames=dof)
 which does not work;
 apply(Q5,2,hist(,xnames=dof));
 does not work either

 and similarly, how do I add titles to qqnorm plot
 to make them informative?

Loop over the column headings rather than over the data itself.  Be
sure that dof has class character.  Always include set.seed if you
post random numbers to r-help so the results are reproducible.  Always
change the par() back after you are finished.  A number of other
stylistic improvements are shown below as well.  Change main= and
xlab= as you like.

set.seed(123)
dof - as.character(c(1,2,4,8,16,32))
Q5 - matrix(rt(100, dof), 100, 6, T, dimnames = list(NULL, dof))
opar - par(mfrow = c(2, 6))
sapply(dof, function(x) hist(Q5[, x], main = x, xlab = ))
myf - function(x) { qqnorm(Q5[, x], main = x, xlab = ); qqline(Q5[, 
x]) }
sapply(dof, myf)
par(opar)


-- 
Statistics  Software Consulting
GKX Group, GKX Associates Inc.
tel: 1-877-GKX-GROUP
email: ggrothendieck at gmail.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] dotchart for matrix data

2010-12-18 Thread David Winsemius


On Dec 18, 2010, at 1:27 PM, e-letter wrote:


On 18/12/2010, Peter Ehlers ehl...@ucalgary.ca wrote:

On 2010-12-18 07:50, e-letter wrote:

Ben Bolker
Sat, 18 Dec 2010 07:07:24 -0800


[... snip ...]


I am trying to create a chart like this
(http://www.b-eye-network.com/images/content/Fig4_3.jpg); so this is
not possible using R?


That looks an awful lot like what lattice's dotplot would
produce. So: have you tried dotplot() as Ben has suggested?



For the benefit of other novices, this is what I did (gnu/linux):

sign-in to a command terminal as root
start R
install.packages(reshape2)

In another terminal as normal user

require(reshape2)
mdot-melt(testdot)
dotplot(value~category,groups=variable,data=mdot)

The resultant graph shows the categories on the abscissa and there
does not seem to be a way of selecting two columns from the original
matrix. It is not like the graph cited in the hyperlink quoted above,
but at least I have successfully followed instructions!


If you want to see a worked example of a dotplot that has two separate  
data series on the same set of lines then look at Fig 10.18 in  
Sarkar's Lattice. The illustration and code are all at the book's  
website. I don't think you did a very good job of explaining in text  
what you expected to see (at least on my reading of it more than once)  
but this may do what you hoped:


dotplot(as.character(mdot$category) ~ mdot$value, labels=mdot$variable)



I changed the axes with the command:

dotplot(category~value,groups=variable,data=mdot)

I believe there is a command to select only certain rows of data which
I think will achieve the desired graph, if unable I'll ask again, so
thank you all.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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
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] pdf package help files

2010-12-18 Thread eric

Newbie here...just learning

Do most packages come with pdf versions of the help files ? If yes, how to I
access the entire pdf file to be able to print it ? Is there a standard
command for that ? 
-- 
View this message in context: 
http://r.789695.n4.nabble.com/pdf-package-help-files-tp3093926p3093926.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] how to use expression as function arguements?

2010-12-18 Thread casperyc

Hi all,

#
integ=function(f,n){ 
# computes vector y = f(x)
x=runif(1)
y=f
hatI=mean(y)
hatI
}
# example of use
integ(x^2+x+100,100)
#
it returns an error says no obj 'x'

how do I 'tell' R to treat 'f' as an input expression?

Thanks.

casper
-- 
View this message in context: 
http://r.789695.n4.nabble.com/how-to-use-expression-as-function-arguements-tp3093940p3093940.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] pdf package help files

2010-12-18 Thread David Winsemius


On Dec 18, 2010, at 2:20 PM, eric wrote:



Newbie here...just learning

Do most packages come with pdf versions of the help files ? If yes,  
how to I
access the entire pdf file to be able to print it ? Is there a  
standard

command for that ?


There may be one but I don't know it if there is. The pdf files to  
which you refer are usually in the doc directory for each package (and  
can be found at CRAN as well). For example on my standard nstallation  
of R2.12 the pdf describing the gsubfn package is found it in:
/Library/Frameworks/R.framework/Versions/2.12/Resources/library/gsubfn/ 
doc/gsubfn.pdf


Each OS is different but once you find the root of R's installation  
there should be library and package sub-directories with doc sub- 
sub-directories. Not all packages have such a directory. The first one  
I looked in was lattice and I could not find one.




--
View this message in context: 
http://r.789695.n4.nabble.com/pdf-package-help-files-tp3093926p3093926.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
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] dotchart for matrix data

2010-12-18 Thread Peter Ehlers

On 2010-12-18 10:27, e-letter wrote:

On 18/12/2010, Peter Ehlersehl...@ucalgary.ca  wrote:

On 2010-12-18 07:50, e-letter wrote:

Ben Bolker
Sat, 18 Dec 2010 07:07:24 -0800


[... snip ...]


I am trying to create a chart like this
(http://www.b-eye-network.com/images/content/Fig4_3.jpg); so this is
not possible using R?


That looks an awful lot like what lattice's dotplot would
produce. So: have you tried dotplot() as Ben has suggested?



For the benefit of other novices, this is what I did (gnu/linux):

sign-in to a command terminal as root
start R
install.packages(reshape2)

In another terminal as normal user

require(reshape2)
mdot-melt(testdot)
dotplot(value~category,groups=variable,data=mdot)

The resultant graph shows the categories on the abscissa and there
does not seem to be a way of selecting two columns from the original
matrix. It is not like the graph cited in the hyperlink quoted above,
but at least I have successfully followed instructions!


It seems to me that you're getting exactly the plot referred
to by the link, except that you have a factor with 4 levels, not 2.



I changed the axes with the command:

dotplot(category~value,groups=variable,data=mdot)

I believe there is a command to select only certain rows of data which
I think will achieve the desired graph, if unable I'll ask again, so
thank you all.


See if the 'subset=' argument works for you:

 dotplot(category ~ value, groups = variable, data = mdot,
 subset = {variable %in% c(values1, values2)},
 pch = c(1,3), cex = 1.5)

Peter Ehlers

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] pdf package help files

2010-12-18 Thread Spencer Graves
  The best way to get a pdf version of any CRAN package is to your 
favorite CRAN mirror, click Packages, then find the package of 
interest.  Reference manual is a pdf version of the package 
documentation.  This also includes other information such as Vignettes, 
which can be extremely valuable for getting an introduction to the package.



  The standard R CMD check process for compiling a package 
produces a pdf version of the manual.  However, this is not normally 
retained with the installed package.



  Hope this helps.
  Spencer


On 12/18/2010 12:44 PM, David Winsemius wrote:


On Dec 18, 2010, at 2:20 PM, eric wrote:



Newbie here...just learning

Do most packages come with pdf versions of the help files ? If yes, 
how to I

access the entire pdf file to be able to print it ? Is there a standard
command for that ?


There may be one but I don't know it if there is. The pdf files to 
which you refer are usually in the doc directory for each package (and 
can be found at CRAN as well). For example on my standard nstallation 
of R2.12 the pdf describing the gsubfn package is found it in:
/Library/Frameworks/R.framework/Versions/2.12/Resources/library/gsubfn/doc/gsubfn.pdf 



Each OS is different but once you find the root of R's installation 
there should be library and package sub-directories with doc 
sub-sub-directories. Not all packages have such a directory. The first 
one I looked in was lattice and I could not find one.




--
View this message in context: 
http://r.789695.n4.nabble.com/pdf-package-help-files-tp3093926p3093926.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
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] how to use expression as function arguements?

2010-12-18 Thread Duncan Murdoch

On 18/12/2010 2:34 PM, casperyc wrote:


Hi all,

#
integ=function(f,n){
# computes vector y = f(x)
x=runif(1)
y=f
hatI=mean(y)
hatI
}
# example of use
integ(x^2+x+100,100)
#
it returns an error says no obj 'x'

how do I 'tell' R to treat 'f' as an input expression?


In integ, you can get the unevaluated expression using

expr - substitute(f)

You can then evaluate it in the local context using

eval(expr)

So your integ function should be

integ=function(f,n){
# computes vector y = f(x)
x=runif(1)
y=eval( substitute(f) )
hatI=mean(y)
hatI
}

I can't help saying that this is bad style, though.  Using non-standard 
evaluation is usually a bad idea.  (There are examples like curve() in 
the base packages, but they are often criticized.)


A user should be able to expect that the x in

 integ(x^2+x+100,100)

refers to his own local variable named x, it shouldn't be a magic name.

Much better style is to require that the first argument is a function 
that takes a single argument; then you'd write your integ as


integ=function(f,n){
# computes vector y = f(x)
x=runif(1)
y=f(x)
hatI=mean(y)
hatI
}

and call it as

integ(function(x) x^2+x+100,100)

Doing this will be a lot more flexible and R-like in the long run.  For 
example, if you have two functions, you can say


f - function(x) x^2+x+100
g - function(x) x^2+x-100

and then do integ(f, 100); integ(g, 100).  The code I gave you would not 
work if f and g were stored as expressions:


 f - expression(x^2+x+100)
 integ(f, 100)
[1] NA
Warning message:
In mean.default(y) : argument is not numeric or logical: returning NA

Duncan Murdoch

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] pdf package help files

2010-12-18 Thread Duncan Murdoch

On 18/12/2010 2:20 PM, eric wrote:


Newbie here...just learning

Do most packages come with pdf versions of the help files ? If yes, how to I
access the entire pdf file to be able to print it ? Is there a standard
command for that ?


No, the pdf version is not normally installed.  If you want to see the 
same content on a locally installed package, run


help_start()

then browse to the package.  The pdf files are just concatenated 
versions of all the help pages shown in that index.


You can produce the pdf using

R CMD Rd2dvi --pdf foo

where foo is a directory holding the source code to the package. 
Alternatively, as others have suggested, just look at the PDF on CRAN.


Duncan Murdoch

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] pdf package help files

2010-12-18 Thread Spencer Graves

Hi, Duncan:


  I'm confused:


help_start()
Error: could not find function help_start


  Thanks,
  Spencer
sessionInfo()
R version 2.12.0 (2010-10-15)
Platform: i386-pc-mingw32/i386 (32-bit)

locale:
[1] LC_COLLATE=English_United States.1252
[2] LC_CTYPE=English_United States.1252
[3] LC_MONETARY=English_United States.1252
[4] LC_NUMERIC=C
[5] LC_TIME=English_United States.1252

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



On 12/18/2010 1:19 PM, Duncan Murdoch wrote:

On 18/12/2010 2:20 PM, eric wrote:


Newbie here...just learning

Do most packages come with pdf versions of the help files ? If yes, 
how to I

access the entire pdf file to be able to print it ? Is there a standard
command for that ?


No, the pdf version is not normally installed.  If you want to see the 
same content on a locally installed package, run


help_start()

then browse to the package.  The pdf files are just concatenated 
versions of all the help pages shown in that index.


You can produce the pdf using

R CMD Rd2dvi --pdf foo

where foo is a directory holding the source code to the package. 
Alternatively, as others have suggested, just look at the PDF on CRAN.


Duncan Murdoch

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] pdf package help files

2010-12-18 Thread Joel Schwartz
I think that should have been

help.start() 


Joel

 -Original Message-
 From: r-help-boun...@r-project.org 
 [mailto:r-help-boun...@r-project.org] On Behalf Of Spencer Graves
 Sent: Saturday, December 18, 2010 1:35 PM
 To: Duncan Murdoch
 Cc: r-help@r-project.org; eric
 Subject: Re: [R] pdf package help files
 
 Hi, Duncan:
 
 
I'm confused:
 
 
 help_start()
 Error: could not find function help_start
 
 
Thanks,
Spencer
 sessionInfo()
 R version 2.12.0 (2010-10-15)
 Platform: i386-pc-mingw32/i386 (32-bit)
 
 locale:
 [1] LC_COLLATE=English_United States.1252 [2] 
 LC_CTYPE=English_United States.1252 [3] 
 LC_MONETARY=English_United States.1252 [4] LC_NUMERIC=C [5] 
 LC_TIME=English_United States.1252
 
 attached base packages:
 [1] stats graphics  grDevices utils datasets  methods   base
  
 
 
 On 12/18/2010 1:19 PM, Duncan Murdoch wrote:
  On 18/12/2010 2:20 PM, eric wrote:
 
  Newbie here...just learning
 
  Do most packages come with pdf versions of the help files 
 ? If yes, 
  how to I access the entire pdf file to be able to print it 
 ? Is there 
  a standard command for that ?
 
  No, the pdf version is not normally installed.  If you want 
 to see the 
  same content on a locally installed package, run
 
  help_start()
 
  then browse to the package.  The pdf files are just concatenated 
  versions of all the help pages shown in that index.
 
  You can produce the pdf using
 
  R CMD Rd2dvi --pdf foo
 
  where foo is a directory holding the source code to the package. 
  Alternatively, as others have suggested, just look at the 
 PDF on CRAN.
 
  Duncan Murdoch
 
  __
  R-help@r-project.org mailing list
  https://stat.ethz.ch/mailman/listinfo/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] pdf package help files

2010-12-18 Thread kamel gaanoun
Hi,

if your question is : how to get help in a pdf file

So do this :

options(help_type=pdf)
your next ?function will be in a pdf file with the name of the function.

2010/12/18 Joel Schwartz j...@joelschwartz.com

 I think that should have been

 help.start()


 Joel

  -Original Message-
  From: r-help-boun...@r-project.org
  [mailto:r-help-boun...@r-project.org] On Behalf Of Spencer Graves
  Sent: Saturday, December 18, 2010 1:35 PM
  To: Duncan Murdoch
  Cc: r-help@r-project.org; eric
  Subject: Re: [R] pdf package help files
 
  Hi, Duncan:
 
 
 I'm confused:
 
 
  help_start()
  Error: could not find function help_start
 
 
 Thanks,
 Spencer
  sessionInfo()
  R version 2.12.0 (2010-10-15)
  Platform: i386-pc-mingw32/i386 (32-bit)
 
  locale:
  [1] LC_COLLATE=English_United States.1252 [2]
  LC_CTYPE=English_United States.1252 [3]
  LC_MONETARY=English_United States.1252 [4] LC_NUMERIC=C [5]
  LC_TIME=English_United States.1252
 
  attached base packages:
  [1] stats graphics  grDevices utils datasets  methods   base
   
 
 
  On 12/18/2010 1:19 PM, Duncan Murdoch wrote:
   On 18/12/2010 2:20 PM, eric wrote:
  
   Newbie here...just learning
  
   Do most packages come with pdf versions of the help files
  ? If yes,
   how to I access the entire pdf file to be able to print it
  ? Is there
   a standard command for that ?
  
   No, the pdf version is not normally installed.  If you want
  to see the
   same content on a locally installed package, run
  
   help_start()
  
   then browse to the package.  The pdf files are just concatenated
   versions of all the help pages shown in that index.
  
   You can produce the pdf using
  
   R CMD Rd2dvi --pdf foo
  
   where foo is a directory holding the source code to the package.
   Alternatively, as others have suggested, just look at the
  PDF on CRAN.
  
   Duncan Murdoch
  
   __
   R-help@r-project.org mailing list
   https://stat.ethz.ch/mailman/listinfo/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.




-- 
Kamel Gaanoun
(+33) (0)6.76.04.65.77

[[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] pdf package help files

2010-12-18 Thread Spencer Graves

Hi, Joel:


  Thanks.  That doubtless was what Duncan meant.  help.start() - 
Reference:  Packages provides access to HTML versions of all the help 
pages from all the packages.



  However, it does NOT provide access to the PDF version of the 
help pages for a package.  For that, you need to go to CRAN or run R 
CMD Rd2dvi --pdf foo, as Duncan suggested.  And for the latter to work, 
you need to source for the package, which you can get from CRAN for CRAN 
packages.



  Best Wishes,
  Spencer


On 12/18/2010 2:46 PM, Joel Schwartz wrote:

I think that should have been

help.start()


Joel


-Original Message-
From: r-help-boun...@r-project.org
[mailto:r-help-boun...@r-project.org] On Behalf Of Spencer Graves
Sent: Saturday, December 18, 2010 1:35 PM
To: Duncan Murdoch
Cc: r-help@r-project.org; eric
Subject: Re: [R] pdf package help files

Hi, Duncan:


I'm confused:


help_start()
Error: could not find function help_start


Thanks,
Spencer
sessionInfo()
R version 2.12.0 (2010-10-15)
Platform: i386-pc-mingw32/i386 (32-bit)

locale:
[1] LC_COLLATE=English_United States.1252 [2]
LC_CTYPE=English_United States.1252 [3]
LC_MONETARY=English_United States.1252 [4] LC_NUMERIC=C [5]
LC_TIME=English_United States.1252

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


On 12/18/2010 1:19 PM, Duncan Murdoch wrote:

On 18/12/2010 2:20 PM, eric wrote:

Newbie here...just learning

Do most packages come with pdf versions of the help files

? If yes,

how to I access the entire pdf file to be able to print it

? Is there

a standard command for that ?

No, the pdf version is not normally installed.  If you want

to see the

same content on a locally installed package, run

help_start()

then browse to the package.  The pdf files are just concatenated
versions of all the help pages shown in that index.

You can produce the pdf using

R CMD Rd2dvi --pdf foo

where foo is a directory holding the source code to the package.
Alternatively, as others have suggested, just look at the

PDF on CRAN.

Duncan Murdoch

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] package survey

2010-12-18 Thread andrija djurovic
Hi R users,

could someone help me to find out which formulas, for standard error
calculation, are  used in following example:

a=data.frame(weights=rep(c(10,1),c(4,1)),fpc=rep(41,5),uk=rep(1,5))

srs-svydesign(id=~1, weights=~weights, data=a)

srs1-svydesign(id=~1, weights=~weights,fpc=~fpc, data=a)

svytotal(~uk,srs)
   total SE
uk41  9

svytotal(~uk,srs1)
  total SE
uk41 8.4334

and does anyone know if it is possible to find the codes for functions in
survey package?

thanks in advance

Andrija

[[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] pdf package help files

2010-12-18 Thread Duncan Murdoch

On 18/12/2010 5:46 PM, Joel Schwartz wrote:

I think that should have been

help.start()


Yes, thanks.  What I need is a Thunderbird plug-in that understands R code.

Duncan Murdoch




Joel


-Original Message-
From: r-help-boun...@r-project.org
[mailto:r-help-boun...@r-project.org] On Behalf Of Spencer Graves
Sent: Saturday, December 18, 2010 1:35 PM
To: Duncan Murdoch
Cc: r-help@r-project.org; eric
Subject: Re: [R] pdf package help files

Hi, Duncan:


I'm confused:


help_start()
Error: could not find function help_start


Thanks,
Spencer
sessionInfo()
R version 2.12.0 (2010-10-15)
Platform: i386-pc-mingw32/i386 (32-bit)

locale:
[1] LC_COLLATE=English_United States.1252 [2]
LC_CTYPE=English_United States.1252 [3]
LC_MONETARY=English_United States.1252 [4] LC_NUMERIC=C [5]
LC_TIME=English_United States.1252

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


On 12/18/2010 1:19 PM, Duncan Murdoch wrote:

On 18/12/2010 2:20 PM, eric wrote:


Newbie here...just learning

Do most packages come with pdf versions of the help files

? If yes,

how to I access the entire pdf file to be able to print it

? Is there

a standard command for that ?


No, the pdf version is not normally installed.  If you want

to see the

same content on a locally installed package, run

help_start()

then browse to the package.  The pdf files are just concatenated
versions of all the help pages shown in that index.

You can produce the pdf using

R CMD Rd2dvi --pdf foo

where foo is a directory holding the source code to the package.
Alternatively, as others have suggested, just look at the

PDF on CRAN.


Duncan Murdoch

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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 survey

2010-12-18 Thread Joel Schwartz
 and does anyone know if it is possible to find the codes for 
 functions in survey package?

Yes, you can find the code by doing the following:

1) Go to the CRAN R package list (http://cran.r-project.org/web/packages/),
scroll down to the survey package link and click on it.

2) Scroll down to the Downloads section and download the package source
file. The R folder in this file contains the code for the functions in the
package.

You can of course follow an analogous procedure to get the code for other
packages.

There might be an easier or quicker way to do it from within R but ,if there
is, I haven't learned it yet.

Joel

 -Original Message-
 From: r-help-boun...@r-project.org 
 [mailto:r-help-boun...@r-project.org] On Behalf Of andrija djurovic
 Sent: Saturday, December 18, 2010 4:23 PM
 To: r-help@r-project.org
 Subject: [R] package survey
 
 Hi R users,
 
 could someone help me to find out which formulas, for 
 standard error calculation, are  used in following example:
 
 a=data.frame(weights=rep(c(10,1),c(4,1)),fpc=rep(41,5),uk=rep(1,5))
 
 srs-svydesign(id=~1, weights=~weights, data=a)
 
 srs1-svydesign(id=~1, weights=~weights,fpc=~fpc, data=a)
 
 svytotal(~uk,srs)
total SE
 uk41  9
 
 svytotal(~uk,srs1)
   total SE
 uk41 8.4334
 
 and does anyone know if it is possible to find the codes for 
 functions in survey package?
 
 thanks in advance
 
 Andrija
 
   [[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] package survey

2010-12-18 Thread David Winsemius


On Dec 18, 2010, at 8:11 PM, Joel Schwartz wrote:


and does anyone know if it is possible to find the codes for
functions in survey package?


Yes, you can find the code by doing the following:

1) Go to the CRAN R package list (http://cran.r-project.org/web/packages/ 
),

scroll down to the survey package link and click on it.

2) Scroll down to the Downloads section and download the package  
source
file. The R folder in this file contains the code for the  
functions in the

package.

You can of course follow an analogous procedure to get the code for  
other

packages.

There might be an easier or quicker way to do it from within R  
but ,if there

is, I haven't learned it yet.


(I suspect Joel knows this.)

If the package is loaded, you can just type the name of the function  
at the console.


svyhist  # produces about a half-page of code.



Joel


-Original Message-
From: r-help-boun...@r-project.org
[mailto:r-help-boun...@r-project.org] On Behalf Of andrija djurovic
Sent: Saturday, December 18, 2010 4:23 PM
To: r-help@r-project.org
Subject: [R] package survey

Hi R users,

could someone help me to find out which formulas, for
standard error calculation, are  used in following example:

a=data.frame(weights=rep(c(10,1),c(4,1)),fpc=rep(41,5),uk=rep(1,5))

srs-svydesign(id=~1, weights=~weights, data=a)

srs1-svydesign(id=~1, weights=~weights,fpc=~fpc, data=a)


 svydesign
function (ids, probs = NULL, strata = NULL, variables = NULL,
fpc = NULL, data = NULL, nest = FALSE, check.strata = !nest,
weights = NULL, pps = FALSE, ...)
{
UseMethod(svydesign, data)
}
environment: namespace:survey

When that happens it means there are more than one function dispatched  
by the S3 system. To find out there names use methods()


 methods(svydesign)
[1] svydesign.character*svydesign.DBimputationList*  
svydesign.default*

[4] svydesign.imputationList*

   Non-visible functions are asterisked

When functions are non-vidible you use getAnywhere:

 getAnywhere(svydesign.default)

(Produces a couple of pages of code.)

--
David.




svytotal(~uk,srs)
  total SE
uk41  9

svytotal(~uk,srs1)
 total SE
uk41 8.4334

and does anyone know if it is possible to find the codes for
functions in survey package?

thanks in advance

Andrija

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


David Winsemius, MD
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] Colours for 3-way probabilities

2010-12-18 Thread Earl F Glynn

Carl Witthoft wrote:

There are a couple Venn Diagram functions out there.

But I would strongly recommend against making charts like this. There
are too many colors, and even non-colorblind people will find them to be
a pain to discriminate, let alone remember what the coding means.

Assuming you want to show the distribution on a cartographic map, maybe
a mini-barchart in each state or county would be better, or three
non-overlapping 'bubbles' whose diameter or area maps to votecount.

Tufte has written a bunch about this sort of problem.


quote
Are there any R functions for creating palettes for three-way data? For
example, election maps for three parties where pure red, blue, and green
show 100% for the Red, Blue, and Green parties respectively, magenta
shows a 50-50 Red-Blue split with 0 for the Greens, cyan a 50-50
Blue/Green split with no Red votes and so on, with grey, black or white
at a 1/3,1/3,1/3 split vote.


I'm not sure that I fully understand what you're trying to do.

A chromaticity diagram conceptually shows all possible colors.
http://www.efg2.com/Lab/Graphics/Colors/Chromaticity.htm

With older CRT displays, the chromaticity coordinates of the red, green 
and blue phosphors on a chromaticity chart was a triangular color 
gamut that device could display.


The gamuts of newer devices, such as LCD displays, or multi-ink printers 
are a bit harder to explain, but basically could be thought of as some 
sort of polygon of possible colors on a chromaticity chart.  Color 
coordinates outside a gamut cannot be displayed on a device.


In theory, devices can have different color gamuts.  There's no 
guarantee that a color outside of the gamut of a display device will be 
displayed as seen on the original device.


The most common additive color primaries are red-green-blue and for 
displays, it's common to use the rgb function to define colors.


See RGB color space here:
http://en.wikipedia.org/wiki/RGB_color_space

R's rgb function (?rgb) by default allows the definition of colors on a 
continuum of 0.0 to 1.0 of R, G, and B primaries.  E.g., red is rgb(1.0, 
0.0, 0.0) and blue would be rgb(0.0, 0.0, 1.0).


So, if you're working with 0.0 to 1.0 probabilities they could be mapped 
the RGB coordinates.


But the reality is that most devices are 24-bit color (ignoring the 
8-bit alpha channel).  R's rgb function can be called as rgb(255,0,0, 
maxColorValue=255) to define red, or rgb(0,0,255, maxColorValue=255) 
to define blue.  Such 0:255 ranges map directly to the hardware in 
many cases.


This chart shows the result of fully-saturated additive RGB primary 
colors:  http://www.efg2.com/Lab/Graphics/Colors/ColorMix.htm

[Also note the subtractive color primaries mentioned there.]

Shades of gray are produced when the R,G,B components are all the 
same, e.g., rgb(0,0,0) is black and rgb(1.0, 1.0, 1.0) is white.


In theory, you could define any three additive color primaries and use a 
Maxwell Triangle of the possible colors produced, e.g., with RGB:

http://www.efg2.com/Lab/Graphics/Colors/MaxwellTriangle.htm

The above discussion works well for continuous data combinations, but if 
you're working with categorical data, perhaps just pick a categorical 
color scheme.  See: Color Schemes Appropriate for Scientific Data Graphics,

http://geography.uoregon.edu/datagraphics/color_scales.htm

This page may be useful for picking R colors:
http://research.stowers-institute.org/efg/R/Color/Chart/index.htm

Or use this PDF showing R's named colors:
http://research.stowers-institute.org/efg/R/Color/Chart/ColorChart.pdf

Besides RGB, other color spaces may be helpful for color selection and 
display.  Hue-Saturtion-Value coordinates can be useful with some 
problems:  See http://en.wikipedia.org/wiki/HSL_and_HSV and 
http://www.efg2.com/Lab/Graphics/Colors/HSV.htm.


For info on R's hsv function:  ?hsv

This page shows the hue map of an RGB image:
http://www.efg2.com/Lab/Graphics/Colors/ShowImage.htm

See the Color Chart page above for a brief example of using R's rgb2hsv 
function to convert from RGB to HSV.


efg

Earl F Glynn
Overland Park, KS

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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 survey

2010-12-18 Thread Joel Schwartz
 

 -Original Message-
 From: David Winsemius [mailto:dwinsem...@comcast.net] 
 Sent: Saturday, December 18, 2010 5:54 PM
 To: Joel Schwartz
 Cc: r-help@r-project.org
 Subject: Re: [R] package survey
 
 
 On Dec 18, 2010, at 8:11 PM, Joel Schwartz wrote:
 
  and does anyone know if it is possible to find the codes for 
  functions in survey package?
 
  Yes, you can find the code by doing the following:
 
  1) Go to the CRAN R package list 
  (http://cran.r-project.org/web/packages/
  ),
  scroll down to the survey package link and click on it.
 
  2) Scroll down to the Downloads section and download the package 
  source
  file. The R folder in this file contains the code for the 
 functions 
  in the package.
 
  You can of course follow an analogous procedure to get the code for 
  other packages.
 
  There might be an easier or quicker way to do it from 
 within R but ,if 
  there is, I haven't learned it yet.
 
 (I suspect Joel knows this.)
 
 If the package is loaded, you can just type the name of the 
 function at the console.
 
 svyhist  # produces about a half-page of code.

Yes, I should have suggested that option as well. It's probably the quickest
way if you just want the code for one or a few functions. But if you want
the code for most or all functions in a package (including ones for which
you might not know the name off the top of your head) is there some way of
sending the code for all functions in particular package to a .r file from
the command line with one or two lines of 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] Resource for learning C/R interface

2010-12-18 Thread Julian TszKin Chan
Hi all,

Is there any tutorial for learning C/R interface ? Thanks


Regards,
Julian

[[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] Resource for learning C/R interface

2010-12-18 Thread Steve Lianoglou
Hi,

On Sat, Dec 18, 2010 at 11:29 PM, Julian TszKin Chan cjul...@bu.edu wrote:
 Hi all,

 Is there any tutorial for learning C/R interface ? Thanks

You'll find some info here:
http://cran.r-project.org/doc/manuals/R-exts.pdf

Also, take a good look at the Rcpp package:
http://dirk.eddelbuettel.com/code/rcpp.html

There's *a lot* of things to learn there, so ... happy reading.

-steve

-- 
Steve Lianoglou
Graduate Student: Computational Systems Biology
 | Memorial Sloan-Kettering Cancer Center
 | Weill Medical College of Cornell University
Contact Info: http://cbio.mskcc.org/~lianos/contact

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Resource for learning C/R interface

2010-12-18 Thread Tal Galili
Hi Julian,
There was also a great thread on this topic just recently here:
http://stackoverflow.com/questions/4106174/where-can-i-learn-to-how-to-write-c-code-to-speed-up-slow-r-functions

You might find it useful.

Cheers,
Tal


Contact
Details:---
Contact me: tal.gal...@gmail.com |  972-52-7275845
Read me: www.talgalili.com (Hebrew) | www.biostatistics.co.il (Hebrew) |
www.r-statistics.com (English)
--




On Sun, Dec 19, 2010 at 8:34 AM, Steve Lianoglou 
mailinglist.honey...@gmail.com wrote:

 Hi,

 On Sat, Dec 18, 2010 at 11:29 PM, Julian TszKin Chan cjul...@bu.edu
 wrote:
  Hi all,
 
  Is there any tutorial for learning C/R interface ? Thanks

 You'll find some info here:
 http://cran.r-project.org/doc/manuals/R-exts.pdf

 Also, take a good look at the Rcpp package:
 http://dirk.eddelbuettel.com/code/rcpp.html

 There's *a lot* of things to learn there, so ... happy reading.

 -steve

 --
 Steve Lianoglou
 Graduate Student: Computational Systems Biology
  | Memorial Sloan-Kettering Cancer Center
  | Weill Medical College of Cornell University
 Contact Info: http://cbio.mskcc.org/~lianos/contact

 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/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] Resource for learning C/R interface

2010-12-18 Thread Phil Spector

Julian -
  I've written a document you might find helpful.

http://www.stat.berkeley.edu/classes/s243/calling.pdf

It also includes the C/matlab interface.

- Phil Spector
 Statistical Computing Facility
 Department of Statistics
 UC Berkeley
 spec...@stat.berkeley.edu


On Sun, 19 Dec 2010, Julian TszKin Chan wrote:


Hi all,

Is there any tutorial for learning C/R interface ? Thanks


Regards,
Julian

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