Displaying 20 results from an estimated 47 matches for "svymean".
2008 Jan 25
3
function code
R-help,
Sorry for this question (I guess it has been addressed before but
I could not find it in the archives)
but how can I see a function code
when the following comes up:
> svymean
function (x, design, na.rm = FALSE, ...)
{
.svycheck(design)
UseMethod("svymean", design)
}
<environment: namespace:survey>
Thanks in advance
2008 Aug 26
2
svymeans question
I have the following code which produces the output below it
clus1 <- svydesign(ids = ~schid, data = lower_dat)
items <- as.formula(paste(" ~ ", paste(lset, collapse= "+")))
rr1 <- svymean(items, clus1, deff='replace', na.rm=TRUE)
> rr1
mean SE DEff
W525209 0.719748 0.015606 2.4932
W525223 0.508228 0.027570 6.2802
W525035 0.827202 0.014060 2.8561
W525131 0.805421 0.015425 3.1350
W525033 0.242982 0.020074 4.5239
W525163 0.904647 0.013905 4.6289
W525165...
2005 May 26
1
Survey and Stratification
..., 23,25,27,21,22, 33,27,29), ncol=6, byrow=F)
colnames(age)<-c("stratum", "id", "weight", "nh", "Nh", "y")
age<-as.data.frame(age)
## create survey design object
age.des1<-svydesign(ids=~id, strata=~stratum, weight=~Nh, data=age)
svymean(~y, age.des1)
## gives mean 25.568, SE 0.9257
age.des2<-svydesign(ids=~id, strata=~stratum, weight=~I(nh/Nh), data=age)
svymean(~y, age.des2)
## gives mean 25.483, SE 0.9227
age.des3<-svydesign(ids=~id, strata=~stratum, weight=~weight, data=age)
svymean(~y, age.des3)
## gives mean 26.296, S...
2008 Aug 15
2
Design-consistent variance estimate
Dear List:
I am working to understand some differences between the results of the
svymean() function in the survey package and from code I have written
myself. The results from svymean() also agree with results I get from
SAS proc surveymeans, so, this suggests I am misunderstanding something.
I am never comfortable with "I did what the software" does mentality, so
I am work...
2012 Oct 02
2
svyby and make.formula
Hello,
Although my R code for the svymean () and svyquantile () functions works fine, I am stuck with the svyby () and make.formula () functions. I got the following error messages.
- Error: object of type 'closure' is not subsettable # svyby ()
- Error in xx[[1]] : subscript out of bounds # make.formula ()
A repr...
2003 Feb 12
2
Various Errors using Survey Package
...ell me what the structure
has to be for a stratified sample with clustering? Looking at the code, it
appears to me that it does not allow more than 1 observation per psu [i.e.
any(sc > 1)].
Error 2). If I go ahead and specify check.strata=FALSE, then svydesign runs
ok. I then tried using the svymean function. In the following example, if
I specify na.rm=TRUE, I get the error below:
> svymean(nhis.df$crc10yr, design=nhis.design, na.rm=TRUE)
Error in rowsum.default(x, strata) : Incorrect length for 'group'
I traced this to the svyCprod call within svymean. SvyCprod calls rowsum
a...
2003 Feb 19
5
Subpopulations in Complex Surveys
Hi,
is there a way to analyze subpopulations (e.g. women over 50, those who
answered "yes" to a particular question) in a survey using Survey package?
Other packages (e.g. Stata, SUDAAN) do this with a subpopulation option to
identify the subpopulation for which the analysis shoud be done. I did not
see this option in the Survey package. Is there another way to do this?
2008 Feb 13
1
survey package: proportion estimate confidence intervals using svymean
Using the survey package I find it is convenient and easy to get estimated
proportions using svymean, and their corresponding estimated standard
errors. But is there any elegant/simple way to calculate corresponding
confidence intervals for those proportions? Of course +/- 1.96 s.e. is a
reasonable approximation for a 95% CI, but (incorrectly) assumes symmetrical
distribution for a proportion....
2003 Sep 20
4
using aggregate with survey-design and survey functions
...I fix this problem? I have
used aggregate with "mean" and "weighted.mean", and that works fine. I am trying
to find out where the difference is. What would be an efficient alternative
to aggregate for a large dataset?
> s <- aggregate(income,list(age,sex),function(x) (svymean(~x,design=d.na)))
Error in aggregate(income, list(age, sex), function(x) (svymean(~x, :
Object "income" not found
[[alternative HTML version deleted]]
2012 Apr 13
2
problem with svyby and NAs (survey package)
...2001 17623 2122
...
Note some years are missing - they are part of the dataset, but all
responses are NA (the question wasn't asked).
However, this gives an error, and I'd like to understand why - it works
for variables without missing years:
svyby(~problem.vandal, ~SurvYear, seh.dsn, svymean, na.rm=TRUE)
Error in tapply(1:NROW(x), list(factor(strata)), function(index) { :
arguments must have same length
The error only occurs when na.rm=TRUE and there are no observations in
one year.
Thanks
alex
Please access the attached hyperlink for an important electronic communications discla...
2006 Dec 05
1
Surveys ans missing values
...am
astonished because it does not seem to do things that are easy to do on
other softs.
I have got data with missing values (I am working on a questionnaire filled
by students) and with weights and stratification. I learned how to use the
survey package, and I would like to do an average (by using svymean) of a
variable that has some NA.
I first tried :
svymean(~q135,survey) #q135 is the name of the variable and survey is the
name of the survey design
but as there is missing values, i get that :
mean SE
q135 NA NA
as a consequence I put the observations without missing values in a vector x...
2006 Jul 07
2
Multistage Sampling
...mpling
design:
library(survey)
multi3 <- data.frame(cluster=c(1,1,1,1 ,2,2,2, 3,3), id=c(1,2,3,4,
1,2,3, 1,2),
nl=c(4,4,4,4, 3,3,3, 2,2), Nl=c(100,100,100,100, 50,50,50, 75,75),
M=rep(23,9),
y=c(23,33,77,25, 35,74,27, 37,72) )
dmulti3 <- svydesign(id=~cluster+id, fpc=~M+Nl, data=multi3)
svymean (~y, dmulti3)
mean SE
y 45.796 5.5483
svytotal(~y, dmulti3)
total SE
y 78999 13643
and I estimate the population total as N=M/m sum(Nl) =
23/3*(100+50+75)=1725. With this, my variance estimator is:
y1<-mean(multi3$y[1:4]) # 39.5
y2<-mean(multi3$y[5:7]) # 45.33
y3<-mean(mult...
2012 Aug 10
1
Direct Method Age-Adjustment to Complex Survey Data
...id = ~SDMVPSU ,
strata = ~SDMVSTRA ,
nest = TRUE ,
weights = ~WTMEC2YR ,
data = x
)
# only perform analyses among individuals aged 20 and over
z <- subset( y , RIDAGEYR >= 20 )
# these four commands calculate the correct non-age-adjusted estimate
svymean( ~HI_CHOL , z , na.rm = T )
svyby( ~HI_CHOL , ~race , z , svymean , na.rm = T )
svyby( ~HI_CHOL , ~RIAGENDR , z , svymean , na.rm = T )
svyby( ~HI_CHOL , ~RIAGENDR+race , z , svymean , na.rm = T )
# but matching the figure exactly requires an exact age adjustment.
# create the population types vec...
2017 Jul 09
2
Help with ftable.svyby
Hi all,
When I try the following with pkg Survey it returns the error below:
ftable(svyby(~INCOME, ~AGECL+RACECL, svymean, design=q50),
rownames=list(AGECL=c("<35", "35-44", "45-54", "55-64",
"65-74", ">=75"),
RACECL=c("white non hispanic", "non white or hispanic"))
Erro...
2010 Mar 26
1
return.replicates in survey pkg
...he replicates estimates from a crosstab done using
svyby?
Here is an example from the help page for svyby in the package:
> data(api)
> dclus1<-svydesign(id=~dnum, weights=~pw, data=apiclus1, fpc=~fpc)
> rclus1<-as.svrepdesign(dclus1)
>
> a <- svyby(~api99, ~stype, rclus1, svymean, return.replicates=TRUE)
> a$replicates
NULL
But, compare to
> b <- svymean(~api99, design=rclus1, return.replicates=TRUE)
> b$replicates
[1] 606.8488 611.5866 609.1989 605.5765 608.1381 606.6927 609.8101
599.4371 602.4368 601.8792 606.7531 630.6575 600.1882 607.5549 599.9942
>
T...
2010 Aug 25
1
Surprising behaviour survey-package with missing values
...om those obtained from svytotal. The estimated mean
incomes do agree with each other. It seems that using the na.rm option
with svytotal is the same as replacing the missing values with zero's,
which is not what I would have expected, especially since this
behaviour seems to differ from that of svymean. Is there a reason for
this behaviour?
I can of course remove the missing values myself before creating the
survey object. However, with many different variables with different
missing values, this is not very practical. Is there an easy way to
get the behaviour I want?
Thanks for your help.
Wit...
2007 Dec 19
2
4 questions regarding hypothesis testing, survey package, ts on samples, plotting
...mple size
p1=the proportion from the second sample
n2=the second sample size
2. How can i find the median of a variable in survey package?
a<-c(1:10)
b<-sample(1:20, 10, replace=T)
b1<-sample(0:1, 10, replace=T)
c<-data.frame(a,b, b1)
library(survey)
design<-svydesign(id=~1, data=c)
svymean(~b, design)
svymean gives me the mean, but what function gives me the svymedian, and what function gives me the svyproportion for b1?
I want to know the median for a metric variable and the proportion for a binomial variable ?
3. Could time series analysis (arima/arma) be applied on data that...
2005 Jun 16
1
Survey - Cluster Sampling
...pled. y are the values sampled. This is my example data:
clus1 <- data.frame(cluster=c(1,1,1,2,2,2,3,3,3), id=seq(1:3,3),
weight=rep(72/9,9), nl=rep(3,9), Nl=rep(3,9), N=rep(72,9), y=c(23,33,77,
25,35,74, 27,37,72) )
1. Let M=m=3 and N=n=9. Then:
dclus1<-svydesign(id=~cluster, data=clus1)
svymean(~y, dclus1)
mean SE
y 44.778 0.294, the unweighted mean, assuming equal probability in the
clusters. ok.
2. Let M=23, m=3 and N=72, n=9, then I am unable to use svydesign correctly:
dclus2<-svydesign(id=~cluster, data=clus1, fpc=~N)
svymean(~y, dclus2)
mean SE
y 44.778 0.28...
2017 Jul 09
0
Help with ftable.svyby
...AGECL = factor( AGECL ) ,
RACECL = factor( RACECL ) )
On Sun, Jul 9, 2017 at 2:59 PM, Orsola Costantini via R-help <
r-help at r-project.org> wrote:
> Hi all,
>
> When I try the following with pkg Survey it returns the error below:
>
> ftable(svyby(~INCOME, ~AGECL+RACECL, svymean, design=q50),
> rownames=list(AGECL=c("<35", "35-44", "45-54", "55-64",
> "65-74", ">=75"),
> RACECL=c("white non hispanic", "non white or hispani...
2012 Sep 21
1
Exactly Replicating Stata's Survey Data Confidence Intervals in R
...Mean Std. Err. [95% Conf. Interval]
-------------+------------------------------------------------
ell0 | .0218579 .0226225 -.0266624 .0703783
--------------------------------------------------------------
# R x64
# simple example using example code pulled from ?svymean
options(digits=20)
library(survey)
library(foreign)
# read the data file from a website, to make sure you're using the same
data in both R and stata
x <- read.dta( "http://www.ats.ucla.edu/stat/stata/library/apiclus1.dta" )
dclus1<-svydesign(id=~dnum, fpc=~fpc, data=x)
# mean...