[R] my function decided to stop working, problem with scoping?

2010-08-26 Thread Roman Luštrik
Hello list.

Until last week, I've been using my function without a problem. I can only
imagine what has changed (no package updates), but all of a sudden, a custom
function that uses raster::xyValues stopped working. For some reason, one of
the values is not found, even though it's there. Here is a snippet of code
from browser() call from within my custom function where everything goes
awry.

Browse[1]> effect.distance
[1] 220.2045  # just to make sure effect.distance is there
Browse[1]> unlist(xyValues(object = object, xy = origin.point, buffer =
effect.distance))
Error in .local(object, xy, ...) : object 'effect.distance' not found
Browse[1]> traceback()
2: stop(gettextf("no function '%s' could be found", f), domain = NA)
1: getS3method("xyValues", "method")
Browse[1]> environment()

Browse[1]> Q
> environment()

> effect.distance
Error: object 'effect.distance' not found


If I call the unlist(...) line in R_GlobalEnv, it seems to work fine. I'm
wondering why this behavior?

Cheers,
Roman



-- 
In God we trust, all others bring data.

[[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] frequency, count rows, data for heat map

2010-08-26 Thread Jan van der Laan
Please, reply to the r-help and not only to me personally. That way
others can can also help, or perhaps benefit from the answers.

You can use strplit to remove the last part of the strings. strplit
returns a list of character vectors from which you (if I understand
you correctly) only want to select the first element. I use laply from
the plyr library for this, although there are probably also other ways
of doing this.

library(plyr)
dat$V3 <- laply(strsplit(as.character(dat$V1), '_'), function(l) l[1])

After that you can use daply as I showed in my previous post
[daply(dat, V3 ~ V2, nrow)] or use the methods suggested by Dennis
Murphy to build your table.

Regards,

Jan



On Thu, Aug 26, 2010 at 1:41 AM, Trip Sweeney  wrote:
> Jan,
> Thanks for responding to my post to listeserve about arranging data matrix
> for heat map.
> I am still a beginner, so the below is the code I used for the matrix and
> did not yet learn how to
> input 'data.frame' (which I need to know to use your code). The below code
> works
> and mock.txt file is attached. There is one thing, though. The input in
> column 1 is tricky
> in the mock.txt file. I need it to sum per unique ID based on character
> prior to the "_"
> So, for example the current script call 1079_17891 and 1079_14794 uniques
> when I want
> them to be tallied together since they are both part of same 1079 samples.
> Occasionally
> a sample has three characters before the "_", like 111_463428 etc in
> mock.txt. The substring
> after the "_" is variable length. In the end, it should be one row for 1079,
> one for 111, and one for 5576.
> Can you help me with this modification of the code? Any advice much
> appreciated. Sincerely, Trip
>
> dat<-read.table('mock.txt',sep="\t")
> sumData=matrix(NA,nrow=length(unique(dat[,1])),ncol=length(unique(dat[,2])))
> rownames(sumData)<-unique(dat[,1])
> colnames(sumData)<-unique(dat[,2])
>
> for (i in 1:dim(sumData)[1]){
>   for(j in 1:dim(sumData)[2]){
>  sumData[i,j]<-sum (dat[,1]==unique(dat[,1])[i] &
> dat[,2]==unique(dat[,2])[j])
>   }
> }
>
> write.table(sumData,"SummarizedData.txt",sep="\t",col.names=NA)
>



On Wed, Aug 25, 2010 at 4:53 PM, rtsweeney  wrote:
>
> Hi all,
> I have read posts of heat map creation but I am one step prior --
> Here is what I am trying to do and wonder if you have any tips?
> We are trying to map sequence reads from tumors to viral genomes.
>
> Example input file :
> 111     abc
> 111     sdf
> 111     xyz
> 1079   abc
> 1079   xyz
> 1079   xyz
> 5576   abc
> 5576   sdf
> 5576   sdf
>
> How may xyz's are there for 1079 and 111? How many abc's, etc?
> How many times did reads from sample (1079) align to virus xyz.
> In some cases there are thousands per virus in a give sample, sometimes one.
> The original file (two columns by tens of thousands of rows; 20 MB) is
> text file (tab delimited).
>
> Output file:
>         abc  sdf  xyz
> 111     1      1     1
> 1079   1      0     2
> 5576   1      2     0
>
> Or, other ways to generate this data so I can then use it for heat map
> creation?
>
> Thanks for any help you may have,
>
> rtsweeney
> palo alto, ca
> --
> View this message in context: 
> http://r.789695.n4.nabble.com/frequency-count-rows-data-for-heat-map-tp2338363p2338363.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.
>
1079_346281416490|ref|NC_013643.1|
1079_346281416323|ref|NC_013646.1|
1079_3789629367|ref|NC_001803.1|
1079_58830984428|ref|NC_004812.1|
1079_1292   9629367|ref|NC_001803.1|
1079_3956   9629357|ref|NC_001802.1|
1079_4736   9629357|ref|NC_001802.1|
1079_7732   21427641|ref|NC_004015.1|
1079_7855   118197620|ref|NC_008584.1|
1079_8618   32453484|ref|NC_004928.1|
1079_11540  10140926|ref|NC_002531.1|
1079_14794  9629367|ref|NC_001803.1|
1079_15738  109255272|ref|NC_008168.1|
1079_17891  299778956|ref|NC_014260.1|
1079_18414  157781212|ref|NC_009823.1|
1079_18414  157781216|ref|NC_009824.1|
1079_20312  9629367|ref|NC_001803.1|
1079_20497  9629357|ref|NC_001802.1|
1079_26750  9629367|ref|NC_001803.1|
1079_27926  9628113|ref|NC_001659.1|
1079_27926  9628113|ref|NC_001659.1|
1079_28033  84662653|ref|NC_007710.1|
1079_30020  47835019|ref|NC_004333.2|
1079_30371  9629367|ref|NC_001803.1|
1079_35750  50313241|ref|NC_001491.2|
1079_35750  50313241|ref|NC_001491.2|
111_463428  56694721|ref|NC_006560.1|
111_464636  114680053|ref|NC_008349.1|
111_464636  9627742|ref|NC_001623.1|
111_465190  9627186|ref|NC_001539.1|
111_467613  51557483|ref|NC_006151.1|
111_467613  51557483|ref|NC_006151.1|
111_467975  9627742|ref|NC_001623.1|
111_467975  

Re: [R] Removing inter-bar spaces in barchart

2010-08-26 Thread Jonathan Greenberg
Oops, small typo, should be:


barchart_test_heights=sin(c(1:100))
barchart_test_bins=c(c(1:50),c(1:50))
groups=c(rep(1,50),rep(2,50))

# Wish below didn't have spaces!
barchart(barchart_test_bins~barchart_test_heights,groups=groups)

On Wed, Aug 25, 2010 at 4:46 PM, Jonathan Greenberg
 wrote:
> I apologize, let me add some data to play with:
>
> barchart_test_heights=sin(c(1:100))
> barchart_test_bins=c(1:100)
> groups=c(rep(1,50),rep(2,50))
>
> I have pre-calculated histogram data and the bins they belong to.  I
> would like to plot the two histograms superimposed on one-another,
> having group 1 bars for a given bin be next to group 2 bars, something
> along the lines of:
>
> barchart(barchart_test_bins~barchart_test_heights,groups=groups)
>
> except with no space between the bars (and a key for the groups).
>
> --j
>
> P.S. And yes I was talking about barchart() from lattice -- however, I
> am happy to use another function if that makes this easier.
>
> On Wed, Aug 25, 2010 at 1:55 PM, David Winsemius  
> wrote:
>>
>> On Aug 24, 2010, at 10:20 PM, Jonathan Greenberg wrote:
>>
>>> Rhelpers:
>>>
>>> I'm trying to make a barchart of a 2-group dataset
>>> (barchart(x~y,data=data,groups=z,horizontal=FALSE)).  My problem is
>>> that I can't, for the life of me, seem to get rid of the inter-bar
>>> space -- box.ratio set to 1 doesn't do much.  Any ideas?  I'd
>>> ideally want zero space between the bars.  Thanks!
>>
>> You didn't provide any data (nor did you illustrate with one of the
>> available datasets that are used in examples.)
>>
>> Compare these two outputs:
>>
>> barchart(yield ~ year, data = barley,
>>         groups = variety,   ylab = "Barley Yield (bushels/acre)",
>>        )
>>
>> barchart(yield ~ variety, data = barley,
>>         groups = year,   ylab = "Barley Yield (bushels/acre)",
>>        )
>>
>> ... and notice that the variables in the "group" have no separation of their
>> bars whereas the rhs variables do. This is the opposite of what I expected,
>> so perhaps you think as I did and reversing the roles of"y" and "z"  might
>> help?
>>
>> --
>>
>> David Winsemius, MD
>> West Hartford, CT
>>
>>
>
>
>
> --
> Jonathan A. Greenberg, PhD
> Assistant Project Scientist
> Center for Spatial Technologies and Remote Sensing (CSTARS)
> Department of Land, Air and Water Resources
> University of California, Davis
> One Shields Avenue
> Davis, CA 95616
> Phone: 415-763-5476
> AIM: jgrn307, MSN: jgrn...@hotmail.com, Gchat: jgrn307
>



-- 
Jonathan A. Greenberg, PhD
Assistant Project Scientist
Center for Spatial Technologies and Remote Sensing (CSTARS)
Department of Land, Air and Water Resources
University of California, Davis
One Shields Avenue
Davis, CA 95616
Phone: 415-763-5476
AIM: jgrn307, MSN: jgrn...@hotmail.com, Gchat: jgrn307

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Removing inter-bar spaces in barchart

2010-08-26 Thread Jonathan Greenberg
I apologize, let me add some data to play with:

barchart_test_heights=sin(c(1:100))
barchart_test_bins=c(1:100)
groups=c(rep(1,50),rep(2,50))

I have pre-calculated histogram data and the bins they belong to.  I
would like to plot the two histograms superimposed on one-another,
having group 1 bars for a given bin be next to group 2 bars, something
along the lines of:

barchart(barchart_test_bins~barchart_test_heights,groups=groups)

except with no space between the bars (and a key for the groups).

--j

P.S. And yes I was talking about barchart() from lattice -- however, I
am happy to use another function if that makes this easier.

On Wed, Aug 25, 2010 at 1:55 PM, David Winsemius  wrote:
>
> On Aug 24, 2010, at 10:20 PM, Jonathan Greenberg wrote:
>
>> Rhelpers:
>>
>> I'm trying to make a barchart of a 2-group dataset
>> (barchart(x~y,data=data,groups=z,horizontal=FALSE)).  My problem is
>> that I can't, for the life of me, seem to get rid of the inter-bar
>> space -- box.ratio set to 1 doesn't do much.  Any ideas?  I'd
>> ideally want zero space between the bars.  Thanks!
>
> You didn't provide any data (nor did you illustrate with one of the
> available datasets that are used in examples.)
>
> Compare these two outputs:
>
> barchart(yield ~ year, data = barley,
>         groups = variety,   ylab = "Barley Yield (bushels/acre)",
>        )
>
> barchart(yield ~ variety, data = barley,
>         groups = year,   ylab = "Barley Yield (bushels/acre)",
>        )
>
> ... and notice that the variables in the "group" have no separation of their
> bars whereas the rhs variables do. This is the opposite of what I expected,
> so perhaps you think as I did and reversing the roles of"y" and "z"  might
> help?
>
> --
>
> David Winsemius, MD
> West Hartford, CT
>
>



-- 
Jonathan A. Greenberg, PhD
Assistant Project Scientist
Center for Spatial Technologies and Remote Sensing (CSTARS)
Department of Land, Air and Water Resources
University of California, Davis
One Shields Avenue
Davis, CA 95616
Phone: 415-763-5476
AIM: jgrn307, MSN: jgrn...@hotmail.com, Gchat: jgrn307

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


Re: [R] how to plot y-axis on the right of x-axis

2010-08-26 Thread Gavin Simpson
On Thu, 2010-08-26 at 06:19 +0800, elaine kuo wrote:
> Yes, I appreciated your answers which well hit my questions. (esp the
> perfect model parts).
> 
> 
> About the plot part, one more question.
> Is it possible to make the two plots (northern and southern richness)
> sharing the same Y axis (latitude = 0, the equator) ?
> In other words, southern richness would be on the left side of the Y
> axis, 
> while northern one on the right side.

Yes, of course:

op <- par(mar = c(5.1,0,4.1,0), oma = c(0,4.1,0,4.1))
layout(matrix(1:2, nrow = 1))
plot(1:100)
plot(1:100, xlim = c(100,1), axes = FALSE)
axis(1)
axis(2, labels = FALSE, tcl = -0.5)
axis(2, labels = FALSE, tcl = 0.5)
axis(4)
box()
layout(1)
par(op)

Is one way doing things by hand. Notice the problem (or potential
problem) of having an axis in the middle of your data; it might obscure
data and the problem is exacerbated if you try to label it. Plus it is a
faff to fiddle around with the plotting margins, etc.

Can't you just code southern latitudes as -degrees N (minus degrees N)
and then plot all the data on the one plot, and fit your models to this
data rather that the original? After all, does it matter if you are at
0.1 degrees N or 0.1 degrees S and as such are in different hemispheres?
You are likely in the same biogeographical region. Here is an exmaple:

