[R] cleaning up a vector

2010-10-01 Thread mlarkin
I calculated a large vector.  Unfortunately, I have some measurement error
in my data and some of the values in the vector are erroneous.  I ended up
wih some Infs and NaNs in the vector.  I would like to filter out the Inf
and NaN values and only keep the values in my vector that range from 1 to
20.  Is there a way to filter out Infs and NaNs in R and end up with a
clean vector?

Mike

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] [Fwd: Re: cleaning up a vector]

2010-10-01 Thread mlarkin
It turns out I didn't have to filter out the 1-20 values.

The code of  x[is.finite(x)] did the trick.

Thanks!!!

Mike




 Original Message 
Subject: Re: [R] cleaning up a vector
From:Henrique Dallazuanna www...@gmail.com
Date:Fri, October 1, 2010 1:55 pm
To:  mlar...@rsmas.miami.edu
Cc:  r-help@r-project.org
--

Try this:

x[is.finite(x)]


On Fri, Oct 1, 2010 at 2:51 PM, mlar...@rsmas.miami.edu wrote:

 I calculated a large vector.  Unfortunately, I have some measurement error
 in my data and some of the values in the vector are erroneous.  I ended up
 wih some Infs and NaNs in the vector.  I would like to filter out the Inf
 and NaN values and only keep the values in my vector that range from 1 to
 20.  Is there a way to filter out Infs and NaNs in R and end up with a
 clean vector?

 Mike

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

   Try this:
   x[is.finite(x)]

   On Fri, Oct 1, 2010 at 2:51 PM, [1]mlar...@rsmas.miami.edu wrote:

 I calculated a large vector.  Unfortunately, I have some measurement error
 in my data and some of the values in the vector are erroneous.  I ended up
 wih some Infs and NaNs in the vector.  I would like to filter out the Inf
 and NaN values and only keep the values in my vector that range from 1 to
 20.  Is there a way to filter out Infs and NaNs in R and end up with a
 clean vector?
 Mike
 __
 [2]r-h...@r-project.org mailing list
 [3]https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide
 [4]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

References

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


[R] maximum likelihood problem

2010-10-01 Thread mlarkin
I am trying to figure out how to run maximum likelihood in R.  Here is my
situation:

I have the following equation:
equation-(1/LR-(exp(-k*T)*LM)*(1-exp(-k)))

LR, T, and LM are vectors of data.  I want to R to change the value of k
to maximize the value of equation.

My attempts at optim and optimize have been unsuccessful.  Are these the
recommended functions that I should use to maximize my equation?

With optim I wanted the function to be maximized so I had to make the
fnscale negative.  Here is what I put:

L-optim(k,equation,control=(fnscale=-1))

My result:   Error: could not find function fn


Here is what I put for optimize:

L-optimise(equation,k,maximum=TRUE)

My result:   Error: 'xmin' not less than 'xmax'

Any advise would be greatly appreciated.
Mike

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] [Fwd: RE: maximum likelihood problem]

2010-10-01 Thread mlarkin
I forgot to add that I first gave a starting value for K.

Nonlinear least squares won't work because my errors are not normally
distributed.

Any advide on my maximum likelihood function would be greatly appreciated.


 Original Message 
Subject: RE: [R] maximum likelihood problem
From:Ravi Varadhan rvarad...@jhmi.edu
Date:Fri, October 1, 2010 5:10 pm
To:  mlar...@rsmas.miami.edu
 r-help@r-project.org
--

Do you want to do a nonlinear least-squares estimation (which is MLE if the
errors are Gaussian)?

If so, you have to define a function that takes the parameter (k) and data
matrix (LR, T, LM), as arguments, and returns a scalar, which is the
residual sum of squares.  Then you can optimize (minimize) that function.

Ravi.

-Original Message-
From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On
Behalf Of mlar...@rsmas.miami.edu
Sent: Friday, October 01, 2010 4:40 PM
To: r-help@r-project.org
Subject: [R] maximum likelihood problem

I am trying to figure out how to run maximum likelihood in R.  Here is my
situation:

I have the following equation:
equation-(1/LR-(exp(-k*T)*LM)*(1-exp(-k)))

LR, T, and LM are vectors of data.  I want to R to change the value of k
to maximize the value of equation.

My attempts at optim and optimize have been unsuccessful.  Are these the
recommended functions that I should use to maximize my equation?

With optim I wanted the function to be maximized so I had to make the
fnscale negative.  Here is what I put:

L-optim(k,equation,control=(fnscale=-1))

My result:   Error: could not find function fn


Here is what I put for optimize:

L-optimise(equation,k,maximum=TRUE)

My result:   Error: 'xmin' not less than 'xmax'

Any advise would be greatly appreciated.
Mike

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