Displaying 20 results from an estimated 2000 matches similar to: "matrices call a function element-wise"
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 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 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 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
2013 Apr 27
1
using metafor for meta-analysis of before-after studies
Hello, Dr. Viechtbauer.
I am trying to perform a meta-analyis on a group of before-after studies using Metafor. I read your webpage including your correspondence with Dr. Dewey (https://stat.ethz.ch/pipermail/r-help/2012-April/308946.html), who also conducted a similar study. These information is very hepful, but I have one additonal question which I wonder if you can give me some instruction.
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
2011 Jun 05
1
tag \href not recognised in rd doc
Hi,
I have a trouble trying to use \href in a rd doc. See example below:
\references{
\href{http://www.ncbi.nlm.nih.gov/pmc/articles/PMC2702787/}{Vaniscotte
A., Pleydell D., Raoul F., Quere J.P., Coeurdassier M., Delattre P., Li
T., Qian W., Takahashi K., Weidmann J.C., Qiu J., Giraudoux P. 2009
Modelling and spatial discrimination of small mammal assemblages: an
example from western
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
2009 Dec 30
1
Fwd: Negbin Error Warnings
Dear Clara,
Thanks for the reply. I am forwarding your message to the list, ok.
When I wrote was a way of get further information to help the helpers.
happy holidays,
milton
---------- Forwarded message ----------
From: Clara Brück <clara_brueck@web.de>
Date: 2009/12/30
Subject: Re: [R] Negbin Error Warnings
To: milton ruser <milton.ruser@gmail.com>
Dear Milton,
Thanks for
2012 Sep 25
1
REML - quasipoisson
hi
I'm puzzled as to the relation between the REML score computed by gam and
the formula (4) on p.4 here:
http://opus.bath.ac.uk/22707/1/Wood_JRSSB_2011_73_1_3.pdf
I'm ok with this for poisson, or for quasipoisson when phi=1.
However, when phi differs from 1, I'm stuck.
#simulate some data
library(mgcv)
set.seed(1)
x1<-runif(500)
x2<-rnorm(500)
2000 Nov 08
3
Strange means of numbers drawn from rpois
Dear all,
I think I must be going crazy.... If I do
> mean(rpois(1000000, 14))
I get:
[1] 13.50420
and again:
> mean(rpois(1000000, 14))
[1] 13.49896
> mean(rpois(1000000, 14))
[1] 13.50161
> mean(rpois(1000000, 15))
[1] 14.49250
> mean(rpois(1000000, 15))
[1] 14.49897
> mean(rpois(1000000, 14.5))
[1] 13.99689
> mean(rpois(1000000, 14.5))
[1] 13.9963
This was on a
platform
2000 Apr 30
2
rpois hangs (PR#530)
Full_Name: Kjetil Kjernsmo
Version: Version 1.0.0
OS: osf1
Submission from: (NULL) (129.240.28.227)
Dear all,
I have come across another really strange bug in rpois.
If I do
> rpois(1, 1000000 * rpois(1, 10000))
sometimes it hangs, and hangs...
On my XP1000 alphaev6 workstation, it seems to happen more
frequently than on other machines. I started a session on an older
computer, and from
2003 Aug 26
4
Viewing function source
I know I should probably RTFM for this question, but could someone tell me
if R supports the idea of "viewing source" on any particular function you
want to use?
If I want to "view source" on the rpois() function, for example, can I do
somethink like:
source(rpois)
To see how the function is implemented?
Regards,
Paul Meagher
Datavore Productions
50 Wood Grove Drive
2009 Oct 06
3
rpois formula
Hi all,
It's been a while since i've used R and I can't remember how to do the
following:
i have
a = rpois (100000, x)
b = rpois (100000, y)
what is the code to show that a>b, b>a and a=b to show just the number of
occurances?
at the moment when I type a>b I get a nice long list of true or false.
so i'm hoping to have the following
a>b
> 35000
b>a
> 25000
2012 Mar 16
2
Elegant Code
Hi,
Can anyone help to write a more elegant version of my code? I am sure
this can be put into a loop but I am having trouble creating the
objects b1,b2,b3,...,etc.
b1 <- rigamma(50,1,1)
theta1 <- rgamma(50,0.5,(1/b1))
sim1 <- rpois(50,theta1)
b2 <- rigamma(50,1,1)
theta2 <- rgamma(50,0.5,(1/b2))
sim2 <- rpois(50,theta2)
b3 <- rigamma(50,1,1)
theta3 <-
2006 Jul 27
3
bug with rpois (PR#9106)
The R poisson random generator rpois appears to have a bug for
theta 10 or larger. The sample mean of the pseudo variates is too
small: sample mean approx theta - 0.5.
I use Version 1.1.1 (August 15, 2000) Of R on a Dell OptiPlex computer
with the
Windows XP Professional operating system.
Has this bug been fixed in later versions?
(I found another reported rpois bug, but it appears to be
2006 Jun 01
4
A coding question
Dear List:
I have the follow code:
y <- replicate(10,replicate(8,sum(rnorm(rpois(1,5)))))
Now I need to apply the following condition to _every_ randomly generated
Normal number in the code above:
x - max(0,x-15) + max(0,x-90), where x represents the individual Normal
numbers.
In other words, the said condition needs to be applied before
replicate(...(replicate(...(sum(...))) takes place.
2000 Jan 14
2
Matrix output from drawing functions
Dear all,
I'm a bit confused about the output from functions that generates random
values, e.g. rpois. I'm using 0.65.1 on Digital UNIX alphaev6.
If I say
> rpois(10,5)
output is not unexpectedly:
[1] 4 6 5 7 6 5 2 2 5 3
but I figured that if I go:
> rpois(10,1:10)
I would get a 10x10 matrix as output, with random values for each of
the vector elements in the row vectors, but