Displaying 4 results from an estimated 4 matches for "wsum".
Did you mean:
sum
2000 Sep 17
1
Weighted Histogram
...in a given interval.
Given equal-length vectors of data 'data' and weights 'w', and breaks
(intervals) for the histogram, I calculate a weighted histogram as
follows (see MASS's 'truehist' for an unweighted histogram):
bin <- cut(data, breaks, include.lowest = TRUE)
wsums <- sapply(split( w, f = bin), sum)
prob <- wsums/(diff(breaks) * sum(w))
where 'bin' is the recoded data vector, 'wsums' is the sum of weights
across each factor in 'bin', and 'prob' is the vector of probabilities
used to plot the true histogram.
But if...
2002 Feb 06
4
Weighted median
Is there a weighted median function out there similar to weighted.mean()
but for medians? If not, I'll try implement or port it myself.
The need for a weighted median came from the following optimization
problem:
x* = arg_x min (a|x| + sum_{k=1}^n |x - b_k|)
where
a : is a *positive* real scalar
x : is a real scalar
n : is an integer
b_k: are negative and positive scalars
2013 Feb 06
0
weighing proportion of rowSums in dataframe
Hi Eik,
thank you so much - it works perfectly!
Thank you and best wishes
Alain
Eik Vettorazzi <E.Vettorazzi@uke.de> hat am 6. Februar 2013 um 17:01 geschrieben:
> Hi Alain,
> here is a one-liner for a df without the rowSum column
>
> df<-data.frame(id=c("x01","x02","x03","x04","x05","x06"),a=c(1,2,NA,4,5,6),b=c(2,4,6,8,10,NA),c=c(NA,3,9,12,NA,NA))
>
> (df$wSum<-apply(sweep(df[,-1],1,rowSums(df[,-1],na.rm=T),"/"),1,function(x)sum...
2013 Feb 06
1
weighing proportion of rowSums in dataframe
...,12,NA,NA),sum=c(3,9,15,24,15,6))
id a b c sum
1 x01 1 2 NA 3
2 x02 2 4 3 9
3 x03 NA 6 9 15
4 x04 4 8 12 24
5 x05 5 10 NA 15
6 x06 6 NA NA 6
#my weights
w<-c(10.5,9,12.8)
#now I want to calculate the proportion of the rowsum = "sum" of every other number in the row, that is df[1,2]/df[1,5], df[1,3]/df[1,5], ...
#e.g.
df.prop
id a b c sum
1 x01 0.33 0.66 NA 3
2 x02 0.22 0.44 0.33 9
3 x03 NA 0.4 0.6 15
4 x04...