Re: [R] expand.grid game

2009-12-21 Thread Robin Hankin

Hi

library(partitions)
jj - blockparts(rep(9,8),17)
dim(jj)

gives 318648


HTH

rksh



baptiste auguie wrote:

Dear list,

In a little numbers game, I've hit a performance snag and I'm not sure
how to code this in C.

The game is the following: how many 8-digit numbers have the sum of
their digits equal to 17?
The brute-force answer could be:

maxi - 9 # digits from 0 to 9
N - 5 # 8 is too large
test - 17 # for example's sake

sum(rowSums(do.call(expand.grid, c(list(1:maxi), rep(list(0:maxi),
N-1 == test)
## 3675

Now, if I make N = 8, R stalls for some time and finally gives up with:
Error: cannot allocate vector of size 343.3 Mb

I thought I could get around this using Reduce() to recursively apply
rowSum to intermediate results, but it doesn't seem to help,


a=list(1:maxi)
b=rep(list(0:maxi), N-1)

foo - function(a, b, fun=sum, ...){
  switch(fun,
 'sum' =  rowSums(do.call(expand.grid, c(a, b))),
 'mean' =  rowMeans(do.call(expand.grid, c(a, b))),
 apply(do.call(expand.grid, c(a, b)), 1, fun, ...)) # generic case
}

sum(Reduce(foo, list(b), init=a) == test)
## 3675 # OK

Same problem with N=8.

Now, if N was fixed I could write a little C code to do this
calculation term-by-term, something along those lines,

test = 0;

for (i1=1, i1=9, i1++) {
 for (i2=0, i2=9, i2++) {

 [... other nested loops ]

  test = test + (i1 + i2 + [...] == 17);

 } [...]
}

but here the number of for loops, N, should remain a variable.

In despair I coded this in R as a wicked eval(parse()) construct, and
it does produce the expected result after an awfully long time.

makeNestedLoops - function(N=3){

  startLoop - function(ii, start=1, end=9){
paste(for (i, ii,  in seq(,start,, ,end,)) {\n, sep=)
  }

  first - startLoop(1)
  inner.start - lapply(seq(2, N), startLoop, start=0)
  calculation - paste(test - test + (, paste(i, seq(1, N),
sep=, collapse=+), ==17 )\n)
  end - replicate(N, }\n)
  code.to.run - do.call(paste, c(list(first), inner.start, calculation, end))
  cat(code.to.run)
  invisible(code.to.run)
}

test - 0
eval(parse(text = makeNestedLoops(8)) )
## 229713

I hope I have missed a better way to do this in R. Otherwise, I
believe what I'm after is some kind of C or C++ macro expansion,
because the number of loops should not be hard coded.

Thanks for any tips you may have!

Best regards,

baptiste

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



--
Robin K. S. Hankin
Uncertainty Analyst
University of Cambridge
19 Silver Street
Cambridge CB3 9EP
01223-764877

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

2009-12-21 Thread Daniel Malter
No, it does not mean that the numbers have zero chance of being wrong. The
extent to which the estimate can be wrong (which is a very bad and imprecise
expression) is indicated by the standard error.

The p-value close to zero implies that the intercept of the underlying
population from which your sample was drawn is significantly different from
zero with a probability that approaches certainty (One minus p2e-16).
Remember that your data is assumed to be a random sample drawn from an
underlying, larger population. Thus, the sample can never PERFECTLY
represent the underlying population (only the underlying population itself
can). However, the regression model gives you an estimate for what the
data-generating process in the underlying population was (i.e., it gives you
probability distributions for the true coefficients of the population,
assuming that the assumptions for OLS regression are met). 

So, given the observed mean in your sample (i.e., your data), the
probability that the true mean of the intercept in the underlying population
is zero approaches zero. Another way to look at this is that it would be
extremely unlikely (next to impossible) to draw a random sample from the
population that has a zero intercept.

By the OLS assumptions, the probability density for the true intercept in
the population will be distributed normally around the estimate for the
intercept, with the mean equal to the estimated intercept and standard
deviation equal to the standard error of the intercept.

Daniel

-
cuncta stricte discussurus
-
-Original Message-
From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On
Behalf Of John Paul Telthorst
Sent: Monday, December 21, 2009 1:13 AM
To: r-help@r-project.org
Subject: [R] Signif. codes

My question is about the Signif. codes and the p-value, specifically, the
output when I run

summary(nameofregression.lm)


So you get this little key:

Signif. codes:  0 *** 0.001 ** 0.01 * 0.05 . 0.1   1

And on a regression I ran, next to the intercept data, I get '***'

Coefficients:

 Estimate Std. Error t value Pr(|t|)

 (Intercept)  7.956520.59993  13.262   2e-16 ***

 day.f2  -0.043480.84843  -0.0510.959

 day.f3  -0.130430.84843  -0.1540.878

 day.f4  -0.217390.84843  -0.2560.798

 day.f5   0.021740.84843   0.0260.980

 day.f6  -0.152170.84843  -0.1790.858

 day.f7   0.149860.84390   0.1780.859


Does this mean that these numbers have a 0% chance of being wrong?  Is there
a way to change this to the .05 level of significance?

Thanks,
John

[[alternative HTML version deleted]]

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


[R] [R-pkgs] new version of randtoolbox

2009-12-21 Thread Christophe Dutang
Dear useRs,

We are happy to announce a new version of the randtoolbox* package  
(version 1.09) on CRAN. The package is dedicated to Random Number  
Generation and in a less exhaustive way to RNG tests. The package is  
source-controlled at r-forge as part of the Rmetrics project 
http://r-forge.r-project.org/projects/rmetrics/ 
  .

We invite you to take a look at the NEWS section to know the latest  
development http://cran.r-project.org/web/packages/randtoolbox/NEWS .


Christophe Dutang and Petr Savicky


* for a license issue, the package has been splitted into 2 packages:  
randtoolbox and rngWELL.

--
Christophe Dutang
Ph.D. student at ISFA, Lyon, France
website: http://dutangc.free.fr







[[alternative HTML version deleted]]

___
R-packages mailing list
r-packa...@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-packages

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

2009-12-21 Thread baptiste auguie
Wow!

system.time({
all = blockparts(rep(9,8),17)
print( dim(all[,all[1,]!=0])[2] ) # remove leading 0s
})

## 229713
   user  system elapsed
  0.160   0.068   0.228

In some ways I think this is close to Hadley's suggestion, though I
didn't know how to implement it.

Thanks a lot to everybody who participated, I have learned interesting
things from a seemingly innocuous question.

Best regards,

baptiste


2009/12/21 Robin Hankin rk...@cam.ac.uk:
 Hi

 library(partitions)
 jj - blockparts(rep(9,8),17)
 dim(jj)

 gives 318648


 HTH

 rksh



 baptiste auguie wrote:

 Dear list,

 In a little numbers game, I've hit a performance snag and I'm not sure
 how to code this in C.

 The game is the following: how many 8-digit numbers have the sum of
 their digits equal to 17?
 The brute-force answer could be:

 maxi - 9 # digits from 0 to 9
 N - 5 # 8 is too large
 test - 17 # for example's sake

 sum(rowSums(do.call(expand.grid, c(list(1:maxi), rep(list(0:maxi),
 N-1 == test)
 ## 3675

 Now, if I make N = 8, R stalls for some time and finally gives up with:
 Error: cannot allocate vector of size 343.3 Mb

 I thought I could get around this using Reduce() to recursively apply
 rowSum to intermediate results, but it doesn't seem to help,


 a=list(1:maxi)
 b=rep(list(0:maxi), N-1)

 foo - function(a, b, fun=sum, ...){
  switch(fun,
         'sum' =  rowSums(do.call(expand.grid, c(a, b))),
         'mean' =  rowMeans(do.call(expand.grid, c(a, b))),
         apply(do.call(expand.grid, c(a, b)), 1, fun, ...)) # generic case
 }

 sum(Reduce(foo, list(b), init=a) == test)
 ## 3675 # OK

 Same problem with N=8.

 Now, if N was fixed I could write a little C code to do this
 calculation term-by-term, something along those lines,

 test = 0;

 for (i1=1, i1=9, i1++) {
  for (i2=0, i2=9, i2++) {

  [... other nested loops ]

  test = test + (i1 + i2 + [...] == 17);

  } [...]
 }

 but here the number of for loops, N, should remain a variable.

 In despair I coded this in R as a wicked eval(parse()) construct, and
 it does produce the expected result after an awfully long time.

 makeNestedLoops - function(N=3){

  startLoop - function(ii, start=1, end=9){
    paste(for (i, ii,  in seq(,start,, ,end,)) {\n, sep=)
  }

  first - startLoop(1)
  inner.start - lapply(seq(2, N), startLoop, start=0)
  calculation - paste(test - test + (, paste(i, seq(1, N),
 sep=, collapse=+), ==17 )\n)
  end - replicate(N, }\n)
  code.to.run - do.call(paste, c(list(first), inner.start, calculation,
 end))
  cat(code.to.run)
  invisible(code.to.run)
 }

 test - 0
 eval(parse(text = makeNestedLoops(8)) )
 ## 229713

 I hope I have missed a better way to do this in R. Otherwise, I
 believe what I'm after is some kind of C or C++ macro expansion,
 because the number of loops should not be hard coded.

 Thanks for any tips you may have!

 Best regards,

 baptiste

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



 --
 Robin K. S. Hankin
 Uncertainty Analyst
 University of Cambridge
 19 Silver Street
 Cambridge CB3 9EP
 01223-764877



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

2009-12-21 Thread Robin Hankin

Hello again everybody.

I fired off my reply before reading the correspondence about
the leading zeros.

You can also assume that there is at least one block
at the leading position, [so that position can take  0,1,2,...,8 additional
blocks] and distribute the remaining 16 blocks amongst all 8
places:

system.time(dim(blockparts(c(8,rep(9,7)),16)))
  user  system elapsed
 0.056   0.016   0.069


this is faster!  :-)

best wishes

rksh





baptiste auguie wrote:

Wow!

system.time({
all = blockparts(rep(9,8),17)
print( dim(all[,all[1,]!=0])[2] ) # remove leading 0s
})

## 229713
   user  system elapsed
  0.160   0.068   0.228

In some ways I think this is close to Hadley's suggestion, though I
didn't know how to implement it.

Thanks a lot to everybody who participated, I have learned interesting
things from a seemingly innocuous question.

Best regards,

baptiste


2009/12/21 Robin Hankin rk...@cam.ac.uk:
  

Hi

library(partitions)
jj - blockparts(rep(9,8),17)
dim(jj)

gives 318648


HTH

rksh



baptiste auguie wrote:


Dear list,

In a little numbers game, I've hit a performance snag and I'm not sure
how to code this in C.

The game is the following: how many 8-digit numbers have the sum of
their digits equal to 17?
The brute-force answer could be:

maxi - 9 # digits from 0 to 9
N - 5 # 8 is too large
test - 17 # for example's sake

sum(rowSums(do.call(expand.grid, c(list(1:maxi), rep(list(0:maxi),
N-1 == test)
## 3675

Now, if I make N = 8, R stalls for some time and finally gives up with:
Error: cannot allocate vector of size 343.3 Mb

I thought I could get around this using Reduce() to recursively apply
rowSum to intermediate results, but it doesn't seem to help,


a=list(1:maxi)
b=rep(list(0:maxi), N-1)

foo - function(a, b, fun=sum, ...){
 switch(fun,
'sum' =  rowSums(do.call(expand.grid, c(a, b))),
'mean' =  rowMeans(do.call(expand.grid, c(a, b))),
apply(do.call(expand.grid, c(a, b)), 1, fun, ...)) # generic case
}

sum(Reduce(foo, list(b), init=a) == test)
## 3675 # OK

Same problem with N=8.

Now, if N was fixed I could write a little C code to do this
calculation term-by-term, something along those lines,

test = 0;

for (i1=1, i1=9, i1++) {
 for (i2=0, i2=9, i2++) {

 [... other nested loops ]

 test = test + (i1 + i2 + [...] == 17);

 } [...]
}

but here the number of for loops, N, should remain a variable.

In despair I coded this in R as a wicked eval(parse()) construct, and
it does produce the expected result after an awfully long time.

makeNestedLoops - function(N=3){

 startLoop - function(ii, start=1, end=9){
   paste(for (i, ii,  in seq(,start,, ,end,)) {\n, sep=)
 }

 first - startLoop(1)
 inner.start - lapply(seq(2, N), startLoop, start=0)
 calculation - paste(test - test + (, paste(i, seq(1, N),
sep=, collapse=+), ==17 )\n)
 end - replicate(N, }\n)
 code.to.run - do.call(paste, c(list(first), inner.start, calculation,
end))
 cat(code.to.run)
 invisible(code.to.run)
}

test - 0
eval(parse(text = makeNestedLoops(8)) )
## 229713

I hope I have missed a better way to do this in R. Otherwise, I
believe what I'm after is some kind of C or C++ macro expansion,
because the number of loops should not be hard coded.

Thanks for any tips you may have!

Best regards,

baptiste

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

  

--
Robin K. S. Hankin
Uncertainty Analyst
University of Cambridge
19 Silver Street
Cambridge CB3 9EP
01223-764877






--
Robin K. S. Hankin
Uncertainty Analyst
University of Cambridge
19 Silver Street
Cambridge CB3 9EP
01223-764877

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

2009-12-21 Thread Ted Harding
I wonder whether this answers Baptiste's question as asked.

1: An 8-digit number can have some digits equal to 0;
   see Baptiste's comment maxi - 9 # digits from 0 to 9

2: According to the man-page fror blockparts in partitions,
   all sets of a=(a1,...,an) satisfying Sum[ai] = n subject
   to 0  ai = yi are given in lexicographical order.

So it would seem that blockparts would not count 8-digit numbers
which have some zero digits.

One could presumably fake it by looping over the number of
non-zero digits, from 2 to 8 -- something like:

  all - 0
  for(i in (2:8)){
jj - blockparts(rep(9,8),17)
all - all + dim(jj)
  }

Or am I missing something?!
Ted.



On 21-Dec-09 07:57:32, Robin Hankin wrote:
 Hi
 library(partitions)
 jj - blockparts(rep(9,8),17)
 dim(jj)
 
 gives 318648
 
 HTH
 rksh
 
 
 
 baptiste auguie wrote:
 Dear list,

 In a little numbers game, I've hit a performance snag and I'm not sure
 how to code this in C.

 The game is the following: how many 8-digit numbers have the sum of
 their digits equal to 17?
 The brute-force answer could be:

 maxi - 9 # digits from 0 to 9
 N - 5 # 8 is too large
 test - 17 # for example's sake

 sum(rowSums(do.call(expand.grid, c(list(1:maxi), rep(list(0:maxi),
 N-1 == test)
 ## 3675

 Now, if I make N = 8, R stalls for some time and finally gives up
 with:
 Error: cannot allocate vector of size 343.3 Mb

 I thought I could get around this using Reduce() to recursively apply
 rowSum to intermediate results, but it doesn't seem to help,


 a=list(1:maxi)
 b=rep(list(0:maxi), N-1)

 foo - function(a, b, fun=sum, ...){
   switch(fun,
  'sum' =  rowSums(do.call(expand.grid, c(a, b))),
  'mean' =  rowMeans(do.call(expand.grid, c(a, b))),
  apply(do.call(expand.grid, c(a, b)), 1, fun, ...)) # generic
  case
 }

 sum(Reduce(foo, list(b), init=a) == test)
 ## 3675 # OK

 Same problem with N=8.

 Now, if N was fixed I could write a little C code to do this
 calculation term-by-term, something along those lines,

 test = 0;

 for (i1=1, i1=9, i1++) {
  for (i2=0, i2=9, i2++) {

  [... other nested loops ]

   test = test + (i1 + i2 + [...] == 17);

  } [...]
 }

 but here the number of for loops, N, should remain a variable.

 In despair I coded this in R as a wicked eval(parse()) construct, and
 it does produce the expected result after an awfully long time.

 makeNestedLoops - function(N=3){

   startLoop - function(ii, start=1, end=9){
 paste(for (i, ii,  in seq(,start,, ,end,)) {\n, sep=)
   }

   first - startLoop(1)
   inner.start - lapply(seq(2, N), startLoop, start=0)
   calculation - paste(test - test + (, paste(i, seq(1, N),
 sep=, collapse=+), ==17 )\n)
   end - replicate(N, }\n)
   code.to.run - do.call(paste, c(list(first), inner.start,
   calculation, end))
   cat(code.to.run)
   invisible(code.to.run)
 }

 test - 0
 eval(parse(text = makeNestedLoops(8)) )
 ## 229713

 I hope I have missed a better way to do this in R. Otherwise, I
 believe what I'm after is some kind of C or C++ macro expansion,
 because the number of loops should not be hard coded.

 Thanks for any tips you may have!

 Best regards,
 baptiste


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

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


Re: [R] expand.grid game

2009-12-21 Thread Ted Harding
OOPS!! See correction below!

On 21-Dec-09 08:45:13, Ted Harding wrote:
 I wonder whether this answers Baptiste's question as asked.
 
 1: An 8-digit number can have some digits equal to 0;
see Baptiste's comment maxi - 9 # digits from 0 to 9
 
 2: According to the man-page fror blockparts in partitions,
all sets of a=(a1,...,an) satisfying Sum[ai] = n subject
to 0  ai = yi are given in lexicographical order.
 
 So it would seem that blockparts would not count 8-digit numbers
 which have some zero digits.
 
 One could presumably fake it by looping over the number of
 non-zero digits, from 2 to 8 -- something like:
 
  all - 0
  for(i in (2:8)){
jj - blockparts(rep(9,8),17)
jj - blockparts(rep(9,i),17)
all - all + dim(jj)
  }
 
 Or am I missing something?!
 Ted.
 
 
 
 On 21-Dec-09 07:57:32, Robin Hankin wrote:
 Hi
 library(partitions)
 jj - blockparts(rep(9,8),17)
 dim(jj)
 
 gives 318648
 
 HTH
 rksh
 
 
 
 baptiste auguie wrote:
 Dear list,

 In a little numbers game, I've hit a performance snag and I'm not
 sure
 how to code this in C.

 The game is the following: how many 8-digit numbers have the sum of
 their digits equal to 17?
 The brute-force answer could be:

 maxi - 9 # digits from 0 to 9
 N - 5 # 8 is too large
 test - 17 # for example's sake

 sum(rowSums(do.call(expand.grid, c(list(1:maxi), rep(list(0:maxi),
 N-1 == test)
 ## 3675

 Now, if I make N = 8, R stalls for some time and finally gives up
 with:
 Error: cannot allocate vector of size 343.3 Mb

 I thought I could get around this using Reduce() to recursively apply
 rowSum to intermediate results, but it doesn't seem to help,


 a=list(1:maxi)
 b=rep(list(0:maxi), N-1)

 foo - function(a, b, fun=sum, ...){
   switch(fun,
  'sum' =  rowSums(do.call(expand.grid, c(a, b))),
  'mean' =  rowMeans(do.call(expand.grid, c(a, b))),
  apply(do.call(expand.grid, c(a, b)), 1, fun, ...)) # generic
  case
 }

 sum(Reduce(foo, list(b), init=a) == test)
 ## 3675 # OK

 Same problem with N=8.

 Now, if N was fixed I could write a little C code to do this
 calculation term-by-term, something along those lines,

 test = 0;

 for (i1=1, i1=9, i1++) {
  for (i2=0, i2=9, i2++) {

  [... other nested loops ]

   test = test + (i1 + i2 + [...] == 17);

  } [...]
 }

 but here the number of for loops, N, should remain a variable.

 In despair I coded this in R as a wicked eval(parse()) construct, and
 it does produce the expected result after an awfully long time.

 makeNestedLoops - function(N=3){

   startLoop - function(ii, start=1, end=9){
 paste(for (i, ii,  in seq(,start,, ,end,)) {\n, sep=)
   }

   first - startLoop(1)
   inner.start - lapply(seq(2, N), startLoop, start=0)
   calculation - paste(test - test + (, paste(i, seq(1, N),
 sep=, collapse=+), ==17 )\n)
   end - replicate(N, }\n)
   code.to.run - do.call(paste, c(list(first), inner.start,
   calculation, end))
   cat(code.to.run)
   invisible(code.to.run)
 }

 test - 0
 eval(parse(text = makeNestedLoops(8)) )
 ## 229713

 I hope I have missed a better way to do this in R. Otherwise, I
 believe what I'm after is some kind of C or C++ macro expansion,
 because the number of loops should not be hard coded.

 Thanks for any tips you may have!

 Best regards,
 baptiste
 
 
 E-Mail: (Ted Harding) ted.hard...@manchester.ac.uk
 Fax-to-email: +44 (0)870 094 0861
 Date: 21-Dec-09   Time: 08:45:09
 -- XFMail --
 
 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide
 http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.


E-Mail: (Ted Harding) ted.hard...@manchester.ac.uk
Fax-to-email: +44 (0)870 094 0861
Date: 21-Dec-09   Time: 08:49:59
-- XFMail --

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


Re: [R] expand.grid game

2009-12-21 Thread Robin Hankin

Hi Ted.

you've found a bug in the documentation for blockparts().
It should read 0 = ai = yi.  I'll fix it before the next
major release (which will include sampling without replacement from
a multiset, Insha'Allah).

Best wishes

rksh


(Ted Harding) wrote:

I wonder whether this answers Baptiste's question as asked.

1: An 8-digit number can have some digits equal to 0;
   see Baptiste's comment maxi - 9 # digits from 0 to 9

2: According to the man-page fror blockparts in partitions,
   all sets of a=(a1,...,an) satisfying Sum[ai] = n subject
   to 0  ai = yi are given in lexicographical order.

So it would seem that blockparts would not count 8-digit numbers
which have some zero digits.

One could presumably fake it by looping over the number of
non-zero digits, from 2 to 8 -- something like:

  all - 0
  for(i in (2:8)){
jj - blockparts(rep(9,8),17)
all - all + dim(jj)
  }

Or am I missing something?!
Ted.



On 21-Dec-09 07:57:32, Robin Hankin wrote:
  

Hi
library(partitions)
jj - blockparts(rep(9,8),17)
dim(jj)

gives 318648

HTH
rksh



baptiste auguie wrote:


Dear list,

In a little numbers game, I've hit a performance snag and I'm not sure
how to code this in C.

The game is the following: how many 8-digit numbers have the sum of
their digits equal to 17?
The brute-force answer could be:

maxi - 9 # digits from 0 to 9
N - 5 # 8 is too large
test - 17 # for example's sake

sum(rowSums(do.call(expand.grid, c(list(1:maxi), rep(list(0:maxi),
N-1 == test)
## 3675

Now, if I make N = 8, R stalls for some time and finally gives up
with:
Error: cannot allocate vector of size 343.3 Mb

I thought I could get around this using Reduce() to recursively apply
rowSum to intermediate results, but it doesn't seem to help,


a=list(1:maxi)
b=rep(list(0:maxi), N-1)

foo - function(a, b, fun=sum, ...){
  switch(fun,
 'sum' =  rowSums(do.call(expand.grid, c(a, b))),
 'mean' =  rowMeans(do.call(expand.grid, c(a, b))),
 apply(do.call(expand.grid, c(a, b)), 1, fun, ...)) # generic
 case
}

sum(Reduce(foo, list(b), init=a) == test)
## 3675 # OK

Same problem with N=8.

Now, if N was fixed I could write a little C code to do this
calculation term-by-term, something along those lines,

test = 0;

for (i1=1, i1=9, i1++) {
 for (i2=0, i2=9, i2++) {

 [... other nested loops ]

  test = test + (i1 + i2 + [...] == 17);

 } [...]
}

but here the number of for loops, N, should remain a variable.

In despair I coded this in R as a wicked eval(parse()) construct, and
it does produce the expected result after an awfully long time.

makeNestedLoops - function(N=3){

  startLoop - function(ii, start=1, end=9){
paste(for (i, ii,  in seq(,start,, ,end,)) {\n, sep=)
  }

  first - startLoop(1)
  inner.start - lapply(seq(2, N), startLoop, start=0)
  calculation - paste(test - test + (, paste(i, seq(1, N),
sep=, collapse=+), ==17 )\n)
  end - replicate(N, }\n)
  code.to.run - do.call(paste, c(list(first), inner.start,
  calculation, end))
  cat(code.to.run)
  invisible(code.to.run)
}

test - 0
eval(parse(text = makeNestedLoops(8)) )
## 229713

I hope I have missed a better way to do this in R. Otherwise, I
believe what I'm after is some kind of C or C++ macro expansion,
because the number of loops should not be hard coded.

Thanks for any tips you may have!

Best regards,
baptiste
  



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



--
Robin K. S. Hankin
Uncertainty Analyst
University of Cambridge
19 Silver Street
Cambridge CB3 9EP
01223-764877

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

2009-12-21 Thread Amit
Thanks very much it solved my problem.

cheers,
Amit

On Sun, Dec 20, 2009 at 7:56 PM, David Winsemius dwinsem...@comcast.net wrote:

 On Dec 20, 2009, at 1:35 PM, Amit wrote:

 Dear All,
 I am trying to plot polynomial regression line to a scatterplot. I did
 following so far:

 x=c(1:9335)
 y=read.table(gp.txt,header=T,sep=\t)
 length(y$PCC) # y$PCC has values between 1 to 0 in decreasing order

 [1] 9335

 plot(x,y$PCC,col=red) #scatterplot between x and y$PCC
 reg=lm(y$PCC~poly(x,6)) # calculating polynomial fit with degree 6
 abline(reg,col=blue)

 Warning message:
 In abline(reg, col = blue) :
  only using the first two of 7regression coefficients

 After the above warning a line is drawn in the graph parallel to the
 y-axis. But I was expecting a curve line through the scatterplot.
 Am I doing something wrong? Please help!

 abline is designed to draw lines of the form y=a+bx, ... hence the name.
 (And as documented on its help page for regression objects).

 An effective method would be with lines and predict:

  plot(cars, main=Stopping Distance versus Speed)
  lines(cars$speed, predict(lm(dist~poly(speed, 6) ,data=cars) ), col=red)


 Best
 Amit

 ___

 David Winsemius, MD
 Heritage Laboratories
 West Hartford, CT



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


Re: [R] Problems in installing MCMCglmm package

2009-12-21 Thread Uwe Ligges



Sunny Srivastava wrote:

Dear R-Helpers,
I am having troubles with installing with MCMCglmm package and I get the
following error with a package Matrix

Warning in library(pkg, character.only = TRUE, logical.return = TRUE,
lib.loc = lib.loc) :
  there is no package called 'Matrix'
Error: package 'Matrix' could not be loaded
Execution halted
ERROR: lazy loading failed for package 'MCMCglmm'

I tried installing the package Matrix - but it was unavailable.

I am not able to understand why am I encountering this error - Any help is
appreciated



Start with a recent version of R. If you install R-2.10.1, Matrix should 
be included. If the installation fails, you need to look for the error 
messages why it failed.


Uwe Ligges







Thx,
S.


R version 2.8.1 (2008-12-22)
x86_64-pc-linux-gnu

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

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

other attached packages:
[1] lattice_0.17-26 MASS_7.2-45

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

[[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] Reading multiple Input Files

2009-12-21 Thread Uwe Ligges

See the FAQs, particularly
How can I save the result of each iteration in a loop into a separate 
file? which applies for the other way round as well.


Uwe Ligges


Maithili Shiva wrote:

Dear R helpers,
 
Suppose I am dealing with no of interest rates at a time and the no of interest rates I am selecting for my analysis is random i.e. it can be 2, can be 10 or even higher. The R-code I had written (with the guidance of R helpers obviously and I am really grateful to all of you) as of now is sort of hard coding when it comes to reading interest rates as an input e.g.
 
## INPUT
 
rate_1   = read.csv('rate1_range.csv')

rate_2   = read.csv('rate2_range.csv')
rate_3   = read.csv('rate3_range.csv')
rate_4   = read.csv('rate4_range.csv')
 
prob_1   = read.csv('rate1_probs.csv')

prob_2   = read.csv('rate2_probs.csv')
prob_3   = read.csv('rate3_probs.csv')
prob_4   = read.csv('rate4_probs.csv')

However, since I am not sure how many interest rates I will be dealing with to 
begin with, I have tried to call these inputs using a loop as follows.
 
In my R working directory, following files are there which are to be read as input..
 
 
rate1_range.csv

rate2_range.csv
rate3_range.csv
rate4_range.csv
 
rate1_probs.csv

rate2_probs.csv
rate3_probs.csv
rate4_probs.csv
 
My R Code
 
# ___
 
n = no_of_Interest_Rates  # This 'n' will be suppllied separately can be anything.
 
n= 4   # As mentioned, this input will be added seperately.
 
for (i in 1:n)
 
 {

 rate_[i]= read.csv('rate[i]_range.csv')
 prob_[i]   = read.csv('rate[i]_probs.csv')
 }
 
# End of code.
 
However when I excute this code (here, n = 4), I get following error.
 
Error in file(file, r) : cannot open the connection

In addition: Warning message:
In file(file, r) :
  cannot open file 'rate[i]_range.csv': No such file or directory
 
Obviously as usual I have written some stupid code.
 
Please guide
 
Regards
 
Maithili
 
 
 



  The INTERNET now has a personality. YOURS! See your Yahoo! Homepage. 
	[[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] Reading multiple Input Files

2009-12-21 Thread bergarog
Hi

I'm not sure if I understood your problem correctly..
Perhaps you are looking for something like this?

Best regards,
Roger


Result - c()
yourPath - c:\\temp
filesInDir - dir(yourPath)
for(file in filesInDir){
fileInfo - paste(yourPath,file,sep=\\)
tmp - read.csv(fileInfo)
# assign(file,tmp)
# Result - c(Result,tmp)
}

[[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] how can generate h(u)=min{a,log(u)} for 0u1 in R ?

2009-12-21 Thread khazaei
Hello,

How can generate a sample from h(u)=min{a,log(u)} for 0u1   in R,please?

thank you
khazaei

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

2009-12-21 Thread Matthew Dowle
or if Dataset is a data.table :

 Dataset = data.table(Dataset)
 Dataset[,abs(ratio-median(ratio)),by=LEAID]
 LEAIDV1
[1,]  6307 0.0911905
[2,]  6307 0.0488095
[3,]  6307 0.0488095
[4,]  6307 0.1088095
[5,]  8300 0.2021538
[6,]  8300 0.000
[7,]  8300 0.060
rather than :
 Dataset$abs - with(Dataset, ave(ratio, LEAID, 
 FUN=function(x)abs(x-median(x

This is less code and more natural (to me anyway) e.g. it doesn't require 
use of function() or ave(). data.table knows that if the j expression 
returns a vector it should silently repeat the groups to match the length of 
the j result (which it is doing here).   If the j expression returns a 
scalar you would just get 2 rows in this example.  Note that the 'by' 
expression must evaluation to integer, or a list of integer vectors,  so in 
this case LEAID must either be integer already or coerced to integer using 
by=as.integer(LEAID).

To give the aggregate expression a name, just wrap with the DT function. 
This is also how to return multiple aggregate functions from each subset 
(some may return vectors, others may return vectors) by listing them inside 
DT() :

 Dataset[,DT(ratio,scaled=abs(ratio-median(ratio)),sum=sum(ratio)),by=LEAID]
 LEAID ratioscaled  sum
[1,]  6307 0.720 0.0911905 3.262381
[2,]  6307 0.7623810 0.0488095 3.262381
[3,]  6307 0.860 0.0488095 3.262381
[4,]  6307 0.920 0.1088095 3.262381
[5,]  8300 0.5678462 0.2021538 2.167846
[6,]  8300 0.770 0.000 2.167846
[7,]  8300 0.830 0.060 2.167846


William Dunlap wdun...@tibco.com wrote in message 
news:77eb52c6dd32ba4d87471dcd70c8d7000243c...@na-pa-vbe03.na.tibco.com...
 -Original Message-
 From: r-help-boun...@r-project.org
 [mailto:r-help-boun...@r-project.org] On Behalf Of L.A.
 Sent: Saturday, December 12, 2009 12:39 PM
 To: r-help@r-project.org
 Subject: Re: [R] by function ??



 Thanks for all the help, They all worked, But I'm stuck again.
 I've tried searching, but I not sure how to word my search as
 nothing came
 up.
 Here is my new hurdle, my data has 7 abservations and my
 results have 2
 answers:


 Here is my data

  LEAID ratio
 3 6307 0.720
 1 6307 0.7623810
 2 6307 0.860
 4 6307 0.920
 5 8300 0.5678462
 7 8300 0.770
 6 8300 0.830


  median-summaryBy(ratio ~ LEAID, data = Dataset, FUN = median)

  print(median)
   LEAID   ratio.median
 1 63070.8111905
 2 83000.770

 Now what I want is a way to compute
 abs(ratio- median)by LEAID for each observation to produce
 something like
 this

 LEAID ratio  abs
 3 6307 0.720 .0912
 1 6307 0.7623810 .0488
 2 6307 0.860 .0488
 4 6307 0.920 .1088
 5 8300 0.5678462 .2022
 7 8300 0.770 .
 6 8300 0.830 .0600

Try ave(), as in
Dataset$abs - with(Dataset, ave(ratio, LEAID, 
FUN=function(x)abs(x-median(x
Dataset
 LEAID ratio   abs
   3  6307 0.720 0.0911905
   1  6307 0.7623810 0.0488095
   2  6307 0.860 0.0488095
   4  6307 0.920 0.1088095
   5  8300 0.5678462 0.2021538
   7  8300 0.770 0.000
   6  8300 0.830 0.060

Bill Dunlap
Spotfire, TIBCO Software
wdunlap tibco.com


 Thanks,
 L.A.




 Ista Zahn wrote:
 
  Hi,
  I think you want
 
  by(TestData[ , RATIO], LEAID, median)
 
  -Ista
 
  On Tue, Dec 8, 2009 at 8:36 PM, L.A. ro...@millect.com wrote:
 
  I'm just learning and this is probably very simple, but I'm stuck.
  I'm trying to understand the by().
  This works.
  by(TestData, LEAID, summary)
 
  But, This doesn't.
 
  by(TestData, LEAID, median(RATIO))
 
 
  ERROR: could not find function FUN
 
  HELP!
  Thanks,
  LA
  --
  View this message in context:
  http://n4.nabble.com/by-function-tp955789p955789.html
  Sent from the R help mailing list archive at Nabble.com.
 
  __
  R-help@r-project.org mailing list
  https://stat.ethz.ch/mailman/listinfo/r-help
  PLEASE do read the posting guide
  http://www.R-project.org/posting-guide.html
  and provide commented, minimal, self-contained, reproducible code.
 
 
 
 
  -- 
  Ista Zahn
  Graduate student
  University of Rochester
  Department of Clinical and Social Psychology
  http://yourpsyche.org
 
  __
  R-help@r-project.org mailing list
  https://stat.ethz.ch/mailman/listinfo/r-help
  PLEASE do read the posting guide
  http://www.R-project.org/posting-guide.html
  and provide commented, minimal, self-contained, reproducible code.
 
 

 -- 
 View this message in context:
 http://n4.nabble.com/by-function-tp955789p962666.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, 

Re: [R] how can generate h(u)=min{a,log(u)} for 0u1 in R ?

2009-12-21 Thread Daniel Malter
Hi, see the example below. There must be a way to do this with apply or
tapply, but it always returned an error incorrect number of dimensions. At
least the code below works

n=100
a=rnorm(n)
u=runif(n)

f=function(x){min(x[,1],log(x[,2]))}

x=data.frame(a,u)

apply(x,1,f) #does not work

#this works
y=NULL
for(i in 1:n) y[i]=f(x[i,])

HTH,
Daniel

-
cuncta stricte discussurus
-
-Original Message-
From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On
Behalf Of khaz...@ceremade.dauphine.fr
Sent: Monday, December 21, 2009 5:17 AM
To: r-help@r-project.org
Subject: [R] how can generate h(u)=min{a,log(u)} for 0u1 in R ?

Hello,

How can generate a sample from h(u)=min{a,log(u)} for 0u1   in R,please?

thank you
khazaei

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

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


Re: [R] how can generate h(u)=min{a,log(u)} for 0u1 in R ?

2009-12-21 Thread Gabor Grothendieck
Use pmin like this:

 set.seed(123)
 pmin(-0.1, log(runif(25)))
 [1] -1.2462628 -0.2378700 -0.8940966 -0.1244104 -0.100 -3.0888020
 [7] -0.6384592 -0.1138195 -0.5952313 -0.7839153 -0.100 -0.7911258
[13] -0.3892415 -0.5575096 -2.2737578 -0.100 -1.4020672 -3.1686692
[19] -1.1149834 -0.100 -0.1170516 -0.3670090 -0.4454955 -0.100
[25] -0.4220431


On Mon, Dec 21, 2009 at 5:16 AM,  khaz...@ceremade.dauphine.fr wrote:
 Hello,

 How can generate a sample from h(u)=min{a,log(u)} for 0u1   in R,please?

 thank you
 khazaei

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

2009-12-21 Thread Duncan Murdoch
I've just posted a demo made with the rgl package to Youtube, visible 
here:  http://www.youtube.com/watch?v=prdZWQD7L5c


For future reference, here are the steps I used:

1.  Design a shape to be displayed, and then play with the animation 
functions to make it change over time.  Use play3d to do it live in R, 
movie3d to write the individual frames of the movie to .png files.


2.  Use the ffmpeg package (not an R package, a separate project at 
http://ffmpeg.org) to convert the .png files to an .mp4 file.  The 
individual frames totalled about 1 GB; the compressed movie is about 45 
MB. 

3.  Upload to Youtube.  I'm not a musician, so I had to use one of their 
licensed background tracks, I couldn't write my own.  I spent a lot of 
time picking one and then adjusting the timing of the video to 
compensate.  Each render/upload cycle at full resolution took about an 
hour and a half.  It's a lot faster to render in a smaller window with 
fewer frames per second, but it's still tedious.   It's easier to 
synchronize if you actually have a copy of the music locally, but 
Youtube doesn't let you download their music.  So the timing isn't 
perfect, but it's good enough for me!


Duncan Murdoch

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


Re: [R] Which hist cell each value falls in?

2009-12-21 Thread S Ellison
cut() might work if you want a character version...

set.seed(221)
x-rnorm(50)
y-rnorm(1)
xh-hist(x)
cut(y, breaks=xh$breaks)
#or
as.character(cut(y, breaks=xh$breaks))

#or for a 'level number' version (a bit like which())
as.numeric(cut(y, breaks=xh$breaks))


 Jim Lemon j...@bitwrit.com.au 18/12/2009 07:57:28 
On 12/18/2009 06:35 AM, Doug Hill wrote:
 Hi, all. I'm using hist() to obtain a vector of break values in an
interval.
 I then want to be able to identify which cell any value from another
vector
 falls in.

 E.g. applying


 breaks
  
   [1] -3.5 -3.0 -2.5 -2.0 -1.5 -1.0 -0.5  0.0  0.5  1.0  1.5  2.0

 to


 x
  
   [1] -3.74519666 -0.38183630 -1.22884247 -0.20971824 -0.30533939
-0.36271207
 [7] -2.27513499 -2.23688653 -1.98827155 -1.48666274 -1.26155084
-0.15234555
 [13] -0.09497287  0.34488440

 would give


 xcells
  
   [1] 1  8  6  8  8  8  4  4  5  6  6  8  8  9

 where:
x= breaks[1] -  cell 1
 breaks[1]  x= breaks[2] -  cell 2
 breaks[2]  x= breaks[3] -  cell 3, etc.


Hi Doug,
The function below does more or less what you want, except that the
bins 
are numbered from zero (meaning that a value is below the range of bins

as x[1] is) to length(breaks) (meaning that a value is above the range

of bins).

whichBin-function(x,breaks,right=TRUE) {
  lenx-length(x)
  # any leftovers must be out of range
  wb-rep(lenx,lenx)
  if(right) wb[x=breaks[1]]-0
  else wb[xbreaks[1]]-0
  for(bin in 1:(length(breaks)-1)) {
   if(right) wb[xbreaks[bin]  x=breaks[bin+1]]-bin
   else wb[x=breaks[bin]  xbreaks[bin+1]]-bin
  }
  return(wb)
}

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.

***
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] as.Date question

2009-12-21 Thread Felix Andrews
I don't know the details of why this is happening, but in any case it
is a good idea to round() your times if you want to convert them to
dates. Just as you would round() a numeric value to convert it to an
integer.

as.Date(round(zzz1, days))


2009/12/21 Jason Morgan jwm-r-h...@skepsi.net:
 Hello,

 On 2009.12.20 18:06:17, MAL wrote:
 All!

 This piece of code:

 zzz1 - as.POSIXct(1999-03-18, tz=CET)
 zzz2 - as.POSIXlt(1999-03-18, tz=CET)
 zzz1 == zzz2
 as.Date(zzz1)
 as.Date(zzz2)

 yields TRUE for zzz1==zzz2, but the two dates returned by as.Date are 
 different:

  as.Date(zzz1)
 [1] 1999-03-17
  as.Date(zzz2)
 [1] 1999-03-18

 I'm using R 2.10.0.

 Would be glad for any clarifications. Thanks!

 I don't know why as.Date() is giving different results, but if look at
 the value of the variables, they are equal:

 zzz1 - as.POSIXct(1999-03-18, tz=CET)
 zzz2 - as.POSIXlt(1999-03-18, tz=CET)
 zzz1 == zzz2
 [1] TRUE
 as.Date(zzz1)
 [1] 1999-03-17
 as.Date(zzz2)
 [1] 1999-03-18
 zzz1
 [1] 1999-03-18 CET
 zzz2
 [1] 1999-03-18 CET

 Maybe someone here can explain the behavior of as.Date().

 Cheers,
 ~Jason


 --
 Jason W. Morgan
 Graduate Student
 Department of Political Science
 *The Ohio State University*
 154 North Oval Mall
 Columbus, Ohio 43210

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




-- 
Felix Andrews / 安福立
Postdoctoral Fellow
Integrated Catchment Assessment and Management (iCAM) Centre
Fenner School of Environment and Society [Bldg 48a]
The Australian National University
Canberra ACT 0200 Australia
M: +61 410 400 963
T: + 61 2 6125 4670
E: felix.andr...@anu.edu.au
CRICOS Provider No. 00120C
-- 
http://www.neurofractal.org/felix/

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

2009-12-21 Thread Muhammad Rahiz

Thanks Barry for the clarification.

With regards to the following;

d2[[i]] - file[[i]] - mean

renamed to

d2[[i]] - f[[i]] - m

The object f contains the following so clearly f is subsettable

[[1]]
 V1
1 10
2 10
3 10

[[2]]
 V1
1 11
2 11
3 11

[[3]]
 V1
1 12
2 12
3 12

My plan is to subtract m from each subset of f and to store the output 
as each individual subsets. So,


output1 - f[[1]] - m
output2 - f[[2]] - m
output3 - f[[3]] - m

If I run the following to achieve the desired result, there is an error 
as written in the subject heading.


d2[[i]] - f[[i]] - m

If I run the following, the error is gone but I'm not getting the output for 
each individual file I require

d2 - f[[i]] - m

The issue is, how do I make d2 subsettable?


Thanks.

Muhammad


Muhammad Rahiz  |  Doctoral Student in Regional Climate Modeling

Climate Research Laboratory, School of Geography  the Environment  
Oxford University Centre for the Environment
South Parks Road, Oxford, OX1 3QY, United Kingdom 
Tel: +44 (0)1865-285194	 Mobile: +44 (0)7854-625974

Email: muhammad.ra...@ouce.ox.ac.uk






Barry Rowlingson wrote:

On Sun, Dec 20, 2009 at 7:40 PM, Muhammad Rahiz
muhammad.ra...@ouce.ox.ac.uk wrote:
  

Hi all,

How can I overcome the error object of type 'closure' not subsettable

I ran the following script
seq - paste(seq(1914, 1916, by=1), *.y, sep=.) # make sequence
c - 3 # total number of files
d2 - file # creates dummy file



 No it doesn't. It copies the object called 'file' into an object
called 'd2'. What's the object called 'file'? If you've not created
one already, its the 'file' function that R uses to read stuff from
files. So when you do:


  

d2[[i]] - file[[i]] - mean



 you are trying to subset from d2 (and from 'file'). If I do this:

  file[[2]]

 I get your error message:

Error in file[[2]] : object of type 'closure' is not subsettable

 So clearly you aren't doing what you think you're doing.

 Some hints:

1. Read a good introduction to R. You are making a number of
fundamental mistakes here.

2. Run each line separately and check what value you get back by printing it.

3. Don't give your objects the same name as R functions (you're using
'seq', 'file', and 'mean'). Although this may work, it will confuse
people later...

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] Object of type 'closure' not subsettable

2009-12-21 Thread Barry Rowlingson
On Mon, Dec 21, 2009 at 1:43 PM, Muhammad Rahiz
muhammad.ra...@ouce.ox.ac.uk wrote:
 Thanks Barry for the clarification.

 With regards to the following;

 d2[[i]] - file[[i]] - mean

 renamed to

 d2[[i]] - f[[i]] - m

 The object f contains the following so clearly f is subsettable

 [[1]]
  V1
 1 10
 2 10
 3 10

 [[2]]
  V1
 1 11
 2 11
 3 11

 [[3]]
  V1
 1 12
 2 12
 3 12

 My plan is to subtract m from each subset of f and to store the output as
 each individual subsets. So,

 output1 - f[[1]] - m
 output2 - f[[2]] - m
 output3 - f[[3]] - m

 If I run the following to achieve the desired result, there is an error as
 written in the subject heading.

 d2[[i]] - f[[i]] - m

 If I run the following, the error is gone but I'm not getting the output for
 each individual file I require

 d2 - f[[i]] - m

 The issue is, how do I make d2 subsettable?



 Well you haven't shown us this time how you initialised d2. Create it
as an empty list:

 d2 - list()

and then you can do:

  d2[[1]]=c(1,2,3)
  d2[[2]]=c(4,5,6)
  d2
[[1]]
[1] 1 2 3

[[2]]
[1] 4 5 6

 As I said, read one of the basic R documents linked on the
documentation section of the R web site, and play with lists and
vectors for a while.

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] Object of type 'closure' not subsettable

2009-12-21 Thread Petr PIKAL
Hi

You were instucted to 

  1. Read a good introduction to R. You are making a number of
  fundamental mistakes here.
 
  2. Run each line separately and check what value you get back by 
printing it.
 
  3. Don't give your objects the same name as R functions (you're using
  'seq', 'file', and 'mean'). Although this may work, it will confuse
  people later...

which you clearly did not do.

r-help-boun...@r-project.org napsal dne 21.12.2009 14:43:44:

 Thanks Barry for the clarification.
 
 With regards to the following;
 
 d2[[i]] - file[[i]] - mean
 
 renamed to
 
 d2[[i]] - f[[i]] - m

What is d2? What does

str(d2) 

tell about the object.

for everybody except you the error message is 

d2[[i]] - f[[i]] - m
Error: object 'f' not found

So what do you expect? Barry clearly explained that d2 is probably a 
function based on what you explained that you did.

d2-file
d2[[1]]
Error in d2[[1]] : object of type 'closure' is not subsettable

Besides of reading a tiny part of R intro docs especially about objects 
and how to manipulate them you could consult also apply family of 
functions (lapply, sapply, ...) and also ave which probably do what you 
want without twisting R to C programming.

ave(some.data, some.levels, FUN=function(x) x-mean(x))
shall do what you want

Regards
Petr


 
 The object f contains the following so clearly f is subsettable
 
 [[1]]
   V1
 1 10
 2 10
 3 10
 
 [[2]]
   V1
 1 11
 2 11
 3 11
 
 [[3]]
   V1
 1 12
 2 12
 3 12
 
 My plan is to subtract m from each subset of f and to store the output 
 as each individual subsets. So,
 
 output1 - f[[1]] - m
 output2 - f[[2]] - m
 output3 - f[[3]] - m
 
 If I run the following to achieve the desired result, there is an error 
 as written in the subject heading.
 
 d2[[i]] - f[[i]] - m
 
 If I run the following, the error is gone but I'm not getting the output 
for 
 each individual file I require
 
 d2 - f[[i]] - m
 
 The issue is, how do I make d2 subsettable?
 
 
 Thanks.
 
 Muhammad
 
 
 Muhammad Rahiz  |  Doctoral Student in Regional Climate Modeling  
 Climate Research Laboratory, School of Geography  the Environment 
 Oxford University Centre for the Environment
 South Parks Road, Oxford, OX1 3QY, United Kingdom 
 Tel: +44 (0)1865-285194Mobile: +44 (0)7854-625974
 Email: muhammad.ra...@ouce.ox.ac.uk
 
 
 
 
 
 
 Barry Rowlingson wrote:
  On Sun, Dec 20, 2009 at 7:40 PM, Muhammad Rahiz
  muhammad.ra...@ouce.ox.ac.uk wrote:
  
  Hi all,
 
  How can I overcome the error object of type 'closure' not 
subsettable
 
  I ran the following script
  seq - paste(seq(1914, 1916, by=1), *.y, sep=.) # make sequence
  c - 3 # total number of files
  d2 - file # creates dummy file
  
 
   No it doesn't. It copies the object called 'file' into an object
  called 'd2'. What's the object called 'file'? If you've not created
  one already, its the 'file' function that R uses to read stuff from
  files. So when you do:
 
 
  
  d2[[i]] - file[[i]] - mean
  
 
   you are trying to subset from d2 (and from 'file'). If I do this:
 
file[[2]]
 
   I get your error message:
 
  Error in file[[2]] : object of type 'closure' is not subsettable
 
   So clearly you aren't doing what you think you're doing.
 
   Some hints:
 
  1. Read a good introduction to R. You are making a number of
  fundamental mistakes here.
 
  2. Run each line separately and check what value you get back by 
printing it.
 
  3. Don't give your objects the same name as R functions (you're using
  'seq', 'file', and 'mean'). Although this may work, it will confuse
  people later...
 
  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.

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

2009-12-21 Thread Paul Smith
On Mon, Dec 21, 2009 at 12:42 PM, Duncan Murdoch murd...@stats.uwo.ca wrote:
 I've just posted a demo made with the rgl package to Youtube, visible here:
  http://www.youtube.com/watch?v=prdZWQD7L5c

 For future reference, here are the steps I used:

 1.  Design a shape to be displayed, and then play with the animation
 functions to make it change over time.  Use play3d to do it live in R,
 movie3d to write the individual frames of the movie to .png files.

 2.  Use the ffmpeg package (not an R package, a separate project at
 http://ffmpeg.org) to convert the .png files to an .mp4 file.  The
 individual frames totalled about 1 GB; the compressed movie is about 45 MB.
 3.  Upload to Youtube.  I'm not a musician, so I had to use one of their
 licensed background tracks, I couldn't write my own.  I spent a lot of time
 picking one and then adjusting the timing of the video to compensate.  Each
 render/upload cycle at full resolution took about an hour and a half.  It's
 a lot faster to render in a smaller window with fewer frames per second, but
 it's still tedious.   It's easier to synchronize if you actually have a copy
 of the music locally, but Youtube doesn't let you download their music.  So
 the timing isn't perfect, but it's good enough for me!

Very nice video, Duncan!

Paul

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Question About Repeat Random Sampling from a Data Frame

2009-12-21 Thread Adam Carr
Good Morning:

I've read many, many posts on the r-help system and I feel compelled to quickly 
admit that I am relatively new to R, I do have several reference books around 
me, but I cannot count myself among the fortunate who seem to strong 
programming intuition. 

I have a data set consisting of 1637 observations of five variables: tensile 
strength, yield strength, elongation, hardness and a character indicator with 
three levels: (Y)es, (N)o, and (F)ail.

My objective is to randomly sample various subsets from this data set and then 
evaluate these subsets using simple parameters among them tests for normality, 
shape and skewness. The data set is ordered by the character variable prior to 
sampling, and the samples are weighted to mirror representation in an overall, 
physical process.

I am sampling the data set using this code:

sample - dataset[sample(1:1637, 500, 
prob=c(rep(163.7/1637,513),rep(245.5/1637,197),rep(1227.8/1637,927)),replace = 
TRUE),]

What I would like to do is iterate this process to create many (say 500 or 
more) sampled sets of n=500 and then evaluate each set for the parameters of 
interest. I would actually be evaluating each variable within each subset for 
my characteristic of interest. I am familiar with sampling and saving single 
columns of data to do this sort of thing, but I am not sure how to accomplish 
this with a multiple-variable data set.

For example, I am currently iterating this using a clunky process:

mysamples-list()
for (i in 1:10){
mysamples[[i]] - dataset[ 
sample(1:1637,100,prob=c(rep(163.7/1637,513),rep(245.5/1637,197),rep(1227.8/1637,927)),replace
 = TRUE), ]
}

But this leaves me with the additional task of defining each mysample[i] 
iteration and converting it to a form on which I can apply a standard 
statistical test like mean() or skewness() to the variable columns within each 
subset. I have attempted to iteratively convert these lists using this code:

mat-matrix(nrow=100,ncol=5)
for (i in 1:length(mysamples))
{mat[i]-do.call('rbind',mysamples[i])}

but running the code generates the error message: number of items to replace is 
not a multiple of replacement length. I have tried unsuccessfully, by reading 
many, many helpful r-help emails on this error, to understand my probably 
obvious mistake. 

Based on the small amount that I think I know about R it seems to me that 
sampling the data frame and containing the samples in a list is likely a pretty 
inefficient way to do this task. Any help that any of you could provide to 
assist me in iteratively sampling the data frame, and storing the samples in a 
form on which I can apply other statistical tests would be greatly appreciated.

Thank you very much for taking the time to consider my questions.

Adam 


  
[[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] Question About Repeat Random Sampling from a Data Frame

2009-12-21 Thread Gustaf Rydevik
On Mon, Dec 21, 2009 at 4:12 PM, Adam Carr adamlc...@yahoo.com wrote:
 Good Morning:

 I've read many, many posts on the r-help system and I feel compelled to 
 quickly admit that I am relatively new to R, I do have several reference 
 books around me, but I cannot count myself among the fortunate who seem to 
 strong programming intuition.

 I have a data set consisting of 1637 observations of five variables: tensile 
 strength, yield strength, elongation, hardness and a character indicator with 
 three levels: (Y)es, (N)o, and (F)ail.

 My objective is to randomly sample various subsets from this data set and 
 then evaluate these subsets using simple parameters among them tests for 
 normality, shape and skewness. The data set is ordered by the character 
 variable prior to sampling, and the samples are weighted to mirror 
 representation in an overall, physical process.

 I am sampling the data set using this code:

 sample - dataset[sample(1:1637, 500, 
 prob=c(rep(163.7/1637,513),rep(245.5/1637,197),rep(1227.8/1637,927)),replace 
 = TRUE),]

 What I would like to do is iterate this process to create many (say 500 or 
 more) sampled sets of n=500 and then evaluate each set for the parameters of 
 interest. I would actually be evaluating each variable within each subset for 
 my characteristic of interest. I am familiar with sampling and saving single 
 columns of data to do this sort of thing, but I am not sure how to accomplish 
 this with a multiple-variable data set.

 For example, I am currently iterating this using a clunky process:

 mysamples-list()
 for (i in 1:10){
 mysamples[[i]] - dataset[ 
 sample(1:1637,100,prob=c(rep(163.7/1637,513),rep(245.5/1637,197),rep(1227.8/1637,927)),replace
  = TRUE), ]
 }

 But this leaves me with the additional task of defining each mysample[i] 
 iteration and converting it to a form on which I can apply a standard 
 statistical test like mean() or skewness() to the variable columns within 
 each subset. I have attempted to iteratively convert these lists using this 
 code:

 mat-matrix(nrow=100,ncol=5)
 for (i in 1:length(mysamples))
 {mat[i]-do.call('rbind',mysamples[i])}

 but running the code generates the error message: number of items to replace 
 is not a multiple of replacement length. I have tried unsuccessfully, by 
 reading many, many helpful r-help emails on this error, to understand my 
 probably obvious mistake.

 Based on the small amount that I think I know about R it seems to me that 
 sampling the data frame and containing the samples in a list is likely a 
 pretty inefficient way to do this task. Any help that any of you could 
 provide to assist me in iteratively sampling the data frame, and storing the 
 samples in a form on which I can apply other statistical tests would be 
 greatly appreciated.

 Thank you very much for taking the time to consider my questions.

 Adam



        [[alternative HTML version deleted]]

That's pretty much how I tend to do those things. what you seem to be
missing is the ?apply family:

mysamples.means-lapply(mysamples,function(x)mean(x[,1]))


Hope that gets you on your way. If you want more help, I'd suggest
including an example data set in your follow-up messages.

/Gustaf

-- 
Gustaf Rydevik, M.Sci.
tel: +46(0)703 051 451
address:Essingetorget 40,112 66 Stockholm, SE
skype:gustaf_rydevik

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

2009-12-21 Thread Markus Häge
Hi there,

I was looking for a Lorentz-distribution in R but I didn't find any
physical distribution. Is there s.th which I can use for fitting.

thanks

Markus

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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,Suggest me some methods to identify t raining set and test set!!!

2009-12-21 Thread bbslover

I want to split my whole dateset to training set and test set, building model
in training set, and validate model using test set. Now, How can I split my
dataset to them reasonally. Please give me a hand, It is better to give me
some R code.

and I see some ways like using SOM to project whole independents to
2-dimensions and find some to be training set and others are test set.  like
below. I also want to do this. and my date is in xls accessory. Please help
me.  and excel file is 218*47 matrix, 47 are indepents. I want to project it
to 2D and label the corresponding sample label like that picture below.

thank you!
http://n4.nabble.com/file/n976245/SOM%2Btraining%2Bset%2Band%2Btest%2Bset.jpg
SOM+training+set+and+test+set.jpg 
http://n4.nabble.com/file/n976245/matlab218x47.xls matlab218x47.xls 
-- 
View this message in context: 
http://n4.nabble.com/Help-Suggest-me-some-methods-to-identify-training-set-and-test-set-tp976245p976245.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] Question About Repeat Random Sampling from a Data Frame

2009-12-21 Thread David Winsemius


On Dec 21, 2009, at 10:12 AM, Adam Carr wrote:


Good Morning:

I've read many, many posts on the r-help system and I feel compelled  
to quickly admit that I am relatively new to R, I do have several  
reference books around me, but I cannot count myself among the  
fortunate who seem to strong programming intuition.


I have a data set consisting of 1637 observations of five variables:  
tensile strength, yield strength, elongation, hardness and a  
character indicator with three levels: (Y)es, (N)o, and (F)ail.


My objective is to randomly sample various subsets from this data  
set and then evaluate these subsets using simple parameters among  
them tests for normality, shape and skewness. The data set is  
ordered by the character variable prior to sampling, and the samples  
are weighted to mirror representation in an overall, physical process.


I am sampling the data set using this code:

sample - dataset[sample(1:1637, 500,  
prob 
= 
c 
(rep 
(163.7/1637,513),rep(245.5/1637,197),rep(1227.8/1637,927)),replace =  
TRUE),]


What I would like to do is iterate this process to create many (say  
500 or more) sampled sets of n=500 and then evaluate each set for  
the parameters of interest. I would actually be evaluating each  
variable within each subset for my characteristic of interest. I am  
familiar with sampling and saving single columns of data to do this  
sort of thing, but I am not sure how to accomplish this with a  
multiple-variable data set.


For example, I am currently iterating this using a clunky process:

mysamples-list()
for (i in 1:10){
mysamples[[i]] -  
dataset 
[ sample 
(1 
: 
1637,100 
,prob 
= 
c 
(rep 
(163.7/1637,513),rep(245.5/1637,197),rep(1227.8/1637,927)),replace =  
TRUE), ]

}



Using lists to store intermediate results is not considered clunky in  
R. (You might want to provide statistical justification for the  
otherwise puzzling sampling strategy.)


But this leaves me with the additional task of defining each  
mysample[i] iteration and converting it to a form on which I can  
apply a standard statistical test like mean() or skewness() to the  
variable columns within each subset. I have attempted to iteratively  
convert these lists using this code:


mat-matrix(nrow=100,ncol=5)
for (i in 1:length(mysamples))
{mat[i]-do.call('rbind',mysamples[i])}


It would help if you explained what you are attempting here in  
ordinary English. There are 10 elements in mysamples, each of which is  
a 100 x 5 dataframe, and mat is just one 100 x 5 matrix, which you  
seem to be referencing incorrectly, given the fact that it has two,  
rather than one, dimension. Furthermore, those dataframes may not be  
of a uniform class, since you said you had character variable. Do you  
really want these all in a character type matrix, which would be what  
is likely to happen given R's requirement that matrix element be of  
only one class? What you say above suggests not.




but running the code generates the error message: number of items to  
replace is not a multiple of replacement length.


Because of the way you are referencing the matrix, probably. If you  
wanted a 10 x 100 x 5 array, then create an array. In R, as far as I  
can tell anyway, matrices are necessarily of 2 dimensions. Tables and  
arrays can be of higher dimension.


I have tried unsuccessfully, by reading many, many helpful r-help  
emails on this error, to understand my probably obvious mistake.


Sorting out such problems is best done with smaller test objects. I  
was surprised to see that you thought it was necessary to convert  
dataframes to matrices in order to calculate descriptive statistics.  
Nothing could be farther from the truth. Furthermore, it for some  
other more valid reason you wanted a list of matrices, there is a  
perfectly good function that will convert a dataframe to a matrix,  
data.matrix(), remembering of course that if there is a single  
character variable in the dataframe, that the entire matrix will be of  
type character.


Based on the small amount that I think I know about R it seems to me  
that sampling the data frame and containing the samples in a list is  
likely a pretty inefficient way to do this task. Any help that any  
of you could provide to assist me in iteratively sampling the data  
frame, and storing the samples in a form on which I can apply other  
statistical tests would be greatly appreciated.


Thank you very much for taking the time to consider my questions.

--

David Winsemius, MD
Heritage Laboratories
West Hartford, CT

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


Re: [R] Help,Suggest me some methods to identify tr aining set and test set!!!

2009-12-21 Thread milton ruser
 Not ellegant.. but...

MyDF-data.frame(cbind(x=runif(10), y=rnorm(10)))
TrainingSize=5
TrainingSize_list-sample(1:nrow(MyDF))[1:TrainingSize]
TrainingSize_list
MyDF.training-MyDF[(1:nrow(MyDF) %in% TrainingSize_list),]
 MyDF.training

 MyDF.test-MyDF[ ! (1:nrow(MyDF) %in% TrainingSize_list),]
 MyDF.test

bests

milton
On Mon, Dec 21, 2009 at 9:09 AM, bbslover dlu...@yeah.net wrote:


 I want to split my whole dateset to training set and test set, building
 model
 in training set, and validate model using test set. Now, How can I split my
 dataset to them reasonally. Please give me a hand, It is better to give me
 some R code.

 and I see some ways like using SOM to project whole independents to
 2-dimensions and find some to be training set and others are test set.
  like
 below. I also want to do this. and my date is in xls accessory. Please help
 me.  and excel file is 218*47 matrix, 47 are indepents. I want to project
 it
 to 2D and label the corresponding sample label like that picture below.

 thank you!

 http://n4.nabble.com/file/n976245/SOM%2Btraining%2Bset%2Band%2Btest%2Bset.jpg
 SOM+training+set+and+test+set.jpg
 http://n4.nabble.com/file/n976245/matlab218x47.xls matlab218x47.xls
 --
 View this message in context:
 http://n4.nabble.com/Help-Suggest-me-some-methods-to-identify-training-set-and-test-set-tp976245p976245.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.htmlhttp://www.r-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.


[[alternative HTML version deleted]]

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


Re: [R] Help,Suggest me some methods to identify tr aining set and test set!!!

2009-12-21 Thread Steve Lianoglou
Hi,

On Mon, Dec 21, 2009 at 9:09 AM, bbslover dlu...@yeah.net wrote:

 I want to split my whole dateset to training set and test set, building model
 in training set, and validate model using test set. Now, How can I split my
 dataset to them reasonally. Please give me a hand, It is better to give me
 some R code.

 and I see some ways like using SOM to project whole independents to
 2-dimensions and find some to be training set and others are test set.  like
 below. I also want to do this. and my date is in xls accessory. Please help
 me.  and excel file is 218*47 matrix, 47 are indepents. I want to project it
 to 2D and label the corresponding sample label like that picture below.

I noticed Max already pointed you to the caret package.

Load the library and look at the help for the createFolds function, eg:

library(caret)
?createFolds

-steve

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

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


[R] Maximum spacing method

2009-12-21 Thread mxm.margarida

Hi!

I'm trying to compare maximum likelihood estimator with maximum spacing
estimator (in Generalized extreme value distribution). My problem is the
following: i know how to determinate maximum likelihood estimator on R, but
i dont find a way to do the maximum spacing estimator...:-(
Any help would be great:-)
-- 
View this message in context: 
http://n4.nabble.com/Maximum-spacing-method-tp976335p976335.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] Suppressing certain debugging output

2009-12-21 Thread Stuart Andrews
keywords: debug, do.call, debugging in, suppress, arguments, list,  
screen, console, output


Hi,

I would like to control the output to the console while debugging  
functions that are called by do.call( FCN, ARGUMENTS )  when the  
arguments are quite large.  Is there a simple way to suppress (or  
compress) this output?


Thanks,
- Stu


For example:

ttt = function(x) { length(x) };  debug(ttt);  do.call(ttt,  
list(x=rep(0,10)))
ttt = function(x) { length(x) };  debug(ttt);  do.call(ttt,  
list(x=rep(0,100)))
ttt = function(x) { length(x) };  debug(ttt);  do.call(ttt,  
list(x=rep(0,1000)))



The first line prints the following to the console ...

debugging in: function(x) { length(x) }
(x = c(0, 0, 0, 0, 0, 0, 0, 0, 0, 0))
debug: {
length(x)
}
Browse[1]


The second prints ...

debugging in: function(x) { length(x) }
(x = c(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0))
debug: {
length(x)
}
Browse[1]


Etc.
Etc.

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

2009-12-21 Thread Albert-Jan Roskam
Hi,

I've just been browsing for IDEs for R, see e.g. 
http://www.linuxlinks.com/article/20080413133953606/R.html

It's probably highly subjective, but which free IDE is the best one around? For 
the Python language, I've always been using IDLE. I like the syntax 
highlighting and the syntax suggestions the user gets while typing a function 
name. Ideally, the IDE should run on any platform.

Thanks!

Albert-Jan

Cheers!!

Albert-Jan



~~

In the face of ambiguity, refuse the temptation to guess.

~~


  
[[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] Closing files after using write

2009-12-21 Thread Nick Torenvliet
When I run the following code in a loop I get an error after about 125 times
saying too many open files...


if(inherits(atmpt, try-error)){
output - paste(yahooSymbol,\n,sep=)
write(output, file = data, append = TRUE, sep = )
} else {


I've tried various things to close the file after write opens it, and looked
through the RBase docs... but I can't find anything that succesfully closes
the file.

This is obviously trivial... any ideas

Nick

[[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] an IDE for R... JGR perhaps?

2009-12-21 Thread Gray Calhoun
Hi Albert-Jan,
  This question gets asked a lot, in both r-help and r-devel, so you
should search the mailing list archives.  The answers usually favor
Emacs (GNU or X) with ESS.
--Gray

On Mon, Dec 21, 2009 at 11:18 AM, Albert-Jan Roskam fo...@yahoo.com wrote:
 Hi,

 I've just been browsing for IDEs for R, see e.g. 
 http://www.linuxlinks.com/article/20080413133953606/R.html

 It's probably highly subjective, but which free IDE is the best one around? 
 For the Python language, I've always been using IDLE. I like the syntax 
 highlighting and the syntax suggestions the user gets while typing a function 
 name. Ideally, the IDE should run on any platform.

 Thanks!

 Albert-Jan

 Cheers!!

 Albert-Jan



 ~~

 In the face of ambiguity, refuse the temptation to guess.

 ~~



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




-- 
Gray Calhoun

Assistant Professor of Economics
Iowa State University

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


Re: [R] Suppressing certain debugging output

2009-12-21 Thread Prof Brian Ripley

On Mon, 21 Dec 2009, Stuart Andrews wrote:

keywords: debug, do.call, debugging in, suppress, arguments, list, screen, 
console, output


Hi,

I would like to control the output to the console while debugging functions 
that are called by do.call( FCN, ARGUMENTS )  when the arguments are quite 
large.  Is there a simple way to suppress (or compress) this output?


Yes.  From ?options

 ‘deparse.max.lines’: controls the number of lines used when
  deparsing in ‘traceback’, ‘browser’, and upon entry to a
  function whose debugging flag is set.  Initially unset, and
  only used if set to a positive integer.



Thanks,
- Stu


For example:

ttt = function(x) { length(x) };  debug(ttt);  do.call(ttt, 
list(x=rep(0,10)))
ttt = function(x) { length(x) };  debug(ttt);  do.call(ttt, 
list(x=rep(0,100)))
ttt = function(x) { length(x) };  debug(ttt);  do.call(ttt, 
list(x=rep(0,1000)))



The first line prints the following to the console ...

debugging in: function(x) { length(x) }
(x = c(0, 0, 0, 0, 0, 0, 0, 0, 0, 0))
debug: {
  length(x)
}
Browse[1]


The second prints ...

debugging in: function(x) { length(x) }
(x = c(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0))
debug: {
  length(x)
}
Browse[1]


Etc.
Etc.

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


--
Brian D. Ripley,  rip...@stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford, Tel:  +44 1865 272861 (self)
1 South Parks Road, +44 1865 272866 (PA)
Oxford OX1 3TG, UKFax:  +44 1865 272595__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Closing files after using write

2009-12-21 Thread Nick Torenvliet
That would work... except I've got a DBConnection I don't want to close and
open constantly

On Mon, Dec 21, 2009 at 12:28 PM, Henrique Dallazuanna www...@gmail.comwrote:

 Try:

 closeAllConnections()

 On Mon, Dec 21, 2009 at 3:22 PM, Nick Torenvliet
 nick.torenvl...@gmail.com wrote:
  When I run the following code in a loop I get an error after about 125
 times
  saying too many open files...
 
 
  if(inherits(atmpt, try-error)){
 output - paste(yahooSymbol,\n,sep=)
 write(output, file = data, append = TRUE, sep = )
  } else {
 
 
  I've tried various things to close the file after write opens it, and
 looked
  through the RBase docs... but I can't find anything that succesfully
 closes
  the file.
 
  This is obviously trivial... any ideas
 
  Nick
 
 [[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.
 



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


[[alternative HTML version deleted]]

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


Re: [R] Closing files after using write

2009-12-21 Thread Henrique Dallazuanna
Try:

closeAllConnections()

On Mon, Dec 21, 2009 at 3:22 PM, Nick Torenvliet
nick.torenvl...@gmail.com wrote:
 When I run the following code in a loop I get an error after about 125 times
 saying too many open files...


 if(inherits(atmpt, try-error)){
            output - paste(yahooSymbol,\n,sep=)
            write(output, file = data, append = TRUE, sep = )
 } else {


 I've tried various things to close the file after write opens it, and looked
 through the RBase docs... but I can't find anything that succesfully closes
 the file.

 This is obviously trivial... any ideas

 Nick

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




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

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


Re: [R] Help,Suggest me some methods to identify tr aining set and test set!!!

2009-12-21 Thread Max Kuhn
 I noticed Max already pointed you to the caret package.

 Load the library and look at the help for the createFolds function, eg:

 library(caret)
 ?createFolds

I think that the createDataPartition function in caret might work
better for you.

There are a number of other packages with similar functions.

Max

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Hello all, How can I get corss-validation MSE of SVM in e1071?

2009-12-21 Thread Max Kuhn
  The caret package is so good, I am learning it, but one problem is that 
 nearZeroVar function can be used to identify near zero–variance variables and 
 it only identify, how can I remove those variables that were identify, 
 because I have many zero- or near zero- ones, it is not realistic to removel 
 it by hand, can this function can identify and removel those ones 
 automatically?


newx - x[, -nearZeroVar(x), drop = FALSE]

should do it

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

2009-12-21 Thread Gray Calhoun
Hi Nick,
  I hope you're being a little disingenuous about how hard you looked

  Typing ?close will pull up the right help page.  I think you're
having trouble because you don't store the file object in a variable,
so there's no convenient way to refer to it when you need to close it
(or when you want to write to it...).  Do three different steps: 1)
open file. 2) write to file. 3) close file; and you should be fine.

You also don't need to open the file 125 times: open it before the loop.

--Gray

On Mon, Dec 21, 2009 at 11:22 AM, Nick Torenvliet
nick.torenvl...@gmail.com wrote:
 When I run the following code in a loop I get an error after about 125 times
 saying too many open files...


 if(inherits(atmpt, try-error)){
            output - paste(yahooSymbol,\n,sep=)
            write(output, file = data, append = TRUE, sep = )
 } else {


 I've tried various things to close the file after write opens it, and looked
 through the RBase docs... but I can't find anything that succesfully closes
 the file.

 This is obviously trivial... any ideas

 Nick

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




-- 
Gray Calhoun

Assistant Professor of Economics
Iowa State University

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


Re: [R] DROP and KEEP statements in R

2009-12-21 Thread rmailbox
My preferred solution would be to use the select option of the subset function.

 data ( iris )

 names ( iris )
[1] Sepal.Length Sepal.Width  Petal.Length Petal.Width  Species   

# KEEP-like way  
 iris_subset_by_keep - subset ( iris, select = c( Sepal.Length, Species ) 
 )

# DROP-like way
 iris_subset_by_drop - subset ( iris, select = c ( -Sepal.Width, 
 -Petal.Length, -Petal.Width) )

 identical ( iris_subset_by_keep , iris_subset_by_drop )
[1] TRUE

 names ( iris_subset_by_keep )
[1] Sepal.Length Species 


p.s.
data NeweRa ( drop = SAS );
set Much_Better;


eRic



- Original message -
From: Wensui Liu liuwen...@gmail.com
To: sarjin...@yahoo.com
Cc: r-help@r-project.org
Date: Sat, 19 Dec 2009 20:19:51 -0500
Subject: Re: [R] DROP and KEEP statements in R

drop example.
 data(iris)
 summary(iris)
  Sepal.LengthSepal.Width Petal.LengthPetal.Width
 Min.   :4.300   Min.   :2.000   Min.   :1.000   Min.   :0.100
 1st Qu.:5.100   1st Qu.:2.800   1st Qu.:1.600   1st Qu.:0.300
 Median :5.800   Median :3.000   Median :4.350   Median :1.300
 Mean   :5.843   Mean   :3.057   Mean   :3.758   Mean   :1.199
 3rd Qu.:6.400   3rd Qu.:3.300   3rd Qu.:5.100   3rd Qu.:1.800
 Max.   :7.900   Max.   :4.400   Max.   :6.900   Max.   :2.500
   Species
 setosa:50
 versicolor:50
 virginica :50

 iris$Species - NULL
 summary(iris)
  Sepal.LengthSepal.Width Petal.LengthPetal.Width
 Min.   :4.300   Min.   :2.000   Min.   :1.000   Min.   :0.100
 1st Qu.:5.100   1st Qu.:2.800   1st Qu.:1.600   1st Qu.:0.300
 Median :5.800   Median :3.000   Median :4.350   Median :1.300
 Mean   :5.843   Mean   :3.057   Mean   :3.758   Mean   :1.199
 3rd Qu.:6.400   3rd Qu.:3.300   3rd Qu.:5.100   3rd Qu.:1.800
 Max.   :7.900   Max.   :4.400   Max.   :6.900   Max.   :2.500

On Sat, Dec 19, 2009 at 3:21 PM, sarjin...@yahoo.com wrote:

 What is equivalent to DROP or KEEP statements of SAS in R?

 --
 This message was sent on behalf of sarjin...@yahoo.com at
 openSubscriber.com
 http://www.opensubscriber.com/messages/r-help@r-project.org/topic.html

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




-- 
==
WenSui Liu
Blog   : statcompute.spaces.live.com
Tough Times Never Last. But Tough People Do.  - Robert Schuller
==

[[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] Question About Repeat Random Sampling from a Data Frame

2009-12-21 Thread Adam Carr
Good Afternoon Dr. Winsemius:

You ask some very good questions and make excellent points; my responses are 
below. I've tried to extract your questions and provide answers just to reduce 
the clutter.

1. You might want to provide statistical justification for the otherwise 
puzzling sampling strategy. 

I assume you mean my overall process of random sampling from a large data set. 
The data set is comprised of observations collected over four years. Although 
the basis for sampling would make a good four-frame Dilbert cartoon if it could 
be condensed enough, my answer begins with the unfortunate truth that there is 
a great divide between the technical and marketing groups at the business where 
I am employed. Many powerful marketing executives, some with technical 
backgrounds, feel that there is something fundamentally wrong with the 
manufacturing process because the data generated over the long term is not 
approximately normally distributed. My task was to examine this set of data, 
trying to keep the representation of Y, N and F approximately equal in the 
sample when compared to the large set, to determine if any subset exhibits the 
holy grail-like normal distribution characteristics. I don't feel that this is 
statistical justification, but it is the
 reason why I am doing this.

2. It would help if you explained what you are attempting here in ordinary 
English. There are 10 elements in mysamples, each of which is a 100 x 5 
dataframe, and mat is just one 100 x 5 matrix, which you seem to be referencing 
incorrectly, given the fact that it has two, rather than one, dimension. 
Furthermore, those dataframes may not be of a uniform class, since you said you 
had character variable. Do you really want these all in a character type 
matrix, which would be what is likely to happen given R's requirement that 
matrix element be of only one class? What you say above suggests not.

It seems from your response that I incorrectly assumed that a list is not the 
same as a data frame. I started down this path after reading the questions and 
answers to a similar problem where the r-help responder suggested a two step 
process and said that the list must be converted to another form in order to be 
available for analysis. 

And you are absolutely correct that I do not want each sample in a character 
type matrix. 

In plain English, I hope, I am simply trying to iterate the process of removing 
random samples from the large data set, and then saving these samples in a 
format that is available for simple analysis. For example, if I remove five 
hundred mysample sets, each of which is composed of a 100 x 5 sample of the 
large data set I am interested in determining the skewness, kurtosis, mean and 
standard deviation of each of the four numeric variables in each of the five 
hundred mysample sets.

3. Sorting out such problems is best done with smaller test objects. I was 
surprised to see...type character.

I agree. I began to do this with a small test data set but it was late last 
evening and I realized that I should ask for help before proceeding on what I 
thought might be incorrect assumptions. I clearly misunderstood that a list 
needed to be converted to a data frame in order to be available for analysis. 

Thank you for taking the time to respond. The discussion and suggestions are 
very helpful. 

Adam






From: David Winsemius dwinsem...@comcast.net

Cc: r-help@r-project.org
Sent: Mon, December 21, 2009 11:23:43 AM
Subject: Re: [R] Question About Repeat Random Sampling from a Data Frame


On Dec 21, 2009, at 10:12 AM, Adam Carr wrote:

 Good Morning:
 
 I've read many, many posts on the r-help system and I feel compelled to 
 quickly admit that I am relatively new to R, I do have several reference 
 books around me, but I cannot count myself among the fortunate who seem to 
 strong programming intuition.
 
 I have a data set consisting of 1637 observations of five variables: tensile 
 strength, yield strength, elongation, hardness and a character indicator with 
 three levels: (Y)es, (N)o, and (F)ail.
 
 My objective is to randomly sample various subsets from this data set and 
 then evaluate these subsets using simple parameters among them tests for 
 normality, shape and skewness. The data set is ordered by the character 
 variable prior to sampling, and the samples are weighted to mirror 
 representation in an overall, physical process.
 
 I am sampling the data set using this code:
 
 sample - dataset[sample(1:1637, 500, 
 prob=c(rep(163.7/1637,513),rep(245.5/1637,197),rep(1227.8/1637,927)),replace 
 = TRUE),]
 
 What I would like to do is iterate this process to create many (say 500 or 
 more) sampled sets of n=500 and then evaluate each set for the parameters of 
 interest. I would actually be evaluating each variable within each subset for 
 my characteristic of interest. I am familiar with sampling and saving single 
 columns of data to do this sort of 

Re: [R] Closing files after using write

2009-12-21 Thread Nick Torenvliet
Hey all, thanks for your input... assigning the connection and then using
unlink works just fine.


Thanks

On Mon, Dec 21, 2009 at 12:33 PM, Gray Calhoun gray.calh...@gmail.comwrote:

 Hi Nick,
  I hope you're being a little disingenuous about how hard you looked

  Typing ?close will pull up the right help page.  I think you're
 having trouble because you don't store the file object in a variable,
 so there's no convenient way to refer to it when you need to close it
 (or when you want to write to it...).  Do three different steps: 1)
 open file. 2) write to file. 3) close file; and you should be fine.

 You also don't need to open the file 125 times: open it before the loop.

 --Gray

 On Mon, Dec 21, 2009 at 11:22 AM, Nick Torenvliet
 nick.torenvl...@gmail.com wrote:
  When I run the following code in a loop I get an error after about 125
 times
  saying too many open files...
 
 
  if(inherits(atmpt, try-error)){
 output - paste(yahooSymbol,\n,sep=)
 write(output, file = data, append = TRUE, sep = )
  } else {
 
 
  I've tried various things to close the file after write opens it, and
 looked
  through the RBase docs... but I can't find anything that succesfully
 closes
  the file.
 
  This is obviously trivial... any ideas
 
  Nick
 
 [[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.
 



 --
 Gray Calhoun

 Assistant Professor of Economics
 Iowa State University


[[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] by function ??

2009-12-21 Thread L.A.


Well, I'm back again.
   Thanks for all the help. Besides working, it's helping me begin to
understand how these functions work.
I still have trouble reading or following the process of a function, which
brings my next question:

Dataset:

LEAID ratio
3 6307 0.720
1 6307 0.7623810
2 6307 0.860
4 6307 0.920
5 8300 0.5678462
7 8300 0.770
6 8300 0.830

Here I want to create confidence intervals around the median. My hang-up now
is how to do pbinom() by LEAID.

Here's my script.

Dataset$obs - with(Dataset, ave(ratio, LEAID, FUN=function(x)length(x)))
obs -by(Dataset[ , ratio], LEAID, length)
obsn -by(Dataset[ , obs], LEAID, FUN=function(x)1:max(x))

q - obsn
n - obs
pbinom -pbinom(q, n, .5)
pbinom - with(Dataset, by(obs, LEAID, FUN=function(x)pbinom(q, n, .5)))
x - pbinom
x.nolag=x[2:n] 
x.lag1=x[1:(obs-1)] 
my.new=cbind(x.nolag,x.lag1) 
x.fill= cbind(0,0) 
my.dat.fr=rbind(x.fill, my.new) 
my.dat.fr 
pr=1 - (2 * my.dat.fr)
cil=ifelse(pr = .95, Dataset[,ratio], 0)
cil
max=sort(cil)
LowerCI=round(max(max),digits=2)
LowerCI
cn=ifelse(pr = .95, Dataset[,ObsNumber], 0)
cmax=sort(cn)
c=max(cmax)
prb=ifelse(pr = .95, pr, 999)
con=sort(prb)
Confidence=min(con)
o= n -( c - 1)
ch=ifelse (q = o , Dataset[,Ratio], 0)
UpperCI=round(max(ch),digits=2)
UpperCI


I hope your not growing tired of my questions, I try reading all I can find,
but I often can't seem understand it until I can actually see it in process.
Thanks,
L.A. 
-- 
View this message in context: 
http://n4.nabble.com/by-function-tp955789p976414.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] mgcv with discrete covariates, interaction term

2009-12-21 Thread John Tillinghast
I'm trying to build a model with an overall smooth function for all  
the data, plus an additional smooth function for *some* of the data.
If ind is my indicator variable (0 for some x, 1 for others), I  
imagined I could write it like this:


gam.obj - gam(y ~ s(x) + ind*s(x))

but this does not work.

Does mgcv have a way of doing this? If not directly, is there a  
reasonable workaround?


__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Object of type 'closure' not subsettable - OK

2009-12-21 Thread Muhammad Rahiz

Thanks Petr, Barry  David for your useful comments.

Given

d2[[i]] - f[[i]] - m

The problem lies in how I define the object, d2[[i]], which I managed to 
resolve by


 d2 - list()

--
Muhammad Rahiz  |  Doctoral Student in Regional Climate Modeling

Climate Research Laboratory, School of Geography  the Environment  
Oxford University Centre for the Environment
South Parks Road, Oxford, OX1 3QY, United Kingdom 
Tel: +44 (0)1865-285194	 Mobile: +44 (0)7854-625974

Email: muhammad.ra...@ouce.ox.ac.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] physical distributions

2009-12-21 Thread Albyn Jones
Is the Lorentz distribution another name for the Cauchy distribution 
with density

  f(x) = \frac{1}{\pi} \frac{1}{1+x^2}

possibly with location and scale parameters?

albyn

On Mon, Dec 21, 2009 at 05:04:05PM +0100, Markus Häge wrote:
 Hi there,
 
 I was looking for a Lorentz-distribution in R but I didn't find any
 physical distribution. Is there s.th which I can use for fitting.
 
 thanks
 
 Markus
 
 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/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] qq plot for 3-parameter lognormal distribution

2009-12-21 Thread reezwan you
Hi:
Could you please guide me how to do a qq plot for a 3-parameter lognormal 
curve. Here is an example from VGAM package to fit lognormal curve. I need to 
do a qq plot to check the fit.
Thanks.

lambda = 4
y = lambda + rlnorm(n - 1000, mean=1.5, sd=exp(-0.8))
fit = vglm(y ~ 1, lognormal3, trace=TRUE)
Coef(fit)
summary(fit)

reez


  __
[[elided Yahoo spam]]

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


Re: [R] Reading multiple Input Files

2009-12-21 Thread Greg Hirson
The easiest way to do this is to use an lapply:

#in working directory
filelist - list.files()
ranges - lapply(filelist[grep(.*range\\.csv, filelist)], read.csv)
probs - lapply(filelist[grep(.*probs\\.csv, filelist)], read.csv)

Hope this helps,

Greg

On 12/20/09 10:24 PM, Maithili Shiva wrote:
 Dear R helpers,
   
 Suppose I am dealing with no of interest rates at a time and the no of 
 interest rates I am selecting for my analysis is random i.e. it can be 2, can 
 be 10 or even higher. The R-code I had written (with the guidance of R 
 helpers obviously and I am really grateful to all of you) as of now is sort 
 of hard coding when it comes to reading interest rates as an input e.g.
   
 ## INPUT
   
 rate_1   = read.csv('rate1_range.csv')
 rate_2   = read.csv('rate2_range.csv')
 rate_3   = read.csv('rate3_range.csv')
 rate_4   = read.csv('rate4_range.csv')
   
 prob_1   = read.csv('rate1_probs.csv')
 prob_2   = read.csv('rate2_probs.csv')
 prob_3   = read.csv('rate3_probs.csv')
 prob_4   = read.csv('rate4_probs.csv')

 However, since I am not sure how many interest rates I will be dealing with 
 to begin with, I have tried to call these inputs using a loop as follows.
   
 In my R working directory, following files are there which are to be read as 
 input..
   
   
 rate1_range.csv
 rate2_range.csv
 rate3_range.csv
 rate4_range.csv
   
 rate1_probs.csv
 rate2_probs.csv
 rate3_probs.csv
 rate4_probs.csv
   
 My R Code
   
 # ___
   
 n = no_of_Interest_Rates  # This 'n' will be suppllied separately  can 
 be anything.
   
 n= 4   # As mentioned, this input will be added seperately.
   
 for (i in 1:n)
   
   {
   rate_[i]= read.csv('rate[i]_range.csv')
   prob_[i]   = read.csv('rate[i]_probs.csv')
   }
   
 # End of code.
   
 However when I excute this code (here, n = 4), I get following error.
   
 Error in file(file, r) : cannot open the connection
 In addition: Warning message:
 In file(file, r) :
cannot open file 'rate[i]_range.csv': No such file or directory
   
 Obviously as usual I have written some stupid code.
   
 Please guide
   
 Regards
   
 Maithili
   
   
   


The INTERNET now has a personality. YOURS! See your Yahoo! Homepage.
   [[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.


-- 
Greg Hirson
ghir...@ucdavis.edu

Graduate Student
Agricultural and Environmental Chemistry

1106 Robert Mondavi Institute North
One Shields Avenue
Davis, CA 95616


[[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] How to put text outside an xyplot?

2009-12-21 Thread Paul Murrell

Hi


Marius Hofert wrote:

Dear R-users,

I have a plot created with the code below. I tried to put some text
to the right of the color key. I worked with grid.text and also
viewport(), but couldn't achieve this. I know this should be simple,
but I just couldn't figure out how to do it. How does this work?



The output in the panel is clipped to the panel.  You could get around 
that by pushing a viewport that turns the clipping off ...


pushViewport(viewport(clip=off))
grid.text(text to the right of the color key,
  1.2,0.5,rot=90)
popViewport()

... (though that way you lose access to the axis coordinates in the 
panel) or, because lattice generates a version of the panel viewport 
with clipping already turned off, draw the plot first then revisit the 
panel viewport with the clipping off ...


xyplot(data[,2]~data[,1],aspect=1,
panel=function(...){
panel.xyplot(...,type=n)
lpoints(data[,1],data[,2],pch=1,col=colorvec)
},
xlab=x,ylab=y,
legend=list(right=list(fun=draw.colorkey,args=list(key=list(col=mygray(10),at=1:10
)

trellis.focus(panel, 1, 1, clip.off=TRUE)
grid.text(text to the right of the color key,
  1.2, 0.5, rot=90)
trellis.unfocus()

... either way, there is still a possibility you won't see anything if 
that x=1.2 for the text is off the right-hand side of the page, so you 
might want to use a different coordinate system, or just draw the text 
relative to the right-hand side of the page rather than relative to the 
panel ...


xyplot(data[,2]~data[,1],aspect=1,
panel=function(...){
panel.xyplot(...,type=n)
lpoints(data[,1],data[,2],pch=1,col=colorvec)
},
	xlab=x,ylab=y, 
legend=list(right=list(fun=draw.colorkey,args=list(key=list(col=mygray(10),at=1:10

)

grid.text(text to the right of the color key,
  x=unit(1, npc) - unit(1, mm),
  just=bottom, rot=90)


Hope that helps.

Paul



Cheers,

Marius

library(lattice) library(grid) myvec=1:10 
data=data.frame(x=myvec,y=myvec) mygray=function(l)
gray(seq(0.2,0.8,length=l)) 
colors=level.colors(data[1:10,2],at=do.breaks(c(1,10),10),col.regions=mygray)
 colorvec=colors[1:10] 
#trellis.device(postscript,color=F,horizontal=F,onefile=F) 
xyplot(data[,2]~data[,1],aspect=1, panel=function(...){ 
panel.xyplot(...,type=n) 
lpoints(data[,1],data[,2],pch=1,col=colorvec) grid.text(text to the
right of the color key,1.2,0.5,rot=90)#does not work. }, 
xlab=x,ylab=y, 
legend=list(right=list(fun=draw.colorkey,args=list(key=list(col=mygray(10),at=1:10

 ) #dev.off()

__ R-help@r-project.org
mailing list https://stat.ethz.ch/mailman/listinfo/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 Paul Murrell
Department of Statistics
The University of Auckland
Private Bag 92019
Auckland
New Zealand
64 9 3737599 x85392
p...@stat.auckland.ac.nz
http://www.stat.auckland.ac.nz/~paul/

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

2009-12-21 Thread teo

Hi:
Could you please guide me how to plot weekly.t2. Below are my values and I
am only able to plot weekly t1 but failing to add a second line
representng weekly t2.
Thanks.



weekly.t1
 [1] 228.5204 326.1224 387.2449 415.4082 443.6735 454.6939 451.5306 475.1020
483.2653 483.0612 488.9362 488.3673 493.4694 515.3061 509.7959
[16] 501.0204 513.5714 516.5306 509.4898 516.4286 509.7959 498.6735 492.9592
473.6735 487.7551 482.9293
 weekly.t2
 [1]  71.57143  95.41667 110.11905 120.65476 124.3 130.11905 132.44048
137.38095 141.60714 135.35714 131.89873 126.7 125.47619
[14] 133.57143 134.34524 137.38095 134.04762 144.40476 148.27381 147.08333
146.42857 137.5 127.14286 127.20238 130.41667 127.67857


plot(c(1:26), weekly.t1, type=l, xlab=Week since treatment start, ylab=
Daily Treatment Dose, main=RIOTT doses, col=blue, axes = FALSE)
points(c(1:26), weekly.t2, type=l, col=red)
axis(side=1, at= c(1:26), as.character(c(1:26)))
axis(side=2, at = seq(from=70, to=700, by=10))
-- 
View this message in context: http://n4.nabble.com/plotting-tp976461p976461.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] Inter-observer reliability, nested categorical data

2009-12-21 Thread Julia

Hi, I am having problems working out what to do with my data, I have a series
of positions (26 for each limb!), nested within a limb (10 of them), nested
within a posture (30 of them). I then have 5 observers rating themso
far I have tried lmer and glm but R doesn't want to play. I'm not sure if
I'm trying to do the right thing, or if it's my data it doesn't like! Any
help with this problem would be much appreciated, just a point in the right
direction, or another study that has had to deal with this kind of data!

Thanks, 

Julia. 
-- 
View this message in context: 
http://n4.nabble.com/Inter-observer-reliability-nested-categorical-data-tp976392p976392.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] plotting

2009-12-21 Thread Stephan Kolassa

Hi teo,

try lines() instead of points().

HTH
Stephan

teo schrieb:

Hi:
Could you please guide me how to plot weekly.t2. Below are my values and I
am only able to plot weekly t1 but failing to add a second line
representng weekly t2.
Thanks.



weekly.t1
 [1] 228.5204 326.1224 387.2449 415.4082 443.6735 454.6939 451.5306 475.1020
483.2653 483.0612 488.9362 488.3673 493.4694 515.3061 509.7959
[16] 501.0204 513.5714 516.5306 509.4898 516.4286 509.7959 498.6735 492.9592
473.6735 487.7551 482.9293

weekly.t2

 [1]  71.57143  95.41667 110.11905 120.65476 124.3 130.11905 132.44048
137.38095 141.60714 135.35714 131.89873 126.7 125.47619
[14] 133.57143 134.34524 137.38095 134.04762 144.40476 148.27381 147.08333
146.42857 137.5 127.14286 127.20238 130.41667 127.67857


plot(c(1:26), weekly.t1, type=l, xlab=Week since treatment start, ylab=
Daily Treatment Dose, main=RIOTT doses, col=blue, axes = FALSE)
points(c(1:26), weekly.t2, type=l, col=red)
axis(side=1, at= c(1:26), as.character(c(1:26)))
axis(side=2, at = seq(from=70, to=700, by=10))


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

2009-12-21 Thread Rice, Terri
Hi,

I have the following table of odds ratios (or), lower limits(ll) and upper 
limits(ul), which I would like to plot as horizontal lines beginning at the 
lower limit, ending at the upper limits and with a dot at the odds ratio on an 
x-axis on a log10 scale. The y axis would be the study sites.

From what I can figure out, it looks like the plotCI function will do 
everything except give me an x-axis that is on a log10 scale and I can't get 
the logaxis function in the log10 package to work.

Study   or  ll  ul  order
UCSF0.7 0.550.891
MDA 0.760.710.932
UK  0.680.510.893
Mayo0.5 0.280.874

Thanks for any suggestions!

Terri



[[alternative HTML version deleted]]

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


Re: [R] Help,Suggest me some methods to identify t raining set and test set!!!

2009-12-21 Thread Frank E Harrell Jr
Ot should be noted that the performance of single split into training + 
test does not perform satisfactorily unless N  10,000 in many cases.


Frank

Max Kuhn wrote:

I noticed Max already pointed you to the caret package.

Load the library and look at the help for the createFolds function, eg:

library(caret)
?createFolds


I think that the createDataPartition function in caret might work
better for you.

There are a number of other packages with similar functions.

Max

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




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

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


Re: [R] Plot odds ratios on log scale

2009-12-21 Thread Marc Schwartz

On Dec 21, 2009, at 2:54 PM, Rice, Terri wrote:


Hi,

I have the following table of odds ratios (or), lower limits(ll) and  
upper limits(ul), which I would like to plot as horizontal lines  
beginning at the lower limit, ending at the upper limits and with a  
dot at the odds ratio on an x-axis on a log10 scale. The y axis  
would be the study sites.


From what I can figure out, it looks like the plotCI function will  
do everything except give me an x-axis that is on a log10 scale and  
I can't get the logaxis function in the log10 package to work.


Study   or  ll  ul  order
UCSF0.7 0.550.891
MDA 0.760.710.932
UK  0.680.510.893
Mayo0.5 0.280.874

Thanks for any suggestions!

Terri




Terri,

You can build your own easily, using plot() and then either arrows()  
or segments() to create the CI boundary lines. Just use 'log = x' in  
the call to plot to create the log scaled x axis.


Presuming that your data above are contained in a data frame called  
'DF':


 DF
  Study   or   ll   ul order
1  UCSF 0.70 0.55 0.89 1
2   MDA 0.76 0.71 0.93 2
3UK 0.68 0.51 0.89 3
4  Mayo 0.50 0.28 0.87 4


# Get the range of values for the x axis
xlim - with(DF, range(or - ll, or + ul))

 xlim
[1] 0.05 1.69

# Plot the points. set the range of the x axis and set to log10 scale
plot(order ~ or, data = DF, xlim = xlim, pch = 19, log = x)

# Add the CI's
with(DF, arrows(or - ll, order, or + ul, order, code = 3, angle = 90))

See ?arrows for help on the options for formatting the lines.

Alternatively, since it appears you are doing a meta-analysis of  
sorts, you might want to look at the metaplot() and forestplot()  
functions in Thomas Lumley's 'rmeta' package on CRAN.


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] StructTS standard errors

2009-12-21 Thread Giovanni Petris

Sorry for asking again, but I did not receive any answers - I know it's a busy 
time... ;-)

Shell I conclude that it is not possible to obtain standard errors from 
StructTS()
or its output?

Thanks,
Giovanni Petris

- Original Message -
From: Giovanni Petris gpet...@uark.edu
Date: Thursday, December 17, 2009 10:13 am
Subject: [R] StructTS standard errors

 
 Hello,
 
 Does anybody know if (and how) it is possible to obtain standard 
 errors of estimated variances from StructTS? (R 2.10.0).
 
 Thank you in advance,
 Giovanni
 
 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-
 guide.htmland 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] Maximum spacing method

2009-12-21 Thread David Scott

mxm.margarida wrote:

Hi!

I'm trying to compare maximum likelihood estimator with maximum spacing
estimator (in Generalized extreme value distribution). My problem is the
following: i know how to determinate maximum likelihood estimator on R, but
i dont find a way to do the maximum spacing estimator...:-(
Any help would be great:-)



You can see an implementation of mps for the normal inverse Gaussian in 
fBasics on R-Forge.


Have a look at the function .nigFit.mps in the file dist-nigFit.R

David Scott



--
_
David Scott Department of Statistics
The University of Auckland, PB 92019
Auckland 1142,NEW ZEALAND
Phone: +64 9 923 5055, or +64 9 373 7599 ext 85055
Email:  d.sc...@auckland.ac.nz,  Fax: +64 9 373 7018

Director of Consulting, Department of Statistics

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

2009-12-21 Thread David Winsemius

Alternate hypotheses:

HA1: There is no one in the readership who is familiar with the  
function (unlikely), or among those lacking knowledge of what package  
it might reside in (such as myself)  chose not to look up what you  
might have provided on the first posting: a self-contained example to  
work with.


HA2: Your question also suggests a certain statistical confusion. Do  
your really want standard errors of estimated variances? That would be  
somewhat unusual. Or do you want to take the square-roots of the  
variances to get standard errors of the estimated coefficients?



On Dec 21, 2009, at 4:26 PM, Giovanni Petris wrote:



Sorry for asking again, but I did not receive any answers - I know  
it's a busy time... ;-)


Shell I conclude that it is not possible to obtain standard errors  
from StructTS()

or its output?

Thanks,
Giovanni Petris

- Original Message -
From: Giovanni Petris gpet...@uark.edu
Date: Thursday, December 17, 2009 10:13 am
Subject: [R] StructTS standard errors



Hello,

Does anybody know if (and how) it is possible to obtain standard
errors of estimated variances from StructTS? (R 2.10.0).

Thank you in advance,
Giovanni

--
David Winsemius, MD
Heritage Laboratories
West Hartford, CT

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


Re: [R] Plot odds ratios on log scale

2009-12-21 Thread Ted Harding
On 21-Dec-09 21:19:27, Marc Schwartz wrote:
 On Dec 21, 2009, at 2:54 PM, Rice, Terri wrote:
 Hi,
 I have the following table of odds ratios (or), lower limits(ll) and  
 upper limits(ul), which I would like to plot as horizontal lines  
 beginning at the lower limit, ending at the upper limits and with a  
 dot at the odds ratio on an x-axis on a log10 scale. The y axis  
 would be the study sites.

 From what I can figure out, it looks like the plotCI function will  
 do everything except give me an x-axis that is on a log10 scale and  
 I can't get the logaxis function in the log10 package to work.

 Study   or  ll  ul  order
 UCSF0.7 0.550.891
 MDA 0.760.710.932
 UK  0.680.510.893
 Mayo0.5 0.280.874

 Thanks for any suggestions!

 Terri
 
 Terri,
 You can build your own easily, using plot() and then either arrows()  
 or segments() to create the CI boundary lines. Just use 'log = x' in 
 the call to plot to create the log scaled x axis.
 
 Presuming that your data above are contained in a data frame called  
 'DF':
 
   DF
Study   or   ll   ul order
 1  UCSF 0.70 0.55 0.89 1
 2   MDA 0.76 0.71 0.93 2
 3UK 0.68 0.51 0.89 3
 4  Mayo 0.50 0.28 0.87 4
 
 
# Get the range of values for the x axis
 xlim - with(DF, range(or - ll, or + ul))
 
   xlim
 [1] 0.05 1.69
 
# Plot the points. set the range of the x axis and set to log10 scale
 plot(order ~ or, data = DF, xlim = xlim, pch = 19, log = x)
 
# Add the CI's
 with(DF, arrows(or - ll, order, or + ul, order, code = 3, angle = 90))
 
 See ?arrows for help on the options for formatting the lines.
 
 Alternatively, since it appears you are doing a meta-analysis of  
 sorts, you might want to look at the metaplot() and forestplot()  
 functions in Thomas Lumley's 'rmeta' package on CRAN.
 
 HTH,
 Marc Schwartz

While Marc was posting the above, I was working out an example
on just those lines! It is simply an illustration of how one
can proceed. Often, it is worth while constructing one's plot
by hand, since then you can cook things exactly as you want
them (Haute Cuisine), rather than get served with what's been
prepared (Pizza Bar, even if it is a high-quality one).

Here is ths code:

## Construct the dataframe
X-rbind(
c(0.7,0.55,0.89,1),
c(0.76,0.71,0.93,2),
c(0.68,0.51,0.89,3),
c(0.5,0.28,0.87,4)
)
colnames(X)-c(OR,LL,UL,Order)
rownames(X)-c(UCSF,MDA,UK,Mayo)
Xdf-as.data.frame(X)

## Construct the plot
plot(Xdf$OR, (5-Xdf$Order), pch=20, log=x,
 xlim=c(0.2,1), ylim=c(0.5,4.5),
 axes=FALSE, frame.plot=TRUE,
 xlab=OR with Confidence Limits, ylab=Order)
at.x - 0.2*(1:5)
axis(1,at=at.x,labels=formatC(at.x,format=fg))
for(i in (1:4)){
  y - (5-Xdf$Order[i])
  lines(c(Xdf$LL[i],Xdf$UL[i]),c(y,y))
  text(0.2,i,labels=as.character(y),pos=4)
  text(0.21,y,labels=rownames(Xdf)[i],pos=4)
}

## Especially see ?plot and ?plot.default for details

Ted.


E-Mail: (Ted Harding) ted.hard...@manchester.ac.uk
Fax-to-email: +44 (0)870 094 0861
Date: 21-Dec-09   Time: 22:13:40
-- XFMail --

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


Re: [R] Plot odds ratios on log scale

2009-12-21 Thread Richard M. Heiberger

Please look at the aedotplot, in which we plot four variables:
A effect, B effect, relative risk, and CI on the relative risk.

It should be easily modified to plot the odds ratios.

## install.packages(HH)  ## if you don't have it yet.

library(aedotplot)
example(aedotplot)

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


Re: [R] Plot odds ratios on log scale

2009-12-21 Thread Marc Schwartz

On Dec 21, 2009, at 4:13 PM, Ted Harding wrote:


On 21-Dec-09 21:19:27, Marc Schwartz wrote:

On Dec 21, 2009, at 2:54 PM, Rice, Terri wrote:

Hi,
I have the following table of odds ratios (or), lower limits(ll) and
upper limits(ul), which I would like to plot as horizontal lines
beginning at the lower limit, ending at the upper limits and with a
dot at the odds ratio on an x-axis on a log10 scale. The y axis
would be the study sites.


From what I can figure out, it looks like the plotCI function will
do everything except give me an x-axis that is on a log10 scale and
I can't get the logaxis function in the log10 package to work.


Study   or  ll  ul  order
UCSF0.7 0.550.891
MDA 0.760.710.932
UK  0.680.510.893
Mayo0.5 0.280.874

Thanks for any suggestions!

Terri


Terri,
You can build your own easily, using plot() and then either arrows()
or segments() to create the CI boundary lines. Just use 'log = x'  
in

the call to plot to create the log scaled x axis.

Presuming that your data above are contained in a data frame called
'DF':


DF

  Study   or   ll   ul order
1  UCSF 0.70 0.55 0.89 1
2   MDA 0.76 0.71 0.93 2
3UK 0.68 0.51 0.89 3
4  Mayo 0.50 0.28 0.87 4


# Get the range of values for the x axis
xlim - with(DF, range(or - ll, or + ul))


xlim

[1] 0.05 1.69

# Plot the points. set the range of the x axis and set to log10 scale
plot(order ~ or, data = DF, xlim = xlim, pch = 19, log = x)

# Add the CI's
with(DF, arrows(or - ll, order, or + ul, order, code = 3, angle =  
90))


See ?arrows for help on the options for formatting the lines.

Alternatively, since it appears you are doing a meta-analysis of
sorts, you might want to look at the metaplot() and forestplot()
functions in Thomas Lumley's 'rmeta' package on CRAN.

HTH,
Marc Schwartz


While Marc was posting the above, I was working out an example
on just those lines! It is simply an illustration of how one
can proceed. Often, it is worth while constructing one's plot
by hand, since then you can cook things exactly as you want
them (Haute Cuisine), rather than get served with what's been
prepared (Pizza Bar, even if it is a high-quality one).


snip

I nominate Ted's comments above for inclusion in the fortunes package.

Now...to the kitchen...that made me hungry... :-)

Regards,

Marc

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Slow survfit -- is there a faster alternative?

2009-12-21 Thread gregory.bronner
Using R 2.10 on Windows:

I have a filtered database of 650k event observations in a data frame
with 20+ variables.

I'd like to be able to quickly generate estimate and plot survival
curves. However the survfit and cph() functions are extremely slow.


As an example: I tried 

results.cox-coxph(Surv(duration, success) ~ start_time + factor1+
factor2+ variable3, data=filteredData) #(took a few seconds)

plot(results.cox)
#(never finished in an hour)

I also tried the cph() function, with similar results.


Is there some easier quick-and-dirty way of producing and plotting
survival curves for large data sets? I've seen some references on this
list that suggest that the underlying algorithm is O(numObs *
numSuccesses) and could be sped up. Has this been done?

Thanks,
___

This e-mail may contain information that is confidential, privileged or 
otherwise protected from disclosure. If you are not an intended recipient of 
this e-mail, do not duplicate or redistribute it by any means. Please delete it 
and any attachments and notify the sender that you have received it in error. 
Unless specifically indicated, this e-mail is not an offer to buy or sell or a 
solicitation to buy or sell any securities, investment products or other 
financial product or service, an official confirmation of any transaction, or 
an official statement of Barclays. Any views or opinions presented are solely 
those of the author and do not necessarily represent those of Barclays. This 
e-mail is subject to terms available at the following link: 
www.barcap.com/emaildisclaimer. By messaging with Barclays you consent to the 
foregoing.  Barclays Capital is the investment banking division of Barclays 
Bank PLC, a company registered in England (number 1026167) with its registered 
offi!
 ce at 1 Churchill Place, London, E14 5HP.  This email may relate to or be sent 
from other members of the Barclays Group.

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

2009-12-21 Thread baloo mia
Dear R experts,

Might be very simple question to ask but would be insightful. As the same story 
of nested for loops. following is the code that I am using to get the 
autocorrelation function of the sample data. I have tried to get rid of for 
loops but since I am touching R after such a long time that I need to practice 
more but I need help to revive my skills. I know that apply() or sapply() would 
be beneficial. I need help...

Best Wishes,
Baloo 

R code
--
acf_wal - function (infile) {
    data-read.table(infile)
    data_value - data[,-1]
    data_value_mean - mean(data_value)
    data_value_square - (data_value - data_value_mean) ^ 2 
    square_sum-sum(data_value_square)
    entry-NROW(data_value)
    deno-square_sum/entry

    tab1-c()
    tab2-c()
    ps_value - seq(0,(floor(entry/2)),1)
    
    for(k in 0:(floor(entry/2))){
        for (i in 1:(entry-k)) {
            mult-(data_value[i] - data_value_mean) * (data_value [i+k] - 
data_value_mean)
            tab1 - c(tab1,mult)
        }
            auto_avg-mean(tab1)
            tab1-c()
            auto_corr-auto_avg/deno
            tab2-c(tab2,auto_corr)
    }

    table_value - cbind (ps_value, tab2)
    colnames(table_value) - c(#ps, acf)


    outfile-unlist(strsplit(infile, split=., fixed=TRUE))[1]

    
write.table(table_value,file=paste(outfile,acf.dat,sep=-),row.names=FALSE,sep=\t,quote=F)
}

--

Sample data
--

1 16.0071
2 16.7966
3 17.575
4 18.1614
5 15.982
6 16.8515
7 15.6828
8 14.9652
9 14.8623
10 14.7079



Help in this regard would be highly appreciated.

 



  
[[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] slow survfit -- is there a better replacement?

2009-12-21 Thread gregory.bronner
Using R 2.10 on Windows:

I have a filtered database of 650k event observations in a data frame
with 20+ variables.

I'd like to be able to quickly generate estimate and plot survival
curves. However the survfit and cph() functions are extremely slow.


As an example: I tried 

results.cox-coxph(Surv(duration, success) ~ start_time + factor1+
factor2+ variable3, data=filteredData)
#(took a few seconds)

plot(results.cox) 
#(never finished in an hour)

I also tried the cph() function, with similar results.


Is there some easier quick-and-dirty way of producing and plotting
survival curves for large data sets? I've seen some references on this
list that suggest that the underlying algorithm is O(numObs *
numSuccesses) and could be sped up. Has this been done?

Thanks,
___

This e-mail may contain information that is confidential, privileged or 
otherwise protected from disclosure. If you are not an intended recipient of 
this e-mail, do not duplicate or redistribute it by any means. Please delete it 
and any attachments and notify the sender that you have received it in error. 
Unless specifically indicated, this e-mail is not an offer to buy or sell or a 
solicitation to buy or sell any securities, investment products or other 
financial product or service, an official confirmation of any transaction, or 
an official statement of Barclays. Any views or opinions presented are solely 
those of the author and do not necessarily represent those of Barclays. This 
e-mail is subject to terms available at the following link: 
www.barcap.com/emaildisclaimer. By messaging with Barclays you consent to the 
foregoing.  Barclays Capital is the investment banking division of Barclays 
Bank PLC, a company registered in England (number 1026167) with its registered 
offi!
 ce at 1 Churchill Place, London, E14 5HP.  This email may relate to or be sent 
from other members of the Barclays Group.

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


Re: [R] Help,Suggest me some methods to identify tr aining set and test set!!!

2009-12-21 Thread bbslover

Thank you for all help. It is helpful for me.

Max Kuhn wrote:
 
 I noticed Max already pointed you to the caret package.

 Load the library and look at the help for the createFolds function, eg:

 library(caret)
 ?createFolds
 
 I think that the createDataPartition function in caret might work
 better for you.
 
 There are a number of other packages with similar functions.
 
 Max
 
 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide
 http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.
 
 

-- 
View this message in context: 
http://n4.nabble.com/Help-Suggest-me-some-methods-to-identify-training-set-and-test-set-tp976245p976641.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] Slow survfit -- is there a faster alternative?

2009-12-21 Thread David Winsemius


On Dec 21, 2009, at 8:20 PM, gregory.bron...@barclayscapital.com  
wrote:



Using R 2.10 on Windows:

I have a filtered database of 650k event observations in a data frame
with 20+ variables.

I'd like to be able to quickly generate estimate and plot survival
curves. However the survfit and cph() functions are extremely slow.


As an example: I tried

results.cox-coxph(Surv(duration, success) ~ start_time + factor1+
factor2+ variable3, data=filteredData) #(took a few seconds)

plot(results.cox)
#(never finished in an hour)


Something is wrong here. I use cph (from the Design package) on  
datasets numbering in the millions with crossed spline terms and the  
plots are virtually immediate.


I also tried the cph() function, with similar results.


The plot.Design function needs more than just the fit as an argument,  
so you are not providing enough information for good advice. When I  
try to plot with an object produced by coxph with no further  
arguments, I get an error.


 plot(survHb)
Error in xy.coords(x, y, xlabel, ylabel, log) :
  'x' and 'y' lengths differ

What happens when you use predict or survfit to process the fit objects:

?survfit.coxph

E.g.:
 survHb - coxph(Surv(surv.yr, death) ~ age+nsmkr +sexMF + HbPr2 +  
GGT, data=hisub)

 plot(Hb)
Error: object 'Hb' not found
Error in plot(Hb) :
  error in evaluating the argument 'x' in selecting a method for  
function 'plot'


#this however, succeeds ---

 sfit-survfit(survHb)
 plot(sfit)

So you need to supply a process form of a fit.





Is there some easier quick-and-dirty way of producing and plotting
survival curves for large data sets? I've seen some references on this
list that suggest that the underlying algorithm is O(numObs *
numSuccesses) and could be sped up. Has this been done?

Thanks,




David Winsemius, MD
Heritage Laboratories
West Hartford, CT

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


[R] RGtk2 - retrieve ggraphics mouse coordinates during drag-and-drop event

2009-12-21 Thread Mark Heckmann

Hi all,

I have a gtable and a ggraphic widget.
I want to drag an element from the table onto the graphic.
When the drag object is released over the ggraphic widget, I want the  
mouse coordinates inside the ggraphic to be returned.
Right now I do not know how to get the mouse ccordinates of the  
ggraphic widget at any given time.

How can I access the ggraphics mouse coordinates?

Below you find my sample code (windows only due to ggraphics).

TIA,
Mark


library(gWidgets)
library(RGtk2)
options(guiToolkit=RGtk2)

w = gwindow(ggraphics example)
table - gtable(1:10, container=w)
g = ggraphics(cont=w, expand=T)
size(g) - c(500,500)

Sys.sleep(1)
plot(rnorm(20), col=red)


## convert from plt coordinates to more familiar usr
pltToUsr = function(x,y) {
plt = par(plt); usr = par(usr)
c( (usr[2]-usr[1])/(plt[2]-plt[1])*(x - plt[1]) + usr[1],
(usr[4] - usr[3])/(plt[4] - plt[3])*(y - plt[3]) + usr[3])
}


addHandlerFocus(g, handler = function(h,...) {
  print(c(focus g))
})

addHandlerClicked(g, handler = function(h,...) {
  x - h$x; y - h$y
  xStart - x; yStart - y
  pressed - TRUE
  print(c(pressed at:, c(x,y)))
})


da - g...@widget@widget
callbackID - gSignalConnect(da,button-release-event, function 
(w,e,...) {

allocation = w$GetAllocation()
xclick = e$GetX()
yclick = e$GetY()
x = xclick/allocation$width
y = (allocation$height - yclick)/allocation$height
xyCoordsRelease - pltToUsr(x,y)
print(c(released at:, pltToUsr(x,y)))
xMove - xyCoordsRelease[1] - xStart
yMove - xyCoordsRelease[2] - yStart
print(c(xMove, round(xMove, 3), yMove, round(yMove, 3)))
plot(rnorm(20), col=red)
#print(qplot(rnorm(100), geom=histogram))
pressed - FALSE
return(TRUE)
})

adddropsource(table) #, handler = defHandlerSource)
#defHandlerSource = function(h,...) print(source)
adddropmotion(g, handler=function(h, ...) {
print(motion)
})
adddroptarget(g,  targetType=object, handler = defHandlerTarget, g)
defHandlerTarget = function(h, ...){
   print(h$dropdata)
}




–––
Mark Heckmann
Dipl. Wirt.-Ing. cand. Psych.
Vorstraße 93 B01
28359 Bremen
Blog: www.markheckmann.de
R-Blog: http://ryouready.wordpress.com

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


[R] [R-pkgs] Rcpp 0.7.0: R/C++ integration now even easier

2009-12-21 Thread Dirk Eddelbuettel

Rcpp version 0.7.0 went onto CRAN this weekend. The key new features are

  o inline support, taken from Oleg Sklyar's neat inline package and 
adapted/extented to support Rcpp as well as external libraries
(see below for an example); this even works on Windows (provided you 
have Rtools installed and configured); 

  o addition of a new simple type RcppSexp for importing or exporting
simple types directly between R and C++

  o addition of a number of new examples for both these features

  o code reorganisation: every class has in its own header and source file 

  o last but not least relicensed from LGPL (=2.1) to GPL (= 2)

My blog (http://dirk.eddelbuettel.com/blog/) has two recent posts with a bit
more details (and colour highlighting of the code below) but let's just look
at one example of using GNU GSL functions for illustrative purposes (as you
wouldn't need this to access random-number generators as R has its own).

Consider this R code snippet:

## use Rcpp to pass down a parameter for the seed, and a vector size
gslrng - '
   int seed = RcppSexp(s).asInt();
   int len = RcppSexp(n).asInt();

   gsl_rng *r;
   gsl_rng_env_setup();
   std::vectordouble v(len);

   r = gsl_rng_alloc (gsl_rng_default);

   gsl_rng_set (r, (unsigned long) seed);
   for (int i=0; ilen; i++) {
   v[i] = gsl_rng_get (r);
   }
   gsl_rng_free(r);

   return RcppSexp(v).asSexp();
   '

## turn into a function that R can call
## compileargs redundant on Debian/Ubuntu as gsl headers are found anyway
funx - cfunction(signature(s=numeric, n=numeric),
  gslrng,
  includes=#include gsl/gsl_rng.h,
  Rcpp=TRUE,
  cppargs=-I/usr/include,
  libargs=-lgsl -lgslcblas)
print(funx(0, 5))


Brief notes on this:

  1)  The character variable gslrng contains valid C++ code.

  2)  The call to cfunction converts this C++ code into a function that
  calls it -- and this function is compiled, linked and loaded
  automagically simply using hints about GSL header files and libraries.

  3)  The interface is explit: cfunction() is told about a function signature
  with numeric variables 's' and 'n'; this is what the C++ code convert
  to (C++ local) variables 'seed' and 'len' using the RcppSexp class.

  4)  We return a single SEXP to R which is based on the std::vectordouble
  v which is also converted on the fly.

  5)  The resulting vector is returned and simply printed at the R level.


More examples are in the source tarball and in the R-Forge SVN archive.

Cheers, Dirk

-- 
Three out of two people have difficulties with fractions.

___
R-packages mailing list
r-packa...@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-packages

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

2009-12-21 Thread rusers.sh
Thanks a lot.

2009/12/20 Henrique Dallazuanna www...@gmail.com

 Try this also:

 sapply(s, function(x)format(x, big.interval = nchar(x) - 3, big.mark =
 .))

 On Sun, Dec 20, 2009 at 7:50 PM, rusers.sh rusers...@gmail.com wrote:
  Hi,
   Anybody can give me some hints on the following problem?
  s-c(110,112321)
   I want to insert a dot . after the third number and get the following
  results.
  110.
  112.321
 
   Thanks a lot.
 
  --
  -
  Jane Chang
  Queen's
 
 [[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.
 



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




-- 
-
Jane Chang
Queen's

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