search for: zhaoxing731

Displaying 9 results from an estimated 9 matches for "zhaoxing731".

2011 Jan 03
3
matrices call a function element-wise
Hello I have 4 1000*1000 matrix A,B,C,D. I want to use the corresponding element of the 4 matrices. Using the "for loop" as follow: E<-o for (i in 1:1000) {for (j in 1:1000) { E<-fisher.test(matrix(c(A[i][j],B[i][j],C[i][j],D[i][j]),2))#call fisher.test for every element } } It is so time-consuming Need vectorization Yours sincerely ZhaoXing Department of
2011 Jan 07
4
how to calculate this natural logarithm
Hello I want to calculate natural logarithm of sum of combinations as follow: (R code) { com_sum=choose(2000000,482)*choose(1000000,118)+choose(2000000,483)*choose(1000000,117)+...+choose(2000000,i)*choose(1000000,600-i)+...+choose(2000000,600)*choose(1000000,0) #calculate the sum result=log(com_sum) #calculate the log of the sum } But
2011 Jan 11
1
how to use "apply" function partial to each vector of a matrix
Hello Suppose I have a matrix mat=(1:16,2) [,1] [,2] [,3] [,4] [1,] 1 5 9 13 [2,] 2 6 10 14 [3,] 3 7 11 15 [4,] 4 8 12 16 I just want to use the "apply" function to the matrix partially there is a vector end=c(2,3,1,3) #sum the 1st 2 numbers of the 1st column #sum the 1st 3 numbers of the 2nd column #sum the 1st number of the 3rd column
2011 Jan 11
1
how to coerce part of each column of a matrix to a vector and merge them
Hello Suppose I have a matrix mat=(1:16,2) [,1] [,2] [,3] [,4] [1,] 1 5 9 13 [2,] 2 6 10 14 [3,] 3 7 11 15 [4,] 4 8 12 16 there is a vector end=c(2,3,1,3) #coerce the 1st 2 numbers of the 1st column to a vector [1] 1 2 #coerce the 1st 3 numbers of the 2nd column and append it to the previous vector [1] 1 2 5 6 7 #coerce the 1st number of
2011 Feb 11
3
How can we make a vector call a function element-wise efficiently?
Hello I have a time-comsuming program which need to simplify, I have tested the annotated program as follow: > #define function which will be call > calsta <- function(c, n=100000) + { + i <- seq(from=0, length=c) + logx <- lchoose(NT-n, CT-i) + lchoose(n, i) + logmax <- max(logx) + logmax + log(sum(exp(logx - logmax))) + } > CT=6000 #assignment to CT >
2011 Feb 07
1
how to return multipy matrix in a function
Hello I have a 100*100 matrix which is from a intensive computation, e.g. mat. Is there any method/function that return the max of every row and the subscript of maximum value simultaneously #define the function > returnfunction<-function(x){ + value<-apply(x,1,max) + index<-apply(x,1,which.max) + } > mat<-matrix(c(3,5,7,2,1,10,4,3,2),3)#initilize the matrix for test >
2011 Feb 12
1
how to improve the precison of this calculation?
Hello T I want to order some calculation "result", there will be lots of "result" that need to calculate and order PS: the "result" is just a intermediate varible and ordering them is the very aim # problem: # For fixed NT and CT, and some pair (c,n). order the pair by corresponding result # c and n are both random variable CT<-6000 #assignment to CT
2011 Jan 10
0
how to create and manage a matrix with vector of different length
Hello I have a data consisting of 245 counties, including the population, number of illness and the geographical information of each county. Fixing each county, I want to sort the other county by distance, which can make a 245*245 matrix with each cell is the corresponding index of the county, e.g. the 3rd row of the matrix is a vector of descending order of the 245 indices, maybe
2013 Apr 06
2
How to plot several years data with date information by months?
Hi, all I have a medium sized data, 6 years. Each observation is a case with a date variable, such as '2004-08-02'. Some of the months didn't occur a case. I want to plot the 6 years data by month, and the Y_axis is the freqency of cases for each month, meaning 12*6=72 bars or points in the figure. I though of a method, 1st, using the months function, then ploting. But I need to