similar to: Weighted.mean(x,wt) vs. t(x) %*% wt

Displaying 20 results from an estimated 7000 matches similar to: "Weighted.mean(x,wt) vs. t(x) %*% wt"

2008 Mar 10
1
crossprod is slower than t(AA)%*BB
Dear Rdevelopers The background for this email is that I was helping a PhD student to improve the speed of her R code. I suggested to replace calls like t(AA)%*% BB by crossprod(AA,BB) since I expected this to be faster. The surprising result to me was that this change actually made her code slower. > ## Examples : > > AA <- matrix(rnorm(3000*1000),3000,1000) > BB <-
2005 Aug 05
6
Computing sums of the columns of an array
Hi, I have a 5x731 array A, and I want to compute the sums of the columns. Currently I do: apply(A, 2, sum) But it turns out, this is slow: 70% of my CPU time is spent here, even though there are many complicated steps in my computation. Is there a faster way? Thanks, Martin
2009 Dec 14
1
New version weighted mean differs from the old one (PR#14142)
Full_Name: Myung-Hoe Huh Version: 2.10 OS: Windows Submission from: (NULL) (116.120.84.194) New Version (2.10.0) weighted mean produces unreasonable result: see below. wt <- c(5, 5, 4, 1)/15 x <- c(3.7,3.3,3.5,2.8) x[4] <- NA (xm <- weighted.mean(x,wt,na.rm=T)) Outcome is > (xm <- weighted.mean(x,wt,na.rm=T)) [1] 3.266667 The number is obtained
2011 Dec 08
1
sum of deviations from the weighted mean
Hi all. I tried to calculate sum of deviations from the weighted mean and i didn't get what i expected - 0. Here is an example: > wt <- c(10,25,38,22,5) > x <- 6:10 > wm <- weighted.mean(x,wt) > (x-wm)*wt [1] -18.70 -21.75 4.94 24.86 10.65 > sum((x-wm)*wt) [1] -1.24345e-14 With simple mean I got 0: > sum(x-mean(x)) [1] 0 Could someone explain me why we
2008 May 28
1
Grouped weighted.mean
Dear all -- I want to compute weighted.mean() for grouped rows. Data frame extract is just below. For each Key, I want the mean of IAC weighted by Wt. DP0[1:20,] Key IAC Wt 2 C3-PD030020050.PD030020050.3.12.3.0 0.765 0.8590000 3 C3-PD030020050.PD030020050.3.12.3.0 0.764 0.8449651 4 C3-PD030020050.PD030020050.3.12.3.0
2008 Jun 28
2
Parallel R
Hello, The problem I'm working now requires to operate on big matrices. I've noticed that there are some packages that allows to run some commands in parallel. I've tried snow and NetWorkSpaces, without much success (they are far more slower that the normal functions) My problem is very simple, it doesn't require any communication between parallel tasks; only that it divides
2009 Oct 10
1
many weighted means: is there a simpler way?
Hi R-users, I would like to calculate weighted mean of several variables by two factors where the weight vector is the same for all variables. Below, there is a simple example where I have only two variables: "v1","v2" both weighted by "wt" and my factors are "gender" and "year". set.seed(1) df <- data.frame(gender = rep(c("M",
2005 Apr 15
5
Pearson corelation and p-value for matrix
Hi, I was trying to evaluate the pearson correlation and the p-values for an nxm matrix, where each row represents a vector. One way to do it would be to iterate through each row, and find its correlation value( and the p-value) with respect to the other rows. Is there some function by which I can use the matrix as input? Ideally, the output would be an nxn matrix, containing the p-values
2008 Apr 17
1
Couldn't (and shouldn't) is.unsorted() be faster?
Hi, Couldn't is.unsorted() bail out immediately here (after comparing the first 2 elements): > x <- 20000000:1 > system.time(is.unsorted(x), gcFirst=TRUE) user system elapsed 0.084 0.040 0.124 > x <- 200000000:1 > system.time(is.unsorted(x), gcFirst=TRUE) user system elapsed 0.772 0.440 1.214 Thanks! H.
2014 Mar 03
2
Project: Weighting Schemes
Hello Sir, I am Reetesh Ranjan, a 3rd year undergraduate student at the *INDIAN INSTITUTE OF TECHNOLOGY BHU, Varanasi-*one of the premier engineering colleges of India. I have gone through your webpage thoroughly and I am very interested in the work that you are undertaking on *Project: Weighting Schemes.*. I earnestly wish to work under your guidance, learn and progress through this experience.
2007 Feb 13
1
simulating from Langevin distributions
Dear all, I have been looking for a while for ways to simulate from Langevin distributions and I thought I would ask here. I am ok with finding an algorithmic reference, though of course, a R package would be stupendous! Btw, just to clarify, the Langevin distribution with (mu, K), where mu is a vector and K>0 the concentration parameter is defined to be: f(x) = exp(K*mu'x) / const where
2005 Feb 25
3
Loops and dataframes
Hi, I am experiencing a long delay when using dataframes inside loops and was wordering if this is a bug or not. Example code: > st <- rep(1,100000) > ed <- rep(2,100000) > for(i in 1:length(st)) st[i] <- ed[i] # works fine > df <- data.frame(start=st,end=ed) > for(i in 1:dim(df)[1]) df[i,1] <- df[i,2] #takes for ever R: R 2.0.0 (2004-10-04) OS: Linux, Fedora Core 2
2004 Dec 06
6
how to get how many lines there are in a file.
hi all If I wanna get the total number of lines in a big file without reading the file's content into R as matrix or data frame, any methods or functions? thanks in advance. Regards
2005 May 08
3
Light-weight data.frame class: was: how to add method to .Primitive function
Hi, Encouraged by a tip from Simon Urbanek I tried to use the S3 machinery to write a faster version of the data.frame class. This quickly hits a snag: the "[.default"(x, i) for some reason cares about the dimensionality of x. In the end there is a full transcript of my R session. It includes the motivation for writing the class and the problems I have encountered. As a result I see
2005 Oct 05
2
eliminate t() and %*% using crossprod() and solve(A,b)
Hi I have a square matrix Ainv of size N-by-N where N ~ 1000 I have a rectangular matrix H of size N by n where n ~ 4. I have a vector d of length N. I need X = solve(t(H) %*% Ainv %*% H) %*% t(H) %*% Ainv %*% d and H %*% X. It is possible to rewrite X in the recommended crossprod way: X <- solve(quad.form(Ainv, H), crossprod(crossprod(Ainv, H), d)) where quad.form() is a little
2005 Apr 27
1
RE: [R] when can we expect Prof Tierney's compiled R?
Luke, Thank you for sharing the benchmark results. The improvement is very substantial, I am looking forward to the release of the byte compiler! The arithmetic shows that x[i]<- is still the bottleneck. I suspect that this is due to a very involved dispatching/search for the appropriate function on the C level. There might be significant gain if loops somehow cached the result of the initial
2009 Mar 04
1
flaw in CRAN package "wavelets": Daubechies "d8" not recognized by function wt.filter
> wt.filter("d8") #### HOW COME ???? Error in validObject(.Object) : invalid class "wt.filter" object: invalid object for slot "transform" in class "wt.filter": got class "function", should be or extend class "character" > wt.filter("d10") # OK An object of
2005 Jan 20
2
Creating a custom connection to read from multiple files
Hello, is it possible to create my own connection which I could use with read.table or scan ? I would like to create a connection that would read from multiple files in sequence (like if they were concatenated), possibly with an option to skip first n lines of each file. I would like to avoid using platform specific scripts for that... (currently I invoke "/bin/cat" from R to create a
2007 Dec 18
1
PCA - "cov.wt(z) : 'x' must contain finite values only"
I am trying to run PCA on a matrix (the first column and row are headers). There are several cells with NA's. When I run PCA with the following code: ______________________________________ setwd("I:/PCA") AsianProp<-read.csv("Matrix.csv", sep=",", header=T, row.names=1) attach(AsianProp) AsianProp AsianProp.pca<-princomp(AsianProp, na.omit)
2009 Feb 21
0
problems in package "wavelets" function "wt.filter"
> wt.filter("d8") Error in validObject(.Object) : invalid class "wt.filter" object: invalid object for slot "transform" in class "wt.filter": got class "function", should be or extend class "character" How come ? The above function works fine with the other Daubechies filters. Thank you. Best regards, Maura tutti i