Re: [R] Minimization problem

2010-05-20 Thread Bernardo Rangel Tura
On Thu, 2010-05-20 at 01:35 -0700, Fred wrote:
 Dear R users,
 
 I am trying to minimize two function simultaneously in R,
 
 function(x)
 
 minimize x[1],x[2],x[3]
 
 mean(distribution(x1,x2,x3) ) - observed mean
 
 std(distribution(x1,x2,x3)) - observed std
 
 What I want to achieve is that simulated mean and standard deviation
 of distribution related to x1 x2 x3  would be close to observed mean
 and observed standard deviation.
 
 
 is there any function in R can reach this?
 
 Thank you for the help first .
 
 F.

Hi!
Do you need use optim, something like this

test - function(parameters){
m.error - mean(distribution(x1,x2,x3) ) - observed mean
m.sd - std(distribution(x1,x2,x3)) - observed std
res - cbind(m.error,sd.error)
return(res)
}
-- 
Bernardo Rangel Tura, M.D,MPH,Ph.D
National Institute of Cardiology
Brazil

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


Re: [R] Minimization problem

2010-05-20 Thread Ravi Varadhan
That would not work in optim.  The objective function must take in a
vector of parameters and return a scalar value.  Your objective function
does not return a scalar.  

This would work:

test - function(x, ...){
m.error - mean(distribution(x)) - observed.mean
sd.error - std(distribution(x)) - observed.std
res - c(m.error, sd.error)
return(sum(res^2))  # returns a scalar
}

Ravi.

-Original Message-
From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On
Behalf Of Bernardo Rangel Tura
Sent: Thursday, May 20, 2010 6:02 AM
To: r-help@r-project.org
Subject: Re: [R] Minimization problem

On Thu, 2010-05-20 at 01:35 -0700, Fred wrote:
 Dear R users,
 
 I am trying to minimize two function simultaneously in R,
 
 function(x)
 
 minimize x[1],x[2],x[3]
 
 mean(distribution(x1,x2,x3) ) - observed mean
 
 std(distribution(x1,x2,x3)) - observed std
 
 What I want to achieve is that simulated mean and standard deviation
 of distribution related to x1 x2 x3  would be close to observed mean
 and observed standard deviation.
 
 
 is there any function in R can reach this?
 
 Thank you for the help first .
 
 F.

Hi!
Do you need use optim, something like this

test - function(parameters){
m.error - mean(distribution(x1,x2,x3) ) - observed mean
m.sd - std(distribution(x1,x2,x3)) - observed std
res - cbind(m.error,sd.error)
return(res)
}
-- 
Bernardo Rangel Tura, M.D,MPH,Ph.D
National Institute of Cardiology
Brazil

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

2009-01-18 Thread David Winsemius


I'm not sure that it comes across as a matrix problem in the sense  
of involving matrix algebra, but it's also possible that I don't  
understand what you are saying. Seems that an appropriate application  
of:


?abs
?max
?sapply
?which.min

... ought to do the trick. If you were hoping for the name of the  
column vector, then may also need to look at:


?names

--
David Winsemius

On Jan 18, 2009, at 7:17 AM, glenn wrote:


Dear All,

Could someone give me some pointers (just a guide as to what  
functions I

need to look at would be fine)
as to how I go about this simple problem please;

The problem looks like this;

Choose x1 to x4 such that you minimize the MAXIMUM ABSOLUTE value  
returned

in the vector result of this matrix problem;

[x1,x2,x3,x4].[ -0.38   -0.52 0.68-0.29 ]
 [ -0.39   -0.42-0.12 0.49 ]
 [ -0.40   -0.20-0.45 0.26 ]
 [ -0.390.03-0.39-0.36 ]


I hope the formatting comes out ok , I did this on a Mac !

Glenn

[[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] Minimization Problem

2009-01-18 Thread Stephan Kolassa

Hi Glenn,

perhaps I'm misunderstanding your problem, but it seems to me that the 
zero vector (yielding a zero vector after the multiplication) will 
happily minimize everything you want.


Apart from that, you may want to look at the Optimization Task View on CRAN.

Good luck,
Stephan


glenn schrieb:

Dear All,

Could someone give me some pointers (just a guide as to what functions I
need to look at would be fine)
as to how I go about this simple problem please;

The problem looks like this;

Choose x1 to x4 such that you minimize the MAXIMUM ABSOLUTE value returned
in the vector result of this matrix problem;

[x1,x2,x3,x4].[ -0.38   -0.52 0.68-0.29 ]
  [ -0.39   -0.42-0.12 0.49 ]
  [ -0.40   -0.20-0.45 0.26 ]
  [ -0.390.03-0.39-0.36 ]
 


I hope the formatting comes out ok , I did this on a Mac !

Glenn

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