Re: [R] spatial analysis

2011-12-06 Thread Rainer M Krug
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

On 06/12/11 03:06, Rolf Turner wrote:
 On 06/12/11 01:44, marianne.zeyrin...@ec.europa.eu wrote:
 Dear all,
 
 I am a PhD student in energy modelling. I am completely stuck
 with the following problem and would be very grateful for any
 kind of help. I have cells
 Don't we all?  We're made of them. :-)
 
 What do you mean by ``I have''?  I.e. be a bit more explicit about 
 the nature of your data.
 and each cell is assigned a number. I would like to form clusters
 of cells where the sum of the cell numbers in each cluster must 
 not exceed 250. One restriction is that only neighbouring cells
 Define neighbouring.
 can be formed into clusters. In the end I would like to have a
 list with all possible cell combinations.
 Do you mean all possible ways in which your ``collection of
 cells'' can be subdivided into such clusters?  My guess is that the
 number of such ways could be extremely large.  (Depending of course
 on how many cells there are in the collection.)
 Is it possible to do this with R If yes, I would very much
 appreciate all possible hints how to solve it.
 Install the fortunes package.  Then type
 
 fortune(Yoda)
 
 But if you want useful help you'll have to make your question much 
 clearer.

Agreed - but as it is a spatial question, you should post it at
r-sig-...@r-project.org, the list of the special interest group
spatial analysis.

I would also look into e.g. GRASS and SAGA, which might be faster with
these kind of spatial calculations.

In general, if I understand you correctly, you can start with each
cell and then grow outwards until you hit your stop criteria (sum =
250), and then you should have your clusters: one solution per
starting cell (assuming symmetric clusters - if the clusters can be
a-symmetric, many many more).

Cheers,

Rainer


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


- -- 
Rainer M. Krug, PhD (Conservation Ecology, SUN), MSc (Conservation
Biology, UCT), Dipl. Phys. (Germany)

Centre of Excellence for Invasion Biology
Stellenbosch University
South Africa

Tel :   +33 - (0)9 53 10 27 44
Cell:   +33 - (0)6 85 62 59 98
Fax :   +33 - (0)9 58 10 27 44

Fax (D):+49 - (0)3 21 21 25 22 44

email:  rai...@krugs.de

Skype:  RMkrug
-BEGIN PGP SIGNATURE-
Version: GnuPG v1.4.11 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAk7d0VYACgkQoYgNqgF2egqOsACfc6CKV1tY/0xbxR41AfwoBMtA
bWsAnRivgAdiuF3MKErvl1l8I+twrOf+
=k9v+
-END PGP SIGNATURE-

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


[R] How to automate the detection of break points for use in cut

2011-12-06 Thread Sébastien Bihorel
Dear R-users,

I would like to know if there is a function (in base R or the extension
packages) that would automatically detect the break points in a vector x
for later use in the cut function. The idea is to determine the boundaries
of the n intervals (n=1) delimiting clusters of data points which could be
considered reasonably close, given a numerical vector x with unknown
content and unknown multimodal distribution.

For instance, given for the vector x defined by set.seed(1234); x -
sort(c(rnorm(20,-1,0.1),rnorm(
10,5,0.1),rnorm(10,100,0.1))), this function would return a vector of 4
points: min(x), one value between 20 and 5, one value between 5 and 100,
and max(x).

Thank you in advance for your suggestions.

Sebastien

[[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 automate the detection of break points for use in cut

2011-12-06 Thread Sébastien Bihorel
Obviously, cut would do the job if one knows the number of intervals in
advance, which I assume I won't. I guess what I'm looking for is a function
that figures out the number of intervals and their boundaries.

Sebastien

On Tue, Dec 6, 2011 at 3:29 AM, Sébastien Bihorel pomc...@free.fr wrote:

 Dear R-users,

 I would like to know if there is a function (in base R or the extension
 packages) that would automatically detect the break points in a vector x
 for later use in the cut function. The idea is to determine the boundaries
 of the n intervals (n=1) delimiting clusters of data points which could be
 considered reasonably close, given a numerical vector x with unknown
 content and unknown multimodal distribution.

 For instance, given for the vector x defined by set.seed(1234); x -
 sort(c(rnorm(20,-1,0.1),rnorm(
 10,5,0.1),rnorm(10,100,0.1))), this function would return a vector of 4
 points: min(x), one value between 20 and 5, one value between 5 and 100,
 and max(x).

 Thank you in advance for your suggestions.

 Sebastien


[[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] factors with multiple levels

2011-12-06 Thread Agnieszka Konopka
Hi R-experts,

I'm running into some trouble with a multi-level factor. My apologies
if this is a basic question, but I have been told there are different
ways to do this and would like to see what you think.

In the dataset I'm looking at, subjects named pictures multiple times
(e.g., they named each picture 8 times), so Repetition is a
multi-level factor. How would you enter it into a model? As a factor?
Or a numeric predictor? I understand the pros and cons of both
approaches, but there seems to be some debate about this. I am not
interested in the individual contrasts between different levels of the
Repetition factor, but only need the equivalent of an F value in a
standard ANOVA for that factor.

And what about dependencies between levels?

Many thanks in advance,

Agnieszka

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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 view/edit large matrix/array in R?

2011-12-06 Thread Milan Bouchet-Valat
Le lundi 05 décembre 2011 à 19:01 -0600, Michael a écrit :
 head, tail and fix commands don't really work well if I have large
 matrix/array for which I would like to be able to scroll up and dow, left
 and right ...
 
 Could anybody please help me?
RKWard has a good data editor, and you can open several objects at the
same time in tabs. But it will not probably work if your data set is
really huge (here it works very well with a few thousand rows, though).

If you need to see a selection of variables in parallel, ordering the
variables so that they're next to each other is probably a good
solution.


Cheers

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

2011-12-06 Thread Johannes Radinger
Hi,

I just started with writing functions in R and so some questions popped up.
I provide some values as argument to my function such as:

function(a,b,c){}

Now i want that the function first checks if the arguments are valid for the 
function. E.g argument a has to be a number in the range 0-1. How can that 
easily done?

So far I have:

a - as.numeric(a)
if(0 = a  a = 1)

to first check if a is a number...if not the function stops and gives an error 
message. If it is a number it just continues... 

But how to check the range? 
Above there is the if-approach but then the rest of the function is exectued as 
part of if (or else). Is there a simpler way without having the if-brackets 
around the remaining code? 
Just a check if the value is between 0 and 1 and if yes continue with the next 
line if no abort the function with a error message? How can such an error 
message be created?

thank you and best regards,

/Johannes
--

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


Re: [R] Problem in while loop

2011-12-06 Thread R. Michael Weylandt
So I just ran your code verbatim with this one change and it finished
in less than 10 seconds. However, even without the change it doesn't
take more than 15 seconds: what exactly lead you to believe this was
an infinite loop?

Michael

On Tue, Dec 6, 2011 at 12:03 AM, R. Michael Weylandt
michael.weyla...@gmail.com michael.weyla...@gmail.com wrote:
 Off the bat I'd suggest you vectorize loglikelihood as a simple one liner:

 sum(log(b^2 + (x-a)^2))

 That alone will speed up your function many times over: I'll look at the big
 function in more detail tomorrow.

 Michael

 On Dec 5, 2011, at 10:37 PM, Gyanendra Pokharel
 gyanendra.pokha...@gmail.com wrote:

 Thanks Michael
 Lets figure out the problem by using the following function. I found the
 same problem in this code too.


 loglikehood - function(a, b = 0.1, x = c(-4.2, -2.85, -2.3, -1.02, 0.7,
 0.98, 2.72, 3.5))

 {

 s - 0

 for(i in 1:length(x)){

 s - s + log(b^2 + (x[i] - a)^2)

 }

 s

 }

 loglikelihood(0.1)

 simann - function(T0 = 1, N = 500, rho = 0.9, x0 = 0, eps = 0.1, f){

 moving - 1

 count - 0

 Temp - T0

 x - x0

 while(moving  0){

 moving - 0

 for(i in 1:N){

 y - x + runif(1,-eps,eps)

 alpha - min(1,exp((f(x) -f(y))/Temp))

 if(runif(1)alpha){

 moving - moving +1

 x - y

 }

 }

 Temp - Temp*rho

 count - count + 1

 }

 fmin - f(x)

 return(c(x,fmin,count))

 }

 simann(f = loglikelihood)

 I hope we can analyze every problems from this function

 On Mon, Dec 5, 2011 at 10:27 PM, R. Michael Weylandt
 michael.weyla...@gmail.com michael.weyla...@gmail.com wrote:

 It's not necessarily equivalent to your loglikelihood function but since
 that function wasn't provided I couldn't test it.

 My broader point is this: you said the problem was that the loop ran
 endlessly: I showed it does not run endlessly for at least one input so at
 least part of the problem lies in loglikelihood, which, being unprovided, I
 have trouble replicating.

 My original guess still stands: it's either 1) a case of you getting stuck
 at probaccept = 1 or 2) so slow it just feels endless.  Either way, my
 prescription is the same: print()

 Michael


 On Dec 5, 2011, at 9:30 PM, Gyanendra Pokharel
 gyanendra.pokha...@gmail.com wrote:

 Yes, your function out- epiann(f = function(a,b) log(dnorm(a)*dnorm(b))),
 N = 10) works well.

 But why you are changing the loglikelihood function to f = function(a,b)
 log(dnorm(a)*dnorm(b))? how it is equivalent to loglikelihood? is there any
 mathematical relation?  I also want to see the plot of aout and bout versus
 loglikelihood, and see the cooling rate in different temperature. how is
 this possible?

 On Mon, Dec 5, 2011 at 6:07 PM, R. Michael Weylandt
 michael.weyla...@gmail.com wrote:

 If you run

 out- epiann(f = function(a,b) log(dnorm(a)*dnorm(b))), N = 10)

 It takes less than 0.5 seconds so there's no problem I can see:
 perhaps you want to look elsewhere to get better speed (like Rcpp or
 general vectorization), or maybe your loglikihood is not what's
 desired, but there's no problem with the loop.

 Michael

 On Mon, Dec 5, 2011 at 5:29 PM, Gyanendra Pokharel
 gyanendra.pokha...@gmail.com wrote:
  Yes, I checked the acceptprob, it is very high but in my view, the
  while
  loop is not stopping, so there is some thing wrong in the use of while
  loop.
  When I removed the while loop, it returned some thing but not the
  result
  what I want. When i run the while loop separately, it never stops.
 
 
 
  On Mon, Dec 5, 2011 at 5:18 PM, R. Michael Weylandt
  michael.weyla...@gmail.com wrote:
 
  Your code is not reproducible nor minimal, but why don't you put a
  command print(acceptprob) in and see if you are getting reasonable
  values. If these values are extremely low it shouldn't surprise you
  that your loop takes a long time to run.
 
  More generally, read up on the use of print() and browser() as
  debugging
  tools.
 
  Michael
 
  On Mon, Dec 5, 2011 at 3:47 PM, Gyanendra Pokharel
  gyanendra.pokha...@gmail.com wrote:
   I forgot to upload the R-code in last email, so heare is one
  
   epiann - function(T0 = 1, N=1000, ainit=1, binit=1,rho = 0.99,
   amean =
   3,
   bmean=1.6, avar =.1, bvar=.1, f){
  
          moving - 1
          count - 0
          Temp - T0
          aout - ainit
          bout - binit
          while(moving  0){
                  moving - 0
                  for (i in 1:N) {
                  aprop - rnorm (1,amean, avar)
                  bprop - rnorm (1,bmean, bvar)
                  if (aprop  0  bprop  0){
                  acceptprob - min(1,exp((f(aout, bout) -
   f(aprop,bprop))/Temp))
                  u - runif(1)
                  if(uacceptprob){
                      moving - moving +1
                      aout - aprop
                      bout - bprop
                      }
                      else{aprob - aout
                          bprob - bout}
                  }
              }
          Temp - Temp*rho
              count - count +1
  
      }

Re: [R] Argument validation within functions

2011-12-06 Thread R. Michael Weylandt
The quick and dirty way to do so is to use: stopifnot() in conjunction
(if necessary with all() and any()). You can replace that first
condition with a simple is.numeric() as well. A more helpful way (if
this is production code) is to use if statement with the stop()
function directly which lets you provide specific error messages.

Michael

On Tue, Dec 6, 2011 at 6:41 AM, Johannes Radinger jradin...@gmx.at wrote:
 Hi,

 I just started with writing functions in R and so some questions popped up.
 I provide some values as argument to my function such as:

 function(a,b,c){}

 Now i want that the function first checks if the arguments are valid for the 
 function. E.g argument a has to be a number in the range 0-1. How can that 
 easily done?

 So far I have:

        a - as.numeric(a)
        if(0 = a  a = 1)

 to first check if a is a number...if not the function stops and gives an 
 error message. If it is a number it just continues...

 But how to check the range?
 Above there is the if-approach but then the rest of the function is exectued 
 as part of if (or else). Is there a simpler way without having the 
 if-brackets around the remaining code?
 Just a check if the value is between 0 and 1 and if yes continue with the 
 next line if no abort the function with a error message? How can such an 
 error message be created?

 thank you and best regards,

 /Johannes
 --

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

2011-12-06 Thread R. Michael Weylandt
The code provided was the hard-to-find C part: there's also some R
code involved that you can get in your console by typing acf without
parentheses.

I'm inclined to believe VR over any Excel implementation (and I don't
know what pc is) but perhaps you can provide a (small) data-set
using the dput() function and say what you are expecting to get from
acf() instead.

Michael

On Mon, Dec 5, 2011 at 8:32 PM, Bazman76 h_a_patie...@hotmail.com wrote:
 Hi there,

 I have now cheked the results against pc give and the excel add-in poptools.

 Poptools and pc give get the same answer but R is quite different especially
 for the acf and pacf()?

 I looked at the book you recommended on p390 itshows the formulas and they
 look pretty standard.

 However looking at the code that you sent the acf function does not seem to
 be being calculated as shown in the book?

 At no point is the series mean calculated? unless the variable x is already
 demeaned in some way ie. there is some preprocessing that I need to see to
 fully understand?



 --
 View this message in context: 
 http://r.789695.n4.nabble.com/a-question-on-autocorrelation-acf-tp2076280p4163021.html
 Sent from the R help mailing list archive at Nabble.com.

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

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


Re: [R] rugarch package: is this forecast correct?

2011-12-06 Thread R. Michael Weylandt
The calculation is numerically stable on my machine: I'd mark it up as
computational/floating-point error and not worry about it.

Michael

