[R] 0^0 computation in R : Why it is defined 1 in R ?
Dear R helpers, today I found something interesting in R. 0^0 gives value 1 in R. But it is undefined in mathematics. During debugging a R code, I found it and it effects my program severely. So my question is why it is defined 1 in R? Is there any particular reason or its a bug in the R software? Here is one demo: * ff=function(u){ return( x^0 * u) } x=0 zz=integrate(ff,lower=0,upper=1)$value zz source('~/.active-rstudio-document') zz [1] 0.5 * Looking forward to hear any response. Regards, Ritwik Bhattacharya Indian Statistical Institute Kolkata __ 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] Query on R plot : Unequispaced label on x-axis
Dear R users, I want to plot a one variable continuous function f(x) vs x, x=[0,1]. Say for example: f(x)= x^2. Now, using the command plot(f~x) I will get a curve where the range of x-axis is [0,1] with all equispaced label. But, I need something else, and that is: my curve will be such that 80% on x-axis the range would be [0,0.5] and the rest 20% would contain [0.5,1]. Let me draw informally here. Say, the line below is my x-axis in graph and my plotting points are like: 0 0.01 0.10.5 1 Any help or suggestion will be highly appreciable. Regards, Ritwik ISI Kolkata __ 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] R Error : Error in vector(list, gamma(n + 1)) : vector size specified is too large
Dear R-listers, I am giving part of my R code : ### n=15 m=1 library(partitions) library(gregmisc) library(combinat) x = t(restrictedparts(n-m,m)) l = length(x[,1]) for(u in 1:l){ A= unique(matrix( unlist(permn(x[u,])), ncol=m, byrow=TRUE )) } ### when I put m=1 error shows : Error in vector(list, gamma(n + 1)) : vector size specified is too large . But it works fine with other values of m ( n). Any suggestion will be highly accepted. Ritwik Bhattacharya SRF, Indian Statistical Institute Kolkata This mail is scanned by Ironport __ 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] R Error : Error in vector(list, gamma(n + 1)) : vector size specified is too large
Dear R-listers, I am giving part of my R code : ### n=15 m=1 library(partitions) library(gregmisc) library(combinat) x = t(restrictedparts(n-m,m)) l = length(x[,1]) for(u in 1:l){ A= unique(matrix( unlist(permn(x[u,])), ncol=m, byrow=TRUE )) } ### when I put m=1 error shows : Error in vector(list, gamma(n + 1)) : vector size specified is too large . But it works fine with other values of m ( n). Any suggestion will be highly accepted. Ritwik Bhattacharya SRF, Indian Statistical Institute Kolkata This mail is scanned by Ironport __ 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 Error : DATA to MATRIX
Thanks David, your suggestion works fine.btw I have another question..If I set (n,m) little bit large, say (n=20,m=10), R cannot handle the large data frame generated through expand.grid.Is there any way to increase R-memory so that I can tackle large data.frame in R ? regards ritwik On Mar 23, 2012, at 2:53 AM, ritwi...@isical.ac.in wrote: Dear Sir/Madam, I'm getting a problem with a R-code which converts a data frame to a matrix. It first generate a (m^(n-m) * m) matrix A and then regenerate another matrix B having less dimension than A which satisfy some condition. Now I wish to assign each row of B to a vector as individual. My problem is when I set any choice of (n,m) except m=1 it works fine but setting m=1 I got the error : Error in B[i, ] : incorrect number of dimensions. Moreover if (n,m) is large (say, (20,8)) I got the error : Error: cannot allocate vector of size 3.0 Gb. I know this is due to large dimension of matrix A. How to solve this problem. My code is given below: ** n=5 m=3 R=numeric(0) # Generate all possible m-tuple ( variables having range 0 to n ) in a ( m^(n-m) * m ) matrix r = expand.grid(rep(list(0:(n-m)), m)) write.table(r,file=test.txt,row.names=FALSE,col.names=FALSE) a= read.table(file=test.txt,sep=,header=FALSE) A= data.matrix(a) #. # Generate matrix whose rowsum = n-m meet.crit = apply(A, 1, function(.row) any((sum(.row)) == n-m)) # criteron for being rowsum = n cbind(A, meet.crit) # Checking rowsum = n for each row -m B=A[meet.crit,] At this point the default behavior of the [ function is to return a vector rather than a matrix. You need to add drop=FALSE as an additional argument. Read the help page for ?[. # Generate matrix #. for(i in 1:choose(n-1,m-1)){ R=B[i,] } *** Can you please help me how to get rid of these errors. Thanking you in advance. Regards Ritwik Bhattacharya Senior Research Fellow SQC OR UNIT, KOLKATA INDIAN STATISTICAL INSTITUTE -- David Winsemius, MD West Hartford, CT This mail is scanned by Ironport This mail is scanned by Ironport __ 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] R Error : DATA to MATRIX
Dear Sir/Madam, I'm getting a problem with a R-code which converts a data frame to a matrix. It first generate a (m^(n-m) * m) matrix A and then regenerate another matrix B having less dimension than A which satisfy some condition. Now I wish to assign each row of B to a vector as individual. My problem is when I set any choice of (n,m) except m=1 it works fine but setting m=1 I got the error : Error in B[i, ] : incorrect number of dimensions. Moreover if (n,m) is large (say, (20,8)) I got the error : Error: cannot allocate vector of size 3.0 Gb. I know this is due to large dimension of matrix A. How to solve this problem. My code is given below: ** n=5 m=3 R=numeric(0) # Generate all possible m-tuple ( variables having range 0 to n ) in a ( m^(n-m) * m ) matrix r = expand.grid(rep(list(0:(n-m)), m)) write.table(r,file=test.txt,row.names=FALSE,col.names=FALSE) a= read.table(file=test.txt,sep=,header=FALSE) A= data.matrix(a) #. # Generate matrix whose rowsum = n-m meet.crit = apply(A, 1, function(.row) any((sum(.row)) == n-m)) # criteron for being rowsum = n cbind(A, meet.crit) # Checking rowsum = n for each row -m B=A[meet.crit,] # Generate matrix #. for(i in 1:choose(n-1,m-1)){ R=B[i,] } *** Can you please help me how to get rid of these errors. Thanking you in advance. Regards Ritwik Bhattacharya Senior Research Fellow SQC OR UNIT, KOLKATA INDIAN STATISTICAL INSTITUTE Voice : +91 9051253944 This mail is scanned by Ironport __ 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] R code Error : Hybrid Censored Weibull Distribution
Dear Sir/madam, I'm getting a problem with a R-code which calculate Fisher Information Matrix for Hybrid Censored Weibull Distribution. My problem is that: when I take weibull(scale=1,shape=2) { i.e shape1} I got my desired result but when I take weibull(scale=1,shape=0.5) { i.e shape1} it gives error : Error in integrate(int2, lower = 0, upper = t) : the integral is probably divergent. I could not found any theoretical interpretation of it. I'm sending the code : # f3-function(t,r){ #calculation for t1 fb1-function(t,r){ v1-numeric(0) for(j in 1:r){ int1-function(x1){ int_1- (1/p+log(x1/lamda))^2 * j * choose(n,j) * (pweibull(x1,shape=p,scale=lamda))^(j-1) * (1 - pweibull(x1,shape=p,scale=lamda))^(n-j) * dweibull(x1,shape=p,scale=lamda) int_1 } v1[j]-integrate(int1,lower=0,upper=t)$value } sum(v1) } #calculation for t2 fb2-function(t,r){ v2-numeric(0) for(j in 1:r){ int2-function(x2){ int_2- (1/p+log(x2/lamda))*(-p/lamda) * j * choose(n,j) * (pweibull(x2,shape=p,scale=lamda))^(j-1) * (1 - pweibull(x2,shape=p,scale=lamda))^(n-j) * dweibull(x2,shape=p,scale=lamda) int_2 } v2[j]-integrate(int2,lower=0,upper=t)$value } sum(v2) } #calculation for t3 fb3-function(t,r){ v3-numeric(0) for(j in 1:r){ int3-function(x3){ int_3- (p/lamda)^2 * j * choose(n,j) * (pweibull(x3,shape=p,scale=lamda))^(j-1) * (1 - pweibull(x3,shape=p,scale=lamda))^(n-j) * dweibull(x3,shape=p,scale=lamda) int_3 } v3[j]-integrate(int3,lower=0,upper=t)$value } sum(v3) } a-c(fb1(t,r),fb2(t,r),fb2(t,r),fb3(t,r)) A-matrix(a,nrow=2,ncol=2,byrow=TRUE) C-solve(A) func1-function(u1){ u11- (log(-log(1-u1)))^2 u11 } m1-(C[1,1]/p^4)*integrate(func1,lower=0,upper=1)$value func2-function(u2){ u22- log(-log(1-u2)) u22 } m2- (-2)*C[1,2]*(1/(p^2 *lamda))*integrate(func2,lower=0,upper=1)$value m3- C[2,2]/lamda^2 m-m1+m2+m3 m } output=f3(5,10) ## Moreover When I consider f3,fb1,fb2,fb3 all are functions of single variable t ,desired results come but in case of two variables the problem arises. Here t is Real Number and r is Integer. I'm suffering this problem since last three months. Please anyone help me out. Thanking you in advance. Regards Ritwik Bhattacharya Senior Research Fellow SQC OR UNIT, KOLKATA INDIAN STATISTICAL INSTITUTE Voice : +91 9051253944 This mail is scanned by Ironport __ 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.