Skip to content

About infinite value

12 messages · Peter Dalgaard, Mendiburu, Felipe (CIP), Bernzweig, Bruce (Consultant) +3 more

#
Hi everyone

I have a problem about "infinite".
If I type 10^308, R shows "1e+308"
When I type 10^309, R shows "Inf"
So, we know if a value is large than 1.XXXe+308, R will show "Inf"
How can i do let the value, like "10^400" ,typed in R to show the word
"1e+400" not "Inf"
#
arigado wrote:
1. You can't, due to the computer representation of floating point numbers.

2. Package brobdingnag lets you do it anyway.
#
I think that the best thing is to work in logarithmic way, to avoid the limitations of the CPU. 
If y = 10^400, to do y=400*log(10), to change all you formulate to the logarithmic way and the final result to apply the antilogarithm. 
 
Felipe de Mendiburu. 
Professor of statistic 
Agrarian National University -La Molina - PERU 

________________________________

De: r-help-bounces at stat.math.ethz.ch en nombre de arigado
Enviado el: lun 23/07/2007 4:17
Para: r-help at stat.math.ethz.ch
Asunto: [R] About infinite value




Hi everyone

I have a problem about "infinite".
If I type 10^308, R shows "1e+308"
When I type 10^309, R shows "Inf"
So, we know if a value is large than 1.XXXe+308, R will show "Inf"
How can i do let the value, like "10^400" ,typed in R to show the word
"1e+400" not "Inf"

--
View this message in context: http://www.nabble.com/About-infinite-value-tf4128557.html#a11740491
Sent from the R help mailing list archive at Nabble.com.

______________________________________________
R-help at stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
1 day later
#
Hi,

I've created the following two matrices (mat1 and mat2) and a function
(f) to calculate the correlations between the two on a row by row basis.

	mat1 <- matrix(sample(1:500,50), ncol = 5, 
		dimnames=list(paste("row", 1:10, sep=""), 
		paste("col", 1:5, sep="")))

	mat2 <- matrix(sample(501:1000,50), ncol = 5, 
		dimnames=list(paste("row", 1:10, sep=""), 
		paste("col", 1:5, sep="")))

	f <- function(x,y) cor(x,y)

When the matrices are squares (# rows = # columns) I have no problems.

However, when they are not (as in the example above with 5 columns and
10 rows), I get the following error:
Error in cor(x, y, na.method, method == "kendall") : 
        incompatible dimensions

Any help would be appreciated.  Thanks!

- Bruce



**********************************************************************
Please be aware that, notwithstanding the fact that the pers...{{dropped}}
#
Your apply is trying to take the correlations of the rows of mat1 with the
columns of mat2 which, of course, does not work if they have different
numbers of columns. I think you mean to take the correlations of the columns
of mat1 with the columns of mat2.  For example, to take the correlations
of the 5 columns of mat1 with the first 4 columns of mat2 try:
col1       col2       col3       col4
col1 -0.34624254 -0.2669519 -0.2705077  0.2183249
col2 -0.26553255 -0.2687643 -0.0865895  0.1819025
col3  0.19474613 -0.2334986  0.1746522  0.2326915
col4  0.09328338  0.5117784  0.2413143 -0.3374916
col5  0.27519716  0.1605331 -0.4057137  0.3282105
On 7/24/07, Bernzweig, Bruce (Consultant) <bbernzwe at bear.com> wrote:
#
are you positive that your function is doing what you expect it to do?

it looks like you want something like:

sapply(1:10, function(i) cor(mat1[i,], mat2[i,]))

b
On Jul 24, 2007, at 11:05 AM, Bernzweig, Bruce ((Consultant)) wrote:

            
#
Thanks Gabor!

You state that my apply is taking rows of mat1 with columns of mat2.

Is this because I have the y=mat2 parameter?
Actually, what I would like is to run the correlations on a row against
row basis:  mat1 row1 x mat2 row1, etc.

Thanks again,

- Bruce


-----Original Message-----
From: Gabor Grothendieck [mailto:ggrothendieck at gmail.com] 
Sent: Tuesday, July 24, 2007 11:31 AM
To: Bernzweig, Bruce (Consultant)
Cc: r-help at stat.math.ethz.ch
Subject: Re: [R] apply & incompatible dimensions error

Your apply is trying to take the correlations of the rows of mat1 with
the
columns of mat2 which, of course, does not work if they have different
numbers of columns. I think you mean to take the correlations of the
columns
of mat1 with the columns of mat2.  For example, to take the correlations
of the 5 columns of mat1 with the first 4 columns of mat2 try:
col1       col2       col3       col4
col1 -0.34624254 -0.2669519 -0.2705077  0.2183249
col2 -0.26553255 -0.2687643 -0.0865895  0.1819025
col3  0.19474613 -0.2334986  0.1746522  0.2326915
col4  0.09328338  0.5117784  0.2413143 -0.3374916
col5  0.27519716  0.1605331 -0.4057137  0.3282105
On 7/24/07, Bernzweig, Bruce (Consultant) <bbernzwe at bear.com> wrote:
basis.
pers...{{dropped}}
http://www.R-project.org/posting-guide.html
**********************************************************************
Please be aware that, notwithstanding the fact that the pers...{{dropped}}
#
Thanks Benilton,

I know what I want to do, just not sure how to do it using R.  The help
documentation is not very clear.

What I am trying to do is calculate correlations on a row against row
basis:  mat1 row1 x mat2 row1, mat1 row1 x mat2 row2, ... mat1 row1 x
mat2 row-n, mat1 row-n, mat2 row-n

- Bruce

-----Original Message-----
From: Benilton Carvalho [mailto:bcarvalh at jhsph.edu] 
Sent: Tuesday, July 24, 2007 11:31 AM
To: Bernzweig, Bruce (Consultant)
Cc: r-help at stat.math.ethz.ch
Subject: Re: [R] apply & incompatible dimensions error

are you positive that your function is doing what you expect it to do?

it looks like you want something like:

sapply(1:10, function(i) cor(mat1[i,], mat2[i,]))

b
On Jul 24, 2007, at 11:05 AM, Bernzweig, Bruce ((Consultant)) wrote:

            
**********************************************************************
Please be aware that, notwithstanding the fact that the pers...{{dropped}}
#
that's garbor's suggestion then.
sorry for the misunderstanding. :-)
b
On Jul 24, 2007, at 11:35 AM, Bernzweig, Bruce ((Consultant)) wrote:

            
#
Then try this:

