Re: [R] install.packages problem
This is something missing from your (unstated) Linux installation. curl-config is part of the original libcurl sources, but Linux distributors tend to separte it out. *How* they do so is non-standard: Fedora and other RPM-based distributions tend to use libcurl-devel Debian and related tend to use libcurl-dev You need to figure this out for your distribution and install the missing piece. On Sat, 5 Nov 2011, eric wrote: I'm trying to install the rdatamarket package. I did an install.packages('rdatamarket') command but got an error about half way through the install as follows: * installing *source* package ‘RCurl’ ... checking for curl-config... no Cannot find curl-config ERROR: configuration failed for package ‘RCurl’ The install continued after the error but looks like it was completed. I'm trying to figure out what the error means and how I fix it. Here's what I'm seeing ...ideas on how to address this would be appreciated : install.packages('rdatamarket') Installing package(s) into ‘/home/eric/R/i486-pc-linux-gnu-library/2.13’ (as ‘lib’ is unspecified) --- Please select a CRAN mirror for use in this session --- also installing the dependencies ‘RCurl’, ‘RJSONIO’ trying URL 'http://lib.stat.cmu.edu/R/CRAN/src/contrib/RCurl_1.7-0.tar.gz' Content type 'application/x-gzip' length 813252 bytes (794 Kb) opened URL == downloaded 794 Kb trying URL 'http://lib.stat.cmu.edu/R/CRAN/src/contrib/RJSONIO_0.96-0.tar.gz' Content type 'application/x-gzip' length 1144519 bytes (1.1 Mb) opened URL == downloaded 1.1 Mb trying URL 'http://lib.stat.cmu.edu/R/CRAN/src/contrib/rdatamarket_0.6.3.tar.gz' Content type 'application/x-gzip' length 12432 bytes (12 Kb) opened URL == downloaded 12 Kb * installing *source* package ‘RCurl’ ... checking for curl-config... no Cannot find curl-config ERROR: configuration failed for package ‘RCurl’ * removing ‘/home/eric/R/i486-pc-linux-gnu-library/2.13/RCurl’ * installing *source* package ‘RJSONIO’ ... Trying to find libjson.h header file checking for gcc... gcc checking whether the C compiler works... yes checking for C compiler default output file name... a.out checking for suffix of executables... checking whether we are cross compiling... no checking for suffix of object files... o checking whether we are using the GNU C compiler... yes checking whether gcc accepts -g... yes checking for gcc option to accept ISO C89... none needed USE_LOCAL = Using local libjson code. Copying files /tmp/RtmpFw9QeX/R.INSTALL4ebf657f/RJSONIO configure: creating ./config.status config.status: creating src/Makevars config.status: creating cleanup ** libs gcc -I/usr/share/R/include -I. -Ilibjson -Ilibjson/Source -DNDEBUG=1 -DJSON_NO_EXCEPTIONS=1 -fpic -std=gnu99 -O3 -pipe -g -c ConvertUTF.c -o ConvertUTF.o g++ -I/usr/share/R/include -I. -Ilibjson -Ilibjson/Source -DNDEBUG=1 -DJSON_NO_EXCEPTIONS=1 -fpic -O3 -pipe -g -c JSONChildren.cpp -o JSONChildren.o g++ -I/usr/share/R/include -I. -Ilibjson -Ilibjson/Source -DNDEBUG=1 -DJSON_NO_EXCEPTIONS=1 -fpic -O3 -pipe -g -c JSONDebug.cpp -o JSONDebug.o g++ -I/usr/share/R/include -I. -Ilibjson -Ilibjson/Source -DNDEBUG=1 -DJSON_NO_EXCEPTIONS=1 -fpic -O3 -pipe -g -c JSONIterators.cpp -o JSONIterators.o g++ -I/usr/share/R/include -I. -Ilibjson -Ilibjson/Source -DNDEBUG=1 -DJSON_NO_EXCEPTIONS=1 -fpic -O3 -pipe -g -c JSONMemory.cpp -o JSONMemory.o g++ -I/usr/share/R/include -I. -Ilibjson -Ilibjson/Source -DNDEBUG=1 -DJSON_NO_EXCEPTIONS=1 -fpic -O3 -pipe -g -c JSONNode.cpp -o JSONNode.o g++ -I/usr/share/R/include -I. -Ilibjson -Ilibjson/Source -DNDEBUG=1 -DJSON_NO_EXCEPTIONS=1 -fpic -O3 -pipe -g -c JSONNode_Mutex.cpp -o JSONNode_Mutex.o g++ -I/usr/share/R/include -I. -Ilibjson -Ilibjson/Source -DNDEBUG=1 -DJSON_NO_EXCEPTIONS=1 -fpic -O3 -pipe -g -c JSONStream.cpp -o JSONStream.o g++ -I/usr/share/R/include -I. -Ilibjson -Ilibjson/Source -DNDEBUG=1 -DJSON_NO_EXCEPTIONS=1 -fpic -O3 -pipe -g -c JSONValidator.cpp -o JSONValidator.o g++ -I/usr/share/R/include -I. -Ilibjson -Ilibjson/Source -DNDEBUG=1 -DJSON_NO_EXCEPTIONS=1 -fpic -O3 -pipe -g -c JSONWorker.cpp -o JSONWorker.o g++ -I/usr/share/R/include -I. -Ilibjson -Ilibjson/Source -DNDEBUG=1 -DJSON_NO_EXCEPTIONS=1 -fpic -O3 -pipe -g -c JSONWriter.cpp -o JSONWriter.o g++ -I/usr/share/R/include -I. -Ilibjson -Ilibjson/Source -DNDEBUG=1 -DJSON_NO_EXCEPTIONS=1 -fpic -O3 -pipe -g -c JSON_Base64.cpp -o JSON_Base64.o gcc -I/usr/share/R/include -I. -Ilibjson -Ilibjson/Source -DNDEBUG=1 -DJSON_NO_EXCEPTIONS=1 -fpic -std=gnu99 -O3 -pipe -g -c JSON_parser.c -o JSON_parser.o gcc -I/usr/share/R/include -I. -Ilibjson -Ilibjson/Source -DNDEBUG=1 -DJSON_NO_EXCEPTIONS=1 -fpic -std=gnu99 -O3 -pipe -g -c RJSON.c -o RJSON.o g++ -I/usr/share/R/include -I. -Ilibjson -Ilibjson/Source -DNDEBUG=1
Re: [R] set seed for random draws
On Sun, 6 Nov 2011, R. Michael Weylandt wrote: I think it's easier than you are making it: the random seed is created in a pretty-random way when you first use it and then it is updated Ah: It is unless you then save the workspace. If you do, then evey subsequent session starts with the same seed until you save the workspace again. So never saving and always saving works fine, but occasional saving can lead to puzzlement. That pretty-random way is as unpredictable as pseado-random numbers (It uses a PRNG internally.) with each call to rDIST(). For example, set.seed(1) x1 - .Random.seed rnorm(1) x2 - .Random.seed rnorm(1) x3 - .Random.seed identical(x1, x2) FALSE identical(x1, x3) FALSE identical(x2, x3) FALSE set.seed(1) identical(x1, .Random.seed) TRUE rnorm(2) identical(x3, .Random.seed) TRUE But the period for the random seed to repeat is very, very long so you don't have to think about it unless you really need to (or for reproducible simulations) Michael On Sat, Nov 5, 2011 at 7:22 PM, Md Desa, Zairul Nor Deana Binti znde...@ku.edu wrote: Thank you everybody for the helpful advices. Basically, I try to figure out why I get different numbers as there are more than one seed for a loop within a loop. Well, I guest I got it now. Because every time random seed is called or specified it'll output different random numbers, as it's requested. Thanks! D From: r-help-boun...@r-project.org [r-help-boun...@r-project.org] on behalf of Rolf Turner [rolf.tur...@xtra.co.nz] Sent: Saturday, November 05, 2011 3:22 PM To: Patrick Burns Cc: r-help@r-project.org; achim.zeil...@uibk.ac.at Subject: Re: [R] set seed for random draws On 05/11/11 22:00, Patrick Burns wrote: SNIP I'd suggest two rules of thumb when coming up against something in R that you aren't sure about: 1. If it is a mundane task, R probably takes care of it. 2. Experiment to see what happens. Of course you could read documentation, but no one does that. SNIP Fortune nomination! cheers, Rolf __ 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-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. -- Brian D. Ripley, rip...@stats.ox.ac.uk Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UKFax: +44 1865 272595__ 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] nested for loops
I sent a post yesterday that I found out why my function didn't work. It's ok now it works. Thank you all. -- View this message in context: http://r.789695.n4.nabble.com/nested-for-loops-tp3992089p3994996.html Sent from the R help mailing list archive at Nabble.com. __ 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] Correlation between matrices
Thank you Dennis, your tips are really helpful. I don't quite understand the lm(y~mouse) part; my intention was -- in pseudo code -- lm(y(Enzyme) ~ y(each elem)). In addition, attach(d) seems necessary before using lm(y~mouse), and since d$mouse has a length 125, while each elem for each region has a length 5, it generates the following error: coefs = ddply(d, .(regions, elem), coefun) Error in model.frame.default(formula = y ~ mouse, drop.unused.levels = TRUE) : variable lengths differ (found for 'mouse') On Sun, Nov 6, 2011 at 12:53 PM, Dennis Murphy djmu...@gmail.com wrote: Hi: I don't think you want to keep these objects separate; it's better to combine everything into a data frame. Here's a variation of your example - the x variable ends up being a mouse, but you may have another variable that's more appropriate to plot so take this as a starting point. One plot uses the ggplot2 package, the other uses the lattice and latticeExtra packages. library('ggplot2') regions = c('cortex', 'hippocampus', 'brain_stem', 'mid_brain', 'cerebellum') mice = paste('mouse', 1:5, sep='') elem - c('Cu', 'Fe', 'Zn', 'Ca', 'Enzyme') # Generate a data frame from the combinations of # mice, regions and elem: d - data.frame(expand.grid(mice = mice, regions = regions, elem = elem), y = rnorm(125)) # Create a numeric version of mice d$mouse - as.numeric(d$mice) # A function to return regression coefficients coefun - function(df) coef(lm(y ~ mouse), data = df) # Apply to all regions * elem combinations coefs - ddply(d, .(regions, elem), coefun) names(coefs) - c('regions', 'elem', 'b0', 'b1') # Generate the plot using package ggplot2: ggplot(d, aes(x = mouse, y = y)) + geom_point(size = 2.5) + geom_abline(data = coefs, aes(intercept = b0, slope = b1), size = 1) + facet_grid(elem ~ regions) # Same plot in lattice: library('lattice') library('latticeExtra') p - xyplot(y ~ mouse | elem + regions, data = d, type = c('p', 'r'), layout = c(5, 5)) HTH, Dennis On Sat, Nov 5, 2011 at 10:49 AM, Kaiyin Zhong kindlych...@gmail.com wrote: regions = c('cortex', 'hippocampus', 'brain_stem', 'mid_brain', 'cerebellum') mice = paste('mouse', 1:5, sep='') for (n in c('Cu', 'Fe', 'Zn', 'Ca', 'Enzyme')) { + assign(n, as.data.frame(replicate(5, rnorm(5 + } names(Cu) = names(Zn) = names(Fe) = names(Ca) = names(Enzyme) = regions row.names(Cu) = row.names(Zn) = row.names(Fe) = row.names(Ca) = row.names(Enzyme) = mice Cu cortex hippocampus brain_stem mid_brain cerebellum mouse1 -0.5436573 -0.31486713 0.1039148 -0.3908665 -1.0849112 mouse2 1.4559136 1.75731752 -2.1195118 -0.9894767 0.3609033 mouse3 -0.6735427 -0.04666507 0.9641000 0.4683339 0.7419944 mouse4 0.6926557 -0.47820023 1.3560802 0.9967562 -1.3727874 mouse5 0.2371585 0.20031393 -1.4978517 0.7535148 0.5632443 Zn cortex hippocampus brain_stem mid_brain cerebellum mouse1 -0.66424043 0.6664478 1.1983546 0.0319403 0.41955740 mouse2 -1.14510448 1.5612235 0.3210821 0.4094753 1.01637466 mouse3 -0.85954416 2.8275458 -0.6922565 -0.8182307 -0.06961242 mouse4 0.03606034 -0.7177256 0.7067217 0.2036655 -0.25542524 mouse5 0.67427572 0.6171704 0.1044267 -1.8636174 -0.07654666 Fe cortex hippocampus brain_stem mid_brain cerebellum mouse1 1.8337008 2.0884261 0.29730413 -1.6884804 0.8336137 mouse2 -0.2734139 -0.5728439 0.63791556 -0.6232828 -1.1352224 mouse3 -0.4795082 0.1627235 0.21775206 1.0751584 -0.5581422 mouse4 1.7125147 -0.5830600 1.40597896 -0.2815305 0.3776360 mouse5 -0.3469067 -0.4813120 -0.09606797 1.0970077 -1.1234038 Ca cortex hippocampus brain_stem mid_brain cerebellum mouse1 -0.7663354 0.8595091 1.33803798 -1.17651576 0.8299963 mouse2 -0.7132260 -0.2626811 0.08025079 -2.40924271 0.7883005 mouse3 -0.7988904 -0.1144639 -0.65901136 0.42462227 0.7068755 mouse4 0.3880393 0.5570068 -0.49969135 0.06633009 -1.3497228 mouse5 1.0077684 0.6023264 -0.57387762 0.25919461 -0.9337281 Enzyme cortex hippocampus brain_stem mid_brain cerebellum mouse1 1.3430936 0.5335819 -0.56992947 1.3565803 -0.8323391 mouse2 1.0520850 -1.0201124 0.8965 1.4719880 1.0854768 mouse3 -0.2802482 0.6863323 -1.37483570 -0.7790174 0.2446761 mouse4 -0.1916415 -0.4566571 1.93365932 1.3493848 0.2130424 mouse5 -1.0349593 -0.1940268 -0.07216321 -0.2968288 1.7406905 In each anatomic region, I would like to calculate the correlation between Enzyme activity and each of the concentrations of Cu, Zn, Fe, and Ca, and do a scatter plot with a tendency line, organizing those plots into a grid. See the image below for the desired effect: http://postimage.org/image/62brra6jn/ How can I achieve this? Thank you in advance. [[alternative HTML version
Re: [R] testing significance of axis loadings from multivariate dudi.mix
On Nov 05, 2011 at 11:01pm Francisco Mora Ardila wrote: But a problem arised with the predict function: it doesn´t seem to work with an object from dudi.mix and I dont understand why. Francisco, There is no predict() method for dudi.mix() or for any of the dudi objects in ade4. I don't see why you can't get around this by doing something like the following, but you need to take account of any scaling/centring that you might do to your data before calling dudi.mix(). ## Does a dudi.mix on continuous data, so really equals a dudi.pca/princomp/PCA library(ade4) data(deug) deug.dudi - dudi.mix(deug$tab, scann=F, nf=2) tt - as.matrix(deug.dudi$tab) %*% as.matrix(deug.dudi$c1) ## see note below qqplot(deug.dudi$li[,1], tt[,1]) qqplot(deug.dudi$li[,2], tt[,2]) deug.princ - princomp(deug$tab, cor=T) qqplot(predict(deug.princ)[,1], tt[,1]) ## scaling not accounted for: deug.princ - princomp(deug$tab, cor=F) qqplot(predict(deug.princ)[,1], tt[,1]) rm(tt, deug.dudi, deug.princ) Note that in the code given above, as.matrix(deug.dudi$tab) %*% as.matrix(deug.dudi$c1) is based on how stats:::predict.princomp does it. Regards, Mark. - Mark Difford (Ph.D.) Research Associate Botany Department Nelson Mandela Metropolitan University Port Elizabeth, South Africa -- View this message in context: http://r.789695.n4.nabble.com/testing-significance-of-axis-loadings-from-multivariate-dudi-mix-tp3994281p3995350.html Sent from the R help mailing list archive at Nabble.com. __ 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] fGarch: garchFit and include.shape/shape parameters
Hello, The function garchFit in the package fGarch allows for choosing a conditional distribution, one of which is the t-distribution. The function allows specification of the shape parameter of the distribution (equal to the degrees of freedom for the t-distribution), for which the default is set to 4. The function also includes an option include.shape, which is a logical flag which determines if the parameter for the shape of the conditional distribution will be estimated or not. Further, it says that if include.shape=FALSE then the shape parameter will be kept fixed during the process of parameter optimization. If I have understood things correctly, I should then set include.shape = TRUE if I want the degrees of freedom (shape parameter) to be estimated when i use garchFit with conditional distribution set to std. *Problem:* garchFit appears to keep using the default shape = 4 even when include.shape is set to TRUE. I have tried this in a loop where garchFit is used on a different data set in each iteration, and inspecting the saved shape parameter estimates from the model (i.e. extracted by modelname@fit$params$shape), I see that they all have the value 4. I have also tried setting shape = NULL (error), and shape = FALSE does not help since FALSE == 0. Have I missed something here, or is this a bug of some sort? Thanks in advance. P.S. I noticed that there are some discrepancies between the package manual and the package as it is run, concerning which conditional distributions are allowed for the garchFit function, but it is perhaps a smaller matter. -- View this message in context: http://r.789695.n4.nabble.com/fGarch-garchFit-and-include-shape-shape-parameters-tp3995466p3995466.html Sent from the R help mailing list archive at Nabble.com. __ 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] linear against nonlinear alternatives - quantile regression
Roger Koenker rkoen...@illinois.edu On Nov 5, 2011, at 1:02 PM, Julia Lira wrote: Dear David, Indeed rq() accepts a vector fo tau. I used the example given by Frank to run fitspl4 - summary(rq(b1 ~ rcs(x,4), tau=c(a1,a2,a3,a4))) and it works. I even can use anova() to test equality of slopes jointly across quantiles. however, it would be interesting to test among different specifications, e.g. rcs(x,4) against rcs(x,3). but it does not work. Probably because the models aren't nested... Thanks for all suggestions! Julia From: dwinsem...@comcast.net Date: Sat, 5 Nov 2011 13:42:34 -0400 To: f.harr...@vanderbilt.edu CC: r-help@r-project.org Subject: Re: [R] linear against nonlinear alternatives - quantile regression I suppose this constitutes thread drift, but your simple example, Frank, made wonder if Rq() accepts a vector argument for tau. I seem to remember that Koencker's rq() does.. Normally I would consult the help page, but the power is still out here in Central Connecticut and I am corresponding with a less capable device. I am guessing that if Rq() does accept such a vector that the form of the nonlinearity would be imposed at all levels of tau. -- David On Nov 5, 2011, at 10:43 AM, Frank Harrell f.harr...@vanderbilt.edu wrote: Just to address a piece of this - in the case in which you are currently focusing on only one quantile, the rms package can help by fitting restricted cubic splines for covariate effects, and then run anova to test for nonlinearity (sometimes a dubious practice because if you then remove nonlinear terms you are mildly cheating). require(rms) f - Rq(y ~ x1 + rcs(x2,4), tau=.25) anova(f) # tests associations and nonlinearity of x2 Frank Julia Lira wrote: Dear all, I would like to know whether any specification test for linear against nonlinear model hypothesis has been implemented in R using the quantreg package. I could read papers concerning this issue, but they haven't been implemented at R. As far as I know, we only have two specification tests in this line: anova.rq and Khmaladze.test. The first one test equality and significance of the slopes across quantiles and the latter one test if the linear specification is model of location or location and scale shift. Do you have any suggestion? Thanks a lot! Best regards, Julia [[alternative HTML version deleted]] __ R-help@ 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. - Frank Harrell Department of Biostatistics, Vanderbilt University -- View this message in context: http://r.789695.n4.nabble.com/linear-against-nonlinear-alternatives-quantile-regression-tp3993327p3993416.html Sent from the R help mailing list archive at Nabble.com. __ 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. [[alternative HTML version deleted]] __ 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] Request for Help: remove zero in fraction from tick labeling
Dear All, I would like to know how to do the following: 1. suppose I have x values from the ordered from 0, 0.5, 1, and would like to label these three points on the x-axis. 2. However, R labels them as 0.0, 0.5, 1.0. But I wan5 them to be 0, .5, 1, since the former way uses limited space of a multi-subgrap plot by adding extra zeros Thank you, Chee [[alternative HTML version deleted]] __ 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] Deleting rows dataframe in R conditional to “if any of (a specific variable) is equal to”
Dear list, I have been struggling for some time now with this code... I have this vector of unique ID EID of length 821 extracted from one of my dataframe (skate). It looks like this: head(skate$EID) [1] 896-19 895-8 899-1 899-5 899-8 895-7 I would like to remove the complete rows in another dataframe (t5) if any of the t5$EID is equal (a duplicate) of skate$EID. I was able to get my 'duplicated' dataframe in t5 of all my matching EID as follow: xx-skate$EID t5[match(xx,t5[,26]), ]#gives me a dataframe of all matching EID in skate$EID record.t trip set month stratum NAFO unit.area time dur.set distance 8948 5 896 1911 221 2J N12 908 158 8849 5 895 810 766 3O R36 1650 168 9289 5 899 112 743 3L V26 2052 158 9299 5 899 512 746 3L W27 1129 147 Where t5[,26] correspond to t5$EID column. I'm sure it's simple, but I'm not sure how to remove all of these now from my t5 dataframe! Tips would be very much appreciated! Thank you! Aurelie Cosandey-Godin Ph.D. student, Department of Biology Industrial Graduate Fellow, WWF-Canada Dalhousie University | Email: god...@dal.ca [[alternative HTML version deleted]] __ 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] Doing dist on separate objects in a text file
On Nov 5, 2011, at 7:20 PM, ScottDaniel wrote: So I have a text file that looks like this: Label X Y Slice 1 Field_1_R3D_D3D_PRJ_w617.tif348 506 1 2 Field_1_R3D_D3D_PRJ_w617.tif359 505 1 3 Field_1_R3D_D3D_PRJ_w617.tif356 524 1 4 Field_1_R3D_D3D_PRJ_w617.tif2 0 1 5 Field_1_R3D_D3D_PRJ_w617.tif412 872 1 6 Field_1_R3D_D3D_PRJ_w617.tif422 863 1 7 Field_1_R3D_D3D_PRJ_w617.tif429 858 1 8 Field_1_R3D_D3D_PRJ_w617.tif429 880 1 9 Field_1_R3D_D3D_PRJ_w617.tif437 865 1 10 Field_1_R3D_D3D_PRJ_w617.tif447 855 1 11 Field_1_R3D_D3D_PRJ_w617.tif450 868 1 12 Field_1_R3D_D3D_PRJ_w617.tif447 875 1 13 Field_1_R3D_D3D_PRJ_w617.tif439 885 1 14 Field_1_R3D_D3D_PRJ_w617.tif2 8 1 What it represents are the locations of centromeres per nucleus in a microscope image. What I need to do is do a dist() on each grouping (the grouping being separated by the low values of x and y's) and then compute an average. The part that I'm having trouble with is writing code that will allow R to separate these objects. I'm having trouble figuring out what you mean by separating the objects. Each row is a separate reading, and I think you just want pairwise distances, right? Do I have to find some way of creating separate data frames for each object? I don't think so. You need to read this file into a data.frame which should be fairly trivial with read.table is you specify the header=TRUE parameter. Or is there a way to parse the file and generate a single data frame of all the pairwise distances? Then assuming there is now a data.frame named dat with those values: dist( cbind(dat$X, dat$Y)) One stumbling block might have been recognizing that the dist function will not work with two x and y arguments but rather requires a matrix (or something coercible to a matrix) as its first argument. This would also have worked: dist(dat[ , c(X, Y)]) -- David. Any suggestions or example code would be much appreciated. Thanks! -- View this message in context: http://r.789695.n4.nabble.com/Doing-dist-on-separate-objects-in-a-text-file-tp3994515p3994515.html Sent from the R help mailing list archive at Nabble.com. __ 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. David Winsemius, MD West Hartford, CT __ 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] linear against nonlinear alternatives - quantile regression
Roger, It's nice to see a reply from the leader in quantile regression. I wonder if I might ask a somewhat unrelated question. A few recent papers have developed ways to force quantile regression curves not to cross. Do you have plans to implement this capability in quantreg? Thanks very much for developing such a fantastic package. Frank Roger Koenker-3 wrote: Roger Koenker rkoenker@ On Nov 5, 2011, at 1:02 PM, Julia Lira wrote: Dear David, Indeed rq() accepts a vector fo tau. I used the example given by Frank to run fitspl4 - summary(rq(b1 ~ rcs(x,4), tau=c(a1,a2,a3,a4))) and it works. I even can use anova() to test equality of slopes jointly across quantiles. however, it would be interesting to test among different specifications, e.g. rcs(x,4) against rcs(x,3). but it does not work. Probably because the models aren't nested... Thanks for all suggestions! Julia From: dwinsemius@ Date: Sat, 5 Nov 2011 13:42:34 -0400 To: f.harrell@ CC: r-help@ Subject: Re: [R] linear against nonlinear alternatives - quantile regression I suppose this constitutes thread drift, but your simple example, Frank, made wonder if Rq() accepts a vector argument for tau. I seem to remember that Koencker's rq() does.. Normally I would consult the help page, but the power is still out here in Central Connecticut and I am corresponding with a less capable device. I am guessing that if Rq() does accept such a vector that the form of the nonlinearity would be imposed at all levels of tau. -- David On Nov 5, 2011, at 10:43 AM, Frank Harrell lt;f.harrell@gt; wrote: Just to address a piece of this - in the case in which you are currently focusing on only one quantile, the rms package can help by fitting restricted cubic splines for covariate effects, and then run anova to test for nonlinearity (sometimes a dubious practice because if you then remove nonlinear terms you are mildly cheating). require(rms) f - Rq(y ~ x1 + rcs(x2,4), tau=.25) anova(f) # tests associations and nonlinearity of x2 Frank Julia Lira wrote: Dear all, I would like to know whether any specification test for linear against nonlinear model hypothesis has been implemented in R using the quantreg package. I could read papers concerning this issue, but they haven't been implemented at R. As far as I know, we only have two specification tests in this line: anova.rq and Khmaladze.test. The first one test equality and significance of the slopes across quantiles and the latter one test if the linear specification is model of location or location and scale shift. Do you have any suggestion? Thanks a lot! Best regards, Julia [[alternative HTML version deleted]] __ R-help@ 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. - Frank Harrell Department of Biostatistics, Vanderbilt University -- View this message in context: http://r.789695.n4.nabble.com/linear-against-nonlinear-alternatives-quantile-regression-tp3993327p3993416.html Sent from the R help mailing list archive at Nabble.com. __ R-help@ 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@ 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. [[alternative HTML version deleted]] __ R-help@ 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@ 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. - Frank Harrell Department of Biostatistics, Vanderbilt University -- View this message in context: http://r.789695.n4.nabble.com/linear-against-nonlinear-alternatives-quantile-regression-tp3993327p3995819.html Sent from the R help mailing list archive at Nabble.com. __ 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,
Re: [R] Matrix element-by-element multiplication
On Nov 6, 2011, at 12:21 AM, R. Michael Weylandt wrote: There are a few (nasty?) side-effects to c(), one of which is stripping a matrix of its dimensionality. E.g., x - matrix(1:4, 2) c(x) [1] 1 2 3 4 So that's probably what happened to you. R has a somewhat odd feature of not really considering a pure vector as a column or row vector but being willing to change it to either: e.g. y - 1:2 x %*% y y %*% x y %*% y while matrix(y) %*% x throws an error, which can also trip folks up. You might also note that x * y and y*x return the same thing in this problem. Getting back to your problem: what are v and b and what are you hoping to get done? Specifically, what happened when you tried v*b (give the exact error message). It seems likely that they are non-conformable matrices, but here non-conformable for element-wise multiplication doesn't mean the same thing as it does for matrix multiplication. E.g., x - matrix(1:4,2) y - matrix(1:6,2) dim(x) [1] 2 2 dim(y) [1] 2 3 x * y -- here R seems to want matrices with identical dimensions, but i can't promise that. x %*% y does work. Hope this helps and yes I know it can seem crazy at first, but there really is reason behind it at the end of the tunnel, Michael On Sun, Nov 6, 2011 at 12:11 AM, Steven Yen s...@utk.edu wrote: My earlier attempt dp - v*b did not work. Because the dimensions did not work. dim(v)[1] (the rows) did not equal dim(b)[2] (the columns) since b did not have a dimension. Then, dp - c(v)*b worked. It worked because of argument recycling. It did not give you a matrix result, however, because of what Michael said. c() turns a matrix into a vector, which it was all along anyway. Here's an example of argument recycling: c(1, 2, 3) * 1:12 [1] 1 4 9 4 10 18 7 16 27 10 22 36 The 1,2,3 vector gets implicitly lengthened as would have happened with rep(c(1,2,3), 4) and then -- David. Confused, Steven At 09:10 PM 11/4/2011, you wrote: Did you even try? a - 1:3 x - matrix(c(1,2,3,2,4,6,3,6,9),3) a*x [,1] [,2] [,3] [1,]123 [2,]48 12 [3,]9 18 27 Michael On Fri, Nov 4, 2011 at 7:26 PM, Steven Yen s...@utk.edu wrote: is there a way to do element-by-element multiplication as in Gauss and MATLAB, as shown below? Thanks. --- a 1.000 2.000 3.000 x 1.0002.0003.000 2.0004.0006.000 3.0006.0009.000 a.*x 1.0002.0003.000 4.0008.00012.00 9.00018.0027.00 -- David Winsemius, MD West Hartford, CT __ 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] Request for Help: remove zero in fraction from tick labeling
On Nov 6, 2011, at 9:07 AM, Chee Chen wrote: Dear All, I would like to know how to do the following: 1. suppose I have x values from the ordered from 0, 0.5, 1, and would like to label these three points on the x-axis. 2. However, R labels them as 0.0, 0.5, 1.0. But I wan5 them to be 0, .5, 1, since the former way uses limited space of a multi-subgrap plot by adding extra zeros as.character(c(0, .5, 1)) [1] 0 0.5 1 I'm guessing that you are doing some sort of potting and using these as axis labels but without code that remains a guess. Thank you, Chee [[alternative HTML version deleted]] __ 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. David Winsemius, MD West Hartford, CT __ 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] Request for Help: remove zero in fraction from tick labe
On 06-Nov-11 14:50:18, David Winsemius wrote: On Nov 6, 2011, at 9:07 AM, Chee Chen wrote: Dear All, I would like to know how to do the following: 1. suppose I have x values from the ordered from 0, 0.5, 1, and would like to label these three points on the x-axis. 2. However, R labels them as 0.0, 0.5, 1.0. But I wan5 them to be 0, .5, 1, since the former way uses limited space of a multi-subgrap plot by adding extra zeros as.character(c(0, .5, 1)) [1] 0 0.5 1 I'm guessing that you are doing some sort of potting and using these as axis labels but without code that remains a guess. Thank you, Chee A general solution is exemplified by the code below. Indications of how to do this (and other customisations) by setting plot paramaters can be found in the output of ?plot.default ( and see also ?par). The code below is a modification (and simplification) of the code for the final example ##--- Log-Log Plot with custom axes in ?plot.default. x - sort(runif(20,0,3)) y - x^2 plot(x, y, type=o, pch='+', col=blue, main=Plot with custom axes, ylab=Y = X^2, xlab=X, axes = FALSE, frame.plot = TRUE) x.at - 0.5*(0:6) axis(1, at = x.at, labels = formatC(x.at, format=fg)) y.at - (0:9) axis(2, at = y.at, labels = formatC(y.at, format=fg)) This sort of customisation does, however, usually require that you tailor the details to the specific plot you are drawing: in general, R can not be persuaded to get it right automatically (in particular, you will need to know the full ranges of the axes in order to get the labels right). Hoping this helps, Ted. E-Mail: (Ted Harding) ted.hard...@wlandres.net Fax-to-email: +44 (0)870 094 0861 Date: 06-Nov-11 Time: 15:17:56 -- XFMail -- __ 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] Correlation between matrices
Hi: On Sat, Nov 5, 2011 at 11:06 PM, Kaiyin Zhong kindlych...@gmail.com wrote: Thank you Dennis, your tips are really helpful. I don't quite understand the lm(y~mouse) part; my intention was -- in pseudo code -- lm(y(Enzyme) ~ y(each elem)). As I said in my first response, I didn't quite understand what you were trying to regress so I used the mouse as a way of showing you how the code works. I think I understand what you want now, though. I'll create a data set in two ways: the first assumes you have the data as constructed in your original post and the second generates random numbers after erecting a 'scaffold' data frame. The game is to separate the enzyme data from the element data and put them into the final data frame as separate columns. Then the regression is easy if that's what you need to do. # Method 1: Generate the data as you did into separate data frames elem0 - c('Cu', 'Fe', 'Zn', 'Ca', 'Enzyme') regions = c('cortex', 'hippocampus', 'brain_stem', 'mid_brain', 'cerebellum') # Creates five 5 x 5 data frames with names V1-V5: for (n in c('Cu', 'Fe', 'Zn', 'Ca', 'Enzyme')) { assign(n, as.data.frame(replicate(5, rnorm(5 } # Stack the chemical element data using melt() from # the reshape2 package: library('reshape2') d1 - rbind(melt(Cu), melt(Zn), melt(Fe), melt(Ca)) # Relabel V1 - V5 with brain region names, add a factor # to distinguish individual elements and tack on the melted # Enzyme data so that it repeats in each element block d1 - within(d1, { variable - factor(d1$variable, labels = regions) elem - factor(rep(elem0[1:4], each = 25)) Enzyme - melt(Enzyme)[, 2] } ) # Plot the data using lattice and latticeExtra: library('lattice') library('latticeExtra') p - xyplot(Enzyme ~ value | variable + elem, data = d1, type = c('p', 'r')) useOuterStrips(p) ### ## Method 2: Generate the random data after setting ## up the element/region/mouse combinations ## # Generate a data frame from the combinations of # mice, regions and elem: library('ggplot2') mice - paste('mouse', 1:5, sep = '') regions = c('cortex', 'hippocampus', 'brain_stem', 'mid_brain', 'cerebellum') elem - elem0[1:4] d0 - data.frame(expand.grid(mice = mice, regions = regions, elem = elem)) d0 - within(d0, { value - rnorm(100) # generate element values Enzyme - rnorm(25) # generate enzyme values } ) # the Enzyme values are recycled through all element blocks. # You can either adapt the lattice code above to plot d0, or you # can do the following to get an analogous plot in ggplot2. # It's easier to compute the slopes and intercepts and put # them into a data frame that ggplot() can import, so that's # what we'll do first. # A function to return regression coefficients from a # generic data frame. Since this function goes into ddply(), # the argument df is a (generic) data frame and the output # will be converted to a one-line data frame. coefun - function(df) coef(lm(Enzyme ~ value, data = df)) # Apply the function to all regions * elem combinations. # Output is a data frame of coefficients corresponding to # each region/element combination coefs - ddply(d0, .(regions, elem), coefun) # Rename the columns names(coefs) - c('regions', 'elem', 'b0', 'b1') # Generate the plot using package ggplot2: ggplot(d0, aes(x = val, y = Enzyme)) + geom_point(size = 2.5) + geom_abline(data = coefs, aes(intercept = b0, slope = b1), size = 1) + xlab() + facet_grid(elem ~ regions) In addition, attach(d) seems necessary before using lm(y~mouse), and since d$mouse has a length 125, while each elem for each region has a length 5, it generates the following error: You should never need to use attach() - use the data = argument in lm() instead, where the value of data is the name of a data frame. It's always easier to use the modeling functions in R having formula interfaces with data frames. coefs = ddply(d, .(regions, elem), coefun) Error in model.frame.default(formula = y ~ mouse, drop.unused.levels = TRUE) : variable lengths differ (found for 'mouse') You're clearly doing something here that's messing up the structure of the data. Study what the code (and its output) above are telling you, particularly if you're not familiar with plyr, lattice and/or ggplot2. Writing functions to insert into a **ply() function in plyr can be tricky. If you continue to have problems, please provide a reproducible example as you did here. HTH, Dennis On Sun, Nov 6, 2011 at 12:53 PM, Dennis Murphy djmu...@gmail.com wrote: Hi: I don't think you want to keep these objects separate; it's better to combine everything into a data frame. Here's a variation of your example - the x variable ends up being a mouse, but you may have another variable that's more appropriate to plot so take this as a
Re: [R] List of user installed packages
Well, you could simply use everything from the old library and just apply update.packages(checkBuilt=TRUE) in order to get the packages updated for the new release. Uwe Ligges On 05.11.2011 19:00, Erich Neuwirth wrote: Running rownames(installed.packages()) will tell you the names of all packages of the version of R in which you are running the command. http://cran.r-project.org/doc/FAQ/R-FAQ.html#R-Add_002dOn-Packages tells you the names of the packages which were installed with R itself. On Nov 5, 2011, at 2:37 PM, Cem Girit wrote: Hello, I am going to install the new version of R 2.14.1. After the installation, I want to copy my installed packages to the new library. But since over time I forgot which ones I installed I want to get a list of all the packages I installed among the packages installed initially by the R-installer. Is this possible? Cem Cem Girit, PhD Biopticon Corporation 182 Nassau Street, Suite 204 Princeton, NJ 08542 Tel: (609)-853-0231 Email:gi...@biopticon.com [[alternative HTML version deleted]] __ 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-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] Deleting rows dataframe in R conditional to “if any of (a specific variable) is equal to”
Not too difficult. Rgames bar-c(3,5,7) Rgames foo-c(1,3,5,6,8,9,7) Rgames match(bar,foo) [1] 2 3 7 # these are the matching positions Rgames foo[-(match(bar,foo))] [1] 1 6 8 9 quote Dear list, I have been struggling for some time now with this code... I have this vector of unique ID EID of length 821 extracted from one of my dataframe (skate). It looks like this: head(skate$EID) [1] 896-19 895-8 899-1 899-5 899-8 895-7 I would like to remove the complete rows in another dataframe (t5) if any of the t5$EID is equal (a duplicate) of skate$EID. I was able to get my 'duplicated' dataframe in t5 of all my matching EID as follow: xx-skate$EID t5[match(xx,t5[,26]), ]#gives me a dataframe of all matching EID in skate$EID record.t trip set month stratum NAFO unit.area time dur.set distance 8948 5 896 1911 221 2J N12 908 158 8849 5 895 810 766 3O R36 1650 168 9289 5 899 112 743 3L V26 2052 158 9299 5 899 512 746 3L W27 1129 147 Where t5[,26] correspond to t5$EID column. I'm sure it's simple, but I'm not sure how to remove all of these now from my t5 dataframe! Tips would be very much appreciated! Thank you! Aurelie Cosandey-Godin Ph.D. student, Department of Biology Industrial Graduate Fellow, WWF-Canada Dalhousie University | Email: godina_at_dal.ca -- Sent from my Cray XK6 Pendeo-navem mei anguillae plena est. __ 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] Double integration using R
Hi, I have a function that I need to do double integration: \int^T_0 \int^t_0 N(\delta / \sigma \sqrt(u)) (1-N(\delta / \sigma \sqrt(u))) du dt where N(x) is a standard normal probability of x. I start off by writing an inner integral into a function. Meaning \int^t_0 N(\delta,\sigma \sqrt(u)) (1-N(\delta,\sigma \sqrt(u))) du. Then calling integrate function on this function. This straightforward way does not seem to work. I am not sure if there is any sample code to do such integration? Thank you. Regards, Robert __ 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] VAR and VECM in multivariate time series
Hello to everyone! I am working on my final year project about multivariate time series. There are three variables in the multivariate time series model. I have a few questions: 1. I used acf and pacf plot and find my variables are nonstationary. But in adf.test() and pp.test(), the data are stationary. why? 2.I use VAR to get a model. y is the matrix of data set and I have made a once difference of it to make it stationary. library(tsDyn) VARselect(y,lag.max=20,type=const,season = NULL, exogen = NULL) y1=VAR(y, p = 16, type = c(const), season = NULL, exogen = NULL, lag.max = NULL,ic = c(AIC)) summary(y1) plot(y1) How can I get estimation of AIC in this model? 3. I also get a VECM model v1=VECM(y, lag=16,beta=NULL, estim=ML) what does ETC mean in the output? and what is a number of cointegrating relationships? I want to make forecast by VECM. j=ca.jo(y,K=16,type='trace',season = NULL) j.var=vec2var(j) predict(j.var,n.ahead=80) Is this a correct way to predict VECM in R? Could anyone help me? Thank you very much -- View this message in context: http://r.789695.n4.nabble.com/VAR-and-VECM-in-multivariate-time-series-tp3995951p3995951.html Sent from the R help mailing list archive at Nabble.com. __ 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] Combining some duplicated rows summing one of their column
Dear list, I have this dataframe: names(events) [1] EIDX Y trip towcatch effort depth [9] season Where some of my unique ID EID appears more than once in 162 cases. length(events$EID)-length(unique(events$EID)) [1] 162 I would like to combined each replicate EID together and sum their catch. I've been trying a few things with the plyr package... but can't find a rather straightforward command. Any tips would be much appreciated! Thank you very much! Aurelie Cosandey-Godin Ph.D. student, Department of Biology Industrial Graduate Fellow, WWF-Canada Dalhousie University | Email: god...@dal.ca [[alternative HTML version deleted]] __ 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] Double integration using R
There do exist packages for multi-variate integration in R, but sticking to base functions, what you've described should work but the inner integral will need to be vectorized before it's passes to the outer integral: Vectorize() can do this directly, but it won't be particularly fast since it's not true vectorization. Send real code if this doesn't help and we can take a look at it. Michael On Nov 6, 2011, at 12:15 PM, Robert A'gata rhelp...@gmail.com wrote: Hi, I have a function that I need to do double integration: \int^T_0 \int^t_0 N(\delta / \sigma \sqrt(u)) (1-N(\delta / \sigma \sqrt(u))) du dt where N(x) is a standard normal probability of x. I start off by writing an inner integral into a function. Meaning \int^t_0 N(\delta,\sigma \sqrt(u)) (1-N(\delta,\sigma \sqrt(u))) du. Then calling integrate function on this function. This straightforward way does not seem to work. I am not sure if there is any sample code to do such integration? Thank you. Regards, Robert __ 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.
Re: [R] Combining some duplicated rows summing one of their column
Since you did not supply a subset of data, or indicate if you wanted all the other values transformed in some ways, here is a simple use of tapply to get your data with respect to 'catch'. If this not what you wanted, you need to be more clear in your request and also give some hints as to what you tried. x - data.frame(EID = sample(10, 20, TRUE), catch = 1:20) tapply(x$catch, x$EID, sum) 1 2 3 4 5 6 7 8 9 10 18 12 20 5 54 19 20 4 56 2 On Sun, Nov 6, 2011 at 2:23 PM, Aurelie Cosandey Godin god...@dal.ca wrote: Dear list, I have this dataframe: names(events) [1] EID X Y trip tow catch effort depth [9] season Where some of my unique ID EID appears more than once in 162 cases. length(events$EID)-length(unique(events$EID)) [1] 162 I would like to combined each replicate EID together and sum their catch. I've been trying a few things with the plyr package... but can't find a rather straightforward command. Any tips would be much appreciated! Thank you very much! Aurelie Cosandey-Godin Ph.D. student, Department of Biology Industrial Graduate Fellow, WWF-Canada Dalhousie University | Email: god...@dal.ca [[alternative HTML version deleted]] __ 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. -- Jim Holtman Data Munger Guru What is the problem that you are trying to solve? Tell me what you want to do, not how you want to do it. __ 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] Request for Help: y-axis label overlapped by x-axis in subplots in big plot
Dear All, I would like to seek for help on this issue: 1. I set par(mfrow=c(2,2)), hoping to plot 4 subgraphs in a whole graph 2. Each subgraph has its own x,y axes and each has x-axis label and y-axis label 3. moreover, subgraphs in the left column of the whole graph are all 3D, and have z axes and labels for z axes 4. subgraphs in the right column of the whole graph are all 2D 5. In each subgraph, x-axis label is at the bottom, y-axis label the left side, z-axis label the right side 5. Issue Now all subgraphs are plotted successfully, except that * the y-axis labels for subgraphs in the right column of the whole graph are overlapped by the z-axis labels of the subgraphs in the left column of the whole graph. (meaning that y axis labels for the 2D subplots in the right column of the whole graph are not shown) 6. what I tried 6.1 When plot each graph in its own plot, everything displayed correctly. 6.2 I switched the order of this subgraphs in the whole graph, so that 3D were in the right column of the whole graph, 2D the left column. But in this case, the y axis labels of the 2D graphs are not shown (because I guess they went out of range of graphical area). Any suggestions? Thank you, Chee [[alternative HTML version deleted]] __ 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] Self-describing data files
Hello all, I have an outstanding request to documents units [1] or other variable-specific facts in data files. I am thinking in particular of tab-delimited files that are suitable to be read into a data frame. One suggestion/request is to add a line of text under the column headings. My first thought was that it might be preferable to consume the first line in the file (perhaps making it easier to skip??), but then I found the comment.char option which appears made for the task. Is there a common/preferred way to tackle this? Bill [1] http://articles.cnn.com/1999-09-30/tech/9909_30_mars.metric.02_1_climate-orbiter-spacecraft-team-metric-system?_s=PM:TECH [[alternative HTML version deleted]] __ 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] Doing dist on separate objects in a text file
On Nov 5, 2011, at 7:20 PM, ScottDaniel wrote: So I have a text file that looks like this: Label X Y Slice 1 Field_1_R3D_D3D_PRJ_w617.tif 348 506 1 2 Field_1_R3D_D3D_PRJ_w617.tif 359 505 1 3 Field_1_R3D_D3D_PRJ_w617.tif 356 524 1 4 Field_1_R3D_D3D_PRJ_w617.tif 2 0 1 5 Field_1_R3D_D3D_PRJ_w617.tif 412 872 1 6 Field_1_R3D_D3D_PRJ_w617.tif 422 863 1 7 Field_1_R3D_D3D_PRJ_w617.tif 429 858 1 8 Field_1_R3D_D3D_PRJ_w617.tif 429 880 1 9 Field_1_R3D_D3D_PRJ_w617.tif 437 865 1 10 Field_1_R3D_D3D_PRJ_w617.tif 447 855 1 11 Field_1_R3D_D3D_PRJ_w617.tif 450 868 1 12 Field_1_R3D_D3D_PRJ_w617.tif 447 875 1 13 Field_1_R3D_D3D_PRJ_w617.tif 439 885 1 14 Field_1_R3D_D3D_PRJ_w617.tif 2 8 1 What it represents are the locations of centromeres per nucleus in a microscope image. What I need to do is do a dist() on each grouping (the grouping being separated by the low values of x and y's) and then compute an average. The part that I'm having trouble with is writing code that will allow R to separate these objects. I'm having trouble figuring out what you mean by separating the objects. Each row is a separate reading, and I think you just want pairwise distances, right? What I mean is that rows 1-3 represent one group of centromeres and rows 5-13 represent a second group. So I want to do a separate dist on each group (i.e. I want a pair wise distance for rows 1 and 3 but not 1 and 12). Does that clear thing up? -- View this message in context: http://r.789695.n4.nabble.com/Doing-dist-on-separate-objects-in-a-text-file-tp3994515p3996701.html Sent from the R help mailing list archive at Nabble.com. [[alternative HTML version deleted]] __ 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] how to use quadrature to integrate some complicated functions
Hello to all, I am having trouble with intregrating a complicated uni-dimensional function of the following form Phi(x-a_1)*Phi(x-a_2)*...*Phi(x-a_{n-1})*phi(x-a_n). Here n is about 5000, Phi is the cumulative distribution function of standard normal, phi is the density function of standard normal, and x ranges over (-infty,infty). My idea is to to use quadrature to handle this integral. But since Phi has not cloaed form, I don't know how to do this effeciently. I appreciate very much if someone has any ideas about it. Thanks! Jeff -- View this message in context: http://r.789695.n4.nabble.com/how-to-use-quadrature-to-integrate-some-complicated-functions-tp3996765p3996765.html Sent from the R help mailing list archive at Nabble.com. __ 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] Request for Help: y-axis label overlapped by x-axis in subplots in big plot
On 11-11-06 3:19 PM, Chee Chen wrote: Dear All, I would like to seek for help on this issue: 1. I set par(mfrow=c(2,2)), hoping to plot 4 subgraphs in a whole graph 2. Each subgraph has its own x,y axes and each has x-axis label and y-axis label 3. moreover, subgraphs in the left column of the whole graph are all 3D, and have z axes and labels for z axes 4. subgraphs in the right column of the whole graph are all 2D 5. In each subgraph, x-axis label is at the bottom, y-axis label the left side, z-axis label the right side 5. Issue Now all subgraphs are plotted successfully, except that * the y-axis labels for subgraphs in the right column of the whole graph are overlapped by the z-axis labels of the subgraphs in the left column of the whole graph. (meaning that y axis labels for the 2D subplots in the right column of the whole graph are not shown) 6. what I tried 6.1 When plot each graph in its own plot, everything displayed correctly. 6.2 I switched the order of this subgraphs in the whole graph, so that 3D were in the right column of the whole graph, 2D the left column. But in this case, the y axis labels of the 2D graphs are not shown (because I guess they went out of range of graphical area). Any suggestions? Change the margins of your plots. Duncan Murdoch __ 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] Correlation analysis
Hi everyone, I am new to R-project. I did search through the list for my problem but i can't find it. I am sorry if this question has been asked. I would like to perform a correlation analysis between a hiv data and gene expression. Basically, i have a file that contains: hiv_name, start_position, end_position, chromosome. I would like to see if these data has anything to do with the location of our genes (I also have another file contains gene_name, start_position, end_position, chromosome). What functions that allow me to do this? I am very new to R and hopefully someone can guide me to the right direction. Thank you very much, [[alternative HTML version deleted]] __ 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] Correlation analysis
I would start by reading one or more of the introduction manuals available here: http://mirrors.ibiblio.org/pub/mirrors/CRAN/ wizi wrote: Hi everyone, I am new to R-project. I did search through the list for my problem but i can't find it. I am sorry if this question has been asked. I would like to perform a correlation analysis between a hiv data and gene expression. Basically, i have a file that contains: hiv_name, start_position, end_position, chromosome. I would like to see if these data has anything to do with the location of our genes (I also have another file contains gene_name, start_position, end_position, chromosome). What functions that allow me to do this? I am very new to R and hopefully someone can guide me to the right direction. Thank you very much, -- View this message in context: http://r.789695.n4.nabble.com/Correlation-analysis-tp3996877p3996961.html Sent from the R help mailing list archive at Nabble.com. __ 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] Correlation analysis
You might find useful tools if you look at Bioconductor as well. M On Nov 6, 2011, at 4:58 PM, Minh Bui buiduym...@gmail.com wrote: Hi everyone, I am new to R-project. I did search through the list for my problem but i can't find it. I am sorry if this question has been asked. I would like to perform a correlation analysis between a hiv data and gene expression. Basically, i have a file that contains: hiv_name, start_position, end_position, chromosome. I would like to see if these data has anything to do with the location of our genes (I also have another file contains gene_name, start_position, end_position, chromosome). What functions that allow me to do this? I am very new to R and hopefully someone can guide me to the right direction. Thank you very much, [[alternative HTML version deleted]] __ 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.
Re: [R] Matrix element-by-element multiplication
It looks like pdf is not a scalar (that term actually has no meaning in R but I know what you mean) but is rather a 1x1 matrix, as attested by the fact it has dimensions. If you give dnorm() a matrix it will return one, as it did here. Perhaps you should look at the is.matrix() and as.vector() functions rather than abusing a side-effect of c(), which makes it much more difficult to see R's internal logic, which, while quirky, is useful at the end of the day. Michael PS - It's good form to cc the list at each step so others can follow along and contribute when I say something wrong. It also helps you get quicker answers. On Nov 6, 2011, at 1:06 AM, Steven Yen s...@utk.edu wrote: I am trying to multiply what I know is a scalar (pdf(xb)) to a column vector of coefficient (bb). In the following, pdf is a scalar and bb is 5 x 1. I first show what worked and then what did not work. If my pdf is a scalar, why would I need c(pdf) to be able to pre-multiply it by a 5 x 1 vector? --- x - as.matrix(colMeans(x)) xb - t(x)%*%bb pdf- dnorm(xb) dim(bb) [1] 5 1 cpdf - c(pdf) dim(cpdf) NULL cpdf [1] 0.304201 (dphat - cpdf*bb) [,1] (Intercept) 0.32744753 xrage -0.00599225 xryr 0.01758431 xrrate -0.08217250 xrrel -0.05695434 pdf- dnorm(xb) dim(pdf) [1] 1 1 pdf [,1] [1,] 0.304201 (dphat - pdf*bb) Error in pdf * bb : non-conformable arrays At 12:21 AM 11/6/2011, you wrote: There are a few (nasty?) side-effects to c(), one of which is stripping a matrix of its dimensionality. E.g., x - matrix(1:4, 2) c(x) [1] 1 2 3 4 So that's probably what happened to you. R has a somewhat odd feature of not really considering a pure vector as a column or row vector but being willing to change it to either: e.g. y - 1:2 x %*% y y %*% x y %*% y while matrix(y) %*% x throws an error, which can also trip folks up. You might also note that x * y and y*x return the same thing in this problem. Getting back to your problem: what are v and b and what are you hoping to get done? Specifically, what happened when you tried v*b (give the exact error message). It seems likely that they are non-conformable matrices, but here non-conformable for element-wise multiplication doesn't mean the same thing as it does for matrix multiplication. E.g., x - matrix(1:4,2) y - matrix(1:6,2) dim(x) [1] 2 2 dim(y) [1] 2 3 x * y -- here R seems to want matrices with identical dimensions, but i can't promise that. x %*% y does work. Hope this helps and yes I know it can seem crazy at first, but there really is reason behind it at the end of the tunnel, Michael On Sun, Nov 6, 2011 at 12:11 AM, Steven Yen s...@utk.edu wrote: My earlier attempt dp - v*b did not work. Then, dp - c(v)*b worked. Confused, Steven At 09:10 PM 11/4/2011, you wrote: Did you even try? a - 1:3 x - matrix(c(1,2,3,2,4,6,3,6,9),3) a*x [,1] [,2] [,3] [1,]123 [2,]48 12 [3,]9 18 27 Michael On Fri, Nov 4, 2011 at 7:26 PM, Steven Yen s...@utk.edu wrote: is there a way to do element-by-element multiplication as in Gauss and MATLAB, as shown below? Thanks. --- a 1.000 2.000 3.000 x 1.0002.0003.000 2.0004.0006.000 3.0006.0009.000 a.*x 1.0002.0003.000 4.0008.00012.00 9.00018.0027.00 -- Steven T. Yen, Professor of Agricultural Economics The University of Tennessee http://web.utk.edu/~syen/ [[alternative HTML version deleted]] __ 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. -- Steven T. Yen, Professor of Agricultural Economics The University of Tennessee http://web.utk.edu/~syen/ -- Steven T. Yen, Professor of Agricultural Economics The University of Tennessee http://web.utk.edu/~syen/ [[alternative HTML version deleted]] __ 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] Matrix element-by-element multiplication
Hi, R may not have a special scalar, but it is common, if informal, in linear algebra to refer to a 1 x 1 matrix as a scalar. Indeed, something like: 1:10 * matrix(2) or matrix(2) * 1:10 are both valid. Even matrix(2) %*% 1:10 and 1:10 %*% matrix(2) work, where the vector seems to be silently coerced to a matrix. R even seems to work hard to convert to a conformable matrix: ## works: 1:10 %*% matrix(1:10) ## does not work matrix(1:10) %*% matrix(1:10) ## works t(matrix(1:10)) %*% matrix(1:10) Interestingly, there is actually a (rather old) comment in arithmetic.c /* If either x or y is a matrix with length 1 and the other is a vector, we want to coerce the matrix to be a vector. Do we want to? We don't do it! BDR 2004-03-06 */ Given the coersion that already occurs with vectors to matrices for %*% and matrices to vectors for *, it seems not unreasonable to convert a 1 x 1 matrix to a vector _for_ * so that the following yields identical results: matrix(1:9, 3) * matrix(2) matrix(1:9, 3) * 2 Of course in the mean time, or in general, it is a good habit to create or explicity coerce objects yourself rather than relying on R to make smart guesses about what should be happening. Cheers, Josh On Sun, Nov 6, 2011 at 4:02 PM, R. Michael Weylandt michael.weyla...@gmail.com michael.weyla...@gmail.com wrote: It looks like pdf is not a scalar (that term actually has no meaning in R but I know what you mean) but is rather a 1x1 matrix, as attested by the fact it has dimensions. If you give dnorm() a matrix it will return one, as it did here. Perhaps you should look at the is.matrix() and as.vector() functions rather than abusing a side-effect of c(), which makes it much more difficult to see R's internal logic, which, while quirky, is useful at the end of the day. Michael PS - It's good form to cc the list at each step so others can follow along and contribute when I say something wrong. It also helps you get quicker answers. On Nov 6, 2011, at 1:06 AM, Steven Yen s...@utk.edu wrote: I am trying to multiply what I know is a scalar (pdf(xb)) to a column vector of coefficient (bb). In the following, pdf is a scalar and bb is 5 x 1. I first show what worked and then what did not work. If my pdf is a scalar, why would I need c(pdf) to be able to pre-multiply it by a 5 x 1 vector? --- x - as.matrix(colMeans(x)) xb - t(x)%*%bb pdf - dnorm(xb) dim(bb) [1] 5 1 cpdf - c(pdf) dim(cpdf) NULL cpdf [1] 0.304201 (dphat - cpdf*bb) [,1] (Intercept) 0.32744753 xrage -0.00599225 xryr 0.01758431 xrrate -0.08217250 xrrel -0.05695434 pdf - dnorm(xb) dim(pdf) [1] 1 1 pdf [,1] [1,] 0.304201 (dphat - pdf*bb) Error in pdf * bb : non-conformable arrays At 12:21 AM 11/6/2011, you wrote: There are a few (nasty?) side-effects to c(), one of which is stripping a matrix of its dimensionality. E.g., x - matrix(1:4, 2) c(x) [1] 1 2 3 4 So that's probably what happened to you. R has a somewhat odd feature of not really considering a pure vector as a column or row vector but being willing to change it to either: e.g. y - 1:2 x %*% y y %*% x y %*% y while matrix(y) %*% x throws an error, which can also trip folks up. You might also note that x * y and y*x return the same thing in this problem. Getting back to your problem: what are v and b and what are you hoping to get done? Specifically, what happened when you tried v*b (give the exact error message). It seems likely that they are non-conformable matrices, but here non-conformable for element-wise multiplication doesn't mean the same thing as it does for matrix multiplication. E.g., x - matrix(1:4,2) y - matrix(1:6,2) dim(x) [1] 2 2 dim(y) [1] 2 3 x * y -- here R seems to want matrices with identical dimensions, but i can't promise that. x %*% y does work. Hope this helps and yes I know it can seem crazy at first, but there really is reason behind it at the end of the tunnel, Michael On Sun, Nov 6, 2011 at 12:11 AM, Steven Yen s...@utk.edu wrote: My earlier attempt dp - v*b did not work. Then, dp - c(v)*b worked. Confused, Steven At 09:10 PM 11/4/2011, you wrote: Did you even try? a - 1:3 x - matrix(c(1,2,3,2,4,6,3,6,9),3) a*x [,1] [,2] [,3] [1,] 1 2 3 [2,] 4 8 12 [3,] 9 18 27 Michael On Fri, Nov 4, 2011 at 7:26 PM, Steven Yen s...@utk.edu wrote: is there a way to do element-by-element multiplication as in Gauss and MATLAB, as shown below? Thanks. --- a 1.000 2.000 3.000 x 1.000 2.000 3.000 2.000 4.000 6.000 3.000 6.000 9.000 a.*x 1.000 2.000 3.000 4.000
Re: [R] Help combining cell labelling and multiple mosaic plots
Hi The problem is that BOTH mosaic() and labeling_cells() are calling seekViewport() to find the right viewport to draw into and for BOTH plots they are finding the same viewports (on the left side of the page). The following code solves the problem (for me anyway) by specifying a different 'prefix' for each mosaic() and labeling_cells() call ... grid.newpage() pushViewport(viewport(layout=grid.layout(1,2))) pushViewport(viewport(layout.pos.col=1)) mosaic(.test, gp=shading_hsv, pop=FALSE, split_verticaL=FALSE, newpage=FALSE, labeling_args=list(offset_varnames=c(top=3), offset_labels=c(top=2)), prefix=plot1) labeling_cells(text=round(prop.table(.test, 1), 2)*100, clip=FALSE)(.test, prefix=plot1) upViewport() pushViewport(viewport(layout.pos.col=2)) mosaic(.test1, gp=shading_hsv, newpage=FALSE, pop=FALSE, split_vertical=FALSE, labeling_args=list(offset_varnames=c(top=3), offset_labels=c(top=2)), prefix=plot2) labeling_cells(text=round(prop.table(.test1, 1), 2)*100, clip=FALSE)(.test1, prefix=plot2) popViewport(2) ... hope that helps. Paul On 1/11/2011 5:21 a.m., Simon Kiss wrote: Dear colleagues I'm using data that looks like .test and .test1 below to draw two mosaic plots with cell labelling (the row percentages from the tables). When I take out the pop=FALSE commands in the mosaic commands and comment out the two lines labelling the cells, then the plots are laid out exactly as I'd like: side-by-side. But I do require the cell labelling and the pop=FALSE arguments. I suspect I need to add in a call to pushViewport or an upViewport command, but I'm not sure. Any advice is welcome. library(vcd) library(grid) .test-as.table(matrix(c(1, 2, 3, 4, 5, 6), nrow=3, ncol=2, byrow=TRUE)) .test-prop.table(.test, 1) .test1-as.table(matrix(c(1, 2, 3, 4), nrow=2, ncol=2, byrow=TRUE)) .test1-prop.table(.test1, 1) dimnames(.test)-list(Fluoride Cluster=c('Beneficial\nand Safe', 'Mixed Opinion', 'Harmful With No Benefits'), Governments Should Not Impose Treatment=c('Agree', 'Disagree')) dimnames(.test1)-list(Vaccines Are Too Much To Handle= c('Agree' , 'Disagree'), Governments Should Not Oblige Treatment =c('Agree', 'Disagree')) grid.newpage() pushViewport(viewport(layout=grid.layout(1,2))) pushViewport(viewport(layout.pos.col=1)) mosaic(.test, gp=shading_hsv, pop=FALSE, split_verticaL=FALSE, newpage=FALSE, labeling_args=list(offset_varnames=c(top=3), offset_labels=c(top=2))) labeling_cells(text=round(prop.table(.test, 1), 2)*100, clip=FALSE)(.test) popViewport() pushViewport(viewport(layout.pos.col=2)) mosaic(.test1, gp=shading_hsv, newpage=FALSE,pop=FALSE, split_vertical=FALSE, labeling_args=list(offset_varnames=c(top=3), offset_labels=c(top=2))) labeling_cells(text=round(prop.table(.test1, 1), 2)*100, clip=FALSE)(.test1) popViewport(2) * Simon J. Kiss, PhD Assistant Professor, Wilfrid Laurier University 73 George Street Brantford, Ontario, Canada N3T 2C9 Cell: +1 905 746 7606 __ 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. -- Dr Paul Murrell Department of Statistics The University of Auckland Private Bag 92019 Auckland New Zealand 64 9 3737599 x85392 p...@stat.auckland.ac.nz http://www.stat.auckland.ac.nz/~paul/ __ 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] tcltk window freezes when using locator( )
Hello useRs Using the following code: library(tcltk) win-tktoplevel() ff-function(){ plot(1:10,1:10) pol-locator(1) print(pol) } button-tkbutton(win,text=test,command=ff) tkpack(button) makes the win panel stop responding when the plot is closed before choosing a location. Usually, the windows task manager has to be used to close the window (which causes R to be stopped as well) or a message saying that R is not responding is displayed. I was having the same problem with R 2.13.0 so I upgraded to 2.14.0 but the problem persists. I am using windows 7. sessionInfo() R version 2.14.0 (2011-10-31) Platform: x86_64-pc-mingw32/x64 (64-bit) locale: [1] LC_COLLATE=French_Canada.1252 LC_CTYPE=French_Canada.1252 [3] LC_MONETARY=French_Canada.1252 LC_NUMERIC=C [5] LC_TIME=French_Canada.1252 attached base packages: [1] tcltk stats graphics grDevices utils datasets methods base Am I doing something wrong or more likely is this a bug? Thanks, Francois Rousseu [[alternative HTML version deleted]] __ 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] Matrix element-by-element multiplication
Mucha gracias!! as.vector worked like a charm and, in this case, produced the same results as c(): c(pdf)*v as.vector(pdf)*v At 07:02 PM 11/6/2011, R. Michael Weylandt michael.weyla...@gmail.com wrote: It looks like pdf is not a scalar (that term actually has no meaning in R but I know what you mean) but is rather a 1x1 matrix, as attested by the fact it has dimensions. If you give dnorm() a matrix it will return one, as it did here. Perhaps you should look at the is.matrix() and as.vector() functions rather than abusing a side-effect of c(), which makes it much more difficult to see R's internal logic, which, while quirky, is useful at the end of the day. Michael PS - It's good form to cc the list at each step so others can follow along and contribute when I say something wrong. It also helps you get quicker answers. On Nov 6, 2011, at 1:06 AM, Steven Yen mailto:s...@utk.edus...@utk.edu wrote: I am trying to multiply what I know is a scalar (pdf(xb)) to a column vector of coefficient (bb). In the following, pdf is a scalar and bb is 5 x 1. I first show what worked and then what did not work. If my pdf is a scalar, why would I need c(pdf) to be able to pre-multiply it by a 5 x 1 vector? --- x - as.matrix(colMeans(x)) xb - t(x)%*%bb pdf- dnorm(xb) dim(bb) [1] 5 1 cpdf - c(pdf) dim(cpdf) NULL cpdf [1] 0.304201 (dphat - cpdf*bb) [,1] (Intercept) 0.32744753 xrage -0.00599225 xryr 0.01758431 xrrate -0.08217250 xrrel -0.05695434 pdf- dnorm(xb) dim(pdf) [1] 1 1 pdf [,1] [1,] 0.304201 (dphat - pdf*bb) Error in pdf * bb : non-conformable arrays At 12:21 AM 11/6/2011, you wrote: There are a few (nasty?) side-effects to c(), one of which is stripping a matrix of its dimensionality. E.g., x - matrix(1:4, 2) c(x) [1] 1 2 3 4 So that's probably what happened to you. R has a somewhat odd feature of not really considering a pure vector as a column or row vector but being willing to change it to either: e.g. y - 1:2 x %*% y y %*% x y %*% y while matrix(y) %*% x throws an error, which can also trip folks up. You might also note that x * y and y*x return the same thing in this problem. Getting back to your problem: what are v and b and what are you hoping to get done? Specifically, what happened when you tried v*b (give the exact error message). It seems likely that they are non-conformable matrices, but here non-conformable for element-wise multiplication doesn't mean the same thing as it does for matrix multiplication. E.g., x - matrix(1:4,2) y - matrix(1:6,2) dim(x) [1] 2 2 dim(y) [1] 2 3 x * y -- here R seems to want matrices with identical dimensions, but i can't promise that. x %*% y does work. Hope this helps and yes I know it can seem crazy at first, but there really is reason behind it at the end of the tunnel, Michael On Sun, Nov 6, 2011 at 12:11 AM, Steven Yen mailto:s...@utk.edus...@utk.edu wrote: My earlier attempt dp - v*b did not work. Then, dp - c(v)*b worked. Confused, Steven At 09:10 PM 11/4/2011, you wrote: Did you even try? a - 1:3 x - matrix(c(1,2,3,2,4,6,3,6,9),3) a*x [,1] [,2] [,3] [1,]123 [2,]48 12 [3,]9 18 27 Michael On Fri, Nov 4, 2011 at 7:26 PM, Steven Yen mailto:s...@utk.edus...@utk.edu wrote: is there a way to do element-by-element multiplication as in Gauss and MATLAB, as shown below? Thanks. --- a 1.000 2.000 3.000 x 1.0002.0003.000 2.0004.0006.000 3.0006.0009.000 a.*x 1.0002.0003.000 4.0008.00012.00 9.00018.0027.00 -- Steven T. Yen, Professor of Agricultural Economics The University of Tennessee http://web.utk.edu/~syen/ [[alternative HTML version deleted]] __ mailto:R-help@r-project.orgR-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. -- Steven T. Yen, Professor of Agricultural Economics The University of Tennessee http://web.utk.edu/~syen/ [[alternative HTML version deleted]] __ 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] partial dependence plots in 'party'
Hello, I can't seem to figure out how to generate partial dependence plots for random forest models generated with the 'party' package. Is there a function for this that I just haven't found yet? Thanks -Philip Dilts __ 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] tcltk window freezes when using locator( )
In fact, the same thing happens (window freezes) when a long computation generated by the tcltk window is stopped through the R console. library(tcltk) library(svMisc) win-tktoplevel() n-1 ff-function(){ for(i in 1:n){progress(i,n)} } button-tkbutton(win,text=test,command=ff) tkpack(button) Francois Rousseu From: francoisrous...@hotmail.com To: r-help@r-project.org Date: Sun, 6 Nov 2011 21:55:58 -0500 Subject: [R] tcltk window freezes when using locator( ) Hello useRs Using the following code: library(tcltk) win-tktoplevel() ff-function(){ plot(1:10,1:10) pol-locator(1) print(pol) } button-tkbutton(win,text=test,command=ff) tkpack(button) makes the win panel stop responding when the plot is closed before choosing a location. Usually, the windows task manager has to be used to close the window (which causes R to be stopped as well) or a message saying that R is not responding is displayed. I was having the same problem with R 2.13.0 so I upgraded to 2.14.0 but the problem persists. I am using windows 7. sessionInfo() R version 2.14.0 (2011-10-31) Platform: x86_64-pc-mingw32/x64 (64-bit) locale: [1] LC_COLLATE=French_Canada.1252 LC_CTYPE=French_Canada.1252 [3] LC_MONETARY=French_Canada.1252 LC_NUMERIC=C [5] LC_TIME=French_Canada.1252 attached base packages: [1] tcltk stats graphics grDevices utils datasets methods base Am I doing something wrong or more likely is this a bug? Thanks, Francois Rousseu [[alternative HTML version deleted]] __ 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. [[alternative HTML version deleted]] __ 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] adjusting levelplot color scale to data
Hi guys, I have a matrix with values varying from approximately -0.7 to 0.33 that I want to create a heatmap/levelplot with. When I execute the levelplot function for my matrix, I end up getting colors that are adjusted to the max and min rather than around 0. In other words, ideally I would like to have a color ramp that goes from red (negative number), to white (0), to blue (positive); however, right now the value 0 is in the blue. Any insight on how to address this problem? Thanks in advance! example... my matrix y looks something like this A B C DE row1 -0.5046406 -0.021579587-0.4419101 -0.2999195330 -0.4845047 row2 -0.3070091 -0.059065936 0.3329806 -0.0519335420 -0.5766368 row3 -0.7271707 0.073282855-0.3181990 -0.2485017700 -0.5732781 row4 0.3329806 -0.017762750-0.1513197 -0.1016354970 0.2528442 levelplot(y) yields a color scale from red (-0.8 to 0.2) to blue (0.2 to 0.4) I'd want the color scale to be from red (-0.8 to 0) to blue (0 to 0.4) - Lanna -- View this message in context: http://r.789695.n4.nabble.com/adjusting-levelplot-color-scale-to-data-tp3997342p3997342.html Sent from the R help mailing list archive at Nabble.com. __ 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] adjusting levelplot color scale to data
Hi, Try specifying explicit break points together with their corresponding colors using at and col.regions, levelplot(m, at= unique(c(seq(-2, 0, length=100), seq(0, 10, length=100))), col.regions = colorRampPalette(c(blue, white, red))(1e3)) HTH, baptiste On 7 November 2011 16:08, Lanna Jin lanna...@gmail.com wrote: Hi guys, I have a matrix with values varying from approximately -0.7 to 0.33 that I want to create a heatmap/levelplot with. When I execute the levelplot function for my matrix, I end up getting colors that are adjusted to the max and min rather than around 0. In other words, ideally I would like to have a color ramp that goes from red (negative number), to white (0), to blue (positive); however, right now the value 0 is in the blue. Any insight on how to address this problem? Thanks in advance! example... my matrix y looks something like this A B C D E row1 -0.5046406 -0.021579587 -0.4419101 -0.2999195330 -0.4845047 row2 -0.3070091 -0.059065936 0.3329806 -0.0519335420 -0.5766368 row3 -0.7271707 0.073282855 -0.3181990 -0.2485017700 -0.5732781 row4 0.3329806 -0.017762750 -0.1513197 -0.1016354970 0.2528442 levelplot(y) yields a color scale from red (-0.8 to 0.2) to blue (0.2 to 0.4) I'd want the color scale to be from red (-0.8 to 0) to blue (0 to 0.4) - Lanna -- View this message in context: http://r.789695.n4.nabble.com/adjusting-levelplot-color-scale-to-data-tp3997342p3997342.html Sent from the R help mailing list archive at Nabble.com. __ 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] Graph binned data
I have a table that looks like this: structure(list(speed = c(3,9,14,8,7,6), result = c(0.697, 0.011, 0.015, 0.012, 0.018, 0.019), house = c(1, 1, 1, 1, 1, 1), date = c(719, 1027, 1027, 1027, 1030, 1030), id = c(1000, 1, 10001, 10002, 10003, 10004)), .Names = c(speed, result, house, date, id), class = data.frame, row.names = c(1000, 1, 10001, 10002, 10003, 10004)) I would like to bin the data by speed, 0-4, 5-9, 10-14, 15-20, etc. Then I would like to make a graph of speed vs result. The graph should show the average result of each bin, and error bars to represent the standard deviation of the result in each bin. What kind of code can I use to make this? Jeffrey __ 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] adjusting levelplot color scale to data
On Nov 6, 2011, at 10:08 PM, Lanna Jin wrote: Hi guys, I have a matrix with values varying from approximately -0.7 to 0.33 that I want to create a heatmap/levelplot with. When I execute the levelplot function for my matrix, I end up getting colors that are adjusted to the max and min rather than around 0. In other words, ideally I would like to have a color ramp that goes from red (negative number), to white (0), to blue (positive); however, right now the value 0 is in the blue. Any insight on how to address this problem? ?levelplot # which leads to ?level.colors # which in turn leads to: ? colorRamp levelplot(as.matrix(dat), at=seq( -.8, .4, length=31), col=color.palette(30) ) And next time, please post the output of dput rather than a mangled print() output. -- David. Thanks in advance! example... my matrix y looks something like this A B C DE row1 -0.5046406 -0.021579587-0.4419101 -0.2999195330 -0.4845047 row2 -0.3070091 -0.059065936 0.3329806 -0.0519335420 -0.5766368 row3 -0.7271707 0.073282855-0.3181990 -0.2485017700 -0.5732781 row4 0.3329806 -0.017762750-0.1513197 -0.1016354970 0.2528442 levelplot(y) yields a color scale from red (-0.8 to 0.2) to blue (0.2 to 0.4) I'd want the color scale to be from red (-0.8 to 0) to blue (0 to 0.4) - Lanna -- View this message in context: http://r.789695.n4.nabble.com/adjusting-levelplot-color-scale-to-data-tp3997342p3997342.html Sent from the R help mailing list archive at Nabble.com. __ 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. David Winsemius, MD West Hartford, CT __ 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] Intercepts is coming as Zero in the Mixed Models
Hi I'm getting the intercepts of the Random effects as 0. Please help me to understand why this is coming Zero This is my R code Data- read.csv(C:/FE and RE.csv) Formula=Y~X2+X3+X4 + (1|State) + (0+X5|State) fit=lmer(formula=Formula,data=Data) ranef(fit). My sample Data State Year Y X2 X3 X4 X5 X6 S2 1960 27.8 397.5 42.2 50.7 78.3 65.8 S1 1960 29.9 413.3 38.1 52 79.2 66.9 S2 1961 29.8 439.2 40.3 54 79.2 67.8 S1 1961 30.8 459.7 39.5 55.3 79.2 69.6 S2 1962 31.2 492.9 37.3 54.7 77.4 68.7 S1 1962 33.3 528.6 38.1 63.7 80.2 73.6 S2 1963 35.6 560.3 39.3 69.8 80.4 76.3 S1 1963 36.4 624.6 37.8 65.9 83.9 77.2 S2 1964 36.7 666.4 38.4 64.5 85.5 78.1 S1 1964 38.4 717.8 40.1 70 93.7 84.7 S2 1965 40.4 768.2 38.6 73.2 106.1 93.3 S1 1965 40.3 843.3 39.8 67.8 104.8 89.7 S2 1966 41.8 911.6 39.7 79.1 114 100.7 S1 1966 40.4 931.1 52.1 95.4 124.1 113.5 S2 1967 40.7 1021.5 48.9 94.2 127.6 115.3 S1 1967 40.1 1165.9 58.3 123.5 142.9 136.7 S2 1968 42.7 1349.6 57.9 129.9 143.6 139.2 S1 1968 44.1 1449.4 56.5 117.6 139.2 132 S2 1969 46.7 1575.5 63.7 130.9 165.5 132.1 S1 1969 50.6 1759.1 61.6 129.8 203.3 154.4 S2 1970 50.1 1994.2 58.9 128 219.6 174.9 S1 1970 51.7 2258.1 66.4 141 221.6 180.8 S2 1971 52.9 2478.7 70.4 168.2 232.6 189.4 -- View this message in context: http://r.789695.n4.nabble.com/Intercepts-is-coming-as-Zero-in-the-Mixed-Models-tp3997498p3997498.html Sent from the R help mailing list archive at Nabble.com. __ 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] adjusting levelplot color scale to data
On Nov 7, 2011, at 12:10 AM, David Winsemius wrote: On Nov 6, 2011, at 10:08 PM, Lanna Jin wrote: Hi guys, I have a matrix with values varying from approximately -0.7 to 0.33 that I want to create a heatmap/levelplot with. When I execute the levelplot function for my matrix, I end up getting colors that are adjusted to the max and min rather than around 0. In other words, ideally I would like to have a color ramp that goes from red (negative number), to white (0), to blue (positive); however, right now the value 0 is in the blue. Any insight on how to address this problem? ?levelplot # which leads to ?level.colors # which in turn leads to: ? colorRamp color.palette =colorRampPalette(c(red, white, blue)) levelplot(as.matrix(dat), at=seq( -.8, .4, length=31), col=color.palette(30) ) And next time, please post the output of dput rather than a mangled print() output. -- David. Thanks in advance! example... my matrix y looks something like this A B C DE row1 -0.5046406 -0.021579587-0.4419101 -0.2999195330 -0.4845047 row2 -0.3070091 -0.059065936 0.3329806 -0.0519335420 -0.5766368 row3 -0.7271707 0.073282855-0.3181990 -0.2485017700 -0.5732781 row4 0.3329806 -0.017762750-0.1513197 -0.1016354970 0.2528442 levelplot(y) yields a color scale from red (-0.8 to 0.2) to blue (0.2 to 0.4) I'd want the color scale to be from red (-0.8 to 0) to blue (0 to 0.4) - Lanna -- View this message in context: http://r.789695.n4.nabble.com/adjusting-levelplot-color-scale-to-data-tp3997342p3997342.html Sent from the R help mailing list archive at Nabble.com. __ 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. David Winsemius, MD West Hartford, CT __ 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. David Winsemius, MD West Hartford, CT __ 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] Graph binned data
On Nov 7, 2011, at 12:09 AM, Jeffrey Joh wrote: I have a table that looks like this: structure(list(speed = c(3,9,14,8,7,6), result = c(0.697, 0.011, 0.015, 0.012, 0.018, 0.019), house = c(1, 1, 1, 1, 1, 1), date = c(719, 1027, 1027, 1027, 1030, 1030), id = c(1000, 1, 10001, 10002, 10003, 10004)), .Names = c(speed, result, house, date, id), class = data.frame, row.names = c(1000, 1, 10001, 10002, 10003, 10004)) I would like to bin the data by speed, 0-4, 5-9, 10-14, 15-20, etc. ?cut Then I would like to make a graph of speed vs result. The graph should show the average result of each bin, ?tapply ?mean dat$sgrp - cut(dat$speed, c(0,5,10, 15, 20), include.lowest=TRUE, right=TRUE) plot( tapply(dat$speed, dat$sgrp, mean), xaxt=n, ylim=c(0,20)) axis(1, at= 1:4, labels = levels(dat$sgrp) ) and error bars to represent the standard deviation of the result in each bin. What kind of code can I use to make this? (This would seem to be pretty basic material. Why don't you do further study of whatever introductory texts you are using.) The CI's can be added with one of the functions in package 'plotrix'. Jeffrey __ 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. David Winsemius, MD West Hartford, CT __ 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] Structural equation modeling in R(lavaan,sem)
I am new to both sem and lavaan package ... I dint exactly get the difference between sem from sem package and sem from lavaan package... , -- View this message in context: http://r.789695.n4.nabble.com/Structural-equation-modeling-in-R-lavaan-sem-tp3409642p3997527.html Sent from the R help mailing list archive at Nabble.com. __ 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.