Re: [R] appending to a vector

2011-04-14 Thread Jonathan P Daily
Neither is the fastest method. The best way would be to vectorize func so 
that it accepts and returns a vector. Many builtin R functions do this and 
say so in their documentation.

The slower way would be to use one of the apply functions, such as:

?lapply
x2 - lapply(x, func)

If you must use a for loop, your second example is faster since it does 
not rewrite x2 each iteration.

An excellent reference on this subject and many other R pitfalls is 'The R 
Inferno'

http://lib.stat.cmu.edu/s/Spoetry/Tutor/R_inferno.pdf 
--
Jonathan P. Daily
Technician - USGS Leetown Science Center
11649 Leetown Road
Kearneysville WV, 25430
(304) 724-4480
Is the room still a room when its empty? Does the room,
 the thing itself have purpose? Or do we, what's the word... imbue it.
 - Jubal Early, Firefly

r-help-boun...@r-project.org wrote on 04/14/2011 04:59:04 AM:

 [image removed] 
 
 [R] appending to a vector
 
 dirknbr 
 
 to:
 
 r-help
 
 04/14/2011 11:32 AM
 
 Sent by:
 
 r-help-boun...@r-project.org
 
 Which one is more efficient?
 
 x2=c()
 for (i in 1:length(x)) {
  x2=c(x2,func(x[i]))
 }
 
 or 
 
 x2=x
 for (i in 1:length(x)) {
  x2=func(x[i])
 }
 
 where func is any function?
 
 Dirk 
 
 --
 View this message in context: http://r.789695.n4.nabble.com/
 appending-to-a-vector-tp3449109p3449109.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] Using help in Windows version of R with disabled browser

2011-04-12 Thread Jonathan P Daily
try:

options(help_type = 'text')
?options

If this works, you can create a site profile (A default is created 
automatically in windows, if I remember correctly) where you can set this 
to run in each session.
--
Jonathan P. Daily
Technician - USGS Leetown Science Center
11649 Leetown Road
Kearneysville WV, 25430
(304) 724-4480
Is the room still a room when its empty? Does the room,
 the thing itself have purpose? Or do we, what's the word... imbue it.
 - Jubal Early, Firefly



From:
Ranjan Maitra mai...@iastate.edu
To:
R-help r-h...@stat.math.ethz.ch
Date:
04/12/2011 01:56 PM
Subject:
[R] Using help in Windows version of R with disabled browser
Sent by:
r-help-boun...@r-project.org



Dear colleagues,

I am trying to get someone to use R on MS Windows with the browser
disabled. My question is how does he/she get to use R-help which goes
off the browser (and correspondingly complains about the inability to
start firefox, etc). In linux, which is what I use, this is not a
problem: what needs to be set in Windows to replicate this behavior?

Sorry if I am not clear: please feel free to ask me for clarifications. 

Thanks again for the helpful advice!

Best wishes,
Ranjan

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

2011-04-11 Thread Jonathan P Daily
It is asking the obvious, but did you run the commands from the rcom 
package after installation (see inline ***s)?
--
Jonathan P. Daily
Technician - USGS Leetown Science Center
11649 Leetown Road
Kearneysville WV, 25430
(304) 724-4480
Is the room still a room when its empty? Does the room,
 the thing itself have purpose? Or do we, what's the word... imbue it.
 - Jubal Early, Firefly

r-help-boun...@r-project.org wrote on 04/11/2011 02:08:02 PM:

 [image removed] 
 
 [R] RExcel
 
 array chip 
 
 to:
 
 r-help
 
 04/11/2011 02:12 PM
 
 Sent by:
 
 r-help-boun...@r-project.org
 
 Hi, I am installing Excel using package RExcelInstaller. When I 
 tried to run 
 
 installRExcel()
 
 I got this error message:
 
 You don not have the R package rcom installed.
 The (D)COM server installed which will aloow you to use the 
 background server in 
 RExcel.
 Since rcom is not installed, foreground mode will be unavailable.
 
 You may continue with the installation, but in most circumstances 
 you probably 
 should cancel current installation, install the package rcom properly 
(do not 
 forget to run the commands

   library(rcom)
   comRegisterRegistry()

 immediately after installation)
 and after that run this installer once again
 
 
 But rcom package was installed without any problem, somehow the 
 installer keeps 
 saying that rcom is not installed.
 
 Any suggestions?
 
 Thanks
 
 John
 
  sessionInfo()
 R version 2.12.2 (2011-02-25)
 Platform: i386-pc-mingw32/i386 (32-bit)
 
 locale:
 [1] LC_COLLATE=English_United States.1252 
 [2] LC_CTYPE=English_United States.1252 
 [3] LC_MONETARY=English_United States.1252
 [4] LC_NUMERIC=C 
 [5] LC_TIME=English_United States.1252 
 
 attached base packages:
 [1] stats graphics  grDevices utils datasets  methods   base 
 
 other attached packages:
 [1] RExcelInstaller_3.1-13 rcom_2.2-3.1   rscproxy_1.3-1 
 
 loaded via a namespace (and not attached):
 [1] tools_2.12.2
[[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] Estimates at each iteration

2011-04-08 Thread Jonathan P Daily
I'm assuming that English is not your first language. In light of that, I 
would suggest that you post your question in a language that we both 
speak: R. Please include:

1) E-step and M-step functions.
2) The proposed optim/maxLik call.

Mostly because (at least optim) does not have a parameter called 
limiter.

HtoH,
Jon
--
Jonathan P. Daily
Technician - USGS Leetown Science Center
11649 Leetown Road
Kearneysville WV, 25430
(304) 724-4480
Is the room still a room when its empty? Does the room,
 the thing itself have purpose? Or do we, what's the word... imbue it.
 - Jubal Early, Firefly

r-help-boun...@r-project.org wrote on 04/08/2011 08:16:36 AM:

 [image removed] 
 
 [R] Estimates at each iteration
 
 hello bye 
 
 to:
 
 r-help
 
 04/08/2011 11:45 AM
 
 Sent by:
 
 r-help-boun...@r-project.org
 
 Dear Sir\ Madam
  I am trying to maximise a complicated loglikelihood function  via 
 EM algorithm 
 which consists of two step E-step and M-stepand in this case I need to 

 maximize the expected of like lihood function  which I get from E- 
step and 
 take those estimates of parameter to update the E-step and repate these 
till 
 convargence has been met. So I need to know if I control the number 
 of iterlim 
 in maxLik or optim Package by puting this number equals to one to 
maximize 
 M-step and getting  just the estimates of parameter for one 
 iteration and hence 
 use them to update the E-step and again maximaize M-step by using maxLik 
or 
 optim by contoling the number of limiter and putting the number equals 
to 1 
 is it true and acceptance? I mean if I do this my results can be 
 reasonable?. please I am waiting your response.
 Regards
 Fauzia Taweab
 phd.student.
[[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 *completely* stop a script after stop()?

2011-04-08 Thread Jonathan P Daily
Would options(error = recover) be of some help?
--
Jonathan P. Daily
Technician - USGS Leetown Science Center
11649 Leetown Road
Kearneysville WV, 25430
(304) 724-4480
Is the room still a room when its empty? Does the room,
 the thing itself have purpose? Or do we, what's the word... imbue it.
 - Jubal Early, Firefly

r-help-boun...@r-project.org wrote on 04/08/2011 12:38:37 PM:

 [image removed] 
 
 Re: [R] How to *completely* stop a script after stop()?
 
 Duncan Murdoch 
 
 to:
 
 algorimancer
 
 04/08/2011 12:40 PM
 
 Sent by:
 
 r-help-boun...@r-project.org
 
 Cc:
 
 r-help
 
 On 08/04/2011 11:47 AM, algorimancer wrote:
  I too am encountering this problem.  When I have a large script, if I 
select
  all in the editor and then ctrl-r to run, if it encounters a stop() 
function
  it simply prints an error message and continues to execute the 
remainder of
  the script, as opposed to terminating execution at that line.  The 
quit()
  function exits R altogether, which I don't want.  Yes, I could 
manually
  select only the portion of script which I want to run, but for lengthy
  scripts which I run repeatedly (generally changing only the name of 
the file
  I want analyzed), this can be quite tedious.  It appears that the only
  solution is to put most of the code in a separate file and call it 
using
  source(); this has the downside of reducing the clarity of the code -- 
it's
  a sort-of structural spaghetti code approach.
 
 It sounds as though you are talking about the Windows GUI.  That's 
 important, because other GUIs probably have different behaviour.
 
 To run a script up to the first error, do this:
 
 Highlight the part you want to run (or Ctrl-a for everything).
 Copy the code using Ctrl-c.
 In the console, run source(clipboard) (perhaps with echo=TRUE if you 
 want to see it as it goes).  This is a lot of typing the first time you 
 do it, but after that, the up arrow can bring back the command.
 
 It would probably make sense for Ctrl-R to do something functionally 
 equivalent to Ctrl-C, source(clipboard, echo=TRUE) rather than the 
 current behaviour.  Not going to happen in 2.13.x, but maybe in 2.14.x 
 in the fall.
 
 Duncan Murdoch
 
  --
  View this message in context: http://r.789695.n4.nabble.com/How-
 to-completely-stop-a-script-after-stop-tp3218808p3436704.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-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
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 graphics straight from R into published articles

2011-03-29 Thread Jonathan P Daily
I think you should google search Sweave, as well as check out the ?Sweave 
page.

Not to mention the graphics devices that embed quite nicely into 
documents, like ?postscript.

HTH,
Jon
--
Jonathan P. Daily
Technician - USGS Leetown Science Center
11649 Leetown Road
Kearneysville WV, 25430
(304) 724-4480
Is the room still a room when its empty? Does the room,
 the thing itself have purpose? Or do we, what's the word... imbue it.
 - Jubal Early, Firefly

r-help-boun...@r-project.org wrote on 03/29/2011 12:31:18 PM:

 [image removed] 
 
 [R] Using graphics straight from R into published articles
 
 blanco 
 
 to:
 
 r-help
 
 03/29/2011 12:44 PM
 
 Sent by:
 
 r-help-boun...@r-project.org
 
 Hi,
 I have been working with R for the past couple of years; analyzing data 
and
 producing some graphics.
 
 I was just wondering if people use graphics from R straight into 
articles or
 are they always edited  in some way; fonts, headers, axis, color etc? 
Using
 photoshop or some other programs?
 
 I would like to think it is possible, better and more profession to do 
it
 all in R.
 I tried google and the search option but found nothing on the topic. 
 
 What are the experiences for all the professionals out there that use R?
 Are there any articles on this specific subject?
 
 thanks,
 blanco
 
 --
 View this message in context: http://r.789695.n4.nabble.com/Using-
 graphics-straight-from-R-into-published-articles-tp3415401p3415401.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] passing arguments via ...

2011-03-29 Thread Jonathan P Daily
It is not clear to me exactly what you are looking to do, but if you are 
trying to check whether an argument has been passed via ..., I have used 
this convention before.

fun - function(arg, ...) {
opts - list(...)
if('opt' %in% names(opts)) # Do something...
}

Does that help?
--
Jonathan P. Daily
Technician - USGS Leetown Science Center
11649 Leetown Road
Kearneysville WV, 25430
(304) 724-4480
Is the room still a room when its empty? Does the room,
 the thing itself have purpose? Or do we, what's the word... imbue it.
 - Jubal Early, Firefly

r-help-boun...@r-project.org wrote on 03/29/2011 01:47:41 PM:

 [image removed] 
 
 [R] passing arguments via ...
 
 Cable, Samuel B Civ USAF AFMC AFRL/RVBXI 
 
 to:
 
 r-help
 
 03/29/2011 01:51 PM
 
 Sent by:
 
 r-help-boun...@r-project.org
 
 I would like to do something like the following:
 
 Fancyhist-function(x,...) {
 
 # first, process x into xprocess somehow, then ...
 
   if (is.null(breaks)) {   # yes, I know this is wrong
 # define the histogram breaks somehow, then call hist:
  hist(xprocess,breaks=breaks,...)
   } else {
 # use breaks give in calling argument
  hist(xprocess,...)
   }
 
 }
 
 But, those of you who know R better than I do have already spotted that
 is.null(breaks) just won't work.  Neither does exists or missing.
 
 I can think of ways to do this involving new arguments with new names --
 like histbreaks or something -- but that seems inelegant.
 
 Is there a way to do what I am trying to do here?
 
 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] ) Error in eval(expr, envir, enclos) : object '' not found

2011-03-23 Thread Jonathan P Daily
It looks like your column name has periods in it somewhere. Is your header 
separated by something other than commas?

look at:
names(data.sex)

or test by

age %in% names(data.sex)
--
Jonathan P. Daily
Technician - USGS Leetown Science Center
11649 Leetown Road
Kearneysville WV, 25430
(304) 724-4480
Is the room still a room when its empty? Does the room,
 the thing itself have purpose? Or do we, what's the word... imbue it.
 - Jubal Early, Firefly

r-help-boun...@r-project.org wrote on 03/23/2011 09:31:40 AM:

 [image removed] 
 
 [R] ) Error in eval(expr, envir, enclos) : object '' not found
 
 mipplor 
 
 to:
 
 r-help
 
 03/23/2011 10:11 AM
 
 Sent by:
 
 r-help-boun...@r-project.org
 
  datafilename=E:/my documents/r/sex/bysex1.csv
  data.sex=read.table(datafilename,header=T)
  data.sex
y.sex.age.region.c.n
 1   1980,F,A,N,-18.15,13.61
 2   1980,F,A,N,-18.61,13.04
 3   1980,F,A,N,-18.81,12.32
 41990,F,A,N,-21.12,11.7
 5   1990,F,A,N,-20.77,11.58
 61990,F,A,N,-21.6,13.34
 71990,F,A,N,-21.78,12.6
 
  model.anova-aov(c~age*sex,data=data.sex)
 Error in eval(expr, envir, enclos) : object 'age' not found
 
 
i just wanna do a anova test. but the error message is as above,,,
what should i do to shoot this problem ? Should i define the age?
 
 
 --
 View this message in context: http://r.789695.n4.nabble.com/Error-
 in-eval-expr-envir-enclos-object-not-found-tp3399503p3399503.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] memory increasing

2011-03-22 Thread Jonathan P Daily
1) What kind of file is a .dta?

2) Do you have more RAM than R is using? Check this with ?memory.limit

3) Are you on a 64 bit OS with 64 bit R?

I can tell you that starting R with --max-mem-size=
may help, but you probably want to look into R interfaces with databases 
first.
--
Jonathan P. Daily
Technician - USGS Leetown Science Center
11649 Leetown Road
Kearneysville WV, 25430
(304) 724-4480
Is the room still a room when its empty? Does the room,
 the thing itself have purpose? Or do we, what's the word... imbue it.
 - Jubal Early, Firefly

r-help-boun...@r-project.org wrote on 03/22/2011 10:17:13 AM:

 [image removed] 
 
 [R] memory increasing
 
 graziella 
 
 to:
 
 r-help
 
 03/22/2011 10:33 AM
 
 Sent by:
 
 r-help-boun...@r-project.org
 
 Dear All,
 I am an Italian researcher in Economics. I work with large sample data. 
I
 need to increase the memory in R-project in order to upload a file 
.dta.
 How can I do this?
 
 Thank you.
 graziella
 
 --
 View this message in context: http://r.789695.n4.nabble.com/memory-
 increasing-tp3396511p3396511.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] Understanding tryCatch

2011-03-18 Thread Jonathan P Daily
tryCatch will only execute it's error function on errors. If you are 
getting warnings, you may find it helpful to set:

options(warn = 2)
?options
tryCatch(warning(!), error = function(x) print(Error!))
--
Jonathan P. Daily
Technician - USGS Leetown Science Center
11649 Leetown Road
Kearneysville WV, 25430
(304) 724-4480
Is the room still a room when its empty? Does the room,
 the thing itself have purpose? Or do we, what's the word... imbue it.
 - Jubal Early, Firefly

r-help-boun...@r-project.org wrote on 03/18/2011 03:04:41 PM:

 [image removed] 
 
 [R] Understanding tryCatch
 
 steven mosher 
 
 to:
 
 r-help
 
 03/18/2011 03:07 PM
 
 Sent by:
 
 r-help-boun...@r-project.org
 
 I've read the help and the archives on tryCatch but I'm still stuggling
 trying to understand how it
 works exactly and how I can use it to get the result I need.
 
 I have a data.frame of urls which point to 11 .zip files. Basically I 
use
 RCurl to get the list of
 files from a ftp and then reduce that directory dump to the 11 zip files 
I
 want to download.
 
 Its easy enough to do that in a loop over the elements in data.frame.
 
 The problem is that the site is very inconsistent. All 11 files will
 download, but I will get random
 warnings that the size of some of the files does not match what was
 downloaded.
 So at the end of the loop I may get 5 warnings about the file size not
 matching.
 These files, when tried a second or third time, will eventually download
 properly.
 
 What I want to do is record which files had this download warning.
 
[[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] a question

2011-03-16 Thread Jonathan P Daily
What operating system are you working with? On windows, making it run by 
double clicking on it from explorer is not going to work. You will 
probably have to write a batch file that invokes Rterm or Rscript (see 
documentation for which you want to use). So if your script file is 
myscript.r, you could use Rterm myscript.r so long as the R executable 
directory is in the search path.

On linux, make sure to start your script starts with #!/usr/bin/env 
Rscript, and make it executable (i.e. chmod +x myscript.r). Now it should 
run when you type ./myscript.r

HTH,
Jon
--
Jonathan P. Daily
Technician - USGS Leetown Science Center
11649 Leetown Road
Kearneysville WV, 25430
(304) 724-4480
Is the room still a room when its empty? Does the room,
 the thing itself have purpose? Or do we, what's the word... imbue it.
 - Jubal Early, Firefly

r-help-boun...@r-project.org wrote on 03/16/2011 06:18:09 AM:

 [image removed] 
 
 [R] a question
 
 Jeela Mohammadian 
 
 to:
 
 r-help
 
 03/16/2011 08:59 AM
 
 Sent by:
 
 r-help-boun...@r-project.org
 
 Hi,
 
 I must seek a favour regarding of R project, 
 
 
 
 can we make an application out of R. I mean a small application that
 automatically runs and do the estimation automatically. Because the
 things I do is that I copy codes from script to work book and then it
 runs and gives the output. can it be done automatically?
 
 I will appreaciate if you could answer.
 
 Best Regards
 
 Jeela
 
 
 
 
 
 
[[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] Scope of variable?

2011-03-16 Thread Jonathan P Daily
?cat

cat prints text, and returns an invisible NULL. Also, it is general 
practice to assign values using '-' even inside of functions, for reasons 
detailed in ?-
--
Jonathan P. Daily
Technician - USGS Leetown Science Center
11649 Leetown Road
Kearneysville WV, 25430
(304) 724-4480
Is the room still a room when its empty? Does the room,
 the thing itself have purpose? Or do we, what's the word... imbue it.
 - Jubal Early, Firefly

r-help-boun...@r-project.org wrote on 03/16/2011 07:41:36 AM:

 [image removed] 
 
 [R] Scope of variable?
 
 Ravi Kulkarni 
 
 to:
 
 r-help
 
 03/16/2011 09:07 AM
 
 Sent by:
 
 r-help-boun...@r-project.org
 
 I know this is a very elementary question... I could not find a solution
 looking at old posts.
 I am unable to access a variable outside the scope of a for loop, even 
when
 the variable was defined before the loop:
 
 haar - function() {
 a = c(1.4560773, 2.3752412, 0.9798882, 3.0909252, 2.3986487, 1.8581543)
 
 for (i in c(1:100)) {
m = matrix(rnorm(36)+1i*rnorm(36),6)
qrm = qr(m)
Q = qr.Q(qrm)
eival = eigen(Q, only.values=T)
ph = Arg(eival$values)
v = Mod(ph)
a = cat(a,v) 
 }
 hist(a)
 }
 
 The hist command does not plot because a is null there.
 How do I plot a? I tried using 
 
   assign(a, a, envir = .GlobalEnv)
 
 but that does not help either... Neither did using -
 Any help is most welcome.
   Ravi
 
 --
 View this message in context: http://r.789695.n4.nabble.com/Scope-
 of-variable-tp3381485p3381485.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] (no subject)

2011-03-15 Thread Jonathan P Daily
I was wondering if there is a way to get read in a single keystroke at a 
time in R as a string, akin to ncurses-style interfaces. I looked into 
readLines, readChar, etc. using stdin, but these all require the use of an 
end of line. Has anyone ever had need to do this or have any ideas on how 
to do this?

Thanks,
Jon

PS I apologize if this double-sends, but I am having mail client issues.
--
Jonathan P. Daily
Technician - USGS Leetown Science Center
11649 Leetown Road
Kearneysville WV, 25430
(304) 724-4480
Is the room still a room when its empty? Does the room,
 the thing itself have purpose? Or do we, what's the word... imbue it.
 - Jubal Early, Firefly

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


Re: [R] Keyboard Input

2011-03-15 Thread Jonathan P Daily
I apologize for being unclear in my original post. What I am trying to 
achieve is to capture the stdin() connection and read in a single 
keystroke - including arrow keys and the like - without having to have to 
use the return key each time. My goal is to create a small UI for rapidly 
looking through the results of a large simulation. As I think about it 
more, though, it is probably going to be easier to dump the data into 
files and look through it outside of R.

Thanks anyways,

Jon
--
Jonathan P. Daily
Technician - USGS Leetown Science Center
11649 Leetown Road
Kearneysville WV, 25430
(304) 724-4480
Is the room still a room when its empty? Does the room,
 the thing itself have purpose? Or do we, what's the word... imbue it.
 - Jubal Early, Firefly

Bert Gunter gunter.ber...@gene.com wrote on 03/15/2011 10:08:51 AM:

 [image removed] 
 
 Re: [R] (no subject)
 
 Bert Gunter 
 
 to:
 
 Jonathan P Daily
 
 03/15/2011 10:08 AM
 
 Cc:
 
 r-help
 
 ?strsplit
 
 x - ThisIsaString
 y- strsplit(x,)
 
 This gives a list, which you can convert to a vector by unlist(y)
 
 Incidentally, you could have found out about strsplit via R's
 help.search(character string) (or similar) or even googling R
 string function . Please use R's native Help capabilities before
 posting to the list.
 
 (I will grant that the unlist()  trick may not be that easy to find).
 
 Also, it's often worthwhile searching the Help archives first. Peter
 Dalgaard answered this same question here a day or two ago.
 
 Cheers,
 Bert
 
 
 
 On Tue, Mar 15, 2011 at 6:35 AM, Jonathan P Daily jda...@usgs.gov 
wrote:
  I was wondering if there is a way to get read in a single keystroke at 
a
  time in R as a string, akin to ncurses-style interfaces. I looked into
  readLines, readChar, etc. using stdin, but these all require the use 
of an
  end of line. Has anyone ever had need to do this or have any ideas on 
how
  to do this?
 
  Thanks,
  Jon
 
  PS I apologize if this double-sends, but I am having mail client 
issues.
  --
  Jonathan P. Daily
  Technician - USGS Leetown Science Center
  11649 Leetown Road
  Kearneysville WV, 25430
  (304) 724-4480
  Is the room still a room when its empty? Does the room,
   the thing itself have purpose? Or do we, what's the word... imbue 
it.
  - Jubal Early, Firefly
 
  __
  R-help@r-project.org mailing list
  https://stat.ethz.ch/mailman/listinfo/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

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


Re: [R] indeterminate for loop

2011-03-15 Thread Jonathan P Daily
?while
You don't want a for loop. You need a while loop.
--
Jonathan P. Daily
Technician - USGS Leetown Science Center
11649 Leetown Road
Kearneysville WV, 25430
(304) 724-4480
Is the room still a room when its empty? Does the room,
 the thing itself have purpose? Or do we, what's the word... imbue it.
 - Jubal Early, Firefly

r-help-boun...@r-project.org wrote on 03/15/2011 10:14:21 AM:

 [image removed] 
 
 [R] indeterminate for loop
 
 lm609 
 
 to:
 
 r-help
 
 03/15/2011 10:16 AM
 
 Sent by:
 
 r-help-boun...@r-project.org
 
 Hello,
 
 I have written a 'for' loop which on the first run makes nearest 
neighbour 
 calculations for my dataset 'A' in relation to dataset 'B', then based 
on 
 these results, some of the rows from A are moved into dataset B, and the 

 calculation is repeated on the remaining rows in A. Therefore a smaller 
and 
 smaller amount of data is analysed as the loop proceeds, since A is 
losing 
 rows each time. The results of the calculation change as less data is 
used, 
 but not in a predictable way, therefore the end point of the loop is 
 indeterminate.
 
 The script is long and the datasets big, but a simplified example where 
'A' 
 and 'B' are datasets, and the function 'ndist2' calculates 'x' is...
 
 for (i in 1:100)
 {
 C - data.frame(ndist2(B,A))
 C1 - subset(C, x = min(C$x))
 B - rbind(B, C1)
 A - subset(C, x  min(C$x))
 }
 
 So eventually A runs out.
 
 Currently, I let the loop run until a warning comes up which effectively 

 says no more data, and at this point it is finished.
 
 What I would now like to do is place this loop inside another loop in 
order 
 to run through multiple datasets, but I can't do this when the script 
 produces a warning message at the end of each dataset.
 
 Is there any way I can overcome this problem?
 
 Thanks for your help,
 Louise
 
 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/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] Keyboard Input