cor(t(mat1), t(mat2))

Also note

1. the above implies that mat1 and mat2 must have the same
number of columns since if x and y are vectors cor(x,y) only makes
sense if they have the same length.

2. the usual convention is that variables are stored as columns
andt that rows correspond to cases so typically you would have
(in terms of your mat1 and mat2):

Mat1 <- t(mat1)
Mat2 <- t(mat2)

and then use Mat1 and Mat2, e.g. cor(Mat1, Mat2)
On 7/24/07, Bernzweig, Bruce (Consultant) <bbernzwe at bear.com> wrote:
#
Thanks for the explanation.

As for the rows/columns thing, the data I receive is given to me in that
way.  I currently read it in using read.csv.  Is there a function I
should look at that can take that and transpose it or should I just
process the data first outside of R?

Thanks,

- Bruce

-----Original Message-----
From: Gabor Grothendieck [mailto:ggrothendieck at gmail.com] 
Sent: Tuesday, July 24, 2007 11:43 AM
To: Bernzweig, Bruce (Consultant)
Cc: r-help at stat.math.ethz.ch
Subject: Re: [R] apply & incompatible dimensions error

Then try this:

cor(t(mat1), t(mat2))

Also note

1. the above implies that mat1 and mat2 must have the same
number of columns since if x and y are vectors cor(x,y) only makes
sense if they have the same length.

2. the usual convention is that variables are stored as columns
andt that rows correspond to cases so typically you would have
(in terms of your mat1 and mat2):

Mat1 <- t(mat1)
Mat2 <- t(mat2)

and then use Mat1 and Mat2, e.g. cor(Mat1, Mat2)
On 7/24/07, Bernzweig, Bruce (Consultant) <bbernzwe at bear.com> wrote:
against
correlations
function
problems.
and
**********************************************************************
**********************************************************************
Please be aware that, notwithstanding the fact that the pers...{{dropped}}
4 days later
#
I think that the best thing is to work in logarithmic way, to avoid the
limitations of the CPU. 
If y = 10^400, to do y=400*log(10), to change all you formulate to the
logarithmic way and the final result to apply the antilogarithm. 
 
Felipe de Mendiburu. 
Professor of statistic 
Agrarian National University -La Molina - PERU 

Thank you.
Thanks your method.