On Mon, Dec 5, 2011 at 11:13 PM, Ivan Popivanov
ivan.popiva...@gmail.com wrote:
 Let me start with the code:

 library(quantmod)
 library(rugarch)
 getSymbols(SPY, from=1900-01-01)
 rets=na.trim(diff(log(Cl(SPY
 tt = tail(rets[/2004-10-29], 1000)
 spec = ugarchspec(variance.model=list(garchOrder=c(1,1)),
 mean.model=list(armaOrder=c(2,5)), distribution.model=sged)
 for(ii in 1:10)
 {
   ttFit = ugarchfit( spec=spec, data=as.vector(tt), out.sample=0,
 solver.control=list(trace=F) )
   ttFore = ugarchforecast( ttFit, n.ahead=1, n.roll=0 )
   print( as.array(ttFore)[,2,] )
 }

 Produces two different results: -0.001087313 and -0.001092084, each
 repeated a few times.

 What is the explanation for that? Since they are based on previous data, I
 was expecting single step forecasts to produce the same result.

 Thanks in advance!
 Ivan

        [[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] Argument validation within functions

2011-12-06 Thread Sébastien Bihorel
Adding on Michael comment:

If your trap all conditions that render your main code invalid at the
beginning of your code, the main code does not have to be within the else
part of a if else statement.

For instance:

myf - function(a,b,c){

if ( ! (is.numeric(a)  (a=0  a=1) ) ){
  stop('a is invalid')
}

if (all bad conditions for b){
  stop('b is invalid')
}

if (all bad conditions for c){
  stop('c is invalid')
}

  return(a+b+c)

}

Sebastien

[[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! what's wrong with setBreakpoint

2011-12-06 Thread Duncan Murdoch

On 11-12-05 10:32 PM, Michael wrote:

Hi all,

I am in the middle of debugging which is stopped using browser()... in
myfile.R at around line #25.

I was then stuck in a big loop which I want to escape and stop the program
at the line after the big loop.

In the debugging mode, I used

Browse[2]  setBreakpoint(myfile.R#38)


What did it print?



I then typed c and ENTER, thinking that it will continue to execute
until when it comes across line #38 and then stop there...

But it didn't work - it continued the execution until the end of the
function, right at the line return(results)...

What happened? How to solve this problem?


One of the complications in R is that you can have multiple copies of a 
function in memory.  You may (or may not, what did it print??) have set 
a breakpoint in one copy, then run another.  Or you may have edited that 
function after originally sourcing it, and lost the source reference.


An alternative to using setBreakpoint is just to edit a call to 
browser() into the function.  It's less convenient, but more robust.


Duncan Murdoch


Thanks a lot!

[[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] How to automate the detection of break points for use in cut

2011-12-06 Thread Duncan Murdoch

On 11-12-06 3:34 AM, Sébastien Bihorel wrote:

Obviously, cut would do the job if one knows the number of intervals in
advance, which I assume I won't. I guess what I'm looking for is a function
that figures out the number of intervals and their boundaries.


That's not really a simple problem, but there are functions that do 
clustering and fit mixture models to data, which might be close enough. 
 See the Cluster task view at 
http://cran.r-project.org/web/views/Cluster.html.


Duncan Murdoch



Sebastien

On Tue, Dec 6, 2011 at 3:29 AM, Sébastien Bihorelpomc...@free.fr  wrote:


Dear R-users,

I would like to know if there is a function (in base R or the extension
packages) that would automatically detect the break points in a vector x
for later use in the cut function. The idea is to determine the boundaries
of the n intervals (n=1) delimiting clusters of data points which could be
considered reasonably close, given a numerical vector x with unknown
content and unknown multimodal distribution.

For instance, given for the vector x defined by set.seed(1234); x-
sort(c(rnorm(20,-1,0.1),rnorm(
10,5,0.1),rnorm(10,100,0.1))), this function would return a vector of 4
points: min(x), one value between 20 and 5, one value between 5 and 100,
and max(x).

Thank you in advance for your suggestions.

Sebastien



[[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] Argument validation within functions

2011-12-06 Thread Johannes Radinger
Hi,

thank you... I think I will go for the if-stop approach
as the stop() stops the total function... So there is just
one little other question: What is the opposite of is.numeric?
Is ther isnot.numeric? How  can that be implemented in following
function:

f - function(a){
if(is.numeric(a)) stop(a is not numeric)
if(0  a  a  1) stop(a must be a value between 0 and 1)
a
}

/Johannes

 Original-Nachricht 
 Datum: Tue, 6 Dec 2011 07:04:59 -0500
 Von: R. Michael Weylandt michael.weyla...@gmail.com
 An: Johannes Radinger jradin...@gmx.at
 CC: r-help@r-project.org
 Betreff: Re: [R] Argument validation within functions

 The quick and dirty way to do so is to use: stopifnot() in conjunction
 (if necessary with all() and any()). You can replace that first
 condition with a simple is.numeric() as well. A more helpful way (if
 this is production code) is to use if statement with the stop()
 function directly which lets you provide specific error messages.
 
 Michael
 
 On Tue, Dec 6, 2011 at 6:41 AM, Johannes Radinger jradin...@gmx.at
 wrote:
  Hi,
 
  I just started with writing functions in R and so some questions popped
 up.
  I provide some values as argument to my function such as:
 
  function(a,b,c){}
 
  Now i want that the function first checks if the arguments are valid for
 the function. E.g argument a has to be a number in the range 0-1. How
 can that easily done?
 
  So far I have:
 
         a - as.numeric(a)
         if(0 = a  a = 1)
 
  to first check if a is a number...if not the function stops and gives an
 error message. If it is a number it just continues...
 
  But how to check the range?
  Above there is the if-approach but then the rest of the function is
 exectued as part of if (or else). Is there a simpler way without having the
 if-brackets around the remaining code?
  Just a check if the value is between 0 and 1 and if yes continue with
 the next line if no abort the function with a error message? How can such an
 error message be created?
 
  thank you and best regards,
 
  /Johannes
  --
 
  __
  R-help@r-project.org mailing list
  https://stat.ethz.ch/mailman/listinfo/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] Paste() - Get all possible combinations from multiple vectors

2011-12-06 Thread Gaj Stan (BIGCAT)
Hello fellow R-users,

Given are three vectors and the outcome would be all possible combinations in 
combination with the paste() function.
For example:

x - c(1:3)
y - letters[1:3]
z - LETTERS[1:3]

My result would thus be 18 names based on all possible combinations between 
these vectors:
1 a A 1 a B, 1 a C, 1 b A, 1 b B, 1 b C, 1 c A, 1 c B, 1 c C, 
etc.

To solve the issue above I would use:

paste(rep(x, each=9), rep(y, each=6), z)

This is a very straightforward example, but when I have vectors of different 
sizes, it will be much more difficult (for me) to create this. Is there an 
easier way to do this?

Many thanks in advance,

  -- Stan

[[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] Argument validation within functions

2011-12-06 Thread Uwe Ligges



On 06.12.2011 13:46, Johannes Radinger wrote:

Hi,

thank you... I think I will go for the if-stop approach
as the stop() stops the total function... So there is just
one little other question: What is the opposite of is.numeric?
Is ther isnot.numeric?


Yes, see:
?!

Uwe Ligges



How can that be implemented in following function:

f- function(a){
if(is.numeric(a)) stop(a is not numeric)
if(0  a  a  1) stop(a must be a value between 0 and 1)
a
}

/Johannes

 Original-Nachricht 

Datum: Tue, 6 Dec 2011 07:04:59 -0500
Von: R. Michael Weylandtmichael.weyla...@gmail.com
An: Johannes Radingerjradin...@gmx.at
CC: r-help@r-project.org
Betreff: Re: [R] Argument validation within functions



The quick and dirty way to do so is to use: stopifnot() in conjunction
(if necessary with all() and any()). You can replace that first
condition with a simple is.numeric() as well. A more helpful way (if
this is production code) is to use if statement with the stop()
function directly which lets you provide specific error messages.

Michael

On Tue, Dec 6, 2011 at 6:41 AM, Johannes Radingerjradin...@gmx.at
wrote:

Hi,

I just started with writing functions in R and so some questions popped

up.

I provide some values as argument to my function such as:

function(a,b,c){}

Now i want that the function first checks if the arguments are valid for

the function. E.g argument a has to be a number in the range 0-1. How
can that easily done?


So far I have:

a- as.numeric(a)
if(0= a  a= 1)

to first check if a is a number...if not the function stops and gives an

error message. If it is a number it just continues...


But how to check the range?
Above there is the if-approach but then the rest of the function is

exectued as part of if (or else). Is there a simpler way without having the
if-brackets around the remaining code?

Just a check if the value is between 0 and 1 and if yes continue with

the next line if no abort the function with a error message? How can such an
error message be created?


thank you and best regards,

/Johannes
--

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide

http://www.R-project.org/posting-guide.html

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


--

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


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


Re: [R] Argument validation within functions

2011-12-06 Thread R. Michael Weylandt
Use the ! (not) operator.

Not sure what you mean by  as the stop() stops the total function:
try the following

f - function(a){
   stopifnot(a  3)
   return(a^2)
}

f(2)
f(4)

Michael

(PS -- It's usually asked to cc the list so that this all gets
threaded properly in folks' mailboxes)

On Tue, Dec 6, 2011 at 7:46 AM, Johannes Radinger jradin...@gmx.at wrote:
 Hi,

 thank you... I think I will go for the if-stop approach
 as the stop() stops the total function... So there is just
 one little other question: What is the opposite of is.numeric?
 Is ther isnot.numeric? How  can that be implemented in following
 function:

 f - function(a){
        if(is.numeric(a)) stop(a is not numeric)
        if(0  a  a  1) stop(a must be a value between 0 and 1)
        a
 }

 /Johannes

  Original-Nachricht 
 Datum: Tue, 6 Dec 2011 07:04:59 -0500
 Von: R. Michael Weylandt michael.weyla...@gmail.com
 An: Johannes Radinger jradin...@gmx.at
 CC: r-help@r-project.org
 Betreff: Re: [R] Argument validation within functions

 The quick and dirty way to do so is to use: stopifnot() in conjunction
 (if necessary with all() and any()). You can replace that first
 condition with a simple is.numeric() as well. A more helpful way (if
 this is production code) is to use if statement with the stop()
 function directly which lets you provide specific error messages.

 Michael

 On Tue, Dec 6, 2011 at 6:41 AM, Johannes Radinger jradin...@gmx.at
 wrote:
  Hi,
 
  I just started with writing functions in R and so some questions popped
 up.
  I provide some values as argument to my function such as:
 
  function(a,b,c){}
 
  Now i want that the function first checks if the arguments are valid for
 the function. E.g argument a has to be a number in the range 0-1. How
 can that easily done?
 
  So far I have:
 
         a - as.numeric(a)
         if(0 = a  a = 1)
 
  to first check if a is a number...if not the function stops and gives an
 error message. If it is a number it just continues...
 
  But how to check the range?
  Above there is the if-approach but then the rest of the function is
 exectued as part of if (or else). Is there a simpler way without having the
 if-brackets around the remaining code?
  Just a check if the value is between 0 and 1 and if yes continue with
 the next line if no abort the function with a error message? How can such an
 error message be created?
 
  thank you and best regards,
 
  /Johannes
  --
 
  __
  R-help@r-project.org mailing list
  https://stat.ethz.ch/mailman/listinfo/r-help
  PLEASE do read the posting guide
 http://www.R-project.org/posting-guide.html
  and provide commented, minimal, self-contained, reproducible code.

 --
 NEU: FreePhone - 0ct/min Handyspartarif mit Geld-zurück-Garantie!
 Jetzt informieren: http://www.gmx.net/de/go/freephone

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Paste() - Get all possible combinations from multiple vectors

2011-12-06 Thread R. Michael Weylandt
outer(outer(x, y, paste), z, paste)

Michael

On Tue, Dec 6, 2011 at 7:53 AM, Gaj Stan (BIGCAT)
stan@maastrichtuniversity.nl wrote:
 Hello fellow R-users,

 Given are three vectors and the outcome would be all possible combinations in 
 combination with the paste() function.
 For example:

 x - c(1:3)
 y - letters[1:3]
 z - LETTERS[1:3]

 My result would thus be 18 names based on all possible combinations between 
 these vectors:
 1 a A 1 a B, 1 a C, 1 b A, 1 b B, 1 b C, 1 c A, 1 c B, 1 c 
 C, etc.

 To solve the issue above I would use:

 paste(rep(x, each=9), rep(y, each=6), z)

 This is a very straightforward example, but when I have vectors of different 
 sizes, it will be much more difficult (for me) to create this. Is there an 
 easier way to do this?

 Many thanks in advance,

  -- Stan

        [[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] Can't load package 'lars'

2011-12-06 Thread Uwe Ligges



On 06.12.2011 03:33, Luc Villandre wrote:

Hi,

I installed package 'lars' earlier tonight and did not get any sort of
error message.

###
** building package indices ...
** testing if installed package can be loaded
Loaded lars 0.9-8

* DONE (lars)
###

However, when I try to load it, I get
###
  library(lars, lib.loc = ~/R/x86_64-redhat-linux-gnu-library/2.11)


Are you sure it is installed at the location you specified?

Uwe Ligges




Error : .onLoad failed in loadNamespace() for 'lars', details:
call: cat(Loaded lars, utils::installed.packages()[lars, Version],
error: subscript out of bounds
Error: package/namespace load failed for ‘lars’
###

Session info:

###
  sessionInfo()
R version 2.14.0 (2011-10-31)
Platform: x86_64-redhat-linux-gnu (64-bit)

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

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

loaded via a namespace (and not attached):
[1] rpart_3.1-50 tools_2.14.0
###

I get the same error message when I try to load it on another machine:

###

  library(lars,lib.loc = ~/R/i686-pc-linux-gnu-library/2.12)
Error : .onLoad failed in loadNamespace() for 'lars', details:
call: cat(Loaded lars, utils::installed.packages()[lars, Version],
error: subscript out of bounds
Error: package/namespace load failed for 'lars'
###

Session info:

###
  sessionInfo()
R version 2.13.1 (2011-07-08)
Platform: i686-pc-linux-gnu (32-bit)

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

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

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

Is there at least a way to circumvent the problem?

Thank you for your help,

Luc Villandre

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Paste() - Get all possible combinations from multiple vectors

2011-12-06 Thread andrija djurovic
Hi. Maybe this will help you:

expand.grid(x,y,z)
apply(expand.grid(x,y,z),1, function (x) paste(x[1], x[2], x[3], sep=))

Andrija

On Tue, Dec 6, 2011 at 1:53 PM, Gaj Stan (BIGCAT) 
stan@maastrichtuniversity.nl wrote:

 Hello fellow R-users,

 Given are three vectors and the outcome would be all possible combinations
 in combination with the paste() function.
 For example:

 x - c(1:3)
 y - letters[1:3]
 z - LETTERS[1:3]

 My result would thus be 18 names based on all possible combinations
 between these vectors:
 1 a A 1 a B, 1 a C, 1 b A, 1 b B, 1 b C, 1 c A, 1 c B, 1
 c C, etc.

 To solve the issue above I would use:

 paste(rep(x, each=9), rep(y, each=6), z)

 This is a very straightforward example, but when I have vectors of
 different sizes, it will be much more difficult (for me) to create this. Is
 there an easier way to do this?

 Many thanks in advance,

  -- Stan

[[alternative HTML version deleted]]

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


[[alternative HTML version deleted]]

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


[R] Regression model when dependent variable can only take positive values

2011-12-06 Thread Michael Haenlein
Dear all,

I would like to run a regression of the form lm(y ~ x1+x2) where the
dependent variable y can only take positive values. Assume, for example,
that y is the height of a person (measured in cm), x1 is the gender
(measured as a binary indicator with 0=male and 1=female) and x2 is the age
of the person (measured in years).

When I run a simple lm(y ~ x1+x2), I obtain an intercept value that is
negative. I interpret that in a way that a person who is male (x1=0) and
just born (x2=0), has a negative height. This evidently does not make
sense. I therefore assume that my estimates might be biased and that I need
to use some other form of estimation that takes account of the fact that
y0 for all observations.

Could anybody please tell me which type of regression would be most
recommendable for this type of analysis?

Thanks very much in advance,

Michael

[[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] Summary coefficients give NA values because of singularities

2011-12-06 Thread Uwe Ligges



On 05.12.2011 21:57, Gathurst wrote:

Hello,

I have a data set which I am using to find a model with the most significant
parameters included and most importantly, the p-values.  The full model is
of the form:
   sad[,1]~b_1 sad[,2]+b_2 sad[,3]+b_3 sad[,4]+b_4 sad[,5]+b_5 sad[,6]+b_6
sad[,7]+b_7 sad[,8]+b_8 sad[,9]+b_9 sad[,10],
where the 9 variables on the right hand side are all indicator variables.
The thing I don't understand is the line ' sad[, 10] NA NA
NA   NA ' as a result of 'Coefficients: (1 not defined because of
singularities)'.

I think the output is taking sad[,10] as the intercept, based on previous
attempts at figuring my issue out, which I find a bit wierd considering
sad[,10] is either 0 or 1.  How do I produce the correct output showing all
p-values?


You cannot: sad[,10] is either collinear to one or more of the other 
variables or is constant.


Uwe Ligges






My code and output is as follows:

sad-matrix(1,ncol=11,nrow=486)
sad[,c(1:10)]-d[,2][-357]
sad[,1]-d[,29][-357]
sad[,2][sad[,2]!=1]-0
sad[,3][sad[,3]!=2]-0
sad[,4][sad[,4]!=3]-0
sad[,5][sad[,5]!=4]-0
sad[,6][sad[,6]!=5]-0
sad[,7][sad[,7]!=6]-0
sad[,8][sad[,8]!=7]-0
sad[,9][sad[,9]!=8]-0
sad[,10][sad[,10]!=9]-0
sad[,2][sad[,2]==1]-1
sad[,3][sad[,3]==2]-1
sad[,4][sad[,4]==3]-1
sad[,5][sad[,5]==4]-1
sad[,6][sad[,6]==5]-1
sad[,7][sad[,7]==6]-1
sad[,8][sad[,8]==7]-1
sad[,9][sad[,9]==8]-1
sad[,10][sad[,10]==9]-1
sad

summary(lm(sad[,1]~sad[,2]+sad[,3]
+sad[,4]+sad[,5]+sad[,6]
+sad[,7]+sad[,8]+sad[,9]+sad[,10]))

Call:
lm(formula = sad[, 1] ~ sad[, 2] + sad[, 3] + sad[, 4] + sad[,
 5] + sad[, 6] + sad[, 7] + sad[, 8] + sad[, 9] + sad[, 10])

Residuals:
 Min  1Q  Median  3Q Max
-3.3191 -0.3893  0.0519  0.7436  1.0519

Coefficients: (1 not defined because of singularities)
 Estimate Std. Error t value Pr(|t|)
(Intercept)  4.340910.14495  29.9472e-16 ***
sad[, 2]-0.161420.18128  -0.890   0.3737
sad[, 3]-0.232210.20275  -1.145   0.2527
sad[, 4] 0.178320.19695   0.905   0.3657
sad[, 5] 0.064500.21447   0.301   0.7638
sad[, 6]-0.159090.18713  -0.850   0.3957
sad[, 7]-0.392860.18171  -2.162   0.0311 *
sad[, 8]-0.084500.21146  -0.400   0.6896
sad[, 9]-0.021760.20170  -0.108   0.9141
sad[, 10] NA NA  NA   NA
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

Residual standard error: 0.9615 on 477 degrees of freedom
Multiple R-squared: 0.02984,Adjusted R-squared: 0.01357
F-statistic: 1.834 on 8 and 477 DF,  p-value: 0.06869

Thanks in advance.

--
View this message in context: 
http://r.789695.n4.nabble.com/Summary-coefficients-give-NA-values-because-of-singularities-tp4162113p4162113.html
Sent from the R help mailing list archive at Nabble.com.

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


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


Re: [R] Plot numeric and categorical variable

2011-12-06 Thread Uwe Ligges

On 05.12.2011 23:22, Juliet Ndukum wrote:

My data consists of numeric (yy) and categorical (xx) variables, as shown below.

xx = c(rep(C, 5), rep(D,5))  xx [1] C C C C C D D D D D  
yy = rnorm(10, 0, 4)  yy [1]  2.7219346 -3.7142481  6.8716534 -0.9352463  0.4901249  3.8113247 [7] -2.6602041  1.7714471  4.7298233  0.8848188
xx1 = as.integer(as.factor(xx))  plot(xx1, yy, ylim = c(-13.5, 4), col=blue)

I have attached the plot above  as plot1
I wish to generate a scatter plot of the data such that instead of 1 it prints 
C, and instead of 2, it prints D on the x- axis (see plot1 attached).
How could I possibly go about this, let me know. Any help will be greatly 
appreciated.
Thanks in advance for your help,JN


Sounds like homework?!
Anyway, see ?par and ?axis to answer your question directly or ?boxplot 
more implicitly...


Best,
Uwe Ligges


















__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Regression model when dependent variable can only take positive values

2011-12-06 Thread ONKELINX, Thierry
Dear Michael,

Did you measure newborns? If not center age to a value that makes sense in 
relation with the range of age in your dataset. Then the intercept will be the 
height at the reference age. And most likeli non-negative.

Best regards,

Thierry

ir. Thierry Onkelinx
Instituut voor natuur- en bosonderzoek / Research Institute for Nature and 
Forest
team Biometrie  Kwaliteitszorg / team Biometrics  Quality Assurance
Kliniekstraat 25
1070 Anderlecht
Belgium
thierry.onkel...@inbo.be
www.inbo.be

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

The plural of anecdote is not data.
~ Roger Brinner

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

-Oorspronkelijk bericht-
Van: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] Namens 
Michael Haenlein
Verzonden: dinsdag 6 december 2011 14:09
Aan: r-help@r-project.org
Onderwerp: [R] Regression model when dependent variable can only take positive 
values

Dear all,

I would like to run a regression of the form lm(y ~ x1+x2) where the dependent 
variable y can only take positive values. Assume, for example, that y is the 
height of a person (measured in cm), x1 is the gender (measured as a binary 
indicator with 0=male and 1=female) and x2 is the age of the person (measured 
in years).

When I run a simple lm(y ~ x1+x2), I obtain an intercept value that is 
negative. I interpret that in a way that a person who is male (x1=0) and just 
born (x2=0), has a negative height. This evidently does not make sense. I 
therefore assume that my estimates might be biased and that I need to use some 
other form of estimation that takes account of the fact that
y0 for all observations.

Could anybody please tell me which type of regression would be most 
recommendable for this type of analysis?

Thanks very much in advance,

Michael

[[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] frequency table?

2011-12-06 Thread Sarah Goslee
After that, you might consult the source code for distance() in ecodist.
That function was specifically written to make it easy for people to
add new dissimilarity/similarity metrics, and I think you'll find it helpful
(even if you just extract the bit you need rather than expand the whole
function).

Sarah

On Mon, Dec 5, 2011 at 9:40 PM, B77S bps0...@auburn.edu wrote:
 Set,

 This is the same post as your Similarity Matrix post.

 I'm not trying to be a smart ass here, but ... ?Can you fit a square peg in
 a round hole?... yes, but it doesn't mean it belongs there.

 I suggest you get a piece of paper and a pencil and figure out 1) what you
 are trying to do and why, and 2) how you would do that by hand.  After you
 do that, you should be able to figure this out on your own or formulate a
 question to post that someone will be able to answer.  Reading might help as
 well.



 set wrote

 Hello R-users,

 I've got a file with individuals as colums and the clusters where they
 occur in as rows. And I wanted a table which tells me how many times each
 individual occurs with another. I don't really know how such a table is
 called...it is not a frequency tableMy eventual goal is to make
 Venn-diagrams from the occurence of my individuals.

 So I've this:

 cluster   ind1 ind2 ind3 etc.
 1            0      1     2
 2            3       0    1
 3            1       1     1

 And I want to go to this:
             ind1      ind2      ind3
 ind1      0          4            2
 ind2      4          0            4
 ind3      2           4           1

 is there a way to do this?
 Thank you for your help

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

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


Re: [R] Problem with clusplot

2011-12-06 Thread Sarah Goslee
Well, if I had to guess (and I do, since we have no idea what your data
look like, and calling your data matrix is a very bad idea): you have more
variables than units, so clusplot() can't use princomp() to create a reduced-
dimension plot.

You could roll your own using a different ordination method, or you could
remove some variables from your data, or you could think about whether
the data you have are appropriate for what you're trying to do with them.

Sarah

On Tue, Dec 6, 2011 at 12:58 AM, elisacarli21 elisacarl...@gmail.com wrote:
 Dear all
 I'm trying to run a cluster analysis with R
 Here are the commands:

 mydata - na.omit(matrix) # listwise deletion of missing
 mydata - scale(matrix) # standardize variables

  fit - kmeans(mydata, 8) # 8 cluster solution
  # get cluster means
 aggregate(mydata,by=list(fit$cluster),FUN=mean)
  # append cluster assignment
  mydata - data.frame(mydata, fit$cluster)

  library(cluster)
 clusplot(mydata, fit$cluster, color=TRUE, shade=TRUE,  labels=2, lines=0)


 I get the following error
 Error in princomp.default(x, scores = TRUE, cor = ncol(x) != 2) :
  'princomp' can only be used with more units than variables

 How can I fix it?

 Thanks


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

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


Re: [R] how to view/edit large matrix/array in R?

2011-12-06 Thread j verzani
Michael comtech.usa at gmail.com writes:

 
 head, tail and fix commands don't really work well if I have large
 matrix/array for which I would like to be able to scroll up and dow, left
 and right ...
 
 Could anybody please help me?
 
 Thanks
 
   [[alternative HTML version deleted]]
 
 


You might look into the RGtk2Extras package and find the dfedit. You could
also embed that in some custom GUI to show variables, as you want. The 
package requires RGtk2, and hence the Gtk libraries to be installed. 
The data frame editor there can gracefully handle large data sets.

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

2011-12-06 Thread Sarah Goslee
Not to mention that I answered this exact question only
yesterday.

2011/12/6 Uwe Ligges lig...@statistik.tu-dortmund.de:
 On 05.12.2011 23:22, Juliet Ndukum wrote:

 My data consists of numeric (yy) and categorical (xx) variables, as shown
 below.

 xx = c(rep(C, 5), rep(D,5))  xx [1] C C C C C D D D
 D D  yy = rnorm(10, 0, 4)  yy [1]  2.7219346 -3.7142481  6.8716534
 -0.9352463  0.4901249  3.8113247 [7] -2.6602041  1.7714471  4.7298233
  0.8848188
 xx1 = as.integer(as.factor(xx))  plot(xx1, yy, ylim = c(-13.5, 4),
 col=blue)

 I have attached the plot above  as plot1
 I wish to generate a scatter plot of the data such that instead of 1 it
 prints C, and instead of 2, it prints D on the x- axis (see plot1 attached).
 How could I possibly go about this, let me know. Any help will be greatly
 appreciated.
 Thanks in advance for your help,JN


 Sounds like homework?!
 Anyway, see ?par and ?axis to answer your question directly or ?boxplot more
 implicitly...

 Best,
 Uwe Ligges






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

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


Re: [R] help! what's wrong with setBreakpoint

2011-12-06 Thread Michael
It printed:

c:\R\myproject1\myfile.R#38:
 myfunc1 step  6,4,9 in environment: R_GlobalEnv

What do you think?

Thank you!

On Tue, Dec 6, 2011 at 6:22 AM, Duncan Murdoch murdoch.dun...@gmail.comwrote:

 On 11-12-05 10:32 PM, Michael wrote:

 Hi all,

 I am in the middle of debugging which is stopped using browser()... in
 myfile.R at around line #25.

 I was then stuck in a big loop which I want to escape and stop the program
 at the line after the big loop.

 In the debugging mode, I used

Browse[2]  setBreakpoint(myfile.R#38)


 What did it print?



 I then typed c and ENTER, thinking that it will continue to execute
 until when it comes across line #38 and then stop there...

 But it didn't work - it continued the execution until the end of the
 function, right at the line return(results)...

 What happened? How to solve this problem?


 One of the complications in R is that you can have multiple copies of a
 function in memory.  You may (or may not, what did it print??) have set a
 breakpoint in one copy, then run another.  Or you may have edited that
 function after originally sourcing it, and lost the source reference.

 An alternative to using setBreakpoint is just to edit a call to browser()
 into the function.  It's less convenient, but more robust.

 Duncan Murdoch


 Thanks a lot!

[[alternative HTML version deleted]]

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




[[alternative HTML version deleted]]

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


Re: [R] help! what's wrong with setBreakpoint

2011-12-06 Thread Duncan Murdoch

On 06/12/2011 9:47 AM, Michael wrote:

It printed:

c:\R\myproject1\myfile.R#38:
  myfunc1 step  6,4,9 inenvironment: R_GlobalEnv

What do you think?


So that set a breakpoint in the copy of the function in the global 
environment.  Are you sure you were executing the same function after 
you hit c?  If you were working on code in a package, you may have been 
executing the function in the namespace of the package, not the one in 
the global environment.


If that's not the case, then are you sure you ever got to that line?  
You can see where the breakpoint was set using


body(myfunc1)[[c(6,4,9)]]

(Watch the parens and brackets!)

Duncan Murdoch


Thank you!

On Tue, Dec 6, 2011 at 6:22 AM, Duncan Murdochmurdoch.dun...@gmail.comwrote:

  On 11-12-05 10:32 PM, Michael wrote:

  Hi all,

  I am in the middle of debugging which is stopped using browser()... in
  myfile.R at around line #25.

  I was then stuck in a big loop which I want to escape and stop the program
  at the line after the big loop.

  In the debugging mode, I used

 Browse[2]   setBreakpoint(myfile.R#38)


  What did it print?



  I then typed c and ENTER, thinking that it will continue to execute
  until when it comes across line #38 and then stop there...

  But it didn't work - it continued the execution until the end of the
  function, right at the line return(results)...

  What happened? How to solve this problem?


  One of the complications in R is that you can have multiple copies of a
  function in memory.  You may (or may not, what did it print??) have set a
  breakpoint in one copy, then run another.  Or you may have edited that
  function after originally sourcing it, and lost the source reference.

  An alternative to using setBreakpoint is just to edit a call to browser()
  into the function.  It's less convenient, but more robust.

  Duncan Murdoch


  Thanks a lot!

 [[alternative HTML version deleted]]

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






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

2011-12-06 Thread Dr Gregory Jefferis
Hello,

Does anyone know of an R package that can read Windows BMP format images? Many 
thanks,

Greg Jefferis.
--
Gregory Jefferis, PhD  
Division of Neurobiology   
MRC Laboratory of Molecular Biology,   
Hills Road,
Cambridge, CB2 0QH, UK.

http://www2.mrc-lmb.cam.ac.uk/group-leaders/h-to-m/g-jefferis 
http://www.neuroscience.cam.ac.uk/directory/profile.php?gsxej2
http://flybrain.stanford.edu

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

2011-12-06 Thread Thomas
I would like to write some data to different files. I can create the  
filename Day1.txt like this:


filen - paste(Day, l, .txt, sep=)

and then I'm using a For loop to write out one row of a matrix,  
something like this:


For (j in 1:10)
{
cat(mat[1,j], ,, file=filen, append=TRUE)
}
cat(\n, file=filen, append=TRUE)

but is there a better way to do this?

Thank you,

Thomas

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

2011-12-06 Thread threshold
Dear R Users,

given that:

 AggDateTime[960:962]
[1] 2011-08-25 23:59:00 BST 2011-08-26 00:00:00 BST
[3] 2011-08-26 00:01:00 BST


 unlist(strsplit(as.character(AggDateTime[960]), , fixed=TRUE))
[1] 2011-08-25 23:59:00  
 unlist(strsplit(as.character(AggDateTime[962]), , fixed=TRUE))
[1] 2011-08-26 00:01:00

Why no time here?
 unlist(strsplit(as.character(AggDateTime[961]), , fixed=TRUE))
[1] 2011-08-26


best, robert




--
View this message in context: 
http://r.789695.n4.nabble.com/split-date-nad-time-tp4164191p4164191.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] MAC Problem with http in R while not problem on Win machine

2011-12-06 Thread Martin Bauer
Hello,

thanks to (http://timelyportfolio.blogspot.com/) and also 
(http://systematicinvestor.wordpress.com) the following code was published and 
it is running smoothly on my Windows enviroment but it is failing to perform on 
my MAC.

#get MAImp code from GIST
#thanks to http://systematicinvestor.wordpress.com
#for showing me how to do this
con=url(https://raw.github.com/gist/1405187/92e7c24ff2459a0830c45b828f1dba41143e9436/MAImp.r;)
source(con)

the error code is the following
Error in source(con) : cannot open the connection
In addition: Warning message:
In source(con) : unsupported URL scheme

How can I amend the code that it will also work on my MAC ?

many thanks

martin
--

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


Re: [R] LaTeX output for summary.lm object - while displaying the information outside the table

2011-12-06 Thread jose Bartolomei


Hi,Yes, you can use all values within the object For example, data(airquality)
obj.lm - summary(lm(Temp~Ozone, airquality))
names(obj.lm)
 [1] call  terms residuals coefficients  aliased  
 sigma
 [7] dfr.squared adj.r.squared fstatistic
cov.unscaled  na.action obj.lm$r.squared [1] 0.4877072 Then you have 
to manage the info to set the table as you want. I use latex() function from 
Hmisc package Best,
Jose 
  From: tal.gal...@gmail.com
 Date: Sun, 4 Dec 2011 16:57:51 +0200
 To: r-help@r-project.org
 Subject: [R] LaTeX output for summary.lm object - while displaying the 
 information outside the table
 
 This seemed to me to be basic, but I can't seem to find a solution online,
 so I wondered what I might be missing.
 
 I wish to include the output of an lm summary object inside an Sweave
 (.Rnw) document. I can either output the summary.lm as is, or use the
 xtable/Hmisc packages (through xtable or latex commands).
 
 Is there something like xtable that also gives the summary information
 which is available from outside the table? (
 
 R2, F statistics etc...?)
 Thanks.
 
 
 Contact
 Details:---
 Contact me: tal.gal...@gmail.com |  972-52-7275845
 Read me: www.talgalili.com (Hebrew) | www.biostatistics.co.il (Hebrew) |
 www.r-statistics.com (English)
 --
 
   [[alternative HTML version deleted]]
 
 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.
  
[[alternative HTML version deleted]]

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


[R] the estimated random effects for each level of grouping

2011-12-06 Thread stat999
Hi, I am a quite beginner of random effect modelling.
Sorry for my ignorant question.

My question is about the values of lme function.
It returns coefficients which is a list with two components.
The R-help file says that it returns the estimated random effects for each
level of grouping.

What is the estimator of this random effects in R?
 
Since the random effects are random variables so this estimate should be
something like mean or mode of the density of the random effect given data,
f_i(b_i|y_i)



--
View this message in context: 
http://r.789695.n4.nabble.com/the-estimated-random-effects-for-each-level-of-grouping-tp4164111p4164111.html
Sent from the R help mailing list archive at Nabble.com.

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


[R] [R-pkgs] pls 2.3.0 released

2011-12-06 Thread Bjørn-Helge Mevik
Version 2.3.0 of the pls package has been released.  The pls package
implements Partial Least Squares Regression and Principal Component
Regression.

The major changes are:

- New analysis method Canonical Powered PLS (CPPLS) implmemented.  See
  ?cppls.fit.

- coefplot() can now plot whiskers at +/-1 SE (since 2.2.0).  See ?coefplot

- The package now has a name space (since 2.2.0).

-- 
Regards,
Bjørn-Helge Mevik

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


[R] HTML Forms to R

2011-12-06 Thread vioravis
I have currently a R function that reads a csv file, does some computations,
produces some plots and writes a csv file as output. I would like to use
HTML forms to make a user interface for calling appropriate parts of the
functions (reading csv file, doing computations, displaying plots and
writing csv files). 

Are there are tutorials available that would help me get started?? 

Thank you.

Ravi

--
View this message in context: 
http://r.789695.n4.nabble.com/HTML-Forms-to-R-tp4164360p4164360.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] a question on autocorrelation acf

2011-12-06 Thread Bazman76
http://r.789695.n4.nabble.com/file/n4164630/R_example.xlsx R_example.xlsx 

Hi there,

I attach an excel file which I use to produce the data.

It simulates a simple AR(1) process y_t=0.5y_{t-1}+z_t.

In column E I have cut and paste values so that we can compare like with
like. 

When I run the acf() on these values, it shows 3 significant lags.

When I run the pacf() it shows one very strong correlation of 0.3 at lag 1,
and a smaller one at lag 2 of around 0.05. 

Now according to the theory the pacf() results should give the correct
exponents for the lags. 
This is a pure AR(1) process so the results should be 0.5 on lag 1 and
statistically insignificant else where?

I have tried if for several realisations of the white noise term and the
results are qualatively similar and is disagreement with the theory.


Kind Regards

Baz

--
View this message in context: 
http://r.789695.n4.nabble.com/a-question-on-autocorrelation-acf-tp2076280p4164630.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] Writing out in loops

2011-12-06 Thread Sarah Goslee
Is there some reason you can't create the entire file in R and then write it
out in a single step?

It looks like you're writing out
mat[1, 1:10]
so you could just use
write.table(mat[1, 1:10], filen)

Can you expand on what you're trying to do?

Sarah

On Tue, Dec 6, 2011 at 4:18 AM, Thomas chesney@gmail.com wrote:
 I would like to write some data to different files. I can create the
 filename Day1.txt like this:

 filen - paste(Day, l, .txt, sep=)

 and then I'm using a For loop to write out one row of a matrix, something
 like this:

 For (j in 1:10)
 {
 cat(mat[1,j], ,, file=filen, append=TRUE)
 }
 cat(\n, file=filen, append=TRUE)

 but is there a better way to do this?

 Thank you,

 Thomas



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

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


Re: [R] How to automate the detection of break points for use in cut

2011-12-06 Thread Sébastien Bihorel
I forgot to post my reply to Duncan's response on the list.

On Tue, Dec 6, 2011 at 7:56 AM, Sébastien Bihorel pomc...@free.fr wrote:

 Thanks for the link Duncan,

 Given the number of methods and links listed in the Cluster task view,
 things are looking a bit more complex than I thought... I'll have to read
 more about clustering before I can start testing.

 Sebastien


 On Tue, Dec 6, 2011 at 7:28 AM, Duncan Murdoch 
 murdoch.dun...@gmail.comwrote:

 On 11-12-06 3:34 AM, Sébastien Bihorel wrote:

 Obviously, cut would do the job if one knows the number of intervals in
 advance, which I assume I won't. I guess what I'm looking for is a
 function
 that figures out the number of intervals and their boundaries.


 That's not really a simple problem, but there are functions that do
 clustering and fit mixture models to data, which might be close enough.
  See the Cluster task view at http://cran.r-project.org/web/**
 views/Cluster.html http://cran.r-project.org/web/views/Cluster.html.

 Duncan Murdoch


 Sebastien

 On Tue, Dec 6, 2011 at 3:29 AM, Sébastien Bihorelpomc...@free.fr
  wrote:

  Dear R-users,

 I would like to know if there is a function (in base R or the extension
 packages) that would automatically detect the break points in a vector x
 for later use in the cut function. The idea is to determine the
 boundaries
 of the n intervals (n=1) delimiting clusters of data points which
 could be
 considered reasonably close, given a numerical vector x with unknown
 content and unknown multimodal distribution.

 For instance, given for the vector x defined by set.seed(1234); x-
 sort(c(rnorm(20,-1,0.1),rnorm(
 10,5,0.1),rnorm(10,100,0.1))), this function would return a vector of 4
 points: min(x), one value between 20 and 5, one value between 5 and 100,
 and max(x).

 Thank you in advance for your suggestions.

 Sebastien


[[alternative HTML version deleted]]




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





[[alternative HTML version deleted]]

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


Re: [R] Argument validation within functions

2011-12-06 Thread Johannes Radinger
Thank you, i didn't know that the !operator is
also working for is.numeric etc.

Anyway I want to test if an argument is set in the
function call and if not a code is executed... So 
far I tried:

f -function(a,b){
if(!exists(b)) print(exists: b is not set)
if(is.null(b)) print(is.null : b is not set)
}

f(a=1,b=2)
f(a=1)
f(b=2)

I don't really know how to do it...e.g: for f(a=1) b is not set
so it also can't be NULL (thats why is.null is not working). I
just want to test if it is set with the function call not outside
the function or before etc.

/Johannes

 Original-Nachricht 
 Datum: Tue, 6 Dec 2011 07:57:44 -0500
 Von: R. Michael Weylandt michael.weyla...@gmail.com
 An: r-help r-help@r-project.org, Johannes Radinger jradin...@gmx.at
 Betreff: Re: [R] Argument validation within functions

 Use the ! (not) operator.
 
 Not sure what you mean by  as the stop() stops the total function:
 try the following
 
 f - function(a){
    stopifnot(a  3)
    return(a^2)
 }
 
 f(2)
 f(4)
 
 Michael
 
 (PS -- It's usually asked to cc the list so that this all gets
 threaded properly in folks' mailboxes)
 
 On Tue, Dec 6, 2011 at 7:46 AM, Johannes Radinger jradin...@gmx.at
 wrote:
  Hi,
 
  thank you... I think I will go for the if-stop approach
  as the stop() stops the total function... So there is just
  one little other question: What is the opposite of is.numeric?
  Is ther isnot.numeric? How  can that be implemented in following
  function:
 
  f - function(a){
         if(is.numeric(a)) stop(a is not numeric)
         if(0  a  a  1) stop(a must be a value between 0 and 1)
         a
  }
 
  /Johannes
 
   Original-Nachricht 
  Datum: Tue, 6 Dec 2011 07:04:59 -0500
  Von: R. Michael Weylandt michael.weyla...@gmail.com
  An: Johannes Radinger jradin...@gmx.at
  CC: r-help@r-project.org
  Betreff: Re: [R] Argument validation within functions
 
  The quick and dirty way to do so is to use: stopifnot() in conjunction
  (if necessary with all() and any()). You can replace that first
  condition with a simple is.numeric() as well. A more helpful way (if
  this is production code) is to use if statement with the stop()
  function directly which lets you provide specific error messages.
 
  Michael
 
  On Tue, Dec 6, 2011 at 6:41 AM, Johannes Radinger jradin...@gmx.at
  wrote:
   Hi,
  
   I just started with writing functions in R and so some questions
 popped
  up.
   I provide some values as argument to my function such as:
  
   function(a,b,c){}
  
   Now i want that the function first checks if the arguments are valid
 for
  the function. E.g argument a has to be a number in the range 0-1. How
  can that easily done?
  
   So far I have:
  
          a - as.numeric(a)
          if(0 = a  a = 1)
  
   to first check if a is a number...if not the function stops and gives
 an
  error message. If it is a number it just continues...
  
   But how to check the range?
   Above there is the if-approach but then the rest of the function is
  exectued as part of if (or else). Is there a simpler way without having
 the
  if-brackets around the remaining code?
   Just a check if the value is between 0 and 1 and if yes continue with
  the next line if no abort the function with a error message? How can
 such an
  error message be created?
  
   thank you and best regards,
  
   /Johannes
   --
  
   __
   R-help@r-project.org mailing list
   https://stat.ethz.ch/mailman/listinfo/r-help
   PLEASE do read the posting guide
  http://www.R-project.org/posting-guide.html
   and provide commented, minimal, self-contained, reproducible code.
 
  --
  NEU: FreePhone - 0ct/min Handyspartarif mit Geld-zurück-Garantie!
  Jetzt informieren: http://www.gmx.net/de/go/freephone

--

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

2011-12-06 Thread Berwin A Turlach
G'day Johannes,

On Tue, 06 Dec 2011 16:15:21 +0100
Johannes Radinger jradin...@gmx.at wrote:

 Thank you, i didn't know that the !operator is
 also working for is.numeric etc.
 
 Anyway I want to test if an argument is set in the
 function call and if not a code is executed... So 
 far I tried:
 
 f -function(a,b){
   if(!exists(b)) print(exists: b is not set)
   if(is.null(b)) print(is.null : b is not set)
 }
 
 f(a=1,b=2)
 f(a=1)
 f(b=2)
 
 I don't really know how to do it...e.g: for f(a=1) b is not set
 so it also can't be NULL (thats why is.null is not working). I
 just want to test if it is set with the function call not outside
 the function or before etc.

?missing

Cheers,

Berwin

== Full address 
A/Prof Berwin A Turlach   Tel.: +61 (8) 6488 3338 (secr)
School of Maths and Stats (M019)+61 (8) 6488 3383 (self)
The University of Western Australia   FAX : +61 (8) 6488 1028
35 Stirling Highway   
Crawley WA 6009e-mail: berwin.turl...@gmail.com
Australiahttp://www.maths.uwa.edu.au/~berwin

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


Re: [R] Problem in while loop

2011-12-06 Thread Gyanendra Pokharel
Yes Michael, it works well and I got the result what I want but it totally
depends on how reliable result do I want. When I take very high rho (near
about 1) and very low psi, it takes very long time may be it gives us more
accurate result. But for lower rho and higher psi, it gives immediately,
and very poor result. Now as I asked before, how I can get the plot of a
versus s which determines the cooling curve with the global minimum of s
at a specific value of a.

On Tue, Dec 6, 2011 at 6:52 AM, R. Michael Weylandt 
michael.weyla...@gmail.com wrote:

 So I just ran your code verbatim with this one change and it finished
 in less than 10 seconds. However, even without the change it doesn't
 take more than 15 seconds: what exactly lead you to believe this was
 an infinite loop?

 Michael

 On Tue, Dec 6, 2011 at 12:03 AM, R. Michael Weylandt
 michael.weyla...@gmail.com michael.weyla...@gmail.com wrote:
  Off the bat I'd suggest you vectorize loglikelihood as a simple one
 liner:
 
  sum(log(b^2 + (x-a)^2))
 
  That alone will speed up your function many times over: I'll look at the
 big
  function in more detail tomorrow.
 
  Michael
 
  On Dec 5, 2011, at 10:37 PM, Gyanendra Pokharel
  gyanendra.pokha...@gmail.com wrote:
 
  Thanks Michael
  Lets figure out the problem by using the following function. I found the
  same problem in this code too.
 
 
  loglikehood - function(a, b = 0.1, x = c(-4.2, -2.85, -2.3, -1.02, 0.7,
  0.98, 2.72, 3.5))
 
  {
 
  s - 0
 
  for(i in 1:length(x)){
 
  s - s + log(b^2 + (x[i] - a)^2)
 
  }
 
  s
 
  }
 
  loglikelihood(0.1)
 
  simann - function(T0 = 1, N = 500, rho = 0.9, x0 = 0, eps = 0.1, f){
 
  moving - 1
 
  count - 0
 
  Temp - T0
 
  x - x0
 
  while(moving  0){
 
  moving - 0
 
  for(i in 1:N){
 
  y - x + runif(1,-eps,eps)
 
  alpha - min(1,exp((f(x) -f(y))/Temp))
 
  if(runif(1)alpha){
 
  moving - moving +1
 
  x - y
 
  }
 
  }
 
  Temp - Temp*rho
 
  count - count + 1
 
  }
 
  fmin - f(x)
 
  return(c(x,fmin,count))
 
  }
 
  simann(f = loglikelihood)
 
  I hope we can analyze every problems from this function
 
  On Mon, Dec 5, 2011 at 10:27 PM, R. Michael Weylandt
  michael.weyla...@gmail.com michael.weyla...@gmail.com wrote:
 
  It's not necessarily equivalent to your loglikelihood function but
 since
  that function wasn't provided I couldn't test it.
 
  My broader point is this: you said the problem was that the loop ran
  endlessly: I showed it does not run endlessly for at least one input so
 at
  least part of the problem lies in loglikelihood, which, being
 unprovided, I
  have trouble replicating.
 
  My original guess still stands: it's either 1) a case of you getting
 stuck
  at probaccept = 1 or 2) so slow it just feels endless.  Either way, my
  prescription is the same: print()
 
  Michael
 
 
  On Dec 5, 2011, at 9:30 PM, Gyanendra Pokharel
  gyanendra.pokha...@gmail.com wrote:
 
  Yes, your function out- epiann(f = function(a,b)
 log(dnorm(a)*dnorm(b))),
  N = 10) works well.
 
  But why you are changing the loglikelihood function to f = function(a,b)
  log(dnorm(a)*dnorm(b))? how it is equivalent to loglikelihood? is there
 any
  mathematical relation?  I also want to see the plot of aout and bout
 versus
  loglikelihood, and see the cooling rate in different temperature. how is
  this possible?
 
  On Mon, Dec 5, 2011 at 6:07 PM, R. Michael Weylandt
  michael.weyla...@gmail.com wrote:
 
  If you run
 
  out- epiann(f = function(a,b) log(dnorm(a)*dnorm(b))), N = 10)
 
  It takes less than 0.5 seconds so there's no problem I can see:
  perhaps you want to look elsewhere to get better speed (like Rcpp or
  general vectorization), or maybe your loglikihood is not what's
  desired, but there's no problem with the loop.
 
  Michael
 
  On Mon, Dec 5, 2011 at 5:29 PM, Gyanendra Pokharel
  gyanendra.pokha...@gmail.com wrote:
   Yes, I checked the acceptprob, it is very high but in my view, the
   while
   loop is not stopping, so there is some thing wrong in the use of
 while
   loop.
   When I removed the while loop, it returned some thing but not the
   result
   what I want. When i run the while loop separately, it never stops.
  
  
  
   On Mon, Dec 5, 2011 at 5:18 PM, R. Michael Weylandt
   michael.weyla...@gmail.com wrote:
  
   Your code is not reproducible nor minimal, but why don't you put a
   command print(acceptprob) in and see if you are getting reasonable
   values. If these values are extremely low it shouldn't surprise you
   that your loop takes a long time to run.
  
   More generally, read up on the use of print() and browser() as
   debugging
   tools.
  
   Michael
  
   On Mon, Dec 5, 2011 at 3:47 PM, Gyanendra Pokharel
   gyanendra.pokha...@gmail.com wrote:
I forgot to upload the R-code in last email, so heare is one
   
epiann - function(T0 = 1, N=1000, ainit=1, binit=1,rho = 0.99,
amean =
3,
bmean=1.6, avar =.1, bvar=.1, f){
   
   moving - 1
   count - 0
   Temp - T0
   

Re: [R] Argument validation within functions

2011-12-06 Thread Enrico Schumann


you may be looking for ?missing

f - function(a,b) {
if (missing(b)) print(b is missing)
}

f(a=1, b=2)
f(a=1)
f(b=2)

Regards,
Enrico

Am 06.12.2011 16:15, schrieb Johannes Radinger:

Thank you, i didn't know that the !operator is
also working for is.numeric etc.

Anyway I want to test if an argument is set in the
function call and if not a code is executed... So
far I tried:

f-function(a,b){
if(!exists(b)) print(exists: b is not set)
if(is.null(b)) print(is.null : b is not set)
}

f(a=1,b=2)
f(a=1)
f(b=2)

I don't really know how to do it...e.g: for f(a=1) b is not set
so it also can't be NULL (thats why is.null is not working). I
just want to test if it is set with the function call not outside
the function or before etc.

/Johannes

 Original-Nachricht 

Datum: Tue, 6 Dec 2011 07:57:44 -0500
Von: R. Michael Weylandtmichael.weyla...@gmail.com
An: r-helpr-help@r-project.org, Johannes Radingerjradin...@gmx.at
Betreff: Re: [R] Argument validation within functions



Use the ! (not) operator.

Not sure what you mean by  as the stop() stops the total function:
try the following

f- function(a){
stopifnot(a  3)
return(a^2)
}

f(2)
f(4)

Michael

(PS -- It's usually asked to cc the list so that this all gets
threaded properly in folks' mailboxes)

On Tue, Dec 6, 2011 at 7:46 AM, Johannes Radingerjradin...@gmx.at
wrote:

Hi,

thank you... I think I will go for the if-stop approach
as the stop() stops the total function... So there is just
one little other question: What is the opposite of is.numeric?
Is ther isnot.numeric? How  can that be implemented in following
function:

f- function(a){
if(is.numeric(a)) stop(a is not numeric)
if(0  a  a  1) stop(a must be a value between 0 and 1)
a
}

/Johannes

 Original-Nachricht 

Datum: Tue, 6 Dec 2011 07:04:59 -0500
Von: R. Michael Weylandtmichael.weyla...@gmail.com
An: Johannes Radingerjradin...@gmx.at
CC: r-help@r-project.org
Betreff: Re: [R] Argument validation within functions



The quick and dirty way to do so is to use: stopifnot() in conjunction
(if necessary with all() and any()). You can replace that first
condition with a simple is.numeric() as well. A more helpful way (if
this is production code) is to use if statement with the stop()
function directly which lets you provide specific error messages.

Michael

On Tue, Dec 6, 2011 at 6:41 AM, Johannes Radingerjradin...@gmx.at
wrote:

Hi,

I just started with writing functions in R and so some questions

popped

up.

I provide some values as argument to my function such as:

function(a,b,c){}

Now i want that the function first checks if the arguments are valid

for

the function. E.g argument a has to be a number in the range 0-1. How
can that easily done?


So far I have:

a- as.numeric(a)
if(0= a  a= 1)

to first check if a is a number...if not the function stops and gives

an

error message. If it is a number it just continues...


But how to check the range?
Above there is the if-approach but then the rest of the function is

exectued as part of if (or else). Is there a simpler way without having

the

if-brackets around the remaining code?

Just a check if the value is between 0 and 1 and if yes continue with

the next line if no abort the function with a error message? How can

such an

error message be created?


thank you and best regards,

/Johannes
--

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide

http://www.R-project.org/posting-guide.html

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


--
NEU: FreePhone - 0ct/min Handyspartarif mit Geld-zurück-Garantie!
Jetzt informieren: http://www.gmx.net/de/go/freephone


--

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


--
Enrico Schumann
Lucerne, Switzerland
http://nmof.net/

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


[R] About summary in linear models

2011-12-06 Thread Otto F. Wagner
Hello!!, for linear models fit I use Gretl, but now I'm starting to use R,
I would like to know if is there some function to obtain a extended summary
like in Gretl.

I will write a example in Gretl


Modelo 1: MCO, usando las observaciones 1968-1982 (T = 15)

Variable dependiente: Invest


Coeficient

St error

t-ratio

p-value



const

377,631

35,0955

10,7601

0,1

***

GNP

0,63612

0,055015

11,5627

0,1

***

CPI

-9,70228

0,913737

-10,6182

0,1

***

Interest

-0,941363

2,21077

-0,4258

0,67927



time

8,49182

3,18142

2,6692

0,02353

**



Average of Dep Var.

 276,0067


St Error Dep. Var

 117,5827

Squared Sum of remainders

 818,6362



Regression standar error

 9,047852

R^2

 0,995771



R^2 adj

 0,994079

F(4, 10)

 588,6040



p-value (de F)

 8,09e-12

Log-likelihood

-51,28100



Akaike

 112,5620

Schwarz

 116,1023



Hannan-Quinn

 112,5243

rho

-0,440663



Durbin-Watson

 2,757428


Like you can see Gretl shows more statisticas.

The same model in R:

Call:
lm(formula = Invest ~ CPI + GNP + Interest + Year, data = Tabla6_3)

Residuals:
Min  1Q  Median  3Q Max
-16.397  -3.864   1.391   4.219  15.779

Coefficients:
  Estimate Std. Error t value Pr(|t|)
(Intercept) -1.633e+04  6.250e+03  -2.612   0.0260 *
CPI -9.702e+00  9.137e-01 -10.618 9.15e-07 ***
GNP  6.361e-01  5.502e-02  11.563 4.14e-07 ***
Interest-9.414e-01  2.211e+00  -0.426   0.6793
Year 8.492e+00  3.181e+00   2.669   0.0235 *
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Thanks so much,

Otto

[[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] Argument validation within functions

2011-12-06 Thread Bert Gunter
On Tue, Dec 6, 2011 at 7:15 AM, Johannes Radinger jradin...@gmx.at wrote:
 Thank you, i didn't know that the !operator is
 also working for is.numeric etc.

Read (more carefully?) R docs, please. ! is a unary function that
takes a logical argument(and will coerce to logical nonlogical
arguments if it can); is.numeric() returns a logical, so of course it
should work. Ergo your failure to understand indicates a fundamental
hole in your understanding of how R works.

-- Bert


 Anyway I want to test if an argument is set in the
 function call and if not a code is executed... So
 far I tried:

 f -function(a,b){
        if(!exists(b)) print(exists: b is not set)
        if(is.null(b)) print(is.null : b is not set)
 }

 f(a=1,b=2)
 f(a=1)
 f(b=2)

 I don't really know how to do it...e.g: for f(a=1) b is not set
 so it also can't be NULL (thats why is.null is not working). I
 just want to test if it is set with the function call not outside
 the function or before etc.

 /Johannes

  Original-Nachricht 
 Datum: Tue, 6 Dec 2011 07:57:44 -0500
 Von: R. Michael Weylandt michael.weyla...@gmail.com
 An: r-help r-help@r-project.org, Johannes Radinger jradin...@gmx.at
 Betreff: Re: [R] Argument validation within functions

 Use the ! (not) operator.

 Not sure what you mean by  as the stop() stops the total function:
 try the following

 f - function(a){
    stopifnot(a  3)
    return(a^2)
 }

 f(2)
 f(4)

 Michael

 (PS -- It's usually asked to cc the list so that this all gets
 threaded properly in folks' mailboxes)

 On Tue, Dec 6, 2011 at 7:46 AM, Johannes Radinger jradin...@gmx.at
 wrote:
  Hi,
 
  thank you... I think I will go for the if-stop approach
  as the stop() stops the total function... So there is just
  one little other question: What is the opposite of is.numeric?
  Is ther isnot.numeric? How  can that be implemented in following
  function:
 
  f - function(a){
         if(is.numeric(a)) stop(a is not numeric)
         if(0  a  a  1) stop(a must be a value between 0 and 1)
         a
  }
 
  /Johannes
 
   Original-Nachricht 
  Datum: Tue, 6 Dec 2011 07:04:59 -0500
  Von: R. Michael Weylandt michael.weyla...@gmail.com
  An: Johannes Radinger jradin...@gmx.at
  CC: r-help@r-project.org
  Betreff: Re: [R] Argument validation within functions
 
  The quick and dirty way to do so is to use: stopifnot() in conjunction
  (if necessary with all() and any()). You can replace that first
  condition with a simple is.numeric() as well. A more helpful way (if
  this is production code) is to use if statement with the stop()
  function directly which lets you provide specific error messages.
 
  Michael
 
  On Tue, Dec 6, 2011 at 6:41 AM, Johannes Radinger jradin...@gmx.at
  wrote:
   Hi,
  
   I just started with writing functions in R and so some questions
 popped
  up.
   I provide some values as argument to my function such as:
  
   function(a,b,c){}
  
   Now i want that the function first checks if the arguments are valid
 for
  the function. E.g argument a has to be a number in the range 0-1. How
  can that easily done?
  
   So far I have:
  
          a - as.numeric(a)
          if(0 = a  a = 1)
  
   to first check if a is a number...if not the function stops and gives
 an
  error message. If it is a number it just continues...
  
   But how to check the range?
   Above there is the if-approach but then the rest of the function is
  exectued as part of if (or else). Is there a simpler way without having
 the
  if-brackets around the remaining code?
   Just a check if the value is between 0 and 1 and if yes continue with
  the next line if no abort the function with a error message? How can
 such an
  error message be created?
  
   thank you and best regards,
  
   /Johannes
   --
  
   __
   R-help@r-project.org mailing list
   https://stat.ethz.ch/mailman/listinfo/r-help
   PLEASE do read the posting guide
  http://www.R-project.org/posting-guide.html
   and provide commented, minimal, self-contained, reproducible code.
 
  --
  NEU: FreePhone - 0ct/min Handyspartarif mit Geld-zurück-Garantie!
  Jetzt informieren: http://www.gmx.net/de/go/freephone

 --

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



-- 

Bert Gunter
Genentech Nonclinical Biostatistics

Internal Contact Info:
Phone: 467-7374
Website:
http://pharmadevelopment.roche.com/index/pdb/pdb-functional-groups/pdb-biostatistics/pdb-ncb-home.htm

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

2011-12-06 Thread Michael
I am not sure...

How do I make sure about that?

esp  Are you sure you were executing the same function after you hit c??

Thanks again!

On Tue, Dec 6, 2011 at 8:57 AM, Duncan Murdoch murdoch.dun...@gmail.comwrote:

 On 06/12/2011 9:47 AM, Michael wrote:

 It printed:

 c:\R\myproject1\myfile.R#38:
  myfunc1 step  6,4,9 inenvironment: R_GlobalEnv

 What do you think?


 So that set a breakpoint in the copy of the function in the global
 environment.  Are you sure you were executing the same function after you
 hit c?  If you were working on code in a package, you may have been
 executing the function in the namespace of the package, not the one in the
 global environment.

 If that's not the case, then are you sure you ever got to that line?  You
 can see where the breakpoint was set using

 body(myfunc1)[[c(6,4,9)]]

 (Watch the parens and brackets!)

 Duncan Murdoch

  Thank you!

 On Tue, Dec 6, 2011 at 6:22 AM, Duncan 
 Murdochmurdoch.duncan@gmail.**commurdoch.dun...@gmail.com
 wrote:

   On 11-12-05 10:32 PM, Michael wrote:
 
   Hi all,
 
   I am in the middle of debugging which is stopped using browser()...
 in
   myfile.R at around line #25.
 
   I was then stuck in a big loop which I want to escape and stop the
 program
   at the line after the big loop.
 
   In the debugging mode, I used
 
  Browse[2]   setBreakpoint(myfile.R#38)
 
 
   What did it print?
 
 
 
   I then typed c and ENTER, thinking that it will continue to
 execute
   until when it comes across line #38 and then stop there...
 
   But it didn't work - it continued the execution until the end of the
   function, right at the line return(results)...
 
   What happened? How to solve this problem?
 
 
   One of the complications in R is that you can have multiple copies of a
   function in memory.  You may (or may not, what did it print??) have
 set a
   breakpoint in one copy, then run another.  Or you may have edited that
   function after originally sourcing it, and lost the source reference.
 
   An alternative to using setBreakpoint is just to edit a call to
 browser()
   into the function.  It's less convenient, but more robust.
 
   Duncan Murdoch
 
 
   Thanks a lot!
 
  [[alternative HTML version deleted]]
 
   __
   R-help@r-project.org mailing list
   
  https://stat.ethz.ch/mailman/listinfo/r-helphttps://stat.ethz.ch/mailman/**listinfo/r-help
 https://stat.**ethz.ch/mailman/listinfo/r-**helphttps://stat.ethz.ch/mailman/listinfo/r-help
 
   PLEASE do read the posting guide 
  http://www.R-project.org/**http://www.r-project.org/**
   
  posting-guide.htmlhttp://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] split date nad time

2011-12-06 Thread David Winsemius


On Dec 6, 2011, at 5:38 AM, threshold wrote:


Dear R Users,

given that:


AggDateTime[960:962]

[1] 2011-08-25 23:59:00 BST 2011-08-26 00:00:00 BST
[3] 2011-08-26 00:01:00 BST



unlist(strsplit(as.character(AggDateTime[960]), , fixed=TRUE))

[1] 2011-08-25 23:59:00

unlist(strsplit(as.character(AggDateTime[962]), , fixed=TRUE))

[1] 2011-08-26 00:01:00

Why no time here?

unlist(strsplit(as.character(AggDateTime[961]), , fixed=TRUE))

[1] 2011-08-26


The real question should be:  why you didn't post the results of :

 dput(AggDateTime[960:962])

--

David Winsemius, MD
West Hartford, CT

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


[R] mfp package - can I exclude some powers?

2011-12-06 Thread Eleni Rapsomaniki
Hi,

The mfp package suggests fractional polynomial transformations for
non-linear predictors. For continuous variables that take negative values
the suggested transformations tend to look ugly, e.g. if x1 is the
original variable it is transformed to something like: (x1+5.67)^1 *
log(x1+5.67), where 5.67 is the shift to make it positive.
Can I somehow modify the mfp function to exclude some powers among those
tried (e.g. those involving log and 0.5). I am willing to sacrifice some
precision for a more interpretable transformation.

Or is there another package to do something similar?

Any suggestions very much appreciated!
Eleni

Medical Statistician
Epidemiology  Public Health
University College London, UK

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


[R] axis thickness in plot()

2011-12-06 Thread AlexC
Hello, 

I am trying to increase the thickness of the axis in plot() without
reverting to the use of paint programs

i see posts on that topic for the xyplot function but want to see if i can
do it with plot() because i've already setup my graph script using that

i thought i could use axis() function and specify lwd=thickness or
lwd.axis= but that does not work like it does for lwd.ticks

If anyone has an idea, sincerely

heres the script

windows(width=7,height=7)
plot(data$Winter,data$NbFirstBroods,ylab=number of breeding
pairs,xlab=winter
harshness,cex=1.5,cex.lab=1.5,cex.axis=1.5,font.axis=2,axes=FALSE)
points(data$Winter,data$NbFirstBroods,cex=1.5,col=black,pch=19)
abline(lm(data$NbFirstBroods~data$Winter),col=red,lwd=4)

i tried axis(1, lwd.axis = 3,lwd.ticks=3) for example

also when adding the y axis axis(2...) x and y axes are disconnected

Thank you for your kind help in advance, 

Alexandre 

--
View this message in context: 
http://r.789695.n4.nabble.com/axis-thickness-in-plot-tp4165430p4165430.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] split date nad time

2011-12-06 Thread threshold

ok, 

 dput(AggDateTime[960:962]) 
structure(c(1314313140L, 1314313200L, 1314313260L), class = c(POSIXct, 
POSIXt), tzone = )

--
View this message in context: 
http://r.789695.n4.nabble.com/split-date-nad-time-tp4164191p4165378.html
Sent from the R help mailing list archive at Nabble.com.

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


[R] help wrapping findInterval into a function

2011-12-06 Thread Steve E.
Dear R Community,

I hope you might be able to assist with a small problem creating a function. 
I am working with water-quality data sets that contain the concentration of
many different elements in water samples.  I need to assign quality-control
flags to values that fall into various concentration ranges.  Rather than a
web of nested if statements, I am employing the findInterval function to
identify values that need to be flagged and to assign the appropriate flag. 
The data consist of a sample identifier, the analysis, and corresponding
value.  The findInterval function works well; however, I would like to
incorporate it into a function so that I can run multiple findInterval
functions for many different water-quality analyses (and I have to do this
for many dataset) but it seems to fall apart when incorporated into a
function.

Run straighforward, the findInterval function works as desired, e.g. below,
creating the new CalciumFlag column with the appropriate flag for, in this
case, levels of calcium in the water:

WQdata$CalciumFlag - with(WQdata, ifelse(analysis == Calcium, (flags -
c(Y, 'Q', , A) [findInterval(WQdata$value, c(-Inf, 0.027, 0.1, 100,
Inf))]),))

However, it does not worked when wrapped in a function (no error messages
are thrown, it simply does not seem to do anything):

WQfunc - function() {
WQdata$CalciumFlag - with(WQdata, ifelse(analysis == Calcium, (flags 
-
c(Y, 'Q', , A) [findInterval(WQdata$value, c(-Inf, 0.027, 0.1, 100,
Inf))]),))
}

Calling the function WQfunc() does not produce an error but also does not
produce the expected CalciumFlag, it seems to not do anything.

Ultimately, what I need to get to is something like below where multiple
findInterval functions for different analyses are included in a single
function, then I can concatenate the results into a single column containing
all flags for all analyses, e.g.:

WQfunc - function() {
WQdata$CalciumFlag - with(WQdata, ifelse(analysis == Calcium, (flags 
-
c(Y, 'Q', , A) [findInterval(WQdata$value, c(-Inf, 0.027, 0.1, 100,
Inf))]),))

WQdata$SodiumFlag - with(WQdata, ifelse(analysis == Sodium, (flags -
c(Y, 'Q', , A) [findInterval(WQdata$value, c(-Inf, 0.050, 0.125, 125,
Inf))]),))

WQdata$MagnesiumFlag - with(WQdata, ifelse(analysis == Magnesium, 
(flags
- c(Y, 'Q', , A) [findInterval(WQdata$value, c(-Inf, 0.065, 0.15, 75,
Inf))]),))

.etc for additional water-quality analyses...

}

As an aside, I started working with the findInterval tool from an example
that I found online but am not clear as to how the multi-component
configuration incorporating brackets actually works, can anyone suggest a
good resource that explains this?


I thank you very much for any assistance you may be able to provide.


Regards,
Steve

--
View this message in context: 
http://r.789695.n4.nabble.com/help-wrapping-findInterval-into-a-function-tp4165464p4165464.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] About summary in linear models

2011-12-06 Thread John C Frain
Your email has become a bit distorted during transmission.  If you
have used the summary command you should be getting some more summary
statistics.  The lm function in R returns an object of class lm
which is a list containing at least the components listed in the help
files for lm.  The objects in the list are used to produce the summary
statistics.

If you are doing more elaborate work this approach (like the use of
internal functions in gretl) is very convenient.

Best Regards

John


On 6 December 2011 15:28, Otto F. Wagner ofwag...@gmail.com wrote:
 Hello!!, for linear models fit I use Gretl, but now I'm starting to use R,
 I would like to know if is there some function to obtain a extended summary
 like in Gretl.

 I will write a example in Gretl


 Modelo 1: MCO, usando las observaciones 1968-1982 (T = 15)

 Variable dependiente: Invest


 Coeficient

 St error

 t-ratio

 p-value



 const

 377,631

 35,0955

 10,7601

 0,1

 ***

 GNP

 0,63612

 0,055015

 11,5627

 0,1

 ***

 CPI

 -9,70228

 0,913737

 -10,6182

 0,1

 ***

 Interest

 -0,941363

 2,21077

 -0,4258

 0,67927



 time

 8,49182

 3,18142

 2,6692

 0,02353

 **



 Average of Dep Var.

  276,0067


 St Error Dep. Var

  117,5827

 Squared Sum of remainders

  818,6362



 Regression standar error

  9,047852

 R^2

  0,995771



 R^2 adj

  0,994079

 F(4, 10)

  588,6040



 p-value (de F)

  8,09e-12

 Log-likelihood

 -51,28100



 Akaike

  112,5620

 Schwarz

  116,1023



 Hannan-Quinn

  112,5243

 rho

 -0,440663



 Durbin-Watson

  2,757428


 Like you can see Gretl shows more statisticas.

 The same model in R:

 Call:
 lm(formula = Invest ~ CPI + GNP + Interest + Year, data = Tabla6_3)

 Residuals:
    Min      1Q  Median      3Q     Max
 -16.397  -3.864   1.391   4.219  15.779

 Coefficients:
              Estimate Std. Error t value Pr(|t|)
 (Intercept) -1.633e+04  6.250e+03  -2.612   0.0260 *
 CPI         -9.702e+00  9.137e-01 -10.618 9.15e-07 ***
 GNP          6.361e-01  5.502e-02  11.563 4.14e-07 ***
 Interest    -9.414e-01  2.211e+00  -0.426   0.6793
 Year         8.492e+00  3.181e+00   2.669   0.0235 *
 ---
 Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

 Thanks so much,

 Otto

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



-- 
John C Frain
Economics Department
Trinity College Dublin
Dublin 2
Ireland
www.tcd.ie/Economics/staff/frainj/home.html
mailto:fra...@tcd.ie
mailto:fra...@gmail.com

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


[R] help! browser() does not get stopped...

2011-12-06 Thread Michael
It's weird!

I am sure that I have inserted browser() in a sub-routine where I
wanted to stop and debug...

But when I start running the main function from the separate main file,

it doesn't stop within the target sub-routine at all.

Please help me!

Thanks!

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


Re: [R] help! browser() does not get stopped...

2011-12-06 Thread Uwe Ligges



On 06.12.2011 18:06, Michael wrote:

It's weird!

I am sure that I have inserted browser() in a sub-routine where I
wanted to stop and debug...

But when I start running the main function from the separate main file,

it doesn't stop within the target sub-routine at all.


Probably you are using some package and call the subroutine within the 
NAMESPACE of the package rather than the one in .GlobalEnv.


Uwe Ligges



Please help me!

Thanks!

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


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

2011-12-06 Thread Uwe Ligges



On 06.12.2011 18:27, Luc Villandre wrote:

Hello,

I do think so.

###
[villandre@stat04 lars]$ pwd
/home/villandre/R/x86_64-redhat-linux-gnu-library/2.11/lars
[villandre@stat04 lars]$ ls
data  DESCRIPTION  help  html  INDEX  libs  Meta  NAMESPACE  R
###

I re-installed it and I still get the same error message.




install.packages(lars, lib = ~/R/x86_64-redhat-linux-gnu-library/2.11)


trying URL 
'http://software.rc.fas.harvard.edu/mirrors/R/src/contrib/lars_0.9-8.tar.gz'
Content type 'application/x-gzip' length 172011 bytes (167 Kb)
opened URL
==
downloaded 167 Kb

* installing *source* package ‘lars’ ...
** libs
gfortran -m64   -fpic  -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions 
-fstack-protector --param=ssp-buffer-size=4 -m64 -mtune=generic -c delcol.f -o 
delcol.o
gcc -m64 -std=gnu99 -shared -L/usr/local/lib64 -o lars.so delcol.o -lgfortran 
-lm -L/usr/lib64/R/lib -lR
installing to 
/mnt/prism/s20/villandre/R/x86_64-redhat-linux-gnu-library/2.11/lars/libs
** R
** data
** preparing package for lazy loading
** help
*** installing help indices
   converting help for package ‘lars’
 finding HTML links ... done
 cv.lars html
 diabeteshtml
 lars-internal   html
 larshtml
 plot.lars   html
 predict.larshtml
 summary.larshtml
** building package indices ...
** testing if installed package can be loaded
Loaded lars 0.9-8

* DONE (lars)

The downloaded packages are in
 ‘/tmp/RtmphxCj4j/downloaded_packages’

library(lars, lib.loc = ~/R/x86_64-redhat-linux-gnu-library/2.11)

Error : .onLoad failed in loadNamespace() for 'lars', details:
   call: cat(Loaded lars, utils::installed.packages()[lars, Version],
   error: subscript out of bounds




I haven't looked closely enough before:

The culprit is in lars which has:

cat(Loaded lars, utils::installed.packages()[lars, Version],

and hence only looks at the default search path to report its version 
while you supplied a different one.


Thus, it is a bug in the package you should report to its maintainer.

I the meantime as a workaround (and maybe more convenient anyway): set 
the location of your library using .libPaths() before loading the package.



Uwe Ligges









Error: package/namespace load failed for ‘lars’


It is the first time I get such an error message when trying to load a package. 
It would seem that the problem is with

###
cat(Loaded lars, utils::installed.packages()[lars, Version]
###

Is there a way to circumvent this problem (e.g. attribute an arbitrary value to 
utils::installed.packages()[lars, Version])?

Thanks for your help,

Luc

From: Uwe Ligges [lig...@statistik.tu-dortmund.de]
Sent: Tuesday, December 06, 2011 8:01 AM
To: Luc Villandre
Cc: r-help
Subject: Re: [R] Can't load package 'lars'

On 06.12.2011 03:33, Luc Villandre wrote:

Hi,

I installed package 'lars' earlier tonight and did not get any sort of
error message.

###
** building package indices ...
** testing if installed package can be loaded
Loaded lars 0.9-8

* DONE (lars)
###

However, when I try to load it, I get
###
library(lars, lib.loc = ~/R/x86_64-redhat-linux-gnu-library/2.11)


Are you sure it is installed at the location you specified?

Uwe Ligges




Error : .onLoad failed in loadNamespace() for 'lars', details:
call: cat(Loaded lars, utils::installed.packages()[lars, Version],
error: subscript out of bounds
Error: package/namespace load failed for ‘lars’
###

Session info:

###
sessionInfo()
R version 2.14.0 (2011-10-31)
Platform: x86_64-redhat-linux-gnu (64-bit)

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

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

loaded via a namespace (and not attached):
[1] rpart_3.1-50 tools_2.14.0
###

I get the same error message when I try to load it on another machine:

###

library(lars,lib.loc = ~/R/i686-pc-linux-gnu-library/2.12)
Error : .onLoad failed in loadNamespace() for 'lars', details:
call: cat(Loaded lars, utils::installed.packages()[lars, Version],
error: subscript out of bounds
Error: package/namespace load failed for 'lars'
###

Session info:

###
sessionInfo()
R version 2.13.1 (2011-07-08)
Platform: i686-pc-linux-gnu (32-bit)

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

attached base packages:

Re: [R] help! what's wrong with setBreakpoint

2011-12-06 Thread Duncan Murdoch

On 06/12/2011 11:11 AM, Michael wrote:

I am not sure...

How do I make sure about that?

esp  Are you sure you were executing the same function after you hit c??


From a later one of your messages (adding a call to browser() didn't do 
anything), I think you weren't.  Now you know how to check.


Debugging code in packages can be tricky.  There are several strategies 
that I've used in different circumstances:


1.  source() the original source files from the command line.  Then 
you're not in a namespace, so you don't have that to confuse you.  (But 
if you don't source everything, you may find the source'd functions 
can't see the ones you skipped.)


2.  Set the environment variable R_KEEP_PKG_SOURCE to yes, then install 
the package; do all my debugging via things like


setBreakpoint(srcfile.R#30, env=somefunction)

where somefunction is in the package being debugged.  You can't make 
permanent changes to the functions this way, but you can add debugging 
code in the setBreakpoint call.


3.  Edit the source and re-install the package.   This is a bit of a 
pain, but it's the best way to reproduce the real execution environment.


Duncan Murdoch


Thanks again!

On Tue, Dec 6, 2011 at 8:57 AM, Duncan Murdochmurdoch.dun...@gmail.comwrote:

  On 06/12/2011 9:47 AM, Michael wrote:

  It printed:

  c:\R\myproject1\myfile.R#38:
   myfunc1 step  6,4,9 inenvironment: R_GlobalEnv

  What do you think?


  So that set a breakpoint in the copy of the function in the global
  environment.  Are you sure you were executing the same function after you
  hit c?  If you were working on code in a package, you may have been
  executing the function in the namespace of the package, not the one in the
  global environment.

  If that's not the case, then are you sure you ever got to that line?  You
  can see where the breakpoint was set using

  body(myfunc1)[[c(6,4,9)]]

  (Watch the parens and brackets!)

  Duncan Murdoch

   Thank you!

  On Tue, Dec 6, 2011 at 6:22 AM, Duncan 
Murdochmurdoch.duncan@gmail.**commurdoch.dun...@gmail.com
  wrote:

 On 11-12-05 10:32 PM, Michael wrote:
  
 Hi all,
  
 I am in the middle of debugging which is stopped using browser()...
  in
 myfile.R at around line #25.
  
 I was then stuck in a big loop which I want to escape and stop the
  program
 at the line after the big loop.
  
 In the debugging mode, I used
  
Browse[2]setBreakpoint(myfile.R#38)
  
  
 What did it print?
  
  
  
 I then typed c and ENTER, thinking that it will continue to
  execute
 until when it comes across line #38 and then stop there...
  
 But it didn't work - it continued the execution until the end of the
 function, right at the line return(results)...
  
 What happened? How to solve this problem?
  
  
 One of the complications in R is that you can have multiple copies of a
 function in memory.  You may (or may not, what did it print??) have
  set a
 breakpoint in one copy, then run another.  Or you may have edited that
 function after originally sourcing it, and lost the source reference.
  
 An alternative to using setBreakpoint is just to edit a call to
  browser()
 into the function.  It's less convenient, but more robust.
  
 Duncan Murdoch
  
  
 Thanks a lot!
  
[[alternative HTML version deleted]]
  
 __
 R-help@r-project.org mailing list
 
https://stat.ethz.ch/mailman/listinfo/r-helphttps://stat.ethz.ch/mailman/**listinfo/r-help
  
https://stat.**ethz.ch/mailman/listinfo/r-**helphttps://stat.ethz.ch/mailman/listinfo/r-help
  
 PLEASE do read the posting guide 
http://www.R-project.org/**http://www.r-project.org/**
 
posting-guide.htmlhttp://www.**r-project.org/posting-guide.**htmlhttp://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] axis thickness in plot()

2011-12-06 Thread Peter Ehlers

On 2011-12-06 08:35, AlexC wrote:

Hello,

I am trying to increase the thickness of the axis in plot() without
reverting to the use of paint programs

i see posts on that topic for the xyplot function but want to see if i can
do it with plot() because i've already setup my graph script using that

i thought i could use axis() function and specify lwd=thickness or
lwd.axis= but that does not work like it does for lwd.ticks

If anyone has an idea, sincerely

heres the script

windows(width=7,height=7)
plot(data$Winter,data$NbFirstBroods,ylab=number of breeding
pairs,xlab=winter
harshness,cex=1.5,cex.lab=1.5,cex.axis=1.5,font.axis=2,axes=FALSE)
points(data$Winter,data$NbFirstBroods,cex=1.5,col=black,pch=19)
abline(lm(data$NbFirstBroods~data$Winter),col=red,lwd=4)


Only you have the object you call 'data'. Why not provide a
simple example (reproducible and minus the obviously unnecessary
annotation) that illustrates your problem?



i tried axis(1, lwd.axis = 3,lwd.ticks=3) for example


Presumably this gave a warning: lwd.axis is not a graphical parameter.
The best thing at that point (if not sooner), is to type ?axis to
see what the arguments for that function are. This would immediately
show that 'lwd' is the argument you want.



also when adding the y axis axis(2...) x and y axes are disconnected


Use box() with your choice of bty and lwd. If you want different
linewidths for the x and y axes, then retrieve the coordinates of
par(usr) and use either abline() or lines().

Peter Ehlers



Thank you for your kind help in advance,

Alexandre

--
View this message in context: 
http://r.789695.n4.nabble.com/axis-thickness-in-plot-tp4165430p4165430.html
Sent from the R help mailing list archive at Nabble.com.

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


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


[R] Bootstrapping

2011-12-06 Thread Bastian Offermann

Hello,

I am having some trouble setting up a bootstrapping prodecure. I create 
artificial data and would like to use these to bootstrap a t-test 
statistic from these. Especially I do not really get how boot uses the 
indices variable or i variable. Can anybody help out? Thanks!!


b0 - 1/2 # intercept as given
b1 - 1   # slope as given
n - 20   # of rand. numbers
u - rnorm(n, mean=0, sd=1)   # generate data
x - rnorm(n, mean=0, sd=1)   #
y - b0 + b1*x + u# model
mu - 1

data1 - matrix(, n, 2)# Data from original draw

tval - function(data1, i) {
  data1[i,1] - y
  data1[i,2] - x
  m - lm(data1[,1]~data1[,2])
  p - coef(m)[2]
  t - (coef(m)[2]-mu)/sqrt(vcov(m)[2,2])   # t-test
  t

}
bs - boot(data = data1, statistic = tval, R = 500, sim = ordinary)
bs
ba - boot.array(bs)[1:5,1:10]
ci - boot.ci(bs, conf=0.95, index=1, type=all)
ci.bca - ci$bca[4:5]
plot(bs, index=1)

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

2011-12-06 Thread Luc Villandre
Hello,

I do think so.

###
[villandre@stat04 lars]$ pwd
/home/villandre/R/x86_64-redhat-linux-gnu-library/2.11/lars
[villandre@stat04 lars]$ ls
data  DESCRIPTION  help  html  INDEX  libs  Meta  NAMESPACE  R
###

I re-installed it and I still get the same error message.



 install.packages(lars, lib = ~/R/x86_64-redhat-linux-gnu-library/2.11)

trying URL 
'http://software.rc.fas.harvard.edu/mirrors/R/src/contrib/lars_0.9-8.tar.gz'
Content type 'application/x-gzip' length 172011 bytes (167 Kb)
opened URL
==
downloaded 167 Kb

* installing *source* package ‘lars’ ...
** libs
gfortran -m64   -fpic  -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions 
-fstack-protector --param=ssp-buffer-size=4 -m64 -mtune=generic -c delcol.f -o 
delcol.o
gcc -m64 -std=gnu99 -shared -L/usr/local/lib64 -o lars.so delcol.o -lgfortran 
-lm -L/usr/lib64/R/lib -lR
installing to 
/mnt/prism/s20/villandre/R/x86_64-redhat-linux-gnu-library/2.11/lars/libs
** R
** data
** preparing package for lazy loading
** help
*** installing help indices
  converting help for package ‘lars’
finding HTML links ... done
cv.lars html 
diabeteshtml 
lars-internal   html 
larshtml 
plot.lars   html 
predict.larshtml 
summary.larshtml 
** building package indices ...
** testing if installed package can be loaded
Loaded lars 0.9-8

* DONE (lars)

The downloaded packages are in
‘/tmp/RtmphxCj4j/downloaded_packages’
 library(lars, lib.loc = ~/R/x86_64-redhat-linux-gnu-library/2.11)
Error : .onLoad failed in loadNamespace() for 'lars', details:
  call: cat(Loaded lars, utils::installed.packages()[lars, Version],
  error: subscript out of bounds
Error: package/namespace load failed for ‘lars’


It is the first time I get such an error message when trying to load a package. 
It would seem that the problem is with

###
cat(Loaded lars, utils::installed.packages()[lars, Version]
###

Is there a way to circumvent this problem (e.g. attribute an arbitrary value to 
utils::installed.packages()[lars, Version])?

Thanks for your help,

Luc

From: Uwe Ligges [lig...@statistik.tu-dortmund.de]
Sent: Tuesday, December 06, 2011 8:01 AM
To: Luc Villandre
Cc: r-help
Subject: Re: [R] Can't load package 'lars'

On 06.12.2011 03:33, Luc Villandre wrote:
 Hi,

 I installed package 'lars' earlier tonight and did not get any sort of
 error message.

 ###
 ** building package indices ...
 ** testing if installed package can be loaded
 Loaded lars 0.9-8

 * DONE (lars)
 ###

 However, when I try to load it, I get
 ###
   library(lars, lib.loc = ~/R/x86_64-redhat-linux-gnu-library/2.11)

Are you sure it is installed at the location you specified?

Uwe Ligges



 Error : .onLoad failed in loadNamespace() for 'lars', details:
 call: cat(Loaded lars, utils::installed.packages()[lars, Version],
 error: subscript out of bounds
 Error: package/namespace load failed for ‘lars’
 ###

 Session info:

 ###
   sessionInfo()
 R version 2.14.0 (2011-10-31)
 Platform: x86_64-redhat-linux-gnu (64-bit)

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

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

 loaded via a namespace (and not attached):
 [1] rpart_3.1-50 tools_2.14.0
 ###

 I get the same error message when I try to load it on another machine:

 ###

   library(lars,lib.loc = ~/R/i686-pc-linux-gnu-library/2.12)
 Error : .onLoad failed in loadNamespace() for 'lars', details:
 call: cat(Loaded lars, utils::installed.packages()[lars, Version],
 error: subscript out of bounds
 Error: package/namespace load failed for 'lars'
 ###

 Session info:

 ###
   sessionInfo()
 R version 2.13.1 (2011-07-08)
 Platform: i686-pc-linux-gnu (32-bit)

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

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

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

 Is there at least a way to circumvent the problem?

 Thank you for your help,

 Luc Villandre

 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/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] To Try or to TryCatch, I have tried to long

2011-12-06 Thread LCOG1
So after about 4 hours struggling with Try and TryCatch I am throwing in the
towel.  I have a more complicated function that used logspline through
iterative distributions and at some point the logspline doesnt function
correctly for some subsets but is fine with others so I need to be able to
identify when the error occurs and stop curtailing the distribution and I
think this Try or TryCatch should do the trick but I think I am missing
something here. A simple example


result_-list()
for(i in 1:10){
  if(inherits(try(sqrt(9-i),silent=TRUE),try-error)){
#If sqrt fails
result_[[i]]-0 } else {
#If sqrt succeeds
result_[[i]] - 1 }
}


I would expect this to fail only when i  9 but succeeds  each time.  DO i
need to specify something different where try-error resides?  Thanks guys

Cheers, 
 Josh


--
View this message in context: 
http://r.789695.n4.nabble.com/To-Try-or-to-TryCatch-I-have-tried-to-long-tp4165578p4165578.html
Sent from the R help mailing list archive at Nabble.com.

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


Re: [R] help! browser() does not get stopped...

2011-12-06 Thread Michael
yeah, any one line command of checking which function is currently in the
memory?

so if I find any function not in the .GlobalEnv.
then I know what the problem is?

2011/12/6 Uwe Ligges lig...@statistik.tu-dortmund.de



 On 06.12.2011 18:29, Michael wrote:

 how do I check and make sure? thx


 E.g. insert cat(Hello World!\n) in the first line of your function you
 called subroutine.

 Best,
 Uwe Ligges









 On 12/6/11, Uwe 
 Liggeslig...@statistik.tu-**dortmund.delig...@statistik.tu-dortmund.de
  wrote:



 On 06.12.2011 18:06, Michael wrote:

 It's weird!

 I am sure that I have inserted browser() in a sub-routine where I
 wanted to stop and debug...

 But when I start running the main function from the separate main file,

 it doesn't stop within the target sub-routine at all.


 Probably you are using some package and call the subroutine within the
 NAMESPACE of the package rather than the one in .GlobalEnv.

 Uwe Ligges


 Please help me!

 Thanks!

 __**
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/**listinfo/r-helphttps://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! browser() does not get stopped...

2011-12-06 Thread Uwe Ligges



On 06.12.2011 18:45, Michael wrote:

yeah, any one line command of checking which function is currently in the
memory?


Which memory? You have to think about namespaces and environments in 
such a case, and then, we need to know what you are actually doing.





so if I find any function not in the .GlobalEnv.
then I know what the problem is?


Err, no. So are you working on package and may NAMESPACES be involved or 
not? If not, my initial guess may be wrong. I think you have to provide 
more information what you are actually doing and how you did define all 
your functions that are involved.


best,
uwe Ligges








2011/12/6 Uwe Liggeslig...@statistik.tu-dortmund.de




On 06.12.2011 18:29, Michael wrote:


how do I check and make sure? thx



E.g. insert cat(Hello World!\n) in the first line of your function you
called subroutine.

Best,
Uwe Ligges










On 12/6/11, Uwe 
Liggeslig...@statistik.tu-**dortmund.delig...@statistik.tu-dortmund.de
  wrote:




On 06.12.2011 18:06, Michael wrote:


It's weird!

I am sure that I have inserted browser() in a sub-routine where I
wanted to stop and debug...

But when I start running the main function from the separate main file,

it doesn't stop within the target sub-routine at all.



Probably you are using some package and call the subroutine within the
NAMESPACE of the package rather than the one in .GlobalEnv.

Uwe Ligges


Please help me!


Thanks!

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








__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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! browser() does not get stopped...

2011-12-06 Thread Duncan Murdoch

On 06/12/2011 12:45 PM, Michael wrote:

yeah, any one line command of checking which function is currently in the
memory?


As Uwe said, that's not a very useful thing to do.   But if you know the 
name you're looking for, find() is useful.  For example,


Browse[1] find(mean)
[1] package:base

You might also want find(mean, mode=function), in case you've also 
got a non-function named mean.


Duncan Murdoch


so if I find any function not in the .GlobalEnv.
then I know what the problem is?

2011/12/6 Uwe Liggeslig...@statistik.tu-dortmund.de



  On 06.12.2011 18:29, Michael wrote:

  how do I check and make sure? thx


  E.g. insert cat(Hello World!\n) in the first line of your function you
  called subroutine.

  Best,
  Uwe Ligges









  On 12/6/11, Uwe 
Liggeslig...@statistik.tu-**dortmund.delig...@statistik.tu-dortmund.de
   wrote:



  On 06.12.2011 18:06, Michael wrote:

  It's weird!

  I am sure that I have inserted browser() in a sub-routine where I
  wanted to stop and debug...

  But when I start running the main function from the separate main file,

  it doesn't stop within the target sub-routine at all.


  Probably you are using some package and call the subroutine within the
  NAMESPACE of the package rather than the one in .GlobalEnv.

  Uwe Ligges


  Please help me!

  Thanks!

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




[[alternative HTML version deleted]]

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


__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] RStudio: copied line is always not the same as the line that I highlighted

2011-12-06 Thread Michael
Hi all,

I am using RStudio. I wanted to copy and past an expression/line.

I highlighted it, and then copied and pasted:

The result was not the line that I wanted, instead, it was the line above...

For example:

I have three lines:



a
b
c


I highlighted b and copied, but the pasted outcome was a...

What happened?

Thanks al ot!

[[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 to de-source and re-source a file?

2011-12-06 Thread Michael
i.e. how to make sure the function that was loaded into workspace/memory is
the version that I edited latest... not some stale version...

This might solve some of my breakpoint and browser/debug problem, even the
RStudio problem that I've met

thanks a lot!

[[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 de-source and re-source a file?

2011-12-06 Thread Duncan Murdoch

On 06/12/2011 1:10 PM, Michael wrote:

i.e. how to make sure the function that was loaded into workspace/memory is
the version that I edited latest... not some stale version...

This might solve some of my breakpoint and browser/debug problem, even the
RStudio problem that I've met


You can use rm() to remove a function.

You can also quit and restart R, making sure that it *does not* load an 
existing workspace (by deleting the .Rdata file if it exists, and never 
answering yes to the question to save it.)  This gives you a nice 
clean slate.


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] help! browser() does not get stopped...

2011-12-06 Thread Michael
Thanks a lot!

What I was wondering is:

if we use find, are the results for locally installed packages, or
search_paths, or the functions that are loaded into memory?

I am looking for some command to tell me which functions are currently in
the memory.

My understanding is that after the first-run of a function, the function is
loaded into memory and stays there until being unloaded.

If I don't unload the function, then any newly edited version will not be
loaded and the one in memory is the stale version...

This might explain a few of my weird problems...

Thanks a lot!

On Tue, Dec 6, 2011 at 12:04 PM, Duncan Murdoch murdoch.dun...@gmail.comwrote:

 On 06/12/2011 12:45 PM, Michael wrote:

 yeah, any one line command of checking which function is currently in the
 memory?


 As Uwe said, that's not a very useful thing to do.   But if you know the
 name you're looking for, find() is useful.  For example,

 Browse[1] find(mean)
 [1] package:base

 You might also want find(mean, mode=function), in case you've also got
 a non-function named mean.

 Duncan Murdoch

  so if I find any function not in the .GlobalEnv.
 then I know what the problem is?

 2011/12/6 Uwe 
 Liggeslig...@statistik.tu-**dortmund.delig...@statistik.tu-dortmund.de
 

 
 
   On 06.12.2011 18:29, Michael wrote:
 
   how do I check and make sure? thx
 
 
   E.g. insert cat(Hello World!\n) in the first line of your function
 you
   called subroutine.
 
   Best,
   Uwe Ligges
 
 
 
 
 
 
 
 
 
   On 12/6/11, Uwe 
  Liggeslig...@statistik.tu-**d**ortmund.dehttp://dortmund.de/
 ligges@statistik.**tu-dortmund.de lig...@statistik.tu-dortmund.de

wrote:
 
 
 
   On 06.12.2011 18:06, Michael wrote:
 
   It's weird!
 
   I am sure that I have inserted browser() in a sub-routine where I
   wanted to stop and debug...
 
   But when I start running the main function from the separate main
 file,
 
   it doesn't stop within the target sub-routine at all.
 
 
   Probably you are using some package and call the subroutine within
 the
   NAMESPACE of the package rather than the one in .GlobalEnv.
 
   Uwe Ligges
 
 
   Please help me!
 
   Thanks!
 
   __
   R-help@r-project.org mailing list
   
  https://stat.ethz.ch/mailman/listinfo/r-helphttps://stat.ethz.ch/mailman/**listinfo/r-help
 https://stat.**ethz.ch/mailman/listinfo/r-**helphttps://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
 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-helphttps://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/**
 posting-guide.html http://www.r-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.




[[alternative HTML version deleted]]

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


Re: [R] How to de-source and re-source a file?

2011-12-06 Thread Michael
Thanks a lot!

But how about removing all the functions in the whole myprogram1.R
source file?

The reason for asking this is of course, after I made some changes, I saved
it, and then I wanted the functions to be reloaded into memory so that I
can do mtrace, or browser etc.

Thank you!

On Tue, Dec 6, 2011 at 12:17 PM, Duncan Murdoch murdoch.dun...@gmail.comwrote:

  On 06/12/2011 1:10 PM, Michael wrote:

 i.e. how to make sure the function that was loaded into workspace/memory
 is
 the version that I edited latest... not some stale version...

 This might solve some of my breakpoint and browser/debug problem, even the
 RStudio problem that I've met


 You can use rm() to remove a function.

 You can also quit and restart R, making sure that it *does not* load an
 existing workspace (by deleting the .Rdata file if it exists, and never
 answering yes to the question to save it.)  This gives you a nice clean
 slate.

 Duncan Murdoch


[[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 de-source and re-source a file?

2011-12-06 Thread Duncan Murdoch

On 06/12/2011 1:19 PM, Michael wrote:

Thanks a lot!

But how about removing all the functions in the whole myprogram1.R
source file?


There's no way for R to know what you did with those functions, so no 
general way to do that.


But if you just source it again, it will overwrite the ones in the 
current evaluation frame.


Duncan Murdoch


The reason for asking this is of course, after I made some changes, I saved
it, and then I wanted the functions to be reloaded into memory so that I
can do mtrace, or browser etc.

Thank you!

On Tue, Dec 6, 2011 at 12:17 PM, Duncan Murdochmurdoch.dun...@gmail.comwrote:

   On 06/12/2011 1:10 PM, Michael wrote:

  i.e. how to make sure the function that was loaded into workspace/memory
  is
  the version that I edited latest... not some stale version...

  This might solve some of my breakpoint and browser/debug problem, even the
  RStudio problem that I've met


  You can use rm() to remove a function.

  You can also quit and restart R, making sure that it *does not* load an
  existing workspace (by deleting the .Rdata file if it exists, and never
  answering yes to the question to save it.)  This gives you a nice clean
  slate.

  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] help! browser() does not get stopped...

2011-12-06 Thread Duncan Murdoch

On 06/12/2011 1:17 PM, Michael wrote:

Thanks a lot!

What I was wondering is:

if we use find, are the results for locally installed packages, or
search_paths, or the functions that are loaded into memory?


It finds what get() would find, so that starts with the current 
evaluation frame, and follows the chain back to the base environment.  
If you haven't used library() or require() to load a package, it won't 
be found.


 I am looking for some command to tell me which functions are currently in


the memory.


ls() will do that for the current evaluation frame.  See its args if you 
want to search back through the chain.



My understanding is that after the first-run of a function, the function is
loaded into memory and stays there until being unloaded.


That's true, but not relevant.  If it hasn't been loaded, a stub is 
there, and find() will see the stub.

If I don't unload the function, then any newly edited version will not be
loaded and the one in memory is the stale version...


That's not true.  As soon as you assign a new value to the name, it will 
be replaced.  But you need to do the assignment in the right place in 
the chain.


Duncan Murdoch


This might explain a few of my weird problems...

Thanks a lot!

On Tue, Dec 6, 2011 at 12:04 PM, Duncan Murdochmurdoch.dun...@gmail.comwrote:

  On 06/12/2011 12:45 PM, Michael wrote:

  yeah, any one line command of checking which function is currently in the
  memory?


  As Uwe said, that's not a very useful thing to do.   But if you know the
  name you're looking for, find() is useful.  For example,

  Browse[1]  find(mean)
  [1] package:base

  You might also want find(mean, mode=function), in case you've also got
  a non-function named mean.

  Duncan Murdoch

   so if I find any function not in the .GlobalEnv.
  then I know what the problem is?

  2011/12/6 Uwe 
Liggeslig...@statistik.tu-**dortmund.delig...@statistik.tu-dortmund.de
  

  
  
 On 06.12.2011 18:29, Michael wrote:
  
 how do I check and make sure? thx
  
  
 E.g. insert cat(Hello World!\n) in the first line of your function
  you
 called subroutine.
  
 Best,
 Uwe Ligges
  
  
  
  
  
  
  
  
  
 On 12/6/11, Uwe 
Liggeslig...@statistik.tu-**d**ortmund.dehttp://dortmund.de/
  ligges@statistik.**tu-dortmund.delig...@statistik.tu-dortmund.de

  wrote:
  
  
  
 On 06.12.2011 18:06, Michael wrote:
  
 It's weird!
  
 I am sure that I have inserted browser() in a sub-routine where I
 wanted to stop and debug...
  
 But when I start running the main function from the separate main
  file,
  
 it doesn't stop within the target sub-routine at all.
  
  
 Probably you are using some package and call the subroutine within
  the
 NAMESPACE of the package rather than the one in .GlobalEnv.
  
 Uwe Ligges
  
  
 Please help me!
  
 Thanks!
  
 __
 R-help@r-project.org mailing list
 
https://stat.ethz.ch/mailman/listinfo/r-helphttps://stat.ethz.ch/mailman/**listinfo/r-help
  
https://stat.**ethz.ch/mailman/listinfo/r-**helphttps://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
  
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-helphttps://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.






__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] To Try or to TryCatch, I have tried to long

2011-12-06 Thread Gene Leynes
I think the problem is that it's only a warning and not an error.

result_-list()
for(i in 1:10){
 if(inherits(try(sqrt(9-i),silent=TRUE),try-error)){
 #If sqrt fails
 cat('fail',i,'\n')
 result_[[i]]-0 } else {
 #If sqrt succeeds
 cat('succeed',i,'\n')
 result_[[i]] - 1 }
}
result_

On Tue, Dec 6, 2011 at 11:11 AM, LCOG1 jr...@lcog.org wrote:

 So after about 4 hours struggling with Try and TryCatch I am throwing in
 the
 towel.  I have a more complicated function that used logspline through
 iterative distributions and at some point the logspline doesnt function
 correctly for some subsets but is fine with others so I need to be able to
 identify when the error occurs and stop curtailing the distribution and I
 think this Try or TryCatch should do the trick but I think I am missing
 something here. A simple example


 result_-list()
 for(i in 1:10){
  if(inherits(try(sqrt(9-i),silent=TRUE),try-error)){
#If sqrt fails
result_[[i]]-0 } else {
#If sqrt succeeds
result_[[i]] - 1 }
 }


 I would expect this to fail only when i  9 but succeeds  each time.  DO i
 need to specify something different where try-error resides?  Thanks guys

 Cheers,
  Josh


 --
 View this message in context:
 http://r.789695.n4.nabble.com/To-Try-or-to-TryCatch-I-have-tried-to-long-tp4165578p4165578.html
 Sent from the R help mailing list archive at Nabble.com.

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


[[alternative HTML version deleted]]

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


[R] convert p-values into z-scores

2011-12-06 Thread Amidou N'Diaye
Is there a program to convert p-values into z-scores for meta-analysis 
purpose? Thanks


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


[R] read.table performance

2011-12-06 Thread Gene Leynes
** Disclaimer: I'm looking for general suggestions **
I'm sorry, but can't send out the file I'm using, so there is no
reproducible example.

I'm using read.table and it's taking over 30 seconds to read a tiny file.
The strange thing is that it takes roughly the same amount of time if the
file is 100 times larger.

After re-reviewing the data Import / Export manual I think the best
approach would be to use Python, or perhaps the readLines function, but I
was hoping to understand why the simple read.table approach wasn't working
as expected.

Some relevant facts:

   1. There are about 3700 columns.  Maybe this is the problem?  Still the
   file size is not very large.
   2. The file encoding is ANSI, but I'm not specifying that in the
   function.  Setting fileEncoding=ANSI produces an unsupported conversion
   error
   3. readLines imports the lines quickly
   4. scan imports the file quickly also

Obviously, scan and readLines would require more coding to identify
columns, etc.

my code:
system.time(dat - read.table('C:/test.txt', nrows=-1, sep='\t',
header=TRUE))

It's taking 33.4 seconds and the file size is only 315 kb!

Thanks

Gene

[[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] Find x value of density plots

2011-12-06 Thread Pavan G
Hello All,

How do I find the x value at max density for say, this plot
plot(density(rnorm(1000)))


Thank you,
P

[[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 de-source and re-source a file?

2011-12-06 Thread Michael
the problem with restarting R is that I then have to re-execute the program
until the point where I wanted to debug, which is a very long-waiting
time...

On Tue, Dec 6, 2011 at 12:17 PM, Duncan Murdoch murdoch.dun...@gmail.comwrote:

  On 06/12/2011 1:10 PM, Michael wrote:

 i.e. how to make sure the function that was loaded into workspace/memory
 is
 the version that I edited latest... not some stale version...

 This might solve some of my breakpoint and browser/debug problem, even the
 RStudio problem that I've met


 You can use rm() to remove a function.

 You can also quit and restart R, making sure that it *does not* load an
 existing workspace (by deleting the .Rdata file if it exists, and never
 answering yes to the question to save it.)  This gives you a nice clean
 slate.

 Duncan Murdoch


[[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] Find x value of density plots

2011-12-06 Thread Bert Gunter
?density
... and pay attention to the Value details.

-- Bert

On Tue, Dec 6, 2011 at 10:42 AM, Pavan G pavan.n...@gmail.com wrote:
 Hello All,

 How do I find the x value at max density for say, this plot
 plot(density(rnorm(1000)))


 Thank you,
 P

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



-- 

Bert Gunter
Genentech Nonclinical Biostatistics

Internal Contact Info:
Phone: 467-7374
Website:
http://pharmadevelopment.roche.com/index/pdb/pdb-functional-groups/pdb-biostatistics/pdb-ncb-home.htm

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


Re: [R] Find x value of density plots

2011-12-06 Thread Duncan Murdoch

On 06/12/2011 1:42 PM, Pavan G wrote:

Hello All,

How do I find the x value at max density for say, this plot
plot(density(rnorm(1000)))


d - density(rnorm(1000))
plot(d)

abline(v=d$x[which.max(d$y)])

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] convert p-values into z-scores

2011-12-06 Thread Jean V Adams
Try this:

pval - 0.05
qnorm(1 - (pval/2))

Jean


Amidou N'Diaye wrote on 12/06/2011 12:27:25 PM:

 Is there a program to convert p-values into z-scores for meta-analysis 
 purpose? Thanks

[[alternative HTML version deleted]]

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


Re: [R] split date nad time

2011-12-06 Thread R. Michael Weylandt
I can't replicate this: does it occur in a fresh R session (no GUI,
just straight --vanilla)? If so, sessionInfo()?

On Tue, Dec 6, 2011 at 11:23 AM, threshold r.kozar...@gmail.com wrote:

 ok,

 dput(AggDateTime[960:962])
 structure(c(1314313140L, 1314313200L, 1314313260L), class = c(POSIXct,
 POSIXt), tzone = )

 --
 View this message in context: 
 http://r.789695.n4.nabble.com/split-date-nad-time-tp4164191p4165378.html
 Sent from the R help mailing list archive at Nabble.com.

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

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


[R] Sequential Sum in R

2011-12-06 Thread vioravis
I am trying to code the following excel formula in R. 

ab  cResultFormula
1   10 0.1 #N/A 
IF(B220,NA(),C2+IF(ISERROR(D1),0,D1))
2   20 0.2 0.2
IF(B320,NA(),C3+IF(ISERROR(D2),0,D2))
3   30 0.3 0.5
IF(B420,NA(),C4+IF(ISERROR(D3),0,D3))
4   40 0.4 0.9
IF(B520,NA(),C5+IF(ISERROR(D4),0,D4))
5   50 0.5 1.4
IF(B620,NA(),C6+IF(ISERROR(D5),0,D5))
6   60 0.6 2   
IF(B720,NA(),C7+IF(ISERROR(D6),0,D6))
7   70 0.7 2.7
IF(B820,NA(),C8+IF(ISERROR(D7),0,D7))
8   80 0.8 3.5
IF(B920,NA(),C9+IF(ISERROR(D8),0,D8))
9   90 0.9 4.4
IF(B1020,NA(),C10+IF(ISERROR(D9),0,D9))
10100 1   5.4
IF(B1120,NA(),C11+IF(ISERROR(D10),0,D10))


The variable Result is obtained using the excel formula shown next to it.
Column D contains the Result.

dataFrame - data.frame(a = seq(1:10),b = seq(10,100,by = 10),c =
seq(0.1,1,by = 0.1))

Can someone please help me as how to calculate the sequential sum in R given
by the excel formula??

Thank you.

Ravi

--
View this message in context: 
http://r.789695.n4.nabble.com/Sequential-Sum-in-R-tp4165916p4165916.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] To Try or to TryCatch, I have tried to long

2011-12-06 Thread Gene Leynes
I've had the same problem in other cases.

Does anyone know how to catch warnings as well as errors?

On Tue, Dec 6, 2011 at 12:34 PM, ROLL Josh F jr...@lcog.org wrote:

 **
 Agreed.  But what I am trying to control is when I get a warning.  I want
 to do something different if a warning OR an error pop up?  Any ideas?

 Cheers

  --
 *From:* gley...@gmail.com [mailto:gley...@gmail.com] *On Behalf Of *Gene
 Leynes
 *Sent:* Tuesday, December 06, 2011 10:27 AM
 *To:* ROLL Josh F
 *Cc:* r-help@r-project.org
 *Subject:* Re: [R] To Try or to TryCatch, I have tried to long

 I think the problem is that it's only a warning and not an error.

 result_-list()
 for(i in 1:10){
  if(inherits(try(sqrt(9-i),silent=TRUE),try-error)){
  #If sqrt fails
  cat('fail',i,'\n')
  result_[[i]]-0 } else {
  #If sqrt succeeds
  cat('succeed',i,'\n')
  result_[[i]] - 1 }
 }
 result_

 On Tue, Dec 6, 2011 at 11:11 AM, LCOG1 jr...@lcog.org wrote:

 So after about 4 hours struggling with Try and TryCatch I am throwing in
 the
 towel.  I have a more complicated function that used logspline through
 iterative distributions and at some point the logspline doesnt function
 correctly for some subsets but is fine with others so I need to be able to
 identify when the error occurs and stop curtailing the distribution and I
 think this Try or TryCatch should do the trick but I think I am missing
 something here. A simple example


 result_-list()
 for(i in 1:10){
  if(inherits(try(sqrt(9-i),silent=TRUE),try-error)){
#If sqrt fails
result_[[i]]-0 } else {
#If sqrt succeeds
result_[[i]] - 1 }
 }


 I would expect this to fail only when i  9 but succeeds  each time.  DO i
 need to specify something different where try-error resides?  Thanks
 guys

 Cheers,
  Josh


 --
 View this message in context:
 http://r.789695.n4.nabble.com/To-Try-or-to-TryCatch-I-have-tried-to-long-tp4165578p4165578.html
 Sent from the R help mailing list archive at Nabble.com.

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




[[alternative HTML version deleted]]

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


Re: [R] read.table performance

2011-12-06 Thread Gabor Grothendieck
On Tue, Dec 6, 2011 at 1:15 PM, Gene Leynes gley...@gmail.com wrote:
 ** Disclaimer: I'm looking for general suggestions **
 I'm sorry, but can't send out the file I'm using, so there is no
 reproducible example.

 I'm using read.table and it's taking over 30 seconds to read a tiny file.
 The strange thing is that it takes roughly the same amount of time if the
 file is 100 times larger.

 After re-reviewing the data Import / Export manual I think the best
 approach would be to use Python, or perhaps the readLines function, but I
 was hoping to understand why the simple read.table approach wasn't working
 as expected.

 Some relevant facts:

   1. There are about 3700 columns.  Maybe this is the problem?  Still the
   file size is not very large.
   2. The file encoding is ANSI, but I'm not specifying that in the
   function.  Setting fileEncoding=ANSI produces an unsupported conversion
   error
   3. readLines imports the lines quickly
   4. scan imports the file quickly also

 Obviously, scan and readLines would require more coding to identify
 columns, etc.

 my code:
 system.time(dat - read.table('C:/test.txt', nrows=-1, sep='\t',
 header=TRUE))

 It's taking 33.4 seconds and the file size is only 315 kb!


You could also try read.csv.sql in the sqldf package and see whether
or not that is any faster. Be sure you are using RSQLite 0.11.0 (and
not an earlier version) with that since earlier versions were compiled
to work with only a maximum of 999 columns.

library(sqldf)
DF - read.csv.sql(C:\\test.txt, header = TRUE, sep = \t)

You may or may not have to use the eol= argument to specify line
endings.  See ?read.csv.sql

-- 
Statistics  Software Consulting
GKX Group, GKX Associates Inc.
tel: 1-877-GKX-GROUP
email: ggrothendieck at gmail.com

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


Re: [R] Sequential Sum in R

2011-12-06 Thread Jean V Adams
vioravis wrote on 12/06/2011 12:42:35 PM:

 I am trying to code the following excel formula in R. 
 
 ab  cResultFormula
 1   10 0.1 #N/A 
 IF(B220,NA(),C2+IF(ISERROR(D1),0,D1))
 2   20 0.2 0.2 
 IF(B320,NA(),C3+IF(ISERROR(D2),0,D2))
 3   30 0.3 0.5 
 IF(B420,NA(),C4+IF(ISERROR(D3),0,D3))
 4   40 0.4 0.9 
 IF(B520,NA(),C5+IF(ISERROR(D4),0,D4))
 5   50 0.5 1.4 
 IF(B620,NA(),C6+IF(ISERROR(D5),0,D5))
 6   60 0.6 2 
 IF(B720,NA(),C7+IF(ISERROR(D6),0,D6))
 7   70 0.7 2.7 
 IF(B820,NA(),C8+IF(ISERROR(D7),0,D7))
 8   80 0.8 3.5 
 IF(B920,NA(),C9+IF(ISERROR(D8),0,D8))
 9   90 0.9 4.4 
 IF(B1020,NA(),C10+IF(ISERROR(D9),0,D9))
 10100 1   5.4 
 IF(B1120,NA(),C11+IF(ISERROR(D10),0,D10))
 
 
 The variable Result is obtained using the excel formula shown next to 
it.
 Column D contains the Result.
 
 dataFrame - data.frame(a = seq(1:10),b = seq(10,100,by = 10),c =
 seq(0.1,1,by = 0.1)) 
 
 Can someone please help me as how to calculate the sequential sum in R 
given
 by the excel formula??
 
 Thank you.
 
 Ravi


Try this:

d - ifelse(dataFrame$b  20, 0, dataFrame$c)
dataFrame$result - cumsum(d)
dataFrame$result[dataFrame$b  20] - NA

Jean
[[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] To Try or to TryCatch, I have tried to long

2011-12-06 Thread William Dunlap
Look at the archives of this mailing list for a discussion
entitled 'Stack trace?' on Nov 9-10 of this year.

Bill Dunlap
Spotfire, TIBCO Software
wdunlap tibco.com 

 -Original Message-
 From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On 
 Behalf Of Gene Leynes
 Sent: Tuesday, December 06, 2011 10:58 AM
 To: ROLL Josh F
 Cc: r-help@r-project.org
 Subject: Re: [R] To Try or to TryCatch, I have tried to long
 
 I've had the same problem in other cases.
 
 Does anyone know how to catch warnings as well as errors?
 
 On Tue, Dec 6, 2011 at 12:34 PM, ROLL Josh F jr...@lcog.org wrote:
 
  **
  Agreed.  But what I am trying to control is when I get a warning.  I want
  to do something different if a warning OR an error pop up?  Any ideas?
 
  Cheers
 
   --
  *From:* gley...@gmail.com [mailto:gley...@gmail.com] *On Behalf Of *Gene
  Leynes
  *Sent:* Tuesday, December 06, 2011 10:27 AM
  *To:* ROLL Josh F
  *Cc:* r-help@r-project.org
  *Subject:* Re: [R] To Try or to TryCatch, I have tried to long
 
  I think the problem is that it's only a warning and not an error.
 
  result_-list()
  for(i in 1:10){
   if(inherits(try(sqrt(9-i),silent=TRUE),try-error)){
   #If sqrt fails
   cat('fail',i,'\n')
   result_[[i]]-0 } else {
   #If sqrt succeeds
   cat('succeed',i,'\n')
   result_[[i]] - 1 }
  }
  result_
 
  On Tue, Dec 6, 2011 at 11:11 AM, LCOG1 jr...@lcog.org wrote:
 
  So after about 4 hours struggling with Try and TryCatch I am throwing in
  the
  towel.  I have a more complicated function that used logspline through
  iterative distributions and at some point the logspline doesnt function
  correctly for some subsets but is fine with others so I need to be able to
  identify when the error occurs and stop curtailing the distribution and I
  think this Try or TryCatch should do the trick but I think I am missing
  something here. A simple example
 
 
  result_-list()
  for(i in 1:10){
   if(inherits(try(sqrt(9-i),silent=TRUE),try-error)){
 #If sqrt fails
 result_[[i]]-0 } else {
 #If sqrt succeeds
 result_[[i]] - 1 }
  }
 
 
  I would expect this to fail only when i  9 but succeeds  each time.  DO i
  need to specify something different where try-error resides?  Thanks
  guys
 
  Cheers,
   Josh
 
 
  --
  View this message in context:
  http://r.789695.n4.nabble.com/To-Try-or-to-TryCatch-I-have-tried-to-long-tp4165578p4165578.html
  Sent from the R help mailing list archive at Nabble.com.
 
  __
  R-help@r-project.org mailing list
  https://stat.ethz.ch/mailman/listinfo/r-help
  PLEASE do read the posting guide
  http://www.R-project.org/posting-guide.html
  and provide commented, minimal, self-contained, reproducible code.
 
 
 
 
   [[alternative HTML version deleted]]
 
 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] To Try or to TryCatch, I have tried to long

2011-12-06 Thread William Dunlap
Or, Google for 'R catching warnings' and third entry is the excellent
  http://www.stats.uwo.ca/faculty/murdoch/software/debuggingR/

Bill Dunlap
Spotfire, TIBCO Software
wdunlap tibco.com 

 -Original Message-
 From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On 
 Behalf Of William Dunlap
 Sent: Tuesday, December 06, 2011 11:38 AM
 To: gleyne...@gmail.com; ROLL Josh F
 Cc: r-help@r-project.org
 Subject: Re: [R] To Try or to TryCatch, I have tried to long
 
 Look at the archives of this mailing list for a discussion
 entitled 'Stack trace?' on Nov 9-10 of this year.
 
 Bill Dunlap
 Spotfire, TIBCO Software
 wdunlap tibco.com
 
  -Original Message-
  From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On 
  Behalf Of Gene Leynes
  Sent: Tuesday, December 06, 2011 10:58 AM
  To: ROLL Josh F
  Cc: r-help@r-project.org
  Subject: Re: [R] To Try or to TryCatch, I have tried to long
 
  I've had the same problem in other cases.
 
  Does anyone know how to catch warnings as well as errors?
 
  On Tue, Dec 6, 2011 at 12:34 PM, ROLL Josh F jr...@lcog.org wrote:
 
   **
   Agreed.  But what I am trying to control is when I get a warning.  I want
   to do something different if a warning OR an error pop up?  Any ideas?
  
   Cheers
  
--
   *From:* gley...@gmail.com [mailto:gley...@gmail.com] *On Behalf Of *Gene
   Leynes
   *Sent:* Tuesday, December 06, 2011 10:27 AM
   *To:* ROLL Josh F
   *Cc:* r-help@r-project.org
   *Subject:* Re: [R] To Try or to TryCatch, I have tried to long
  
   I think the problem is that it's only a warning and not an error.
  
   result_-list()
   for(i in 1:10){
if(inherits(try(sqrt(9-i),silent=TRUE),try-error)){
#If sqrt fails
cat('fail',i,'\n')
result_[[i]]-0 } else {
#If sqrt succeeds
cat('succeed',i,'\n')
result_[[i]] - 1 }
   }
   result_
  
   On Tue, Dec 6, 2011 at 11:11 AM, LCOG1 jr...@lcog.org wrote:
  
   So after about 4 hours struggling with Try and TryCatch I am throwing in
   the
   towel.  I have a more complicated function that used logspline through
   iterative distributions and at some point the logspline doesnt function
   correctly for some subsets but is fine with others so I need to be able 
   to
   identify when the error occurs and stop curtailing the distribution and I
   think this Try or TryCatch should do the trick but I think I am missing
   something here. A simple example
  
  
   result_-list()
   for(i in 1:10){
if(inherits(try(sqrt(9-i),silent=TRUE),try-error)){
  #If sqrt fails
  result_[[i]]-0 } else {
  #If sqrt succeeds
  result_[[i]] - 1 }
   }
  
  
   I would expect this to fail only when i  9 but succeeds  each time.  DO 
   i
   need to specify something different where try-error resides?  Thanks
   guys
  
   Cheers,
Josh
  
  
   --
   View this message in context:
   http://r.789695.n4.nabble.com/To-Try-or-to-TryCatch-I-have-tried-to-long-tp4165578p4165578.html
   Sent from the R help mailing list archive at Nabble.com.
  
   __
   R-help@r-project.org mailing list
   https://stat.ethz.ch/mailman/listinfo/r-help
   PLEASE do read the posting guide
   http://www.R-project.org/posting-guide.html
   and provide commented, minimal, self-contained, reproducible code.
  
  
  
 
  [[alternative HTML version deleted]]
 
  __
  R-help@r-project.org mailing list
  https://stat.ethz.ch/mailman/listinfo/r-help
  PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
  and provide commented, minimal, self-contained, reproducible code.
 
 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.

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


Re: [R] help wrapping findInterval into a function

2011-12-06 Thread David Winsemius


On Dec 6, 2011, at 11:43 AM, Steve E. wrote:


Dear R Community,

I hope you might be able to assist with a small problem creating a  
function.
I am working with water-quality data sets that contain the  
concentration of
many different elements in water samples.  I need to assign quality- 
control
flags to values that fall into various concentration ranges.  Rather  
than a
web of nested if statements, I am employing the findInterval  
function to
identify values that need to be flagged and to assign the  
appropriate flag.


It's probably your use of with rather than findInterval. The 'with'  
function sets up an environment and is used mostly in interactive  
session. If you have not passed a dataframe into the function then you  
should use the name of the dataframe and '['.



The data consist of a sample identifier, the analysis, and  
corresponding

value.  The findInterval function works well; however, I would like to
incorporate it into a function so that I can run multiple findInterval
functions for many different water-quality analyses (and I have to  
do this

for many dataset) but it seems to fall apart when incorporated into a
function.

Run straighforward, the findInterval function works as desired, e.g.  
below,
creating the new CalciumFlag column with the appropriate flag for,  
in this

case, levels of calcium in the water:

WQdata$CalciumFlag - with(WQdata, ifelse(analysis == Calcium,  
(flags -
c(Y, 'Q', , A) [findInterval(WQdata$value, c(-Inf, 0.027, 0.1,  
100,

Inf))]),))

However, it does not worked when wrapped in a function (no error  
messages

are thrown, it simply does not seem to do anything):

WQfunc - function() {
	WQdata$CalciumFlag - with(WQdata, ifelse(analysis == Calcium,  
(flags -
c(Y, 'Q', , A) [findInterval(WQdata$value, c(-Inf, 0.027, 0.1,  
100,

Inf))]),))
}

Calling the function WQfunc() does not produce an error but also  
does not

produce the expected CalciumFlag, it seems to not do anything.

Ultimately, what I need to get to is something like below where  
multiple

findInterval functions for different analyses are included in a single
function, then I can concatenate the results into a single column  
containing

all flags for all analyses, e.g.:

WQfunc - function() {
	WQdata$CalciumFlag - with(WQdata, ifelse(analysis == Calcium,  
(flags -
c(Y, 'Q', , A) [findInterval(WQdata$value, c(-Inf, 0.027, 0.1,  
100,

Inf))]),))

	WQdata$SodiumFlag - with(WQdata, ifelse(analysis == Sodium,  
(flags -
c(Y, 'Q', , A) [findInterval(WQdata$value, c(-Inf, 0.050,  
0.125, 125,

Inf))]),))

	WQdata$MagnesiumFlag - with(WQdata, ifelse(analysis ==  
Magnesium, (flags
- c(Y, 'Q', , A) [findInterval(WQdata$value, c(-Inf, 0.065,  
0.15, 75,

Inf))]),))

.etc for additional water-quality analyses...

}

As an aside, I started working with the findInterval tool from an  
example

that I found online but am not clear as to how the multi-component
configuration incorporating brackets actually works, can anyone  
suggest a

good resource that explains this?


I thank you very much for any assistance you may be able to provide.


Regards,
Steve

--
View this message in context: 
http://r.789695.n4.nabble.com/help-wrapping-findInterval-into-a-function-tp4165464p4165464.html
Sent from the R help mailing list archive at Nabble.com.

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


David Winsemius, MD
West Hartford, CT

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


[R] varaince explined of a regression tree using ctree

2011-12-06 Thread Antonio Punzon Merino
Dear, 
I would like know the way to calculate the variance explained of a regression 
tree. I use the function ctree from library party
many thanks

[[alternative HTML version deleted]]

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


Re: [R] RStudio: copied line is always not the same as the line that I highlighted

2011-12-06 Thread Jeff Newmiller
RStudio is not R. Go ask the RStudio support people at www.rstudio.org.
---
Jeff NewmillerThe .   .  Go Live...
DCN:jdnew...@dcn.davis.ca.usBasics: ##.#.   ##.#.  Live Go...
  Live:   OO#.. Dead: OO#..  Playing
Research Engineer (Solar/BatteriesO.O#.   #.O#.  with
/Software/Embedded Controllers)   .OO#.   .OO#.  rocks...1k
--- 
Sent from my phone. Please excuse my brevity.

Michael comtech@gmail.com wrote:

Hi all,

I am using RStudio. I wanted to copy and past an expression/line.

I highlighted it, and then copied and pasted:

The result was not the line that I wanted, instead, it was the line
above...

For example:

I have three lines:



a
b
c


I highlighted b and copied, but the pasted outcome was a...

What happened?

Thanks al ot!

   [[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] To Try or to TryCatch, I have tried to long

2011-12-06 Thread ROLL Josh F
 Thank for the links.  I reread one I found yesterday about changing the 
options parameter to options(warn = 2) and that allows the try() function to 
see a warning the same way as an error so problem solved using the existing 
code.  

Cheers, 
 Josh

-Original Message-
From: William Dunlap [mailto:wdun...@tibco.com] 
Sent: Tuesday, December 06, 2011 11:42 AM
To: gleyne...@gmail.com; ROLL Josh F
Cc: r-help@r-project.org
Subject: RE: [R] To Try or to TryCatch, I have tried to long

Or, Google for 'R catching warnings' and third entry is the excellent
  http://www.stats.uwo.ca/faculty/murdoch/software/debuggingR/

Bill Dunlap
Spotfire, TIBCO Software
wdunlap tibco.com 

 -Original Message-
 From: r-help-boun...@r-project.org 
 [mailto:r-help-boun...@r-project.org] On Behalf Of William Dunlap
 Sent: Tuesday, December 06, 2011 11:38 AM
 To: gleyne...@gmail.com; ROLL Josh F
 Cc: r-help@r-project.org
 Subject: Re: [R] To Try or to TryCatch, I have tried to long
 
 Look at the archives of this mailing list for a discussion entitled 
 'Stack trace?' on Nov 9-10 of this year.
 
 Bill Dunlap
 Spotfire, TIBCO Software
 wdunlap tibco.com
 
  -Original Message-
  From: r-help-boun...@r-project.org 
  [mailto:r-help-boun...@r-project.org] On Behalf Of Gene Leynes
  Sent: Tuesday, December 06, 2011 10:58 AM
  To: ROLL Josh F
  Cc: r-help@r-project.org
  Subject: Re: [R] To Try or to TryCatch, I have tried to long
 
  I've had the same problem in other cases.
 
  Does anyone know how to catch warnings as well as errors?
 
  On Tue, Dec 6, 2011 at 12:34 PM, ROLL Josh F jr...@lcog.org wrote:
 
   **
   Agreed.  But what I am trying to control is when I get a warning.  
   I want to do something different if a warning OR an error pop up?  Any 
   ideas?
  
   Cheers
  
--
   *From:* gley...@gmail.com [mailto:gley...@gmail.com] *On Behalf Of 
   *Gene Leynes
   *Sent:* Tuesday, December 06, 2011 10:27 AM
   *To:* ROLL Josh F
   *Cc:* r-help@r-project.org
   *Subject:* Re: [R] To Try or to TryCatch, I have tried to long
  
   I think the problem is that it's only a warning and not an error.
  
   result_-list()
   for(i in 1:10){
if(inherits(try(sqrt(9-i),silent=TRUE),try-error)){
#If sqrt fails
cat('fail',i,'\n')
result_[[i]]-0 } else {
#If sqrt succeeds
cat('succeed',i,'\n')
result_[[i]] - 1 }
   }
   result_
  
   On Tue, Dec 6, 2011 at 11:11 AM, LCOG1 jr...@lcog.org wrote:
  
   So after about 4 hours struggling with Try and TryCatch I am 
   throwing in the towel.  I have a more complicated function that 
   used logspline through iterative distributions and at some point 
   the logspline doesnt function correctly for some subsets but is 
   fine with others so I need to be able to identify when the error 
   occurs and stop curtailing the distribution and I think this Try 
   or TryCatch should do the trick but I think I am missing 
   something here. A simple example
  
  
   result_-list()
   for(i in 1:10){
if(inherits(try(sqrt(9-i),silent=TRUE),try-error)){
  #If sqrt fails
  result_[[i]]-0 } else {
  #If sqrt succeeds
  result_[[i]] - 1 } }
  
  
   I would expect this to fail only when i  9 but succeeds  each time.  DO 
   i
   need to specify something different where try-error resides?  Thanks
   guys
  
   Cheers,
Josh
  
  
   --
   View this message in context:
   http://r.789695.n4.nabble.com/To-Try-or-to-TryCatch-I-have-tried-to-long-tp4165578p4165578.html
   Sent from the R help mailing list archive at Nabble.com.
  
   __
   R-help@r-project.org mailing list
   https://stat.ethz.ch/mailman/listinfo/r-help
   PLEASE do read the posting guide
   http://www.R-project.org/posting-guide.html
   and provide commented, minimal, self-contained, reproducible code.
  
  
  
 
  [[alternative HTML version deleted]]
 
  __
  R-help@r-project.org mailing list
  https://stat.ethz.ch/mailman/listinfo/r-help
  PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
  and provide commented, minimal, self-contained, reproducible code.
 
 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/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] making changes to global variables in functions

2011-12-06 Thread Yev
I'm trying to write a function that takes several objects with many
different attributes and then changes their attributes. So what I wanted to
happen in the simplified example below is for the function to change the
attributes of the objects state1 and state2 that are passed to it. But
because stateA and stateB are local, this isn't working. Are there any easy
solutions?

e.g., if I could combine the two objects stateA and stateB into a single
object, I could return it and then assign it back to objects state1 and
state2. Or if I could pass a pointer to the original object.. But I cannot
find an easy way of doing either.  Thanks in advance..

state1 - list(n=100, won=0)
state2 - list(n=100, won=0)

fight2 - function(stateA, stateB){
   stateA$n - 50
   stateB$n -50
}

fight2(state1,state2)

state1$n
state2$n

[[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] Writing out in loops

2011-12-06 Thread Thomas
Thanks for the reply. I'm writing data out as it is generated into a number of 
different files and not saving it as I go (although I could - not sure which 
would be quicker). In fact I tried this today and  the approach with the loop 
seems to run reasonably fast.

Thomas

On 6 Dec 2011, at 15:07, Sarah Goslee wrote:

 Is there some reason you can't create the entire file in R and then write it
 out in a single step?
 
 It looks like you're writing out
 mat[1, 1:10]
 so you could just use
 write.table(mat[1, 1:10], filen)
 
 Can you expand on what you're trying to do?
 
 Sarah
 
 On Tue, Dec 6, 2011 at 4:18 AM, Thomas chesney@gmail.com wrote:
 I would like to write some data to different files. I can create the
 filename Day1.txt like this:
 
 filen - paste(Day, l, .txt, sep=)
 
 and then I'm using a For loop to write out one row of a matrix, something
 like this:
 
 For (j in 1:10)
 {
 cat(mat[1,j], ,, file=filen, append=TRUE)
 }
 cat(\n, file=filen, append=TRUE)
 
 but is there a better way to do this?
 
 Thank you,
 
 Thomas
 
 
 
 -- 
 Sarah Goslee
 http://www.functionaldiversity.org

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


Re: [R] help wrapping findInterval into a function

2011-12-06 Thread William Dunlap
No, the problem is not with with but is
that the OP's did not return the modified
data.frame.  He didn't show how the function
was called, but I suspect the usage was like
  f0 - function() globalDataFrame$newCol - ...
  f0()
where it should have been
  f1 - function(dataFrame) {
dataFrame$newCol - ...
dataFrame # return modified dataFrame
  }
  globalDataFrame - f1(globalDataFrame)

Bill Dunlap
Spotfire, TIBCO Software
wdunlap tibco.com 

 -Original Message-
 From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On 
 Behalf Of David Winsemius
 Sent: Tuesday, December 06, 2011 12:05 PM
 To: Steve E.
 Cc: r-help@r-project.org
 Subject: Re: [R] help wrapping findInterval into a function
 
 
 On Dec 6, 2011, at 11:43 AM, Steve E. wrote:
 
  Dear R Community,
 
  I hope you might be able to assist with a small problem creating a
  function.
  I am working with water-quality data sets that contain the
  concentration of
  many different elements in water samples.  I need to assign quality-
  control
  flags to values that fall into various concentration ranges.  Rather
  than a
  web of nested if statements, I am employing the findInterval
  function to
  identify values that need to be flagged and to assign the
  appropriate flag.
 
 It's probably your use of with rather than findInterval. The 'with'
 function sets up an environment and is used mostly in interactive
 session. If you have not passed a dataframe into the function then you
 should use the name of the dataframe and '['.
 
 
  The data consist of a sample identifier, the analysis, and
  corresponding
  value.  The findInterval function works well; however, I would like to
  incorporate it into a function so that I can run multiple findInterval
  functions for many different water-quality analyses (and I have to
  do this
  for many dataset) but it seems to fall apart when incorporated into a
  function.
 
  Run straighforward, the findInterval function works as desired, e.g.
  below,
  creating the new CalciumFlag column with the appropriate flag for,
  in this
  case, levels of calcium in the water:
 
  WQdata$CalciumFlag - with(WQdata, ifelse(analysis == Calcium,
  (flags -
  c(Y, 'Q', , A) [findInterval(WQdata$value, c(-Inf, 0.027, 0.1,
  100,
  Inf))]),))
 
  However, it does not worked when wrapped in a function (no error
  messages
  are thrown, it simply does not seem to do anything):
 
  WQfunc - function() {
  WQdata$CalciumFlag - with(WQdata, ifelse(analysis == Calcium,
  (flags -
  c(Y, 'Q', , A) [findInterval(WQdata$value, c(-Inf, 0.027, 0.1,
  100,
  Inf))]),))
  }
 
  Calling the function WQfunc() does not produce an error but also
  does not
  produce the expected CalciumFlag, it seems to not do anything.
 
  Ultimately, what I need to get to is something like below where
  multiple
  findInterval functions for different analyses are included in a single
  function, then I can concatenate the results into a single column
  containing
  all flags for all analyses, e.g.:
 
  WQfunc - function() {
  WQdata$CalciumFlag - with(WQdata, ifelse(analysis == Calcium,
  (flags -
  c(Y, 'Q', , A) [findInterval(WQdata$value, c(-Inf, 0.027, 0.1,
  100,
  Inf))]),))
 
  WQdata$SodiumFlag - with(WQdata, ifelse(analysis == Sodium,
  (flags -
  c(Y, 'Q', , A) [findInterval(WQdata$value, c(-Inf, 0.050,
  0.125, 125,
  Inf))]),))
 
  WQdata$MagnesiumFlag - with(WQdata, ifelse(analysis ==
  Magnesium, (flags
  - c(Y, 'Q', , A) [findInterval(WQdata$value, c(-Inf, 0.065,
  0.15, 75,
  Inf))]),))
 
  .etc for additional water-quality analyses...
 
  }
 
  As an aside, I started working with the findInterval tool from an
  example
  that I found online but am not clear as to how the multi-component
  configuration incorporating brackets actually works, can anyone
  suggest a
  good resource that explains this?
 
 
  I thank you very much for any assistance you may be able to provide.
 
 
  Regards,
  Steve
 
  --
  View this message in context: 
  http://r.789695.n4.nabble.com/help-wrapping-findInterval-into-a-
 function-tp4165464p4165464.html
  Sent from the R help mailing list archive at Nabble.com.
 
  __
  R-help@r-project.org mailing list
  https://stat.ethz.ch/mailman/listinfo/r-help
  PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
  and provide commented, minimal, self-contained, reproducible code.
 
 David Winsemius, MD
 West Hartford, CT
 
 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and 

Re: [R] varaince explined of a regression tree using ctree

2011-12-06 Thread Patrick Breheny

On 12/06/2011 03:05 PM, Antonio Punzon Merino wrote:

I would like know the way to calculate the variance explained of a
regression tree. I use the function ctree from library party


ctree does not provide this information by default, but it is not 
difficult to calculate:


X - matrix(rnorm(100*10),ncol=10)
y - X%*%c(rep(2,5),rep(0,5))+rnorm(100)
fit - ctree(y~.,data=as.data.frame(X))
r - y - predict(fit)
1-var(r)/var(y)

--
Patrick Breheny
Assistant Professor
Department of Biostatistics
Department of Statistics
University of Kentucky

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


[R] using StatEt IDE for Eclipse

2011-12-06 Thread Matteo Richiardi
Hi,
I'm trying to use StatEt IDE for Eclipse as my R editor, but I'm completely
lost. I've read all I could find online, made apparently all I had to do
(installing rj, configuraing StatEt, etc.) but still cannot make R running.
Below is the error log file.
Thank you so much for assistance.
Matteo


!ENTRY de.walware.statet.r.console.ui 1 0 2011-12-05 16:21:51.355
!MESSAGE Launching the R Console was cancelled, because it seems starting
the R engine failed.
Please make sure that R package 'rj' (1.0.0 or compatible) is installed and
that the R library paths are set correctly for the R environment
configuration 'R-2.14.0'.
!SESSION 2011-12-05 16:23:23.552
---
eclipse.buildId=M20110909-1335
java.version=1.6.0_21
java.vendor=Sun Microsystems Inc.
BootLoader constants: OS=win32, ARCH=x86_64, WS=win32, NL=it_IT
Command-line arguments:  -os win32 -ws win32 -arch x86_64

!ENTRY org.eclipse.osgi 2 1 2011-12-05 16:23:29.901
!MESSAGE NLS unused message: FindReplaceAction_label in:
de.walware.ecommons.ui.SharedMessages

!ENTRY org.eclipse.ui 4 4 2011-12-05 16:23:30.712
!MESSAGE Class load Failure:
'org.eclipse.ecf.docshare.menu.DocShareRosterMenuContributionItem'

!ENTRY org.eclipse.ui 4 0 2011-12-05 16:23:30.714
!MESSAGE Class load Failure:
'org.eclipse.ecf.docshare.menu.DocShareRosterMenuContributionItem'
!STACK 1
org.eclipse.core.runtime.CoreException: Plug-in de.walware.ecommons.ltk.ui
was unable to load class
org.eclipse.ecf.docshare.menu.DocShareRosterMenuContributionItem.
 at
org.eclipse.core.internal.registry.osgi.RegistryStrategyOSGI.throwException(RegistryStrategyOSGI.java:194)
at
org.eclipse.core.internal.registry.osgi.RegistryStrategyOSGI.createExecutableExtension(RegistryStrategyOSGI.java:176)
 at
org.eclipse.core.internal.registry.ExtensionRegistry.createExecutableExtension(ExtensionRegistry.java:905)
at
org.eclipse.core.internal.registry.ConfigurationElement.createExecutableExtension(ConfigurationElement.java:243)
 at
org.eclipse.core.internal.registry.ConfigurationElementHandle.createExecutableExtension(ConfigurationElementHandle.java:55)
at
org.eclipse.ui.internal.util.Util.safeLoadExecutableExtension(Util.java:879)
 at
org.eclipse.ui.internal.menus.DynamicMenuContributionItem.createContributionItem(DynamicMenuContributionItem.java:222)
at
org.eclipse.ui.internal.menus.DynamicMenuContributionItem.getContributionItem(DynamicMenuContributionItem.java:215)
 at
org.eclipse.ui.internal.menus.DynamicMenuContributionItem.fill(DynamicMenuContributionItem.java:195)
at org.eclipse.jface.action.MenuManager.doItemFill(MenuManager.java:741)
 at org.eclipse.jface.action.MenuManager.update(MenuManager.java:822)
at org.eclipse.jface.action.MenuManager.update(MenuManager.java:682)
 at
org.eclipse.ui.internal.menus.WorkbenchMenuService.updateManagers(WorkbenchMenuService.java:330)
at
org.eclipse.ui.internal.menus.WorkbenchMenuService$4.propertyChange(WorkbenchMenuService.java:316)
 at
org.eclipse.ui.internal.services.EvaluationAuthority$1.run(EvaluationAuthority.java:252)
at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42)
 at
org.eclipse.ui.internal.services.EvaluationAuthority.fireServiceChange(EvaluationAuthority.java:246)
at
org.eclipse.ui.internal.services.EvaluationAuthority.endSourceChange(EvaluationAuthority.java:197)
 at
org.eclipse.ui.internal.services.EvaluationAuthority.sourceChanged(EvaluationAuthority.java:135)
at
org.eclipse.ui.internal.services.ExpressionAuthority.sourceChanged(ExpressionAuthority.java:311)
 at
org.eclipse.ui.internal.services.ExpressionAuthority.sourceChanged(ExpressionAuthority.java:290)
at
org.eclipse.ui.AbstractSourceProvider.fireSourceChanged(AbstractSourceProvider.java:99)
 at
org.eclipse.ui.internal.services.WorkbenchSourceProvider.checkActivePart(WorkbenchSourceProvider.java:401)
at
org.eclipse.ui.internal.services.WorkbenchSourceProvider.checkActivePart(WorkbenchSourceProvider.java:300)
 at
org.eclipse.ui.internal.services.WorkbenchSourceProvider.handleCheck(WorkbenchSourceProvider.java:286)
at
org.eclipse.ui.internal.services.WorkbenchSourceProvider.checkOtherSources(WorkbenchSourceProvider.java:855)
 at
org.eclipse.ui.internal.services.WorkbenchSourceProvider$6.handleEvent(WorkbenchSourceProvider.java:839)
at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)
 at org.eclipse.swt.widgets.Display.filterEvent(Display.java:1262)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1052)
 at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1077)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1058)
 at org.eclipse.swt.widgets.Decorations.WM_ACTIVATE(Decorations.java:1647)
at org.eclipse.swt.widgets.Shell.WM_ACTIVATE(Shell.java:2137)
 at org.eclipse.swt.widgets.Control.windowProc(Control.java:4525)
at org.eclipse.swt.widgets.Canvas.windowProc(Canvas.java:341)
 at org.eclipse.swt.widgets.Decorations.windowProc(Decorations.java:1610)
at org.eclipse.swt.widgets.Shell.windowProc(Shell.java:2061)
 at 

Re: [R] making changes to global variables in functions

2011-12-06 Thread R. Michael Weylandt
No pointer functionality in R (that I know of), but if you want to
return two objects as one the standard way is to put them in a list
and to return that list.

Michael

On Tue, Dec 6, 2011 at 2:35 PM, Yev kirp...@gmail.com wrote:
 I'm trying to write a function that takes several objects with many
 different attributes and then changes their attributes. So what I wanted to
 happen in the simplified example below is for the function to change the
 attributes of the objects state1 and state2 that are passed to it. But
 because stateA and stateB are local, this isn't working. Are there any easy
 solutions?

 e.g., if I could combine the two objects stateA and stateB into a single
 object, I could return it and then assign it back to objects state1 and
 state2. Or if I could pass a pointer to the original object.. But I cannot
 find an easy way of doing either.  Thanks in advance..

 state1 - list(n=100, won=0)
 state2 - list(n=100, won=0)

 fight2 - function(stateA, stateB){
   stateA$n - 50
   stateB$n -50
 }

 fight2(state1,state2)

 state1$n
 state2$n

        [[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] using StatEt IDE for Eclipse

2011-12-06 Thread Luke Miller
You will likely find more help on the StatEt mailing list, since the
author of the package monitors it:

http://lists.r-forge.r-project.org/mailman/listinfo/statet-user



On Tue, Dec 6, 2011 at 4:04 PM, Matteo Richiardi
matteo.richia...@gmail.com wrote:

 Hi,
 I'm trying to use StatEt IDE for Eclipse as my R editor, but I'm completely
 lost. I've read all I could find online, made apparently all I had to do
 (installing rj, configuraing StatEt, etc.) but still cannot make R running.
 Below is the error log file.
 Thank you so much for assistance.
 Matteo


 !ENTRY de.walware.statet.r.console.ui 1 0 2011-12-05 16:21:51.355
 !MESSAGE Launching the R Console was cancelled, because it seems starting
 the R engine failed.
 Please make sure that R package 'rj' (1.0.0 or compatible) is installed and
 that the R library paths are set correctly for the R environment
 configuration 'R-2.14.0'.
 !SESSION 2011-12-05 16:23:23.552
 ---
 eclipse.buildId=M20110909-1335
 java.version=1.6.0_21
 java.vendor=Sun Microsystems Inc.
 BootLoader constants: OS=win32, ARCH=x86_64, WS=win32, NL=it_IT
 Command-line arguments:  -os win32 -ws win32 -arch x86_64

 !ENTRY org.eclipse.osgi 2 1 2011-12-05 16:23:29.901
 !MESSAGE NLS unused message: FindReplaceAction_label in:
 de.walware.ecommons.ui.SharedMessages

 !ENTRY org.eclipse.ui 4 4 2011-12-05 16:23:30.712
 !MESSAGE Class load Failure:
 'org.eclipse.ecf.docshare.menu.DocShareRosterMenuContributionItem'

 !ENTRY org.eclipse.ui 4 0 2011-12-05 16:23:30.714
 !MESSAGE Class load Failure:
 'org.eclipse.ecf.docshare.menu.DocShareRosterMenuContributionItem'
 !STACK 1
 org.eclipse.core.runtime.CoreException: Plug-in de.walware.ecommons.ltk.ui
 was unable to load class
 org.eclipse.ecf.docshare.menu.DocShareRosterMenuContributionItem.
  at
 org.eclipse.core.internal.registry.osgi.RegistryStrategyOSGI.throwException(RegistryStrategyOSGI.java:194)
 at
 org.eclipse.core.internal.registry.osgi.RegistryStrategyOSGI.createExecutableExtension(RegistryStrategyOSGI.java:176)
  at
 org.eclipse.core.internal.registry.ExtensionRegistry.createExecutableExtension(ExtensionRegistry.java:905)
 at
 org.eclipse.core.internal.registry.ConfigurationElement.createExecutableExtension(ConfigurationElement.java:243)
  at
 org.eclipse.core.internal.registry.ConfigurationElementHandle.createExecutableExtension(ConfigurationElementHandle.java:55)
 at
 org.eclipse.ui.internal.util.Util.safeLoadExecutableExtension(Util.java:879)
  at
 org.eclipse.ui.internal.menus.DynamicMenuContributionItem.createContributionItem(DynamicMenuContributionItem.java:222)
 at
 org.eclipse.ui.internal.menus.DynamicMenuContributionItem.getContributionItem(DynamicMenuContributionItem.java:215)
  at
 org.eclipse.ui.internal.menus.DynamicMenuContributionItem.fill(DynamicMenuContributionItem.java:195)
 at org.eclipse.jface.action.MenuManager.doItemFill(MenuManager.java:741)
  at org.eclipse.jface.action.MenuManager.update(MenuManager.java:822)
 at org.eclipse.jface.action.MenuManager.update(MenuManager.java:682)
  at
 org.eclipse.ui.internal.menus.WorkbenchMenuService.updateManagers(WorkbenchMenuService.java:330)
 at
 org.eclipse.ui.internal.menus.WorkbenchMenuService$4.propertyChange(WorkbenchMenuService.java:316)
  at
 org.eclipse.ui.internal.services.EvaluationAuthority$1.run(EvaluationAuthority.java:252)
 at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42)
  at
 org.eclipse.ui.internal.services.EvaluationAuthority.fireServiceChange(EvaluationAuthority.java:246)
 at
 org.eclipse.ui.internal.services.EvaluationAuthority.endSourceChange(EvaluationAuthority.java:197)
  at
 org.eclipse.ui.internal.services.EvaluationAuthority.sourceChanged(EvaluationAuthority.java:135)
 at
 org.eclipse.ui.internal.services.ExpressionAuthority.sourceChanged(ExpressionAuthority.java:311)
  at
 org.eclipse.ui.internal.services.ExpressionAuthority.sourceChanged(ExpressionAuthority.java:290)
 at
 org.eclipse.ui.AbstractSourceProvider.fireSourceChanged(AbstractSourceProvider.java:99)
  at
 org.eclipse.ui.internal.services.WorkbenchSourceProvider.checkActivePart(WorkbenchSourceProvider.java:401)
 at
 org.eclipse.ui.internal.services.WorkbenchSourceProvider.checkActivePart(WorkbenchSourceProvider.java:300)
  at
 org.eclipse.ui.internal.services.WorkbenchSourceProvider.handleCheck(WorkbenchSourceProvider.java:286)
 at
 org.eclipse.ui.internal.services.WorkbenchSourceProvider.checkOtherSources(WorkbenchSourceProvider.java:855)
  at
 org.eclipse.ui.internal.services.WorkbenchSourceProvider$6.handleEvent(WorkbenchSourceProvider.java:839)
 at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)
  at org.eclipse.swt.widgets.Display.filterEvent(Display.java:1262)
 at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1052)
  at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1077)
 at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1058)
  at 

Re: [R] Change the limits of a plot a posteriori

2011-12-06 Thread Greg Snow
The zoomplot function in the TeachingDemos package can be used for this (it 
actually redoes the entire plot, but with new limits).  This will generally 
work for a quick exploration, but for quality plots it is suggested to create 
the 1st plot with the correct range to begin with.

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


 -Original Message-
 From: r-help-boun...@r-project.org [mailto:r-help-bounces@r-
 project.org] On Behalf Of jcano
 Sent: Thursday, December 01, 2011 11:12 AM
 To: r-help@r-project.org
 Subject: [R] Change the limits of a plot a posteriori
 
 Hi all
 
 How can I change the limits (xlim or ylim) in a plot that has been
 already
 created?
 
 For example, consider this naive example
 curve(dbeta(x,2,4))
 curve(dbeta(x,8,13),add=T,col=2)
 
 When adding the second curve, it goes off the original limits computed
 by R
 for the first graph, which are roughly, c(0,2.1)
 
 I know two obvious solutions for this, which are:
 1) passing a sufficiently large parameter e.g. ylim=c(0,4) to the first
 graphic
 curve(dbeta(x,2,4),ylim=c(0,4))
 curve(dbeta(x,8,13),add=T,col=2)
 
 or
 
 2) switch the order in which I plot the curves
 curve(dbeta(x,8,13),col=2)
 curve(dbeta(x,2,4),add=T)
 
 but I guess if there is any way of adjusting the limits of the graphic
 a
 posteriori, once you have a plot with the undesired limits, forcing R
 to
 redraw it with the new limits, but without having to execute again the
 curve commands
 
 Hope I made myself clear
 
 Best regards and thank you very much in advance
 
 
 --
 View this message in context: http://r.789695.n4.nabble.com/Change-the-
 limits-of-a-plot-a-posteriori-tp4129750p4129750.html
 Sent from the R help mailing list archive at Nabble.com.
 
 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-
 guide.html
 and provide commented, minimal, self-contained, reproducible code.

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


[R] any R-Revolution users here? How to make Revolution portable?

2011-12-06 Thread Michael
How to make a portable version of Revolution R?

I just wanted to be able to carry it anywhere I go in a USB drive...

I don't need fancy functionalities, just need the visual debugger therein...
btw, Windows or Linux doesn't matter...

Any thoughts?

Thanks a lot!

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


  1   2   >