[R] optimize function help!!

2008-07-22 Thread emir.toktar
Dear R users, I´m trying to optimize simultaneously two binomials inequalities used to acceptance sampling, which are nonlinear solution, so there is no simple direct solution. The 'n' represents the sample size and the 'c' an acceptance number or maximum number of defects (nonconforming) in sampl

[R] Optimize jackknife code

2007-12-31 Thread mw-u2
Hi, I have the following jackknife code which is much slower than my colleagues C code. Yet I like R very much and wonder how R experts would optimize this. I think that the for (i in 1:N_B) part is bad because Rprof() said sum() is called very often but I have no idea how to optimize it. #

[R] optimize() stuck in local plateau ?

2007-09-30 Thread Mike Lawrence
Hi all, Consider the following function: my.func = function(x){ y=ifelse(x>-.5,0,ifelse(x< -.8,abs(x)/2,abs(x))) print(c(x,y)) #print what was tested and what the result is return(y) } curve(my.func,from=-1,1) When I attempt to find the maximum of this function,

Re: [R] optimize() stuck in local plateau ?

2007-09-30 Thread Moshe Olshansky
Hi Mike, You function is discontinuous at -0.8, so you can expect everything :-}! But this is not the only problem. The algorithm for optimize never gets there. In general there exists no universal method to find the global maximum of a function (unless it satisfies certain conditions). You can al

Re: [R] optimize() stuck in local plateau ?

2007-10-01 Thread Patrick Burns
Given a univariate problem where the maximum must be between -1 and 1, I would test with a grid of points, then refine that if necessary. Patrick Burns [EMAIL PROTECTED] +44 (0)20 8525 0696 http://www.burns-stat.com (home of S Poetry and "A Guide for the Unwilling S User") Mike Lawrence wrote: >

Re: [R] optimize() stuck in local plateau ?

2007-10-01 Thread Ravi Varadhan
alth/People/Faculty/Varadhan.html -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Mike Lawrence Sent: Monday, October 01, 2007 1:29 AM To: Rhelp Subject: [R] optimize() stuck in local plateau ? Hi all, Consider the

Re: [R] optimize() stuck in local plateau ?

2007-10-01 Thread Mike Lawrence
p://www.jhsph.edu/agingandhealth/People/Faculty/ > Varadhan.html > > > > -- > -- > > > > -Original Message- > From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] > project.org]

Re: [R] optimize() stuck in local plateau ?

