[R] Unexpected R Behavior: Adding 4 to Large Numbers/IDs Containing Current Year

2011-06-29 Thread Christopher T. Moore

Hello,

I have encountered some unexpected behavior in R that seems to occur as a 
result of having the current year embedded in a number:





#Some large numbers, representing IDs.
IDs - c(41255689815201100, 41255699815201100, 41255709815201100)

#In scientific notation
IDs 

[1] 4.125569e+16 4.125570e+16 4.125571e+16


#Change penalty.
options(scipen = 5)

#Why does R add 4?
IDs

[1] 41255689815201104 41255699815201104 41255709815201104


#Changing from numeric to character makes no difference.
as.character(IDs)

[1] 41255689815201104 41255699815201104 41255709815201104


#What happens if I treat the numbers as characters?
 IDs.character - c(41255689815201100, 41255699815201100, 
41255709815201100)


#No change.
IDs.character

[1] 41255689815201100 41255699815201100 41255709815201100


#R adds 4 upon converting to numeric.
as.numeric(IDs.character)

[1] 41255689815201104 41255699815201104 41255709815201104


 #Is this problem occurring because the current year is embedded in the 
number?

IDs - c(41255689815201100, 41255699815201000, 41255709815201200)

#R is no longer adding 4 to the numbers without 2011.
IDs

[1] 41255689815201104 41255699815201000 41255709815201200





Am I doing something wrong? Any insight on how I can avoid the problem of R 
changing numbers on its own? Are others able to replicate this example? Is 
this some kind of bug? Am I right that this problem is occurring because 
the current year is embedded in the number? I discovered this when trying 
to merge two data sets, one with IDs stored numbers and one with IDs as 
characters. I have replicated this in Windows XP with R 2.12 and Windows 7 
with R 2.13 (both 32- and 64-bit versions).


Thanks,
Chris

--
Christopher T. Moore, M.P.P.
Doctoral Student
Quantitative Methods in Education
University of Minnesota
44.9785°N, 93.2396°W
moor0...@umn.edu
http://umn.edu/~moor0554

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] Flexibly Retrieving Objects with an Index

2011-02-02 Thread Christopher T. Moore

Greetings,

I would like to flexibly combine several data frames objects without 
specifying the exact names of the objects in memory. Should I use indexing 
to call those objects out of memory? I regularly use indexes to flexibly 
extract parts of data frames and lists and to read files from my hard 
drive, but I can't figure out how to do so with stored objects.


In my case, all of the data frames of interest are formatted the same way 
and have been assigned to objects with the prefix data.. The following 
examples combine only the names (not the objects themselves):

rbind(ls()[grep(data., ls(), fixed=T)])
list(ls()[grep(data., ls(), fixed=T)])

Is there a way to get ls() (or some other function) to return the object 
instead of just the name? I searched the help files and the R-help archives 
but couldn't find a solution. Thanks in advance.


Sincerely,
Chris

--
Christopher T. Moore, M.P.P.
Doctoral Student
Quantitative Methods in Education
University of Minnesota
44.9785°N, 93.2396°W
moor0...@umn.edu
http://umn.edu/~moor0554

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Flexibly Retrieving Objects with an Index

2011-02-02 Thread Christopher T. Moore

That works great.  Thanks, Henrique.  -Chris

--
Christopher T. Moore, M.P.P.
Doctoral Student
Quantitative Methods in Education
University of Minnesota
44.9785°N, 93.2396°W
moor0...@umn.edu
http://umn.edu/~moor0554

On Feb 2 2011, Henrique Dallazuanna wrote:


Try this:

do.call(rbind, mget(ls(pattern = 'data'), envir = .GlobalEnv))

On Wed, Feb 2, 2011 at 5:20 PM, Christopher T. Moore 
moor0...@umn.eduwrote:



Greetings,

I would like to flexibly combine several data frames objects without
  specifying the exact names of the objects in memory. Should I use 
indexing

to call those objects out of memory? I regularly use indexes to flexibly
  extract parts of data frames and lists and to read files from my hard 
drive,

but I can't figure out how to do so with stored objects.

In my case, all of the data frames of interest are formatted the same way
and have been assigned to objects with the prefix data.. The following
examples combine only the names (not the objects themselves):
rbind(ls()[grep(data., ls(), fixed=T)])
list(ls()[grep(data., ls(), fixed=T)])

Is there a way to get ls() (or some other function) to return the object
  instead of just the name? I searched the help files and the R-help 
archives

but couldn't find a solution. Thanks in advance.

