search for: componentwise

Displaying 10 results from an estimated 10 matches for "componentwise".

2008 Dec 30
3
Componentwise means of a list of matrices?
...h entry of which is a matrix of constant dimensions. Is there a good way (i.e., not using a for loop) to apply a mean to each matrix entry *across list entries*? Example: foo <- list(rbind(c(1,2,3),c(4,5,6)),rbind(c(7,8,9),c(10,11,12))) some.sort.of.apply(foo,FUN=mean) I'm looking for a componentwise mean across the two entries of foo, i.e., the following output: [,1] [,2] [,3] [1,] 4 5 6 [2,] 7 8 9 [NB. My "real" application involves trimming and psych::winsor(), so anything that generalizes to this would be extra good.] I've been looking at apply and...
2011 Nov 16
1
Theil decomposition
I came across the package 'ineq' that computes a variety of inequality measures (e.g. gini, theil etc). I want to compute the Theil index (racial segregation) and decompose the total into sub-components (by geog levels). I think the package doesn't report the decomposition (correct me if I'm wrong). Just wonder is that available elsewhere? K.
2020 Feb 21
0
function(x) !is.na(x) & x "is_true(.)" etc. was: [R] How to index..
...at "!x" is faster than "x == 0", but does not (yet!) work for complex ## if we did these in C, would gain a factor 2 (or so): is0 <- function(x) !is.na(x) & x == 0 isN0 <- function(x) is.na(x) | x != 0 is1 <- function(x) !is.na(x) & x # also == "isTRUE componentwise" {{Note that here 0 <==> FALSE and non-0 <==> TRUE , and I had preferred the shorter words to the longer ones in the Matrix pkg, not the least as '0' is relevant also for talking/programming about sparse matrices .. }} ... and then there are all* and any* vers...
2010 Jul 12
3
How to mean, min lists and numbers
I would like to sum/mean/min a list of lists and numbers to return the related lists. -1+2*c(1,1,0)+2+c(-1,10,-1) returns c(2,13,0) but sum(1,2*c(1,1,0),2,c(-1,10,-1)) returns 15 not a list. Using the suggestions of Gabor Grothendieck, Reduce('+',list(-1,2*c(1,1,0),2,c(-1,10,-1))) returns what we want, c(2,13,0). However, it seems that this way does not work to mean/min. So, how to
2015 Mar 03
2
[R] Why does R replace all row values with NAs
...7 7 8 7 > 10 10 11 10 > Bill Dunlap > TIBCO Software > wdunlap tibco.com Yes; the Matrix package has had these is0 <- function(x) !is.na(x) & x == 0 isN0 <- function(x) is.na(x) | x != 0 is1 <- function(x) !is.na(x) & x # also == "isTRUE componentwise" namespace hidden for a while [note the comment of the last one!] and using them for readibility in its own code. Maybe we should (again) consider providing some versions of these with R ? The Matrix package also has had fast allFalse <- all0 <- function(x) .Call(R_all0, x) anyFals...
2015 Mar 03
2
[R] Why does R replace all row values with NAs
...; TIBCO Software >> > wdunlap tibco.com >> >> Yes; the Matrix package has had these >> >> is0 <- function(x) !is.na(x) & x == 0 >> isN0 <- function(x) is.na(x) | x != 0 >> is1 <- function(x) !is.na(x) & x # also == "isTRUE componentwise" > > Note that using %in% to block propagation of NAs is about 2x faster: > > > x <- sample(c(NA_integer_, 1:10000), 500000, replace=TRUE) > > microbenchmark(as.logical(x) %in% TRUE, !is.na(x) & x) > Unit: milliseconds > expr min...
2011 Jan 07
2
how to run linear regression models at once
hey, folks, I have two very simple questions. I am not quite sure if I can do this using R. so, I am analyzing a large data frame with thousands of variables. For example: Dependent variables: d1, d2, d3 (i.e., there are three dependent variables) Independent variables: s1, s2, s3, ......s1000 (i.e., there are 1000 independent variables) now I want to run simple linear regression analyses of
2015 Mar 03
0
[R] Why does R replace all row values with NAs
...t; Bill Dunlap > > TIBCO Software > > wdunlap tibco.com > > Yes; the Matrix package has had these > > is0 <- function(x) !is.na(x) & x == 0 > isN0 <- function(x) is.na(x) | x != 0 > is1 <- function(x) !is.na(x) & x # also == "isTRUE componentwise" Note that using %in% to block propagation of NAs is about 2x faster: > x <- sample(c(NA_integer_, 1:10000), 500000, replace=TRUE) > microbenchmark(as.logical(x) %in% TRUE, !is.na(x) & x) Unit: milliseconds expr min lq mean median...
2015 Mar 03
0
[R] Why does R replace all row values with NAs
...; > wdunlap tibco.com >>> >>> Yes; the Matrix package has had these >>> >>> is0 <- function(x) !is.na(x) & x == 0 >>> isN0 <- function(x) is.na(x) | x != 0 >>> is1 <- function(x) !is.na(x) & x # also == "isTRUE componentwise" >>> >> >> Note that using %in% to block propagation of NAs is about 2x faster: >> >> > x <- sample(c(NA_integer_, 1:10000), 500000, replace=TRUE) >> > microbenchmark(as.logical(x) %in% TRUE, !is.na(x) & x) >> Unit: milliseconds >&...
2012 Aug 27
3
How to generate a matrix of Beta or Binomial distribution
Hi folks, I have a question about how to efficiently produce random numbers from Beta and Binomial distributions. For Beta distribution, suppose we have two shape vectors shape1 and shape2. I hope to generate a 10000 x 2 matrix X whose i th rwo is a sample from reta(2,shape1[i]mshape2[i]). Of course this can be done via loops: for(i in 1:10000) { X[i,]=rbeta(2,shape1[i],shape2[i]) } However,