2007-10-01 Thread Ravi Varadhan
-Original Message- From: Mike Lawrence [mailto:[EMAIL PROTECTED] Sent: Monday, October 01, 2007 10:27 AM To: Ravi Varadhan Cc: 'Rhelp' Subject: Re: [R] optimize() stuck in local plateau ? I may be misunderstanding, but my example seems to v

[R] optimize simultaneously two binomials inequalities using nlm

2008-07-29 Thread emir.toktar
Dear R users, I´m trying to optimize simultaneously two binomials inequalities used to acceptance sampling, which are nonlinear solution, so there is no simple direct solution. Please, let me explain shortly the the problem and the question as following. The objective is to obtain the smallest v

[R] optimize simultaneously two binomials inequalities using nlm( ) or optim( )

2008-08-04 Thread emir.toktar
Dear R users, I´m trying to optimize simultaneously two binomials inequalities (used in acceptance sampling) which are nonlinear solution, so there is no simple direct solution. Please, let me explain shortly the the problem and the question as following. The objective is to obtain the smallest v

[R] Optimize for loop / find last record for each person

2009-02-27 Thread Andrew Ziem
I want to find the last record for each person_id in a data frame (from a SQL database) ordered by date. Is there a better way than this for loop? for (i in 2:length(history[,1])) { if (history[i, "person_id"] == history[i - 1, "person_id"]) history[i, "order"] = history[i - 1, "order"]

Re: [R] optimize simultaneously two binomials inequalities using nlm( ) or optim( )

2008-08-05 Thread Spencer Graves
I saw your post on 7/29, and I have not seen a reply, so I will attempt a response to the question at the start of your email: obtain the smallest value of 'n' (sample size) satisfying both inequalities: (1-alpha) <= pbinom(c, n, p1) && pbinom(c, n, p2) <= beta, where alpha, p1,

Re: [R] optimize simultaneously two binomials inequalities using nlm( ) or optim( )

2008-08-05 Thread Marc Schwartz
Just a quick follow up to Spencer's post, you might want to look at the AcceptanceSampling package on CRAN: http://cran.r-project.org/web/packages/AcceptanceSampling/index.html HTH, Marc Schwartz on 08/05/2008 09:00 AM Spencer Graves wrote: I saw your post on 7/29, and I have not seen a

Re: [R] optimize simultaneously two binomials inequalities using nlm( ) or optim( )

2008-08-06 Thread Emir Toktar
Thanks Mr. Graves for your support. > I saw your post on 7/29, and I have not seen a reply, > so I will attempt a response to the question at the start of > your email: > > obtain the smallest value of 'n' (sample size) satisfying > both inequalities: > > (1-alpha)

Re: [R] optimize simultaneously two binomials inequalities using nlm( ) or optim( )

2008-08-06 Thread Emir Toktar
. EToktar > -Original Message- > From: Marc Schwartz [mailto:[EMAIL PROTECTED] > Sent: Tuesday, August 05, 2008 1:12 PM > To: Spencer Graves > Cc: [EMAIL PROTECTED]; r-help@r-project.org > Subject: Re: [R] optimize simultaneously two binomials > inequalities using nlm(

Re: [R] Optimize for loop / find last record for each person

2009-02-27 Thread Jorge Ivan Velez
Dear Andrew, Here is one way: # Some data set.seed(1) mydata<-data.frame(person_id=rep(1:10,10),x=rnorm(100)) mydata # last register for person_id with(mydata,tapply(x,person_id,function(x) tail(x,1))) # test for person_id=1 mydata[mydata$person_id==1,] # see the last number in column 2 HTH,

Re: [R] Optimize for loop / find last record for each person

2009-02-27 Thread David Winsemius
"...from an SQL database."How? Structure of the result? You say "ordered by date" but then you don't reference any date variable? And your code creates an "order" column, but that would not appear necessary for the stated purpose and you don't output the last "order" within a "person_i

Re: [R] Optimize for loop / find last record for each person

2009-02-27 Thread Jorge Ivan Velez
Dear Andrew: Here is another way assuming you have an order column in your history data as well as a person_id. Again, your variable of interest is x: # Some data set.seed(1) history<-data.frame( person_id=rep(1:10,each=10), record=rep(sample(10),10), x=rnorm(100)

Re: [R] Optimize for loop / find last record for each person

2009-02-27 Thread William Dunlap
[,"person_id"]),,drop=FALSE] history[order(history$date),,drop=FALSE] } > f2(history) person_id date 2 Mary2 7 Alex7 9Sue9 10 Joe 10 Bill Dunlap TIBCO Software Inc - Spotfire Division wdunlap tibco.com

Re: [R] Optimize for loop / find last record for each person

2009-02-27 Thread Andrew Ziem
On Fri, Feb 27, 2009 at 2:10 PM, William Dunlap wrote: > Andrew, it makes it easier to help if you supply a typical > input and expected output along with your code.  I tried > your code with the following input: I'll be careful to avoid these mistakes. Also, I should not have used a reserved wo

Re: [R] Optimize for loop / find last record for each person

2009-02-27 Thread Jorge Ivan Velez
Hi Andrew, Just remember that something was bad with the code I sent you (the same you referred to in [1]). This version runs with no problems: # Some data history_ <- data.frame(person_id=c(1,2,2),date_=c("2009-01-01","2009-02-03","2009-02-02"),x=c(0.01,0.05,0.06)) colnames(history_) <- c("perso