Displaying 20 results from an estimated 2000 matches similar to: "problem for wtd.quantile()"
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]]
2007 Jul 23
1
replacing double for loops with apply's
Hi,
I am doing double for loops to calculate SDs with some weights and wondering
if I can get rid of the outer for loop as well. I made a simple examples
which is essentially what I am doing.
Thanks for your help!
-Young
#------------------------------------------------------
# wtd.var is Hmisc package
# you can replace the 3 lines inside for loop as
# sdx[i,] =
2012 Nov 19
5
help on matrix column removal based on another matrix results
Hi everyone, now I am trying to finish writing the code (I had asked for
assistance on subtracting arrays)
This is what I what I am running in R:
> source("/home/ie/Documents/TTU/GA_Research/GLUE/R-Project/R_GLUE_Example/NSEr.R")
NSEr <- function (obs, sim)
{
{jjh <- (as.vector(obs) - sim)^2
Xjjhs <- apply(Xjjh, 2, sum)
Yii <- (obs - mean(obs))^2
Yiis <- apply(Yii, 2,
2010 Dec 30
2
optim and singularity
Hello,
I was unable to find clues to my problem in ?optim. Using the data and code
below, I get an error ("system is exactly singular") when a particular line
of code is left in, but have found that 'optim' works when I comment it out.
The line of code in question is after the closeAllConnections() line of code
and contains a call to "na.approx" from the zoo package.
2004 Oct 21
0
Hmisc: Using stratified weighted means (wtd.mean) within a function
Hello list,
I have the following function which, as you can see, uses mean:
meanratings <- round(apply(stack03[,c(102:121)],2,function(x) (tapply(x ,actcode, mean, na.rm=T))), digits=1)
The above function yields the following output:
q27a q27b q27c q27d q27e q27f q27g q27h q27i q27j q27k q27l q27m q27o q27p
1 7.8 8.1 7.7 7.9 7.9 NaN NaN 8.4 7.8 7.0 7.6 NaN NaN 7.1 6.0
2
2010 Mar 20
2
different forms of nls recommendations
Hello,
Using this data:
http://n4.nabble.com/file/n1676330/US_Final_Values.txt US_Final_Values.txt
and the following code i got the image at the end of this message:
US.final.values<-read.table("c:/tmp/US_Final_Values.txt",header=T,sep=" ")
US.nls.1<-nls(US.final.values$ECe~a*US.final.values$WTD^b+c,data=US.final.values,start=list(a=2.75,b=-0.95,c=0.731),trace=TRUE)
2011 Apr 20
2
survexp with weights
Hello,
I probably have a syntax error in trying to generate an expected
survival curve from a weighted cox model, but I can't see it. I used
the help sample code to generate a weighted model, with the addition
of a "weights=albumin" argument (I only chose albumin because it had
no missing values, not because of any real relevance). Below are my
code with the resulting error
2012 Jul 24
1
Function for ddply
Hello, all. I'm new to R and just beginning to learn to write functions. I
know I'm out of my depth posting here, and I'm sure my issue is mundane.
But here goes. I'm analyzing the American National Election Study (nes),
looking at mean values of a numeric dep_var (environ.therm) across values
of a factor (partyid3). I use ddply from plyr and wtd.mean from Hmisc. The
nes requires a
2012 Apr 20
1
pasting a formula string with double quotes in it
Hello everyone,
I have tried several ways of doing this and searched the documentation and
help lists and I have been unable to find an answer or even whether it is
possible to do it. I am pasting together a formula and I need to insert
double quotes around the strings. Here's an example:
location <- c("AL", "AK", "MA", "PA")
v=2
test <-
2009 Jun 23
3
subset POSIXct
Hi,
I have a data frame with two columns: dt and tf. The dt column is
datetime and the tf column is a temperature.
dt tf
1 2009-06-20 00:53:00 73
2 2009-06-20 01:08:00 73
3 2009-06-20 01:44:00 72
4 2009-06-20 01:53:00 71
5 2009-06-20 02:07:00 72
...
I need a subset of the rows where the minutes are 53. The hour is
immaterial. I can not find a wildcard
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;
2012 Jun 13
1
How to calculate the statistcs for extracted region?
I have a binary file(a) with size of (360 720 )for the globe.I wrote the code
given below to read and extract an area (south america)from that file. when
I use summary for the whole file I got:
summary(a, na.rm=FALSE)
Min. 1st Qu. Median Mean 3rd Qu. Max. NA's
0.00 1.00 3.00 4.15 7.00 20.00 200083 .
But when I used summary for the region(b) which I extracted, I got
2008 Jan 07
2
How should I improve the following R code?
I'm looking for a way to improve code that's proven to be inefficient.
Suppose that a data source generates the following table every minute:
Index Count
------------
0 234
1 120
7 11
30 1
I save the tables in the following CSV format:
time,index,count
0,0:1:7:30,234:120:11:1
1,0:2:3:19,199:110:87:9
That is, each line represents a table, and I
2012 Mar 06
1
How to eliminate for next loops in this script
I needed to compute a complicated cross tabulation to show weighted means
and standard deviations and the only method I could get that worked uses a
series of nested for next loops. I know that there must be a better way to
do so, but could use some assistance pointing the way.
Here is my working, but inefficient script:
library(Hmisc)
rm(list=ls())
load('NHTS.Rdata')
day.wt <-
2006 Jan 12
2
tapply and weighted means
I' m trying to compute weighted mean on different
groups but it only returns NA. If I use the following
data.frame truc:
x y w
1 1 1
1 2 2
1 3 1
1 4 2
0 2 1
0 3 2
0 4 1
0 5 1
where x is a factor, and then use the command :
tapply(truc$y,list(truc$x),wtd.mean, weights=truc$w)
I just get NA. What's the problem ? What can I do ?
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?
>
2017 Nov 24
0
number to volume weighted distribution
Hi Petr,
I think that Duncan suggests something like this:
x<- c(rep(10,20), rep(300,5), rep(100, 10))
tx <- table(x)
prop.x <- tx / sum(tx)
vx <- as.integer(names(tx))
prop.wx <- tx * vx / sum(tx * vx)
plot(ecdf(x))
plot(vx, cumsum(prop.x), ylim = 0:1)
plot(vx, cumsum(prop.wx), ylim = 0:1)
Best regards,
Thierry
ir. Thierry Onkelinx
Statisticus / Statistician
Vlaamse
2011 Sep 09
2
get and save
I have a data frame 'tmp' and a vector 'name' containing 'd2'.
I want to save 'tmp' under the name hidden in 'name', and the file must have
the same name, plus the extension '.rda'.
So I try
> tmp
x y
1 1 3
2 2 4
> name
[1] "d2"
> assign(name, tmp)
> summary(get(name))
x y
Min. :1.00 Min. :3.00
1st
2010 Dec 22
0
adjust secondary y-axis bounds to minimize visual residuals
Hello,
I'm plotting two sets of data referenced to either the left or right y-axes.
The first, water table depth (blue circles), is plotted on the left y-axis
in reverse order (0 at the top) as this is more intuitive when thinking in
terms of depth. The second is electrical conductance (a surrogate for
salinity), and is referenced to the right y-axis. The data and plot
commands follow
2008 Jun 15
1
Help finding the mode and maximum for a specified 'window' of time series data
I am relatively new to R, so apologize up front for my long question,
particularly if there is too much or too little information.
I have a large time series data set where each subject's behavior was
originally coded on .25s intervals for 3min task. I am trying to determine
if the findings are different depending on the coding interval (i.e. Compare
.25s to 1s to 5s to 10s).
I also need to