Sincerely,
Chris

--
Christopher T. Moore, M.P.P.
Doctoral Student
Quantitative Methods in Education
University of Minnesota
44.9785°N, 93.2396°W
moor0...@umn.edu
http://umn.edu/~moor0554 http://umn.edu/%7Emoor0554

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide
http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.








__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] Heterogeneous Correlation Matrix with Survey Weights

2010-02-25 Thread Christopher T. Moore

Hello,

I have a data set containing categorical and ordinal factors, as well as 
sampling weights (i.e., survey weights reflecting unequal probabilities of 
selection). I want to fit a structural equation model with sem(). I have 
run sem() on weighted covariance matrices using advice from John Fox (see 
http://tolstoy.newcastle.edu.au/R/e5/help/08/12/8773.html and 
http://blog.lib.umn.edu/moor0554/canoemoore/2009/09/sem_complex_samples_r_update.html). 
However, since I have categorical/ordinal variables, I would like to 
compute a weighted heterogeneous correlation matrix with hetcor().


Is there a way to do this in R? I couldn't find any guidance in the r-help 
archives or in the polycor help files. Should I truncate the sampling 
weights to integers and then populate the data set with redundant 
rows/cases so that the number of rows equals the population size 
(N700,000)? Or is there a better way to compute a weighted heterogeneous 
correlation matrix?


Thanks,
Chris

--
Christopher T. Moore, M.P.P.
Doctoral Student
Quantitative Methods in Education
University of Minnesota
44.9785°N, 93.2396°W
moor0...@umn.edu
http://umn.edu/~moor0554

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] Error from termplot() with make.panel.svysmooth() for complex survey data

2009-10-14 Thread Christopher T. Moore

Greetings,

I am using library(survey) to analyze some complex sample data. After 
fitting a model I tried to use termplot() with make.panel.svysmooth(), but 
I received an error (see below).


Could someone help me interpret the error message so I can make the 
necessary corrections? The make.panel.svysmooth() function seems to work 
fine, and termplot() worked fine after I dropped the smoother. This led me 
to believe that the error is coming from panel.smooth(), but the code for 
that function does not contain the rowsum() and findInterval() functions 
shown in the error message. I should also note that error does not depend 
on the inclusion or omission of missing data, as I tried it both ways.


I'm analyzing private data, so I can't provide a reproducible example, but 
here's the output:
 design - svydesign(ids=~PSU, weights=~W, 
strat=~STR, nest=T, data=data) model - svyglm(fmla, design=design) 
#works fine as evidenced by summary (not shown) termplot(model, 
data=model.frame(design), partial.resid=T, se=T, 
smooth=make.panel.svysmooth(design))
Waiting to confirm page change... Error in rowsum.default(c(rep(0, ngrid), 
w), c(1:ngrid, findInterval(mm[, :

 incorrect length for 'group'

make.panel.svysmooth(design)
function (x, y, span = 2/3, col.smooth = red, col = par(col), 
   bg = NA, pch = par(pch), cex = 1, ...) 
{
   if (is.null(bandwidth)) 
   bandwidth - range(x) * span/3

   s - svysmooth(y ~ x, design = design, bandwidth = bandwidth)
   points(x, y, pch = pch, bg = bg, col = col)
   lines(s[[1]], col = col.smooth, ...)
}
environment: 0x0225a5d4
termplot(model, data=model.frame(design), partial.resid=T, se=T) #works 
but without smoothing panel.smooth
function (x, y, col = par(col), bg = NA, pch = par(pch), 
   cex = 1, col.smooth = red, span = 2/3, iter = 3, ...) 
{

   points(x, y, pch = pch, col = col, bg = bg, cex = cex)
   ok - is.finite(x)  is.finite(y)
   if (any(ok)) 
   lines(stats::lowess(x[ok], y[ok], f = span, iter = iter), 
   col = col.smooth, ...)

}
environment: namespace:graphics

sessionInfo()
R version 2.9.2 (2009-08-24) i386-pc-mingw32 attached base packages: [1] 
splines stats graphics grDevices utils datasets methods base other attached 
packages: [1] quantreg_4.38 SparseM_0.80 KernSmooth_2.23-3 survey_3.16 
car_1.2-15 foreign_0.8-37




Thanks in advance for any help you can provide.

Regards,
Chris

--
Christopher Moore, M.P.P.
Doctoral Student
Quantitative Methods in Education
University of Minnesota
44.9785°N, 93.2396°W
moor0...@umn.edu
http://umn.edu/~moor0554

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.