2011-03-15 Thread Jonathan P Daily
Solved. Thanks.
--
Jonathan P. Daily
Technician - USGS Leetown Science Center
11649 Leetown Road
Kearneysville WV, 25430
(304) 724-4480
Is the room still a room when its empty? Does the room,
 the thing itself have purpose? Or do we, what's the word... imbue it.
 - Jubal Early, Firefly

Gabor Grothendieck ggrothendi...@gmail.com wrote on 03/15/2011 10:38:34 
AM:

 [image removed] 
 
 Re: [R] Keyboard Input
 
 Gabor Grothendieck 
 
 to:
 
 Jonathan P Daily
 
 03/15/2011 10:38 AM
 
 Cc:
 
 Bert Gunter, r-help
 
 On Tue, Mar 15, 2011 at 10:29 AM, Jonathan P Daily jda...@usgs.gov 
wrote:
  I apologize for being unclear in my original post. What I am trying to
  achieve is to capture the stdin() connection and read in a single
  keystroke - including arrow keys and the like - without having to have 
to
  use the return key each time. My goal is to create a small UI for 
rapidly
  looking through the results of a large simulation. As I think about it
  more, though, it is probably going to be easier to dump the data into
  files and look through it outside of R.
 
 
 See:
 http://r.789695.n4.nabble.com/detecting-a-key-press-td2324938.html
 
 -- 
 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] tryCatch - Continuing for/next loop after error

2011-03-10 Thread Jonathan P Daily
--
Jonathan P. Daily
Technician - USGS Leetown Science Center
11649 Leetown Road
Kearneysville WV, 25430
(304) 724-4480
Is the room still a room when its empty? Does the room,
 the thing itself have purpose? Or do we, what's the word... imbue it.
 - Jubal Early, Firefly

r-help-boun...@r-project.org wrote on 03/10/2011 03:51:15 AM:

 [image removed] 
 
 [R] tryCatch - Continuing for/next loop after error
 
 Costas 
 
 to:
 
 r-help
 
 03/10/2011 03:53 AM
 
 Sent by:
 
 r-help-boun...@r-project.org
 
 Please respond to costas.vorlow
 
 Dear all,
 
 I am not sure I understand fully the functionality of tryCatch and 
 try commands and how these are used to continue a for/next loop if an 
 error occurs within the loop.
 
 Can somebody point me to material (or share some code) with more 
 extensive examples than the ones in the help/FAQ pages?
 
 Do explain my problem in more detail:
 
 for (i in 100:1000)
 {
   ## do some other stuff
 
  dataset-head(data,i)
  tryCatch(estimatemodel(dataset))

if estimatemodel returns an error (i.e. via a call to stop()), then this 
should break out of the loop:

tryCatch(estimatemodel(dataset), error = function() break)

if you want to skip to the next iteration, use:
tryCatch(estimatemodel(dataset), error = function() next)

 
 }
 
 My for/next loop reads in data (increasing the dataset by one point at 
 every loop run) and then estimates a model. When the problem is 
 computationally singular, the loop exits. I want to continue the loop 
 and register an error estimation value for that step. However when I 
 use use the try tryCatch(estimatemodel(data)) (where estimatemodel() is 
 a wrapper function calling the model estimation and optimization 
 routines), the problem still persists.
 
 Is this the correct way to use tryCatch (or try) or should these go 
 inside the actual code bits (i.e., in a more low level fashion) that 
 conduct the optimization and model estimation?
 
 Apologies if this is not clear enough.
 
 Best,
 Costas
 
 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/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] tryCatch - Continuing for/next loop after error

2011-03-10 Thread Jonathan P Daily
Wow, I had a major brain fart there. The function after error was supposed 
to accept an argument, and next won't do anything there because inside the 
function there is no loop. Also, the first argument of tryCatch is an 
expression, so do the assignment there. Corrections inline below:
--
Jonathan P. Daily
Technician - USGS Leetown Science Center
11649 Leetown Road
Kearneysville WV, 25430
(304) 724-4480
Is the room still a room when its empty? Does the room,
 the thing itself have purpose? Or do we, what's the word... imbue it.
 - Jubal Early, Firefly

Nipesh Bajaj bajaj141...@gmail.com wrote on 03/10/2011 10:21:38 AM:

 [image removed] 
 
 Re: [R] tryCatch - Continuing for/next loop after error
 
 Nipesh Bajaj 
 
 to:
 
 Jonathan P Daily
 
 03/10/2011 10:21 AM
 
 Cc:
 
 r-help
 
 Hi Jonathan, I was also trying to understand this tryCatch function on
 my own problem. Here is mine:
 
 fn1 - function(x) {
   if(as.integer(x) == 5) {
 stop(stop) 
  }
   return(x+5)
}
 res - matrix(NA, 5, 7)
 for(i in 1:5) {
   for(j in 1:7) {
 res[i,j] - tryCatch(fn1(j), error = function() next)
  }
}

for(i in 1:5) { for(j in 1:7) {
tryCatch(res[i,j] - fn1(j), error = function(x) x)
} }

 
 I was expecting while completion of these loops, the 5th column of
 'res' will have NA values. However I got some error:
 
 Error in value[[3L]](cond) : unused argument(s) (cond)
 
 What is the actual problem here?
 
 Thanks,
 
 
 On Thu, Mar 10, 2011 at 7:19 PM, Jonathan P Daily jda...@usgs.gov 
wrote:
  --
  Jonathan P. Daily
  Technician - USGS Leetown Science Center
  11649 Leetown Road
  Kearneysville WV, 25430
  (304) 724-4480
  Is the room still a room when its empty? Does the room,
   the thing itself have purpose? Or do we, what's the word... imbue 
it.
  - Jubal Early, Firefly
 
  r-help-boun...@r-project.org wrote on 03/10/2011 03:51:15 AM:
 
  [image removed]
 
  [R] tryCatch - Continuing for/next loop after error
 
  Costas
 
  to:
 
  r-help
 
  03/10/2011 03:53 AM
 
  Sent by:
 
  r-help-boun...@r-project.org
 
  Please respond to costas.vorlow
 
  Dear all,
 
  I am not sure I understand fully the functionality of tryCatch and
  try commands and how these are used to continue a for/next loop if 
an
  error occurs within the loop.
 
  Can somebody point me to material (or share some code) with more
  extensive examples than the ones in the help/FAQ pages?
 
  Do explain my problem in more detail:
 
  for (i in 100:1000)
  {
## do some other stuff
 
   dataset-head(data,i)
   tryCatch(estimatemodel(dataset))
 
  if estimatemodel returns an error (i.e. via a call to stop()), then 
this
  should break out of the loop:
 
  tryCatch(estimatemodel(dataset), error = function() break)
 
  if you want to skip to the next iteration, use:
  tryCatch(estimatemodel(dataset), error = function() next)
 
 
  }
 
  My for/next loop reads in data (increasing the dataset by one point 
at
  every loop run) and then estimates a model. When the problem is
  computationally singular, the loop exits. I want to continue the loop
  and register an error estimation value for that step. However when 
I
  use use the try tryCatch(estimatemodel(data)) (where estimatemodel() 
is
  a wrapper function calling the model estimation and optimization
  routines), the problem still persists.
 
  Is this the correct way to use tryCatch (or try) or should these go
  inside the actual code bits (i.e., in a more low level fashion) that
  conduct the optimization and model estimation?
 
  Apologies if this is not clear enough.
 
  Best,
  Costas
 
  __
  R-help@r-project.org mailing list
  https://stat.ethz.ch/mailman/listinfo/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] tryCatch - Continuing for/next loop after error

2011-03-10 Thread Jonathan P Daily
I did not know that. When reading the help topic for the first time 
myself, I think I assumed that it returned no value since it had no Value 
section, and I haven't used it in a way that it would return a value.
--
Jonathan P. Daily
Technician - USGS Leetown Science Center
11649 Leetown Road
Kearneysville WV, 25430
(304) 724-4480
Is the room still a room when its empty? Does the room,
 the thing itself have purpose? Or do we, what's the word... imbue it.
 - Jubal Early, Firefly

William Dunlap wdun...@tibco.com wrote on 03/10/2011 11:29:59 AM:

 [image removed] 
 
 RE: [R] tryCatch - Continuing for/next loop after error
 
 William Dunlap 
 
 to:
 
 Jonathan P Daily, Nipesh Bajaj
 
 03/10/2011 11:30 AM
 
 Cc:
 
 r-help
 
  -Original Message-
  From: r-help-boun...@r-project.org 
  [mailto:r-help-boun...@r-project.org] On Behalf Of Jonathan P Daily
  Sent: Thursday, March 10, 2011 7:49 AM
  To: Nipesh Bajaj
  Cc: r-help@r-project.org
  Subject: Re: [R] tryCatch - Continuing for/next loop after error
  
  Wow, I had a major brain fart there. The function after error 
  was supposed 
  to accept an argument, and next won't do anything there 
  because inside the 
  function there is no loop. Also, the first argument of tryCatch is an 
  expression, so do the assignment there. Corrections inline below:
 
 The stuff about the error handle requiring an argument and
 not being able to call next() from outside of a loop is true,
 but you do not need to do the assignment inside the main expression
 of tryCatch().  I find it clearer if you do the assignment outside
 of tryCatch() so the main expression can return one thing and the
 error handler can return something else.  You can use this in an
 *apply() function or a for loop, while the assignment-in-tryCatch()
 won't work in a *apply() call.  E.g., suppose we have a function
 that only works on positive odd integers:
   o - function (x) {
   stopifnot(x%%2 == 1, x0)
   (x - 1)/2
   }
 Then you can use tryCatch to flag the bad inputs with a code
 that tells you about the bad input:
sapply(1:5, function(i)tryCatch(o(i), error=function(e)-1000-i))
   [1] 0 -1002 1 -1004 2
 or with a for loop where you don't have to prefill the output
 vector with any particular values:
value - numeric(5)
for(i in 1:5) value[i] - tryCatch(o(i), error=function(e)-1000-i)
value
   [1] 0 -1002 1 -1004 2
 
 To do that with with an assignment in the main expression of tryCatch
 would require something like
value - -1000 -(1:5)
for(i in 1:5) tryCatch(value[i] - o(i), error=function(e)NULL)
value
   [1] 0 -1002 1 -1004 2
 which seems to me uglier and harder to follow since value's entries
 are filled in different parts of the code.
 
 Bill Dunlap
 Spotfire, TIBCO Software
 wdunlap tibco.com 
  --
  Jonathan P. Daily
  Technician - USGS Leetown Science Center
  11649 Leetown Road
  Kearneysville WV, 25430
  (304) 724-4480
  Is the room still a room when its empty? Does the room,
   the thing itself have purpose? Or do we, what's the word... 
  imbue it.
   - Jubal Early, Firefly
  
  Nipesh Bajaj bajaj141...@gmail.com wrote on 03/10/2011 10:21:38 AM:
  
   [image removed] 
   
   Re: [R] tryCatch - Continuing for/next loop after error
   
   Nipesh Bajaj 
   
   to:
   
   Jonathan P Daily
   
   03/10/2011 10:21 AM
   
   Cc:
   
   r-help
   
   Hi Jonathan, I was also trying to understand this tryCatch 
  function on
   my own problem. Here is mine:
   
   fn1 - function(x) {
 if(as.integer(x) == 5) {
   stop(stop) 
}
 return(x+5)
  }
   res - matrix(NA, 5, 7)
   for(i in 1:5) {
 for(j in 1:7) {
   res[i,j] - tryCatch(fn1(j), error = function() next)
}
  }
  
  for(i in 1:5) { for(j in 1:7) {
  tryCatch(res[i,j] - fn1(j), error = function(x) x)
  } }
  
   
   I was expecting while completion of these loops, the 5th column of
   'res' will have NA values. However I got some error:
   
   Error in value[[3L]](cond) : unused argument(s) (cond)
   
   What is the actual problem here?
   
   Thanks,
   
   
   On Thu, Mar 10, 2011 at 7:19 PM, Jonathan P Daily jda...@usgs.gov 
  wrote:
--
Jonathan P. Daily
Technician - USGS Leetown Science Center
11649 Leetown Road
Kearneysville WV, 25430
(304) 724-4480
Is the room still a room when its empty? Does the room,
 the thing itself have purpose? Or do we, what's the 
  word... imbue 
  it.
- Jubal Early, Firefly
   
r-help-boun...@r-project.org wrote on 03/10/2011 03:51:15 AM:
   
[image removed]
   
[R] tryCatch - Continuing for/next loop after error
   
Costas
   
to:
   
r-help
   
03/10/2011 03:53 AM
   
Sent by:
   
r-help-boun...@r-project.org
   
Please respond to costas.vorlow

Re: [R] sum of variables in function

2011-03-10 Thread Jonathan P Daily
How about:


x - rnorm(1000)
fn - function(k) sum(x[1:k]*(x[k+1] + x[k+2]))
vals - sapply(1:100, fn)
vals

--
Jonathan P. Daily
Technician - USGS Leetown Science Center
11649 Leetown Road
Kearneysville WV, 25430
(304) 724-4480
Is the room still a room when its empty? Does the room,
 the thing itself have purpose? Or do we, what's the word... imbue it.
 - Jubal Early, Firefly

r-help-boun...@r-project.org wrote on 03/10/2011 08:49:25 AM:

 [image removed] 
 
 [R] sum of variables in function
 
 beatleb 
 
 to:
 
 r-help
 
 03/10/2011 01:15 PM
 
 Sent by:
 
 r-help-boun...@r-project.org
 
 Dear R users,
 
 Probably, this is quite a simpe question, but I do not find the proper 
way
 to obtain want I need. To explain the problem, I constructed a simple
 example. 
 
 Suppose I have the following function:
 
 try1-function(x){
 y-x[1:2]
 z-x[3:4]
 y[1]*(z[1]+z[2])+y[2]*(z[1]+z[2])
 }
 
 This function will be part of a for loop. This is what I like to obtain 
for
 every k:
 
 if k=2
 try1-function(x){
 y-x[1:2]
 z-x[3:4]
 y[1]*(z[1]+z[2])+y[2]*(z[1]+z[2])
 }
 
 if k=3
 try1-function(x){
 y-x[1:3]
 z-x[4:5]
 y[1]*(z[1]+z[2])+y[2]*(z[1]+z[2])+y[3]*(z[1]+z[2])
 }
 
 if k=4
 try1-function(x){
 y-x[1:3]
 z-x[4:5]
 y[1]*(z[1]+z[2])+y[2]*(z[1]+z[2])+y[3]*(z[1]+z[2])+y[4]*(z[1]+z[2]) 
 }
 
 Assume that k will be quite high, for example 100. 
 The problem isn't in defining a for loop, or in defining the appropriate 
y
 or z, but in the line starting with 
 y[1]. The values of the variables are still unknown, which causes that I 
am
 not able to create this sum.
 
 I really hope that there is somebody in the audience that can help me.
 
 
 
 --
 View this message in context: http://r.789695.n4.nabble.com/sum-of-
 variables-in-function-tp3345888p3345888.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] Complex sampling?

2011-03-09 Thread Jonathan P Daily
--
Jonathan P. Daily
Technician - USGS Leetown Science Center
11649 Leetown Road
Kearneysville WV, 25430
(304) 724-4480
Is the room still a room when its empty? Does the room,
 the thing itself have purpose? Or do we, what's the word... imbue it.
 - Jubal Early, Firefly

r-help-boun...@r-project.org wrote on 03/09/2011 01:01:32 PM:

 [image removed] 
 
 [R] Complex sampling?
 
 Hosack, Michael 
 
 to:
 
 r-help@R-project.org
 
 03/09/2011 01:04 PM
 
 Sent by:
 
 r-help-boun...@r-project.org
 
  -Original Message-
  From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-
 project.org]
  On Behalf Of Hosack, Michael
  Sent: Wednesday, March 09, 2011 7:34 AM
  To: r-help at R-project.org
  Subject: [R] Complex sampling?
  
  R users,
  
  I am trying to generate a randomized weekday survey schedule that 
ensures
  even coverage of weekdays in
  the sample, where the distribution of variable DOW is random with 
respect
  to WEEK. To accomplish this I need
  to randomly sample without replacement two weekdays per week for each 
of
  27 weeks (only 5 are shown). 
 
 This seems simple enough, sampling without replacement.
 
 However,
  I need to sample from a sequence (3:7) that needs to be completely
  depleted and replenished until the
  final selection is made. Here is an example of what I want to do,
  beginning at WEEK 1. I would prefer to do
  this without using a loop, if possible.
  
  sample frame: [3,4,5,6,7] -- [4,5,6] -- [4],[1,2,3,(4),5,6] --
  [1,2,4,5,6] -- for each WEEK in dataframe
 
 OK, now you have me completely lost.  Sorry, but I have no clue as 
 to what you just did here.  I looks like you are trying to describe 
 some transformation/algorithm but I don't follow it.
 
 
 
 I could not reply to this email because it not been delivered to my 
 inbox, so I had to copy it from the forum. 
 I apologize for the confusion, this would take less than a minute to
 explain in conversation but an hour 
 to explain well in print. Two DOW_NUMs will be selected randomly 
 without replacement from the vector 3:7 for each WEEK. When this 
 vector is reduced to a single integer that integer will be selected

This is what doesn't make sense to me. You sample two values from 3:7 
without replacement. Then this sample of two is turned into one by a 
mechanism you have not specified. Are these averaged? Lets assume you 
assign this mechanism to fun(x1) where x1 is the sample.
 
 and the vector will be restored and a single integer will then be 
 selected that differs from the prior selected integer (i.e. cannot 
 sample the same day twice in the same week).

so then you want to sample twice from 3:7 again such that fun(x2) != 
fun(x1)?

If so, then this might be what you need.

vals - matrix(,5,2)

pairs - expand.grid(3:7, 3:7)

for(i in 1:5)
{
vals[i,1] - fun(sample(pairs))
vals[i,2] - fun(sample(pairs[fun(pairs) != vals[i,1])))
}

Or something similar.

This process will be 
 repeated until two DOW_NUM have been assigned for each WEEK. That 
 process is what I attempted to illustrate in my original message. 
 This is beyond my current coding capabilities. 
 
 
 
  
  Randomly sample 2 DOW_NUM without replacement from each WEEK ( () = no 
two
  identical DOW_NUM can be sampled
  in the same WEEK)
  
  sample = {3,7}, {5,6}, {4,3}, {1,5}, -- for each WEEK in dataframe
  
 
 So, are you sampling from [3,4,5,6,7], or [1,2,4,5,6], or ...?  Can 
 you show an 'example' of what you would like to end up given your data 