## dummy data
set.seed(123)
dat <- data.frame(richness = c(rpois(100, lambda = 5),
   rpois(100, lambda = 2)),
  latitudeN = c(sort(sample(seq(0.01, 90,
length = 1000),
100)),
sort(sample(seq(-0.01, -90, 
length = 1000),
100

## fit model to N sites:
## ignoring that richness is a count:
## hint use glm( family = poisson) as a start
modN <- lm(richness ~ latitudeN, data = dat, subset = latitudeN > 0)
## fit model to S sites
modS <- lm(richness ~ latitudeN, data = dat, subset = latitudeN < 0)

# prediction data
pdatN <- data.frame(latitudeN = seq(0.01, 90, length = 100))
pdatS <- data.frame(latitudeN = seq(-0.01, -90, length = 100))

## predict
pdatN <- within(pdatN, richness <- predict(modN, newdata = pdatN))
pdatS <- within(pdatS, richness <- predict(modS, newdata = pdatS))

## plotting
plot(richness ~ latitudeN, data = dat, 
 xlab = expression(Latitude~(degree*N)),
 ylab = "Species Richness")
lines(richness ~ latitudeN, data = pdatN, col = "red")
lines(richness ~ latitudeN, data = pdatS, col = "blue")
legend("topleft", ncol = 2, legend = c("N","S"),
   col = c("red","blue"), lty = "solid", bty = "n")

HTH

G

> Elaine
> 
> 
> 
> 
> Two plot panels on the same device like:
> 
> layout(1:2)
> plot(1:100)
> plot(1:100)
> layout(1)
> 
> 
> =>  Yes that's what I want
> 
> The second panel for southern species richness, do you mean you want
> the
> plot to go like this:
> 
> plot(1:100, xlim = c(100,1))
> 
> 
> =>  Yes, too. 
> 
> 
> 
> 
> 
> 

-- 
%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%
 Dr. Gavin Simpson [t] +44 (0)20 7679 0522
 ECRC, UCL Geography,  [f] +44 (0)20 7679 0565
 Pearson Building, [e] gavin.simpsonATNOSPAMucl.ac.uk
 Gower Street, London  [w] http://www.ucl.ac.uk/~ucfagls/
 UK. WC1E 6BT. [w] http://www.freshwaters.org.uk
%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%

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


[R] Problem with terms of the form (a >1) and subsetting of a terms object

2010-08-26 Thread Niels Richard Hansen

I have the following problem

mydata <- data.frame(a=1:3)
form <- ~ (a>1) - 1
model.matrix(form,mydata)

 a > 1FALSE a > 1TRUE
1  1 0
2  0 1
3  0 1
...

However

model.matrix(update(terms(form)[1],~.-1),mydata)

  (Intercept) a > 1 - 1TRUE
1   1 1
2   1 1
3   1 1
...

Taking

terms(form)[1]

extracts the formula with only the first term, but the parentheses
are thrown away, and after the update, I get a different formula.
Is that supposed to be so?

Thanks, Niels

--
Niels Richard Hansen Web:   www.math.ku.dk/~richard 
Associate Professor  Email: niels.r.han...@math.ku.dk
Department of Mathematical Sciences nielsrichardhan...@gmail.com
University of Copenhagen Skype: nielsrichardhansen.dk   
Universitetsparken 5 Phone: +45 353 20783 (office)  
2100 Copenhagen Ø   +45 2859 0765 (mobile)
Denmark

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

2010-08-26 Thread e-letter
>On Wed, 2010-08-25 at 09:32 +0100, e-letter wrote:
>> On 24/08/2010, David Winsemius  wrote:
>> >
>> > On Aug 24, 2010, at 9:37 AM, e-letter wrote:
>> >
>> >> Readers,
>> >>
>> >> According to the documentation for the function 'plotmath' there is no
>> >> apparent possibility to add the percent sign (%) to a plot function,
>> >
>> > Where did you see an assertion made???
>> >
>> Within R I entered the command:
>>
>> ?plotmath
>
>Surely you don't expect the R help pages to document everything that
>*isn't* possible with a given function? They'd be infinitely long! ;-)
>
No, following previous advice it would be preferable to add the
following (or similar) to the documentation:

'syntax' 'meaning'
...
'%' %
...

>What you meant to say was, "?plotmath doesn't show me how to add a %
>symbol to a plot. How do I do it?"
>
>> Also accessed using:
>>
>> help.start(browser="opera")
>>
>> Navigating the web browser page:
>>
>> packages
>> packages in /usr/lib/R/library
>> grdevices
>> plotmath
>>
>> In the list headed 'syntax' and 'meaning' within the section 'details'.
>>
>
>> >  > TestChars <- function(sign=1, font=1, ...)
>> > + {
>> > +if(font == 5) { sign <- 1; r <- c(32:126, 160:254)
>> > +} else if (l10n_info()$MBCS) r <- 32:126 else r <- 32:255
>> > +if (sign == -1) r <- c(32:126, 160:255)
>> > +par(pty="s")
>> > +plot(c(-1,16), c(-1,16), type="n", xlab="", ylab="",
>> > + xaxs="i", yaxs="i")
>> > +grid(17, 17, lty=1)
>> > +for(i in r) try(points(i%%16, i%/%16, pch=sign*i, font=font,...))
>> > + }
>> >  > TestChars(font=5)
>> >
>> > Notice that the "%" sign is three characters to the right (i.e.
>> > higher) of the "forall" symbol that is produced by the example code
>>
>> I can't see 'forall' in the code above.
>
>You need to run it in R. Then you will see a plot of the glyphs
>available in the symbol font. 'forall' is a mathematical symbol:
>
>http://en.wikipedia.org/wiki/Table_of_mathematical_symbols
>
>> > they offer. (The numbering proceeds from bottom up which confused me
>> > at first.)
>> >
>> What numbering?
>
>The numbering of the glyphs so you can use the number to draw the symbol
>you want. They are on the plot. You did run the code provided by David?
>
I did not read any instruction that it was code to apply! Anyway,
below is the result:

> TestChars <- function(sign=1, font=1, ...)
+ + {
+ +if(font == 5) { sign <- 1; r <- c(32:126, 160:254)
+ +} else if (l10n_info()$MBCS) r <- 32:126 else r <- 32:255
Error: syntax error, unexpected '}' in:
"
"
> +if (sign == -1) r <- c(32:126, 160:255)
Error in sign == -1 : comparison (1) is possible only for atomic and list types
> +par(pty="s")
Error in +par(pty = "s") : invalid argument to unary operator
> +plot(c(-1,16), c(-1,16), type="n", xlab="", ylab="",
+ + xaxs="i", yaxs="i")
Error: syntax error, unexpected EQ_ASSIGN, expecting ',' in "+
plot(c(-1,16), c(-1,16), type="n", xlab="", ylab="","
> +grid(17, 17, lty=1)
Error in int_abline(a = a, b = b, h = h, v = v, untf = untf, ...) :
plot.new has not been called yet
> +for(i in r) try(points(i%%16, i%/%16, pch=sign*i, font=font,...))
Error: object "r" not found
> + }
Error: syntax error, unexpected '}' in "+ }"
> TestChars(font=5)
Error: could not find function "TestChars"

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

2010-08-26 Thread Stephen T.

Wow, I was aware of R's lazy evaluation but didn't realize that was the cause 
here. If the function, adder(), was not simple as I'd defined, I suppose I 
could also force the evaluation of "x" in a wrapping function before passing it 
to adder() as an alternative:
> adder <- function(x) function(y) x + y> plus <- Map(function(x) {force(x); 
> adder(x)},c(one=1,two=2))> plus$one(1)[1] 2> plus$two(1)[1] 3
Thanks Gabor!

> From: ggrothendi...@gmail.com
> Date: Thu, 26 Aug 2010 00:28:34 -0400
> Subject: Re: [R] list of closures
> To: obsessiv...@hotmail.com
> CC: r-help@r-project.org
> 
> On Thu, Aug 26, 2010 at 12:04 AM, Stephen T.  wrote:
> >
> > Hi, I wanted to create a list of closures. When I use Map(), mapply(), 
> > lapply(), etc., to create this list, it appears that the wrong arguments 
> > are being passed to the main function. For example:
> > Main function:
> >> adder <- function(x) function(y) x + y
> > Creating list of closures with Map():
> >> plus <- Map(adder,c(one=1,two=2))> plus$one(1)[1] 3> plus$two(1)[1] 3
> > Examining what value was bound to "x":
> >> Map(function(fn) get("x",environment(fn)),plus)$one[1] 2$two[1] 2
> >
> > This is what I had expected:
> >> plus <- list(one=adder(1),two=adder(2))> plus$one(1)[1] 2> plus$two(1)[1] 3
> >> Map(function(fn) get("x",environment(fn)),plus)$one[1] 1$two[1] 2
> >
> > Anyone know what's going on? Thanks much!
> 
> R uses lazy evaluation of function arguments.  Try forcing x:
> 
> > adder <- function(x) { force(x); function(y) x + y }
> > plus <- Map(adder,c(one=1,two=2))
> > plus$one(1)
> [1] 2
> > plus$two(1)
> [1] 3
  
[[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] percentage sign in expression

2010-08-26 Thread e-letter
>It's possible that my help page is different than yours. Right after
>the syntax/meaning description on mine (which is a Mac OSX system) is
>a paragraph:
>
>"The symbol font uses Adobe Symbol encoding so, for example, a lower
>case mu can be obtained either by the special symbol mu or by
>symbol("m"). This provides access to symbols that have no special
>symbol name, for example, the universal, or forall, symbol is
>symbol("\042"). To see what symbols are available in this way
>useTestChars(font=5) as given in the examples for points: some are
>only available on some devices."
>
>(In this case I would be surprised if the help pages were different
>because this makes a cross-reference to the examples in points.  I am
>not surprised about cross-platform differences in descriptions of
>graphical devices  and would have included a caveat if I were
>corresponding on rhelp about such. I suppose the font issues could be
>platform specific so if you want to correct me on this point, I will
>try to file it away. I did, however, give you the code needed to to
>display Symbols and it sounds further on that it succeeded)
>
I agree and seems that in this example that the documentation for
graphical devices is platform dependent. This should be stated in the
manual if not already. Please see previous post for the errors trying
to apply the commands provided.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] my function decided to stop working, problem with scoping?

2010-08-26 Thread Roman Luštrik

To clarify, when I run the unlist(...) in R_GlobalEnv, I create all the
necessary variables (including effect.distance).
-- 
View this message in context: 
http://r.789695.n4.nabble.com/my-function-decided-to-stop-working-problem-with-scoping-tp2339228p2339263.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] list of closures

2010-08-26 Thread Stephen T.

Hi Philippe, thanks for the suggestion - for my smaller problems I find that 
closures are quicker to define and deploy. At larger scales, I've implemented 
S4 objects with methods and attributes - though while elegant, I find that OO 
(apart from what's built-in) adds significant biolerplate in defining classes, 
so try to avoid it when I can... but I don't know much about the proto package 
except that it loads with gsubfn() - might look into it. Thanks!Stephen

> Date: Thu, 26 Aug 2010 06:51:50 +0200
> From: phgrosj...@sciviews.org
> To: obsessiv...@hotmail.com
> CC: ggrothendi...@gmail.com; r-help@r-project.org
> Subject: Re: [R] list of closures
> 
> Unless for learning R, you should really consider R.oo or proto packages 
> that may be more convenient for you (but you don't provide enough 
> context to tell).
> Best,
> 
> Philippe
> 
> On 26/08/10 06:28, Gabor Grothendieck wrote:
> > On Thu, Aug 26, 2010 at 12:04 AM, Stephen T.  
> > wrote:
> >>
> >> Hi, I wanted to create a list of closures. When I use Map(), mapply(), 
> >> lapply(), etc., to create this list, it appears that the wrong arguments 
> >> are being passed to the main function. For example:
> >> Main function:
> >>> adder<- function(x) function(y) x + y
> >> Creating list of closures with Map():
> >>> plus<- Map(adder,c(one=1,two=2))>  plus$one(1)[1] 3>  plus$two(1)[1] 3
> >> Examining what value was bound to "x":
> >>> Map(function(fn) get("x",environment(fn)),plus)$one[1] 2$two[1] 2
> >>
> >> This is what I had expected:
> >>> plus<- list(one=adder(1),two=adder(2))>  plus$one(1)[1] 2>  
> >>> plus$two(1)[1] 3
> >>> Map(function(fn) get("x",environment(fn)),plus)$one[1] 1$two[1] 2
> >>
> >> Anyone know what's going on? Thanks much!
> >
> > R uses lazy evaluation of function arguments.  Try forcing x:
> >
> >> adder<- function(x) { force(x); function(y) x + y }
> >> plus<- Map(adder,c(one=1,two=2))
> >> plus$one(1)
> > [1] 2
> >> plus$two(1)
> > [1] 3
> >
> > __
> > R-help@r-project.org mailing list
> > https://stat.ethz.ch/mailman/listinfo/r-help
> > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> > and provide commented, minimal, self-contained, reproducible code.
> >
> >
  
[[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] Secant Method Convergence (Method to replicate Excel XIRR/IRR)

2010-08-26 Thread Berend Hasselman

I couldn't resist the temptation.

Here is the example using the R package nleqslv.


library(nleqslv)

npv <- function (irr, cashFlow, times) sum(cashFlow / (1 + irr)^times)

CF <- c(-1000,500,500,500,500,500)
dates <-
c("1/1/2001","2/1/2002","3/1/2003","4/1/2004","5/1/2005","6/1/2006")
cfDate <- as.Date(dates,format="%m/%d/%Y")
times <- as.numeric(difftime(cfDate, cfDate[1], units="days"))/365.24

irr.start <- 0.05
# default Broyden ==> secant like method
nleqslv(irr.start, npv, control=list(trace=1), cashFlow=CF, times=times)


/Berend
-- 
View this message in context: 
http://r.789695.n4.nabble.com/Secant-Method-Convergence-Method-to-replicate-Excel-XIRR-IRR-tp2338672p2339187.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] Problem with terms of the form (a >1) and subsetting of a terms object

2010-08-26 Thread Dimitris Rizopoulos

I think you need an I(), i.e.,

form <- ~ I(a > 1) - 1


I hope it helps.

Best,
Dimitris


On 8/26/2010 9:17 AM, Niels Richard Hansen wrote:

I have the following problem

mydata <- data.frame(a=1:3)
form <- ~ (a>1) - 1
model.matrix(form,mydata)

a > 1FALSE a > 1TRUE
1 1 0
2 0 1
3 0 1
...

However

model.matrix(update(terms(form)[1],~.-1),mydata)

(Intercept) a > 1 - 1TRUE
1 1 1
2 1 1
3 1 1
...

Taking

terms(form)[1]

extracts the formula with only the first term, but the parentheses
are thrown away, and after the update, I get a different formula.
Is that supposed to be so?

Thanks, Niels



--
Dimitris Rizopoulos
Assistant Professor
Department of Biostatistics
Erasmus University Medical Center

Address: PO Box 2040, 3000 CA Rotterdam, the Netherlands
Tel: +31/(0)10/7043478
Fax: +31/(0)10/7043014

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


Re: [R] how to plot y-axis on the right of x-axis

2010-08-26 Thread Gavin Simpson
On Thu, 2010-08-26 at 06:11 +0800, elaine kuo wrote:
> Thank you.
> The answers provides the right direction and a code was written accordingly.
> 
> One more request, if the label of axis X wants to be drawn from 5 to 1 (left
> to right)
> rather than 1 to 5, is it fine to change axis (4, at = NULL) ?
> If so, which value should be input ?

If I understand you correctly, No. The data have been plotted assuming
xlim of (more or less) c(1, 5). All axis can do is change the labels and
where the marks are placed. You need to manually set the xlim argument
to plot to get the data plotted the other way round.

plot(1:5, axes = FALSE, xlim = c(5,1))
axis(1)
axis(4)
box()

Notice that all we've done here is change the limits for the x axis in
the plot() call, we haven't had to change any of the other code.

Note also that axis(side = 4) is on the one on the right so doesn't
pertain to the x-axis. If you want to know how to use axis more
flexibly, read ?axis as it explains there what 'at' is a requires as
input from you. For example, we might want to label at different points,
not 1,2,3,4,5 etc:

plot(1:5, axes = FALSE, xlim = c(5,1))
axis(1)
axis(4, at = seq(1.5, 4.5, by = 1))
box()

HTH

G

> 
> Thanks again.
> 
> Elaine
> 
> code
> plot(1:5,axes=FALSE)
> axis(1)
> axis(4)
> box()
> 
> 
> 
> 
> On Wed, Aug 25, 2010 at 5:39 PM, Jim Lemon  wrote:
> 
> > On 08/25/2010 09:12 AM, elaine kuo wrote:
> >
> >> Dear List,
> >>
> >> I have a richness data distributing across 20 N to 20 S latitude. (120
> >> E-140
> >> E longitude).
> >>
> >>
> >> I would like to draw the richness in the north hemisphere and a regression
> >> line in the plot
> >> (x-axis: latitude, y-axis: richness in the north hemisphere).
> >> The above demand is done using plot.
> >>
> >> Then, south hemisphere richness and regression are required to be
> >> generated
> >> using
> >> the same y-axis above but an x-axis on the left side of the y-axis.
> >> (The higher latitude in the south hemisphere, the left it would move)
> >>
> >> Please kindly share how to design the south plot and regression line for
> >> richness.
> >> Also, please advise if any more info is in need.
> >>
> >>  Hi Elaine,
> > Changing the position of the axes is easily done by changing the "side" and
> > "pos" arguments of the "axis" function. If you want to move the y-axis to
> > the right (or as you state it, the x axis to the left):
> >
> > # y axis on the left
> > plot(1:5,axes=FALSE)
> > axis(1)
> > axis(2)
> > # add a y axis one third of the way to the right
> > xylim<-par("usr")
> > axis(2,pos=xylim[1]+diff(xylim[1:2])/3)
> > # add another y axis two thirds of the way
> > axis(4,pos=xylim[2]-diff(xylim[1:2])/3)
> > # add one more on the right
> > axis(4)
> >
> > You can move the x axis up and down using the same tricks.
> >
> > Jim
> >
> 
>   [[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.

-- 
%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%
 Dr. Gavin Simpson [t] +44 (0)20 7679 0522
 ECRC, UCL Geography,  [f] +44 (0)20 7679 0565
 Pearson Building, [e] gavin.simpsonATNOSPAMucl.ac.uk
 Gower Street, London  [w] http://www.ucl.ac.uk/~ucfagls/
 UK. WC1E 6BT. [w] http://www.freshwaters.org.uk
%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%

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

2010-08-26 Thread Stephen Liu
Hi folks,


Following command only works on Windows
> Test01=read.table(file.choose(), header=TRUE)

It popup open a dialog box for choosing file.


But it doesn't work on Linux (Ubuntu);
> Test01=read.table(file.choose(), header=TRUE)
Enter file name: 


Entering file name doesn't work.  Please advise.  TIA


B.R.
Stephen L




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

2010-08-26 Thread Gavin Simpson
On Wed, 2010-08-25 at 11:30 -0400, RICHARD M. HEIBERGER wrote:
> Kay,
> 
> doe this do what you want?
> 
> 
> dotplot(y1+y2 ~ facs$Treatment|facs$Sites,
> outer=TRUE,
> scales = list(x = list(rot = 90, tck=c(1,0))),
> ylab=c("y1", "y2"),
> xlab=c("Site 1", "Site 2"),
> strip=FALSE)

This would be better, to avoid abusing the poor R formula handling
sugar:

dotplot(y1 + y2 ~ Treatment | Sites, ## no $
## Supply a data argument
data = facs,
## as before
outer=TRUE,
scales = list(x = list(rot = 90, tck=c(1,0))),
ylab=c("y1", "y2"),
xlab=c("Site 1", "Site 2"),
strip=FALSE)

G

> 
> On Wed, Aug 25, 2010 at 11:04 AM, Kay Cichini wrote:
> 
> >
> > hello,
> >
> > i want to stack two lattice plots beneath each other using one x-axis and
> > sharing the same text-panels,
> > like:
> > #
> > library(lattice)
> >
> > y1 <- rnorm(100,100,10)
> > y2 <- rnorm(100,10,1)
> > facs<-expand.grid(Sites=rep(c("Site I","Site II"),25),Treatment=c("A","B"))
> > pl1<-dotplot(y1 ~ facs$Treatment|facs$Sites,
> > scales = list(x = list(rot = 90, tck=c(1,0
> > pl2<-dotplot(y2 ~ facs$Treatment|facs$Sites,
> > scales = list(x = list(rot = 90, tck=c(1,0
> >
> > print(pl1, split=c(1,2,1,2), more=TRUE)
> > print(pl2, split=c(1,1,1,2))
> > #
> >
> > but as said, ideally the plots should be stacked with only the lower plot
> > giving the x-axis annotation
> > and only the upper plot with text-panels.
> >
> > thanks a lot,
> > kay
> >
> > -
> > 
> > Kay Cichini
> > Postgraduate student
> > Institute of Botany
> > Univ. of Innsbruck
> > 
> >
> > --
> > View this message in context:
> > http://r.789695.n4.nabble.com/lattice-help-required-tp2338382p2338382.html
> > Sent from the R help mailing list archive at Nabble.com.
> >
> > __
> > R-help@r-project.org mailing list
> > https://stat.ethz.ch/mailman/listinfo/r-help
> > PLEASE do read the posting guide
> > http://www.R-project.org/posting-guide.html
> > and provide commented, minimal, self-contained, reproducible code.
> >
> 
>   [[alternative HTML version deleted]]
> 
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

-- 
%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%
 Dr. Gavin Simpson [t] +44 (0)20 7679 0522
 ECRC, UCL Geography,  [f] +44 (0)20 7679 0565
 Pearson Building, [e] gavin.simpsonATNOSPAMucl.ac.uk
 Gower Street, London  [w] http://www.ucl.ac.uk/~ucfagls/
 UK. WC1E 6BT. [w] http://www.freshwaters.org.uk
%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%

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

2010-08-26 Thread Gavin Simpson
On Thu, 2010-08-26 at 02:30 -0400, David Kane wrote:
> How reliable is R-Forge? http://r-forge.r-project.org/
> 
> It is down now (for me). Reporting "R-Forge Could Not Connect to Database: "
> 
> I have just started to use it for a project. It has been down for
> several hours (at least) on different occasions over the last couple
> of days. Is that common? Will it be more stable soon?
> 
> Apologies if this is not an appropriate question for R-help.
> 
> Dave Kane

In my experience, very. Although in the past few days there have been
two periods of downtime (error as you report). The resource has been
going through lots of changes over the past several months so some of
the features of R-Forge have been offline (like the full build process)
from time to time, but this is the first full outage I've been aware of
for sometime.

R-Forge hosts hundreds of projects and packages, which also attests to
general reliability.

G

-- 
%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%
 Dr. Gavin Simpson [t] +44 (0)20 7679 0522
 ECRC, UCL Geography,  [f] +44 (0)20 7679 0565
 Pearson Building, [e] gavin.simpsonATNOSPAMucl.ac.uk
 Gower Street, London  [w] http://www.ucl.ac.uk/~ucfagls/
 UK. WC1E 6BT. [w] http://www.freshwaters.org.uk
%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Change value of a slot of an S4 object within a method.

2010-08-26 Thread Joris Meys
OK, I admit. It will never win a beauty price, but I won't either so
we go pretty well together.

Seriously, I am aware this is about the worst way to solve such a
problem. But as I said, rewriting the class definitions wasn't an
option any more. I'll definitely take your advice for the next
project.

Cheers
Joris

On Wed, Aug 25, 2010 at 9:36 PM, Steve Lianoglou
 wrote:
> Howdy,

> My eyes start to gloss over on their first encounter of `substitute`
> ... add enough `eval`s and (even) an `expression` (!) to that, and
> you'll probably see me running for the hills ... but hey, if it makes
> sense to you, more power to you ;-)
>
> Glad you found a fix that works,
>
> -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
>



-- 
Joris Meys
Statistical consultant

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

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

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


Re: [R] percentage sign in expression

2010-08-26 Thread Gavin Simpson
On Thu, 2010-08-26 at 08:17 +0100, e-letter wrote:
> >On Wed, 2010-08-25 at 09:32 +0100, e-letter wrote:
> >> On 24/08/2010, David Winsemius  wrote:
> >> >
> >> > On Aug 24, 2010, at 9:37 AM, e-letter wrote:
> >> >
> >> >> Readers,
> >> >>
> >> >> According to the documentation for the function 'plotmath' there is no
> >> >> apparent possibility to add the percent sign (%) to a plot function,
> >> >
> >> > Where did you see an assertion made???
> >> >
> >> Within R I entered the command:
> >>
> >> ?plotmath
> >
> >Surely you don't expect the R help pages to document everything that
> >*isn't* possible with a given function? They'd be infinitely long! ;-)
> >
> No, following previous advice it would be preferable to add the
> following (or similar) to the documentation:
> 
> 'syntax' 'meaning'
> ...
> '%' %
> ...

Should we also get the R devs to add

'a' a
'b' b


?

This is just literal text. And as such is not what plotmath is all
about, which is providing notation for common mathematical symbology.
'%' is not, it is plain text. And that is handled by expression() or
bquote() etc. Nothing to do with plotmath.

Note that it does go into details of how to view the glyphs available
with the symbol font on your machine (using the TestChars() function
available in the example section of ?points ) and then plot these glyphs
in both the main body of the help page and in the example. So it is
documented there, but again, do you want the devs to do:

'syntax'   'Meaning'
symbol("\042")FOO
symbol("\043")BAR


How do they handle different availability of glyphs on the various OSes
that there might be etc? Hence the TestChars() and generic instructions
on how to draw all glyphs in your systems symbol font. It just requires
a little bit more effort on your part to find the correct \xxx code.

G

> >What you meant to say was, "?plotmath doesn't show me how to add a %
> >symbol to a plot. How do I do it?"
> >
> >> Also accessed using:
> >>
> >> help.start(browser="opera")
> >>
> >> Navigating the web browser page:
> >>
> >> packages
> >> packages in /usr/lib/R/library
> >> grdevices
> >> plotmath
> >>
> >> In the list headed 'syntax' and 'meaning' within the section 'details'.
> >>
> >
> >> >  > TestChars <- function(sign=1, font=1, ...)
> >> > + {
> >> > +if(font == 5) { sign <- 1; r <- c(32:126, 160:254)
> >> > +} else if (l10n_info()$MBCS) r <- 32:126 else r <- 32:255
> >> > +if (sign == -1) r <- c(32:126, 160:255)
> >> > +par(pty="s")
> >> > +plot(c(-1,16), c(-1,16), type="n", xlab="", ylab="",
> >> > + xaxs="i", yaxs="i")
> >> > +grid(17, 17, lty=1)
> >> > +for(i in r) try(points(i%%16, i%/%16, pch=sign*i, font=font,...))
> >> > + }
> >> >  > TestChars(font=5)
> >> >
> >> > Notice that the "%" sign is three characters to the right (i.e.
> >> > higher) of the "forall" symbol that is produced by the example code
> >>
> >> I can't see 'forall' in the code above.
> >
> >You need to run it in R. Then you will see a plot of the glyphs
> >available in the symbol font. 'forall' is a mathematical symbol:
> >
> >http://en.wikipedia.org/wiki/Table_of_mathematical_symbols
> >
> >> > they offer. (The numbering proceeds from bottom up which confused me
> >> > at first.)
> >> >
> >> What numbering?
> >
> >The numbering of the glyphs so you can use the number to draw the symbol
> >you want. They are on the plot. You did run the code provided by David?
> >
> I did not read any instruction that it was code to apply! Anyway,
> below is the result:
> 
> > TestChars <- function(sign=1, font=1, ...)
> + + {
> + +if(font == 5) { sign <- 1; r <- c(32:126, 160:254)
> + +} else if (l10n_info()$MBCS) r <- 32:126 else r <- 32:255
> Error: syntax error, unexpected '}' in:
> "
> "
> > +if (sign == -1) r <- c(32:126, 160:255)
> Error in sign == -1 : comparison (1) is possible only for atomic and list 
> types
> > +par(pty="s")
> Error in +par(pty = "s") : invalid argument to unary operator
> > +plot(c(-1,16), c(-1,16), type="n", xlab="", ylab="",
> + + xaxs="i", yaxs="i")
> Error: syntax error, unexpected EQ_ASSIGN, expecting ',' in "+
> plot(c(-1,16), c(-1,16), type="n", xlab="", ylab="","
> > +grid(17, 17, lty=1)
> Error in int_abline(a = a, b = b, h = h, v = v, untf = untf, ...) :
> plot.new has not been called yet
> > +for(i in r) try(points(i%%16, i%/%16, pch=sign*i, font=font,...))
> Error: object "r" not found
> > + }
> Error: syntax error, unexpected '}' in "+ }"
> > TestChars(font=5)
> Error: could not find function "TestChars"
> 
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

-- 
%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%
 Dr. Gavin Simpson [t] +44 (0)20 7679 0522
 ECR

Re: [R] Removing inter-bar spaces in barchart

2010-08-26 Thread Deepayan Sarkar
On Thu, Aug 26, 2010 at 5:22 AM, Jonathan Greenberg
 wrote:
> Oops, small typo, should be:
>
>
> barchart_test_heights=sin(c(1:100))
> barchart_test_bins=c(c(1:50),c(1:50))
> groups=c(rep(1,50),rep(2,50))
>
> # Wish below didn't have spaces!
> barchart(barchart_test_bins~barchart_test_heights,groups=groups)

barchart(barchart_test_bins~barchart_test_heights,groups=groups, box.width = 1)

(see ?panel.barchart.)

-Deepayan

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


Re: [R] Looking for an image (R 64-bit on Linux 64-bit) on Amazon EC2

2010-08-26 Thread Sarah Goslee
It would presumably help you get a good answer if you explained
what Amazon EC2 was, and what limitations are involved in that
platform. You got a very good answer for standard 64-bit Linux,
because that was the recognizable part of your query. To go beyond
that we need more information.

*Can* you install software from source? What version of linux is
it running? Are repos for that version available? Etc. In other
words, how do you install any software?

Sarah

On Wed, Aug 25, 2010 at 9:12 PM, noclue_  wrote:
>
>
>>> You have a 64 bit Linux?  If so...
>
>>>Dowload the sources
>
> Do you mean download Linux kernel source code and then compile it on Amazon
> EC2?
>
>
> --
> View this message in context: 
> http://r.789695.n4.nabble.com/Looking-for-an-image-R-64-bit-on-Linux-64-bit-on-Amazon-EC2-tp2338938p2339072.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.
>



-- 
Sarah Goslee
http://www.stringpage.com
http://www.astronomicum.com
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] Surprising behaviour survey-package with missing values

2010-08-26 Thread Jan van der LAan
[I already sent this message to the list almost a day ago using an  
other email address, but that message does not seem to get through. In  
case it finally does get through, I appologize for the the double  
posting]


Dear list,

I got some surprising results when using the svytotal routine from the  
survey package with data containing missing values.


Some example code demonstrating the behaviour is included below.

I have a stratified sampling design where I want to estimate the total  
income. In some strata some of the incomes are missing. I want to  
ignore these missing incomes. I would have expected that  
svytotal(~income, design=mydesign, na.rm=TRUE) would do the trick.  
However, when calculating the estimates 'by hand' the estimates were  
different from those obtained from svytotal. The estimated mean  
incomes do agree with each other. It seems that using the na.rm option  
with svytotal is the same as replacing the missing values with zero's,  
which is not what I would have expected, especially since this  
behaviour seems to differ from that of svymean. Is there a reason for  
this behaviour?


I can of course remove the missing values myself before creating the  
survey object. However, with many different variables with different  
missing values, this is not very practical. Is there an easy way to  
get the behaviour I want?


Thanks for your help.

With regards,

Jan van der Laan


=== EXAMPLE ===

library(survey)
library(plyr)

# generate some data
data <- data.frame(
 id = 1:20,
 stratum = rep(c("a", "b"), each=10),
 income = rnorm(20, 100),
 n = rep(c(100, 200), each=10)
 )
data$income[5] <- NA

# calculate mean and total income for every stratum using survey package
des <- svydesign(ids=~id, strata=~stratum, data=data, fpc=~n)
svyby(~income, by=~stratum, FUN=svytotal, design=des, na.rm=TRUE)
mn  <- svyby(~income, by=~stratum, FUN=svymean, design=des, na.rm=TRUE)
mn
n   <- svyby(~n, by=~stratum, FUN=svymean, design=des)

# total does not equal mean times number of persons in stratum
mn[2] * n[2]

# calculate mean and total income 'by hand'. This does not give the same total
# as svytotal, but it does give the same mean
ddply(data, .(stratum), function(d) {
   data.frame(
 mean = mean(d$income, na.rm=TRUE),
 n = mean(d$n),
 total = mean(d$income, na.rm=TRUE) * mean(d$n)
   )
 })

# when we set income to 0 for missing cases and repeat the previous estimation
# we get the same answer as svytotal (but not svymean)
data2 <- data
data2$income[is.na(data$income )] <- 0
ddply(data2, .(stratum), function(d) {
   data.frame(
 mean = mean(d$income, na.rm=TRUE),
 n = mean(d$n),
 total = mean(d$income, na.rm=TRUE) * mean(d$n)
   )
 })

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

2010-08-26 Thread Jari Oksanen
David Kane  kanecap.com> writes:

> 
> How reliable is R-Forge? http://r-forge.r-project.org/
> 
> It is down now (for me). Reporting "R-Forge Could Not Connect to Database: "
> 
> I have just started to use it for a project. It has been down for
> several hours (at least) on different occasions over the last couple
> of days. Is that common? Will it be more stable soon?
> 
> Apologies if this is not an appropriate question for R-help.
> 
Dave,

This is rather a subject for R-devel. Ignoring this inappropriateness: yes,
indeed, R-Forge has been flaky lately. The database was disconnected for the
whole weekend, came back on Monday, and is gone again. It seems that mailing
lists and email alerts of commits were not working even when the basic R-Forge
was up.

I have sent two messages to r-fo...@r-project.org on these problems. I haven't
got no response, but soon after the first message the Forge woke up, and soon
after the second message it went down. Since I'm not Bayeasian, I don't know
what to say about the effect of my messages.

Cheers, Jari Oksanen

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

2010-08-26 Thread Ben Holt
I have data similar to this:

Location Surveyor Result
A1 83
A2 76
A3 45
B1 71
B4 67
C2 23
C5 12
D3 34
E4 75
F4 46
G5 90
etc (5 million records in total)

I need to divide the data to many subsets then randomly select 5 different 
locations and 5 different surveyors (one at each of the 5 randomly selected 
locations) for each subset.

The function I have written basically picks five locations and then 1 surveyor 
in each location, checks that there are five different surveyors and if there 
isn't tries again.  The problem is that for some subsets this doesn't work.

Some subsets don't have enough locations/surveyors or both, but this can be 
checked for easily.  The problem subsets do have enoughs locations and 
surveyors but still cannot produce 5 locations each with a different surveyor.  
The matrix below demonstrates such a subset:
 
  locations
  A B C D E
1 1 0 0 0 0
Surveyors   2 1 0 0 0 0
3 1 0 0 0 0
4 1 0 0 0 0
5 1 1 1 1 1

I cannot think of a way to check for such a situation and therefore I have 
simply programmed the function to give up after 100 attempts if it can't find a 
solution.  This is not very satisfactory however as the analysis takes a very 
long time to run and it would also be very useful useful for me to know how 
many suitable solution there are.

I reckon some of you clever folk out there must be able to think of a better 
solution.

Any advice appreciated,

Ben

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


Re: [R] Problem with terms of the form (a >1) and subsetting of a terms object

2010-08-26 Thread Niels Richard Hansen



On 26/08/10 09.30, Dimitris Rizopoulos wrote:

I think you need an I(), i.e.,

form <- ~ I(a > 1) - 1


Yes, it solves the concrete problem, but does not really answer
the question. Let me rephrase. Should the use of terms like (a>1)
be discouraged in R and replaced by I(a>1) systematically, or is the
behavior below unexpected?

Best, Niels




I hope it helps.

Best,
Dimitris


On 8/26/2010 9:17 AM, Niels Richard Hansen wrote:

I have the following problem

mydata <- data.frame(a=1:3)
form <- ~ (a>1) - 1
model.matrix(form,mydata)

a > 1FALSE a > 1TRUE
1 1 0
2 0 1
3 0 1
...

However

model.matrix(update(terms(form)[1],~.-1),mydata)

(Intercept) a > 1 - 1TRUE
1 1 1
2 1 1
3 1 1
...

Taking

terms(form)[1]

extracts the formula with only the first term, but the parentheses
are thrown away, and after the update, I get a different formula.
Is that supposed to be so?

Thanks, Niels





--
Niels Richard Hansen Web:   www.math.ku.dk/~richard 
Associate Professor  Email: niels.r.han...@math.ku.dk
Department of Mathematical Sciences nielsrichardhan...@gmail.com
University of Copenhagen Skype: nielsrichardhansen.dk   
Universitetsparken 5 Phone: +45 353 20783 (office)  
2100 Copenhagen Ø   +45 2859 0765 (mobile)
Denmark

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

2010-08-26 Thread David Hajage
Hello useRs and guRus,

I was trying to add the support of str() in the ascii package, and I
realized that str() does not have a print method. It uses cat() from inside
the function and returns nothing.

Since it is not usual in R, I wonder why? Is there a particular reason?

Thank you very much for your attention on... well, this unimportant
question.

david

[[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] Problems when Apply a script to a list

2010-08-26 Thread Evgenia

Dear users, 

***I have a function f to simulate data from a model (example below used
only to show my problems)

f<-function(n,mean1){
a<-matrix(rnorm(n, mean1 , sd = 1),ncol=5)
b<-matrix(runif(n),ncol=5)
data<-rbind(a,b)
out<-data
out}

*I want to simulate 1000 datasets (here only 5) so I use
S<-list()

for (i in 1:5){
S[[i]]<-f(n=10,mean1=0)}

**I have a very complicated function  for estimation of a model which I
want to apply to Each one of the above simulated datasets

fun<-function(data){data<-as.matrix(data)
sink(' Example.txt',append=TRUE) 
  cat("\n***\nEstimation
\n\nDataset Sim : ", 
i )
d<-data%*%t(data)
s<-solve(d)
print(s)
out<-s
out
}
results<-list()
for (i in 1:5){results[[i]]<-fun(data=S[[i]])}


My questions are:
1) for some datasets system is computational singular and this causes
execution of the for to stop.By this way I have only results until this
problem happens.How can I pass over the execution for this step and have
results for All other datasets for which function fun is applicable?

2) After some runs to my program, I receive this error message someError in
sink("output.txt") : sink stack is full . How can I solve this problem, as I
want to have results of my program for 1000 datasets.

3) Using for is the correct way to run my proram for a list

Thanks alot

Evgenia

-- 
View this message in context: 
http://r.789695.n4.nabble.com/Problems-when-Apply-a-script-to-a-list-tp2339403p2339403.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] Showing a line function on the ploat area

2010-08-26 Thread Jim Lemon

On 08/26/2010 01:06 AM, Neta wrote:


I have a collection of results. I use R to get the linearization presented.
how can I get R to show the equation and R^2 value on the plot area next to
the graph?


Hi Neta,
You can use functions like textbox or boxed.labels (plotrix package) to 
display arbitrary text:



par(mar=c(6,4,4,2))
plot(1:5)
par(xpd=TRUE)
library(plotrix)
boxed.labels(4,0,
 "response~x1+x2\nr-squared = 0.7326",FALSE)
par(xpd=FALSE

Jim

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


Re: [R] Removing inter-bar spaces in barchart

2010-08-26 Thread Jim Lemon

On 08/26/2010 06:36 AM, Dennis Murphy wrote:

...
It looks like he's using barchart() in lattice, which does have a box.ratio
argument.


That's why I didn't suggest using barp with width=0.5

Jim

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


Re: [R] using an objects contents in a text string

2010-08-26 Thread josquint

Thankyou!!!  I knew this was so simple and I had tried paste but with the
wrong syntax so I moved on. This opens a whole new world to me!! 
-- 
View this message in context: 
http://r.789695.n4.nabble.com/using-an-objects-contents-in-a-text-string-tp2338061p2339437.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] frequency table for a list matching some conditions

2010-08-26 Thread Olga Lyashevska
Dear all,

I have a list that contains 3 sublists( x1, x2, x3)

mylist<-list(x1=c("A","A","A","B","C","Z","Y"),x2=c("D","D","E","E","F","Z","X"),x3=c("A","A","A","B","Y","Z"))
mylist
$x1
[1] "A" "A" "A" "B" "C" "Z" "Y"

$x2
[1] "D" "D" "E" "E" "F" "Z" "X"

$x3
[1] "A" "A" "A" "B" "Y" "Z"

I also have another list, that contains some specific elements.
newlist<-c("A","B","C","D","E","F")
newlist
[1] "A" "B" "C" "D" "E" "F"

I want to match mylist[1], mylist[2], etc with newlist and I am looking for the 
following output:

A  B  C  D  E  F
x1  3  1  1  NA NA NA
x2  NA NA NA 2  2  1
x3  3  1  NA NA NA NA

Any thoughts?

Many thanks 
Olga

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

2010-08-26 Thread josquint

The answer is indeed a LINUX cluster with more memory. Thanks, Josquin
-- 
View this message in context: 
http://r.789695.n4.nabble.com/vector-allocation-error-tp2333299p2339451.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] frequency table for a list matching some conditions

2010-08-26 Thread Dimitris Rizopoulos

one way is the following:

mylist <- list(x1 = c("A","A","A","B","C","Z","Y"),
x2 = c("D","D","E","E","F","Z","X"),
x3 = c("A","A","A","B","Y","Z"))
newlist <- c("A","B","C","D","E","F")


tab <- t(sapply(mylist, function (x)
table(factor(x, levels = newlist
tab[tab == 0] <- NA
tab


I hope it helps.

Best,
Dimitris


On 8/26/2010 11:47 AM, Olga Lyashevska wrote:

Dear all,

I have a list that contains 3 sublists( x1, x2, x3)

mylist<-list(x1=c("A","A","A","B","C","Z","Y"),x2=c("D","D","E","E","F","Z","X"),x3=c("A","A","A","B","Y","Z"))
mylist
$x1
[1] "A" "A" "A" "B" "C" "Z" "Y"

$x2
[1] "D" "D" "E" "E" "F" "Z" "X"

$x3
[1] "A" "A" "A" "B" "Y" "Z"

I also have another list, that contains some specific elements.
newlist<-c("A","B","C","D","E","F")
newlist
[1] "A" "B" "C" "D" "E" "F"

I want to match mylist[1], mylist[2], etc with newlist and I am looking for the 
following output:

A  B  C  D  E  F
x1  3  1  1  NA NA NA
x2  NA NA NA 2  2  1
x3  3  1  NA NA NA NA

Any thoughts?

Many thanks
Olga

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



--
Dimitris Rizopoulos
Assistant Professor
Department of Biostatistics
Erasmus University Medical Center

Address: PO Box 2040, 3000 CA Rotterdam, the Netherlands
Tel: +31/(0)10/7043478
Fax: +31/(0)10/7043014

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

2010-08-26 Thread Petr PIKAL
Dear all

I want to save several ggplots in one pdf document. I tried this

for (i in names(iris)[2:4]) {
p<-ggplot(iris, aes(x=Sepal.Length, y=iris[,i], colour=Species))
p+geom_point(aes(size=3))
}

with different variations of y input but was not successful. In past I 
used qplot in similar fashion which worked

for(i in names(mleti)[7:15]) print(qplot(sito, mleti1[,i], 
facets=~typ,ylab=i, geom=c("point", "line"), colour=ordered(minuty), 
data=mleti1))

So I wonder if anybody used ggplot in cycle and how to solve input of 
variables throughout cycle

Thank you

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] ggplot inside cycle

2010-08-26 Thread Abhijit Dasgupta, PhD
You haven't wrapped p in the print command, which is one of the ways to 
make sure the plot gets printed  when we need it.

 print(p+geom_point(aes(size=3))) does the trick
On 08/26/2010 06:08 AM, Petr PIKAL wrote:

Dear all

I want to save several ggplots in one pdf document. I tried this

for (i in names(iris)[2:4]) {
p<-ggplot(iris, aes(x=Sepal.Length, y=iris[,i], colour=Species))
p+geom_point(aes(size=3))
}

with different variations of y input but was not successful. In past I
used qplot in similar fashion which worked

for(i in names(mleti)[7:15]) print(qplot(sito, mleti1[,i],
facets=~typ,ylab=i, geom=c("point", "line"), colour=ordered(minuty),
data=mleti1))

So I wonder if anybody used ggplot in cycle and how to solve input of
variables throughout cycle

Thank you

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.



__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Problems when Apply a script to a list

2010-08-26 Thread Joris Meys
Answers below.

On Thu, Aug 26, 2010 at 11:20 AM, Evgenia  wrote:
>
> Dear users,
>
> ***I have a function f to simulate data from a model (example below used
> only to show my problems)
>
> f<-function(n,mean1){
> a<-matrix(rnorm(n, mean1 , sd = 1),ncol=5)
> b<-matrix(runif(n),ncol=5)
> data<-rbind(a,b)
> out<-data
> out}
>
> *I want to simulate 1000 datasets (here only 5) so I use
> S<-list()
>
> for (i in 1:5){
> S[[i]]<-f(n=10,mean1=0)}
>
> **I have a very complicated function  for estimation of a model which I
> want to apply to Each one of the above simulated datasets
>
> fun<-function(data){data<-as.matrix(data)
> sink(' Example.txt',append=TRUE)
>          cat("\n***\nEstimation
> \n\nDataset Sim : ",
>            i )
> d<-data%*%t(data)
> s<-solve(d)
> print(s)
> out<-s
> out
> }
> results<-list()
> for (i in 1:5){results[[i]]<-fun(data=S[[i]])}
>
>
> My questions are:
> 1) for some datasets system is computational singular and this causes
> execution of the for to stop.By this way I have only results until this
> problem happens.How can I pass over the execution for this step and have
> results for All other datasets for which function fun is applicable?

see ?try, or ?tryCatch.

I'd do something in the line of
for(i in 1:5){
 tmp <- try(fun(data=S[[i]]))
 results[[i]] <- ifelse(is(tmp,"try-error"),NA,tmp)
}

Alternatively, you could also use lapply :
results <- lapply(S,function(x{
   tmp <- try(fun(data=x))
ifelse(is(tmp,"try-error"),NA,tmp)
})

>
> 2) After some runs to my program, I receive this error message someError in
> sink("output.txt") : sink stack is full . How can I solve this problem, as I
> want to have results of my program for 1000 datasets.

That is because you never empty the sink. add sink() after the last
line you want in the file. This will empty the sink buffer to the
file. Otherwise R keeps everything in the memory, and that gets too
full after a while.

>
> 3) Using for is the correct way to run my proram for a list
See the lapply solution.

>
> Thanks alot
>
> Evgenia
>
> --
> View this message in context: 
> http://r.789695.n4.nabble.com/Problems-when-Apply-a-script-to-a-list-tp2339403p2339403.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.
>



-- 
Joris Meys
Statistical consultant

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

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

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


Re: [R] frequency table for a list matching some conditions

2010-08-26 Thread Olga Lyashevska
Thanks Dimitris,

It works nicely!

Regards,
Olga

On Thu, 2010-08-26 at 11:55 +0200, Dimitris Rizopoulos wrote: 
> one way is the following:
> 
> mylist <- list(x1 = c("A","A","A","B","C","Z","Y"),
>  x2 = c("D","D","E","E","F","Z","X"),
>  x3 = c("A","A","A","B","Y","Z"))
> newlist <- c("A","B","C","D","E","F")
> 
> 
> tab <- t(sapply(mylist, function (x)
>  table(factor(x, levels = newlist
> tab[tab == 0] <- NA
> tab

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

2010-08-26 Thread Petr PIKAL
Thanks. I knew I forgot something obvious.

Petr

r-help-boun...@r-project.org napsal dne 26.08.2010 12:29:52:

> You haven't wrapped p in the print command, which is one of the ways to 
> make sure the plot gets printed  when we need it.
>   print(p+geom_point(aes(size=3))) does the trick
> On 08/26/2010 06:08 AM, Petr PIKAL wrote:
> > Dear all
> >
> > I want to save several ggplots in one pdf document. I tried this
> >
> > for (i in names(iris)[2:4]) {
> > p<-ggplot(iris, aes(x=Sepal.Length, y=iris[,i], colour=Species))
> > p+geom_point(aes(size=3))
> > }
> >
> > with different variations of y input but was not successful. In past I
> > used qplot in similar fashion which worked
> >
> > for(i in names(mleti)[7:15]) print(qplot(sito, mleti1[,i],
> > facets=~typ,ylab=i, geom=c("point", "line"), colour=ordered(minuty),
> > data=mleti1))
> >
> > So I wonder if anybody used ggplot in cycle and how to solve input of
> > variables throughout cycle
> >
> > Thank you
> >
> > 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.
> >
> 
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/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] equalize function with zero and convert it

2010-08-26 Thread Immanuel Seeger
Dear all, 
I want to equalize a symbolic derivative (of a function with two
variables) with zero and convert it to a variable, e.g. x.
 
I'm computing the derivative by: (found it in the archive)
library(Ryacas)
f <- function(x,y) (100-x-y)*x-10*x
yacas(f) # register f with yacas
Df <- f
body(Df) <- yacas(expression(deriv(f(x,y),x)))[[1]]
Df
 
R-Output:
function (x, y) 
100 - x - y - x - 10
 
Questions : 
1.  How can I equalize the derivative(140-x-y-x-20) with zero?
2.  How can I convert it to x?
 
I want something like: 
45-0.5*y=x
 
With only one variable or two non-symbolic variables it's working with
uniroot(f, c(-10, 10))$root.
 
Thank you!
 
Immanuel Seeger
 
 
 
 

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

2010-08-26 Thread John Barrett [jzb]
I am trying to use Rcmdr 1.5_4 with R-2.11.1 (order to run to run the new 
version of misdist-0.5.3 which is built under R-2.11.1). however relimp is 
required for Rcmdr and the version of relimp_1.0.1 downloaded from CRAN will 
not work with the latest version of Rcmdr (I get error message telling me to 
reload it). Is there any way round this problem or will there be a new version 
relimp that is compatible?  Any advice would be gratefully received.
many thanks
John

Prof. Barrett
Univ. of Aberystwyth



[[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] Quick GREP challenge

2010-08-26 Thread Dimitri Shvorob

> grep("f[0-9]+=", "f1=5,f22=3,", value = T)
[1] "f1=5,f22=3,"

How do I make the line output c("f1", "f22") instead? (Actually, c(1,22)
would be even better).

Thank you.

 
-- 
View this message in context: 
http://r.789695.n4.nabble.com/Quick-GREP-challenge-tp2339486p2339486.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 plot y-axis on the right of x-axis

2010-08-26 Thread Jim Lemon

On 08/26/2010 08:11 AM, elaine kuo wrote:

...
One more request, if the label of axis X wants to be drawn from 5 to 1
(left to right)
rather than 1 to 5, is it fine to change axis (4, at = NULL) ?
If so, which value should be input ?



Hi Elaine,
There are a couple of ways to do this. One is to use the revaxis 
function (plotrix) that reverses the conventional direction of the axes 
by silently changing the sign of the values. If you use this, you must 
remember to change the sign of the position of your y axes. Another way 
is the plot in the normal direction but print the tick labels backwards:


plot(1:5,xaxt="n")
axis(1,1:5,5:1)

Using this method, you have to remember that your labels don't 
correspond to the values, so if you wanted a y axis positioned at x=4, 
you would have to use:


axis(2,1:5,pos=2)

Jim

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


Re: [R] lattice help required

2010-08-26 Thread Duncan Mackay

Hi

Coming a bit late to the thread another way to reduce the space between the 
panels may be along the lines of Deepayan's reply with the layout.widths in


http://finzi.psych.upenn.edu/R/Rhelp02/archive/43626.html

I regularly use this and  the latticeExtra addition will be welcome - I 
have not downloaded it yet.


Also the 'useOuterStrips'  from the latticeExtra package.may be of 
assistance in the setting the strips.


Regards

Duncan

Duncan Mackay
Department of Agronomy and Soil Science
University of New England
ARMIDALE NSW 2351
Email home: mac...@northnet.com.au


At 17:34 26/08/2010, you wrote:

On Wed, 2010-08-25 at 11:30 -0400, RICHARD M. HEIBERGER wrote:
> Kay,
>
> doe this do what you want?
>
>
> dotplot(y1+y2 ~ facs$Treatment|facs$Sites,
> outer=TRUE,
> scales = list(x = list(rot = 90, tck=c(1,0))),
> ylab=c("y1", "y2"),
> xlab=c("Site 1", "Site 2"),
> strip=FALSE)

This would be better, to avoid abusing the poor R formula handling
sugar:

dotplot(y1 + y2 ~ Treatment | Sites, ## no $
## Supply a data argument
data = facs,
## as before
outer=TRUE,
scales = list(x = list(rot = 90, tck=c(1,0))),
ylab=c("y1", "y2"),
xlab=c("Site 1", "Site 2"),
strip=FALSE)

G

>
> On Wed, Aug 25, 2010 at 11:04 AM, Kay Cichini 
wrote:

>
> >
> > hello,
> >
> > i want to stack two lattice plots beneath each other using one x-axis and
> > sharing the same text-panels,
> > like:
> > #
> > library(lattice)
> >
> > y1 <- rnorm(100,100,10)
> > y2 <- rnorm(100,10,1)
> > facs<-expand.grid(Sites=rep(c("Site I","Site 
II"),25),Treatment=c("A","B"))

> > pl1<-dotplot(y1 ~ facs$Treatment|facs$Sites,
> > scales = list(x = list(rot = 90, tck=c(1,0
> > pl2<-dotplot(y2 ~ facs$Treatment|facs$Sites,
> > scales = list(x = list(rot = 90, tck=c(1,0
> >
> > print(pl1, split=c(1,2,1,2), more=TRUE)
> > print(pl2, split=c(1,1,1,2))
> > #
> >
> > but as said, ideally the plots should be stacked with only the lower plot
> > giving the x-axis annotation
> > and only the upper plot with text-panels.
> >
> > thanks a lot,
> > kay
> >
> > -
> > 
> > Kay Cichini
> > Postgraduate student
> > Institute of Botany
> > Univ. of Innsbruck
> > 
> >
> > --
> > View this message in context:
> > 
http://r.789695.n4.nabble.com/lattice-help-required-tp2338382p2338382.html

> > Sent from the R help mailing list archive at Nabble.com.
> >
> > __
> > R-help@r-project.org mailing list
> > https://stat.ethz.ch/mailman/listinfo/r-help
> > PLEASE do read the posting guide
> > 
http://www.R-project.org/posting-guide.html

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

> and provide commented, minimal, self-contained, reproducible code.

--
%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%
 Dr. Gavin Simpson [t] +44 (0)20 7679 0522
 ECRC, UCL Geography,  [f] +44 (0)20 7679 0565
 Pearson Building, [e] gavin.simpsonATNOSPAMucl.ac.uk
 Gower Street, London  [w] http://www.ucl.ac.uk/~ucfagls/
 UK. WC1E 6BT. [w] http://www.freshwaters.org.uk
%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] SEM : Warning : Could not compute QR decomposition of Hessian

2010-08-26 Thread Anne Mimet

Dear John,

Thank a lot for your answer. Indeed, i misunderstood the place of  
indicator variables in the path diagram, i thank they were considered  
as exogeneous variables. Thanks for your answer, i changed variances  
of latente variables to NA, and remove indicator variables from  
fixed.x argument. Unfortunately, it doesn't change the warning message.

I place the path diagram of the model here : http://yfrog.com/n7pathdiagj

Because of the diagram complexity, i used some colors for the  
different paths :

- green for environnental variable
- brown for landscape variables
- orange for municipalities variables
- blue for inter-municipalitie variables
- red for departemental variable
- grey for landuse variables
- and in dark the relations between indicator and latente variables,  
errors, variances and covariances.


There must be other mistakes in the model, i can't find them.

Thanks again,

Regards,

Anne



John Fox  a écrit :


Dear Anne,

I started to diagram your model but stopped when I noticed some problems:
(1) Some variables, such as pays_alti, are clearly endogenous, since they
have arrows pointing to them, yet are declared as fixed exogenous variables;
that clearly doesn't make sense. (2) You've placed conflicting constraints
on factor loadings and the variances of latent variables, for example
setting both the path from the factor type_paysage to the indicator
pays_alti and the variance of type_paysage to 1; again, that doesn't make
sense.

Do you have a path diagram for the model that you're trying to fit? It would
in particular be helpful to have a diagram of the structural part of the
model.

Regards,
 John


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



-Original Message-
From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org]

On

Behalf Of Anne Mimet
Sent: August-25-10 10:27 AM
To: r-help@r-project.org
Subject: [R] SEM : Warning : Could not compute QR decomposition of Hessian

Hi useRs,

I'm trying for the first time to use a sem. The model finally runs,
but gives a warning saying :
"In sem.default(ram = ram, S = S, N = N, param.names = pars, var.names
= vars,  :   Could not compute QR decomposition of Hessian.
Optimization probably did not converge. "

I found in R-help some posts on this warning, but my attemps to modify
the code didn't change the warning message (i tried to give an error
of 1 to the latente variables). I can't figure what the problem is.
Here is the code :


tab<-read.table("F:/Mes documents/stats/sem/donnees_corr.txt",
header=T, sep="",na.strings = "NA")

tab[,46]<-as.factor(tab[,46])
tab[,24]<-as.factor(tab[,24])
tab[,40]<-as.factor(tab[,40])

fct_cor<-hetcor(tab, ML=T)
cor_tab<- fct_cor$correlations

moment_tab<-read.moments(diag=F, names=c('c1','c2', 'c3','c4','c5',
'c6','c7', 'c8', 'c9',  'ind_plando', 'long_sup15', 'long_inf15',
'pente', 'est', 'sud','ouest', 'nord' ,'reg_hydriq', 'prof_sol',
'pierro', 'efferv', 'struct','drainage','texture', 'route1_pond',
'route2_pond',
'pourcactif', 'tx_chomage', 'pourcagric', 'pourc_jeunes', 'pop99',
'rev_imp_foyer','eq_CONC', 'eq_sante', 'eq_edu', 'sold_nat',
'sold_mig', 'tps_dom_emp','TXEMPLOI','ORIECO','dist_paris','axe1',
'axe2', 'axe3', 'dist_protect','urbanisation','pays_incli','pays_alti'))
# after comes the moment matrix (triangular)

ram_tab<-specify.model()
type_paysage->pays_alti,NA,1
type_paysage->pays_incli, pays2, NA
pedo->reg_hydriq, NA, 1
pedo->prof_sol, ped8, NA
pedo->pierro, ped9, NA
pedo->efferv, ped10, NA
pedo->struct, ped11, NA
pedo->drainage, ped12, NA
pedo->texture, ped13, NA
adj_99->c1, NA,1
adj_99->c2, adj2,NA
adj_99->c3, adj3,NA
adj_99->c4, adj4,NA
adj_99->c5, adj5,NA
adj_99->c6, adj6,NA
adj_99->c7, adj7,NA
adj_99->c8, adj8,NA
adj_99->c9, adj9,NA
etat_hexa->axe1, NA, 1
etat_hexa->axe2, et2, NA
etat_hexa->axe3, et3, NA
socioBV->sold_mig, BV1, NA
socioBV->sold_nat, BV2, NA
socioBV->TXEMPLOI, BV3, NA
socioBV->ORIECO, BV4, NA
socioBV->tps_dom_emp, NA, 1
eqBV->eq_CONC, NA, 1
eqBV->eq_sante, eq2, NA
eqBV->eq_edu, eq3, NA
socio_com->pourcactif , NA, 1
socio_com->tx_chomage, com2, NA
socio_com->pourcagric, com3, NA
socio_com->pourc_jeunes, com4, NA
socio_com->pop99, com5, NA
socio_com->rev_imp_foyer, com7, NA
access_hexa->route1_pond, NA, 1
access_hexa->route2_pond, acc2, NA
hydro->ind_plando, NA, 1
hydro->long_sup15, eau2, NA
hydro->long_inf15, eau3, NA
topog->pente, NA, 1
topog->est, top2, NA
topog->sud, top3, NA
topog->nord, top4, NA
topog->ouest, top5, NA
dist_protect-> urbanisation, cor1,NA
dist_protect-> adj_99, cor2, NA
dist_protect-> etat_hexa, cor3, NA
topog-> urbanisation, cor4, NA
topog-> adj_99, cor5, NA
topog-> etat_hexa, cor6, NA
topog-> access_hexa, cor7, NA
topog<->hydro, cor8, NA
topog<->pedo, cor9, NA
pedo-> urbanisation, cor10, NA
pedo-> adj_99, cor11, NA
pedo-> etat_hexa, cor12, NA
pedo<->hydro, cor1,

Re: [R] Quick GREP challenge

2010-08-26 Thread Sarah Goslee
It isn't entirely clear what you are trying to do - your grep() statement
simply returns the entire string you started with.

But to turn that string into a vector, you will need some combination
of gsub(), strsplit(), and as.numeric() with the exact values depending
on the exact form of the output returned by grep. By c(1, 22) do you
mean a vector (my first assumption), or do you actually mean the
string "c(1, 22)"?

If the former, maybe something like this:

> x <- "f1=5,f22=3"
> x <- gsub("=[0-9]+", "", x)
> x
[1] "f1,f22"
> x <- gsub("f", "", x)
> x
[1] "1,22"
> x <- strsplit(x, ",")
> x
[[1]]
[1] "1"  "22"

> x <- unlist(x)
> x
[1] "1"  "22"
> x <- as.numeric(x)
> x
[1]  1 22

Sarah

On Thu, Aug 26, 2010 at 6:16 AM, Dimitri Shvorob
 wrote:
>
>> grep("f[0-9]+=", "f1=5,f22=3,", value = T)
> [1] "f1=5,f22=3,"
>
> How do I make the line output c("f1", "f22") instead? (Actually, c(1,22)
> would be even better).
>
> Thank you.
>
>


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


Re: [R] Quick GREP challenge

2010-08-26 Thread Duncan Mackay

I too am unsure of what is required but another way is

gsub(",$","",gsub("[f53=]+","",a))
[1] "1,22"

Regards

Duncan

Duncan Mackay
Department of Agronomy and Soil Science
University of New England
ARMIDALE NSW 2351
Email home: mac...@northnet.com.au



At 21:47 26/08/2010, you wrote:

It isn't entirely clear what you are trying to do - your grep() statement
simply returns the entire string you started with.

But to turn that string into a vector, you will need some combination
of gsub(), strsplit(), and as.numeric() with the exact values depending
on the exact form of the output returned by grep. By c(1, 22) do you
mean a vector (my first assumption), or do you actually mean the
string "c(1, 22)"?

If the former, maybe something like this:

> x <- "f1=5,f22=3"
> x <- gsub("=[0-9]+", "", x)
> x
[1] "f1,f22"
> x <- gsub("f", "", x)
> x
[1] "1,22"
> x <- strsplit(x, ",")
> x
[[1]]
[1] "1"  "22"

> x <- unlist(x)
> x
[1] "1"  "22"
> x <- as.numeric(x)
> x
[1]  1 22

Sarah

On Thu, Aug 26, 2010 at 6:16 AM, Dimitri Shvorob
 wrote:
>
>> grep("f[0-9]+=", "f1=5,f22=3,", value = T)
> [1] "f1=5,f22=3,"
>
> How do I make the line output c("f1", "f22") instead? (Actually, c(1,22)
> would be even better).
>
> Thank you.
>
>


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


[R] Random slopes in lmer

2010-08-26 Thread Samantha Patrick
Hi

I want to extract the random slopes from a lmer (I am doing a random 
regression), but are the answers obtained from ranef or coef?

My model is: mod1<-lmer(B~ A +(A|bird), family=quasibinomial)

And I want to obtain a slope for each individual bird but am not sure which 
output I need and can't find the answer anywhere.

Thanks

Sam


Dr Samantha Patrick
EU INTERREG Post Doc
Davy 618
Marine Biology & Ecology Research Centre
University of Plymouth
Plymouth
PL4 8AA

T: 01752 586165
M: 07740472719


[[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] Quick GREP challenge

2010-08-26 Thread Gabor Grothendieck
On Thu, Aug 26, 2010 at 6:16 AM, Dimitri Shvorob
 wrote:
>
>> grep("f[0-9]+=", "f1=5,f22=3,", value = T)
> [1] "f1=5,f22=3,"
>
> How do I make the line output c("f1", "f22") instead? (Actually, c(1,22)
> would be even better).
>

strapply in gsubfn extracts matches based on content rather than
delimiters.  See home page for more info http://gsubfn.googlecode.com

> library(gsubfn)
> x <- "f1=5,f22=3,"
> strapply(x, "f\\d+")[[1]]
[1] "f1"  "f22"

-- 
GKX Group
GKX Associates Inc.
1-877-GKX-GROUP
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] print method for str?

2010-08-26 Thread Gabor Grothendieck
On Thu, Aug 26, 2010 at 4:42 AM, David Hajage  wrote:
> Hello useRs and guRus,
>
> I was trying to add the support of str() in the ascii package, and I
> realized that str() does not have a print method. It uses cat() from inside
> the function and returns nothing.
>
> Since it is not usual in R, I wonder why? Is there a particular reason?
>
> Thank you very much for your attention on... well, this unimportant
> question.
>

It still dispatches to S3 methods though.  See str.zoo in the zoo
package as an example.

-- 
GKX Group
GKX Associates Inc.
1-877-GKX-GROUP
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.


[R] Passing data to aov

2010-08-26 Thread Bryan Hanson
Hello Again Gurus and Lurkers:

I¹m trying to build a very user-friendly function which does aov without
having the user type in a formula (which would be tedious in this case).
The idea is to take the response from a PCA score matrix, and the factors
from a list.  A simple example is the function given below, along with test
data and a sample call to the function.

I'm certainly having trouble understanding the proper ways to work with
formulas and related items, but I think what I do in the function should
work (it's built on ideas dug out of the archives).  However, when the data
is passed to aov (directly or via manova), something in the bowels of aov
complains with the following error:

Error in model.frame.default(formula = form, drop.unused.levels = TRUE) :
  object is not a matrix

To me, the formula looks legitimate, and the variables in the formula are
all in the environment (I think: The way I am doing this is basically that
described in ?summary.manova where only a formula is passed, no data
argument).  Based upon reading the archives, the problem might arise with
one of the deparse statements in aov, but I can't resolve it.  It might also
be one of scoping/environment, but again, this is only an idea.

TIA for any assistance.  Bryan
*
Bryan Hanson
Professor of Chemistry & Biochemistry
DePauw University, Greencastle IN USA


hypTestScores <-
function(mylist, score.matrix, pcs = 1:3, fac = NULL, ...) {

scores <- score.matrix[,pcs]
#str(scores)# looks correct to me
form <- as.formula(paste("scores", "~", paste(fac, collapse = "*")),
env = parent.frame())
#str(form)   # looks correct to me
attach(mylist)
if (length(pcs) > 1) out <- manova(formula = form, ...)
if (length(pcs) == 1) out <- aov(formula = form, ...)
print(summary(out))
detach(mylist)
invisible(out) 
}

# test data
td1 <- matrix(rnorm(50), ncol = 5) # like PCA scores
td2 <- list(
f1 = as.factor(sample(c("A", "B"), 10, replace = TRUE)),
f2 = as.factor(sample(c("C", "D"), 10, replace = TRUE)))

# test call
hypTestScores(mylist = td2, score.matrix = td1,
fac = c("f1", "f2"))
detach("mylist") # needed if there is an error

> sessionInfo()
R version 2.11.0 (2010-04-22)
x86_64-apple-darwin9.8.0

locale:
[1] en_US.UTF-8/en_US.UTF-8/C/C/en_US.UTF-8/en_US.UTF-8

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

other attached packages:
 [1] faraway_1.0.4  GGally_0.2 xtable_1.5-6
 [4] mvbutils_2.5.1 ggplot2_0.8.8  proto_0.3-8
 [7] reshape_0.8.3  ChemoSpec_1.45 R.utils_1.4.0
[10] R.oo_1.7.2 R.methodsS3_1.2.0  rgl_0.91
[13] lattice_0.18-5 mvoutlier_1.4  plyr_1.0.3
[16] RColorBrewer_1.0-2 chemometrics_0.8   som_0.3-5
[19] robustbase_0.5-0-1 rpart_3.1-46   pls_2.1-0
[22] pcaPP_1.8-1mvtnorm_0.9-9  nnet_7.3-1
[25] mclust_3.4.4   MASS_7.3-5 lars_0.9-7
[28] e1071_1.5-23   class_7.3-2

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

2010-08-26 Thread Ista Zahn
Hi John,
I'm having some trouble sorting out your request, for the following reasons:

1) I don't know what misdist is (can't find it on CRAN or google) or why you
need Rcmdr to run it. Presumably you meant mixdist?
2) relimp is not required by Rcmdr, merely suggested. Rcmdr will work fine
without it.
3) I hope that by "downloaded from CRAN" you do not mean that you manually
downloaded it. R has package management, use it! What happens exactly when
you try

install.packages("Rcmdr" dep=TRUE)

?
4) I had no trouble installing Rcmdr (and all dependencies etc., including
relimp) using the command above. My session information is below. Please
include yours (as well as the actual errors you get, if any) in your reply.

> sessionInfo()
R version 2.11.1 (2010-05-31)
i486-pc-linux-gnu

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

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

other attached packages:
[1] Rcmdr_1.6-0 car_2.0-2   survival_2.35-8 nnet_7.3-1
[5] MASS_7.3-7

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


Best,
Ista

On Thu, Aug 26, 2010 at 6:39 AM, John Barrett [jzb]  wrote:

> I am trying to use Rcmdr 1.5_4 with R-2.11.1 (order to run to run the new
> version of misdist-0.5.3 which is built under R-2.11.1). however relimp is
> required for Rcmdr and the version of relimp_1.0.1 downloaded from CRAN will
> not work with the latest version of Rcmdr (I get error message telling me to
> reload it). Is there any way round this problem or will there be a new
> version relimp that is compatible?  Any advice would be gratefully received.
> many thanks
> John
>
> Prof. Barrett
> Univ. of Aberystwyth
>
>
>
>[[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.
>



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

[[alternative HTML version deleted]]

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


Re: [R] equalize function with zero and convert it

2010-08-26 Thread Gabor Grothendieck
On Thu, Aug 26, 2010 at 6:57 AM, Immanuel Seeger  wrote:
> Dear all,
> I want to equalize a symbolic derivative (of a function with two
> variables) with zero and convert it to a variable, e.g. x.
>
> I'm computing the derivative by: (found it in the archive)
> library(Ryacas)
> f <- function(x,y) (100-x-y)*x-10*x
> yacas(f) # register f with yacas
> Df <- f
> body(Df) <- yacas(expression(deriv(f(x,y),x)))[[1]]
> Df
>
> R-Output:
> function (x, y)
> 100 - x - y - x - 10
>
> Questions :
> 1.      How can I equalize the derivative(140-x-y-x-20) with zero?
> 2.      How can I convert it to x?
>
> I want something like:
> 45-0.5*y=x
>
> With only one variable or two non-symbolic variables it's working with
> uniroot(f, c(-10, 10))$root.
>

This solves for x:

> library(Ryacas)
Loading required package: XML
> x <- Sym("x")
> y <- Sym("y")
> Solve((100-x-y)*x-10*x == 0, "x")
[1] "Starting Yacas!"
expression(list(x == -((10 - (100 - y) + root((100 - y - 10)^2,
2))/2), x == -((10 - (100 - y) - root((100 - y - 10)^2, 2))/2)))

-- 
GKX Group
GKX Associates Inc.
1-877-GKX-GROUP
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] Problem with terms of the form (a >1) and subsetting of a terms object

2010-08-26 Thread peter dalgaard

On Aug 26, 2010, at 10:35 AM, Niels Richard Hansen wrote:

> 
> 
> On 26/08/10 09.30, Dimitris Rizopoulos wrote:
>> I think you need an I(), i.e.,
>> 
>> form <- ~ I(a > 1) - 1
> 
> Yes, it solves the concrete problem, but does not really answer
> the question. Let me rephrase. Should the use of terms like (a>1)
> be discouraged in R and replaced by I(a>1) systematically, or is the
> behavior below unexpected?

I'd say "yes", and "maybe". I think the only constructs that are guaranteed to 
protect arithmetic expressions are function calls, including I(). So it is more 
or less coincidental that ~ (a>1) - 1 works in the first place; when updating 
it, you probably should "expect the unexpected".  

There could still be a bug -- it looks somewhat wrong that a>1 isn't retained 
as a call to "<" with arguments a and 1, parentheses or not, but the model 
formula expansion code involves deep and dark magic, and I'd just avoid going 
too near it.


-- 
Peter Dalgaard
Center for Statistics, Copenhagen Business School
Solbjerg Plads 3, 2000 Frederiksberg, Denmark
Phone: (+45)38153501
Email: pd@cbs.dk  Priv: pda...@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] approxfun-problems (yleft and yright ignored)

2010-08-26 Thread Samuel Wuest
Hi Greg,
thanks for the suggestion:

I have attached some small dataset that can be used to reproduce the
odd behavior of the approxfun-function.

If it gets stripped off my email, it can also be downloaded at:
http://bioinf.gen.tcd.ie/approx.data.Rdata

Strangely, the problem seems specific to the data structure in my
expression set, when I use simulated data, everything worked fine.

Here is some code that I run and resulted in the strange output that I
have described in my initial post:

> ### load the data: a list called approx.data
> load(file="approx.data.Rdata")
> ### contains the slots "x", "y", "input"
> names(approx.data)
[1] "x" "y" "input"
> ### with y ranging between 0 and 1
> range(approx.data$y)
[1] 0 1
> ### compare ranges of x and input-x values (the latter is a small subset of 
> 500 data points):
> range(approx.data$x)
[1] 3.098444 7.268812
> range(approx.data$input)
[1]  3.329408 13.026700
>
>
> ### generate the interpolation function (warning message benign)
> interp <- approxfun(approx.data$x, approx.data$y, yleft=1, yright=0, rule=2)
Warning message:
In approxfun(approx.data$x, approx.data$y, yleft = 1, yright = 0,  :
  collapsing to unique 'x' values
>
> ### apply to input-values
> y.out <- sapply(approx.data$input, interp)
>
> ### still I find output values >1, even though yleft=1:
> range(y.out)
[1] 0.00 7.207233
> hist(y.out)
>
> ### and the input-data points for which strange interpolation does occur have 
> no unusual distribution (however, they lie close to max(x)):
> hist(approx.data$input[which(y.out>1)])

The session info can be found below, thanks a million for any help.

Sam

On 25 August 2010 19:31, Greg Snow  wrote:
> The plots did not come through, see the posting guide for which attachments 
> are allowed.  It will be easier for us to help if you can send reproducible 
> code (we can copy and paste to run, then examine, edit, etc.).  Try finding a 
> subset of your data for which the problem still occurs, then send the data if 
> possible, or similar simulated data if you cannot send original data.
>
> --
> Gregory (Greg) L. Snow Ph.D.
> Statistical Data Center
> Intermountain Healthcare
> greg.s...@imail.org
> 801.408.8111
>
>
>> -Original Message-
>> From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-
>> project.org] On Behalf Of Samuel Wuest
>> Sent: Wednesday, August 25, 2010 8:20 AM
>> To: r-help@r-project.org
>> Subject: [R] approxfun-problems (yleft and yright ignored)
>>
>> Dear all,
>>
>> I have run into a problem when running some code implemented in the
>> Bioconductor panp-package (applied to my own expression data), whereby
>> gene
>> expression values of known true negative probesets (x) are interpolated
>> onto
>> present/absent p-values (y) between 0 and 1 using the *approxfun -
>> function*{stats}; when I have used R version 2.8, everything had
>> worked fine,
>> however, after updating to R 2.11.1., I got unexpected output
>> (explained
>> below).
>>
>> Please correct me here, but as far as I understand, the yleft and
>> yright
>> arguments set the extreme values of the interpolated y-values in case
>> the
>> input x-values (on whose approxfun is applied) fall outside range(x).
>> So if
>> I run approxfun with yleft=1 and yright=0 with y-values between 0 and
>> 1,
>> then I should never get any values higher than 1. However, this is not
>> the
>> case, as this code-example illustrates:
>>
>> > ### define the x-values used to construct the approxfun, basically
>> these
>> are 2000 expression values ranging from ~ 3 to 7:
>> > xNeg <- NegExprs[, 1]
>> > xNeg <- sort(xNeg, decreasing = TRUE)
>> >
>> > ### generate 2000 y-values between 0 and 1:
>> > yNeg <- seq(0, 1, 1/(length(xNeg) - 1))
>> > ### define yleft and yright as well as the rule to clarify what
>> should
>> happen if input x-values lie outside range(x):
>> > interp <- approxfun(xNeg, yNeg, yleft = 1, yright = 0, rule=2)
>> Warning message:
>> In approxfun(xNeg, yNeg, yleft = 1, yright = 0, rule = 2) :
>>   collapsing to unique 'x' values
>> > ### apply the approxfun to expression data that range from ~2.9 to
>> 13.9
>> and can therefore lie outside range(xNeg):
>> >  PV <- sapply(AllExprs[, 1], interp)
>> > range(PV)
>> [1]    0.000 6208.932
>> > summary(PV)
>>      Min.   1st Qu.    Median      Mean   3rd Qu.      Max.
>> 0.000e+00 0.000e+00 2.774e-03 1.299e+00 3.164e-01 6.209e+03
>>
>> So the resulting output PV object contains data ranging from 0 to 6208,
>> the
>> latter of which lies outside yleft and is not anywhere close to extreme
>> y-values that were used to set up the interp-function. This seems wrong
>> to
>> me, and from what I understand, yleft and yright are simply ignored?
>>
>> I have attached a few histograms that visualize the data distributions
>> of
>> the objects I xNeg, yNeg, AllExprs[,1] (== input x-values) and PV (the
>> output), so that it is easier to make sense of the data structures...
>>
>> Does anyone have an explanation for this or

[R] Passing arguments between S4 methods fails within a function:bug? example with raster package.

2010-08-26 Thread Joris Meys
Dear all,

This problem came up initially while debugging a function, but it
seems to be a more general problem of R. I hope I'm wrong, but I can't
find another explanation. Let me illustrate with the raster package.

For an object "RasterLayer" (which inherits from Raster), there is a
method xyValues defined with the signature
(object="RasterLayer",xy="matrix"). There is also a method with
signature (object="Raster",xy="vector"). The only thing this method
does, is change xy into a matrix and then pass on to the next method
using callGeneric again. Arguments are passed.

Now this all works smoothly, as long as you stay in the global environment :
require(raster)

a <- raster()
a[] <- 1:ncell(a)

origin <- c(-80,50)
eff.dist <- 10

unlist(xyValues(a,xy=origin,buffer=eff.dist))
[1] 14140 14141 14500 14501

Now let's make a very basic test function :

test <- function(x,orig.point){
eff.distance <- 10
p <- unlist(xyValues(x,xy=orig.point,buffer=eff.distance))
return(p)
}

This gives the following result :
> test(a,origin)
Error in .local(object, xy, ...) : object 'eff.distance' not found

huh? Apparently, eff.distance got lost somewhere in the parsetree (am
I saying this correctly?)

The funny thing is when we change origin to a matrix :
> origin <- matrix(origin,ncol=2)

> unlist(xyValues(a,xy=origin,buffer=eff.dist))
[1] 14140 14141 14500 14501

> test(a,origin)
[1] 14140 14141 14500 14501

It all works again! So something goes wrong with passing the arguments
from one method to another using callGeneric. Is this a bug in R or am
I missing something obvious?

The relevant code from the raster package :

setMethod("xyValues", signature(object='Raster', xy='vector'),
function(object, xy, ...) {
if (length(xy) == 2) {
callGeneric(object, matrix(xy, ncol=2), ...)
} else {
stop('xy coordinates should be a two-column matrix or 
data.frame,
or a vector of two numbers.')
}
} )

setMethod("xyValues", signature(object='RasterLayer', xy='matrix'),
function(object, xy, method='simple', buffer=NULL, fun=NULL, 
na.rm=TRUE) {

if (dim(xy)[2] != 2) {
stop('xy has wrong dimensions; it should have 2 
columns' )
}

if (! is.null(buffer)) {
return( .xyvBuf(object, xy, buffer, fun, na.rm=na.rm) )
}

if (method=='bilinear') {
return(.bilinearValue(object, xy))
} else if (method=='simple') {
cells <- cellFromXY(object, xy)
return(.readCells(object, cells))
} else {
stop('invalid method argument. Should be simple or 
bilinear.')
}
}   
)   



-- 
Joris Meys
Statistical consultant

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

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

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


Re: [R] Quick GREP challenge

2010-08-26 Thread David Winsemius


On Aug 26, 2010, at 8:15 AM, Gabor Grothendieck wrote:


On Thu, Aug 26, 2010 at 6:16 AM, Dimitri Shvorob
 wrote:



grep("f[0-9]+=", "f1=5,f22=3,", value = T)

[1] "f1=5,f22=3,"

How do I make the line output c("f1", "f22") instead? (Actually,  
c(1,22)

would be even better).



strapply in gsubfn extracts matches based on content rather than
delimiters.  See home page for more info http://gsubfn.googlecode.com


library(gsubfn)
x <- "f1=5,f22=3,"
strapply(x, "f\\d+")[[1]]

[1] "f1"  "f22"


I read the request as for c(1,22) offered without quotes so t emeaning  
was obscure but perhaps this is what OP wanted:


as.numeric( strapply(x, "f(\\d+)=")[[1]] )
[1]  1 22
# or
> as.numeric(unlist(strapply(x, "f(\\d+)=")))
[1]  1 22





--
GKX Group
GKX Associates Inc.
1-877-GKX-GROUP
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.


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] Passing data to aov

2010-08-26 Thread Ivan Calandra
  Hi,

First, some toy data would have helped a lot, and that can explain why 
you got so few answers...

Second, I have maybe some thoughts about it, not sure if this can help.

The error tells you that the data passed to aov is not a matrix. In your 
function, you don't specify explicitly the data object to be used, that 
might be a problem. And that object has to be a matrix, it might not be.
Maybe something like:

form<- as.formula(paste("pcs", "~", paste(fac, collapse = "*")),
...
if (length(pcs) == 1) out<- aov(formula = form, data=score.matrix)

That would work if I understood what you're doing (hum...) and if both "pcs" 
and "fac" are parts of "score.matrix". But I've always done aov from a 
dataframe, which makes sense if you have both numerical variables and factors. 
How can you do it from a matrix? Maybe my understanding is limited.

As I said, just some thoughts...
HTH,
Ivan


Le 8/26/2010 14:47, Bryan Hanson a écrit :
> Hello Again Gurus and Lurkers:
>
> I¹m trying to build a very user-friendly function which does aov without
> having the user type in a formula (which would be tedious in this case).
> The idea is to take the response from a PCA score matrix, and the factors
> from a list.  A simple example is the function given below, along with test
> data and a sample call to the function.
>
> I'm certainly having trouble understanding the proper ways to work with
> formulas and related items, but I think what I do in the function should
> work (it's built on ideas dug out of the archives).  However, when the data
> is passed to aov (directly or via manova), something in the bowels of aov
> complains with the following error:
>
> Error in model.frame.default(formula = form, drop.unused.levels = TRUE) :
>object is not a matrix
>
> To me, the formula looks legitimate, and the variables in the formula are
> all in the environment (I think: The way I am doing this is basically that
> described in ?summary.manova where only a formula is passed, no data
> argument).  Based upon reading the archives, the problem might arise with
> one of the deparse statements in aov, but I can't resolve it.  It might also
> be one of scoping/environment, but again, this is only an idea.
>
> TIA for any assistance.  Bryan
> *
> Bryan Hanson
> Professor of Chemistry&  Biochemistry
> DePauw University, Greencastle IN USA
>
>
> hypTestScores<-
>  function(mylist, score.matrix, pcs = 1:3, fac = NULL, ...) {
>
>  scores<- score.matrix[,pcs]
> #str(scores)# looks correct to me
>  form<- as.formula(paste("scores", "~", paste(fac, collapse = "*")),
>  env = parent.frame())
> #str(form)   # looks correct to me
>  attach(mylist)
>  if (length(pcs)>  1) out<- manova(formula = form, ...)
>  if (length(pcs) == 1) out<- aov(formula = form, ...)
>  print(summary(out))
>  detach(mylist)
>  invisible(out)
>  }
>
> # test data
> td1<- matrix(rnorm(50), ncol = 5) # like PCA scores
> td2<- list(
>  f1 = as.factor(sample(c("A", "B"), 10, replace = TRUE)),
>  f2 = as.factor(sample(c("C", "D"), 10, replace = TRUE)))
>
> # test call
> hypTestScores(mylist = td2, score.matrix = td1,
>  fac = c("f1", "f2"))
> detach("mylist") # needed if there is an error
>
>> sessionInfo()
> R version 2.11.0 (2010-04-22)
> x86_64-apple-darwin9.8.0
>
> locale:
> [1] en_US.UTF-8/en_US.UTF-8/C/C/en_US.UTF-8/en_US.UTF-8
>
> attached base packages:
> [1] datasets  tools grid  graphics  grDevices utils stats
> [8] methods   base
>
> other attached packages:
>   [1] faraway_1.0.4  GGally_0.2 xtable_1.5-6
>   [4] mvbutils_2.5.1 ggplot2_0.8.8  proto_0.3-8
>   [7] reshape_0.8.3  ChemoSpec_1.45 R.utils_1.4.0
> [10] R.oo_1.7.2 R.methodsS3_1.2.0  rgl_0.91
> [13] lattice_0.18-5 mvoutlier_1.4  plyr_1.0.3
> [16] RColorBrewer_1.0-2 chemometrics_0.8   som_0.3-5
> [19] robustbase_0.5-0-1 rpart_3.1-46   pls_2.1-0
> [22] pcaPP_1.8-1mvtnorm_0.9-9  nnet_7.3-1
> [25] mclust_3.4.4   MASS_7.3-5 lars_0.9-7
> [28] e1071_1.5-23   class_7.3-2
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

-- 
Ivan CALANDRA
PhD Student
University of Hamburg
Biozentrum Grindel und Zoologisches Museum
Abt. Säugetiere
Martin-Luther-King-Platz 3
D-20146 Hamburg, GERMANY
+49(0)40 42838 6231
ivan.calan...@uni-hamburg.de

**
http://www.for771.uni-bonn.de
http://webapp5.rrz.uni-hamburg.de/mammals/eng/mitarbeiter.php


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

Re: [R] equalize function with zero and convert it

2010-08-26 Thread Gabor Grothendieck
On Thu, Aug 26, 2010 at 9:45 AM, Immanuel Seeger  wrote:
> Thanks, but my problem is that I have my formulas in functions.
> How can I do that for functions or e.g. for the body(Df) below?

Try this:

> library(Ryacas)
> Solve(deparse(body(f)), "x")
[1] "Starting Yacas!"
expression(list(x == -((10 - (100 - y) + root((100 - y - 10)^2,
2))/2), x == -((10 - (100 - y) - root((100 - y - 10)^2, 2))/2)))
>
> out <- yacas(Solve(deparse(body(f)), "x"))
> out$text[[1]][[2]]
x == -((10 - (100 - y) + root((100 - y - 10)^2, 2))/2)


> And: How can I refer to the first solution of expression?
> Thanks a lot!
>
> -Ursprüngliche Nachricht-
> Von: Gabor Grothendieck [mailto:ggrothendi...@gmail.com]
> Gesendet: Donnerstag, 26. August 2010 14:56
> An: Immanuel Seeger
> Cc: r-help@r-project.org
> Betreff: Re: [R] equalize function with zero and convert it
>
> On Thu, Aug 26, 2010 at 6:57 AM, Immanuel Seeger 
> wrote:
>> Dear all,
>> I want to equalize a symbolic derivative (of a function with two
>> variables) with zero and convert it to a variable, e.g. x.
>>
>> I'm computing the derivative by: (found it in the archive)
>> library(Ryacas)
>> f <- function(x,y) (100-x-y)*x-10*x
>> yacas(f) # register f with yacas
>> Df <- f
>> body(Df) <- yacas(expression(deriv(f(x,y),x)))[[1]]
>> Df
>>
>> R-Output:
>> function (x, y)
>> 100 - x - y - x - 10
>>
>> Questions :
>> 1.      How can I equalize the derivative(140-x-y-x-20) with zero?
>> 2.      How can I convert it to x?
>>
>> I want something like:
>> 45-0.5*y=x
>>
>> With only one variable or two non-symbolic variables it's working with
>> uniroot(f, c(-10, 10))$root.
>>
>
> This solves for x:
>
>> library(Ryacas)
> Loading required package: XML
>> x <- Sym("x")
>> y <- Sym("y")
>> Solve((100-x-y)*x-10*x == 0, "x")
> [1] "Starting Yacas!"
> expression(list(x == -((10 - (100 - y) + root((100 - y - 10)^2,
>    2))/2), x == -((10 - (100 - y) - root((100 - y - 10)^2, 2))/2)))
>
> --
> GKX Group
> GKX Associates Inc.
> 1-877-GKX-GROUP
> ggrothendieck at gmail.com
>
>



-- 
GKX Group, GKX Associates Inc.
Statistics & Software Consulting
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] Passing data to aov

2010-08-26 Thread David Winsemius


On Aug 26, 2010, at 8:47 AM, Bryan Hanson wrote:


Hello Again Gurus and Lurkers:

I’m trying to build a very user-friendly function which does aov  
without
having the user type in a formula (which would be tedious in this  
case).
The idea is to take the response from a PCA score matrix, and the  
factors
from a list.  A simple example is the function given below, along  
with test

data and a sample call to the function.

I'm certainly having trouble understanding the proper ways to work  
with
formulas and related items, but I think what I do in the function  
should
work (it's built on ideas dug out of the archives).  However, when  
the data
is passed to aov (directly or via manova), something in the bowels  
of aov

complains with the following error:

Error in model.frame.default(formula = form, drop.unused.levels =  
TRUE) :

 object is not a matrix


Actually I got a different error (also on a Mac. but with a version  
that is two month later than yours and with quite a smaller number of  
packages loaded):

> hypTestScores(mylist = td2, score.matrix = td1,
+fac = c("f1", "f2"))
Error in eval(expr, envir, enclos) : object 'scores' not found

Which went away if I removed the "env=" argument. My guess is that you  
were telling manova to look further up the lexical tree than it should  
have (or that attach() operation messed up the environment somehow):


> hypTestScores(mylist = td2, score.matrix = td1,
+fac = c("f1", "f2"))
  Df  Pillai approx F num Df den Df Pr(>F)
f1 1 0.31663  0.61777  3  4 0.6392
f2 1 0.36652  0.77145  3  4 0.5673
f1:f2  1 0.15687  0.24808  3  4 0.8593
Residuals  6

> detach("mylist") # needed if there is an error
Error in detach("mylist") : invalid 'name' argument

You might want to do inside the function something like

res =try(  your function )
if (res="try-error") {stop() } else{
}



To me, the formula looks legitimate, and the variables in the  
formula are
all in the environment (I think: The way I am doing this is  
basically that

described in ?summary.manova where only a formula is passed, no data
argument).  Based upon reading the archives, the problem might arise  
with
one of the deparse statements in aov, but I can't resolve it.  It  
might also

be one of scoping/environment, but again, this is only an idea.

TIA for any assistance.  Bryan
*
Bryan Hanson
Professor of Chemistry & Biochemistry
DePauw University, Greencastle IN USA


hypTestScores <-
   function(mylist, score.matrix, pcs = 1:3, fac = NULL, ...) {

   scores <- score.matrix[,pcs]
#str(scores)# looks correct to me
   form <- as.formula(paste("scores", "~", paste(fac, collapse =  
"*")),

   env = parent.frame())
#str(form)   # looks correct to me
   attach(mylist)
   if (length(pcs) > 1) out <- manova(formula = form, ...)
   if (length(pcs) == 1) out <- aov(formula = form, ...)
   print(summary(out))
   detach(mylist)
   invisible(out)
   }

# test data
td1 <- matrix(rnorm(50), ncol = 5) # like PCA scores
td2 <- list(
   f1 = as.factor(sample(c("A", "B"), 10, replace = TRUE)),
   f2 = as.factor(sample(c("C", "D"), 10, replace = TRUE)))

# test call
hypTestScores(mylist = td2, score.matrix = td1,
   fac = c("f1", "f2"))
detach("mylist") # needed if there is an error


sessionInfo()

R version 2.11.0 (2010-04-22)
x86_64-apple-darwin9.8.0

locale:
[1] en_US.UTF-8/en_US.UTF-8/C/C/en_US.UTF-8/en_US.UTF-8

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

other attached packages:
[1] faraway_1.0.4  GGally_0.2 xtable_1.5-6
[4] mvbutils_2.5.1 ggplot2_0.8.8  proto_0.3-8
[7] reshape_0.8.3  ChemoSpec_1.45 R.utils_1.4.0
[10] R.oo_1.7.2 R.methodsS3_1.2.0  rgl_0.91
[13] lattice_0.18-5 mvoutlier_1.4  plyr_1.0.3
[16] RColorBrewer_1.0-2 chemometrics_0.8   som_0.3-5
[19] robustbase_0.5-0-1 rpart_3.1-46   pls_2.1-0
[22] pcaPP_1.8-1mvtnorm_0.9-9  nnet_7.3-1
[25] mclust_3.4.4   MASS_7.3-5 lars_0.9-7
[28] e1071_1.5-23   class_7.3-2

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] daisy(): space allocation issue

2010-08-26 Thread abanero

Hi,

I'm trying to apply the function daisy() to a data.frame 1x10 but I have
not enough space (error message: cannot allocate vector of length
1476173280).

I didn't imagine I was not able to work with a matrix of just 1
observations... I have setted in Rgui --max-mem-size=2G (I'm not able to set
more space..)

How can I solve this issue? Separating observations depending on some rules?

thanks
-- 
View this message in context: 
http://r.789695.n4.nabble.com/daisy-space-allocation-issue-tp2339844p2339844.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] About plot graphs

2010-08-26 Thread Stephen Liu
Hi folks,

Following command prints 2 graphs side-by-side:-
layout(matrix(1:2, nrow=1))
plot(Date,Input_No.)
plot(Test01$Date, Test01$Input_No.)

However each is a square graph I need a rectangular layout.  Pls advise how to 
make it.  TIA

B.R.
satimis




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

2010-08-26 Thread David Winsemius


On Aug 26, 2010, at 10:44 AM, Stephen Liu wrote:


Hi folks,

Following command prints 2 graphs side-by-side:-
layout(matrix(1:2, nrow=1))


?layout
#Read the details for the widths and heights arguments more carefully  
and (as it suggests)  see the examples.



plot(Date,Input_No.)
plot(Test01$Date, Test01$Input_No.)

However each is a square graph I need a rectangular layout.  Pls  
advise how to

make it.  TIA


--

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] SEM : Warning : Could not compute QR decomposition of Hessian

2010-08-26 Thread John Fox
Dear Anne,

> -Original Message-
> From: Anne Mimet [mailto:ami...@mnhn.fr]
> Sent: August-26-10 7:45 AM
> To: John Fox
> Cc: r-help@r-project.org
> Subject: RE: [R] SEM : Warning : Could not compute QR decomposition of
> Hessian
> 
> Dear John,
> 
> Thank a lot for your answer. Indeed, i misunderstood the place of
> indicator variables in the path diagram, i thank they were considered
> as exogeneous variables. Thanks for your answer, i changed variances
> of latente variables to NA, and remove indicator variables from
> fixed.x argument. Unfortunately, it doesn't change the warning message.
> I place the path diagram of the model here : http://yfrog.com/n7pathdiagj
> 
> Because of the diagram complexity, i used some colors for the
> different paths :
> - green for environnental variable
> - brown for landscape variables
> - orange for municipalities variables
> - blue for inter-municipalitie variables
> - red for departemental variable
> - grey for landuse variables
> - and in dark the relations between indicator and latente variables,
> errors, variances and covariances.
> 
> There must be other mistakes in the model, i can't find them.

You haven't sent me your updated R code, so I'm just going by the path
diagram, but, yes, I think that there are more problems. I assume that the
circles represent error variables, which in the RAM formulation used by
sem() would appear as self-directed double-headed arrows. If that's the
case, why do observed exogenous variables like dist.protect have an error
component? As well, if the absence of double-headed arrows between pairs of
exogenous variables implies that they are uncorrelated, then your model has
many such constraints. Did you really intend that? I'm also not convinced
that the model is identified -- there are, I believe, just 6 exogenous
variables -- but the (possibly inadvertent) constraints placed on error
correlations may indentify it. Just to be clear, there is no guarantee that
sem() will be able to estimate your model even if it is specified as you
intend and even if it is identified.

At this point, I'd make two suggestions: First, if you want to continue to
try to use the sem package, and if you haven't already done so, I'd suggest
that you read my 2006 article "Structural equation modeling with the sem
package in R", Structural Equation Modeling, 13:465–486, which is referenced
in ?sem. Second, there are apparently sufficient problems here that you
would do well to find someone to talk to about the formulation of your
model.

Regards,
 John

> 
> Thanks again,
> 
> Regards,
> 
> Anne
> 
> 
> 
> John Fox  a écrit :
> 
> > Dear Anne,
> >
> > I started to diagram your model but stopped when I noticed some
problems:
> > (1) Some variables, such as pays_alti, are clearly endogenous, since
they
> > have arrows pointing to them, yet are declared as fixed exogenous
> variables;
> > that clearly doesn't make sense. (2) You've placed conflicting
constraints
> > on factor loadings and the variances of latent variables, for example
> > setting both the path from the factor type_paysage to the indicator
> > pays_alti and the variance of type_paysage to 1; again, that doesn't
make
> > sense.
> >
> > Do you have a path diagram for the model that you're trying to fit? It
> would
> > in particular be helpful to have a diagram of the structural part of the
> > model.
> >
> > Regards,
> >  John
> >
> > 
> > John Fox
> > Senator William McMaster
> >   Professor of Social Statistics
> > Department of Sociology
> > McMaster University
> > Hamilton, Ontario, Canada
> > web: socserv.mcmaster.ca/jfox
> >
> >
> >> -Original Message-
> >> From: r-help-boun...@r-project.org
[mailto:r-help-boun...@r-project.org]
> > On
> >> Behalf Of Anne Mimet
> >> Sent: August-25-10 10:27 AM
> >> To: r-help@r-project.org
> >> Subject: [R] SEM : Warning : Could not compute QR decomposition of
Hessian
> >>
> >> Hi useRs,
> >>
> >> I'm trying for the first time to use a sem. The model finally runs,
> >> but gives a warning saying :
> >> "In sem.default(ram = ram, S = S, N = N, param.names = pars, var.names
> >> = vars,  :   Could not compute QR decomposition of Hessian.
> >> Optimization probably did not converge. "
> >>
> >> I found in R-help some posts on this warning, but my attemps to modify
> >> the code didn't change the warning message (i tried to give an error
> >> of 1 to the latente variables). I can't figure what the problem is.
> >> Here is the code :
> >>
> >>
> >> tab<-read.table("F:/Mes documents/stats/sem/donnees_corr.txt",
> >> header=T, sep="",na.strings = "NA")
> >>
> >> tab[,46]<-as.factor(tab[,46])
> >> tab[,24]<-as.factor(tab[,24])
> >> tab[,40]<-as.factor(tab[,40])
> >>
> >> fct_cor<-hetcor(tab, ML=T)
> >> cor_tab<- fct_cor$correlations
> >>
> >> moment_tab<-read.moments(diag=F, names=c('c1','c2', 'c3','c4','c5',
> >> 'c6','c7', 'c8', 'c9',  'ind_plando', 'long_sup15', 'long_inf15',
> >> 'pente', 'est', 'sud','ouest', 

Re: [R] Passing data to aov

2010-08-26 Thread Ivan Calandra
  Hi!

I didn't see the toy data, my bad.

I guess David's solution fixed the problem.

Ivan

Le 8/26/2010 16:10, Bryan Hanson a écrit :
> Hi Ivan, there is toy data given in the original post.
>
> The object passed to aov is a matrix, it is called scores, and it is passed
> via the formula that is created in the sense that the formula specifies
> objects in the calling environment.  At least that is what is supposed to
> happen.
>
> I've not been able to find an example of manova using a data frame - aov,
> yes.  I think that is because the response vector in manova must be a
> matrix, and you can't put a matrix in a data frame as a separate object.
> You could put the columns of the matrix into the data frame, but then it is
> not seen as a single entity, it's seen as separate columns, and specifying
> this in the formula looks impossible as I understand it.
>
> But, obviously there is something I don't understand!  Thanks, Bryan
>
>
> On 8/26/10 9:50 AM, "Ivan Calandra"  wrote:
>
>>Hi,
>>
>> First, some toy data would have helped a lot, and that can explain why
>> you got so few answers...
>>
>> Second, I have maybe some thoughts about it, not sure if this can help.
>>
>> The error tells you that the data passed to aov is not a matrix. In your
>> function, you don't specify explicitly the data object to be used, that
>> might be a problem. And that object has to be a matrix, it might not be.
>> Maybe something like:
>>
>> form<- as.formula(paste("pcs", "~", paste(fac, collapse = "*")),
>> ...
>> if (length(pcs) == 1) out<- aov(formula = form, data=score.matrix)
>>
>> That would work if I uderstood what you're doing (hum...) and if both "pcs"
>> and "fac" are parts of "score.matrix". But I've always done aov from a
>> dataframe, which makes sense if you have both numerical variables and 
>> factors.
>> How can you do it from a matrix? Maybe my understanding is limited.
>>
>> As I said, just some thoughts...
>> HTH,
>> Ivan
>>
>>
>> Le 8/26/2010 14:47, Bryan Hanson a écrit :
>>> Hello Again Gurus and Lurkers:
>>>
>>> I¹m trying to build a very user-friendly function which does aov without
>>> having the user type in a formula (which would be tedious in this case).
>>> The idea is to take the response from a PCA score matrix, and the factors
>>> from a list.  A simple example is the function given below, along with test
>>> data and a sample call to the function.
>>>
>>> I'm certainly having trouble understanding the proper ways to work with
>>> formulas and related items, but I think what I do in the function should
>>> work (it's built on ideas dug out of the archives).  However, when the data
>>> is passed to aov (directly or via manova), something in the bowels of aov
>>> complains with the following error:
>>>
>>> Error in model.frame.default(formula = form, drop.unused.levels = TRUE) :
>>> object is not a matrix
>>>
>>> To me, the formula looks legitimate, and the variables in the formula are
>>> all in the environment (I think: The way I am doing this is basically that
>>> described in ?summary.manova where only a formula is passed, no data
>>> argument).  Based upon reading the archives, the problem might arise with
>>> one of the deparse statements in aov, but I can't resolve it.  It might also
>>> be one of scoping/environment, but again, this is only an idea.
>>>
>>> TIA for any assistance.  Bryan
>>> *
>>> Bryan Hanson
>>> Professor of Chemistry&   Biochemistry
>>> DePauw University, Greencastle IN USA
>>>
>>>
>>> hypTestScores<-
>>>   function(mylist, score.matrix, pcs = 1:3, fac = NULL, ...) {
>>>
>>>   scores<- score.matrix[,pcs]
>>> #str(scores)# looks correct to me
>>>   form<- as.formula(paste("scores", "~", paste(fac, collapse = "*")),
>>>   env = parent.frame())
>>> #str(form)   # looks correct to me
>>>   attach(mylist)
>>>   if (length(pcs)>   1) out<- manova(formula = form, ...)
>>>   if (length(pcs) == 1) out<- aov(formula = form, ...)
>>>   print(summary(out))
>>>   detach(mylist)
>>>   invisible(out)
>>>   }
>>>
>>> # test data
>>> td1<- matrix(rnorm(50), ncol = 5) # like PCA scores
>>> td2<- list(
>>>   f1 = as.factor(sample(c("A", "B"), 10, replace = TRUE)),
>>>   f2 = as.factor(sample(c("C", "D"), 10, replace = TRUE)))
>>>
>>> # test call
>>> hypTestScores(mylist = td2, score.matrix = td1,
>>>   fac = c("f1", "f2"))
>>> detach("mylist") # needed if there is an error
>>>
 sessionInfo()
>>> R version 2.11.0 (2010-04-22)
>>> x86_64-apple-darwin9.8.0
>>>
>>> locale:
>>> [1] en_US.UTF-8/en_US.UTF-8/C/C/en_US.UTF-8/en_US.UTF-8
>>>
>>> attached base packages:
>>> [1] datasets  tools grid  graphics  grDevices utils stats
>>> [8] methods   base
>>>
>>> other attached packages:
>>>[1] faraway_1.0.4  GGally_0.2 xtable_1.5-6
>>>[4] mvbutils_2.5.1 ggplot2_0.8.8  proto_0.3-8
>>>[7] reshape_0.8.3  ChemoSpec_1.45 R.utils_1.4.0
>>> [10] R.oo_1.7

Re: [R] Random slopes in lmer

2010-08-26 Thread Darin A. England
coef(mod1)$bird will give you a matrix with two columns. The first
column is the intercept for each bird and the second column is the
slope for each bird.

ranef(mod1) will also give you a matrix of two columns. These
represent the random effects. That is, how much the intercept (or
slope) is shifted from overall mean.

HTH,
Darin

On Thu, Aug 26, 2010 at 01:15:10PM +0100, Samantha Patrick wrote:
> Hi
> 
> I want to extract the random slopes from a lmer (I am doing a random 
> regression), but are the answers obtained from ranef or coef?
> 
> My model is: mod1<-lmer(B~ A +(A|bird), family=quasibinomial)
> 
> And I want to obtain a slope for each individual bird but am not sure which 
> output I need and can't find the answer anywhere.
> 
> Thanks
> 
> Sam
> 
> 
> Dr Samantha Patrick
> EU INTERREG Post Doc
> Davy 618
> Marine Biology & Ecology Research Centre
> University of Plymouth
> Plymouth
> PL4 8AA
> 
> T: 01752 586165
> M: 07740472719
> 
> 
>   [[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] Passing data to aov

2010-08-26 Thread Bryan Hanson
A big thanks David!  Eliminating the env = parent.frame() seems to fix
everything.  I hate it when I'm that close... I included that because from
?as.formula it seemed to be the default, but on re-read, I guess it doesn't
really say that.  In addition, I had included it even though it was the
default as I felt at some point I would have to change it so I wanted it
there as a reminder.  Instead, it led me astray...

Thanks so much! Bryan (coming to you from the R-Inferno today)


On 8/26/10 10:14 AM, "David Winsemius"  wrote:

> 
> On Aug 26, 2010, at 8:47 AM, Bryan Hanson wrote:
> 
>> Hello Again Gurus and Lurkers:
>> 
>> I¹m trying to build a very user-friendly function which does aov
>> without
>> having the user type in a formula (which would be tedious in this
>> case).
>> The idea is to take the response from a PCA score matrix, and the
>> factors
>> from a list.  A simple example is the function given below, along
>> with test
>> data and a sample call to the function.
>> 
>> I'm certainly having trouble understanding the proper ways to work
>> with
>> formulas and related items, but I think what I do in the function
>> should
>> work (it's built on ideas dug out of the archives).  However, when
>> the data
>> is passed to aov (directly or via manova), something in the bowels
>> of aov
>> complains with the following error:
>> 
>> Error in model.frame.default(formula = form, drop.unused.levels =
>> TRUE) :
>>  object is not a matrix
> 
> Actually I got a different error (also on a Mac. but with a version
> that is two month later than yours and with quite a smaller number of
> packages loaded):
>> hypTestScores(mylist = td2, score.matrix = td1,
> +fac = c("f1", "f2"))
> Error in eval(expr, envir, enclos) : object 'scores' not found
> 
> Which went away if I removed the "env=" argument. My guess is that you
> were telling manova to look further up the lexical tree than it should
> have (or that attach() operation messed up the environment somehow):
> 
>> hypTestScores(mylist = td2, score.matrix = td1,
> +fac = c("f1", "f2"))
>Df  Pillai approx F num Df den Df Pr(>F)
> f1 1 0.31663  0.61777  3  4 0.6392
> f2 1 0.36652  0.77145  3  4 0.5673
> f1:f2  1 0.15687  0.24808  3  4 0.8593
> Residuals  6
> 
>> detach("mylist") # needed if there is an error
> Error in detach("mylist") : invalid 'name' argument
> 
> You might want to do inside the function something like
> 
> res =try(  your function )
> if (res="try-error") {stop() } else{
>  }
> 
>> 
>> To me, the formula looks legitimate, and the variables in the
>> formula are
>> all in the environment (I think: The way I am doing this is
>> basically that
>> described in ?summary.manova where only a formula is passed, no data
>> argument).  Based upon reading the archives, the problem might arise
>> with
>> one of the deparse statements in aov, but I can't resolve it.  It
>> might also
>> be one of scoping/environment, but again, this is only an idea.
>> 
>> TIA for any assistance.  Bryan
>> *
>> Bryan Hanson
>> Professor of Chemistry & Biochemistry
>> DePauw University, Greencastle IN USA
>> 
>> 
>> hypTestScores <-
>>function(mylist, score.matrix, pcs = 1:3, fac = NULL, ...) {
>> 
>>scores <- score.matrix[,pcs]
>> #str(scores)# looks correct to me
>>form <- as.formula(paste("scores", "~", paste(fac, collapse =
>> "*")),
>>env = parent.frame())
>> #str(form)   # looks correct to me
>>attach(mylist)
>>if (length(pcs) > 1) out <- manova(formula = form, ...)
>>if (length(pcs) == 1) out <- aov(formula = form, ...)
>>print(summary(out))
>>detach(mylist)
>>invisible(out)
>>}
>> 
>> # test data
>> td1 <- matrix(rnorm(50), ncol = 5) # like PCA scores
>> td2 <- list(
>>f1 = as.factor(sample(c("A", "B"), 10, replace = TRUE)),
>>f2 = as.factor(sample(c("C", "D"), 10, replace = TRUE)))
>> 
>> # test call
>> hypTestScores(mylist = td2, score.matrix = td1,
>>fac = c("f1", "f2"))
>> detach("mylist") # needed if there is an error
>> 
>>> sessionInfo()
>> R version 2.11.0 (2010-04-22)
>> x86_64-apple-darwin9.8.0
>> 
>> locale:
>> [1] en_US.UTF-8/en_US.UTF-8/C/C/en_US.UTF-8/en_US.UTF-8
>> 
>> attached base packages:
>> [1] datasets  tools grid  graphics  grDevices utils stats
>> [8] methods   base
>> 
>> other attached packages:
>> [1] faraway_1.0.4  GGally_0.2 xtable_1.5-6
>> [4] mvbutils_2.5.1 ggplot2_0.8.8  proto_0.3-8
>> [7] reshape_0.8.3  ChemoSpec_1.45 R.utils_1.4.0
>> [10] R.oo_1.7.2 R.methodsS3_1.2.0  rgl_0.91
>> [13] lattice_0.18-5 mvoutlier_1.4  plyr_1.0.3
>> [16] RColorBrewer_1.0-2 chemometrics_0.8   som_0.3-5
>> [19] robustbase_0.5-0-1 rpart_3.1-46   pls_2.1-0
>> [22] pcaPP_1.8-1mvtnorm_0.9-9  nnet_7.3-1
>> [25] mclust_3.4.4   MASS_7.3-5 lars_0.9-7
>> [28] e1071_1.5-23   class_7.3-2
>> 
>> ___

[R] reliability of R-Forge?

2010-08-26 Thread R P Herrold

On Thu, 26 Aug 2010, Gavin Simpson wrote:


On Thu, 2010-08-26 at 02:30 -0400, David Kane wrote:

How reliable is R-Forge? http://r-forge.r-project.org/

It is down now (for me). Reporting "R-Forge Could Not Connect to Database: "


late to chime in, so had tossed the first piece.  As this 
relates to 'reliability of R-Forge' in the sense of possible 
process issues, rather than availability of the archive, I 
wanted to 'tag into' this thread


I 'mirror' r-forge, so I have not seen this ...

One thing I note, mirroring r-forge, and processing 'diffs' 
netween successive days, is that the md5sums of some packages 
regularly change without version number bumps.  From this 
morning's report in my email:


Thu Aug 26 04:30:01 EDT 2010

--- /tmp/rforge-pre.txt 2010-08-26 04:30:33.0 -0400
+++ /tmp/rforge-post.txt2010-08-26 04:38:03.0 
-0400

@@ -8,18 +8,18 @@
 AquaEnv_1.0-1.tar.gz   615059a5369d1aba149e6142fedffdde
 ArvoRe_0.1.6.tar.gzc955ae7c64c4270740172ad2219060ff
 BB_2010.7-1.tar.gz 4f85093ab24fac5c0b91539ec6efb8b7
-BCE_2.0.tar.gz 5a3fe3ecabbe2b2e278f6a48fc19d18d
-BIOMOD_1.1-5.tar.gzd2f74f21bc8858844f8d71627fd8e687
+BCE_2.0.tar.gz 65a968c586e729a1c1ca34a37f5c293a
+BIOMOD_1.1-5.tar.gz6929e5ad6a14709de7065286ec684942
 ...
-BTSPAS_2010.08.tar.gz  16b8f265846a512c329f0b52ba1924ab
+BTSPAS_2010.08.tar.gz  809a96b11f1094e95b217af113abd0ac
 ...
-BayesR_0.1-1.tar.gz72bd41c90845032eb9d15c4c6d086dec
+BayesFactorPCL_0.5.tar.gz  173ab741c399309314eff240a4c3cd6f
+BayesR_0.1-1.tar.gz9560b511f1b955a60529599672d58fea
 ...
-BiplotGUI_0.0-6.tar.gz 594b3a275cde018eaa74e1ef974dd522
+BiplotGUI_0.0-6.tar.gz 857a484fdba6cb97be4e42e38bb6d0fd
 ...
-IsoGene_1.0-18.tar.gz  679a5aecb7182474ed6a870fa52ca2e3
+IsoGene_1.0-18.tar.gz  f37572957b2a9846a8d738ec88ac8690

and so forth.  I've not taken the trime to understand why 
seemingly new versions are appearing without version bumps 
yet.


Is anyone aware of explanations, other than a release process 
that does not require unique versioning of differing content? 
[it seems pretty basic to me that a 'receiver' of new content 
could do the checks I do, and decline to push conflicting 
md5sums over an identically named prior candidate in archive]


-- Russ herrold

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Find classes for each column of a data.frame

2010-08-26 Thread Daniel Brewer
Hello,

Is there a simple way to get the class type for each column of a
data.frame?  I am in the situation where I would like to get all the
columns of a data.frame that are factors.

I have tried:
apply(df,2,class)
but all the columns come back as class "character".

Thanks

Dan

-- 
**
Daniel Brewer, Ph.D.

Institute of Cancer Research
Molecular Carcinogenesis
Email: daniel.bre...@icr.ac.uk
**

The Institute of Cancer Research: Royal Cancer Hospital, a charitable Company 
Limited by Guarantee, Registered in England under Company No. 534147 with its 
Registered Office at 123 Old Brompton Road, London SW7 3RP.

This e-mail message is confidential and for use by the a...{{dropped:2}}

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Find classes for each column of a data.frame

2010-08-26 Thread David Winsemius


On Aug 26, 2010, at 11:31 AM, Daniel Brewer wrote:


Hello,

Is there a simple way to get the class type for each column of a
data.frame?  I am in the situation where I would like to get all the
columns of a data.frame that are factors.

I have tried:
apply(df,2,class)


lapply(df, class)


but all the columns come back as class "character".


Agree that is not what I would have expected.

--
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] Find classes for each column of a data.frame

2010-08-26 Thread Erik Iverson

That's because apply works on arrays/matrices, not data.frames.

It therefore coerces your data.frame to a matrix of type
character, since you have factors, thus the result.

You want sapply or lapply, since a data.frame is actually a
list.

sapply(df, class)

and then to get what you want:

df[sapply(df, is.factor)]

Daniel Brewer wrote:

Hello,

Is there a simple way to get the class type for each column of a
data.frame?  I am in the situation where I would like to get all the
columns of a data.frame that are factors.

I have tried:
apply(df,2,class)
but all the columns come back as class "character".

Thanks

Dan



__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Find classes for each column of a data.frame

2010-08-26 Thread David Winsemius


On Aug 26, 2010, at 11:31 AM, Daniel Brewer wrote:


Hello,

Is there a simple way to get the class type for each column of a
data.frame?  I am in the situation where I would like to get all the
columns of a data.frame that are factors.

I have tried:
apply(df,2,class)
but all the columns come back as class "character".


Just realized it happens because of matrix coercion.

--

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] Find classes for each column of a data.frame

2010-08-26 Thread Ivan Calandra
  Since a data.frame is a list, you should use lapply() or sapply():

 > df <- data.frame(a=1:5, b=LETTERS[1:5])
 > lapply(df, class)
$a
[1] "integer"
$b
[1] "factor"
 > sapply(df, class)
 a b
"integer"  "factor"

HTH,
Ivan

Le 8/26/2010 17:31, Daniel Brewer a écrit :
> Hello,
>
> Is there a simple way to get the class type for each column of a
> data.frame?  I am in the situation where I would like to get all the
> columns of a data.frame that are factors.
>
> I have tried:
> apply(df,2,class)
> but all the columns come back as class "character".
>
> Thanks
>
> Dan
>

-- 
Ivan CALANDRA
PhD Student
University of Hamburg
Biozentrum Grindel und Zoologisches Museum
Abt. Säugetiere
Martin-Luther-King-Platz 3
D-20146 Hamburg, GERMANY
+49(0)40 42838 6231




[[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] print method for str?

2010-08-26 Thread Gavin Simpson
On Thu, 2010-08-26 at 10:42 +0200, David Hajage wrote:
> Hello useRs and guRus,
> 
> I was trying to add the support of str() in the ascii package, and I
> realized that str() does not have a print method. It uses cat() from inside
> the function and returns nothing.
> 
> Since it is not usual in R, I wonder why? Is there a particular reason?

The Value section of ?str has a (the?) reason. Efficiency.

str is an S3 generic though, so you can write your own methods for it.

HTH

G

> Thank you very much for your attention on... well, this unimportant
> question.
> 
> david
> 
>   [[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.

-- 
%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%
 Dr. Gavin Simpson [t] +44 (0)20 7679 0522
 ECRC, UCL Geography,  [f] +44 (0)20 7679 0565
 Pearson Building, [e] gavin.simpsonATNOSPAMucl.ac.uk
 Gower Street, London  [w] http://www.ucl.ac.uk/~ucfagls/
 UK. WC1E 6BT. [w] http://www.freshwaters.org.uk
%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Find classes for each column of a data.frame

2010-08-26 Thread Barry Rowlingson
On Thu, Aug 26, 2010 at 4:31 PM, Daniel Brewer  wrote:
> Hello,
>
> Is there a simple way to get the class type for each column of a
> data.frame?  I am in the situation where I would like to get all the
> columns of a data.frame that are factors.
>
> I have tried:
> apply(df,2,class)
> but all the columns come back as class "character".

 apply is treating it as a matrix, and so converts it to the lowest common form.

 try lapply and use is.factor, with some unlist for good measure:

 z=data.frame(x=1:10,l=factor(1:10))
 unlist(lapply(z,is.factor))

   x l
FALSE  TRUE


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] Passing arguments between S4 methods fails within a function:bug? example with raster package.

2010-08-26 Thread Niels Richard Hansen

Joris,

I looked at the problem. Here is a minimal example reproducing
the error

setGeneric("myplus",function(x,y,...) standardGeneric("myplus"))
setMethod("myplus",c(x="numeric",y="numeric"),
  function(x,y,z=0) x+y+z
  )
setMethod("myplus",c(x="numeric",y="list"),
  function(x,y,...) callGeneric(x,unlist(y),...)
  )

myplus(1,1)   ## 2; OK
myplus(1,1,1) ## 3; OK

myplus(1,list(1)) ## 2; OK
myplus(1,list(1),z=1) ## 3; OK

a.c1 <- 1
myplus(1,list(1),z=a.c1) ## 3; OK

test <- function(x,y) {
  a.c <- 1## Problem occurs when using '.' in variable name
  myplus(a,y,z=a.c)
}

test(1,list(1)) ## error
test(1,1)  ## 3; OK

It looks like a bug. I went through all environments from inside
the call of myplus("numeric","numeric") and a.c is nicely located
in parent.frame(6) with the value 1. However, when it has a '.' (dot)
in the variable name, the variable is not found. If it has a name
without a '.' (dot) there is no problem:

test <- function(x,y) {
  a <- 1
  myplus(a,y,z=a)
}

test(1,list(1)) ## 3; OK

- Niels

On 26/08/10 15.32, Joris Meys wrote:

Dear all,

This problem came up initially while debugging a function, but it
seems to be a more general problem of R. I hope I'm wrong, but I can't
find another explanation. Let me illustrate with the raster package.

For an object "RasterLayer" (which inherits from Raster), there is a
method xyValues defined with the signature
(object="RasterLayer",xy="matrix"). There is also a method with
signature (object="Raster",xy="vector"). The only thing this method
does, is change xy into a matrix and then pass on to the next method
using callGeneric again. Arguments are passed.

Now this all works smoothly, as long as you stay in the global environment :
require(raster)

a<- raster()
a[]<- 1:ncell(a)

origin<- c(-80,50)
eff.dist<- 10

unlist(xyValues(a,xy=origin,buffer=eff.dist))
[1] 14140 14141 14500 14501

Now let's make a very basic test function :

test<- function(x,orig.point){
 eff.distance<- 10
 p<- unlist(xyValues(x,xy=orig.point,buffer=eff.distance))
 return(p)
}

This gives the following result :

test(a,origin)

Error in .local(object, xy, ...) : object 'eff.distance' not found

huh? Apparently, eff.distance got lost somewhere in the parsetree (am
I saying this correctly?)

The funny thing is when we change origin to a matrix :

origin<- matrix(origin,ncol=2)



unlist(xyValues(a,xy=origin,buffer=eff.dist))

[1] 14140 14141 14500 14501


test(a,origin)

[1] 14140 14141 14500 14501

It all works again! So something goes wrong with passing the arguments
from one method to another using callGeneric. Is this a bug in R or am
I missing something obvious?

The relevant code from the raster package :

setMethod("xyValues", signature(object='Raster', xy='vector'),
function(object, xy, ...) {
if (length(xy) == 2) {
callGeneric(object, matrix(xy, ncol=2), ...)
} else {
stop('xy coordinates should be a two-column matrix or 
data.frame,
or a vector of two numbers.')
}
} )

setMethod("xyValues", signature(object='RasterLayer', xy='matrix'),
function(object, xy, method='simple', buffer=NULL, fun=NULL, 
na.rm=TRUE) {

if (dim(xy)[2] != 2) {
stop('xy has wrong dimensions; it should have 2 
columns' )
}

if (! is.null(buffer)) {
return( .xyvBuf(object, xy, buffer, fun, na.rm=na.rm) )
}

if (method=='bilinear') {
return(.bilinearValue(object, xy))
} else if (method=='simple') {
cells<- cellFromXY(object, xy)
return(.readCells(object, cells))
} else {
stop('invalid method argument. Should be simple or 
bilinear.')
}
}   
)   





--
Niels Richard Hansen Web:   www.math.ku.dk/~richard 
Associate Professor  Email: niels.r.han...@math.ku.dk
Department of Mathematical Sciences nielsrichardhan...@gmail.com
University of Copenhagen Skype: nielsrichardhansen.dk   
Universitetsparken 5 Phone: +45 353 20783 (office)  
2100 Copenhagen Ø   +45 2859 0765 (mobile)
Denmark

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Find classes for each column of a data.frame

2010-08-26 Thread Marc Schwartz

On Aug 26, 2010, at 10:36 AM, David Winsemius wrote:

> 
> On Aug 26, 2010, at 11:31 AM, Daniel Brewer wrote:
> 
>> Hello,
>> 
>> Is there a simple way to get the class type for each column of a
>> data.frame?  I am in the situation where I would like to get all the
>> columns of a data.frame that are factors.
>> 
>> I have tried:
>> apply(df,2,class)
> 
> lapply(df, class)
> 
>> but all the columns come back as class "character".
> 
> Agree that is not what I would have expected.


> sapply(iris, class)
Sepal.Length  Sepal.Width Petal.Length  Petal.Width  Species 
   "numeric""numeric""numeric""numeric" "factor" 


> apply(iris, 2, class)
Sepal.Length  Sepal.Width Petal.Length  Petal.Width  Species 
 "character"  "character"  "character"  "character"  "character" 


The second occurs because apply() will coerce the data frame to a matrix:


> str(as.matrix(iris))
 chr [1:150, 1:5] "5.1" "4.9" "4.7" "4.6" "5.0" "5.4" ...
 - attr(*, "dimnames")=List of 2
  ..$ : NULL
  ..$ : chr [1:5] "Sepal.Length" "Sepal.Width" "Petal.Length" "Petal.Width" ...

Since a matrix can only contain a single class of objects (recall that a matrix 
is a vector with dim attributes), 'iris' becomes a character matrix.

HTH,

Marc Schwartz

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


Re: [R] daisy(): space allocation issue

2010-08-26 Thread Gavin Simpson
On Thu, 2010-08-26 at 07:35 -0700, abanero wrote:
> Hi,
> 
> I'm trying to apply the function daisy() to a data.frame 1x10 but I have
> not enough space (error message: cannot allocate vector of length
> 1476173280).
> 
> I didn't imagine I was not able to work with a matrix of just 1
> observations... I have setted in Rgui --max-mem-size=2G (I'm not able to set
> more space..)

You are trying make a 10,000 x 10,000 matrix of dissimilarities.

> How can I solve this issue? Separating observations depending on some rules?

Get/use a machine with more RAM?

I doubt separating observations into chunks and doing the dissimilarity
computations on those chunks then recombining will work as the end
result will still be the 10k x 10k matrix. (If that is what you meant.)

What do you want to do with the dissimilarities? If clustering, try the
clara() function in the same package (cluster) as daisy. But then you'd
need to work out whether clustering such a large number of observations
is a useful activity...

If something else, perhaps let us know what you want to do with the
dissimilarities or what you are trying to achieve as there may be other
things that you can do instead.

> thanks

HTH

G

-- 
%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%
 Dr. Gavin Simpson [t] +44 (0)20 7679 0522
 ECRC, UCL Geography,  [f] +44 (0)20 7679 0565
 Pearson Building, [e] gavin.simpsonATNOSPAMucl.ac.uk
 Gower Street, London  [w] http://www.ucl.ac.uk/~ucfagls/
 UK. WC1E 6BT. [w] http://www.freshwaters.org.uk
%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%

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


[R] R: daisy(): space allocation issue

2010-08-26 Thread Giuseppe De Vitis
Hi,


Gavin Simpson wrote: 
> What do you want to do with the dissimilarities?

Clustering.

Gavin Simpson wrote:
> If clustering, try the clara() function

I can't because the variables are mixed (numeric and categorical) and (I 
suppose..) I should  use "gower" distance in advance, shouldn't I?

Thanks
 Giuseppe  


-Messaggio originale-
Da: Gavin Simpson [mailto:gavin.simp...@ucl.ac.uk] 
Inviato: 26 August 2010 17:47
A: abanero
Cc: r-help@r-project.org
Oggetto: Re: [R] daisy(): space allocation issue

On Thu, 2010-08-26 at 07:35 -0700, abanero wrote:
> Hi,
> 
> I'm trying to apply the function daisy() to a data.frame 1x10 but I have
> not enough space (error message: cannot allocate vector of length
> 1476173280).
> 
> I didn't imagine I was not able to work with a matrix of just 1
> observations... I have setted in Rgui --max-mem-size=2G (I'm not able to set
> more space..)

You are trying make a 10,000 x 10,000 matrix of dissimilarities.

> How can I solve this issue? Separating observations depending on some rules?

Get/use a machine with more RAM?

I doubt separating observations into chunks and doing the dissimilarity
computations on those chunks then recombining will work as the end
result will still be the 10k x 10k matrix. (If that is what you meant.)

What do you want to do with the dissimilarities? If clustering, try the
clara() function in the same package (cluster) as daisy. But then you'd
need to work out whether clustering such a large number of observations
is a useful activity...

If something else, perhaps let us know what you want to do with the
dissimilarities or what you are trying to achieve as there may be other
things that you can do instead.

> thanks

HTH

G

-- 
%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%
 Dr. Gavin Simpson [t] +44 (0)20 7679 0522
 ECRC, UCL Geography,  [f] +44 (0)20 7679 0565
 Pearson Building, [e] gavin.simpsonATNOSPAMucl.ac.uk
 Gower Street, London  [w] http://www.ucl.ac.uk/~ucfagls/
 UK. WC1E 6BT. [w] http://www.freshwaters.org.uk
%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%

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

2010-08-26 Thread Samantha Patrick
Hi 
Thanks for your help - however if I have a model of:

mod1<-lmer(B~ A+C+(A|bird), family=quasibinomial) 

coef then gives me an individual slope for factors A and C.  However the random 
effect is only nested within factor - so I am only trying to allow the slope to 
vary in relation to effect A

Many Thanks

Sam

Dr Samantha Patrick
EU INTERREG Post Doc
Davy 618
Marine Biology & Ecology Research Centre
University of Plymouth 
Plymouth
PL4 8AA

T: 01752 586165 
M: 07740472719


-Original Message-
From: Darin A. England [mailto:engl...@cs.umn.edu] 
Sent: 26 August 2010 16:12
To: Samantha Patrick
Cc: r-help@R-project.org
Subject: Re: [R] Random slopes in lmer

coef(mod1)$bird will give you a matrix with two columns. The first
column is the intercept for each bird and the second column is the
slope for each bird.

ranef(mod1) will also give you a matrix of two columns. These
represent the random effects. That is, how much the intercept (or
slope) is shifted from overall mean.

HTH,
Darin

On Thu, Aug 26, 2010 at 01:15:10PM +0100, Samantha Patrick wrote:
> Hi
> 
> I want to extract the random slopes from a lmer (I am doing a random 
> regression), but are the answers obtained from ranef or coef?
> 
> My model is: mod1<-lmer(B~ A +(A|bird), family=quasibinomial)
> 
> And I want to obtain a slope for each individual bird but am not sure which 
> output I need and can't find the answer anywhere.
> 
> Thanks
> 
> Sam
> 
> 
> Dr Samantha Patrick
> EU INTERREG Post Doc
> Davy 618
> Marine Biology & Ecology Research Centre
> University of Plymouth
> Plymouth
> PL4 8AA
> 
> T: 01752 586165
> M: 07740472719
> 
> 
>   [[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] reliability of R-Forge?

2010-08-26 Thread Dirk Eddelbuettel

On 26 August 2010 at 11:28, R P Herrold wrote:
| On Thu, 26 Aug 2010, Gavin Simpson wrote:
| 
| > On Thu, 2010-08-26 at 02:30 -0400, David Kane wrote:
| >> How reliable is R-Forge? http://r-forge.r-project.org/
| >>
| >> It is down now (for me). Reporting "R-Forge Could Not Connect to Database: 
"
| 
| late to chime in, so had tossed the first piece.  As this 
| relates to 'reliability of R-Forge' in the sense of possible 
| process issues, rather than availability of the archive, I 
| wanted to 'tag into' this thread
| 
| I 'mirror' r-forge, so I have not seen this ...
| 
| One thing I note, mirroring r-forge, and processing 'diffs' 
| netween successive days, is that the md5sums of some packages 
| regularly change without version number bumps.  From this 
| morning's report in my email:
| 
| Thu Aug 26 04:30:01 EDT 2010
| 
| --- /tmp/rforge-pre.txt 2010-08-26 04:30:33.0 -0400
| +++ /tmp/rforge-post.txt2010-08-26 04:38:03.0 
| -0400
| @@ -8,18 +8,18 @@
|   AquaEnv_1.0-1.tar.gz   615059a5369d1aba149e6142fedffdde
|   ArvoRe_0.1.6.tar.gzc955ae7c64c4270740172ad2219060ff
|   BB_2010.7-1.tar.gz 4f85093ab24fac5c0b91539ec6efb8b7
| -BCE_2.0.tar.gz 5a3fe3ecabbe2b2e278f6a48fc19d18d
| -BIOMOD_1.1-5.tar.gzd2f74f21bc8858844f8d71627fd8e687
| +BCE_2.0.tar.gz 65a968c586e729a1c1ca34a37f5c293a
| +BIOMOD_1.1-5.tar.gz6929e5ad6a14709de7065286ec684942
|   ...
| -BTSPAS_2010.08.tar.gz  16b8f265846a512c329f0b52ba1924ab
| +BTSPAS_2010.08.tar.gz  809a96b11f1094e95b217af113abd0ac
|   ...
| -BayesR_0.1-1.tar.gz72bd41c90845032eb9d15c4c6d086dec
| +BayesFactorPCL_0.5.tar.gz  173ab741c399309314eff240a4c3cd6f
| +BayesR_0.1-1.tar.gz9560b511f1b955a60529599672d58fea
|   ...
| -BiplotGUI_0.0-6.tar.gz 594b3a275cde018eaa74e1ef974dd522
| +BiplotGUI_0.0-6.tar.gz 857a484fdba6cb97be4e42e38bb6d0fd
|   ...
| -IsoGene_1.0-18.tar.gz  679a5aecb7182474ed6a870fa52ca2e3
| +IsoGene_1.0-18.tar.gz  f37572957b2a9846a8d738ec88ac8690
| 
| and so forth.  I've not taken the trime to understand why 
| seemingly new versions are appearing without version bumps 
| yet.
| 
| Is anyone aware of explanations, other than a release process 
| that does not require unique versioning of differing content? 
| [it seems pretty basic to me that a 'receiver' of new content 
| could do the checks I do, and decline to push conflicting 
| md5sums over an identically named prior candidate in archive]

Version numbers change only when DESCRIPTION/Version gets updated.

Content (of the tarball) and thusly md5sum changes whenever _any_ file
in the archive changes.

Methinks you tricked yourself into assuming tarballs have to be constant
because they are on CRAN _where changes happen only with new releases_.  

Dirk

-- 
Dirk Eddelbuettel | e...@debian.org | http://dirk.eddelbuettel.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] Find classes for each column of a data.frame

2010-08-26 Thread Gabor Grothendieck
On Thu, Aug 26, 2010 at 11:31 AM, Daniel Brewer  wrote:
> Hello,
>
> Is there a simple way to get the class type for each column of a
> data.frame?  I am in the situation where I would like to get all the
> columns of a data.frame that are factors.
>
> I have tried:
> apply(df,2,class)
> but all the columns come back as class "character".
>

Try this where iris is a builtin data frame with one several numeric
columns and one factor column, Species:

> onlyFactors <- Filter(is.factor, iris)
> str(onlyFactors)
'data.frame':   150 obs. of  1 variable:
 $ Species: Factor w/ 3 levels "setosa","versicolor",..: 1 1 1 1 1 1 1 1 1 1 ...

-- 
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] Quick GREP challenge

2010-08-26 Thread Dimitri Shvorob

Many thanks!
-- 
View this message in context: 
http://r.789695.n4.nabble.com/Quick-GREP-challenge-tp2339486p2339818.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] equalize function with zero and convert it

2010-08-26 Thread Immanuel Seeger
Thanks, but my problem is that I have my formulas in functions.
How can I do that for functions or e.g. for the body(Df) below?
And: How can I refer to the first solution of expression?
Thanks a lot!

-Ursprüngliche Nachricht-
Von: Gabor Grothendieck [mailto:ggrothendi...@gmail.com] 
Gesendet: Donnerstag, 26. August 2010 14:56
An: Immanuel Seeger
Cc: r-help@r-project.org
Betreff: Re: [R] equalize function with zero and convert it

On Thu, Aug 26, 2010 at 6:57 AM, Immanuel Seeger 
wrote:
> Dear all,
> I want to equalize a symbolic derivative (of a function with two
> variables) with zero and convert it to a variable, e.g. x.
>
> I'm computing the derivative by: (found it in the archive)
> library(Ryacas)
> f <- function(x,y) (100-x-y)*x-10*x
> yacas(f) # register f with yacas
> Df <- f
> body(Df) <- yacas(expression(deriv(f(x,y),x)))[[1]]
> Df
>
> R-Output:
> function (x, y)
> 100 - x - y - x - 10
>
> Questions :
> 1.      How can I equalize the derivative(140-x-y-x-20) with zero?
> 2.      How can I convert it to x?
>
> I want something like:
> 45-0.5*y=x
>
> With only one variable or two non-symbolic variables it's working with
> uniroot(f, c(-10, 10))$root.
>

This solves for x:

> library(Ryacas)
Loading required package: XML
> x <- Sym("x")
> y <- Sym("y")
> Solve((100-x-y)*x-10*x == 0, "x")
[1] "Starting Yacas!"
expression(list(x == -((10 - (100 - y) + root((100 - y - 10)^2,
2))/2), x == -((10 - (100 - y) - root((100 - y - 10)^2, 2))/2)))

-- 
GKX Group
GKX Associates Inc.
1-877-GKX-GROUP
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.


[R] mailing list

2010-08-26 Thread Sonia Spirling
Hello,

I was wondering if I could be taken off the list to get emails?

Thanks
Sonia

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

2010-08-26 Thread Hans W Borchers
Ben Holt  bio.ku.dk> writes:
> I have data similar to this:
> 
> Location Surveyor Result
> A1 83
> A2 76
> A3 45
> B1 71
> B4 67
> C2 23
> C5 12
> D3 34
> E4 75
> F4 46
> G5 90
> etc (5 million records in total)
> 
> I need to divide the data to many subsets then randomly select 5 different
> locations and 5 different surveyors (one at each of the 5 randomly selected
> locations) for each subset.
> 
> The function I have written basically picks five locations and then 1
> surveyor in each location, checks that there are five different surveyors
> and if there isn't tries again. The problem is that for some subsets this
> doesn't work.
> 
> Some subsets don't have enough locations/surveyors or both, but this can be
> checked for easily. The problem subsets do have enoughs locations and
> surveyors but still cannot produce 5 locations each with a different
> surveyor. The matrix below demonstrates such a subset:
>  
>   locations
>   A B C D E
> 1 1 0 0 0 0
> Surveyors   2 1 0 0 0 0
> 3 1 0 0 0 0
> 4 1 0 0 0 0
> 5 1 1 1 1 1
> 
> I cannot think of a way to check for such a situation and therefore I have
> simply programmed the function to give up after 100 attempts if it can't
> find a solution. This is not very satisfactory however as the analysis takes
> a very long time to run and it would also be very useful useful for me to
> know how many suitable solution there are.

If I understand you correctly:  The task of finding a maximal number of
'independent' pairs (of surveyors and locations) is called the "generalized
(or: maximum) linear assignment" problem, see

http://en.wikipedia.org/wiki/Generalized_assignment_problem

and there appears not to exist an efficient algorithm. One can think of
procedures to find at least 5 such pairs (or to report infeasibility), but
I think with millions of records in one of those subsets any approach (using
loops) will be intolerable slow.

Perhaps you can rethink your original intention or try to provide additional
information during the process of generating the data.

Of course, I would be glad to hear more positive news as this kind of problem
does show up in many discrete optimization tasks.

Hans Werner

> I reckon some of you clever folk out there must be able to think of a better
> solution.
> 
> Any advice appreciated,
> 
> Ben
>

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

2010-08-26 Thread Bert Gunter
???
You were provided exactly what you requested. I think you either need
to read up on what random effects models mean or more clearly
communicate what YOU mean. (It's unclear to me, anyway).

-- 
Bert Gunter
Genentech Nonclinical Statistics

On Thu, Aug 26, 2010 at 8:57 AM, Samantha Patrick
 wrote:
> Hi
> Thanks for your help - however if I have a model of:
>
> mod1<-lmer(B~ A+C+(A|bird), family=quasibinomial)
>
> coef then gives me an individual slope for factors A and C.  However the 
> random effect is only nested within factor - so I am only trying to allow the 
> slope to vary in relation to effect A
>
> Many Thanks
>
> Sam
>
> Dr Samantha Patrick
> EU INTERREG Post Doc
> Davy 618
> Marine Biology & Ecology Research Centre
> University of Plymouth
> Plymouth
> PL4 8AA
>
> T: 01752 586165
> M: 07740472719
>
>
> -Original Message-
> From: Darin A. England [mailto:engl...@cs.umn.edu]
> Sent: 26 August 2010 16:12
> To: Samantha Patrick
> Cc: r-help@R-project.org
> Subject: Re: [R] Random slopes in lmer
>
> coef(mod1)$bird will give you a matrix with two columns. The first
> column is the intercept for each bird and the second column is the
> slope for each bird.
>
> ranef(mod1) will also give you a matrix of two columns. These
> represent the random effects. That is, how much the intercept (or
> slope) is shifted from overall mean.
>
> HTH,
> Darin
>
> On Thu, Aug 26, 2010 at 01:15:10PM +0100, Samantha Patrick wrote:
>> Hi
>>
>> I want to extract the random slopes from a lmer (I am doing a random 
>> regression), but are the answers obtained from ranef or coef?
>>
>> My model is: mod1<-lmer(B~ A +(A|bird), family=quasibinomial)
>>
>> And I want to obtain a slope for each individual bird but am not sure which 
>> output I need and can't find the answer anywhere.
>>
>> Thanks
>>
>> Sam
>>
>>
>> Dr Samantha Patrick
>> EU INTERREG Post Doc
>> Davy 618
>> Marine Biology & Ecology Research Centre
>> University of Plymouth
>> Plymouth
>> PL4 8AA
>>
>> T: 01752 586165
>> M: 07740472719
>>
>>
>>       [[alternative HTML version deleted]]
>>
>> __
>> R-help@r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

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

2010-08-26 Thread Sarah Goslee
Certainly. The link at the bottom of each and every email to this list has
the web address at which you may do so.

For your convenience:
https://stat.ethz.ch/mailman/listinfo/r-help

Sarah

On Thu, Aug 26, 2010 at 9:05 AM, Sonia Spirling
 wrote:
> Hello,
>
> I was wondering if I could be taken off the list to get emails?
>
> Thanks
> Sonia
>

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


Re: [R] Find classes for each column of a data.frame

2010-08-26 Thread Barry Rowlingson
On Thu, Aug 26, 2010 at 4:44 PM, Marc Schwartz  wrote:

>> sapply(iris, class)
> Sepal.Length  Sepal.Width Petal.Length  Petal.Width      Species
>   "numeric"    "numeric"    "numeric"    "numeric"     "factor"

 Note that comparing the result of class(foo) is a bad way of telling
if something is of a particular class, because of inheritance -
class(foo) can be a vector if the object belongs to more than one
class.

 Always test using is.whatever(foo), which returns TRUE if foo is a whatever:

 > f=factor(letters)
 > class(f)
 [1] "factor"
 > class(f)=c("factor","alphabet")
 > f
  [1] a b c d e f g h i j k l m n o p q r s t u v w x y z
 Levels: a b c d e f g h i j k l m n o p q r s t u v w x y z
 > is.factor(f)
 [1] TRUE

 but now:

 > class(f)=="factor"
 [1]  TRUE FALSE

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] Find classes for each column of a data.frame

2010-08-26 Thread S Ellison
try

lapply(df, class)

Steve E

On Thu, Aug 26, 2010 at 4:31 PM, Daniel Brewer
 wrote:
> Hello,
>
> Is there a simple way to get the class type for each column of a
> data.frame?  I am in the situation where I would like to get all the
> columns of a data.frame that are factors.
>
> I have tried:
> apply(df,2,class)
> but all the columns come back as class "character".

 apply is treating it as a matrix, and so converts it to the lowest
common form.

 try lapply and use is.factor, with some unlist for good measure:

 z=data.frame(x=1:10,l=factor(1:10))
 unlist(lapply(z,is.factor))

   x l
FALSE  TRUE


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.

***
This email and any attachments are confidential. Any use...{{dropped:8}}

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

2010-08-26 Thread R P Herrold

On Thu, 26 Aug 2010, Dirk Eddelbuettel wrote:


On 26 August 2010 at 11:28, R P Herrold wrote:



| Is anyone aware of explanations, other than a release process
| that does not require unique versioning of differing content?
| [it seems pretty basic to me that a 'receiver' of new content
| could do the checks I do, and decline to push conflicting
| md5sums over an identically named prior candidate in archive]

Version numbers change only when DESCRIPTION/Version gets updated.

Content (of the tarball) and thusly md5sum changes whenever _any_ file
in the archive changes.

Methinks you tricked yourself into assuming tarballs have to be constant
because they are on CRAN _where changes happen only with new releases_.


It is good to know that my tool was looking at the wrong 
datum.  Thank you, Dirk.


I shall amend my tool.  Probably I'll add a 'unroller' and 
diff tool so I may seem the changes pushing through


Doesn't this cause your builder some heartburn in Debian 
package md5sum verification phase of autobuilding, or do you 
simply auto-bump the release field within a version series?


-- Russ herrold

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


Re: [R] Passing arguments between S4 methods fails within a function:bug? example with raster package.

2010-08-26 Thread Martin Morgan

 On 8/26/2010 8:43 AM, Niels Richard Hansen wrote:

setGeneric("myplus",function(x,y,...) standardGeneric("myplus"))
setMethod("myplus",c(x="numeric",y="numeric"),
  function(x,y,z=0) x+y+z
  )
setMethod("myplus",c(x="numeric",y="list"),
  function(x,y,...) callGeneric(x,unlist(y),...)
  )

myplus(1,1)   ## 2; OK
myplus(1,1,1) ## 3; OK

myplus(1,list(1)) ## 2; OK
myplus(1,list(1),z=1) ## 3; OK

a.c1 <- 1
myplus(1,list(1),z=a.c1) ## 3; OK

test <- function(x,y) {
  a.c <- 1## Problem occurs when using '.' in variable name
  myplus(a,y,z=a.c)
}

test(1,list(1)) ## error
test(1,1)  ## 3; OK


I get an error in both instances, because in fact there is no variable 
'a' defined (anywhere) in the session. I do get your results if I define 
a global variable a <- 2


The reason for the original problem can be seen by looking at how the 
methods are implemented (I added parentheses in the setMethod calls for 
clarity)


> showMethods(myplus, includeDef=TRUE)
Function: myplus (package .GlobalEnv)
x="numeric", y="list"
function (x, y, ...)
{
callGeneric(x, unlist(y), ...)
}


x="numeric", y="numeric"
function (x, y, ...)
{
.local <- function (x, y, z = 0)
{
x + y + z
}
.local(x, y, ...)
}

and in particular the c("numeric", "numeric") method has an extra 
argument z, and so has a nested .local function. This is how the methods 
package deals with method signatures that differ from the generic.


I think, roughly, that when c("numeric", "numeric") tries finally to 
resolve it's argument 'x', it looks for a variable 'a' in the 
environment two levels up (method --> generic) from where it is being 
resolved. This is fine if the method has no .local environment (e.g., if 
c("numeric", "numeric") where defined as function(x, y, ...) { x +y }). 
I think that there is no general solution to this; the user could 
callGeneric or evaluate symbols from arbitrarily nested functions within 
either the calling or called methods themselves, and could arrive at a 
particular method through callGeneric or other routes (e.g., 
callNextMethod) that are not consistent in terms of the implied frame of 
evaluation. I could be mistaken.


A simple solution is to provided named arguments to callGeneric, e.g., 
callGeneric(x=x, y=unlist(y), ...).


These issues are likely to cause problems for eval / substitute 
expressions like the one posted by Joris yesterday, where there are 
implicit assumptions about the environment in which the experession is 
being evaluated.


Martin

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

2010-08-26 Thread Darin A. England
I'm sure this has appeared before on this list, but the biggest 
help to me has been: "Gelman and Hill", Data Analysis and 
Regression Using Multilevel/Hierarchical Models, which contains
clear explanations and the R code to go along. Also check out
http://lme4.r-forge.r-project.org/book/

Looking at Sam's model specification, C is a fixed effect. 


On Thu, Aug 26, 2010 at 09:15:14AM -0700, Bert Gunter wrote:
> ???
> You were provided exactly what you requested. I think you either need
> to read up on what random effects models mean or more clearly
> communicate what YOU mean. (It's unclear to me, anyway).
> 
> -- 
> Bert Gunter
> Genentech Nonclinical Statistics
> 
> On Thu, Aug 26, 2010 at 8:57 AM, Samantha Patrick
>  wrote:
> > Hi
> > Thanks for your help - however if I have a model of:
> >
> > mod1<-lmer(B~ A+C+(A|bird), family=quasibinomial)
> >
> > coef then gives me an individual slope for factors A and C. ?However the 
> > random effect is only nested within factor - so I am only trying to allow 
> > the slope to vary in relation to effect A
> >
> > Many Thanks
> >
> > Sam
> >
> > Dr Samantha Patrick
> > EU INTERREG Post Doc
> > Davy 618
> > Marine Biology & Ecology Research Centre
> > University of Plymouth
> > Plymouth
> > PL4 8AA
> >
> > T: 01752 586165
> > M: 07740472719
> >
> >
> > -Original Message-
> > From: Darin A. England [mailto:engl...@cs.umn.edu]
> > Sent: 26 August 2010 16:12
> > To: Samantha Patrick
> > Cc: r-help@R-project.org
> > Subject: Re: [R] Random slopes in lmer
> >
> > coef(mod1)$bird will give you a matrix with two columns. The first
> > column is the intercept for each bird and the second column is the
> > slope for each bird.
> >
> > ranef(mod1) will also give you a matrix of two columns. These
> > represent the random effects. That is, how much the intercept (or
> > slope) is shifted from overall mean.
> >
> > HTH,
> > Darin
> >
> > On Thu, Aug 26, 2010 at 01:15:10PM +0100, Samantha Patrick wrote:
> >> Hi
> >>
> >> I want to extract the random slopes from a lmer (I am doing a random 
> >> regression), but are the answers obtained from ranef or coef?
> >>
> >> My model is: mod1<-lmer(B~ A +(A|bird), family=quasibinomial)
> >>
> >> And I want to obtain a slope for each individual bird but am not sure 
> >> which output I need and can't find the answer anywhere.
> >>
> >> Thanks
> >>
> >> Sam
> >>
> >>
> >> Dr Samantha Patrick
> >> EU INTERREG Post Doc
> >> Davy 618
> >> Marine Biology & Ecology Research Centre
> >> University of Plymouth
> >> Plymouth
> >> PL4 8AA
> >>
> >> T: 01752 586165
> >> M: 07740472719
> >>
> >>
> >> ? ? ? [[alternative HTML version deleted]]
> >>
> >> __
> >> R-help@r-project.org mailing list
> >> https://stat.ethz.ch/mailman/listinfo/r-help
> >> PLEASE do read the posting guide 
> >> http://www.R-project.org/posting-guide.html
> >> and provide commented, minimal, self-contained, reproducible code.
> >
> > __
> > R-help@r-project.org mailing list
> > https://stat.ethz.ch/mailman/listinfo/r-help
> > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> > and provide commented, minimal, self-contained, reproducible code.

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

2010-08-26 Thread William Dunlap


Bill Dunlap
Spotfire, TIBCO Software
wdunlap tibco.com  

> -Original Message-
> From: r-help-boun...@r-project.org 
> [mailto:r-help-boun...@r-project.org] On Behalf Of Dimitri Shvorob
> Sent: Thursday, August 26, 2010 3:16 AM
> To: r-help@r-project.org
> Subject: [R] Quick GREP challenge
> 
> 
> > grep("f[0-9]+=", "f1=5,f22=3,", value = T)
> [1] "f1=5,f22=3,"
> 
> How do I make the line output c("f1", "f22") instead? 
> (Actually, c(1,22)
> would be even better).

If you had S+ you could use subpattern and keep arguments
to strsplit (which otherwise acts like R's strsplit):

  > strings <- c("f1=5,f22=3,", "g4,f55,f66", "hello")
  > strsplit(strings, "f([[:digit:]]+)", subpattern=1, keep=TRUE)
  [[1]]:
  [1] "1"  "22"
  
  [[2]]:
  [1] "55" "66"

  [[3]]:
  character(0)

keep=TRUE means to split the string by what is not in
the pattern (keeping what is in the pattern) instead
of the usual splitting by what is in the pattern and
keeping what is not in the pattern.

subpattern=n means to match by the whole pattern but
to use only the n'th parenthesized subpattern when
deciding what to split by or keep.  In this case the
whole pattern matches 'f' followed by 1 or more digits
but we only want the keep the digits.  (subpattern=0,
the default, means to use the entire pattern.)

You still need to use as.integer() or as.numeric() on
the output elements.

Bill Dunlap
Spotfire, TIBCO Software
wdunlap tibco.com 
> 
> 
> Thank you.
> 
>  
> -- 
> View this message in context: 
> http://r.789695.n4.nabble.com/Quick-GREP-challenge-tp2339486p2
339486.html
> Sent from the R help mailing list archive at Nabble.com.
> 
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide 
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
> 

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


Re: [R] reliability of R-Forge?

2010-08-26 Thread Marc Schwartz
On Aug 26, 2010, at 11:01 AM, Dirk Eddelbuettel wrote:

> 
> On 26 August 2010 at 11:28, R P Herrold wrote:
> | On Thu, 26 Aug 2010, Gavin Simpson wrote:
> | 
> | > On Thu, 2010-08-26 at 02:30 -0400, David Kane wrote:
> | >> How reliable is R-Forge? http://r-forge.r-project.org/
> | >>
> | >> It is down now (for me). Reporting "R-Forge Could Not Connect to 
> Database: "
> | 
> | late to chime in, so had tossed the first piece.  As this 
> | relates to 'reliability of R-Forge' in the sense of possible 
> | process issues, rather than availability of the archive, I 
> | wanted to 'tag into' this thread
> | 
> | I 'mirror' r-forge, so I have not seen this ...
> | 
> | One thing I note, mirroring r-forge, and processing 'diffs' 
> | netween successive days, is that the md5sums of some packages 
> | regularly change without version number bumps.  From this 
> | morning's report in my email:
> | 
> | Thu Aug 26 04:30:01 EDT 2010
> | 
> | --- /tmp/rforge-pre.txt 2010-08-26 04:30:33.0 -0400
> | +++ /tmp/rforge-post.txt2010-08-26 04:38:03.0 
> | -0400
> | @@ -8,18 +8,18 @@
> |   AquaEnv_1.0-1.tar.gz   615059a5369d1aba149e6142fedffdde
> |   ArvoRe_0.1.6.tar.gzc955ae7c64c4270740172ad2219060ff
> |   BB_2010.7-1.tar.gz 4f85093ab24fac5c0b91539ec6efb8b7
> | -BCE_2.0.tar.gz 5a3fe3ecabbe2b2e278f6a48fc19d18d
> | -BIOMOD_1.1-5.tar.gzd2f74f21bc8858844f8d71627fd8e687
> | +BCE_2.0.tar.gz 65a968c586e729a1c1ca34a37f5c293a
> | +BIOMOD_1.1-5.tar.gz6929e5ad6a14709de7065286ec684942
> |   ...
> | -BTSPAS_2010.08.tar.gz  16b8f265846a512c329f0b52ba1924ab
> | +BTSPAS_2010.08.tar.gz  809a96b11f1094e95b217af113abd0ac
> |   ...
> | -BayesR_0.1-1.tar.gz72bd41c90845032eb9d15c4c6d086dec
> | +BayesFactorPCL_0.5.tar.gz  173ab741c399309314eff240a4c3cd6f
> | +BayesR_0.1-1.tar.gz9560b511f1b955a60529599672d58fea
> |   ...
> | -BiplotGUI_0.0-6.tar.gz 594b3a275cde018eaa74e1ef974dd522
> | +BiplotGUI_0.0-6.tar.gz 857a484fdba6cb97be4e42e38bb6d0fd
> |   ...
> | -IsoGene_1.0-18.tar.gz  679a5aecb7182474ed6a870fa52ca2e3
> | +IsoGene_1.0-18.tar.gz  f37572957b2a9846a8d738ec88ac8690
> | 
> | and so forth.  I've not taken the trime to understand why 
> | seemingly new versions are appearing without version bumps 
> | yet.
> | 
> | Is anyone aware of explanations, other than a release process 
> | that does not require unique versioning of differing content? 
> | [it seems pretty basic to me that a 'receiver' of new content 
> | could do the checks I do, and decline to push conflicting 
> | md5sums over an identically named prior candidate in archive]
> 
> Version numbers change only when DESCRIPTION/Version gets updated.
> 
> Content (of the tarball) and thusly md5sum changes whenever _any_ file
> in the archive changes.
> 
> Methinks you tricked yourself into assuming tarballs have to be constant
> because they are on CRAN _where changes happen only with new releases_.  
> 
> Dirk


I might also point out that the same process is in place for the daily tarballs 
of R itself, available via:

  ftp://ftp.stat.math.ethz.ch/Software/R/

The R version does not change with each new daily tarball, but the svn rev 
number will change with each new commit. Thus, each day, the checksum will be 
different, since the tarball is generated each day with the new svn commits 
from the prior 24 hours, unless of course, there have been no new commits in 
that time frame.

In the case of the R tarballs, the generating script also includes a file 
called SVN-REVISION, which will contain something like:

Revision: 52804
Last Changed Date: 2010-08-25


You don't get that with the R-Forge tarballs, since that file/info is not 
included in R source package tarballs.

The same would occur BTW, if you did an svn checkout rather than using the 
tarball directly. Your checkout would reflect the current rev state of the svn 
repo at that time, which will be more granular than a daily source tarball and 
might be different 5 minutes later, if a new commit occurred in that time frame.

This approach is part and parcel of using an svn repo. You can have main trunks 
(in the case of R, R-Devel), along with defined branches (eg. R 2.x.y), each of 
which may get hundreds or thousands of commits over some window of time, 
without a version bump during that time frame. R-Forge packages will not have 
the same frequency of commits, but the same approach can be applied.

So you need to differentiate between the ongoing development/commit process and 
the versioned release process.

HTH,

Marc Schwartz

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


Re: [R] Problem with clusterCall, "Error in checkForRemoteErrors(lapply(cl, recvResult)) : "

2010-08-26 Thread telm8

Did anyone manage to have a look at this? I have now tried foreach with doMC
backen and multicore, but still no luck. If someone can help that would be
much appreciated!
-- 
View this message in context: 
http://r.789695.n4.nabble.com/Problem-with-clusterCall-Error-in-checkForRemoteErrors-lapply-cl-recvResult-tp2338375p2340076.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] Data Manipulations and SQL

2010-08-26 Thread stephenb

Greetings Gabor,

is it possible to open a channel to a data frame in the default environment?
there are cases when using a sql update statement is the simplest
alternative, so instead of dumping the df and then updating and then
reimporting it I would like to update the df directly in R.

Thank you.
Stephen
-- 
View this message in context: 
http://r.789695.n4.nabble.com/Data-Manipulations-and-SQL-tp860420p2340098.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] anova for plm objects

2010-08-26 Thread Roberto Patuelli
Dear All,

I'm looking to perform an ANOVA between two nested panel fixed effects models. 
I tried with anova, as well as with waldtest. anova tells me there is no method 
available for plm objects, while waldtest tells me my models are not nested. I 
think they are instead. The difference between the two models is that in the 
second I let the regression coefficients of a given variable variate according 
to a factor.

MODEL 1
depFE.plm = plm(urate ~ l1_urate + month, model = "within", data = 
unempl_data1, effect = "individual")

MODEL 2
depLDFE.plm = plm(urate ~ factor(ID):l1_urate + month, model = "within", data = 
unempl_data1, effect = "individual")

anova
> anova(depFE.plm, depLDFE.plm)
Errore in UseMethod("anova") : 
  no applicable method for 'anova' applied to an object of class "c('plm', 
'panelmodel')"

waldtest
> waldtest(depFE.plm, depLDFE.plm)
Errore in modelCompare(objects[[i - 1]], objects[[i]], vfun = vcov.) : 
  models are not nested

Did anyone code a plm method for anova?
OR
Does anyone know why according to waldtest my models are not nested?

Thanks
Roberto


Roberto Patuelli, Ph.D.
Istituto Ricerche Economiche (IRE) (Institute for Economic Research)
Università della Svizzera Italiana (University of Lugano)
via Maderno 24, CP 4361
CH-6904 Lugano
Switzerland
Phone: +41-(0)58-666-4166
Fax: +39-02-700419665
Email: roberto.patue...@usi.ch
Homepage: http://www.people.lu.unisi.ch/patuellr

[[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] Data Manipulations and SQL

2010-08-26 Thread Gabor Grothendieck
On Thu, Aug 26, 2010 at 1:18 PM, stephenb  wrote:
> is it possible to open a channel to a data frame in the default environment?
> there are cases when using a sql update statement is the simplest
> alternative, so instead of dumping the df and then updating and then
> reimporting it I would like to update the df directly in R.

Assuming that this is a question about sqldf see these links. The
first has an example of update and the second discusses connections
that persist across sqldf commands:

http://code.google.com/p/sqldf/#8._Why_am_I_having_problems_with_update?
http://code.google.com/p/sqldf/#Example_10._Persistent_Connections

You may also wish to use the RSQLite package directly.

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


[R] non-linear plot parameters

2010-08-26 Thread Marlin Keith Cox
I need the parameters estimated for a non-linear equation, an example of the
data is below.


rm(list=ls())
Time<-c( 0, 0, 0, 0, 0, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 4, 4, 4,
4, 4, 5, 5, 5, 5, 5, 8, 8, 8, 8, 8)
Level<-c( 100, 110,  90,  95,  87,  60,  65,  61,  55,  57,  40,  41,  50,
47,
44,  44,  42,  38,  40, 37,  37,  35,  40,  34,  32,  20,  22,  25,  27,
29)
plot(Time,Level,pch=16)

Keith



-- 
M. Keith Cox, Ph.D.
Alaska NOAA Fisheries, National Marine Fisheries Service
Auke Bay Laboratories
17109 Pt. Lena Loop Rd.
Juneau, AK 99801
keith@noaa.gov
marlink...@gmail.com
U.S. (907) 789-6603

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

2010-08-26 Thread Jeff Newmiller
Look for a vectorized solution such  as ?table or ?aggregate to obtain a list 
of combination counts, followed by logical indexing or ?subset to get a set of 
valid combinations, and then use ?sample to get your random selections of 
locations/surveyors and then process only those combinations from your original 
data set. Keep in mind that constraints that you apply late in the selection 
process that can be applied earlier or on less data will usually become more 
efficient.

If you provide actual sample statements that you have already tried, you may 
get a less abstract response. See the posting guide mentioned at the end of 
every posting for more guidance.

"Ben Holt"  wrote:

>I have data similar to this:
>
>Location Surveyor Result
>A1 83
>A2 76
>A3 45
>B1 71
>B4 67
>C2 23
>C5 12
>D3 34
>E4 75
>F4 46
>G5 90
>etc (5 million records in total)
>
>I need to divide the data to many subsets then randomly select 5 different 
>locations and 5 different surveyors (one at each of the 5 randomly selected 
>locations) for each subset.
>
>The function I have written basically picks five locations and then 1 surveyor 
>in each location, checks that there are five different surveyors and if there 
>isn't tries again.  The problem is that for some subsets this doesn't work.
>
>Some subsets don't have enough locations/surveyors or both, but this can be 
>checked for easily.  The problem subsets do have enoughs locations and 
>surveyors but still cannot produce 5 locations each with a different surveyor. 
> The matrix below demonstrates such a subset:
> 
>  locations
>  A B C D E
>1 1 0 0 0 0
>Surveyors   2 1 0 0 0 0
>3 1 0 0 0 0
>4 1 0 0 0 0
>5 1 1 1 1 1
>
>I cannot think of a way to check for such a situation and therefore I have 
>simply programmed the function to give up after 100 attempts if it can't find 
>a solution.  This is not very satisfactory however as the analysis takes a 
>very long time to run and it would also be very useful useful for me to know 
>how many suitable solution there are.
>
>I reckon some of you clever folk out there must be able to think of a better 
>solution.
>
>Any advice appreciated,
>
>Ben
>
>__
>R-help@r-project.org mailing list
>https://stat.ethz.ch/mailman/listinfo/r-help
>PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
>and provide commented, minimal, self-contained, reproducible code.

---
Jeff NewmillerThe .   .  Go Live...
DCN:Basics: ##.#.   ##.#.  Live Go...
  Live:   OO#.. Dead: OO#..  Playing
Research Engineer (Solar/BatteriesO.O#.   #.O#.  with
/Software/Embedded Controllers)   .OO#.   .OO#.  rocks...1k
---
Sent from my phone. Please excuse my brevity.

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


  1   2   >