similar to: tapply and weighted means

Displaying 20 results from an estimated 5000 matches similar to: "tapply and weighted means"

2005 Oct 31
3
Applying a function to a vector
I have defined a function to compute the value of a beta distribution of the second kind (the existing beta distribution of th stats package is the beta distribution of the first kind). It works perfectly for a single value, but I want to apply it to a vector of 22 000 values. I can use a loop for the calculation of each value but it runs very very slowly. So, what can I change ? Hers's the
2007 Aug 01
1
Re : Custom axis
Maybe I do not explain well what I would like to do. I do not want to change the labels of the axis, but the scale. What I want is a general procedure for changing the scale. Its like using a logarithmic scale on a plot. Labels are the same, but the increases of x along the x-axis are defined by a known monotone and continuous function. Florent Bresson ----- Message d'origine ---- De :
2006 Oct 16
5
Re : Generate a random bistochastic matrix
Thanks, I tried someting like this, but computation takes times for large matrices btransf <- function(y,X=length(y)^4) { N <- length(y) bm <- matrix(rep(1/N,N^2),N,N) for(j in 1:X){ coord <- sample(1:N,4,replace=T) d <- runif(1,0,min(bm[coord[1],coord[2]],bm[coord[3],coord[4]]))
2005 Nov 28
3
optimization with inequalities
I have to estimate the following model for several group of observations : y(1-y) = p[1]*(x^2-y) + p[2]*y*(x-1) + p[3]*(x-y) with constraints : p[1]+p[3] >= 1 p[1]+p[2]+p[3]+1 >= 0 p[3] >= 0 I use the following code : func <- sum((y(1-y) - p[1]*(x^2-y) + p[2]*y*(x-1) + p[3]*(x-y))^2) estim <- optim( c(1,0,0),func, method="L-BFGS-B" , lower=c(1-p[3], -p[1]-p[3]-1,
2006 Oct 16
2
Re : Re : Generate a random bistochastic matrix
Yes, you're right. In fact, it's just an adaptation of a matlab command and the author advises using N^4 replications that's why it's the default in the function. The bistochastic matrix is not my subject of interest, but I need it to perform some random tranformation of a vector of incomes. Florent Bresson ----- Message d'origine ---- De : Richard M. Heiberger <rmh at
2007 Aug 24
2
Applying a function to an array
Dear R-users, I would like to apply a function (more precisely sd()) over the third dimension of a three-dimension array. The function apply would be interesting but the chosen function can only be applied on the rows and columns of the array according to the help file. I can use a loop to cut the array in matrices and then use apply for each replication, but it's not very nice. A small
2005 Dec 05
3
The gamma function and infinity
I have to calculate some formula like: gamma(x)/(gamma(x+y) and I observed that for relatively big values of x, R returns infinity and so cannot compute the formula. Is it possible to force R to give the real value of gamma(x) instead of Inf ? thanks
2006 Oct 16
2
Generate a random bistochastic matrix
Please, I would like to generate a random bistochastic matrix, that is a squared matrix of non-negative numbers with each row and each column sum to 1, for example : .2 .3 .5 .6 .3 .1 .2 .4 .4 I don't know of to code this. Do you have any idea ? Thanks Florent Bresson ___________________________________________________________________________ Demandez ?
2006 Jul 19
3
Progress in a loop
Hi, I have to use a loop to perform a quite computer intensive estimation and I would like to know the progress of the loop during the process. I tried to include something like print(paste(k,date(),sep=" : ")) where k is the number of the iteration, but the result appears only at the end of the loop. Can someone help me please ?
2005 Oct 19
1
Problem with na in nls
I'm trying to run a nls on a subset of a data.frame. In the subset, one observation is NA. So I drop the observation but when I ask for : >sm <- nls(machin$revcum ~ Lc.singh(machin$popcum,p), start=list(p=c(2,3))) I get : Erreur dans parse(file, n, text, prompt) : syntax error in "~ " If I put some value for the non available observation instead of droping it, it works.
2003 Jul 31
1
help with tapply and weighted.mean
Hello! I have data frame with 'weights' in one of the columns. I need to compute weighted mean on another column other factor variable and i am trying to: res<-tapply(data$k,list(data$model),weighted.mean,w=data$w,na.rm=T) and i get: Warning messages: 1: longer object length is not a multiple of shorter object length in: x * w 2: longer object length is not a multiple of shorter
2007 Jan 15
2
Kernel density output
Hi, I'm using the density() command for a given vector x and I would like to know how to get the estimated value of the density for each element of the vector x instead of values corresponding to points from a grid. Thanks Florent Bresson
2007 May 31
3
Problem with Weighted Variance in Hmisc
The function wtd.var(x,w) in Hmisc calculates the weighted variance of x where w are the weights. It appears to me that wtd.var(x,w) = var(x) if all of the weights are equal, but this does not appear to be the case. Can someone point out to me where I am going wrong here? Thanks. Tom La Bone [[alternative HTML version deleted]]
2009 Jan 19
1
conditional weighted quintiles
Dear All, I am economist and working on poverty / income inequality. I need descriptive statitics like the ratio of education expentitures between different income quintiles where each household has a different weight. After a bit of google search I found 'Hmisc' and 'quantreg' libraries for weighted quantiles. The problem is that these packages give me only weighted quintiles;
2005 Nov 16
2
numericDeriv
I have to compute some standard errors using the delta method and so have to use the command "numericDeriv" to get the desired gradient. Befor using it on my complicated function, I've done a try with a simple exemple : x <- 1:5 numericDeriv(quote(x^2),"x") and i get : [1] 1 8 27 64 125 216 attr(,"gradient") [,1] [,2] [,3] [,4] [,5] [,6] [1,] Inf
2008 Aug 04
1
R and emacs
I wrote a "program" truc.r with emacs In emacs, I start the buffer R, then I eval the buffer truc.r (C-c C-b) All is correct and I have my results. But, when I return to Console R, and make: > source ("truc.r"), I obtain an error: Erreur dans source("truc.r") : invalid multibyte character in parser at line 1 If I copy, line by line the instructions of the
2009 Nov 14
4
Weighted descriptives by levels of another variables
I've noticed that R has a number of very useful functions for obtaining descriptive statistics on groups of variables, including summary {stats}, describe {Hmisc}, and describe {psych}, but none that I have found is able to provided weighted descriptives of subsets of a data set (ex. descriptives for both males and females for age, where accurate results require use of sampling
2008 Aug 03
1
(sans objet)
- Peut-on poser des questions en fran?ais? - Tr?s simple. Je fais un programme "truc.r" (sous emacs) Ce programme r?alise des graphiques. Je voudrais les enregistrer au fur et ? mesure -- sinon, quand la session est finie, ces graphiques sont perdus-- J'ai essay?: pdf("truc.pdf") Mais le fichier "truc.pdf" cr?? est vide. Comment fait-on? Merci et salutations
2017 Nov 24
0
number to volume weighted distribution
On 24/11/2017 6:27 AM, PIKAL Petr wrote: > Dear all > > Strictly speaking it is not R question but as you are the most capable persons I know I give it a try. > > I am strugling with recalculation of number weighted to volume weighted distribution. > > Suppose I have objects (cubes) with size > > x<- c(rep(10,20), rep(100, 10), rep(300,5)) > I can get >
2017 Nov 24
2
number to volume weighted distribution
Hi Duncan I tried Ecdf and/or wtd.quantile from Hmisc and it is working (probably). Ecdf(x, q=.5) Ecdf(x, weights=xw,col=2, add=T, q=.5) wtd.quantile(x) 0% 25% 50% 75% 100% 10 10 10 100 300 wtd.quantile(x, weights=xw, type="i/n") 0% 25% 50% 75% 100% 10.0000 138.8667 192.5778 246.2889 300.0000 But could you please be more specific in this? >