[R] t-test with autocorrelation correction
Has anyone implemented a t-test with the effective sample size correction proposed by Dale and Fortin, Ecoscience 9(2):162-167, 2002, using a discussion by Cressie, 1993, page 15? thanks, Denis __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] zero index and lazy evaluation in ifelse()
I don't understand this behavior: a - c(0, 1, 2, 3) b - c(1, 2, 3, 4) ifelse (a == 0, 0, b[a]) [1] 0 2 3 1 rather than the desired 0 1 2 3. Thanks for any explanation. __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] zero index and lazy evaluation in ifelse()
This seems to contradict the help file. ... 'yes' will be evaluated if and only if any element of 'test' is true, and analogously for 'no'... Peter Dalgaard [EMAIL PROTECTED] wrote on 2005-01-13 13:24:31: [EMAIL PROTECTED] writes: I don't understand this behavior: a - c(0, 1, 2, 3) b - c(1, 2, 3, 4) ifelse (a == 0, 0, b[a]) [1] 0 2 3 1 rather than the desired 0 1 2 3. Thanks for any explanation. b[a] is c(1,2,3), recycling to length 4 gives c(1,2,3,1), get it? -- O__ Peter Dalgaard Blegdamsvej 3 c/ /'_ --- Dept. of Biostatistics 2200 Cph. N (*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918 ~~ - ([EMAIL PROTECTED]) FAX: (+45) 35327907 __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] zero index and lazy evaluation in ifelse()
Thanks to all for clarifying that it isn't an element by element test and evaluation, rather an any test as the code says. Peter Dalgaard [EMAIL PROTECTED] wrote on 2005-01-13 14:22:50: [EMAIL PROTECTED] writes: This seems to contradict the help file. ... 'yes' will be evaluated if and only if any element of 'test' is true, and analogously for 'no'... It doesn't. Read closer. Both 'yes' and 'no' is evaluated. The former is c(0, 0, 0, 0) the latter is c(1, 2, 3, 1). Peter Dalgaard [EMAIL PROTECTED] wrote on 2005-01-13 13:24:31: [EMAIL PROTECTED] writes: I don't understand this behavior: a - c(0, 1, 2, 3) b - c(1, 2, 3, 4) ifelse (a == 0, 0, b[a]) [1] 0 2 3 1 rather than the desired 0 1 2 3. Thanks for any explanation. b[a] is c(1,2,3), recycling to length 4 gives c(1,2,3,1), get it? __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] apply ( , , table)
a - matrix (c( 7, 1, 1, 2, 6, 3, 4, 0, 1, 4, 5, 1, 8, 4, 4, 6, 1, 1, 2, 5), nrow=4, byrow=TRUE) b - apply (a, 1, table) apply documentation says clearly that if the rows of the result of FUN are the same length, then an array will be returned. And column-major would be the appropriate order in R. But b above is pretty opaque compared to what one would expect, and what one would get from apply ( , , table) if the rows were not of equal length. One needs to do something like n - matrix (apply (a, 1, function (x) unique (sort (x))), nrow=nrow(a)) to get the corresponding names of b to figure out the counts. Denis White __ [EMAIL PROTECTED] mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] rank() vs SAS proc rank
SAS proc rank has ties options of high and low that would allow producing ranks of the type found in the sports pages, e.g., rank (c(1,1,2,2,2,2,3)) == 1 1 3 3 3 3 7 Could R support these ties.methods? __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] column names in matrix vs. data frame in R 1.8
... Ok, I'll regard it as an inconsistency that the conversion of dimnames to data frame column names changes reserved words to legitimate names but direct assignment doesn't. It's not inconsistent. data.frame has an argument `check.names' to control the behaviour on *creating* a data frame, and you didn't consult the documentation. Using the function names- on the list underlying the data frame does not know or care it is applied to a data frame. After thinking about this, I guess I wonder why names- shouldn't have the argument 'check.names' and/or check the class of its main argument. Why offer protection in one situation and not another? __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] Data for use in maps()
I am interested in plotting maps visualizing spatial statistics in an aggregated fashion, according to administrative boundaries. More specifically, I have fitted a cross-section model on data regarding Italian counties (province, for Italian readers) and I would like to visualize residual behavior on a map, in order to have a first assessment of their spatial autocorrelation. I would also make some EDA on the spatial patterns (if any) of the regressors. I have found the maps package (and related) and would be able to do what I want, e.g., for the USA, essentially by map(state,fill=T,col=color) where color is dependent on the statistic of interest, but I still lack a data file for counties' boundaries in Italy. Does anybody know where to find one? Is there any convenient tool for converting from other formats? I would like to do everything in R if possible. Thanks in advance Giovanni Millo RD Dept. Dear Millo Giovanni: Attached is a zip file containing three files. The file 'italy.prov.pol' is a R/Splus format polygon file of the provinces. In this file, there are NA records in the $y column where the polygons end. The corresponding $x column are polygon identifiers. The file 'italy.prov.pat' has three columns: the first are the polygon identifiers used in 'italy.prov.pol', the second are the NUTS3 identifiers, and the third are the names. The file 'italy.prov.crf' has commas separating the fields. The file italy.prov.e00 is an arc/info export file of a polygon coverage of the province boundaries. This was extracted from the European NUTS3 file of third level political boundaries available at: http://www.grid.unep.ch/data/grid/gnv159.php. The R/S format files above were made from this arc/info file. All location coordinates in the above files are geographic (longitude, latitude). In Becker and Wilks document Constructing a Geographical Database that accompanies the 'maps' package there is a description of how to make a database that can be used by the maps package. I am not aware that anyone has made this capability available in R, and I have not done this either. You can read the .pol file like this: prov - read.table (italy.prov.pol, header=TRUE) You can then use this function: plot.map - function (x, y) { rx - range (x[!is.na(y)], na.rm=TRUE) ry - range (y[!is.na(x)], na.rm=TRUE) plot.new () plot.window (rx, ry, asp=1) } and say plot.map (prov$x, prov$y) polygon (prov) You can read the .pat file like this: pat - read.table (italy.prov.pat, sep=,, header=TRUE, quote=) With this file you can connect the polygon boundaries in the .pol file with names in .pat and with your statistics. There is a crude mapping facility available in contributed package maptree. Best wishes, Denis White US EPA, 200 SW 35th St, Corvallis, Oregon, 97333 USA voice: 541.754.4476, email: [EMAIL PROTECTED] web: www.epa.gov/wed/pages/staff/white/ attachment deleted __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] column names in matrix vs. data frame in R 1.8
[EMAIL PROTECTED] writes: Is the difference in behavior below, introduced in 1.8, inconsistent or, at least, undesirable? I couldn't find this in the NEWS. On the one hand, a - matrix (1:4, nrow=2) a - data.frame (a) names (a) - c(break,next) names (a) [1] break next On the other, a - matrix (1:4, nrow=2) dimnames(a) - list (1:2, c(break,next)) a - data.frame (a) names(a) [1] break. next. Works fine if you don't use keywords as column names a - matrix (1:4, nrow=2) dimnames(a) - list (1:2, c(foo,bar)) b - data.frame(a) names(b) [1] foo bar The difference in the result for your example has to do with an extra step in the second case to obtain a legitimate name that can be used with the $ operator. R generates a syntax error for a$break but not for a$break. Ok, I'll regard it as an inconsistency that the conversion of dimnames to data frame column names changes reserved words to legitimate names but direct assignment doesn't. __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] column names in matrix vs. data frame in R 1.8
Is the difference in behavior below, introduced in 1.8, inconsistent or, at least, undesirable? I couldn't find this in the NEWS. On the one hand, a - matrix (1:4, nrow=2) a - data.frame (a) names (a) - c(break,next) names (a) [1] break next On the other, a - matrix (1:4, nrow=2) dimnames(a) - list (1:2, c(break,next)) a - data.frame (a) names(a) [1] break. next. thanks, Denis __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] Index of item in matrix
Try these: which.col - function (mat, x) (which(mat==x)-1) %/% nrow(mat) + 1 which.row - function (mat, x) (which(mat==x)-1) %% nrow(mat) + 1 Knowing the R community, there may be already functions to do this. Is there a fast way to find the index(row and column) of a point in a matrix? __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help
Re: [R] circle
plot.new () plot.window (c(0,1), c(0,1)) # method 1 symbols (0.5, 0.5, circles=0.01, inches=FALSE, add=TRUE) # method 2 points (0.5, 0.5, pch=21, cex=3, col=green) # method 3 library (maptree) ngon (c(0.5, 0.5, 10, 2), n=10, type=2) I hope this isnt a stupid question .I wonder if someone could help me out..I want to plot a circle and dont know exactly if there is a special function in R or something that could help me out __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help
Re: [R] Logical Indexing of vectors -- Odd Behavior or....
Notice that seq (.1, .9, by=.1)[3] - 0.3 [1] 5.551115e-17 See the thread [R] round() seems inconsistent when rounding 5s about March 16 on the same issue, inexact representation. R-Community, I'm puzzled by the following behavior in R 1.6.2 and have found no reference to this in the archives: P - seq(.1,.9,by=.1) P[P .4] [1] 0.5 0.6 0.7 0.8 0.9 as expected. However, P[P .3] [1] 0.3 0.4 0.5 0.6 0.7 0.8 0.9 ??? Which is unexpected. Furthermore on the logical side P.1 [1] FALSE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE P.2 [1] FALSE FALSE TRUE TRUE TRUE TRUE TRUE TRUE TRUE P.3 [1] FALSE FALSE TRUE TRUE TRUE TRUE TRUE TRUE TRUE P.4 [1] FALSE FALSE FALSE FALSE TRUE TRUE TRUE TRUE TRUE P.5 [1] FALSE FALSE FALSE FALSE FALSE TRUE TRUE TRUE TRUE P.6 [1] FALSE FALSE FALSE FALSE FALSE FALSE TRUE TRUE TRUE P.7 [1] FALSE FALSE FALSE FALSE FALSE FALSE TRUE TRUE TRUE What's with .3 and .7? Any pointers to where I might find out the info would be greatly appreciated, I'm running 1.6.2 on windows XP, Sincerely, __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help
[R] reserved words documentation
I wanted a data frame component to be named next, for example: m - data.frame (matrix (0, nrow=2, ncol=2)) names (m) - c(prev, next) m prev next 100 200 But next being reserved prevents $ indexing without quotes: m$next Error: syntax error m$next [1] 0 0 Although they are mostly obvious, I can't find in the documentation (using Jon Baron's searcher, at least) a list of these words. Am I missing the documentation, or could such a list be added to a future release? thanks, Denis __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help
Re: [R] Managing size of plots with many points
One approach you might consider is Dan Carr's hexbin function available in Splus and in the Bioconductor package at www.bioconductor.org. What is available to limit obvious overplotting, e.g. with a million points? My primary motivation is to produce plots from R and S-Plus that occupy minimal hard drive space without sacrificing visual clarity. (I've crashed MicroSoft PowerPoint by including plots that are too big.) Right now, I can think of three different scenarios: 1. Monotonic applications such as a normal probability plot. 2. Lines (or connected dots). 3. General scatterplots. Several approaches have been suggested, and I've implemented an ugly algorithm. However, I believe something better should be available, but I don't even know what words to use in a search. Ideas? Thanks, Spencer Graves __ [EMAIL PROTECTED] mailing list http://www.stat.math.ethz.ch/mailman/listinfo/r-help
Re: [R] removing leading/trailing blanks
Hi, What's the best way of dropping leading or trailing blanks from a character string? The only thing I can think of is using sub() to replace blanks with null strings, but I don't know if there is a better way (I also don't know how to represent the trailing blank in a regular expression). Thanks, Doug Grove sub (^[ \t]*, , sub ([ \t]*$, , hello )) __ [EMAIL PROTECTED] mailing list http://www.stat.math.ethz.ch/mailman/listinfo/r-help
Re: [R] subset with NA
Easy question that I can't find an answer for. I'm trying to subset a data frame and want to exclude the positive values, i.e. I want the NA values. My data: summary(temp$tuna) Min. 1st Qu. MedianMean 3rd Qu.Max.NA's 1 2 3 3 4 51211 Querying for subset(temp, tuna %in% NA, select subset(temp, tuna == NA, select subset(temp, tuna == as.character(NA), select All yield an empty data frame. An R-help post (http://www.r-project.org/nocvs/mail/r-help/2002/3645.html) suggested looking at http://developer.r-project.org/150update.txt, which I did but I'm confused as to how to accurately query for an NA string. subset (temp, is.na (temp$tuna), ...) __ [EMAIL PROTECTED] mailing list http://www.stat.math.ethz.ch/mailman/listinfo/r-help
[R] example methods for whatis
Having difficulty following the examples in John Chambers paper Classes and Methods in the S Language, dated 9 August 2001. See error below in whatis (matrix (0,2,3)). Thanks for help. library (methods) whatis - function (object) paste (an object of class, + data.class (object)) setMethod (whatis, vector, function (object) + paste (data.class (object), vector of length, + length (object))) Creating a new generic function for whatis in package .GlobalEnv [1] whatis whatIsMatrix - function (object) + paste (data.class (as (object, vector)), matrix with, + nrow (object), rows and, ncol (object), columns) setMethod (whatis, matrix, whatIsMatrix) [1] whatis whatis (matrix (0,2,3)) Error in paste(., prefix, name, sep = __) : evaluation is nested too deeply: infinite recursion? R.version _ platform i386-pc-mingw32 arch i386 os mingw32 system i386, mingw32 status major1 minor6.2 year 2003 month01 day 10 language R __ [EMAIL PROTECTED] mailing list http://www.stat.math.ethz.ch/mailman/listinfo/r-help
[R] masking polygons (formerly no subject)
I have two routine tasks that I am wasting time over trying to solve. Can anyone help? I want to display the results of some geostatistical analysis quickly in R before exporting back to GIS . Does anyone have a trick for overlaying a polygon on an image of a krigging surface (prmat in spatial) in such a way that the space outside the polygon is whited out (so I trim within state boundaries)? Also, has anyone got a function for converting decimal degrees to UTM within R itself? Thanks, Duncan Golicher Below is some simple code to illustrate a way to do it. The idea is to concatenate the coordinates of the polygon of interest (e.g., state boundary) to the coordinates describing the plot region (in data space). This trick assumes that the polygon of interest lies entirely within the plot region. Then the polygon shading algorithm treats the polygon of interest like a hole in the outer polygon and leaves it transparent. If the polygon of interest itself has interior holes it may not work. n - 50 * 3 x - runif (n) y - runif (n) x[(seq(n) %% 3) == 0] - NA y[(seq(n) %% 3) == 0] - NA plot.new () range.x - range (x, na.rm=TRUE) range.y - range (y, na.rm=TRUE) plot.window (range.x, range.y, asp=1) lines (x, y) wind.x - c(range.x, rev (range.x), range.x[1]) wind.y - c(range.y[1], range.y, rev (range.y)) # example polygon poly.x - wind.x / 2 + 0.25 poly.y - wind.y / 2 + 0.25 mask.x - c(wind.x, poly.x) mask.y - c(wind.y, poly.y) polygon (mask.x, mask.y, col=white, border=white) __ [EMAIL PROTECTED] mailing list http://www.stat.math.ethz.ch/mailman/listinfo/r-help