below?
 
  
  Thanks you,
  
  Mike
  
  
   DATE DOW DOW_NUM WEEK
  2  2011-05-02 Mon   31
  3  2011-05-03 Tue   41
  4  2011-05-04 Wed   51
  5  2011-05-05 Thu   61
  6  2011-05-06 Fri   71
  9  2011-05-09 Mon   32
  10 2011-05-10 Tue   42
  11 2011-05-11 Wed   52
  12 2011-05-12 Thu   62
  13 2011-05-13 Fri   72
  16 2011-05-16 Mon   33
  17 2011-05-17 Tue   43
  18 2011-05-18 Wed   53
  19 2011-05-19 Thu   63
  20 2011-05-20 Fri   73
  23 2011-05-23 Mon   34
  24 2011-05-24 Tue   44
  25 2011-05-25 Wed   54
  26 2011-05-26 Thu   64
  27 2011-05-27 Fri   74
  30 2011-05-30 Mon   35
  31 2011-05-31 Tue   45
  32 2011-06-01 Wed   55
  33 2011-06-02 Thu   65
  34 2011-06-03 Fri   75
  
  DF -
  structure(list(DATE = structure(c(15096, 15097, 15098, 15099,
  15100, 15103, 15104, 15105, 15106, 15107, 15110, 15111, 15112,
  15113, 15114, 15117, 15118, 15119, 15120, 15121, 15124, 15125,
  15126, 15127, 15128), class = Date), DOW = c(Mon, Tue,
  Wed, Thu, Fri, Mon, Tue, Wed, Thu, Fri, Mon,
  Tue, Wed, Thu, Fri, Mon, Tue, Wed, Thu, Fri,
  Mon, Tue, Wed, Thu, Fri), DOW_NUM = c(3, 4, 5, 6, 7,
  3, 4, 5, 6, 7, 3, 4, 5, 6, 7, 3, 4, 5, 6, 7, 3, 4, 5, 6, 7),
  WEEK = c(1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 4,
  4, 4, 4

Re: [R] generate 3 distinct random samples without replacement

2011-03-07 Thread Jonathan P Daily
would this work?

s - sample(d1, 300, F)
D - data.frame(a = s[1:100], b = s[101:200], c = s[201:300])
--
Jonathan P. Daily
Technician - USGS Leetown Science Center
11649 Leetown Road
Kearneysville WV, 25430
(304) 724-4480
Is the room still a room when its empty? Does the room,
 the thing itself have purpose? Or do we, what's the word... imbue it.
 - Jubal Early, Firefly

r-help-boun...@r-project.org wrote on 03/07/2011 02:17:19 PM:

 [image removed] 
 
 [R] generate 3 distinct random samples without replacement
 
 Cesar Hincapié 
 
 to:
 
 r-help
 
 03/07/2011 03:06 PM
 
 Sent by:
 
 r-help-boun...@r-project.org
 
 Hello:
 
 I wonder if I could get a little help with random sampling in R.
 
 I have a vector of length 7375.  I would like to draw 3 distinct 
 random samples, each of length 100 without replacement.  I have 
 tried the following:
 
 d1 - 1:7375
 
 set.seed(7)
 i - sample(d1, 100, replace=F)
 s1 - sort(d1[i])
 s1
 
 d2 - d1[-i]
 set.seed(77)
 j - sample(d2, 100, replace=F)
 s2 - sort(d2[j])
 s2
 
 d3 - d2[-j]
 set.seed(777)
 k - sample(d3, 100, replace=F)
 s3 - sort(d3[k])
 s3
 
 D - data.frame(a=s1,b=s2,c=s3)
 
 
 However, s2 is only 97 elements long, and s3, only 96 long.
 
 I would appreciate any suggestions on a better approach.
 I'm also curious to know why my second and third samples are less 
 than 100 elements in length.
 
 Thanks for your time and consideration,
 
 Cesar A. Hincapié, DC, MHSc
 
 Research Fellow, Division of Health Care and Outcomes Research, 
 Toronto Western Research Institute
 PhD Candidate in Epidemiology, Dalla Lana School of Public Health, 
 University of Toronto
 e. cesar.hinca...@utoronto.ca
 
 
 
 
 
[[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] Probabilities greather than 1 in HIST

2011-03-03 Thread Jonathan P Daily
If you read ?hist, you will answer your own question.

The issue in your code is the parameter prob = T, which does nothing. By 
default, hist reports density.
--
Jonathan P. Daily
Technician - USGS Leetown Science Center
11649 Leetown Road
Kearneysville WV, 25430
(304) 724-4480
Is the room still a room when its empty? Does the room,
 the thing itself have purpose? Or do we, what's the word... imbue it.
 - Jubal Early, Firefly

r-help-boun...@r-project.org wrote on 03/03/2011 09:03:21 AM:

 [image removed] 
 
 [R] Probabilities greather than 1 in HIST
 
 jpmaroco 
 
 to:
 
 r-help
 
 03/03/2011 10:13 AM
 
 Sent by:
 
 r-help-boun...@r-project.org
 
 Dear all,
 I am a newbie in R and could not find help on this problem. I am trying 
to
 plot an histogram with probabilities in the y axis. This is the code I 
am
 using:
 
 #TLC uniform
 n=30
 mi=1; mx=6
 nrep=1000
 xbar=rep(0,nrep)
 for (i in 1:nrep) {xbar[i]=mean(runif(n,min=mi,max=mx))}
 hist(xbar,prob=TRUE,breaks=Sturges,xlim=c(1,6),main=paste(n =,n),
 xlab=Média, ylab=Probabilidade)
 curve(dnorm(x,mean=mean(xbar),sd=sd(xbar)),add=TRUE,lwd=2,col=red)
 
 The problem is that I am getting greater than 1 probabilities in the Y 
axis?
 Is there a way to correct this?
 Many thanks in advance.
 Joao
 
 --
 View this message in context: http://r.789695.n4.nabble.com/
 Probabilities-greather-than-1-in-HIST-tp388p388.html
 Sent from the R help mailing list archive at Nabble.com.
[[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] Vector manipulations

2011-03-02 Thread Jonathan P Daily
Is this what you want? I don't know what your v looks like, but this won't 
work if there are cases in which v won't sum to exactly x.

x - 20
v - sample(0:1, 100, T)

w - v[1:which(cumsum(v)==x)]
--
Jonathan P. Daily
Technician - USGS Leetown Science Center
11649 Leetown Road
Kearneysville WV, 25430
(304) 724-4480
Is the room still a room when its empty? Does the room,
 the thing itself have purpose? Or do we, what's the word... imbue it.
 - Jubal Early, Firefly

r-help-boun...@r-project.org wrote on 03/02/2011 10:42:12 AM:

 [image removed] 
 
 [R] Vector manipulations
 
 Benjamin Hartley 
 
 to:
 
 r-help
 
 03/02/2011 11:08 AM
 
 Sent by:
 
 r-help-boun...@r-project.org
 
 I have a question regarding the most efficient way to select a substring 
of
 a vector:
 
 I have a vector of value v, and I want to select a subspace of this 
vector
 called w such that:
 
 w=v[1:n]
 
 where
 
 sum(w) = x
 
 I am interested in what you thing would be the most efficient way to do 
this
 - I would like to avoid slowing down my simulations as much as possible.
 
 Thank you very much for any help that anyone is able to give.
 
[[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] bootstrap resampling - simplified

2011-03-02 Thread Jonathan P Daily
I will point out again that sampling a five-fold replicate of 1:20 is not 
the same as resampling with replacement, although I made an error in 
reporting probabilities - the P(x2 = 1 | x1 = 1) = 4/99 and not 4/100. 
When sampling with replacement, P(x2 = 1 | x1 = 1) = P(x2 = 1 | x1 != 1) = 
1/20.
--
Jonathan P. Daily
Technician - USGS Leetown Science Center
11649 Leetown Road
Kearneysville WV, 25430
(304) 724-4480
Is the room still a room when its empty? Does the room,
 the thing itself have purpose? Or do we, what's the word... imbue it.
 - Jubal Early, Firefly

r-help-boun...@r-project.org wrote on 03/02/2011 01:05:01 PM:

 [image removed] 
 
 Re: [R] bootstrap resampling - simplified
 
 Vokey, John 
 
 to:
 
 r-help
 
 03/02/2011 01:07 PM
 
 Sent by:
 
 r-help-boun...@r-project.org
 
 On 2011-03-02, at 4:00 AM, r-help-requ...@r-project.org wrote:
 
  Hello there,
  
  I have a problem concerning bootstrapping in R - especially 
 focusing on the resampling part of it. I try to sum it up in a 
 simplified way so that I would not confuse anybody.
  
  I have a small database consisting of 20 observations (basically 
 numbers from 1 to 20, I mean: 1, 2, 3, 4, 5, ... 18, 19, 20).
  
  I would like to resample this database many times for the 
 bootstrap process with the following conditions. Firstly, every 
 resampled database should also include 20 observations. Secondly, 
 when selecting a number from the above-mentioned 20 numbers, you can
 do this selection with replacement. The difficult part comes now: 
 one number can be selected only maximum 5 times. In order to make 
 this clear I show you a couple of examples. So the resampled 
 databases might be like the following ones:
  
  (1st database)  1,2,1,2,1,2,1,2,1,2,3,3,3,3,3,4,4,4,4,4
  4 different numbers are chosen (1, 2, 3, 4), each selected - for 
 the maximum possible - 5 times.
  
  (2nd database)  1,8,8,6,8,8,8,2,3,4,5,6,6,6,6,7,19,1,1,1
  Two numbers - 8 and 6 - selected 5 times (the maximum possible 
 times), number 1 selected 4 times, the others selected less than 4 
times.
  
  (3rd database)  1,1,2,2,3,3,4,4,9,9,9,10,10,13,10,9,3,9,2,1
  Number 9 chosen for the maximum possible 5 times, number 10, 3, 2,
 1 chosen for 3 times, number 4 selected twice and number 13 selectedonly 
once.
  
  ...
  
  Anybody knows how to implement my tricky condition into one of 
 the R functions - that one number can be selected only 5 times at 
 most? Are 'boot' and 'bootstrap' packages capable of managing this? 
 I guess they are, I just couldn't figure it out yet...
  
  Thanks very much! Best regards,
  Laszlo Bodnar
 
 Laszlo,
   Create a vector consisting of 5 of each number.  Then, for each 
 sample, scramble the order of the items in the vector, and select 
 the first 20.
 
 
 --
 Please avoid sending me Word or PowerPoint attachments.
 See http://www.gnu.org/philosophy/no-word-attachments.html
 
 -Dr. John R. Vokey
 
 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/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] bootstrap resampling - simplified

2011-03-02 Thread Jonathan P Daily
I apologize if I was not clear in my response. I only mentioned x1, x2 in 
my example, but I did not clarify that I also knew that P(x6 = 1 | x1..5 = 
1) = 0 in the original request. I also see that if he meant that he wanted 
to sample with replacement from the set of sequences that sample(rep(1:20, 
5), 20) is fine for generating said sequences. My interpretation was that 
the sequences themselves should be sampling with replacement until 
frequency hits 5, whereupon it is not replaced. Hence my suggestion of:

bigsamp - sample(1:20, 100, T)
idx - sort(unlist(sapply(1:20, function(x) which(bigsamp == 
x)[1:5])))[1:20]
samp - bigsamp[idx]

I apologize for my lack of clarity, though after reading the original post 
I'm not sure which solution the OP was looking for.

Cheers,
Jon
--
Jonathan P. Daily
Technician - USGS Leetown Science Center
11649 Leetown Road
Kearneysville WV, 25430
(304) 724-4480
Is the room still a room when its empty? Does the room,
 the thing itself have purpose? Or do we, what's the word... imbue it.
 - Jubal Early, Firefly

Bert Gunter gunter.ber...@gene.com wrote on 03/02/2011 02:42:40 PM:

 [image removed] 
 
 Re: [R] bootstrap resampling - simplified
 
 Bert Gunter 
 
 to:
 
 Jonathan P Daily
 
 03/02/2011 02:42 PM
 
 Cc:
 
 Vokey, John, r-help, r-help-bounces
 
 Folks:
 
 On Wed, Mar 2, 2011 at 10:32 AM, Jonathan P Daily jda...@usgs.gov 
wrote:
  I will point out again that sampling a five-fold replicate of 1:20 is 
not
  the same as resampling with replacement,
 
 -- Correct. In sampling with replacement from 1:20 there is positive
 probability of getting all 1's or all 2's, etc. The poster
 specifically said that he wanted 0 probability of such results. So,
 obviously, the poster does NOT want to sample with replacement from
 1:20. What he does want (I think) is a re-sample of size n from the
 set of all **vectors** of length 20, each element of which is an
 integer from 1 to 20, and for which no individual values occur more
 than 5 times in the vector. Of course I'm just
 interpreting/paraphrasing the original post (if I got it right), but I
 think doing so makes the nature of the task clearer: one needs to find
 some way to sample with replacement from the space of all such
 **sequences**.
 
 I think it is now clear that one may do so by rejection sampling: i.e.
 sample with replacement from 1:20 and throw away any sequences that
 fail the at most 5 criterion. The sequences that remain are samples of
 size 1 from the population of sequences that satisfy the poster's
 criteria (in theory, anyway; this might tax a pseudo RNG in practice).
 A collection of n such sequences is a bootstrap sample from this
 population. I **think** that's what the poster wants -- and what
 others have already provided. However, maybe this clarifies why it
 works.
 
 If I have made any error in this, **Please** post a message pointing
 out my error. I sometimes get confused about this stuff, too.
 
 Cheers,
 Bert
 
 
 
 
 
  although I made an error in
  reporting probabilities - the P(x2 = 1 | x1 = 1) = 4/99 and not 4/100.
  When sampling with replacement, P(x2 = 1 | x1 = 1) = P(x2 = 1 | x1 != 
1) =
  1/20.
  --
  Jonathan P. Daily
  Technician - USGS Leetown Science Center
  11649 Leetown Road
  Kearneysville WV, 25430
  (304) 724-4480
  Is the room still a room when its empty? Does the room,
   the thing itself have purpose? Or do we, what's the word... imbue 
it.
  - Jubal Early, Firefly
 
  r-help-boun...@r-project.org wrote on 03/02/2011 01:05:01 PM:
 
  [image removed]
 
  Re: [R] bootstrap resampling - simplified
 
  Vokey, John
 
  to:
 
  r-help
 
  03/02/2011 01:07 PM
 
  Sent by:
 
  r-help-boun...@r-project.org
 
  On 2011-03-02, at 4:00 AM, r-help-requ...@r-project.org wrote:
 
   Hello there,
  
   I have a problem concerning bootstrapping in R - especially
  focusing on the resampling part of it. I try to sum it up in a
  simplified way so that I would not confuse anybody.
  
   I have a small database consisting of 20 observations (basically
  numbers from 1 to 20, I mean: 1, 2, 3, 4, 5, ... 18, 19, 20).
  
   I would like to resample this database many times for the
  bootstrap process with the following conditions. Firstly, every
  resampled database should also include 20 observations. Secondly,
  when selecting a number from the above-mentioned 20 numbers, you can
  do this selection with replacement. The difficult part comes now:
  one number can be selected only maximum 5 times. In order to make
  this clear I show you a couple of examples. So the resampled
  databases might be like the following ones:
  
   (1st database)  1,2,1,2,1,2,1,2,1,2,3,3,3,3,3,4,4,4,4,4
   4 different numbers are chosen (1, 2, 3, 4), each selected - for
  the maximum possible - 5 times.
  
   (2nd database)  1,8,8,6,8,8,8,2,3,4,5,6,6,6,6,7,19,1,1,1
   Two numbers - 8 and 6 - selected 5 times (the maximum

Re: [R] bootstrap resampling question

2011-03-01 Thread Jonathan P Daily
I'm not sure that is equivalent to sampling with replacement, since if the 
first draw is 1, then the probability that the next draw will be one is 
4/100 instead of the 1/20 it would be in sampling with replacement. I 
think the way to do this would be what Greg suggested - something like:

bigsamp - sample(1:20, 100, T)
idx - sort(unlist(sapply(1:20, function(x) which(bigsamp == 
x)[1:5])))[1:20]
samp - bigsamp[idx]

--
Jonathan P. Daily
Technician - USGS Leetown Science Center
11649 Leetown Road
Kearneysville WV, 25430
(304) 724-4480
Is the room still a room when its empty? Does the room,
 the thing itself have purpose? Or do we, what's the word... imbue it.
 - Jubal Early, Firefly

r-help-boun...@r-project.org wrote on 03/01/2011 09:37:31 AM:

 [image removed] 
 
 Re: [R] bootstrap resampling question
 
 Giovanni Petris 
 
 to:
 
 Bodnar Laszlo EB_HU
 
 03/01/2011 11:58 AM
 
 Sent by:
 
 r-help-boun...@r-project.org
 
 Cc:
 
 'r-help@r-project.org'
 
 A simple way of sampling with replacement from 1:20, with the additional
 constraint that each number can be selected at most five times is
 
  sample(rep(1:20, 5), 20)
 
 HTH,
 Giovanni
 
 On Tue, 2011-03-01 at 11:30 +0100, Bodnar Laszlo EB_HU wrote:
  Hello there,
  
  I have a problem concerning bootstrapping in R - especially 
 focusing on the resampling part of it. I try to sum it up in a 
 simplified way so that I would not confuse anybody.
  
  I have a small database consisting of 20 observations (basically 
 numbers from 1 to 20, I mean: 1, 2, 3, 4, 5, ... 18, 19, 20).
  
  I would like to resample this database many times for the 
 bootstrap process with the following two conditions. The resampled 
 databases should also have 20 observations and you can select each 
 of the previously mentioned 20 numbers with replacement. I guess it 
 is obvious so far. Now the more difficult second condition is that 
 one number can be selected only maximum 5 times. In order to make 
 this clear I try to show you an example. So there can be resampled 
 databases like the following ones:
  
  (1st database)  1,2,1,2,1,2,1,2,1,2,3,3,3,3,3,4,4,4,4,4
  (4 different numbers are chosen, each selected 5 times)
  
  (2nd database)  1,8,8,6,8,8,8,2,3,4,5,6,6,6,6,7,19,1,1,1
  (Two numbers - 8 and 6 - selected 5 times, number 1 selected 
 four times, the others selected less than 4 times)
  
  My very first guess that came to my mind whilst thinking about the
 problem was the sample function where there are settings like 
 replace=TRUE and prob=... where you can create a probability vector 
 i.e. how much should be the probability of selecting a number. So I 
 tried to calculate probabilities first. I thought the problem can 
 basically described as a k-combination with repetitions. 
 Unfortunately the only thing I could calculate so far is the total 
 number of all possible selections which amounts to 137 846 527 049.
  
  Anybody knows how to implement my second tricky condition into 
 one of the R functions? Are 'boot' and 'bootstrap' packages capable 
 of managing this? I guess they are, I just couldn't figure it out yet...
  
  Thanks very much! Best regards,
  Laszlo Bodnar
  
  
 

  Ez az e-mail és az összes hozzá tartozó csatolt melléklet titkos 
 és/vagy jogilag, szakmailag vagy más módon védett információt
 tartalmazhat. Amennyiben nem Ön a levél címzettje akkor a levél 
 tartalmának közlése, reprodukálása, másolása, vagy egyéb más úton 
 történő terjesztése, felhasználása szigorúan tilos. Amennyiben 
 tévedésből kapta meg ezt az üzenetet kérjük azonnal értesítse az 
 üzenet küldőjét. Az Erste Bank Hungary Zrt. (EBH) nem vállal 
 felelősséget az információ teljes és pontos - címzett(ek)hez történő
 - eljuttatásáért, valamint semmilyen késésért, kapcsolat 
 megszakadásból eredő hibáért, vagy az információ felhasználásából 
 vagy annak megbízhatatlanságából eredő kárért.
  
  Az üzenetek EBH-n kívüli küldője vagy címzettje tudomásul veszi és
 hozzájárul, hogy az üzenetekhez más banki alkalmazott is hozzáférhet
 az EBH folytonos munkamenetének biztosítása érdekében.
  
  
  This e-mail and any attached files are confidential 
and/...{{dropped:19}}
  
  __
  R-help@r-project.org mailing list
  https://stat.ethz.ch/mailman/listinfo/r-help
  PLEASE do read the posting guide 
http://www.R-project.org/posting-guide.html
  and provide commented, minimal, self-contained, reproducible code.
 
 -- 
 
 Giovanni Petris  gpet...@uark.edu
 Associate Professor
 Department of Mathematical Sciences
 University of Arkansas - Fayetteville, AR 72701
 Ph: (479) 575-6324, 575-8630 (fax)
 http://definetti.uark.edu/~gpetris/
 
 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide

Re: [R] Variable names AS variable names?

2011-02-25 Thread Jonathan P Daily
To access a variable by a character string name, try

for(code in codes)
{
dat - get(code)
[stuff]
}

Other options include ?assign if you need to manipulate the original, or 
?with to use the subject of codes as an environment.
--
Jonathan P. Daily
Technician - USGS Leetown Science Center
11649 Leetown Road
Kearneysville WV, 25430
(304) 724-4480
Is the room still a room when its empty? Does the room,
 the thing itself have purpose? Or do we, what's the word... imbue it.
 - Jubal Early, Firefly

r-help-boun...@r-project.org wrote on 02/25/2011 12:33:32 PM:

 [image removed] 
 
 Re: [R] Variable names AS variable names?
 
 Noah Silverman 
 
 to:
 
 02/25/2011 12:35 PM
 
 Sent by:
 
 r-help-boun...@r-project.org
 
 Cc:
 
 r-help
 
 My actual code is several things with adaptive filtering.  This will
 require accessing data sporadically.  The loop was just a quick example
 for the e-mail.
 
 One application is to work with online (streaming) data.  If I get a new
 data point in for code a1, I'll need to be able to reference the
 matrix named a1. 
 
 On 2/25/11 12:23 AM, David Winsemius wrote:
 
  On Feb 25, 2011, at 1:55 AM, Noah Silverman wrote:
 
  How can I dynamically use a variable as the name for another 
variable?
 
  I realize this sounds cryptic, so an example is best:
 
  #Start with an array of codes
  codes - c(a1, b24, q99)
 
  Is there some reason not to use list(a1, b24, q99)? If not then:
 
  lapply(codes, somefun)
 
 
 
  #Each code has a corresponding matrix (could be vector)
  a1 - matrix(rnorm(100), nrow=10)
  b24 - matrix(rnorm(100), nrow=10)
  q99 - matrix(rnorm(100), nrow=10)
 
  #Now, I want to loop through all the codes and do something with each
  matrix
  for(code in codes){
 #here is where I'm stuck.  I don't want the value of code, but the
  variable who's name is the value of code
 
  }
 
 
  Any suggestions?
 
  -N
 
  __
  R-help@r-project.org mailing list
  https://stat.ethz.ch/mailman/listinfo/r-help
  PLEASE do read the posting guide
  http://www.R-project.org/posting-guide.html
  and provide commented, minimal, self-contained, reproducible code.
 
  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 provide commented, minimal, self-contained, reproducible code.


Re: [R] Running code sequentially from separate scripts (but not functions)

2011-02-24 Thread Jonathan P Daily
If you are just wanting to run them once, you can just do:

source(code1.r)
source(code2.r)
source(code3.r)

or place the file names in a vector, say 'filenames' and:

sapply(filenames, source)

If you want to use them multiple times, try:

run1 - parse(code1.r)
run2 - parse(code2.r)
run3 - parse(code3.r)

# Use this to run anytime
eval(run1)
eval(run2)
eval(run3)
--
Jonathan P. Daily
Technician - USGS Leetown Science Center
11649 Leetown Road
Kearneysville WV, 25430
(304) 724-4480
Is the room still a room when its empty? Does the room,
 the thing itself have purpose? Or do we, what's the word... imbue it.
 - Jubal Early, Firefly

r-help-boun...@r-project.org wrote on 02/24/2011 10:21:47 AM:

 [image removed] 
 
 [R] Running code sequentially from separate scripts (but not functions)
 
 Dimitri Liakhovitski 
 
 to:
 
 r-help
 
 02/24/2011 10:24 AM
 
 Sent by:
 
 r-help-boun...@r-project.org
 
 Hello!
 
 I am wondering if it's possible to run - in sequence - code that is
 stored in several R scripts.
 For example:
 
 Script in the file code1.r contains the code:
 a = 3; b = 5; c = a + b
 
 Script in the file code2.r contains the code:
 d = 10; e = d - c
 
 Script in the file code3.r contains the code:
 result=e/a
 
 I understand that I could write those 3 scripts as 3 functions and
 source them from another script.
 But maybe there is a way of having them run one by one as such?
 
 Thanks a lot!
 
 -- 
 Dimitri Liakhovitski
 Ninah Consulting
 www.ninah.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] create dummy variables by for loop

2011-02-24 Thread Jonathan P Daily
See inline below.
--
Jonathan P. Daily
Technician - USGS Leetown Science Center
11649 Leetown Road
Kearneysville WV, 25430
(304) 724-4480
Is the room still a room when its empty? Does the room,
 the thing itself have purpose? Or do we, what's the word... imbue it.
 - Jubal Early, Firefly

r-help-boun...@r-project.org wrote on 02/24/2011 01:23:54 PM:

 [image removed] 
 
 [R] create dummy variables by for loop
 
 Changbin Du 
 
 to:
 
 r-help@r-project.org
 
 02/24/2011 01:25 PM
 
 Sent by:
 
 r-help-boun...@r-project.org
 
 HI, Dear R community,
 
 I try to create 100 dummy variables like the following:
 
 ack$id_1 - (ack$ID==1)*1
 ack$id_2 - (ack$ID==2)*1
 ..
 .
 ack$id_100 - (ack$ID==100)*1
 
 
 I used the following codes:
 
 for(i in 1:100){
   ack$id_[i] - (ack$ID==i)*1
  }
This doesn't do what you think it does. when i = 1, it assigns the result 
of (ack$ID==1)*1 to the first element of ack$id_

If you want ack$id_i to be created, try:

ack[[paste(id, i, sep = _)]] - (ack$ID==i)*1


 
 But only one column is created, can anyone help me?
 
 Thanks a lot!
 
 
 -- 
 Sincerely,
 Changbin
 --
 
[[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 string to call/manipulate an object

2011-02-23 Thread Jonathan P Daily
If you are looping through and have the names of the files as characters, 
say in ticker.names - c(IBM, ...), you may be able to do this using:

for(nam in ticker.names)
{
[snip...]
eval(parse(text = paste('colnames(', nam, ') - c(
open,high,low,close,vol)', sep = '')))
}

HTH,
Jon
--
Jonathan P. Daily
Technician - USGS Leetown Science Center
11649 Leetown Road
Kearneysville WV, 25430
(304) 724-4480
Is the room still a room when its empty? Does the room,
 the thing itself have purpose? Or do we, what's the word... imbue it.
 - Jubal Early, Firefly

r-help-boun...@r-project.org wrote on 02/23/2011 10:23:35 AM:

 [image removed] 
 
 Re: [R] Using string to call/manipulate an object
 
 Kushan Thakkar 
 
 to:
 
 David Winsemius
 
 02/23/2011 10:55 AM
 
 Sent by:
 
 r-help-boun...@r-project.org
 
 Cc:
 
 r-help
 
 @Scott:
 
 I can't just use
 
 colnames(IBM) - c(open,high,low,close,vol)
 
 
 I have nearly 100 tickers stored in an vector and I am looping through 
them.
 Its not a good idea to hardcode all of them.
 
 @David:
 Column names is just an example. I have a long script that takes in an 
xts
 object and performs a series of manipulation. I want to to be able to 
run
 the same program on a series of xts objects through a loop. For that I 
need
 to be able to able to dynamically point/refer to those xts object inside 
my
 loop.
 
 
 On Wed, Feb 23, 2011 at 8:58 AM, David Winsemius 
 dwinsem...@comcast.netwrote:
 
 
  On Feb 23, 2011, at 8:55 AM, Kushan Thakkar wrote:
 
   I am using getSymbols function from quantmod package to get price 
data
  from
  internet.
 
  Currently I have:
 
  my.ticker - IBM
  getSymbols(my.ticker,src=google)
 
  This  creates an xts object named my.ticker which contains historical
  price
  data for IBM.
 
  How can I call and manipulating this xts object using my original 
string
  my.ticker?
 
  I want to do:
  colnames(my.ticker) - c(open,high,low,close,vol)
 
 
  If you want to change the colnames (an attribute) of the object now 
named
  IBM in your global environment, then look a:
 
  ?attributes
  ?attr
 
 
 
  However, this does not work as my.ticker refers to the string IBM 
rather
  than the xts object called IBM.
 
  Out of desperation, I have also tried:
  colnames(paste(my.ticker)) - c(open,high,low,close,vol)
  colnames(as.xts(my.ticker)) - c(open,high,low,close,vol)
 
 
  But why are you do this??? It already has a perfectly servicable set 
of
  names:
 
   colnames(get(my.ticker))
  [1] IBM.Open   IBM.High   IBM.LowIBM.Close  IBM.Volume
 
  --
  David.
 
 
  Thanks
  Kushan
 
 [[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.
 
 
  David Winsemius, MD
  West Hartford, CT
 
 
 
[[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] R script HELP!

2011-02-18 Thread Jonathan P Daily
It looks to me like when you assign ID_min and ID_max that you want them 
to be vectors. In R, this is accomplished by ?c.

Example:
ID_min - c(976834501,  290018099.3145, 1000)

--
Jonathan P. Daily
Technician - USGS Leetown Science Center
11649 Leetown Road
Kearneysville WV, 25430
(304) 724-4480
Is the room still a room when its empty? Does the room,
 the thing itself have purpose? Or do we, what's the word... imbue it.
 - Jubal Early, Firefly

r-help-boun...@r-project.org wrote on 02/18/2011 08:21:36 AM:

 [image removed] 
 
 [R] R script HELP!
 
 whizevans 
 
 to:
 
 r-help
 
 02/18/2011 08:49 AM
 
 Sent by:
 
 r-help-boun...@r-project.org
 
 
 The following is my R script which I am struggling with to assess ICESat
 data..perhaps it is the ID_min or ID_max that is wrong? I don't know, 
any
 help would be greatly appreciated :(
 
 
 # OPTIONS - CHANGE THESE VARIABLES IF NEEDED\par
 
##\par
 \par
 icesatfile - 
 
 'C:/Users/Whiz/My_Documents/Year3/GY3072/ICESat_GLAS/IDLreadGLASWF/
 out_wf_GLA01_09030918_r5947_031_L2E.dat'\par
 \par
 plotdir - 
'C:/Users/Whiz/My_Documents/Year3/GY3072/ICESat_GLAS/PLOT'\par
 \par
 \par
 \par
 ID_min - 976834501  290018099.3145 1000 #231741042 # specify range of
 waveforms to be plotted, -1 means all\par
 ID_max - 976834506  290018101.2895 1000 @@@note 
only
 one ID used @@@\par
 \par
 \par
 \par
 noise - 0.05 # values below NOISE will be disregarded in the waveform
 fitting\par
 sdthres - 0.02 # threshold for a standard deviation of volt 
measurements
 indicating the presence of a signal\par
 \par
 fit_waveform_model - TRUE # set to TRUE this activates the Gaussian
 waveform model fitting and plotting\par
 #fit_waveform_select - c(976834501  290018099.3145 1000)  # gives the
 Unique ID for which the model fitting will 
 
 be activated\par
 \par
 
#\par
 # END OF OPTIONS\par
 -- 
 View this message in context: http://r.789695.n4.nabble.com/R-
 script-HELP-tp3312644p3312644.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] R script HELP!

2011-02-18 Thread Jonathan P Daily
Well, this script only shows the option settings, so I assumed that the 
string being used as your infile was formatted for R. As for how it will 
have to look for R to read it in, there are many ways to do this - I would 
start by reading R Data Import/Export that ships with every copy of R. 
As for scripts and their default writing methods AFAIR Rscript writes to 
stdout, though if you want it to save your modified data in some other 
format than a text dump, look at the various methods of exporting data... 
again in the aforementioned R Data Import/Export.
--
Jonathan P. Daily
Technician - USGS Leetown Science Center
11649 Leetown Road
Kearneysville WV, 25430
(304) 724-4480
Is the room still a room when its empty? Does the room,
 the thing itself have purpose? Or do we, what's the word... imbue it.
 - Jubal Early, Firefly

r-help-boun...@r-project.org wrote on 02/18/2011 10:29:55 AM:

 [image removed] 
 
 Re: [R] R script HELP!
 
 whizevans 
 
 to:
 
 r-help
 
 02/18/2011 11:06 AM
 
 Sent by:
 
 r-help-boun...@r-project.org
 
 
 OK thanks Jonathon, I will have a go.
 Is the plotdir file technically my output file? Or what is this 
otherwise?
 
 Also, having never used R script before, is it not very good at reading
 data, may I have to alter my input file in excel first?
 Thanks
 
 
 -- 
 View this message in context: http://r.789695.n4.nabble.com/R-
 script-HELP-tp3312644p3312898.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] CDF of Sample Quantile

2011-02-14 Thread Jonathan P Daily
If I understand this, you have a value x, or a vector of values x, and you 
want to know the CDF that this value is drawn from a normal distribution?

I assume you are drawing from rnorm for your simulations, so look at the 
other functions listed when you ?rnorm.

HTH
--
Jonathan P. Daily
Technician - USGS Leetown Science Center
11649 Leetown Road
Kearneysville WV, 25430
(304) 724-4480
Is the room still a room when its empty? Does the room,
 the thing itself have purpose? Or do we, what's the word... imbue it.
 - Jubal Early, Firefly

r-help-boun...@r-project.org wrote on 02/14/2011 09:58:09 AM:

 [image removed] 
 
 [R] CDF of Sample Quantile
 
 Bentley Coffey 
 
 to:
 
 r-help
 
 02/14/2011 01:58 PM
 
 Sent by:
 
 r-help-boun...@r-project.org
 
 I need to calculate the probability that a sample quantile will exceed a
 threshold given the size of the iid sample and the parameters describing 
the
 distribution of each observation (normal, in my case). I can compute the
 probability with brute force simulation: simulate a size N sample, apply 
R's
 quantile() function on it, compare it to the threshold, replicate this 
MANY
 times, and count the number of times the sample quantile exceeded the
 threshold (dividing by the total number of replications yields the
 probability of interest). The problem is that the number of replications
 required to get sufficient precision (3 digits say) is so HUGE that this
 takes FOREVER. I have to perform this task so much in my script 
(searching
 over the sample size and repeated for several different distribution
 parameters) that it takes too many hours to run.
 
 I've searched for pre-existing code to do this in R and haven't found
 anything. Perhaps I'm missing something. Is anyone aware of an R 
function to
 compute this probability?
 
 I've tried writing my own code using the fact that R's quantile() 
function
 is a linear combination of 2 order statistics. Basically, I wrote down 
the
 mathematical form of the joint pdf for the 2 order statistics (a 
function of
 the sample size and the distribution parameters) then performed a
 pseudo-Monte Carlo integration (i.e. using Halton Draws rather than R's
 random draws) over the region where the sample quantile exceeds the
 threshold. In theory, this should work and it takes about 1000 times 
fewer
 clock cycles to compute than the Brute Force approach. My problem is 
that
 there is a significant discrepancy between the results using Brute Force 
and
 using this more efficient approach that I have coded up. I believe that 
the
 problem is numerical error but it could be some programming bug; 
regardless,
 I have been unable to locate the source of this problem and have spent 
over
 20 hours trying to identify it this weekend. Please, somebody help!!!
 
 So, again, my question: is there code in R for quickly evaluating the 
CDF of
 a Sample Quantile given the sample size and the parameters governing the
 distribution of each iid point in the sample?
 
 Grateful for any help,
 
 Bentley
 
[[alternative HTML version deleted]]
 
 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide 
http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.

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


Re: [R] help - the condition has length 1 and only the first element will be used

2011-02-10 Thread Jonathan P Daily
The issue here is that if only accepts a single True/False argument. Try 
these functions:
?ifelse
?all
?any
--
Jonathan P. Daily
Technician - USGS Leetown Science Center
11649 Leetown Road
Kearneysville WV, 25430
(304) 724-4480
Is the room still a room when its empty? Does the room,
 the thing itself have purpose? Or do we, what's the word... imbue it.
 - Jubal Early, Firefly

r-help-boun...@r-project.org wrote on 02/10/2011 09:07:40 AM:

 [image removed] 
 
 [R] help - the condition has length  1 and only the first element 
 will be used
 
 Bodnar Laszlo EB_HU 
 
 to:
 
 'r-help@r-project.org'
 
 02/10/2011 10:25 AM
 
 Sent by:
 
 r-help-boun...@r-project.org
 
 Hello there,
 
 
 
 I don't know if I'm addressing my question to the right e-mail 
 address, I hope I do. Actually I have a little problem concerning 
 writing a code in R. I try to briefly sum up my problem.
 
 
 
 As you can see below, I created the functions Equation1 and 
 Equation2 with some conditions.
 
 
 
   Equation1 -function(x){
 
  if (x=0.25) y -1-4*x
 
  if (x0.25)   y -0
 
  y
 
  }
 
 
 
   Equation2 -function(x){
 
  if (x=0.25)y -4*x
 
  if (x0.25  x=0.5)   y -2-4*x
 
  if (x0.5)   y -0
 
  y
 
  }
 
 
 
   And then I generated a sequence of numbers from 0 to 1 using 
 the following code:
 
 
 
   x -seq(0,1,0.05)
 
 
 
   What I intended to do was to create 3 columns like below. In 
 the first column you can find all the x values I created just before
 using the seq procedure and in the next 2 columns you can see all 
 the calculated values of functions Equation1 and Equation2 respectively.
 
 
 
   x  Egyenlet1  Egyenlet2
 
   0.00  1.000.00
 
   0.05  0.800.20
 
   0.10  0.600.40
 
   0.15  0.400.60
 
   0.20  0.200.80
 
   0.25  0.001.00
 
   0.30  0.000.80
 
   0.35  0.000.60
 
   0.40  0.000.40
 
   0.45  0.000.20
 
   0.50  0.000.00
 
   0.55  0.000.00
 
   0.60  0.000.00
 
   0.65  0.000.00
 
   0.70  0.000.00
 
   0.75  0.000.00
 
   0.80  0.000.00
 
   0.85  0.000.00
 
   0.90  0.000.00
 
   0.95  0.000.00
 
   1.00  0.000.00
 
 
 
   Unfortunately I didn't know how to create these columns. 
 Whenever I tried to send the following codes into R:
 
   Equation1(x) or Equation1(x) (remember x representing the 
 values from 0 to 1)
 
   ...I instantaneously got a warning message saying:
 
 
 
[1]  1.0  0.8  0.6  0.4  0.2  0.0 -0.2 -0.4 -0.6 -0.8 -1.0 
 -1.2 -1.4 -1.6 -1.8 -2.0 -2.2 -2.4 -2.6 -2.8 -3.0
 
   Warning messages:
 
   1: In if (x = 0.25) y - 1 - 4 * x :
 
 the condition has length  1 and only the first element will be 
used
 
   2: In if (x  0.25) y - 0 :
 
 the condition has length  1 and only the first element will be 
used
 
 
 
   Could somebody please help me with this? I would greatly 
 appreciate if somebody would reply.
 
   Thank you very much and have a pleasant day!
 
 
 
   Best regards,
 
   Laszlo
 
 
 
 

 
 Ez az e-mail és az összes hozzá tartozó csatolt melléklet 
 titkos és/vagy jogilag, szakmailag vagy más módon védett 
 információt tartalmazhat. Amennyiben nem �n a levél címzettje 
 akkor a levél tartalmának közlése, reprodukálása, másolása, 
 vagy egyéb más úton történÅ? terjesztése, felhasználása 
 szigorúan tilos. Amennyiben tévedésbÅ?l kapta meg ezt az
 üzenetet kérjük azonnal értesítse az üzenet küldÅ?jét. Az 
 Erste Bank Hungary Zrt. (EBH) nem vállal felelÅ?sséget az 
 információ teljes és pontos - címzett(ek)hez történÅ? - 
 eljuttatásáért, valamint semmilyen késésért, kapcsolat 
 megszakadásból eredÅ? hibáért, vagy az információ 
 felhasználásából vagy annak megbízhatatlanságából eredÅ? 
kárért.
 
 
 
 Az üzenetek EBH-n kívüli küldÅ?je vagy címzettje tudomásul 
 veszi és hozzájárul, hogy az üzenetekhez más banki alkalmazott 
 is hozzáférhet az EBH folytonos munkamenetének biztosítása 
érdekében.
 
 
 
 
 
 This e-mail and any attached files are confidential 
and/...{{dropped:19}}
 
 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide 
http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained

Re: [R] R-/Text-editor for Windows?

2011-01-31 Thread Jonathan P Daily
Well, AutoHotKey [1] is a free program/scripting language that runs 
scripts to perform basic window handling, file I/O, and program execution. 
It also allows you to bind the running of these scripts to keys or 
mouse-strokes with the option of making each window-specific. NppToR is 
actually a compiled AutoHotKey script designed to do Notepad++ specific 
things. For example, one of my generic, slower, user-unfriendly scripts 
is:

TestConsole()
{
IfWinNotExist, ahk_class Console_2_Main,
{
Run, C:\Documents and Settings\jdaily\Console2\Console.exe 
-t R
WinWait, ahk_class Console_2_Main,
}
}

ActivateConsole()
{
TestConsole()
WinActivate, ahk_class Console_2_Main,
WinWaitActive, ahk_class Console_2_Main,
}

#1::
WinGetActiveTitle, editor
old_clipboard = %clipboard%
Send, {CTRLDOWN}c{CTRLUP}
ActivateConsole()
Send, {CTRLDOWN}{END}{CTRLUP}{RETURN}
WinActivate, %editor%,
clipboard = %old_clipboard%
return

What it does when I press the Super+1 is assign the current window to a 
variable editor, backup my current clipboard, and copy my highlighted 
text. Then it checks to see if Console [2] is active and opens console 
with R if not open. It pastes the copied text and reactivates editor, 
restoring my old clipboard. Its nice because it works whether I'm in 
Geany, Notepad, MSword, etc., but I didn't bother doing any checking to 
make sure console's active tab is R. This could easily be solved if you 
just use RTerm/RGui by replacing all the instances of Console with the 
appropriate R executable.

[1]www.autohotkey.com
[2]sourceforge.net/projects/console
--
Jonathan P. Daily
Technician - USGS Leetown Science Center
11649 Leetown Road
Kearneysville WV, 25430
(304) 724-4480
Is the room still a room when its empty? Does the room,
 the thing itself have purpose? Or do we, what's the word... imbue it.
 - Jubal Early, Firefly

Liviu Andronic landronim...@gmail.com wrote on 01/29/2011 04:08:46 AM:

 [image removed] 
 
 Re: [R] R-/Text-editor for Windows?
 
 Liviu Andronic 
 
 to:
 
 Jonathan P Daily
 
 01/29/2011 04:09 AM
 
 Cc:
 
 Sascha Vieweg, r-help, r-help-bounces
 
 Hello
 
 On Fri, Jan 28, 2011 at 8:03 PM, Jonathan P Daily jda...@usgs.gov 
wrote:
  Geany also handles a ton of filetypes, but lacks a direct interface to 
R
  in the windows version - I wrote an AutoHotKey script that did this 
for me
  in about 5 minutes.
 
 Could you please expand on that? I prefer to use Geany when working on
 Linux, but I always found it annoying the Windows limitation.
 
 Thank you
 Liviu

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


Re: [R] R-/Text-editor for Windows?

2011-01-28 Thread Jonathan P Daily
Notepad ++ handles just about anything and has an accompanying program 
NppToR to make passing scripts easier.

Geany also handles a ton of filetypes, but lacks a direct interface to R 
in the windows version - I wrote an AutoHotKey script that did this for me 
in about 5 minutes. On the other hand, geany is cross platform.

As always, EMACS + ESS and Vim are also options.
--
Jonathan P. Daily
Technician - USGS Leetown Science Center
11649 Leetown Road
Kearneysville WV, 25430
(304) 724-4480
Is the room still a room when its empty? Does the room,
 the thing itself have purpose? Or do we, what's the word... imbue it.
 - Jubal Early, Firefly

r-help-boun...@r-project.org wrote on 01/28/2011 01:55:25 PM:

 [image removed] 
 
 [R] R-/Text-editor for Windows?
 
 Sascha Vieweg 
 
 to:
 
 r-help
 
 01/28/2011 01:57 PM
 
 Sent by:
 
 r-help-boun...@r-project.org
 
 Tinn-R (http://www.sciviews.org/Tinn-R/) is one of the topmost 
 suggestions when googling an R-(text-)editor for Windows. However, 
 to me it appears dissappointing that Tinn-R does not handle utf-8 
 (mac-roman, or any other) encoded R-scripts or, in general, text 
 files. Besides Emacs and the R built-in editor, could you 
 recommend a good editor for Windows, even some commmercial for a 
 small price? (For a comparison, TextMate for OS X is 35 USD and 
 does a great job on all plain text and code related issues, not 
 only R.) Thanks, *S*
 
 -- 
 Sascha Vieweg, saschav...@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@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Quantile Regression: Extracting Residuals

2011-01-19 Thread Jonathan P Daily
Try looking here:

?rq.object
?residuals

R has excellent documentation that can answer many such questions with 
less than a minute of reading.
--
Jonathan P. Daily
Technician - USGS Leetown Science Center
11649 Leetown Road
Kearneysville WV, 25430
(304) 724-4480
Is the room still a room when its empty? Does the room,
 the thing itself have purpose? Or do we, what's the word... imbue it.
 - Jubal Early, Firefly

r-help-boun...@r-project.org wrote on 01/19/2011 11:30:49 AM:

 [image removed] 
 
 [R] Quantile Regression: Extracting Residuals
 
 Thanaset 
 
 to:
 
 r-help
 
 01/19/2011 02:12 PM
 
 Sent by:
 
 r-help-boun...@r-project.org
 
 
 Dear R users
 
 Is there a way to obtain the residuals from a model fitted by quantile
 regression?  Thank you.
 
 Thanaset
 -- 
 View this message in context: http://r.789695.n4.nabble.com/
 Quantile-Regression-Extracting-Residuals-tp3225423p3225423.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] Question about histogram

2011-01-13 Thread Jonathan P Daily
Because a histogram is descriptive and makes no assumptions about what it 
describes? Attaching a probability to the bars assumes that some random 
draw is being made. Suppose my data is a count of computers running a 
particular OS. What would be the value in reporting this as a probability 
that a randomly chosen computer is running Ubuntu? Density is more 
universal, IMO.
--
Jonathan P. Daily
Technician - USGS Leetown Science Center
11649 Leetown Road
Kearneysville WV, 25430
(304) 724-4480
Is the room still a room when its empty? Does the room,
 the thing itself have purpose? Or do we, what's the word... imbue it.
 - Jubal Early, Firefly

r-help-boun...@r-project.org wrote on 01/13/2011 01:37:01 PM:

 [image removed] 
 
 [R] Question about histogram
 
 Longe 
 
 to:
 
 r-help
 
 01/13/2011 03:11 PM
 
 Sent by:
 
 r-help-boun...@r-project.org
 
 Dear list,
 
 I'm new to R, please bear with my silly questions.  I'm trying to get an 

 understanding of why the results I get from a call to hist() are not as 
 I thought I would get.  When I use the parameter freq=FALSE, I think the 

 plot will contain bars that none of them is larger than 1, because 
 they're probabilities.  But for my code, the bars exceeded 1.
 
 The actual data seems immaterial.  I tried with dummy data:
 
   hist(runif(1000), freq=FALSE)
 
 and the histogram includes bars well over 1 in height.  The man page 
 says that freq=FALSE produces densities, so that the total area is 1. 
 Clearly if all the values are between 0 and 1, as is the case here, some 

 of the bars stand out above 1, for the area to be 1.  I thought that it 
 is the sum of the bar heights that would be 1, so that the bars reflect 
 probabilities for each interval, rather than densities.  So, the answer 
 to my question would be because it's densities, not probabilities, but 

 then the question is, why densities and not probabilities?
 
 Regards,
 L.
 
 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide 
http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
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 wrap a long line in R scripts?

2011-01-10 Thread Jonathan P Daily
a - rey lo
ong charrr

Although the indentation is just personal preference.
--
Jonathan P. Daily
Technician - USGS Leetown Science Center
11649 Leetown Road
Kearneysville WV, 25430
(304) 724-4480
Is the room still a room when its empty? Does the room,
 the thing itself have purpose? Or do we, what's the word... imbue it.
 - Jubal Early, Firefly

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
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 wrap a long line in R scripts?

2011-01-10 Thread Jonathan P Daily
To elaborate, expressions and any explicit enclosures can also be simply 
split between lines. Often, this is done without space issues just for 
clarity.

EX:

vec - c(LETTERS[1:5], 1:5,
letters[1:5])

plot(X, Y, main = A plot, xlab = X Values, ylab = Response,
lty = 1,
pch = 5,
cex = .75)

num - ((a1 + a2 + a3)/b1 + 
(a4 + a5 + a6)/b2) / 
b3
--
Jonathan P. Daily
Technician - USGS Leetown Science Center
11649 Leetown Road
Kearneysville WV, 25430
(304) 724-4480
Is the room still a room when its empty? Does the room,
 the thing itself have purpose? Or do we, what's the word... imbue it.
 - Jubal Early, Firefly

r-help-boun...@r-project.org wrote on 01/10/2011 09:04:23 AM:

 [image removed] 
 
 Re: [R] how to wrap a long line in R scripts?
 
 Jonathan P Daily 
 
 to:
 
 Tutu2008
 
 01/10/2011 09:09 AM
 
 Sent by:
 
 r-help-boun...@r-project.org
 
 Cc:
 
 r-help, r-help-bounces
 
 a - rey lo
 ong charrr
 
 Although the indentation is just personal preference.
 --
 Jonathan P. Daily
 Technician - USGS Leetown Science Center
 11649 Leetown Road
 Kearneysville WV, 25430
 (304) 724-4480
 Is the room still a room when its empty? Does the room,
  the thing itself have purpose? Or do we, what's the word... imbue it.
  - Jubal Early, Firefly
 
 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/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 wrap a long line in R scripts?

2011-01-10 Thread Jonathan P Daily
Oops! Good catch. I have been coding in python and R recently and now I'm 
mixing conventions ... R's automatic line wrapping and Python's 
auto-catenation given a line wrap (via '\').

A better solution would be:

a - paste(rey lo,
ong charrr, sep = )
print(a)

--
Jonathan P. Daily
Technician - USGS Leetown Science Center
11649 Leetown Road
Kearneysville WV, 25430
(304) 724-4480
Is the room still a room when its empty? Does the room,
 the thing itself have purpose? Or do we, what's the word... imbue it.
 - Jubal Early, Firefly

r-help-boun...@r-project.org wrote on 01/10/2011 09:51:28 AM:

 [image removed] 
 
 Re: [R] how to wrap a long line in R scripts?
 
 Keith Jewell 
 
 to:
 
 r-help
 
 01/10/2011 09:54 AM
 
 Sent by:
 
 r-help-boun...@r-project.org
 
 
 Jonathan P Daily jda...@usgs.gov wrote in message 
 
news:of588e803b.869e9aff-on85257814.004d298d-85257814.004d4...@usgs.gov...
 a - rey lo
 ong charrr
 
  Although the indentation is just personal preference.
  --
  Jonathan P. Daily
  Technician - USGS Leetown Science Center
  11649 Leetown Road
  Kearneysville WV, 25430
  (304) 724-4480
  Is the room still a room when its empty? Does the room,
  the thing itself have purpose? Or do we, what's the word... imbue it.
  - Jubal Early, Firefly
 
 
 Did you test that? Printing a to see the result so the commands are
 -
 a - rey lo
 ong charrr
 a
 
 Pasting directly into Rgui
  a - rey lo
 + ong charrr
  a
 [1] rey lo\nong 
 charrr
 
 Saving to file 'test.r' and sourcing
  source(C:\\Documents and Settings\\jewell\\Desktop\\test.r, 
echo=TRUE)
  a - rey lo
 + ong charrr
  a
 [1] rey lo\nong 
 charrr
 
 I don't think this is what the OP wanted.
 I guess he wants rey loong 
 charrr
 
 I don't know the answer (other than, as suggested by Peter Ehlers) to 
build 
 it bit by bit.
 
 KJ
 
 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/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] matrices call a function element-wise

2011-01-03 Thread Jonathan P Daily
IIRC, R is perfectly able to call matrices as vectors, so you might be 
able to do this:

FT - function(i) fisher.test(matrix(c(A[i],B[i],C[i],D[i]),2))
E - sapply(1:100, FT)

Though I don't know how much time you will save.
--
Jonathan P. Daily
Technician - USGS Leetown Science Center
11649 Leetown Road
Kearneysville WV, 25430
(304) 724-4480
Is the room still a room when its empty? Does the room,
 the thing itself have purpose? Or do we, what's the word... imbue it.
 - Jubal Early, Firefly

r-help-boun...@r-project.org wrote on 01/03/2011 09:57:14 AM:

 [image removed] 
 
 [R] matrices call a function element-wise
 
 zhaoxing731 
 
 to:
 
 R-help
 
 01/03/2011 01:46 PM
 
 Sent by:
 
 r-help-boun...@r-project.org
 
 Hello
 
 I have 4 1000*1000 matrix A,B,C,D. I want to use the corresponding 
 element of the 4 matrices. Using the for loop as follow:
 
 E-o
 for (i in 1:1000)
 {for (j in 1:1000)
  {
  E-fisher.test(matrix(c(A[i][j],B[i][j],C[i][j],D[i][j]),
 2))#call fisher.test for every element
  }
 }
 
 It is so time-consuming
 Need vectorization
 
 Yours sincerely
 
 
 
 
 ZhaoXing
 Department of Health Statistics
 West China School of Public Health
 Sichuan University
 No.17 Section 3, South Renmin Road
 Chengdu, Sichuan 610041
 P.R.China
 
[[alternative HTML version deleted]]
 
 
 __
 8O?lW2aQE;3,4sH]A?Cb7QSJOd?
 
 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/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] randomForest speed improvements

2011-01-03 Thread Jonathan P Daily
Have you tried adjusting:
mtry - the number of parameters to try per tree
ntree - the number of trees grown
keep.forest - logical on whether to store tree

Specifically, I found huge improvements in speed by switching keep.forest 
to FALSE in the past when I didn't actually need the forest post analysis.
--
Jonathan P. Daily
Technician - USGS Leetown Science Center
11649 Leetown Road
Kearneysville WV, 25430
(304) 724-4480
Is the room still a room when its empty? Does the room,
 the thing itself have purpose? Or do we, what's the word... imbue it.
 - Jubal Early, Firefly

r-help-boun...@r-project.org wrote on 01/03/2011 02:59:29 PM:

 [image removed] 
 
 [R] randomForest speed improvements
 
 apresley 
 
 to:
 
 r-help
 
 01/03/2011 03:03 PM
 
 Sent by:
 
 r-help-boun...@r-project.org
 
 
 Hi there,
 
 We're trying to use randomForest to do some predictions.  The 
test-harness
 for our code is pretty straightforward:
 
   library ('randomForest');
   data202 - read.csv (random.csv, header=TRUE);
   x- data202[1:5,1:6];
   y- data202[1:5,8];
   y- y[,drop=TRUE];
 
   x2 - data202[50001:6,1:6];
   y2 - data202[50001:6,8];
   y2 - y2[,drop=TRUE];
 
   RFobject - randomForest(x,y,na.action=na.roughfix);
   p - predict (RFobject, x2);
 
 In this case, the CSV contains 10 columns, of which 1-6 are numeric in
 nature (day of week, week of month, etc...) and column 8 is the target
 (sales, a numeric number).
 
 randomForest does fine with the data, our issue is how long it takes. In
 this case, about 5,000 rows of data seems to take just a few seconds, 
but
 going to 50,000 rows doesn't take 5x the time, it takes perhaps 30 or 40
 minutes.
 
 We've downloaded and tried RT-Rank, which is a multi-threaded version of
 RandomForest, and this seems to produce the same (or slightly better)
 predictions, but also gets done fairly quickly.
 
 What can we do to improve the speed of this data computation?  The 
system
 we're on is a dual quad-core Intel CPU @ 2.33Ghz, and with 16GB of RAM 
...
 we're using the stock R RPM for CentOS 5.5.
 
 Thanks!
 
 --
 Anthony
 -- 
 View this message in context: http://r.789695.n4.nabble.com/
 randomForest-speed-improvements-tp3172523p3172523.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] Windows editor suggestions - autosave

2010-12-29 Thread Jonathan P Daily
I can also suggest the following:

Notepad++ has an AutoSave plugin, a slew of other useful features, and a 
Scintilla editor. If you use other languages, it is also extensible and 
has almost no learning curve. NppToR is a background application that 
allows you to pass lines or files straight from your editor to an R 
console.

Notepad++: notepad-plus-plus.org
NppToR: sourceforge.net/projects/npptor/ 

I can also suggest Geany, another Scintilla-powered editor. In the plugins 
list, Save Actions has a autosave feature. While Geany doesn't have a 
native R interface in Windows (I wrote one for myself in AutoHotKey in 
about 2 mins), it has a ton of other options and is cross-platform.

Geany: www.geany.org
--
Jonathan P. Daily
Technician - USGS Leetown Science Center
11649 Leetown Road
Kearneysville WV, 25430
(304) 724-4480
Is the room still a room when its empty? Does the room,
 the thing itself have purpose? Or do we, what's the word... imbue it.
 - Jubal Early, Firefly

r-help-boun...@r-project.org wrote on 12/29/2010 11:32:40 AM:

 [image removed] 
 
 [R] Windows editor suggestions - autosave
 
 Michael Conklin 
 
 to:
 
 R-help
 
 12/29/2010 11:35 AM
 
 Sent by:
 
 r-help-boun...@r-project.org
 
 I am looking for advice on an editor to use with R (windows) that 
 has an autosave feature.  I typically write scripts using the RGui 
 (and tried TinnR yesterday) but I am having continuing problems with
 BSODs (non R related) and have in the past have had issues with R 
 crashes and would really like a system that does not require me to 
 remember to hit the save button on my script every 10 minutes so 
 that I can avoid redoing everything.
 
 W. Michael Conklin
 Chief Methodologist
 Google Voice: (612) 56STATS
 
 MarketTools, Inc. | www.markettools.com
 6465 Wayzata Blvd | Suite 170 |  St. Louis Park, MN 55426.  PHONE: 
 952.417.4719 | CELL: 612.201.8978   
 This email and attachment(s) may contain confidential and/or 
 proprietary information and is intended only for the intended 
 addressee(s) or its authorized agent(s). Any disclosure, printing, 
 copying or use of such information is strictly prohibited. If this 
 email and/or attachment(s) were received in error, please 
 immediately notify the sender and delete all copies
 
 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/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] Faster way to do it??...using apply?

2010-12-28 Thread Jonathan P Daily
I don't know if it's any faster, but it is also possible this way:

y - ifelse(x ==1, round(runif(x)), sign(x))
--
Jonathan P. Daily
Technician - USGS Leetown Science Center
11649 Leetown Road
Kearneysville WV, 25430
(304) 724-4480
Is the room still a room when its empty? Does the room,
 the thing itself have purpose? Or do we, what's the word... imbue it.
 - Jubal Early, Firefly

r-help-boun...@r-project.org wrote on 12/28/2010 12:48:04 PM:

 [image removed] 
 
 Re: [R] Faster way to do it??...using apply?
 
 Henrique Dallazuanna 
 
 to:
 
 M.Ribeiro
 
 12/28/2010 12:51 PM
 
 Sent by:
 
 r-help-boun...@r-project.org
 
 Cc:
 
 r-help
 
 Try this indeed
 
 replace(replace(x, x == 1, sample(0:1, sum(x == 1), rep = TRUE)), x == 
2, 1)
 
 On Tue, Dec 28, 2010 at 3:14 PM, M.Ribeiro mresende...@yahoo.com.br 
wrote:
 
 
  Hi Henrique,
  Thanks for the fast answer,
  The only problem in your code, which I think I didn't mention in my 
message
  is that I would like one different random sampling procedure for each 
1 in
  my vector
 
  The way it was written, it samples only once and replace by every 1:
   x = as.matrix(c(1,1,1,1,1,1,1,1,1,1,1,1,1,1,1))
   replace(replace(x, x == 1, sample(0:1, 1)), x == 2, 1)
[,1]
   [1,]1
   [2,]1
   [3,]1
   [4,]1
   [5,]1
   [6,]1
   [7,]1
   [8,]1
   [9,]1
  [10,]1
  [11,]1
  [12,]1
  [13,]1
  [14,]1
  [15,]1
 
  Thanks
 
  --
  View this message in context:
  http://r.789695.n4.nabble.com/Faster-way-to-do-it-using-apply-
 tp3166161p3166203.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.
 
 
 
 
 -- 
 Henrique Dallazuanna
 Curitiba-Paraná-Brasil
 25° 25' 40 S 49° 16' 22 O
 
[[alternative HTML version deleted]]
 
 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide 
http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.

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


Re: [R] Fitting a Triangular Distribution to Bivariate Data

2010-12-23 Thread Jonathan P Daily
I don't know if any specific package has a triangular distribution, but I 
know you can fit a model using first degree b-splines with a single knot.

library(splines)
?bs
x - 1:100
y - rnorm(100, ifelse(x 50, x, 100-x), 15)
fit - lm(y ~ bs(x, knots = 50, degree = 1))

--
Jonathan P. Daily
Technician - USGS Leetown Science Center
11649 Leetown Road
Kearneysville WV, 25430
(304) 724-4480
Is the room still a room when its empty? Does the room,
 the thing itself have purpose? Or do we, what's the word... imbue it.
 - Jubal Early, Firefly

r-help-boun...@r-project.org wrote on 12/22/2010 01:19:16 PM:

 [image removed] 
 
 [R] Fitting a Triangular Distribution to Bivariate Data
 
 David Bapst 
 
 to:
 
 r-help
 
 12/22/2010 04:04 PM
 
 Sent by:
 
 r-help-boun...@r-project.org
 
 Hello,
 I have some xy data which clearly shows a non-monotonic, peaked
 triangular trend. You can get an idea of what it looks like with:
 
 x-1:20
 y-c(2*x[1:10]+1,-2*x[11:20]+42)
 
 I've tried fitting a quadratic, but it just doesn't the data-structure
 with the break point adequately. Is there anyway to fit a triangular
 or 'tent' function to my data in R?
 
 Some sample code would be appreciated; I'm not new to R, but I
 sometimes have difficulty understanding the model-fitting functions
 (finally figured out how to extrapolate with predict() today!)
 
 Thanks!
 -Dave Bapst, UChicago
 
 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/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 optimize function parameters?

2010-12-20 Thread Jonathan P Daily
Without an example, I'm not sure how much help I can be. Does your 
Variogram calculation return a single value that could be minimized? Or 
could it be coerced to be so?

I would suggest, if you haven't done so, a look at ?nlm and ?nlminb.
Alternatively, the CRAN package 'optimx' serves as a wrapper to many 
optimization algorithms and offers methods to compare them side-by-side.

Good luck,
Jon
--
Jonathan P. Daily
Technician - USGS Leetown Science Center
11649 Leetown Road
Kearneysville WV, 25430
(304) 724-4480
Is the room still a room when its empty? Does the room,
 the thing itself have purpose? Or do we, what's the word... imbue it.
 - Jubal Early, Firefly

r-help-boun...@r-project.org wrote on 12/20/2010 09:39:49 AM:

 [image removed] 
 
 [R] How to optimize function parameters?
 
 zbynek.jano...@gmail.com 
 
 to:
 
 r-help
 
 12/20/2010 10:43 AM
 
 Sent by:
 
 r-help-boun...@r-project.org
 
 
 Hi,
 
 I have a dataset and I want to fit a function to it.
 The function is variogram model (http://en.wikipedia.org/wiki/Variogram)
 The variogram model is defined by three parameters and I want them to be
 automatically optimized for real time data.
 I tried to use gafit {gafit} for this, but there are some data
 configuration, where optimal results given by gafit() are negative, 
which is
 not correct and cannot be used for further calculating. gafit() does not
 enable me to set a range of possible results (at least I did not 
succeded in
 doing so), therefore I am looking for another solution (Powell´s 
gradient
 descent possibly?).
 
 Can anyone give me a hint where to look?
 
 Thanks
 
 Zbynek
 -- 
 View this message in context: http://r.789695.n4.nabble.com/How-to-
 optimize-function-parameters-tp3095603p3095603.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] How to optimize function parameters?

2010-12-20 Thread Jonathan P Daily
If you can somehow add the sign of the output to the root square error, 
nlm, nlminb, and many options within optimx accept bounds.
--
Jonathan P. Daily
Technician - USGS Leetown Science Center
11649 Leetown Road
Kearneysville WV, 25430
(304) 724-4480
Is the room still a room when its empty? Does the room,
 the thing itself have purpose? Or do we, what's the word... imbue it.
 - Jubal Early, Firefly

r-help-boun...@r-project.org wrote on 12/20/2010 01:13:53 PM:

 [image removed] 
 
 Re: [R] How to optimize function parameters?
 
 zbynek.jano...@gmail.com 
 
 to:
 
 r-help
 
 12/20/2010 02:35 PM
 
 Sent by:
 
 r-help-boun...@r-project.org
 
 
 Thanks for your suggestions, I will certainly look at that
 
 To answer your question...
 I can calculate root square error between empirical data a those 
predicted
 by model (I used this to optimize the parameters using gafit()).
 
 -- 
 View this message in context: http://r.789695.n4.nabble.com/How-to-
 optimize-function-parameters-tp3095603p3095938.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] Alter plot point size by value of the plot value

2010-12-17 Thread Jonathan P Daily
Assuming your plot values are X and Y:

cex.val - 1 + (Y  1E-6)*.5 - (Y  1E-3)*.5
plot(X, Y, cex = cex.val)

--
Jonathan P. Daily
Technician - USGS Leetown Science Center
11649 Leetown Road
Kearneysville WV, 25430
(304) 724-4480
Is the room still a room when its empty? Does the room,
 the thing itself have purpose? Or do we, what's the word... imbue it.
 - Jubal Early, Firefly

r-help-boun...@r-project.org wrote on 12/17/2010 11:58:07 AM:

 [image removed] 
 
 [R] Alter plot point size by value of the plot value
 
 Douglas Scheftner 
 
 to:
 
 r-help
 
 12/17/2010 12:00 PM
 
 Sent by:
 
 r-help-boun...@r-project.org
 
 R folks,
 
   I am trying to create a mhtplot plot that will alter the point 
 size via the plot point value.The size of the point should 
 change via a set criteria such as:
 
 if  point value 10^-6 size 3x
 else if 10^-3 point value 10^-6 size 2x
 else point value 10^-3 size is x
 
 I consider myself an R newbie, and I am assuming that I could do 
 this via some sort of function to change the parameter cex value of 
 the plot, but I do not even know where to begin.  I have searched 
 for something similar to this, but have not had any luck.  Is it 
 possible to write a function that will alter the cex value via the 
 plot value.  Any suggestions?
 
 Thanks in advance,
 Doug
 
 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/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] Integrate two function in R

2010-12-16 Thread Jonathan P Daily
As a minor plug for my favorite non stat-based mathematics software, 
sagemath also has a rudimentary R interface built-in
--
Jonathan P. Daily
Technician - USGS Leetown Science Center
11649 Leetown Road
Kearneysville WV, 25430
(304) 724-4480
Is the room still a room when its empty? Does the room,
 the thing itself have purpose? Or do we, what's the word... imbue it.
 - Jubal Early, Firefly

r-help-boun...@r-project.org wrote on 12/16/2010 09:11:33 AM:

 [image removed] 
 
 Re: [R] Integrate two function in R
 
 Kjetil Halvorsen 
 
 to:
 
 Ben Bolker
 
 12/16/2010 09:13 AM
 
 Sent by:
 
 r-help-boun...@r-project.org
 
 Cc:
 
 r-help
 
 see inline.
 
 On Thu, Dec 16, 2010 at 10:11 AM, Ben Bolker bbol...@gmail.com wrote:
  Alaios alaios at yahoo.com writes:
 
 
  Hello I have two function in R
  like
  g(x)=2x-3
  and s(x)=5x^2+2
 
  and I want to find the integrafl of the g(x)*s(x) inside the 
 interval of [a,b]
 
 
   Analytically or numerically?
   It sounds like you want the answer analytically, in which case R
  can't do it, but it is an easy integral
 
   g(x)*s(x) = 10*x^3-15*x^2+4*x-6
   indefinite integral = 10/3*x^4 -15/3*x^3 + 4/2*x^2 - 6*x + C
   evaluate between a and b
 
   or if you can't do this (although this is a very basic integral)
  you can try it on Wolfram alpha/the Mathematica integrator (google
  for it)
 
 Or a free software alternative: sage
 http://www.sagemath.org/
 
 kjetil
 
 
 
   use ?integrate (surprisingly enough) for 1-D numerical integration
 
  __
  R-help@r-project.org mailing list
  https://stat.ethz.ch/mailman/listinfo/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 about nlminb function

2010-12-15 Thread Jonathan P Daily
How are we supposed to help you if we have no idea how you are using it? 
Did you read the PORT documentation? Did you look at the control 
parameters outlined in the function help page? Often times for me a return 
of the initial conditions is an issue with either inappropriate tolerance 
or having variables on very different scales.

Since you did not follow the posting guide (important part *'d below), my 
only suggestion is to ?nlminb
--
Jonathan P. Daily
Technician - USGS Leetown Science Center
11649 Leetown Road
Kearneysville WV, 25430
(304) 724-4480
Is the room still a room when its empty? Does the room,
 the thing itself have purpose? Or do we, what's the word... imbue it.
 - Jubal Early, Firefly

r-help-boun...@r-project.org wrote on 12/15/2010 08:53:39 AM:

 [image removed] 
 
 [R] Help about nlminb function
 
 kamel gaanoun 
 
 to:
 
 r-help
 
 12/15/2010 08:56 AM
 
 Sent by:
 
 r-help-boun...@r-project.org
 
 Hi Everyone,
 
   Can anyone help me resolve a problem that i'm having with nlminb. The
 problem is that it stops after just one iteration and returns the same
 values as start ones.
 
 
 Thank you very much for your help.
 
 
 Sincerely.
 
 
 -- 
 Kamel Gaanoun
 (+33) (0)6.76.04.65.77
 
[[alternative HTML version deleted]]
 
 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
**
 PLEASE do read the posting guide 
http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.

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

2010-12-15 Thread Jonathan P Daily
Your function is evaluating to Inf. Is this expected behavior? I don't 
know what starting values you are using, but it looks like the initial 
values evaluate to Inf. If this is also true for values near your initial 
conditions then I am not surprised the optimization returns initial 
values.

Try changing parametres[,3]
--
Jonathan P. Daily
Technician - USGS Leetown Science Center
11649 Leetown Road
Kearneysville WV, 25430
(304) 724-4480
Is the room still a room when its empty? Does the room,
 the thing itself have purpose? Or do we, what's the word... imbue it.
 - Jubal Early, Firefly

kamel gaanoun kamel.gaan...@gmail.com wrote on 12/15/2010 09:22:57 AM:

 [image removed] 
 
 Re: [R] Help about nlminb function
 
 kamel gaanoun 
 
 to:
 
 Jonathan P Daily
 
 12/15/2010 09:23 AM
 
 Cc:
 
 r-help, r-help-bounces
 
 I appologize for the lack of information in my previous mail, but it
 is my first one.
 
 Yes  I red -in part- the Port documentation to learn what does the 
 message X-convergence (3) mean.
 
 so this is my nlminb and the results :
 
 res1-nlminb(parametres[,3], V, lower=c(rep(0.01, 18), rep(0.01, 3),
 rep(-Inf, 6)), upper=c(rep(Inf, 18), rep(0.99, 3), rep(Inf, 6)), 
 control = list(maxit=1000) )
 
 
 Results :  res1
 $par
  [1] 1.000 1.000 1.000 1.000 1.000 1.000 
1.000
  [8] 1.000 1.000 1.000 1.000 1.000 1.000 
1.000
 [15] 1.000 1.000 1.000 1.000 0.6899225 0.7993528 
0.6480687
 [22] 0.000 0.000 0.000 0.000 0.000 0.000
 
 $objective
 [1] Inf
 
 $convergence
 [1] 0
 
 $message
 [1] X-convergence (3)
 
 $iterations
 [1] 1
 
 $evaluations
 function gradient 
2   27 
 
 
 So as you see, it stops after just one iteration but it is converging.
 
 
 Thanks

 2010/12/15 Jonathan P Daily jda...@usgs.gov
 How are we supposed to help you if we have no idea how you are using it?
 Did you read the PORT documentation? Did you look at the control
 parameters outlined in the function help page? Often times for me a 
return
 of the initial conditions is an issue with either inappropriate 
tolerance
 or having variables on very different scales.
 
 Since you did not follow the posting guide (important part *'d below), 
my
 only suggestion is to ?nlminb
 --
 Jonathan P. Daily
 Technician - USGS Leetown Science Center
 11649 Leetown Road
 Kearneysville WV, 25430
 (304) 724-4480
 Is the room still a room when its empty? Does the room,
  the thing itself have purpose? Or do we, what's the word... imbue it.
 - Jubal Early, Firefly
 
 r-help-boun...@r-project.org wrote on 12/15/2010 08:53:39 AM:
 
  [image removed]
 
  [R] Help about nlminb function
 
  kamel gaanoun
 
  to:
 
  r-help
 
  12/15/2010 08:56 AM
 
  Sent by:
 
  r-help-boun...@r-project.org
 
  Hi Everyone,
 
Can anyone help me resolve a problem that i'm having with nlminb. 
The
  problem is that it stops after just one iteration and returns the same
  values as start ones.
 
 
  Thank you very much for your help.
 
 
  Sincerely.
 
 
  --
  Kamel Gaanoun
  (+33) (0)6.76.04.65.77
 
 [[alternative HTML version deleted]]
 
  __
  R-help@r-project.org mailing list
  https://stat.ethz.ch/mailman/listinfo/r-help
 
**
  PLEASE do read the posting guide
 http://www.R-project.org/posting-guide.html
  and provide commented, minimal, self-contained, reproducible code.
 
**

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

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


Re: [R] Integration with LaTex and LyX

2010-12-13 Thread Jonathan P Daily
?Sweave

LyX is a bit harder, although you can probably export LyX docs to a *.tex 
and Sweave those fairly painlessly.
--
Jonathan P. Daily
Technician - USGS Leetown Science Center
11649 Leetown Road
Kearneysville WV, 25430
(304) 724-4480
Is the room still a room when its empty? Does the room,
 the thing itself have purpose? Or do we, what's the word... imbue it.
 - Jubal Early, Firefly

r-help-boun...@r-project.org wrote on 12/13/2010 10:27:43 AM:

 [image removed] 
 
 [R] Integration with LaTex and LyX
 
 Eduardo de Oliveira Horta 
 
 to:
 
 r-help
 
 12/13/2010 10:29 AM
 
 Sent by:
 
 r-help-boun...@r-project.org
 
 Hello,
 
 Are there any packages which allow for a good integration between R and
 LaTex / LyX? I'm interested mainly in automatic (automagic?) imports of
 plots/graphics.
 
 Thanks in advance and best regards,
 
 Eduardo de Oliveira Horta
 
[[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] string

2010-12-07 Thread Jonathan P Daily
?paste

collapse = T may be necessary.
--
Jonathan P. Daily
Technician - USGS Leetown Science Center
11649 Leetown Road
Kearneysville WV, 25430
(304) 724-4480
Is the room still a room when its empty? Does the room,
 the thing itself have purpose? Or do we, what's the word... imbue it.
 - Jubal Early, Firefly

r-help-boun...@r-project.org wrote on 12/07/2010 10:11:41 AM:

 [image removed] 
 
 [R] string
 
 Benoit Wastine 
 
 to:
 
 r-help
 
 12/07/2010 10:14 AM
 
 Sent by:
 
 r-help-boun...@r-project.org
 
 Hi,
 
 I'm running R 2.11
 Does anyone know if it possible to transform one character vector to one 

 character string ?
 
 Many thanks
 Benoit
 
 -- 
 Benoit Wastine
 Laboratoire des Sciences du Climat et de l’Environnement (LSCE/IPSL)
 CEA-CNRS-UVSQ
 CE Saclay
 Orme des merisiers
 Bât 703 - Pte 13A
 91191 Gif sur Yvette Cedex
 France
 
 Tel : 33 (0)1 69 08 21 97
 Fax : 33 (0)1 69 08 77 16
 
 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/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] More elegant magnitude method

2010-12-07 Thread Jonathan P Daily
I have a need to find the order of number to get a scaling parameter as a 
power of 10. I have a function that works *so far*, but it is ugly and 
probably buggy. In the interest of avoiding code-based outliers in my 
data, I thought I would ask if anyone here has a better way.

 scl - function(x){
+ length(charToRaw(format(trunc(x), scientific = F)))-1}
 a - 123456789
 b - 1E15
 c -  12.345
 scl(a)
[1] 8
 scl(b)
[1] 15
 scl(c)
[1] 1

Thanks
--
Jonathan P. Daily
Technician - USGS Leetown Science Center
11649 Leetown Road
Kearneysville WV, 25430
(304) 724-4480
Is the room still a room when its empty? Does the room,
 the thing itself have purpose? Or do we, what's the word... imbue it.
 - Jubal Early, Firefly

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


Re: [R] More elegant magnitude method

2010-12-07 Thread Jonathan P Daily
What a brain fart...

Thanks!
--
Jonathan P. Daily
Technician - USGS Leetown Science Center
11649 Leetown Road
Kearneysville WV, 25430
(304) 724-4480
Is the room still a room when its empty? Does the room,
 the thing itself have purpose? Or do we, what's the word... imbue it.
 - Jubal Early, Firefly

David Winsemius dwinsem...@comcast.net wrote on 12/07/2010 02:50:34 PM:

 [image removed] 
 
 Re: [R] More elegant magnitude method
 
 David Winsemius 
 
 to:
 
 Jonathan P Daily
 
 12/07/2010 02:50 PM
 
 Cc:
 
 r-help
 
 
 On Dec 7, 2010, at 2:43 PM, Jonathan P Daily wrote:
 
  I have a need to find the order of number to get a scaling parameter 
  as a
  power of 10. I have a function that works *so far*, but it is ugly and
  probably buggy. In the interest of avoiding code-based outliers in my
  data, I thought I would ask if anyone here has a better way.
 
  scl - function(x){
  + length(charToRaw(format(trunc(x), scientific = F)))-1}
  a - 123456789
  b - 1E15
  c -  12.345
  scl(a)
  [1] 8
  scl(b)
  [1] 15
  scl(c)
  [1] 1
 
 scl- function(x) trunc(log(x,10))
   scl(a)
 [1] 8
  
   scl(b)
 [1] 15
  
   scl(c)
 [1] 1
 
 Seems mathematically clearer.
 -- 
 David Winsemius, MD
 West Hartford, CT


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


Re: [R] Optimize multiple variable sets

2010-12-06 Thread Jonathan P Daily
Correct me if I'm wrong, but isn't the minimal x value in your example the 
same regardless of what positive coefficient you apply to x? If that is 
the case, you would expect the same min(x) for each iteration.

i.e. in the interval [0,1] the minimum x value of x^2 + x is the same as 
x^2 + 1*x, at x = 0.
--
Jonathan P. Daily
Technician - USGS Leetown Science Center
11649 Leetown Road
Kearneysville WV, 25430
(304) 724-4480
Is the room still a room when its empty? Does the room,
 the thing itself have purpose? Or do we, what's the word... imbue it.
 - Jubal Early, Firefly

r-help-boun...@r-project.org wrote on 12/06/2010 07:00:57 AM:

 [image removed] 
 
 [R] Optimize multiple variable sets
 
 sandra lag 
 
 to:
 
 r-help
 
 12/06/2010 08:54 AM
 
 Sent by:
 
 r-help-boun...@r-project.org
 
 
 
 Hi,
 I usually use optimize function for ML Estimation. Now I´ve got a 
 data frame with many sets, but I can´t save estimates each time I 
 run the code for each data set (I´m using a for loop with my 
 loglikelihood function and works ok but when I apply another for loop 
to:
 optimize(my.loglikelihood.function[i], int=c(0.0001,10))
 it doesn´t work;
 
 alternatively, using optimize inside the for loop (like in the 
 example below), it returns always the same value, which is not expected:
 
 data-matrix(c(1,1,1, 2,2,2, 3,3,3, 4,4,4), nrow=3, ncol=4)
 c-dim(data)[2]
 results-vector(length=c)
 for (i in 1:c){
 f-function(x){
 x^2+x*sum(data[,i])
 }
 results[i]-optimize(f,int=c(0.0001,10))[1] #minimum
 }
 #results
 
 Can someone please indicate me if there´s a different function/ way 
 to do so? (with no need of initial parameter values)
 Thanks! Sandra 
 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/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] Optimize multiple variable sets

2010-12-06 Thread Jonathan P Daily
I suppose I should have been more clear. I saw that her interval did not 
include the actual minimum, but I was asking if (and if, why) she was 
expecting the minimum x value to be different for each run. If the y value 
were returned the same on each run that would be puzzling.

As for the returned x issue, you are correct that it is a 'tol' issue: 
reducing tol to something reasonably low approximates the min fairly well.
--
Jonathan P. Daily
Technician - USGS Leetown Science Center
11649 Leetown Road
Kearneysville WV, 25430
(304) 724-4480
Is the room still a room when its empty? Does the room,
 the thing itself have purpose? Or do we, what's the word... imbue it.
 - Jubal Early, Firefly

peter dalgaard pda...@gmail.com wrote on 12/06/2010 09:39:43 AM:

 [image removed] 
 
 Re: [R] Optimize multiple variable sets
 
 peter dalgaard 
 
 to:
 
 Jonathan P Daily
 
 12/06/2010 09:39 AM
 
 Cc:
 
 sandra lag, r-help, r-help-bounces
 
 
 On Dec 6, 2010, at 15:15 , Jonathan P Daily wrote:
 
  Correct me if I'm wrong, but isn't the minimal x value in your example 
the 
  same regardless of what positive coefficient you apply to x? If that 
is 
  the case, you would expect the same min(x) for each iteration.
  
  i.e. in the interval [0,1] the minimum x value of x^2 + x is the same 
as 
  x^2 + 1*x, at x = 0.
 
 You're wrong --- slightly. The returned $minimum is the x, the y is 
 $objective. But the interval given doesn't bracket the minimum, as 
 you'll clearly see if you put int=c(-10,10). The only puzzling bit 
 is that optimize() doesn't actually return the left endpoint, but 
 rather the first evaluation point inside the interval. The rather 
 wide tolerance of .Machine$double.eps^0.25  == 0.0001220703 probably
 plays a role in this.
 
 -- 
 Peter Dalgaard
 Center for Statistics, Copenhagen Business School
 Solbjerg Plads 3, 2000 Frederiksberg, Denmark
 Phone: (+45)38153501
 Email: pd@cbs.dk  Priv: pda...@gmail.com


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


Re: [R] rpart results - problem after oversampling

2010-12-02 Thread Jonathan P Daily
Short answer: Not really.

Slightly longer answer: from what I remember of partitioning methods, a 
given split is made at either a single observation or between two 
consecutive observations. In your case, I estimate rpart would have split 
on that particular point... except that there are 6 of them now. So the 
choice of which 6 to split is arbitrary. (Someone with more knowledge of 
rpart's guts feel free to correct me).
--
Jonathan P. Daily
Technician - USGS Leetown Science Center
11649 Leetown Road
Kearneysville WV, 25430
(304) 724-4480
Is the room still a room when its empty? Does the room,
 the thing itself have purpose? Or do we, what's the word... imbue it.
 - Jubal Early, Firefly

r-help-boun...@r-project.org wrote on 12/02/2010 05:34:23 AM:

 [image removed] 
 
 [R] rpart results - problem after oversampling
 
 Mederos, Vicente (Santander) 
 
 to:
 
 r-help@r-project.org
 
 12/02/2010 05:36 AM
 
 Sent by:
 
 r-help-boun...@r-project.org
 
 Hi all,
 
 I am trying to predict a target variable that takes values 0 or 1 
 using the rpart command. In my initial dataset I have few positive 
 observations of the target variable; therefore I have oversampled 
 the rare event by a multiple of 6 (i.e. from 762 to 4572).
 
 However, in my results, I end up with a number of positives in one 
 of the terminal nodes that is not divisible by 6. As I have the same
 observation repeated 6 times, shouldn't all of them follow the same 
 branch of the tree and go to the same terminal node?
 
 Thanks for your help,
 
 Vicente
 Emails aren't always secure, and they may be intercepted or changed
 after they've been sent. Santander doesn't accept liability if this
 happens. If you think someone may have interfered with this email,
 please get in touch with the sender another way. This message doesn't
 create or change any contract. Santander doesn't accept responsibility
 for damage caused by any viruses contained in this email or its
 attachments. Emails may be monitored. If you've received this email by
 mistake, please let the sender know at once that it's gone to the wrong
 person and then destroy it without copying, using, or telling anyone
 about its contents. Santander UK plc (SAN UK) Reg. No. 2294747 and Abbey
 National Treasury Services plc (ANTS) Reg. No. 2338548 are registered in
 England and have their Registered Offices at 2 Triton Square, Regent's
 Place, London, NW1 3AN. www.santander.co.uk SAN UK and ANTS are
 authorised and regulated by the Financial Services Authority (Reg. No.
 106054 and 146003 respectively). SAN UK advises on mortgages, a limited
 range of life assurance, pension and collective investment scheme
 products and acts as an insurance intermediary for general insurance.
 Santander and the flame logo are registered trademarks.
 Ref:[PDB#1-4]
 
[[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] Sequence for repeated numbers

2010-12-01 Thread Jonathan P Daily
Try this:

 ord - order(grade)
 ID - Id[ord]
 grade - grade[ord]
 sequence - unlist(sapply(table(grade), FUN = function(x) 1:x), 
use.names = F)

And as a general tip, it is much easier to work with related values like 
ID and grade if they are in a data frame. Such as:

 dat - data.frame(ID, grade)
 dat - dat[order(grade),]

--
Jonathan P. Daily
Technician - USGS Leetown Science Center
11649 Leetown Road
Kearneysville WV, 25430
(304) 724-4480
Is the room still a room when its empty? Does the room,
 the thing itself have purpose? Or do we, what's the word... imbue it.
 - Jubal Early, Firefly

r-help-boun...@r-project.org wrote on 12/01/2010 11:08:06 AM:

 [image removed] 
 
 [R] Sequence for repeated numbers
 
 Luana Marotta 
 
 to:
 
 r-help, r-help-request
 
 12/01/2010 11:09 AM
 
 Sent by:
 
 r-help-boun...@r-project.org
 
 Hello fellows,
 
 I would like to create a sequence for repeated numbers in a dataset. For
 example:
 
 ID - c(1:20)
 grade - c(4,4,4,5,5,7,7,7,7,8,8,8,9,9,9,9,9,10,10,10)
 
 Data:
 
 ID  Grade
 1   4
 2   4
 3   4
 4   5
 5   5
 6   7
 7   7
 8   7
 9   7
 (...)
 
 I would like to create a variable sequence:
 
 Data:
 ID GradeSequence:
 1   4  1
 2   4  2
 3   4  3
 4   5  1
 5   5  2
 6   7  1
 7   7  2
 8   7  3
 9   7  4
 
 Any help is very much appreciate!
 
 Thank you,
 
 Luana Marotta
 
[[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] Two dimensional Array defined on intevals

2010-11-29 Thread Jonathan P Daily
Does this work for you?

g - function(x,y) ifelse(x  .5, 0, 2) + ifelse(y  .5, 1, 2)

--
Jonathan P. Daily
Technician - USGS Leetown Science Center
11649 Leetown Road
Kearneysville WV, 25430
(304) 724-4480
Is the room still a room when its empty? Does the room,
 the thing itself have purpose? Or do we, what's the word... imbue it.
 - Jubal Early, Firefly

r-help-boun...@r-project.org wrote on 11/29/2010 11:37:41 AM:

 [image removed] 
 
 [R] Two dimensional Array defined on intevals
 
 Leon Adams 
 
 to:
 
 r-help
 
 11/29/2010 11:39 AM
 
 Sent by:
 
 r-help-boun...@r-project.org
 
 Hi I am new to R and am trying to set up a two-dimensional array/matrix 
with
 the elements defined by the function similar to below. Been trying to 
use
 outer with apply but can't seem to get the indexing quite right. Is 
their a
 simple way of accomplishing this task ??
 
   -
 /
| 1  x  0.5  y  0.5
|
   /  2  x  0.5  y  0.5
 /
 G(x,y) =   \
  \
  |   3  x  0.5  y  0.5
  |
  \   4  x  0.5  y  0.5
-
 -- 
 Thanks in advance
 Leon Adams
 
[[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] Population abundance, change point

2010-11-24 Thread Jonathan P Daily
I agree that SiZer is not the ultimate answer to all changepoint analysis, 
but that is why there are so many changepoint detection methods used. I 
will clarify, though, that my understanding of SiZer (which may be wrong) 
was that the smoothing splines are just a vessel for finding the 
changepoints, and made no assumptions about the continuity of the 
changepoint itself.

One thing that would certainly help, especially with the confidence 
intervals about 0, is some bandwidth selection standard, though choosing 
that standard would be a difficult process to say the least.
--
Jonathan P. Daily
Technician - USGS Leetown Science Center
11649 Leetown Road
Kearneysville WV, 25430
(304) 724-4480
Is the room still a room when its empty? Does the room,
 the thing itself have purpose? Or do we, what's the word... imbue it.
 - Jubal Early, Firefly

Gavin Simpson gavin.simp...@ucl.ac.uk wrote on 11/24/2010 09:15:55 AM:

 [image removed] 
 
 Re: [R] Population abundance, change point
 
 Gavin Simpson 
 
 to:
 
 Jonathan P Daily
 
 11/24/2010 09:16 AM
 
 Cc:
 
 Mike Marchywka, r-help, r-help-bounces, carusonm
 
 Please respond to gavin.simpson
 
 On Wed, 2010-11-17 at 09:17 -0500, Jonathan P Daily wrote:
  Indeed I have looked into various non-standard changepoint analysis 
  methods. I figured the OP was more interested in traditional methods 
since 
  you have to spend less time justifying your methodology. Wavelets are 
one 
  potential nontraditional method, as is Significant Zero Crossings (R 
  package SiZer), which fits arbitrary-degree smoothing splines over a 
range 
  of bandwidth parameters and looks for changes.
 
 ...By looking to see if the derivative of the fitted curve is different
 from 0 (given a suitable confidence interval on the derivative. My
 problem with all of this is that these data are time series and SiZeR
 doesn't take this into account (AFAICS) when computing the confidence
 intervals - they are certainly too narrow for examples I have run.
 
 Also, if these things are using splines, aren't we already assuming that
 the underlying function is smooth and not a discontinuity? So which
 technique the OP chooses will depend on how they think about the type of
 change taking place at the changepoint - a point I think you made
 earlier Jonathan.
 
 Don't mean to be too negative, this has been a very useful discussion
 that I am coming to late after a spot of time in the field.
 
 All the best,
 
 G
 
   With large communities of 
  abundance counts, another approach that is gaining popularity is the 
  community-level indicator taxa analysis (TITAN), though that is not 
useful 
  to the OP. 
  --
  Jonathan P. Daily
  Technician - USGS Leetown Science Center
  11649 Leetown Road
  Kearneysville WV, 25430
  (304) 724-4480
  Is the room still a room when its empty? Does the room,
   the thing itself have purpose? Or do we, what's the word... imbue 
it.
   - Jubal Early, Firefly
  
  Mike Marchywka marchy...@hotmail.com wrote on 11/17/2010 09:11:11 
AM:
  
   [image removed] 
   
   RE: [R] Population abundance, change point
   
   Mike Marchywka 
   
   to:
   
   jdaily, carusonm
   
   11/17/2010 09:11 AM
   
   Cc:
   
   r-help, r-help-bounces
   
   
   
   
   
To: carus...@gmail.com
From: jda...@usgs.gov
Date: Wed, 17 Nov 2010 08:45:01 -0500
CC: r-help@r-project.org; r-help-boun...@r-project.org
Subject: Re: [R] Population abundance, change point
   
There are really no set ways to determine a changepoint, since a
changepoint depends completely on what you decide. Recursive 
  partitioning
will fit a best changepoint, but it will pretty much always fit 
one. 
  This
   If you are open to newer ideas,
   have you looked at wavelets at all? these come up on googel along 
with 
  R.
   Also with aonly a few points, even 20-30, you coldconsider 
exhasiutvely
   fitting slopes to all 2^n subsets and plowing throgh the histograms
   looking for anything that may be publishable or illuminating about 
your 
  data.
   Fitting to your own model or null hypotheses would make interesting
   contrasts of course,  populations remained the same after atrazine 
  spill
   or asteroid hit etc.
   
   
function can be found in the package rpart:
   
 fit - rpart(count ~ year, control = list(maxdepth = 1))
 summary(fit)
   
However this measure offers no level of confidence. This is where 
  packages
like strucchange and party come into use, as they provide measures 
of
confidence. Alternatively, you could look into regression-based 
  methods
where the changepoint is some parameter. Piecewise regression, for
instance, is as simple as fitting a spline of degree 1 and 
changepoint 
  X:
   
 library(splines)
 fit - lm(count ~ bs(year, knots = X, degree = 1))
 plot(year, count)
 lines(year, fitted(fit))
   
Then you can fit a regression at each

Re: [R] Population abundance, change point

2010-11-24 Thread Jonathan P Daily
I understand that smoothing splines produce continuous models, however the 
end product of SiZer is not a single model that is then used in any 
predictive manner. Rather, the end product is a map of potential 
changepoint locations along a gradient. Are you suggesting that SiZer 
would not find a changepoint at the Aswan Dam? If so, I would argue 
against that conclusion. If your point is that pulling one underlying 
spline model used to create a SiZer map out and trying to draw conclusions 
from that model is ineffective, you are absolutely right. I tend to think 
of SiZer outputs more akin to tree outputs than piecewise regression 
outputs.
--
Jonathan P. Daily
Technician - USGS Leetown Science Center
11649 Leetown Road
Kearneysville WV, 25430
(304) 724-4480
Is the room still a room when its empty? Does the room,
 the thing itself have purpose? Or do we, what's the word... imbue it.
 - Jubal Early, Firefly

Gavin Simpson gavin.simp...@ucl.ac.uk wrote on 11/24/2010 12:09:15 PM:

 [image removed] 
 
 Re: [R] Population abundance, change point
 
 Gavin Simpson 
 
 to:
 
 Jonathan P Daily
 
 11/24/2010 12:09 PM
 
 Cc:
 
 r-help, carusonm
 
 Please respond to gavin.simpson
 
 On Wed, 2010-11-24 at 10:59 -0500, Jonathan P Daily wrote:
  I agree that SiZer is not the ultimate answer to all changepoint 
analysis, 
  but that is why there are so many changepoint detection methods used. 
I 
  will clarify, though, that my understanding of SiZer (which may be 
wrong) 
  was that the smoothing splines are just a vessel for finding the 
  changepoints, and made no assumptions about the continuity of the 
  changepoint itself.
 
 But by the nature of using splines, they *you) are positing a model for
 what the changepoint looks like. If you model the classic Nile data with
 a spline model (say using gam()) then it will suggest that there was a
 smooth transition from high flow before the dam at Aswan was built to
 lower flow afterwards. Other techniques that posit a discontinuity as a
 changepoint would fit two, effectively flat [slope 0], linear lines
 either side of the point when the dam was built.
 
 If you didn't know a dam was built and all you fitted was a spline to
 the data, that would likely influence how you interpreted the change.
 
  One thing that would certainly help, especially with the confidence 
  intervals about 0, is some bandwidth selection standard, though 
choosing 
  that standard would be a difficult process to say the least.
 
 That won't help with the lack of independence in the residuals, which
 will result in deflated CI on the derivatives, hence more wiggles seem
 significant... Oh the joy.
 
 Also, there has to be a point where with siZer you are just looking at
 pattern in noise at the small bandwidth end of things...
 
 I'll get off my soap box about now! ;-)
 
 Cheers,
 
 G
 
  --
  Jonathan P. Daily
  Technician - USGS Leetown Science Center
  11649 Leetown Road
  Kearneysville WV, 25430
  (304) 724-4480
  Is the room still a room when its empty? Does the room,
   the thing itself have purpose? Or do we, what's the word... imbue 
it.
   - Jubal Early, Firefly
  
  Gavin Simpson gavin.simp...@ucl.ac.uk wrote on 11/24/2010 09:15:55 
AM:
  
   [image removed] 
   
   Re: [R] Population abundance, change point
   
   Gavin Simpson 
   
   to:
   
   Jonathan P Daily
   
   11/24/2010 09:16 AM
   
   Cc:
   
   Mike Marchywka, r-help, r-help-bounces, carusonm
   
   Please respond to gavin.simpson
   
   On Wed, 2010-11-17 at 09:17 -0500, Jonathan P Daily wrote:
Indeed I have looked into various non-standard changepoint 
analysis 
methods. I figured the OP was more interested in traditional 
methods 
  since 
you have to spend less time justifying your methodology. Wavelets 
are 
  one 
potential nontraditional method, as is Significant Zero Crossings 
(R 
package SiZer), which fits arbitrary-degree smoothing splines over 
a 
  range 
of bandwidth parameters and looks for changes.
   
   ...By looking to see if the derivative of the fitted curve is 
different
   from 0 (given a suitable confidence interval on the derivative. My
   problem with all of this is that these data are time series and 
SiZeR
   doesn't take this into account (AFAICS) when computing the 
confidence
   intervals - they are certainly too narrow for examples I have run.
   
   Also, if these things are using splines, aren't we already assuming 
that
   the underlying function is smooth and not a discontinuity? So which
   technique the OP chooses will depend on how they think about the 
type of
   change taking place at the changepoint - a point I think you made
   earlier Jonathan.
   
   Don't mean to be too negative, this has been a very useful 
discussion
   that I am coming to late after a spot of time in the field.
   
   All the best,
   
   G
   
 With large communities of 
abundance counts

Re: [R] Check for is.object

2010-11-22 Thread Jonathan P Daily
I think you want the function ?exists

if(!exists(NewObject))

--
Jonathan P. Daily
Technician - USGS Leetown Science Center
11649 Leetown Road
Kearneysville WV, 25430
(304) 724-4480
Is the room still a room when its empty? Does the room,
 the thing itself have purpose? Or do we, what's the word... imbue it.
 - Jubal Early, Firefly

r-help-boun...@r-project.org wrote on 11/22/2010 10:14:51 AM:

 [image removed] 
 
 [R] Check for is.object
 
 Santosh Srinivas 
 
 to:
 
 r-help
 
 11/22/2010 10:17 AM
 
 Sent by:
 
 r-help-boun...@r-project.org
 
 Hello,
 
 I am trying to recursively append some data from multiple files into a
 common object
 
 For this, I am using in a loop
 
 NewObject - rbind(NewObject,tempObject)
 
 
 For the first loop, obviously there is no NewObject ... so I wanted to 
do
 NewObject - tempObject[0,]
 
 Now when it loops again I want to put the statement do NewObject -
 tempObject[0,] inside a if statement ... so that it does I can skip it 
once
 NewObject has been initialized.
 
 But, is.object doesn't seem to work. 
 
 What is the alternative check that I can do? And is there a better way 
to
 achieve what I want?
 
 Thanks,
 S
 
 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide 
http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.

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


Re: [R] question about constraint minimization

2010-11-19 Thread Jonathan P Daily
Does ?constrOptim look as though it will handle your needs?
--
Jonathan P. Daily
Technician - USGS Leetown Science Center
11649 Leetown Road
Kearneysville WV, 25430
(304) 724-4480
Is the room still a room when its empty? Does the room,
 the thing itself have purpose? Or do we, what's the word... imbue it.
 - Jubal Early, Firefly

r-help-boun...@r-project.org wrote on 11/19/2010 02:51:46 PM:

 [image removed] 
 
 [R] question about constraint minimization
 
 dhacade...@gmail.com 
 
 to:
 
 r-help
 
 11/19/2010 03:15 PM
 
 Sent by:
 
 r-help-boun...@r-project.org
 
 
 Hi, 
 
 I am a beginner of R. There is a question about constraint minimization. 
A
 function, y=f(x1,x2,x3x12), needs to be minimized. There are 3
 requirements for the minimization: 
 
 (1) x2+x3+...+x12=1.5 (x1 is excluded);
 (2) x1=x3=x4;
 (3) x1, x3 and x5 are in the range of -1~0, respectively. The rest 
variables
 (x2, x4, x6, x7, , x12) are in the range of 0~1, respectively.
 
 The optim function is used. And part of my input is as follow, where
 xx1r represents the x12:
 
 xx1r=1.5-x[2]-x[1]-x[1]-x[3]-x[4]-x[5]-x[6]-x[7]-x[8]-x[9]
 start=rnorm(9)
 up=1:9/1:9*1
 lo=1:9/1:9*-1
 out=optim(start,f,lower=lo,upper=up,method=L-BFGS-B,hessian=TRUE,
 control=list(trace=6,maxit=1000))
 
 There are two problems in this input. the up and lo only define a 
range
 of -1~1 for x1 to x11, which can not meet the requirement (3). In 
addition,
 there is not any constraint imposed on x12. I have no idea how to 
specify a
 matrix that can impose different constraints on individual variables in 
a
 function. Any suggestion is highly appreciated.
 
 Best,
 Hao
 
 
 -- 
 View this message in context: http://r.789695.n4.nabble.com/
 question-about-constraint-minimization-tp3050880p3050880.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] predict() an rpart() model: how to ignore missing levels in a factor

2010-11-18 Thread Jonathan P Daily
I don't think that, considering the mechanism behind recursive 
partitioning, that there is any way for you to ignore the crop factor if 
it is not in the original test set. What decision should be made if, for 
instance, the next split in a decision tree were on crops and output was 5 
for apples, 6 for bananas, and you had an instance of jicamas? It can't 
ignore the crop factor at that point since the next decision hinges on it.

What I think you can do, however, is pre-trim your test set by testing 
whether each factor is present in the first set with something like 
(UNTESTED):

 test.set - test.set[test.set$crop %in% original.set$crop,]
--
Jonathan P. Daily
Technician - USGS Leetown Science Center
11649 Leetown Road
Kearneysville WV, 25430
(304) 724-4480
Is the room still a room when its empty? Does the room,
 the thing itself have purpose? Or do we, what's the word... imbue it.
 - Jubal Early, Firefly

r-help-boun...@r-project.org wrote on 11/18/2010 12:35:41 PM:

 [image removed] 
 
 [R] predict() an rpart() model: how to ignore missing levels in a factor
 
 jamessc 
 
 to:
 
 r-help
 
 11/18/2010 12:37 PM
 
 Sent by:
 
 r-help-boun...@r-project.org
 
 
 I am using an algorigm to split my data set into two random sections
 repeatedly and constuct a model using rpart() on one, test on the other 
and
 average out the results.
 
 One of my variables is a factor(crop) where each crop type has a code. 
Some
 crop types occur infrequently or singly. when the data set is randomly
 split, it may be that the first data set has a crop type which is not
 present in the second and so using predict() I get the error:
 
 Error in model.frame.default(Terms, newdata, na.action = na.action, xlev 
=
 attr(object,  : 
   factor 'factor(c2001)' has new level(s) 13, 24, 35
 
 where c2001 is the crop. I would like the predict function to ignore 
these
 records. is there a command which will allow this as part of the 
predict()
 function? With those with a small number of records (eg. 3-4), I would 
hope
 some of the models would have the right balance to allow a prediction to 
be
 made.
 -- 
 View this message in context: http://r.789695.n4.nabble.com/predict-
 
an-rpart-model-how-to-ignore-missing-levels-in-a-factor-tp3049218p3049218.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] Population abundance, change point

2010-11-17 Thread Jonathan P Daily
There are really no set ways to determine a changepoint, since a 
changepoint depends completely on what you decide. Recursive partitioning 
will fit a best changepoint, but it will pretty much always fit one. This 
function can be found in the package rpart:

 fit - rpart(count ~ year, control = list(maxdepth = 1))
 summary(fit)

However this measure offers no level of confidence. This is where packages 
like strucchange and party come into use, as they provide measures of 
confidence. Alternatively, you could look into regression-based methods 
where the changepoint is some parameter. Piecewise regression, for 
instance, is as simple as fitting a spline of degree 1 and changepoint X:

 library(splines)
 fit - lm(count ~ bs(year, knots = X, degree = 1))
 plot(year, count)
 lines(year, fitted(fit))

Then you can fit a regression at each year and compare. Alternatively, 
since count data is often noisy, you could easily substitute quantile 
regression for linear regression to much of the same effect (assuming 
whatever tau you decide, I used 0.8 but this is arbitrary):

 library(splines)
 library(quantreg)
 fit - rq(count ~ bs(year, knots = X, degree = 1), tau = 0.8)
 plot(year, count)
 lines(year, fitted(fit))
--
Jonathan P. Daily
Technician - USGS Leetown Science Center
11649 Leetown Road
Kearneysville WV, 25430
(304) 724-4480
Is the room still a room when its empty? Does the room,
 the thing itself have purpose? Or do we, what's the word... imbue it.
 - Jubal Early, Firefly

r-help-boun...@r-project.org wrote on 11/16/2010 05:30:49 PM:

 [image removed] 
 
 [R] Population abundance, change point
 
 Nicholas M. Caruso 
 
 to:
 
 r-help
 
 11/16/2010 05:32 PM
 
 Sent by:
 
 r-help-boun...@r-project.org
 
 I am trying to understand my population abundance data and am looking 
into
 analyses of change point to try and determine, at approximately what 
point
 do populations begin to change (either decline or increasing).
 
 Can anyone offer suggestions on ways to go about this?
 
 I have looked into bcp and strucchange packages but am not completely
 convinced that these are appropriate for my data.
 
 Here is an example of what type of data I have
 Year of survey (continuous variable) 1960 - 2009 (there are gaps in the
 surveys (e.g., there were no surveys from 2002-2004)
 Relative abundance of salamanders during the survey periods
 
 
 Thanks for your help, Nick
 
 -- 
 Nicholas M Caruso
 Graduate Student
 CLFS-Biology
 4219 Biology-Psychology Building
 University of Maryland, College Park, MD 20742-5815
 
 
 
 
 --
 I learned something of myself in the woods today,
 and walked out pleased for having made the acquaintance.
 
[[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] Population abundance, change point

2010-11-17 Thread Jonathan P Daily
Indeed I have looked into various non-standard changepoint analysis 
methods. I figured the OP was more interested in traditional methods since 
you have to spend less time justifying your methodology. Wavelets are one 
potential nontraditional method, as is Significant Zero Crossings (R 
package SiZer), which fits arbitrary-degree smoothing splines over a range 
of bandwidth parameters and looks for changes. With large communities of 
abundance counts, another approach that is gaining popularity is the 
community-level indicator taxa analysis (TITAN), though that is not useful 
to the OP. 
--
Jonathan P. Daily
Technician - USGS Leetown Science Center
11649 Leetown Road
Kearneysville WV, 25430
(304) 724-4480
Is the room still a room when its empty? Does the room,
 the thing itself have purpose? Or do we, what's the word... imbue it.
 - Jubal Early, Firefly

Mike Marchywka marchy...@hotmail.com wrote on 11/17/2010 09:11:11 AM:

 [image removed] 
 
 RE: [R] Population abundance, change point
 
 Mike Marchywka 
 
 to:
 
 jdaily, carusonm
 
 11/17/2010 09:11 AM
 
 Cc:
 
 r-help, r-help-bounces
 
 
 
 
 
  To: carus...@gmail.com
  From: jda...@usgs.gov
  Date: Wed, 17 Nov 2010 08:45:01 -0500
  CC: r-help@r-project.org; r-help-boun...@r-project.org
  Subject: Re: [R] Population abundance, change point
 
  There are really no set ways to determine a changepoint, since a
  changepoint depends completely on what you decide. Recursive 
partitioning
  will fit a best changepoint, but it will pretty much always fit one. 
This
 If you are open to newer ideas,
 have you looked at wavelets at all? these come up on googel along with 
R.
 Also with aonly a few points, even 20-30, you coldconsider exhasiutvely
 fitting slopes to all 2^n subsets and plowing throgh the histograms
 looking for anything that may be publishable or illuminating about your 
data.
 Fitting to your own model or null hypotheses would make interesting
 contrasts of course,  populations remained the same after atrazine 
spill
 or asteroid hit etc.
 
 
  function can be found in the package rpart:
 
   fit - rpart(count ~ year, control = list(maxdepth = 1))
   summary(fit)
 
  However this measure offers no level of confidence. This is where 
packages
  like strucchange and party come into use, as they provide measures of
  confidence. Alternatively, you could look into regression-based 
methods
  where the changepoint is some parameter. Piecewise regression, for
  instance, is as simple as fitting a spline of degree 1 and changepoint 
X:
 
   library(splines)
   fit - lm(count ~ bs(year, knots = X, degree = 1))
   plot(year, count)
   lines(year, fitted(fit))
 
  Then you can fit a regression at each year and compare. Alternatively,
  since count data is often noisy, you could easily substitute quantile
  regression for linear regression to much of the same effect (assuming
  whatever tau you decide, I used 0.8 but this is arbitrary):
 
   library(splines)
   library(quantreg)
   fit - rq(count ~ bs(year, knots = X, degree = 1), tau = 0.8)
   plot(year, count)
   lines(year, fitted(fit))
  --
  Jonathan P. Daily
  Technician - USGS Leetown Science Center
  11649 Leetown Road
  Kearneysville WV, 25430
  (304) 724-4480
  Is the room still a room when its empty? Does the room,
  the thing itself have purpose? Or do we, what's the word... imbue it.
  - Jubal Early, Firefly
 
  r-help-boun...@r-project.org wrote on 11/16/2010 05:30:49 PM:
 
   [image removed]
  
   [R] Population abundance, change point
  
   Nicholas M. Caruso
  
   to:
  
   r-help
  
   11/16/2010 05:32 PM
  
   Sent by:
  
   r-help-boun...@r-project.org
  
   I am trying to understand my population abundance data and am 
looking
  into
   analyses of change point to try and determine, at approximately what
  point
   do populations begin to change (either decline or increasing).
  
   Can anyone offer suggestions on ways to go about this?
  
   I have looked into bcp and strucchange packages but am not 
completely
   convinced that these are appropriate for my data.
  
   Here is an example of what type of data I have
   Year of survey (continuous variable) 1960 - 2009 (there are gaps in 
the
   surveys (e.g., there were no surveys from 2002-2004)
   Relative abundance of salamanders during the survey periods
  
  
   Thanks for your help, Nick
  
   --
   Nicholas M Caruso
   Graduate Student
   CLFS-Biology
   4219 Biology-Psychology Building
   University of Maryland, College Park, MD 20742-5815
  
  
  
  
   --
   I learned something of myself in the woods today,
   and walked out pleased for having made the acquaintance.
  
   [[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

Re: [R] help on IDE

2010-11-17 Thread Jonathan P Daily
Each IDE is going to have its own setup that will also usually depend on 
what type of computer you are running. EMACS, for instance, requires a 
pre-existing R install with the 'ess' package (packages are usually 
installed inside R). Geany, on the other hand, requires an R install and, 
in some cases, a custom Run command.

Linux systems also often ship language specific IDEs with dependency 
checks on R, but not always.
--
Jonathan P. Daily
Technician - USGS Leetown Science Center
11649 Leetown Road
Kearneysville WV, 25430
(304) 724-4480
Is the room still a room when its empty? Does the room,
 the thing itself have purpose? Or do we, what's the word... imbue it.
 - Jubal Early, Firefly

r-help-boun...@r-project.org wrote on 11/17/2010 01:41:39 PM:

 [image removed] 
 
 [R] help on IDE
 
 Partha Sinha 
 
 to:
 
 r-help
 
 11/17/2010 01:50 PM
 
 Sent by:
 
 r-help-boun...@r-project.org
 
 I am new comer in R.There r few IDE like Tinn R,VIM etc.I mean How to
 use them? Do I need to install R and then install them to use or they
 can work alone? Also does one install packages on R or IDEs? Can I
 call/use the package from IDEs?
 regards
 Parth
 
 -- 
 Socrates, proclaimed: I came to know one thing; that I know nothing.
 
 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/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] Anyone can help with this question

2010-11-16 Thread Jonathan P Daily
assuming your data takes the form of

locationlatitudelongitude
string  num num
string2 num num

try:

sub - dat[sample.int(length(dat$location), 1000),]
--
Jonathan P. Daily
Technician - USGS Leetown Science Center
11649 Leetown Road
Kearneysville WV, 25430
(304) 724-4480
Is the room still a room when its empty? Does the room,
 the thing itself have purpose? Or do we, what's the word... imbue it.
 - Jubal Early, Firefly

r-help-boun...@r-project.org wrote on 11/16/2010 12:13:57 PM:

 [image removed] 
 
 [R] Anyone can help with this question
 
 Mariana 
 
 to:
 
 r-help
 
 11/16/2010 02:22 PM
 
 Sent by:
 
 r-help-boun...@r-project.org
 
 
 Hi there:
 I am a total beginner in R, and I have a simple question:
 I have a table with thousands of lines that represent locations, and two
 columns: latitude and longitude. I need to randomly sample 1000 lines. 
How
 do I do it? I know the command sample, but it samples elements
 independently, not lines. 
 If there is a better place for me to ask that type of question, please 
let
 me know.
 Thanks a lot,
 Mariana (from Brazil)
 
 -- 
 View this message in context: http://r.789695.n4.nabble.com/Anyone-
 can-help-with-this-question-tp3045265p3045265.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] Null values in R

2010-11-15 Thread Jonathan P Daily
Would ?is.null be what you are looking for?
--
Jonathan P. Daily
Technician - USGS Leetown Science Center
11649 Leetown Road
Kearneysville WV, 25430
(304) 724-4480
Is the room still a room when its empty? Does the room,
 the thing itself have purpose? Or do we, what's the word... imbue it.
 - Jubal Early, Firefly



From:
Raji raji.sanka...@gmail.com
To:
r-help@r-project.org
Date:
11/15/2010 09:58 AM
Subject:
[R] Null values in R
Sent by:
r-help-boun...@r-project.org




Hi R-helpers , can you please let me know the methods in which NULL values
can be handled in R? Are there any generic commands/functions that can be
given in a workspace,so that the NULL values occuring in that workspace 
(for
any datasets that are loaded , any output that is calculated) , are
considered in the same way?

Thanks in advance.
-- 
View this message in context: 
http://r.789695.n4.nabble.com/Null-values-in-R-tp3043184p3043184.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] external R scripts

2010-11-10 Thread Jonathan P Daily
It would be possible to call other R scripts using calls to ?system or 
?system2 and ?Rscript, provided you formatted what you passed as [args] 
and how your scripts handled [args].
--
Jonathan P. Daily
Technician - USGS Leetown Science Center
11649 Leetown Road
Kearneysville WV, 25430
(304) 724-4480
Is the room still a room when its empty? Does the room,
 the thing itself have purpose? Or do we, what's the word... imbue it.
 - Jubal Early, Firefly



From:
Maas James Dr (MED) j.m...@uea.ac.uk
To:
r-help@r-project.org r-help@r-project.org
Date:
11/10/2010 08:42 AM
Subject:
[R] external R scripts
Sent by:
r-help-boun...@r-project.org



Is it possible to send data from an executing R script, to external R 
script files, on linux in this case, get that external R script to 
execute, and pass results back to the central script?  If so what commands 
should I be looking at?  I've googled for R and external, stuff like that 
but no luck.

The reason for the question is that I need to generate simulation data, 
then perform several different analyses on the same data set, then collate 
the results.  All individual analyses can be done sequentially, or perhaps 
more quickly by doing the individual analyses simultaneously if I pass 
them to external functions.

Thanks

J

===
Dr. Jim Maas
University of East Anglia


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

2010-11-10 Thread Jonathan P Daily
I know the default plot() method expects dat$x and dat$y to exist and be 
equal if you simply try

 plot(dat)

Try looking at
 methods(plot)
to see if there is a specified method from maptools,
then check documentation on ?plot.methodfrommaptools

Otherwise, check spb for $x and $y objects.
--
Jonathan P. Daily
Technician - USGS Leetown Science Center
11649 Leetown Road
Kearneysville WV, 25430
(304) 724-4480
Is the room still a room when its empty? Does the room,
 the thing itself have purpose? Or do we, what's the word... imbue it.
 - Jubal Early, Firefly



From:
Aleksandr Andreev aleksandr.andr...@gmail.com
To:
r-help@r-project.org
Date:
11/10/2010 01:10 PM
Subject:
[R] maptools package
Sent by:
r-help-boun...@r-project.org



A few years back, I wrote some code to plot maps with the maptools
package. Now I am trying to reproduce my results, only to find out
that maptools has been updated and my code no longer works.

I've been able to fix the first part of it by forcing
spb - maptools:::read.shape(/home/sasha/Documents/maps/spb.shp)

(as read.shape has been deprecated)

but now when I do
plot(spb, xlab=Longitude, ylab=Latitude, main=Map of St
Petersburg, Russia)

I get the message
Error in xy.coords(x, y, xlabel, ylabel, log) :
  'x' is a list, but does not have components 'x' and 'y'

What's the new syntax that I'm supposed to use?

I'm using R version 2.12.0 (2010-10-15) on x86_64-pc-linux-gnu (64-bit)

Thanks,


Aleksandr Andreev
Graduate Student - Department of Economics
University of North Carolina at Chapel Hill
Mobile: +1 303 507 93 88
Skype: typiconman

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

2010-11-08 Thread Jonathan P Daily
Use set.seed()
--
Jonathan P. Daily
Technician - USGS Leetown Science Center
11649 Leetown Road
Kearneysville WV, 25430
(304) 724-4480
Is the room still a room when its empty? Does the room,
 the thing itself have purpose? Or do we, what's the word... imbue it.
 - Jubal Early, Firefly



From:
Xiaoxi Gao rhel...@hotmail.com
To:
R Help r-help@r-project.org
Date:
11/08/2010 03:59 PM
Subject:
[R] Random Sample
Sent by:
r-help-boun...@r-project.org




Hello R users,
Here is my question about generating random sample. How to set the random 
seed to recreate the same random numbers?  For example, 10 random numbers 
is generated from N(0,1), then runif(10) is used.What if I want to get 
the same 10 random numbers when I run runif(10) again? Is it possible?I 
think .Random.seed should be used here.
Thanks.
Xiaoxi  
 [[alternative HTML version deleted]]

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



[[alternative HTML version deleted]]

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


Re: [R] improve R memory under linux

2010-11-05 Thread Jonathan P Daily
A very small script should fit just fine in an email: what are you 
trying to do?

Likely, you are assigning many small variables in some loop. Even if you 
have 4GB of RAM available, if R assigns 3.99 GB of it and then then a call 
comes in to assign something of size .02, it will tell you it can't 
allocate an object of size .02.
--
Jonathan P. Daily
Technician - USGS Leetown Science Center
11649 Leetown Road
Kearneysville WV, 25430
(304) 724-4480
Is the room still a room when its empty? Does the room,
 the thing itself have purpose? Or do we, what's the word... imbue it.
 - Jubal Early, Firefly



From:
ricardo souza ricsouz...@yahoo.com.br
To:
r-help@r-project.org
Date:
11/05/2010 11:29 AM
Subject:
[R] improve R memory under linux
Sent by:
r-help-boun...@r-project.org



Dear all,

I am using ubuntu linux 32 with 4 Gb.  I am running a very small script 
and I always got the same error message:  CAN NOT ALLOCATE A VECTOR OF 
SIZE 231.8 Mb.

I have reading carefully the instruction in ?Memory.  Using the function 
gc() I got very low numbers of memory (please sea below).  I know that it 
has been posted several times at r-help (
http://tolstoy.newcastle.edu.au/R/help/05/06/7565.html#7627qlink2).  
However I did not find yet the solution to improve my memory issue in 
Linux.  Somebody cold please give some instruction how to improve my 
memory under linux? 

 gc()
 used (Mb) gc trigger (Mb) max used (Mb)
Ncells 170934  4.6 35  9.4   35  9.4
Vcells 195920  1.5 786432  6.0   781384  6.0

INCREASING THE R MEMORY FOLLOWING THE INSTRUCTION IN  ?Memory

I started R with:

R --min-vsize=10M --max-vsize=4G --min-nsize=500k --max-nsize=900M
 gc()
 used (Mb) gc trigger (Mb) limit (Mb) max used (Mb)
Ncells 130433  3.5 50 13.4  25200   50 13.4
Vcells  81138  0.71310720 10.0 NA   499143  3.9

It increased but not so much! 

Please, please let me know.  I have read all r-help about this matter, but 
not solution. Thanks for your attention!

Ricardo


 
 [[alternative HTML version deleted]]

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



[[alternative HTML version deleted]]

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


Re: [R] subsets, %in%

2010-11-05 Thread Jonathan P Daily
Any logical value can be negatively compared using !
does:
subset(dat, !(dat$ID %in% someID))

provide what you need?
--
Jonathan P. Daily
Technician - USGS Leetown Science Center
11649 Leetown Road
Kearneysville WV, 25430
(304) 724-4480
Is the room still a room when its empty? Does the room,
 the thing itself have purpose? Or do we, what's the word... imbue it.
 - Jubal Early, Firefly



From:
mp.sylves...@gmail.com
To:
r-help@r-project.org
Date:
11/05/2010 02:21 PM
Subject:
[R] subsets, %in%
Sent by:
r-help-boun...@r-project.org



Hi,

I have a question about %in% and subsettin data frames.

Say I need to keep ID 1,2,4,5, 10 from the data frame dat. I can do:

dat - data.frame(ID = 1:10, var = 1:10)
someID - c(1,2,4,5,10)
subset(dat, dat$ID %in% someID)

Is there a quick way to do the opposite, ie to do a subset that contains 
all ID but someID? Something like %not in%, which would *remove* lines 
with 
ID in someID?

I am asking because I need this in a more complex example where there are 
multiple lines with the same ID (data in long format) and I need to remove 
 
selected ID.

thanks,

MP

 [[alternative HTML version deleted]]

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



[[alternative HTML version deleted]]

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


Re: [R] cross-validation for choosing regression trees

2010-11-04 Thread Jonathan P Daily
Forgive me if I misunderstand your goals but I have no idea what you are 
trying to determine or what your data is. I can say, however, that setting 
mindev to 0 has always overfit data for me, and that you are more than 
likely looking at a situation in which that 1 node tree is more accurate.

Also, if you look at ?cv.tree, the default function to use is 
prune.tree(). Perhaps prune.tree() is trimming down to that terminal node?

If you want an alternative look at CART methods that may account for some 
of your issues, I would recommend the packages 'rpart' and 'party', as 
they may be more informative.
--
Jonathan P. Daily
Technician - USGS Leetown Science Center
11649 Leetown Road
Kearneysville WV, 25430
(304) 724-4480
Is the room still a room when its empty? Does the room,
 the thing itself have purpose? Or do we, what's the word... imbue it.
 - Jubal Early, Firefly



From:
Shiyao Liu lsy...@iastate.edu
To:
r-help@r-project.org
Date:
11/03/2010 09:04 PM
Subject:
[R] cross-validation for choosing regression trees
Sent by:
r-help-boun...@r-project.org



Dear All,

We came across a problem when using the tree package to analyze our data
set.

First, in the tree function, if we use the default value mindev=0.01,
the resulting regression tree has a single node. So, we set mindev=0, 
and
obtain a tree with 931 terminal nodes.

However, when we further use the cv.tree function to run a 10-fold
cross-validation, the error message is:

Error in prune.tree(list(frame = list(var = 1L, n = 6676, dev =
3.28220789569792,  : can not prune singlenode tree.

Is the cv.tree function respecting the mindev chosen in the tree 
function
or what else might be wrong?

Thanks,
Shiyao

 [[alternative HTML version deleted]]

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



[[alternative HTML version deleted]]

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


Re: [R] memory allocation problem

2010-11-03 Thread Jonathan P Daily
The optim function is very resource hungry. I have had similar problems in 
the past when dealing with extremely large datasets.

What is perhaps happening is that each 'step' of the optimization 
algorithm stores some info so that it can compare to the next 'step', and 
while the original vector may only be a few Mb of data, over many 
iterations a huge amount memory is allocated to the optimization steps.

Maybe look at the control options under ?optim, particularly stuff like 
trace, fnscale, ndeps, etc. that may cut down on the amount of data being 
stored each step as well as the number of steps needed.

Good luck!
--
Jonathan P. Daily
Technician - USGS Leetown Science Center
11649 Leetown Road
Kearneysville WV, 25430
(304) 724-4480
Is the room still a room when its empty? Does the room,
 the thing itself have purpose? Or do we, what's the word... imbue it.
 - Jubal Early, Firefly



From:
Lorenzo Cattarino l.cattar...@uq.edu.au
To:
David Winsemius dwinsem...@comcast.net, Peter Langfelder 
peter.langfel...@gmail.com
Cc:
r-help@r-project.org
Date:
11/03/2010 03:26 AM
Subject:
Re: [R] memory allocation problem
Sent by:
r-help-boun...@r-project.org



Thanks for all your suggestions,

This is what I get after removing all the other (not useful) objects and
run my code:

 getsizes()
[,1]
org_results 47240832
myfun  11672
getsizes4176
SS  3248
coeff168
NA  NA
NA  NA
NA  NA
NA  NA
NA  NA

 est_coeff - optim(coeff,SS, steps=org_results$no.steps,
Range=org_results$Range, H1=org_results$H1, H2=org_results$H2,
p=org_results$p)
Error: cannot allocate vector of size 5.0 Mb
In addition: Warning messages:
1: In optim(coeff, SS, steps = org_results$no.steps, Range =
org_results$Range,  :
  Reached total allocation of 4055Mb: see help(memory.size)
2: In optim(coeff, SS, steps = org_results$no.steps, Range =
org_results$Range,  :
  Reached total allocation of 4055Mb: see help(memory.size)
3: In optim(coeff, SS, steps = org_results$no.steps, Range =
org_results$Range,  :
  Reached total allocation of 4055Mb: see help(memory.size)
4: In optim(coeff, SS, steps = org_results$no.steps, Range =
org_results$Range,  :
  Reached total allocation of 4055Mb: see help(memory.size)


It seems that R is using all the default availabe memory (4 GB, which is
the RAM of my processor).

 memory.limit()
[1] 4055
 memory.size()
[1] 4049.07


My dataframe has a size of 47240832 bytes, or about 45 Mb. So it should
not be a problem in terms of memory usage?

I do not understand what is going on.

Thanks for your help anyway

Lorenzo

-Original Message-
From: David Winsemius [mailto:dwinsem...@comcast.net] 
Sent: Wednesday, 3 November 2010 12:48 PM
To: Lorenzo Cattarino
Cc: r-help@r-project.org
Subject: Re: [R] memory allocation problem

Restart your computer. (Yeah, I know that what the help-desk always 
says.)
Start R before doing anything else.

Then run your code in a clean session. Check ls() oafter starte up to 
make sure you don't have a bunch f useless stuff in your .Rdata 
file.   Don't load anything that is not germane to this problem.  Use 
this function to see what sort of space issues you might have after 
loading objects:

  getsizes - function() {z - sapply(ls(envir=globalenv()),
 function(x) object.size(get(x)))
(tmp - as.matrix(rev(sort(z))[1:10]))}

Then run your code.

-- 
David.

On Nov 2, 2010, at 10:13 PM, Lorenzo Cattarino wrote:

 I would also like to include details on my R version



 version  _

 platform   x86_64-pc-mingw32
 arch   x86_64

 os mingw32
 system x86_64, mingw32
 status
 major  2
 minor  11.1
 year   2010
 month  05
 day31
 svn rev52157
 language   R
 version.string R version 2.11.1 (2010-05-31)

 from FAQ 2.9

(http://cran.r-project.org/bin/windows/base/rw-FAQ.html#There-seems-to-b
 e-a-limit-on-the-memory-it-uses_0021

http://cran.r-project.org/bin/windows/base/rw-FAQ.html#There-seems-to-b
 e-a-limit-on-the-memory-it-uses_0021 ) it says that:
 For a 64-bit build, the default is the amount of RAM

 So in my case the amount of RAM would be 4 GB. R should be able to
 allocate a vector of size 5 Mb without me typing any command (either 
 as
 memory.limit() or appended string in the target path), is that right?



 From: Lorenzo Cattarino
 Sent: Wednesday, 3 November 2010 10:55 AM
 To: 'r-help@r-project.org'
 Subject: memory allocation problem



 I forgot to mention that I am using windows 7 (64-bit) and the R 
 version
 2.11.1 (64-bit)



 From: Lorenzo Cattarino

 I am trying to run a non linear parameter optimization using the
 function optim() and I have problems regarding memory allocation.

 My data are in a dataframe with 9 columns. There are 656100 rows.

 head(org_results)

 comb.id   p

Re: [R] optim works on command-line but not inside a function

2010-11-03 Thread Jonathan P Daily
As the error message says, the values of your function must be finite in 
order to run the algorithm.

Some part of your loop is passing arguments (inits maybe... you only tried 
(0,0) in the CLI example) that cause IRT.llZetaLambdaCorrNan to be 
infinite.
--
Jonathan P. Daily
Technician - USGS Leetown Science Center
11649 Leetown Road
Kearneysville WV, 25430
(304) 724-4480
Is the room still a room when its empty? Does the room,
 the thing itself have purpose? Or do we, what's the word... imbue it.
 - Jubal Early, Firefly



From:
Damokun dmroi...@students.cs.uu.nl
To:
r-help@r-project.org
Date:
11/03/2010 10:19 AM
Subject:
[R] optim works on command-line but not inside a function
Sent by:
r-help-boun...@r-project.org




Dear all, 

I am trying to optimize a logistic function using optim, inside the
following functions: 
#Estimating a and b from thetas and outcomes by ML

IRT.estimate.abFromThetaX - function(t, X, inits, lw=c(-Inf,-Inf),
up=rep(Inf,2)){

  optRes - optim(inits, method=L-BFGS-B, fn=IRT.llZetaLambdaCorrNan, 

  gr=IRT.gradZL, 

  lower=lw, upper=up, t=t, X=X)

  c(optRes$par[2], -(optRes$par[1]/optRes$par[2]) )

}

#Estimating a and b from thetas and outcomes by ML, avoiding 0*log(0)
IRT.estimate.abFromThetaX2 - function(tar, Xes, inits, lw=c(-Inf,-Inf),
up=rep(Inf,2)){

  optRes - optim(inits, method=L-BFGS-B, fn=IRT.llZetaLambdaCorrNan, 

  gr=IRT.gradZL, 

  lower=lw, upper=up, t=tar, X=Xes)

  c(optRes$par[2], -(optRes$par[1]/optRes$par[2]) )

}

The problem is that this does not work: 
 IRT.estimate.abFromThetaX(sx, st, c(0,0))
Error in optim(inits, method = L-BFGS-B, fn = IRT.llZetaLambdaCorrNan, : 

  L-BFGS-B needs finite values of 'fn'
But If I try the same optim call on the command line, with the same data, 
it
works fine:
 optRes - optim(c(0,0), method=L-BFGS-B, fn=IRT.llZetaLambdaCorrNan, 
+   gr=IRT.gradZL, 
+   lower=c(-Inf, -Inf), upper=c(Inf, Inf), t=st, X=sx)
 optRes
$par
[1] -0.6975157  0.7944972
$convergence
[1] 0
$message
[1] CONVERGENCE: REL_REDUCTION_OF_F = FACTR*EPSMCH

Does anyone have an idea what this could be, and what I could try to avoid
this error? I tried bounding the parameters, with lower=c(-10, -10) and
upper=... but that made no difference. 

Thanks, 
Diederik Roijers
Utrecht University MSc student. 
--
PS: the other functions I am using are: 

#IRT.p is the function that represents the probability 
#of a positive outcome of an item with difficulty b, 
#discriminativity a, in combination with a student with
#competence theta. 

IRT.p - function(theta, a, b){

   epow - exp(-a*(theta-b))

   result - 1/(1+epow)

   result

}


# = IRT.p^-1 ; for usage in the loglikelihood

IRT.oneOverP - function(theta, a, b){

   epow - exp(-a*(theta-b))

   result - (1+epow)

   result

}

# = (1-IRT.p)^-1 ; for usage in the loglikelihood
IRT.oneOverPneg - function(theta, a, b){

   epow - exp(a*(theta-b))

   result - (1+epow)

   result

}


#simulation-based sample generation of thetas and outcomes
#based on a given a and b. (See IRT.p) The sample-size is n

IRT.generateSample - function(a, b, n){

   x-rnorm(n, mean=b, sd=b/2)

   t-IRT.p(x,a,b)

   ch-runif(length(t))

   t[t=ch]=1

   t[tch]=0

   cbind(x,t)

}


#This loglikelihood function is based on the a and be parameters, 
#and requires thetas as input in X, and outcomes in t
#prone to give NaN errors due to 0*log(0)

IRT.logLikelihood2 - function(params, t, X){

   pos- sum(t * log(IRT.p(X,params[1],params[2])))

   neg- sum(  (1-t) * log( (1-IRT.p(X,params[1],params[2])) )  )

   -pos-neg

}

#Avoiding NaN problems due to 0*log(0) 
#otherwise equivalent to IRT.logLikelihood2
IRT.logLikelihood2CorrNan - function(params, t, X){

   pos- sum(t * log(IRT.oneOverP(X,params[1],params[2])))

   neg- sum((1-t) * log(IRT.oneOverPneg(X,params[1],params[2])))

   -pos-neg

}

#IRT.p can also be espressed in terms of z and l 
#where z=-ab and l=a - makes it a standard logit function

IRT.pZL - function(theta, z, l){

   epow - exp(-(z+l*theta))

   result - 1/(1+epow)

   result

}

#as IRT.oneOverP but now for IRT.pZL 
IRT.pZLepos - function(theta, z, l){

   epow - exp(-(z+l*theta))

   result - (1+epow)

   result

}


#as IRT.oneOverPneg but now for IRT.pZL 
IRT.pZLeneg - function(theta, z, l){

   epow - exp(z+l*theta)

   result - (1+epow)

   result

}



#The loglikelihood of IRT, but now expressed in terms of z and l

IRT.llZetaLambda - function(params, t, X){

   pos- sum(t * log(IRT.pZL( X,params[1],params[2]) ))

   neg- sum(  (1-t) * log( (1-IRT.pZL(X,params[1],params[2] )) )  )

   -pos-neg

}

#Same as IRT.logLikelihood2CorrNan but for IRT.llZetaLambda
IRT.llZetaLambdaCorrNan - function(params, t, X){

   pos - sum(t * log(IRT.pZLepos( X,params[1],params[2]) ))

   neg - sum((1-t) * log(IRT.pZLeneg(X,params[1],params[2]) ))

   pos+neg

}


#Gradient of IRT.llZetaLambda

IRT.gradZL - function(params, t, X){

  res-numeric(length(params

Re: [R] programming questions

2010-11-03 Thread Jonathan P Daily
For data frames you can also use with()

in your example:

with(d, exists(z))
--
Jonathan P. Daily
Technician - USGS Leetown Science Center
11649 Leetown Road
Kearneysville WV, 25430
(304) 724-4480
Is the room still a room when its empty? Does the room,
 the thing itself have purpose? Or do we, what's the word... imbue it.
 - Jubal Early, Firefly



From:
ivo welch ivo.we...@gmail.com
To:
Erik Iverson er...@ccbr.umn.edu
Cc:
r-help r-h...@stat.math.ethz.ch
Date:
11/03/2010 02:20 PM
Subject:
Re: [R] programming questions
Sent by:
r-help-boun...@r-project.org



yikes.  this is all my fault.  it was the first thing that I ever
defined when I started using R.

   is.defined - function(name) exists(as.character(substitute(name)))

I presume there is something much better...

/iaw


On Wed, Nov 3, 2010 at 2:12 PM, Erik Iverson er...@ccbr.umn.edu wrote:


 ivo welch wrote:

 quick programming questions.  I want to turn on more errors.  there
 are two traps I occasionally fall into.

 * I wonder why R thinks that a variable is always defined in a data 
frame.

  is.defined(d)
 [1] FALSE
  d= data.frame( x=1:5, y=1:5 )
  is.defined(d$z)
 [1] TRUE
  is.defined(nonexisting$garbage)
 [1] TRUE

 Which package/version of R is the 'is.defined' function in?

 I don't seem to have it here on 2.11.1, which I know is not
 the latest version of R.

 What does 'defined' mean?


 this is a bit unfortunate for me, because subsequent errors become
 less clear.   right now, I need to do '(is.defined(d) and
 !is.null(d$z))' to check that my function inputs are valid.  It would
 be nicer if one could just write if (is.defined(d$z).

 z %in% names(d) ?


 * is there a way to turn off automatic recycling?  I would rather get
 an error than unexpected recycling.  I can force recycling with rep()
 when I need to.

 regards,

 /iaw

 
 Ivo Welch (ivo.we...@brown.edu, ivo.we...@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@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] R script on linux?

2010-11-02 Thread Jonathan P Daily
What is the error message?
--
Jonathan P. Daily
Technician - USGS Leetown Science Center
11649 Leetown Road
Kearneysville WV, 25430
(304) 724-4480
Is the room still a room when its empty? Does the room,
 the thing itself have purpose? Or do we, what's the word... imbue it.
 - Jubal Early, Firefly



From:
gokhanocakoglu ocako...@uludag.edu.tr
To:
r-help@r-project.org
Date:
11/02/2010 09:11 AM
Subject:
Re: [R] R  script on linux?
Sent by:
r-help-boun...@r-project.org




I can't run the script the program doesn't work...
-- 
View this message in context: 
http://r.789695.n4.nabble.com/R-script-on-linux-tp3023650p3023670.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] R script on linux?

2010-11-02 Thread Jonathan P Daily
Alternatively, you can simply prefix all scripts with

#! /path/to/R/Rscript
...

where the path is usually /usr/bin/
This info is in the manual that comes packaged with R under, conveniently, 
the scripting section. I assumed that he was getting some error message.
Likely, the script was not created executable, in which case the terminal 
command chmod +x myscript.R will do it.
--
Jonathan P. Daily
Technician - USGS Leetown Science Center
11649 Leetown Road
Kearneysville WV, 25430
(304) 724-4480
Is the room still a room when its empty? Does the room,
 the thing itself have purpose? Or do we, what's the word... imbue it.
 - Jubal Early, Firefly



From:
Thomas Levine thomas.lev...@gmail.com
To:
Jonathan P Daily jda...@usgs.gov
Cc:
gokhanocakoglu ocako...@uludag.edu.tr, r-help@r-project.org, 
r-help-boun...@r-project.org
Date:
11/02/2010 02:24 PM
Subject:
Re: [R] R script on linux?



Open a terminal, then run these two commands.

cd /home/the/directory/with/your/script
R

Then run this in R

source('yourscript.R')

Tom

2010/11/2 Jonathan P Daily jda...@usgs.gov:
 What is the error message?
 --
 Jonathan P. Daily
 Technician - USGS Leetown Science Center
 11649 Leetown Road
 Kearneysville WV, 25430
 (304) 724-4480
 Is the room still a room when its empty? Does the room,
  the thing itself have purpose? Or do we, what's the word... imbue it.
 - Jubal Early, Firefly



 From:
 gokhanocakoglu ocako...@uludag.edu.tr
 To:
 r-help@r-project.org
 Date:
 11/02/2010 09:11 AM
 Subject:
 Re: [R] R  script on linux?
 Sent by:
 r-help-boun...@r-project.org




 I can't run the script the program doesn't work...
 --
 View this message in context:
 http://r.789695.n4.nabble.com/R-script-on-linux-tp3023650p3023670.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.




[[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] Possible memory leak in loop.

2010-11-01 Thread Jonathan P Daily
I was trying to use memory.size() to determine whether a code loop I am 
executing created a memory leak, since one replicate of the simulation 
takes 670.98 seconds according to proc.time(), while 5 replicates takes 
170762 seconds. So I set it up as:

memA - memory.size()

looping code...

memB - memory.size()

memA returns as 9.3, and memB returns 11.3. I'm not familiar with 
fluctuation patterns in RAM usage (if there are any). Does anyone with 
more experience know if this is indicative of a memory leak?

Thanks,
Jon
--
Jonathan P. Daily
Technician - USGS Leetown Science Center
11649 Leetown Road
Kearneysville WV, 25430
(304) 724-4480
Is the room still a room when its empty? Does the room,
 the thing itself have purpose? Or do we, what's the word... imbue it.
 - Jubal Early, Firefly
[[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] Possible memory leak in loop.

2010-11-01 Thread Jonathan P Daily
Thank you, I will give that a try.
--
Jonathan P. Daily
Technician - USGS Leetown Science Center
11649 Leetown Road
Kearneysville WV, 25430
(304) 724-4480
Is the room still a room when its empty? Does the room,
 the thing itself have purpose? Or do we, what's the word... imbue it.
 - Jubal Early, Firefly



From:
jim holtman jholt...@gmail.com
To:
Jonathan P Daily jda...@usgs.gov
Cc:
r-help@r-project.org
Date:
11/01/2010 09:48 AM
Subject:
Re: [R] Possible memory leak in loop.



If you are running on Windows, you might want to use 'perfmon' to look
at the memory usage of the process over time.  You might also want to
put calls to memory.size in your looping code to see if there are
things you are doing in the code that might temporarily use a lot of
space and maybe fragment memory.

On Mon, Nov 1, 2010 at 8:35 AM, Jonathan P Daily jda...@usgs.gov wrote:
 I was trying to use memory.size() to determine whether a code loop I am
 executing created a memory leak, since one replicate of the simulation
 takes 670.98 seconds according to proc.time(), while 5 replicates takes
 170762 seconds. So I set it up as:

 memA - memory.size()

 looping code...

 memB - memory.size()

 memA returns as 9.3, and memB returns 11.3. I'm not familiar with
 fluctuation patterns in RAM usage (if there are any). Does anyone with
 more experience know if this is indicative of a memory leak?

 Thanks,
Jon
 --
 Jonathan P. Daily
 Technician - USGS Leetown Science Center
 11649 Leetown Road
 Kearneysville WV, 25430
 (304) 724-4480
 Is the room still a room when its empty? Does the room,
  the thing itself have purpose? Or do we, what's the word... imbue it.
 - Jubal Early, Firefly
[[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.




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

What is the problem that you are trying to solve?



[[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] Zoom in in a plot

2010-10-27 Thread Jonathan P Daily
In that case you may wish to look into the rggobi package, which provides 
an R interface to the ggobi tools. I haven't used it much, but it has a 
lot of interactive options.
--
Jonathan P. Daily
Technician - USGS Leetown Science Center
11649 Leetown Road
Kearneysville WV, 25430
(304) 724-4480
Is the room still a room when its empty? Does the room,
 the thing itself have purpose? Or do we, what's the word... imbue it.
 - Jubal Early, Firefly



From:
Alaios ala...@yahoo.com
To:
Greg Snow greg.s...@imail.org, Rhelp r-help@r-project.org
Date:
10/27/2010 02:21 AM
Subject:
Re: [R] Zoom in in a plot
Sent by:
r-help-boun...@r-project.org



Actually I want to see  how close are some point to a line segment  so I 
want to 
use some zoom lenses and zoom in and out into different parts of the plot 
and 
see how some places look like.

Best Regards





From: Greg Snow greg.s...@imail.org

Sent: Tue, October 26, 2010 6:47:32 PM
Subject: RE: [R] Zoom in in a plot

For a quick exploration of the plot you can use the zoomplot function in 
the 
TeachingDemos package.  But for production graphs it is better to 
explicitly set 
the xlim and ylim parameters in creating the plot up front.

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


 -Original Message-
 From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-
 project.org] On Behalf Of Alaios
 Sent: Tuesday, October 26, 2010 9:31 AM
 To: Rhelp
 Subject: [R] Zoom in in a plot
 
 in a simple plot. When i do plot is it possible to zoom in or out or
 this is not
 possible at all?
 
 Best Regards
 Alex
 
 
 
 
 [[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.



[[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] Best IDE for R

2010-10-27 Thread Jonathan P Daily
I noticed that nabble link presented Notepad++ as having to copy/paste 
into the editor. There is a companion to NP++, though, that allows 
line/file passing directly to an R console, auto-completion, and a bunch 
of other goodies called NppToR.
--
Jonathan P. Daily
Technician - USGS Leetown Science Center
11649 Leetown Road
Kearneysville WV, 25430
(304) 724-4480
Is the room still a room when its empty? Does the room,
 the thing itself have purpose? Or do we, what's the word... imbue it.
 - Jubal Early, Firefly



From:
Dennis Murphy djmu...@gmail.com
To:
Santosh Srinivas santosh.srini...@gmail.com
Cc:
r-help@r-project.org
Date:
10/27/2010 09:03 AM
Subject:
Re: [R] Best IDE for R
Sent by:
r-help-boun...@r-project.org



Hi:

This topic came up a couple of days ago:

http://r.789695.n4.nabble.com/R-file-td3009812.html#a3009812

HTH,
Dennis

On Wed, Oct 27, 2010 at 4:01 AM, Santosh Srinivas 
santosh.srini...@gmail.com wrote:

 Dear R-Group,

 I am looking for suggestions for the best IDE for R. Best is obviously
 subjective but I need just the basic features that should function well
 (and
 I looked through the threads already).
 - Proper integration with R 2.11.1
 - Good key shortcuts ... similar to the R Gui
 - Manageability of Projects, etc.
 - Neat formatting features

 I tried Revolution R but it seems huge in size for something my basic 
needs
 and keep throwing up configuration problems.
 I tried Komodo. It works fine but having problems with proper 
integration
 into R and unable to do debugging.

 Any help?

 Thanks,
 S

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



[[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] Best IDE for R

2010-10-27 Thread Jonathan P Daily
I can second using Geany as an IDE. Another large plus for it is that it 
is cross platform (I work in both Windows and Linux), cross environment (I 
also code in Python/Sage), very customizable, and even has a version on 
PortableApps for windows so you can take a customized version around on a 
USB stick with ease.
--
Jonathan P. Daily
Technician - USGS Leetown Science Center
11649 Leetown Road
Kearneysville WV, 25430
(304) 724-4480
Is the room still a room when its empty? Does the room,
 the thing itself have purpose? Or do we, what's the word... imbue it.
 - Jubal Early, Firefly



From:
Liviu Andronic landronim...@gmail.com
To:
Lee Hachadoorian lee.hachadooria...@gmail.com
Cc:
r-h...@stat.math.ethz.ch
Date:
10/27/2010 02:45 PM
Subject:
Re: [R] Best IDE for R
Sent by:
r-help-boun...@r-project.org



On Wed, Oct 27, 2010 at 4:05 PM, Lee Hachadoorian
lee.hachadooria...@gmail.com wrote:
 For an R-enabled text editor, I would suggest Tinn-R for Windows or 
RGedit
 (a gedit plugin) for Linux/Gnome-desktop. Since both are just text
 editors, they will work with whatever version R you have installed
 (criteria 1).

 RGedit is pretty spare: basically just console integration and keyboard
 shortcuts to send code (current line, selection, defined blocks) to the
 console. Criteria 1 Y 2 basic 3 N 4 N

For Linux and Mac, I usually suggest Geany [1] as an alternative to
Gedit. Geany is an intuitive IDE that can send commands to rterm in
the integrated virtual terminal emulator. It provides various features
for project management, source highlighting, code folding, etc.

Regards
Liviu

[1] http://www.r-bloggers.com/integrating-r-with-geany/

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

2010-10-26 Thread Jonathan P Daily
A call to read.table(..., sep = , ...) reads in any length of whitespace 
as the delimiter. On your sample text it read in a 2 column dataframe.
--
Jonathan P. Daily
Technician - USGS Leetown Science Center
11649 Leetown Road
Kearneysville WV, 25430
(304) 724-4480
Is the room still a room when its empty? Does the room,
 the thing itself have purpose? Or do we, what's the word... imbue it.
 - Jubal Early, Firefly



From:
Ùukasz Ræcùawowicz lukasz.reclawow...@gmail.com
To:
amindlessbrain jillianrowe91...@gmail.com
Cc:
r-help@r-project.org
Date:
10/26/2010 09:34 AM
Subject:
Re: [R] Reading in a tab delimitated file
Sent by:
r-help-boun...@r-project.org



2010/10/26 amindlessbrain jillianrowe91...@gmail.com


 (I'm not sure why the disease column isn't showing up as a tab here, but
it
 is sep by \t in my file.


You've got a double tab space, I don't know is there a prettier way, but
paste this:

pd-read.delim(new_treat.txt,sep=)

-- 
Mi³ego dnia

 [[alternative HTML version deleted]]

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



[[alternative HTML version deleted]]

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


Re: [R] Reading in a tab delimitated file

2010-10-26 Thread Jonathan P Daily
Right, I forgot to mention to use header = T.
--
Jonathan P. Daily
Technician - USGS Leetown Science Center
11649 Leetown Road
Kearneysville WV, 25430
(304) 724-4480
Is the room still a room when its empty? Does the room,
 the thing itself have purpose? Or do we, what's the word... imbue it.
 - Jubal Early, Firefly



From:
Henrique Dallazuanna www...@gmail.com
To:
amindlessbrain jillianrowe91...@gmail.com
Cc:
r-help@r-project.org
Date:
10/26/2010 11:08 AM
Subject:
Re: [R] Reading in a tab delimitated file
Sent by:
r-help-boun...@r-project.org



Try this:

Lines - SampleIDDisease
E-CBIL-28-raw-cel-1435145228.cel1
E-CBIL-28-raw-cel-1435145451.cel2
E-CBIL-28-raw-cel-1435145479.cel2
E-CBIL-28-raw-cel-1435145132.cel3
E-CBIL-28-raw-cel-1435145417.cel3
E-CBIL-28-raw-cel-1435145301.cel2
E-CBIL-28-raw-cel-1435145558.cel1
E-CBIL-28-raw-cel-1435145073.cel3
E-CBIL-28-raw-cel-1435145196.cel2
E-CBIL-28-raw-cel-1435145511.cel1
E-CBIL-28-raw-cel-1435145336.cel3
E-CBIL-28-raw-cel-1435145260.cel2
E-CBIL-28-raw-cel-1435145167.cel2
E-CBIL-28-raw-cel-1435145387.cel3
E-CBIL-28-raw-cel-1435145099.cel3

DF - read.table(textConnection(Lines), header = TRUE)

On Tue, Oct 26, 2010 at 10:35 AM, amindlessbrain 
jillianrowe91...@gmail.com
 wrote:


 Hi all,

 I have a total newbie question, but I could really use some help.

 I need to read in this file:

 SampleIDDisease
 E-CBIL-28-raw-cel-1435145228.cel1
 E-CBIL-28-raw-cel-1435145451.cel2
 E-CBIL-28-raw-cel-1435145479.cel2
 E-CBIL-28-raw-cel-1435145132.cel3
 E-CBIL-28-raw-cel-1435145417.cel3
 E-CBIL-28-raw-cel-1435145301.cel2
 E-CBIL-28-raw-cel-1435145558.cel1
 E-CBIL-28-raw-cel-1435145073.cel3
 E-CBIL-28-raw-cel-1435145196.cel2
 E-CBIL-28-raw-cel-1435145511.cel1
 E-CBIL-28-raw-cel-1435145336.cel3
 E-CBIL-28-raw-cel-1435145260.cel2
 E-CBIL-28-raw-cel-1435145167.cel2
 E-CBIL-28-raw-cel-1435145387.cel3
 E-CBIL-28-raw-cel-1435145099.cel3

 (I'm not sure why the disease column isn't showing up as a tab here, but
it
 is sep by \t in my file.

 I've tried several variations on these:

 pd - read.AnnotatedDataFrame (new_treat.txt , header = TRUE , 
sep=\t,
 row.names = SampleID, colClasses = c(Disease = character))

 And I keep on getting this error:

 Error in read.table(filename, sep = sep, header = header, quote = quote, 
 :
  more columns than column names

 Any help would be very very very appreciated!

 Thanks!



 --
 View this message in context:
 
http://r.789695.n4.nabble.com/Reading-in-a-tab-delimitated-file-tp3013620p3013620.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.




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

 [[alternative HTML version deleted]]

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



[[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] Zoom in in a plot

2010-10-26 Thread Jonathan P Daily
I think that this would be possible if you save the graph to a scalable 
format.

Try looking into:
?postscript
?xfig
?pdf
--
Jonathan P. Daily
Technician - USGS Leetown Science Center
11649 Leetown Road
Kearneysville WV, 25430
(304) 724-4480
Is the room still a room when its empty? Does the room,
 the thing itself have purpose? Or do we, what's the word... imbue it.
 - Jubal Early, Firefly



From:
Alaios ala...@yahoo.com
To:
Rhelp r-help@r-project.org
Date:
10/26/2010 11:32 AM
Subject:
[R] Zoom in in a plot
Sent by:
r-help-boun...@r-project.org



in a simple plot. When i do plot is it possible to zoom in or out or this 
is not 
possible at all?

Best Regards
Alex



 
 [[alternative HTML version deleted]]

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



[[alternative HTML version deleted]]

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


Re: [R] anomalies with the loess() function

2010-10-26 Thread Jonathan P Daily
?loess

use this instead:

fit - loess(b~a)
lines(a, predict(fit))
--
Jonathan P. Daily
Technician - USGS Leetown Science Center
11649 Leetown Road
Kearneysville WV, 25430
(304) 724-4480
Is the room still a room when its empty? Does the room,
 the thing itself have purpose? Or do we, what's the word... imbue it.
 - Jubal Early, Firefly



From:
Federico Bonofiglio bonori...@gmail.com
To:
r-help@r-project.org
Date:
10/26/2010 02:38 PM
Subject:
[R] anomalies with the loess() function
Sent by:
r-help-boun...@r-project.org



Hello Masters,

I run the loess() function to obtain local weighted regressions, given
lowess() can't handle NAs, but I don't
improve significantly my situation.., actually loess() performance 
leave
me much puzzled

I attach my easy experiment below

#--SCRIPT--

#I explore the functionalities of lowess()  loess()
#because I have encountered problems in execute local weighted regressions
#with lowess() (in presence of NAs)  with loess() (always!!!)


#I generate 2 fictious vectors

a-sample(c(sample(1:1000,100),rep(NA,50)))

b-sample(c(sample(1:1000,100),rep(NA,50)))

#lm() has no problems..can handle the missing values
plot(a,b)
abline(lm(b~a),col=red,lwd=2)

#loess return a plain mess like it would go dizzed with ordering or
something.
#Off course lowess() turns useless in presence of NAs, I don't even try 
it.

lines(loess(b~a))

#I get rid off NAs and compare lowess()  loess() performance, expecting 
to
#obtain the same result as both functions implement local weighted
regressions

a-na.omit(a)
b-na.omit(b)

#check out the evidence.something's wrong with loess()???

par(mfrow=c(1,2))
plot(a,b)
lines(lowess(a,b),col=red)#if NAs are excluded lowess() runs regularly
plot(a,b)
lines(loess(b~a),col=red)#.but loess() keeps messing all 
over...!!???

 [[alternative HTML version deleted]]

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



[[alternative HTML version deleted]]

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


Re: [R] lowess() won't handle NAs

2010-10-25 Thread Jonathan P Daily
Try using the loess() function instead - it has an na.action parameter 
that should be able to handle your problem.
--
Jonathan P. Daily
Technician - USGS Leetown Science Center
11649 Leetown Road
Kearneysville WV, 25430
(304) 724-4480
Is the room still a room when its empty? Does the room,
 the thing itself have purpose? Or do we, what's the word... imbue it.
 - Jubal Early, Firefly
[[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] Passing rq models to Fstats

2010-03-04 Thread Jonathan P Daily
I have seen literature on using a combination of the 'strucchange' and 
'segmented' packages to find and fit piecewise linear models. I have been 
trying to apply the same methods to quantile regression from the quantreg 
package, but am having issues using a rq object where the function 
assumes a lm. Has anyone had this issue?
--
Jonathan P. Daily
Technician - USGS Leetown Science Center
11649 Leetown Road
Kearneysville WV, 25430
(304) 724-4480
Is the room still a room when its empty? Does the room,
 the thing itself have purpose? Or do we, what's the word... imbue it.
 - Jubal Early, Firefly
[[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.