[R] Splitting data frame into columns with dplyr

2015-10-01 Thread Michael . Laviolette
I have a data frame with a structure similar to the following. The variable z is a grouping variable; x and y are measurement variables. library(dplyr) df <- data.frame(z = rep(c("A", "B")), x = 1:6, y = 7:12) %>% arrange(z) z x y 1 A 1 7 2 A 3 9 3 A 5 11 4 B 2 8 5 B 4 10 6 B 6 12 I nee

[R] Omitting NA's using dcast (reshape2 package)

2015-06-22 Thread Michael . Laviolette
I'm using the "dcast" function from Hadley's "reshape2" package to do some tabulations. I can't get it to exclude NA's in the variables being tabulated. Here's a simple example. v1 <- c(rep("A", 5), rep("B", 5), NA) v2 <- c("X", "Y", "Y", "Z", "Z", "X", "Y", "Y", "Z", NA, "Z") v3 <- c(rep("a", 4)

[R] Flat tables for confidence intervals with "survey" package

2015-02-04 Thread Michael . Laviolette
I'm preparing some reports for substate regions from BRFSS survey data. I can get estimates easily enough, but am having problems putting the results in convenient form. Here's some code using the New Hampshire portion of the public BRFSS "SMART" data: library(foreign) library(survey) # download

[R] Using "survey" package with ACS PUMS

2014-09-30 Thread Michael . Laviolette
I'm trying to reproduce some results from the American Community Survey PUMS data using the "survey" package. I'm using the one-year 2012 estimates for New Hampshire (http://www2.census.gov/acs2012_1yr/pums/csv_pnh.zip) and comparing to the estimates for user verification from http://www.census.go

Re: [R] Using "survey" package with ACS PUMS

2014-09-30 Thread Michael . Laviolette
Setting the options did the trick. The code using "Fay" came from another post, but this works: options( "survey.replicates.mse" = TRUE) pums_p.rep <- svrepdesign(repweights = pums_p[207:286], weights = ~PWGTP, combined.weights = TRUE,

[R] Using calibrate for raking (survey package)

2013-10-10 Thread Michael . Laviolette
I'm studying the calibration function in the survey package in preparation for raking some survey data. Results from the rake function below agree with other sources. When I run calibrate, I get a warning message and the M and F weights seem to be reversed. Even allowing for that, the deviation bet

Re: [R] Excluding all missing values with dcast ("reshape2" package)

2012-12-06 Thread Michael . Laviolette
Thanks for the response. It turns out this will work if the data include no other variables with missings; unfortunately, that was the case. I was successful using xtabs with the extra step of converting the returned table to a data frame. Thanks again! -M.L. Hi, ?na.omit() dat1<-read.table(text=

Re: [R] Excluding all missing values with dcast ("reshape2" package)

2012-12-06 Thread Michael . Laviolette
Thanks for the response. The drop option of dcast was the first thing I tried. Sorry for the lack of reproducibility, but my data set is large, I couldn't find anything in the package examples, and I had hoped the modification would be straightforward. Using dcast was my first choice because it ret

[R] Excluding all missing values with dcast ("reshape2" package)

2012-12-03 Thread Michael . Laviolette
Hello--I'm doing a simple crosstab using dcast: rawfreq <- dcast(nh11brfs, race3~CHCCOPD, length) with the results race3 Yes No NA 1 White non-Hispanic 446 5473 21 2 Other non-Hispanic 29 211 0 3 Hispanic 6 81 1 4 10 83 1 How would I modify

[R] Using extract function for dates in sqldf

2012-03-21 Thread Michael . Laviolette
I'm trying to use sqldf to query for the earliest date of a blood test when patients have had multiple tests in a given year. My query looks like this: test11 <- sqldf("select CHILD_ID, min(SAMP_DATE) from lab group by CHILD_ID having extract (ye

[R] Applying function to only numeric variable (plyr package?)

2011-10-12 Thread Michael . Laviolette
My data frame consists of character variables, factors, and proportions, something like c1 <- c("A", "B", "C", "C") c2 <- factor(c(1, 1, 2, 2), labels = c("Y","N")) x <- c(0.5234, 0.6919, 0.2307, 0.1160) y <- c(0.9251, 0.7616, 0.3624, 0.4462) df <- data.frame(c1, c2, x, y) pct <- function(x) roun

[R] Model fit using mcexact from exactLoglinTest

2011-07-08 Thread Michael . Laviolette
I'm using the mcexact function from the exactLoglinTest package on data comparing performance of rapid and laboratory tests for detection of H1N1 flu. My setup is as follows: ridt.res <- c("A-B-", "A+B-", "A-B+") pcr.res <- c("Negative", "AH3", "B") xtab <- expand.grid(ridt = ridt.res, pcr = pcr.

[R] Packages for quasi-symmetry and quasi-independence

2011-07-07 Thread Michael . Laviolette
Are there any packages with functions that can fit quasi-symmetry and quasi-indepedence models to square contingency tables? M. Laviolette __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide

[R] Overlaying maps

2011-05-18 Thread Michael . Laviolette
off() only the last map appears, the previous ones having been cleared. Can someone clarify? Thanks, Michael Laviolette PhD MPH New Hampshire Department of Health and Human Services __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/

[R] Risk differences with survey package

2011-03-07 Thread Michael . Laviolette
I'm trying to use the survey package to calculate a risk difference with confidence interval for binge drinking between sexes. Variables are X_RFBING2 (Yes, No) and SEX. Both are factors. I can get the group prevalences easily enough with result <- svyby(~X_RFBING2, ~SEX, la04.svy, svymean, na.rm