Re: [R] plot.mob() fails with cut() error 'breaks' are not unique
On Tue, 22 Jan 2013, Jason Musil wrote: DeaR all, I am using mob() for model based partitioning, with a dichotomous variable (participant's correct/incorrect response to a test item) regressed onto a continuous predictor related to a given property of the test item. Although this variable is continuous, the value of this variable for many items in this particular analysis is 0. The partitioning criterion is self-reported ability in a related area. mob1 - mob( correct ~ circular.mean | srp.dimension, control=mob_control(alpha=.001), model=glinearModel, family=binomial() ) plot(mob1) Error in cut.default(x, breaks = breaks, include.lowest = TRUE) : 'breaks' are not unique The same persists if I specify either a desired number of breaks, or explicit breakpoints (e.g. breaks=3 or breaks=c(-0.1,0.1,0.5)). I guess this is to do with the funny distribution of the predictor variable, but I'm not sure what to do about it. Jason, you can't pass the breaks argument to the plot method directly but need to pass it on to the panel function drawing the terminal panels. As an example consider example(mob) plot(fmPID) plot(fmPID, tp_args = list(breaks = c(0, 100, 120, 200))) Hope that fixes your problem. Best, Z Many thanks and apologies if this doesn't fit the mailing list---it is my first posting! Jason Musil __ 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] How to construct a valid seed for l'Ecuyer's method with given .Random.seed?
Since clusterSetupRNG() calls clusterSetupRNGstream() and this calls .lec.SetPackageSeed(), I could further minimalize the problem: set.seed(1) RNGkind(L'Ecuyer-CMRG) # = .Random.seed is of length 7 (first number encodes the rng kind) (seed - .Random.seed[2:7]) # should give a valid seed for l'Ecuyer's RNG require(rlecuyer) # latest version 0.3-3 .lec.SetPackageSeed(seed) The last line fails with: , | Error in .lec.SetPackageSeed(seed) : | Seed[0] = -767742437, Seed is not set. ` Looking at .lec.SetPackageSeed, seed seems to pass .lec.CheckSeed() [the check could probably be improved here (but further checking is done in the C code; see below)]: , | .lec.SetPackageSeed | function (seed = rep(12345, 6)) | { | if (!exists(.lec.Random.seed.table, envir = .GlobalEnv)) | .lec.init() | seed - .lec.CheckSeed(seed) # = bad check since it's passed | .Call(r_set_package_seed, as.double(seed), PACKAGE = rlecuyer) # = this fails! | return(seed) | } | environment: namespace:rlecuyer ` Going into the C code, r_set_package_seed calls RngStream_SetPackageSeed which in turn calls CheckSeed(seed). The relevant part of CheckSeed is this: , | for (i = 0; i 3; ++i) { | if (seed[i] = m1) { | /* HS 01-25-2012 */ | error(Seed[%1d] = %d, Seed is not set.\n, i,m1); |/* original code | fprintf (stderr, \n |ERROR: Seed[%1d] = m1, Seed is not set.\n |\n\n, i); | return (-1); |*/ | } | } ` Note that seed[0] in this (C-)code corresponds to the first element of my variable seed, which is -1535484873. This should definitely be smaller than m1 since m1 is defined as 4294967087.0 on line 34 in ./src/RngStream.c of the package 'rlecuyer'. Why is seed[i] then = m1??? This is strange. Indeed, as you can see from the error message above, m1 is taken as -767742437 in my case (why?). Still (and even more confusing), -1535484873 = -767742437 is FALSE (!) but the if(){} is entered anyways... Cheers, Marius __ 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] Dot plot of character and numeric matrix
Dear List, I have a set of data which looks like this (small set of sample) A A 0.431 A A 0.439 A A 0.507 A G 0.508 A A 0.514 I will like to use this data to plot a dot plot, with the X-axis being of type character, and my y axis of type numeric. When I try to use the dot chart function, I get the error message 'x' must be a numeric vector or matrix, which I can understand it to be a result of the fact that I have characters AA, AG etc as my x-values. Any idea how I can go about doing this? Thanks in advanced! Jeremy [[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] importing data
Dear All, Sorry for asking a newbie question. I want to ask how to import 1000 datasets whose file names are labelled from data1.dat to data1000.dat into R so that they are named M[1, , ] to M[1000, , ] accordingly. Thank you very much. Best Regards, Ray [[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] Simple use of dcast (reshape2 package)
On Tue, 22-Jan-2013 at 08:30AM -0500, Ista Zahn wrote: | Hi, | | ID is not the value column. Your casting call should be | | dcast(aa, ... ~ Target, value.var = Eaten) Thanks for that illumination. That does exactly what I wanted. I knew there were many ways of achieving the result, but I was particularly interested in understanding how dcast() would do it. It's also more elegant than any of the other ways of achieving the same result. Thanks also for the other suggestions from various other responders. P | | Best, | Ista | | On Tue, Jan 22, 2013 at 4:23 AM, Patrick Connolly | p_conno...@slingshot.co.nz wrote: | Suppose I have a small dataframe | | aa | Target Eaten ID | 50 TPP 0 1 | 51 TPP 1 2 | 52 TPP 3 3 | 53 TPP 1 4 | 54 TPP 2 5 | 50.1GPA 9 1 | 51.1GPA11 2 | 52.1GPA 8 3 | 53.1GPA 8 4 | 54.1GPA10 5 | | And I want to reshape it into | |ID TPP GPA | 1 1 0 9 | 2 2 1 11 | 3 3 3 8 | 4 4 1 8 | 5 5 2 10 | | I realise that dcast function in the reshape2 package can handle much | more complicated tasks than that, but I can't make it do a simple one. | | If I simply tried | | dcast(aa, ... ~ Target) | Using ID as value column: use value.var to override. | Aggregation function missing: defaulting to length |Eaten GPA TPP | 1 0 0 1 | 2 1 0 2 | 3 2 0 1 | 4 3 0 1 | 5 8 2 0 | 6 9 1 0 | 710 1 0 | 811 1 0 | | As per the help file, it's giving counts of the numbers in the Eaten | column since that's the default fun.aggregate value. | | My questions are: what fun.aggregate would work? Alternatively, can | value.var be set to something useful? | | TIA | | -- | ~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~. | ___Patrick Connolly | {~._.~} Great minds discuss ideas | _( Y )_ Average minds discuss events | (:_~*~_:) Small minds discuss people | (_)-(_) . Eleanor Roosevelt | | ~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~. | | __ | 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. -- ~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~. ___Patrick Connolly {~._.~} Great minds discuss ideas _( Y )_ Average minds discuss events (:_~*~_:) Small minds discuss people (_)-(_) . Eleanor Roosevelt ~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~. __ 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] dummy encoding in metafor
At 08:30 23/01/2013, Alma Wilflinger wrote: Dear Wolfgang and Michael, thank you very much for your help! Concerning the Variance: I took the variance I used for CMA (which is always 1), so I think it should be the right one. It seems unlikely to me that the variance from each study would be the same although I suppose it could be possible. Are you sure you are supplying the right values to CMA? Thank you for noticing and mentioning though :) I really appreciate how helpful you both are. best, Alma From: Viechtbauer Wolfgang (STAT) wolfgang.viechtba...@maastrichtuniversity.nl To: Michael Dewey i...@aghmed.fsnet.co.uk; Alma Wilflinger alma_an...@yahoo.com; r-help@r-project.org r-help@r-project.org Sent: Monday, January 21, 2013 11:10 AM Subject: RE: [R] dummy encoding in metafor As Michael already mentioned, the error: Error in qr.solve(wX, diag(k)) : singular matrix 'a' in solve indeed indicates that your design matrix is not of full rank (i.e., there are linear dependencies among your predictors). With this many factors in the same model, this is not surprising if k is only 94 (which is actually quite large for a meta-analysis). One options is to leave out some of the predictors. You can also try collapsing some of the levels of the factors. Of course, you lose some details that way, but apparently you don't have enough data in the first place to carry out such a detailed analysis. One other thing I noticed. You wrote: rma(yi=Mean, vi=Variance, ni=N.1, ...) I suspect that your variable Variance is actually the variance of the raw scores. However, the vi argument is used to pass the sampling variances of the yi values to the function -- not the variance of raw scores. The (estimated) sampling variance of a mean is s^2 / n, so if I am not mistaken, you really want to use: rma(yi=Mean, vi=Variance/N.1, ...) Best, Wolfgang -- Wolfgang Viechtbauer, Ph.D., Statistician Department of Psychiatry and Psychology School for Mental Health and Neuroscience Faculty of Health, Medicine, and Life Sciences Maastricht University, P.O. Box 616 (VIJV1) 6200 MD Maastricht, The Netherlands +31 (43) 388-4170 | http://www.wvbauer.com -Original Message- From: mailto:r-help-boun...@r-project.orgr-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Michael Dewey Sent: Monday, January 21, 2013 10:40 To: Alma Wilflinger; Michael Dewey; mailto:r-help@r-project.orgr-help@r-project.org Subject: Re: [R] dummy encoding in metafor At 14:48 20/01/2013, Alma Wilflinger wrote: Hi, thank you very much for your kind answer. If you look a bit further down the manual page you will see ### using a model formula to specify the same model rma(yi, vi, mods=~factor(alloc)+year+ablat, data=dat, method=REML, btt=c(2,3)) which is much easier. I have seen the possibility of using a model formula for dummy encoding and you are right it is much easier than doing it by hand. Thing is that if I include some moderator variables into the parameters I get the error: Error in qr.solve(wX, diag(k)) : singular matrix 'a' in solve I suspect that you have a linear dependence between your moderator variables. Depending on how many levels there are for country, sample, and so on you do have a lot of predictors (you presumably know that a factor counts as levels-1 for this purpose?) For example this call works: result = rma(yi=Mean, vi=Variance, ni=N.1, mods=~factor(Country) + relevel(factor(Sample), ref=Students) + Gender + Age + factor(Category) + relevel(factor(Block), ref=c)+ relevel(factor(order), ref=x), data=csvDataCmaAll, method=REML) If I add the trials which is of type INT: result = rma(yi=Mean, vi=Variance, ni=N.1, mods=~factor(Country) + relevel(factor(Sample), ref=Students) + Gender + Age + factor(Category) + relevel(factor(Block), ref=c)+ relevel(factor(order), ref=x) + trials, data=csvDataCmaAll, method=REML) I get the error and I was not able to find a definite reason for this error or how to solve it I wanted to try it by doing it manually. I think I have found out that it somehow relates to the If you code them yourself R does not know. You know. Regarding this I think my question was not clear enough. If R does the dummy encoding automatically via a model formula it leaves out one of the factors and uses it as a baseline automatically. If I do it by hand R is still able to execute the function but the baseline is missing because I do not define it via a parameter. You perhaps would benefit from rereading some of the introductory material about formulas. Also look for anything about the model matrix (also called the design matrix) I simply want to know how R is handling this and what I have to do by hand to get the correct results. Sorry, this may be a beginners question, but as stated I am new to this field. You say you have seven moderator variables. Unless you have a shed load of
[R] problems with coercing a factor to be numeric
Dear R listers, I am trying to compute the mean of a dummy variable that is encoded as a factor. However, even though the levels of my factor are 0 - 1, when I compute the mean (after coercing the factor to be numeric), R changes 0 into 1 and 1 into yes, thus altering my expected result. Please, consider the following working example: pp - rep(0:1, 10) pp - factor(pp, levels=(0:1), labels=c(no,yes)) mean(pp) #this won't work because the argument is not numeric or logical mean(as.integer(pp)) # this computes the average, but not on the range 0-1, but 1-2. Indeed, the result is 1.5 and not 0.5 as expected. What am I doing wrong? Thanks in advance for your kind support, f. -- Francesco Sarracino, Ph.D. https://sites.google.com/site/fsarracino/ [[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] problems with coercing a factor to be numeric
Check R FAQ 7.10: How do I convert factors to numeric? I hope it helps. Best, Dimitris On 1/23/2013 10:33 AM, Francesco Sarracino wrote: Dear R listers, I am trying to compute the mean of a dummy variable that is encoded as a factor. However, even though the levels of my factor are 0 - 1, when I compute the mean (after coercing the factor to be numeric), R changes 0 into 1 and 1 into yes, thus altering my expected result. Please, consider the following working example: pp - rep(0:1, 10) pp - factor(pp, levels=(0:1), labels=c(no,yes)) mean(pp) #this won't work because the argument is not numeric or logical mean(as.integer(pp)) # this computes the average, but not on the range 0-1, but 1-2. Indeed, the result is 1.5 and not 0.5 as expected. What am I doing wrong? Thanks in advance for your kind support, f. -- Dimitris Rizopoulos Assistant Professor Department of Biostatistics Erasmus University Medical Center Address: PO Box 2040, 3000 CA Rotterdam, the Netherlands Tel: +31/(0)10/7043478 Fax: +31/(0)10/7043014 Web: http://www.erasmusmc.nl/biostatistiek/ __ 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] problems with coercing a factor to be numeric
Dear Dimitris, thanks for your quick reply. I've tried the solutions proposed in 7.10 How do I convert factors to numeric? as.numeric(as.character(pp)) and as.numeric(levels(pp))[as.integer(pp)] However, whatever I do, I get Warning message: NAs introduced by coercion and the output is a vector of NA. Any ideas? f. On 23 January 2013 10:39, D. Rizopoulos d.rizopou...@erasmusmc.nl wrote: Check R FAQ 7.10: How do I convert factors to numeric? I hope it helps. Best, Dimitris On 1/23/2013 10:33 AM, Francesco Sarracino wrote: Dear R listers, I am trying to compute the mean of a dummy variable that is encoded as a factor. However, even though the levels of my factor are 0 - 1, when I compute the mean (after coercing the factor to be numeric), R changes 0 into 1 and 1 into yes, thus altering my expected result. Please, consider the following working example: pp - rep(0:1, 10) pp - factor(pp, levels=(0:1), labels=c(no,yes)) mean(pp) #this won't work because the argument is not numeric or logical mean(as.integer(pp)) # this computes the average, but not on the range 0-1, but 1-2. Indeed, the result is 1.5 and not 0.5 as expected. What am I doing wrong? Thanks in advance for your kind support, f. -- Dimitris Rizopoulos Assistant Professor Department of Biostatistics Erasmus University Medical Center Address: PO Box 2040, 3000 CA Rotterdam, the Netherlands Tel: +31/(0)10/7043478 Fax: +31/(0)10/7043014 Web: http://www.erasmusmc.nl/biostatistiek/ -- Francesco Sarracino, Ph.D. https://sites.google.com/site/fsarracino/ [[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] problems with coercing a factor to be numeric
check also pp - rep(0:1, 10) pp - factor(pp, levels=(0:1), labels=c(no,yes)) unclass(pp) unclass(pp) - 1 Best, Dimitris On 1/23/2013 10:48 AM, Francesco Sarracino wrote: Dear Dimitris, thanks for your quick reply. I've tried the solutions proposed in 7.10 How do I convert factors to numeric? as.numeric(as.character(pp)) and as.numeric(levels(pp))[as.integer(pp)] However, whatever I do, I get Warning message: NAs introduced by coercion and the output is a vector of NA. Any ideas? f. On 23 January 2013 10:39, D. Rizopoulos d.rizopou...@erasmusmc.nl mailto:d.rizopou...@erasmusmc.nl wrote: Check R FAQ 7.10: How do I convert factors to numeric? I hope it helps. Best, Dimitris On 1/23/2013 10:33 AM, Francesco Sarracino wrote: Dear R listers, I am trying to compute the mean of a dummy variable that is encoded as a factor. However, even though the levels of my factor are 0 - 1, when I compute the mean (after coercing the factor to be numeric), R changes 0 into 1 and 1 into yes, thus altering my expected result. Please, consider the following working example: pp - rep(0:1, 10) pp - factor(pp, levels=(0:1), labels=c(no,yes)) mean(pp) #this won't work because the argument is not numeric or logical mean(as.integer(pp)) # this computes the average, but not on the range 0-1, but 1-2. Indeed, the result is 1.5 and not 0.5 as expected. What am I doing wrong? Thanks in advance for your kind support, f. -- Dimitris Rizopoulos Assistant Professor Department of Biostatistics Erasmus University Medical Center Address: PO Box 2040, 3000 CA Rotterdam, the Netherlands Tel: +31/(0)10/7043478 tel:%2B31%2F%280%2910%2F7043478 Fax: +31/(0)10/7043014 tel:%2B31%2F%280%2910%2F7043014 Web: http://www.erasmusmc.nl/biostatistiek/ -- Francesco Sarracino, Ph.D. https://sites.google.com/site/fsarracino/ -- Dimitris Rizopoulos Assistant Professor Department of Biostatistics Erasmus University Medical Center Address: PO Box 2040, 3000 CA Rotterdam, the Netherlands Tel: +31/(0)10/7043478 Fax: +31/(0)10/7043014 Web: http://www.erasmusmc.nl/biostatistiek/ __ 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] problems with coercing a factor to be numeric
Thanks, this works! but I am surprised that R has such a strange behavior and that there is no way to control it. BTW, also as.integer(pp)-1 works! Still, it doesn't look to me as a first best. At any rate, thanks a lot for your help. f. On 23 January 2013 10:53, D. Rizopoulos d.rizopou...@erasmusmc.nl wrote: check also pp - rep(0:1, 10) pp - factor(pp, levels=(0:1), labels=c(no,yes)) unclass(pp) unclass(pp) - 1 Best, Dimitris On 1/23/2013 10:48 AM, Francesco Sarracino wrote: Dear Dimitris, thanks for your quick reply. I've tried the solutions proposed in 7.10 How do I convert factors to numeric? as.numeric(as.character(pp)) and as.numeric(levels(pp))[as.integer(pp)] However, whatever I do, I get Warning message: NAs introduced by coercion and the output is a vector of NA. Any ideas? f. On 23 January 2013 10:39, D. Rizopoulos d.rizopou...@erasmusmc.nl mailto:d.rizopou...@erasmusmc.nl wrote: Check R FAQ 7.10: How do I convert factors to numeric? I hope it helps. Best, Dimitris On 1/23/2013 10:33 AM, Francesco Sarracino wrote: Dear R listers, I am trying to compute the mean of a dummy variable that is encoded as a factor. However, even though the levels of my factor are 0 - 1, when I compute the mean (after coercing the factor to be numeric), R changes 0 into 1 and 1 into yes, thus altering my expected result. Please, consider the following working example: pp - rep(0:1, 10) pp - factor(pp, levels=(0:1), labels=c(no,yes)) mean(pp) #this won't work because the argument is not numeric or logical mean(as.integer(pp)) # this computes the average, but not on the range 0-1, but 1-2. Indeed, the result is 1.5 and not 0.5 as expected. What am I doing wrong? Thanks in advance for your kind support, f. -- Dimitris Rizopoulos Assistant Professor Department of Biostatistics Erasmus University Medical Center Address: PO Box 2040, 3000 CA Rotterdam, the Netherlands Tel: +31/(0)10/7043478 tel:%2B31%2F%280%2910%2F7043478 Fax: +31/(0)10/7043014 tel:%2B31%2F%280%2910%2F7043014 Web: http://www.erasmusmc.nl/biostatistiek/ -- Francesco Sarracino, Ph.D. https://sites.google.com/site/fsarracino/ -- Dimitris Rizopoulos Assistant Professor Department of Biostatistics Erasmus University Medical Center Address: PO Box 2040, 3000 CA Rotterdam, the Netherlands Tel: +31/(0)10/7043478 Fax: +31/(0)10/7043014 Web: http://www.erasmusmc.nl/biostatistiek/ -- Francesco Sarracino, Ph.D. https://sites.google.com/site/fsarracino/ [[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] Concatenate two lists, list by list
Thanks a lot Petr, for the answer unfortunately that would convert everything to a matrix num [1:32002, 1:3] 0 0 0 0 0 0 0 0 0 0 ... but if you check below you can see that I Want those to form a list. Regards Alex From: PIKAL Petr petr.pi...@precheza.cz Sent: Tuesday, January 22, 2013 11:51 AM Subject: RE: [R] Concatenate two lists, list by list Hi Maybe you could use mapply mapply(c, Part1$dataset,Part2$dataset) Regards Petr -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-bounces@r- project.org] On Behalf Of Alaios Sent: Tuesday, January 22, 2013 11:26 AM To: R help Subject: [R] Concatenate two lists, list by list Dear all, I would like to concatenate the lists below str(Part2$dataset) List of 3 $ : num [1:16001] 0 0 0 0 0 0 0 0 0 0 ... $ : num [1:16001] 0 0 0 0 0 0 0 0 0 0 ... $ : num [1:16001] 0 0 0 0 0 0 0 0 0 0 ... str(Part1$dataset) List of 3 $ : num [1:16001] 0 0 0 0 0 0 0 0 0 0 ... $ : num [1:16001] 0 0 0 0 0 0 0 0 0 0 ... $ : num [1:16001] 0 0 0 0 0 0 0 0 0 0 ... I tried concatenating those with: str(cbind(Part1$datase,Part2$dataset)) List of 6 $ : num [1:16001] 0 0 0 0 0 0 0 0 0 0 ... $ : num [1:16001] 0 0 0 0 0 0 0 0 0 0 ... $ : num [1:16001] 0 0 0 0 0 0 0 0 0 0 ... $ : num [1:16001] 0 0 0 0 0 0 0 0 0 0 ... $ : num [1:16001] 0 0 0 0 0 0 0 0 0 0 ... $ : num [1:16001] 0 0 0 0 0 0 0 0 0 0 ... - attr(*, dim)= int [1:2] 3 2 but I want something different. To concatenate those into a list by list operation so I will end up with something looking like that str(concatenatedLists) List of 3 $ : num [1:32002] 0 0 0 0 0 0 0 0 0 0 ... $ : num [1:32002] 0 0 0 0 0 0 0 0 0 0 ... $ : num [1:32002] 0 0 0 0 0 0 0 0 0 0 ... - attr(*, dim)= int [1:2] 3 2 Is there anything that can do that in R? Regards Alex [[alternative HTML version deleted]] [[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] Concatenate two lists, list by list
you just need: mapply(c, Part1$dataset, Part2$dataset, SIMPLIFY = FALSE) I hope it helps. Best, Dimitris On 1/23/2013 11:01 AM, Alaios wrote: Thanks a lot Petr, for the answer unfortunately that would convert everything to a matrix num [1:32002, 1:3] 0 0 0 0 0 0 0 0 0 0 ... but if you check below you can see that I Want those to form a list. Regards Alex From: PIKAL Petr petr.pi...@precheza.cz Sent: Tuesday, January 22, 2013 11:51 AM Subject: RE: [R] Concatenate two lists, list by list Hi Maybe you could use mapply mapply(c, Part1$dataset,Part2$dataset) Regards Petr -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-bounces@r- project.org] On Behalf Of Alaios Sent: Tuesday, January 22, 2013 11:26 AM To: R help Subject: [R] Concatenate two lists, list by list Dear all, I would like to concatenate the lists below str(Part2$dataset) List of 3 $ : num [1:16001] 0 0 0 0 0 0 0 0 0 0 ... $ : num [1:16001] 0 0 0 0 0 0 0 0 0 0 ... $ : num [1:16001] 0 0 0 0 0 0 0 0 0 0 ... str(Part1$dataset) List of 3 $ : num [1:16001] 0 0 0 0 0 0 0 0 0 0 ... $ : num [1:16001] 0 0 0 0 0 0 0 0 0 0 ... $ : num [1:16001] 0 0 0 0 0 0 0 0 0 0 ... I tried concatenating those with: str(cbind(Part1$datase,Part2$dataset)) List of 6 $ : num [1:16001] 0 0 0 0 0 0 0 0 0 0 ... $ : num [1:16001] 0 0 0 0 0 0 0 0 0 0 ... $ : num [1:16001] 0 0 0 0 0 0 0 0 0 0 ... $ : num [1:16001] 0 0 0 0 0 0 0 0 0 0 ... $ : num [1:16001] 0 0 0 0 0 0 0 0 0 0 ... $ : num [1:16001] 0 0 0 0 0 0 0 0 0 0 ... - attr(*, dim)= int [1:2] 3 2 but I want something different. To concatenate those into a list by list operation so I will end up with something looking like that str(concatenatedLists) List of 3 $ : num [1:32002] 0 0 0 0 0 0 0 0 0 0 ... $ : num [1:32002] 0 0 0 0 0 0 0 0 0 0 ... $ : num [1:32002] 0 0 0 0 0 0 0 0 0 0 ... - attr(*, dim)= int [1:2] 3 2 Is there anything that can do that in R? Regards Alex [[alternative HTML version deleted]] [[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. -- Dimitris Rizopoulos Assistant Professor Department of Biostatistics Erasmus University Medical Center Address: PO Box 2040, 3000 CA Rotterdam, the Netherlands Tel: +31/(0)10/7043478 Fax: +31/(0)10/7043014 Web: http://www.erasmusmc.nl/biostatistiek/ __ 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] [R-pkgs] lambda.r 1.1.0 on CRAN
Dear useRs, I'm pleased to announce that version 1.1.0 of lambda.r is now available on CRAN (http://cran.r-project.org/web/packages/lambda.r/). This package provides a complete functional programming environment within R (and is backwards compatible with S3). Lambda.r introduces many concepts including: . Multipart function definitions . Guard statements to control execution of functions . Pattern matching in function definitions . An intuitive type system . Optional strong typing via type constraints . Type variables . Cleaner syntax for attributes Using these techniques, systems can be written more efficiently and with less headache. Here is a brief example of what you can do with lambda.r. fib(n) %::% numeric : numeric fib(n) %when% { n 0 } %as% { stop(Negative numbers not allowed) } fib(0) %as% 1 fib(1) %as% 1 fib(n) %as% { fib(n-1) + fib(n-2) } fib(-1) Error in function (n) : Negative numbers not allowed fib(5) [1] 8 Documentation is available at the following locations: . http://cartesianfaith.wordpress.com/category/r/lambda-r/ . https://github.com/muxspace/lambda.r A more complete discussion on why analytical systems should be designed using functional programming principles will be available in my forthcoming book on functional programming and computational finance. Warm Regards, Brian Rowe ___ R-packages mailing list r-packa...@r-project.org https://stat.ethz.ch/mailman/listinfo/r-packages __ 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] dummy encoding in metafor
Dear Wolfgang and Michael, thank you very much for your help! Concerning the Variance: I took the variance I used for CMA (which is always 1), so I think it should be the right one. Thank you for noticing and mentioning though :) I really appreciate how helpful you both are. best, Alma From: Viechtbauer Wolfgang (STAT) wolfgang.viechtba...@maastrichtuniversity.nl To: Michael Dewey i...@aghmed.fsnet.co.uk; Alma Wilflinger alma_an...@yahoo.com; r-help@r-project.org r-help@r-project.org Sent: Monday, January 21, 2013 11:10 AM Subject: RE: [R] dummy encoding in metafor As Michael already mentioned, the error: Error in qr.solve(wX, diag(k)) : singular matrix 'a' in solve indeed indicates that your design matrix is not of full rank (i.e., there are linear dependencies among your predictors). With this many factors in the same model, this is not surprising if k is only 94 (which is actually quite large for a meta-analysis). One options is to leave out some of the predictors. You can also try collapsing some of the levels of the factors. Of course, you lose some details that way, but apparently you don't have enough data in the first place to carry out such a detailed analysis. One other thing I noticed. You wrote: rma(yi=Mean, vi=Variance, ni=N.1, ...) I suspect that your variable Variance is actually the variance of the raw scores. However, the vi argument is used to pass the sampling variances of the yi values to the function -- not the variance of raw scores. The (estimated) sampling variance of a mean is s^2 / n, so if I am not mistaken, you really want to use: rma(yi=Mean, vi=Variance/N.1, ...) Best, Wolfgang -- Wolfgang Viechtbauer, Ph.D., Statistician Department of Psychiatry and Psychology School for Mental Health and Neuroscience Faculty of Health, Medicine, and Life Sciences Maastricht University, P.O. Box 616 (VIJV1) 6200 MD Maastricht, The Netherlands +31 (43) 388-4170 | http://www.wvbauer.com -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Michael Dewey Sent: Monday, January 21, 2013 10:40 To: Alma Wilflinger; Michael Dewey; r-help@r-project.org Subject: Re: [R] dummy encoding in metafor At 14:48 20/01/2013, Alma Wilflinger wrote: Hi, thank you very much for your kind answer. If you look a bit further down the manual page you will see ### using a model formula to specify the same model rma(yi, vi, mods=~factor(alloc)+year+ablat, data=dat, method=REML, btt=c(2,3)) which is much easier. I have seen the possibility of using a model formula for dummy encoding and you are right it is much easier than doing it by hand. Thing is that if I include some moderator variables into the parameters I get the error: Error in qr.solve(wX, diag(k)) : singular matrix 'a' in solve I suspect that you have a linear dependence between your moderator variables. Depending on how many levels there are for country, sample, and so on you do have a lot of predictors (you presumably know that a factor counts as levels-1 for this purpose?) For example this call works: result = rma(yi=Mean, vi=Variance, ni=N.1, mods=~factor(Country) + relevel(factor(Sample), ref=Students) + Gender + Age + factor(Category) + relevel(factor(Block), ref=c)+ relevel(factor(order), ref=x), data=csvDataCmaAll, method=REML) If I add the trials which is of type INT: result = rma(yi=Mean, vi=Variance, ni=N.1, mods=~factor(Country) + relevel(factor(Sample), ref=Students) + Gender + Age + factor(Category) + relevel(factor(Block), ref=c)+ relevel(factor(order), ref=x) + trials, data=csvDataCmaAll, method=REML) I get the error and I was not able to find a definite reason for this error or how to solve it I wanted to try it by doing it manually. I think I have found out that it somehow relates to the If you code them yourself R does not know. You know. Regarding this I think my question was not clear enough. If R does the dummy encoding automatically via a model formula it leaves out one of the factors and uses it as a baseline automatically. If I do it by hand R is still able to execute the function but the baseline is missing because I do not define it via a parameter. You perhaps would benefit from rereading some of the introductory material about formulas. Also look for anything about the model matrix (also called the design matrix) I simply want to know how R is handling this and what I have to do by hand to get the correct results. Sorry, this may be a beginners question, but as stated I am new to this field. You say you have seven moderator variables. Unless you have a shed load of studies you will not be able to look at them simultaneously. Apologies if you already knew that. No I have not known that. In total I have about 94 studies and want to test different sets of moderators. Do you think this is sufficient
[R] generating ccensoring time for constant survival rate
Dear R-ers, I've generated data for failure times log(T) from standard normal distribution. How can I generate data for censoring times from log-normal distribution which ý can get constatnt hazard rate. [[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] mixed effects meta-regression: nlme vs. metafor
Hi, I would like to do a meta-analysis, i.e., a mixed-effects regression, but I don't seem to get what I want using both the nlme or metafor packages. My question: is there indeed no way to do it? And if so, is there another package I could use? Here are the details: In my meta-analysis I'm comparing different studies that report a measure at time zero and after a certain followup time. Each reported measurement comes with standard error, and each study uses one (or several) of a few treatment categories. I want to fit a random effect for each study (the study effect) and a treatment-dependent time effect. For the moment I use a linear model, i.e., twice the followup time will give you twice the effect, etc... I get /almost/ what I want using nlme via this command: lme01 - lme(effect ~ treatment + treatment*time - time - 1, random = ~ 1|study, weights = varFixed(~se2), data = dat) effect is the real-valued measurement, treatment is a factor, and time is the followup time in months. se2 is the squared standard error. Problem is: using the varFixed() option, lme() will fit an additional variance parameter scaling the provided standard errors by a certain factor to be estimated. According to some discussions on the web, you once were able to prevent the fitting of the extra variance parameter in some pre-1998 S-plus versions of nlme using a lmeControl(sigma=1) option, but this does not appear to available any more. I again get /almost/ what I want using the metafor package: rma01 - rma(yi = effect, vi = se2, mods = ~ treatment + treatment*time - time - 1, data = dat) rma() will correctly digest the provided standard errors, but this time the problem is that rma() will always treat each line in the data set as a different study, there does not appear to be a way to tell rma() that several data points belong to the same study, i.e., have a common random effect. What I am missing is an equivalent to the random statement in the lme() command above. Adding an option like slab=as.character(dat$study) only seems to affect the labeling but not the actual computation. Any ideas? Many thanks in advance, Christian Roever __ 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] New Book: Statistical Psychology with R [in French]
Dear M. Noel: You may know that there is a list of books on the R web site (www.r-project.org - books: www.r-project.org/doc/bib/R-books.html). I'm not sure what you should do to get this book listed there. If no one else suggests what to do, you might wish to write to Frau Palege in the Institut für Statistik und Mathematik, Wirtschaftsuniversität Wien, evelyn.pal...@wu.ac.at. If she does not handle this, she might be able to find someone who does. Best Wishes, Spencer On 1/22/2013 11:56 PM, Yvonnick Noel wrote: Dear useRs, French reading people among you might be interested by the following book: Noel, Y. (2013). Psychologie statistique avec R [Statistical psychology with R, in French], coll. PratiqueR, Paris: Springer. http://www.springer.com/psychology/book/978-2-8178-0424-8 This book provides a detailed presentation of all basics of statistical inference for psychologists, both in a fisherian and a bayesian approach. Although many authors have recently advocated for the use of bayesian statistics in psychology (Wagenmaker et al., 2010, 2011 ; Kruschke, 2010 ; Rouder et al., 2009) statistical manuals for psychologists barely mention them. This manual provides a full bayesian toolbox for commonly encountered problems in psychology and social sciences, for comparing proportions, variances and means, and discusses the advantages. But all foundations of the frequentist approach are also provided, from data description to probability and density, through combinatorics and set algebra. A special emphasis has been put on the analysis of categorical data and contingency tables. Binomial and multinomial models with beta and Dirichlet priors are presented, and their use for making (between rows or between cells) contrasts in contingency tables is detailed on real data. An automatic search of the best model for all problem types is implemented in the AtelieR package, available on CRAN. Bayesian ANOVA is also presented, and illustrated on real data with the help of the AtelieR and R2STATS packages (a GUI for GLM and GLMM in R). In addition to classical and Bayesian inference on means, direct and Bayesian inference on effect size and standardized effects are presented. I hope you might find this book useful, Best regards, Yvonnick Noel University of Brittany, Rennes France __ 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. -- Spencer Graves, PE, PhD President and Chief Technology Officer Structure Inspection and Monitoring, Inc. 751 Emerson Ct. San José, CA 95126 ph: 408-655-4567 web: www.structuremonitoring.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] Concatenate two lists, list by list
Thanks a lot. Unfortunately that did not help either. num [1:32003, 1:3] 0 0 0 0 0 0 0 0 0 0 ... - attr(*, dimnames)=List of 2 ..$ : chr [1:32003] ... ..$ : NULL but I want to get List of 3 $ : num [1:32002] 0 0 0 0 0 0 0 0 0 0 ... $ : num [1:32002] 0 0 0 0 0 0 0 0 0 0 ... $ : num [1:32002] 0 0 0 0 0 0 0 0 0 0 ... - attr(*, dim)= int [1:2] 3 2 I am sorry that I can not find reproducible example to show you Alex From: D. Rizopoulos d.rizopou...@erasmusmc.nl Cc: PIKAL Petr petr.pi...@precheza.cz; R help R-help@r-project.org Sent: Wednesday, January 23, 2013 11:08 AM Subject: Re: [R] Concatenate two lists, list by list you just need: mapply(c, Part1$dataset, Part2$dataset, SIMPLIFY = FALSE) I hope it helps. Best, Dimitris On 1/23/2013 11:01 AM, Alaios wrote: Thanks a lot Petr, for the answer unfortunately that would convert everything to a matrix num [1:32002, 1:3] 0 0 0 0 0 0 0 0 0 0 ... but if you check below you can see that I Want those to form a list. Regards Alex From: PIKAL Petr petr.pi...@precheza.cz Sent: Tuesday, January 22, 2013 11:51 AM Subject: RE: [R] Concatenate two lists, list by list Hi Maybe you could use mapply mapply(c, Part1$dataset,Part2$dataset) Regards Petr -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-bounces@r- project.org] On Behalf Of Alaios Sent: Tuesday, January 22, 2013 11:26 AM To: R help Subject: [R] Concatenate two lists, list by list Dear all, I would like to concatenate the lists below str(Part2$dataset) List of 3 $ : num [1:16001] 0 0 0 0 0 0 0 0 0 0 ... $ : num [1:16001] 0 0 0 0 0 0 0 0 0 0 ... $ : num [1:16001] 0 0 0 0 0 0 0 0 0 0 ... str(Part1$dataset) List of 3 $ : num [1:16001] 0 0 0 0 0 0 0 0 0 0 ... $ : num [1:16001] 0 0 0 0 0 0 0 0 0 0 ... $ : num [1:16001] 0 0 0 0 0 0 0 0 0 0 ... I tried concatenating those with: str(cbind(Part1$datase,Part2$dataset)) List of 6 $ : num [1:16001] 0 0 0 0 0 0 0 0 0 0 ... $ : num [1:16001] 0 0 0 0 0 0 0 0 0 0 ... $ : num [1:16001] 0 0 0 0 0 0 0 0 0 0 ... $ : num [1:16001] 0 0 0 0 0 0 0 0 0 0 ... $ : num [1:16001] 0 0 0 0 0 0 0 0 0 0 ... $ : num [1:16001] 0 0 0 0 0 0 0 0 0 0 ... - attr(*, dim)= int [1:2] 3 2 but I want something different. To concatenate those into a list by list operation so I will end up with something looking like that str(concatenatedLists) List of 3 $ : num [1:32002] 0 0 0 0 0 0 0 0 0 0 ... $ : num [1:32002] 0 0 0 0 0 0 0 0 0 0 ... $ : num [1:32002] 0 0 0 0 0 0 0 0 0 0 ... - attr(*, dim)= int [1:2] 3 2 Is there anything that can do that in R? Regards Alex [[alternative HTML version deleted]] [[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. -- Dimitris Rizopoulos Assistant Professor Department of Biostatistics Erasmus University Medical Center Address: PO Box 2040, 3000 CA Rotterdam, the Netherlands Tel: +31/(0)10/7043478 Fax: +31/(0)10/7043014 Web: http://www.erasmusmc.nl/biostatistiek/ [[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] Nesting fixed factors in lme4 package
Hi, thanks. I am indeed interested in the main effects of A and B and their interaction+ I want to incorporate C (the block or 'repetition' within which the A and B treatments were applied) as a random variable. So A*B would be the way, however errors of A and B are different due to different experimental plot sizes. When doing Anova the correct code should be this: summary(aov(ln_response) ~ A*B + Error(rep/A), data=Exp2) in which case the effect of A is calculated by using error A*rep and the effect of B and A*B is calculated using pooled error of B*rep and A*B*rep This I dont know how to specify in glmer. Maybe 'nesting' is not a right term to use (?) To: r-h...@stat.math.ethz.ch From: bbol...@gmail.com Date: Fri, 18 Jan 2013 14:07:02 + Subject: Re: [R] Nesting fixed factors in lme4 package Martina Ozan martina_ozan at hotmail.com writes: Hi, can anyone tell me how to nest two fixed factors using glmer in lme4? I have a split-plot design with two fixed factors - A (whole plot factor) and B (subplot factor), both with two levels. I want to do GLMM as I also want to include different plots as a random factor. But I am interested on the effect of A a B and their interaction on the response variable. I tried this:glmer(response~A*B+(A/B)+(1|C),data=Exp2,family=poisson but it gives the same output as if I removed (A/B) all together or used (A:B) instead thus the output is the same as: glmer(response~A*B+(1|C),data=Exp2,family=poisson anyone can help with how I define this nesting, so that data are analysed correctly given my split-plot design? thanks, Martina In general mixed model questions should go to r-sig-mixed-mod...@r-project.org , but this is actually *not* specifically a mixed model problem. If A and B are fixed factors, you're typically interested in A*B, which translates to 1+A+B+A:B, i.e. intercept; main effects of A and of B; and the interaction. The nesting syntax A/B translates to 1 + A + A:B, i.e. no main effect of B. Nesting would typically make more sense in a random-effects context where the meaning of B=1 in unit A=1 is different from B=1 in unit A=2, i.e. where you don't want or it doesn't make sense to estimate a main effect of B across levels of A. Ben Bolker __ 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.
Re: [R] Concatenate two lists, list by list
In this example, I get the following: lis1 - replicate(3, rnorm(5), simplify = FALSE) lis2 - replicate(3, rnorm(5), simplify = FALSE) lis1 lis2 mapply(c, lis1, lis2, SIMPLIFY = FALSE) Best, Dimitris On 1/23/2013 11:58 AM, Alaios wrote: Thanks a lot. Unfortunately that did not help either. num [1:32003, 1:3] 0 0 0 0 0 0 0 0 0 0 ... - attr(*, dimnames)=List of 2 ..$ : chr [1:32003] ... ..$ : NULL but I want to get List of 3 $ : num [1:32002] 0 0 0 0 0 0 0 0 0 0 ... $ : num [1:32002] 0 0 0 0 0 0 0 0 0 0 ... $ : num [1:32002] 0 0 0 0 0 0 0 0 0 0 ... - attr(*, dim)= int [1:2] 3 2 I am sorry that I can not find reproducible example to show you Alex *From:* D. Rizopoulos d.rizopou...@erasmusmc.nl *To:* Alaios ala...@yahoo.com *Cc:* PIKAL Petr petr.pi...@precheza.cz; R help R-help@r-project.org *Sent:* Wednesday, January 23, 2013 11:08 AM *Subject:* Re: [R] Concatenate two lists, list by list you just need: mapply(c, Part1$dataset, Part2$dataset, SIMPLIFY = FALSE) I hope it helps. Best, Dimitris On 1/23/2013 11:01 AM, Alaios wrote: Thanks a lot Petr, for the answer unfortunately that would convert everything to a matrix num [1:32002, 1:3] 0 0 0 0 0 0 0 0 0 0 ... but if you check below you can see that I Want those to form a list. Regards Alex From: PIKAL Petr petr.pi...@precheza.cz mailto:petr.pi...@precheza.cz Sent: Tuesday, January 22, 2013 11:51 AM Subject: RE: [R] Concatenate two lists, list by list Hi Maybe you could use mapply mapply(c, Part1$dataset,Part2$dataset) Regards Petr -Original Message- From: r-help-boun...@r-project.org mailto:r-help-boun...@r-project.org [mailto:r-help-bounces@r- project.org http://project.org/] On Behalf Of Alaios Sent: Tuesday, January 22, 2013 11:26 AM To: R help Subject: [R] Concatenate two lists, list by list Dear all, I would like to concatenate the lists below str(Part2$dataset) List of 3 $ : num [1:16001] 0 0 0 0 0 0 0 0 0 0 ... $ : num [1:16001] 0 0 0 0 0 0 0 0 0 0 ... $ : num [1:16001] 0 0 0 0 0 0 0 0 0 0 ... str(Part1$dataset) List of 3 $ : num [1:16001] 0 0 0 0 0 0 0 0 0 0 ... $ : num [1:16001] 0 0 0 0 0 0 0 0 0 0 ... $ : num [1:16001] 0 0 0 0 0 0 0 0 0 0 ... I tried concatenating those with: str(cbind(Part1$datase,Part2$dataset)) List of 6 $ : num [1:16001] 0 0 0 0 0 0 0 0 0 0 ... $ : num [1:16001] 0 0 0 0 0 0 0 0 0 0 ... $ : num [1:16001] 0 0 0 0 0 0 0 0 0 0 ... $ : num [1:16001] 0 0 0 0 0 0 0 0 0 0 ... $ : num [1:16001] 0 0 0 0 0 0 0 0 0 0 ... $ : num [1:16001] 0 0 0 0 0 0 0 0 0 0 ... - attr(*, dim)= int [1:2] 3 2 but I want something different. To concatenate those into a list by list operation so I will end up with something looking like that str(concatenatedLists) List of 3 $ : num [1:32002] 0 0 0 0 0 0 0 0 0 0 ... $ : num [1:32002] 0 0 0 0 0 0 0 0 0 0 ... $ : num [1:32002] 0 0 0 0 0 0 0 0 0 0 ... - attr(*, dim)= int [1:2] 3 2 Is there anything that can do that in R? Regards Alex [[alternative HTML version deleted]] [[alternative HTML version deleted]] __ R-help@r-project.org mailto: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. -- Dimitris Rizopoulos Assistant Professor Department of Biostatistics Erasmus University Medical Center Address: PO Box 2040, 3000 CA Rotterdam, the Netherlands Tel: +31/(0)10/7043478 Fax: +31/(0)10/7043014 Web: http://www.erasmusmc.nl/biostatistiek/ -- Dimitris Rizopoulos Assistant Professor Department of Biostatistics Erasmus University Medical Center Address: PO Box 2040, 3000 CA Rotterdam, the Netherlands Tel: +31/(0)10/7043478 Fax: +31/(0)10/7043014 Web: http://www.erasmusmc.nl/biostatistiek/ __ 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] CFA with lavaan or with SEM
Hi Sorry for the rather long message. I am trying to use the cfa command in the lavaan package to run a CFA however I am unsure over a couple of issues. I have @25 dichotomous variables, 300 observations and an EFA on a training dataset suggests a 3 factor model. After defining the model I use the command fit.dat - cfa(model.1, data=my.dat, std.lv = T, estimator=WLSMV, ordered=c(var1,var2 and so on for the other 23 variables)) Is it right that I define the variables as ordered (the output returns thresholds suggesting I should). Does the cfa command calculate tetrachoric correlations in the background? However, output for the command returns two variables with small negative variances (-0.002) which I think is due to the correlation matrix not being positive definite. Is it reasonable to force these to be zero when defining the model or is this more a sign of problems with the model? As an alternative is it possible to calculate the tetrachoric correlations using hetcor (which applies smoothing) and then use the smoothed sample correlation as the input to the model, such as fit.cor - cfa(model.1, sample.cov=my.hetcor, sample.nobs=300, std.lv = T,estimator=ML, ordered=c(var1,var2 and so on for the other 23 variables)). This however does not produce thresholds suggesting what I have tried is nonsense but is there a way to do this? Final question is I have a lot of missing data - listwise deletion leaves 90 subjects. Is there a way to calculate estimates using pairwise deletion (this is another reason why I tried using the correlation matrix as the input). I have tried the analysis using John Fox's SEM package / command. I calculate the correlation matrix with smoothing my.cor-hetcor(north.dat.sub,use=pairwise.complete.obs)$correlations This returns the warning indicating that the correlation matrix was adjusted to make it positive definite. However the following sem model does not run, with the error message that the matrix is non-invertible. mod1-sem::sem(sem .model.1, S=my.cor, 300) Should the smoothing not allow it to be inverted? thanks for help, david The University of Glasgow, charity number SC004401 [[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] mixed effects meta-regression: nlme vs. metafor
Hello Christian, First of all, it's good to see that you are well aware of the fact that lme() without lmeControl(sigma=1) will lead to the estimation of the residual variance component, which implies that the sampling variances specified via varFixed() are only assumed to be known up to a proportionality constant -- however, in the usual meta-analytic models, we assume that the sampling variances are exactly known. In fact, trying to disentangle that residual variance component from any random study effects is usually next to impossible. I mention this explicitly one more time, because I have seen some publications using lme() in exactly this way ... Indeed, lmeControl(sigma=1) is an option only available in (at least some versions of) S-Plus (I know that it is available in version 6). Of course, that's not that helpful unless you happen to have a copy of S-Plus. In fact, I ended up developing the metafor package (which started out with a function called mima() that is essentially the predecessor of the rma() function) for that very reason -- I needed a function to fit the meta-analytic random- and mixed-effects models. As you are also aware of, right now, rma() adds a random effect per observation (i.e., observed effect or outcome), while you want a random effect per study (which of course only matters if you have more than one outcome per study -- as in your example). I have a function in the works that will allow you to do just that. It's not in the package yet, but it will be in the future. This essentially relates back to numerous requests I have received for adding functions to the metafor package that will handle multivariate meta-analytic models, dependent outcomes, and things like network meta-analyses. And to my shame, I have said numerous times: Yes, it's in the works, it will be in the package in the future, don't know yet when (don't hold your breath). It's probably just as frustrating for me not to find the time to work as much on the package as I would like as it is for those waiting for me to get around to actually adding that functionality to the package. I actually have picked up quite a bit of steam in terms of working on the package recently. I am very close to releasing an updated version, the package website (http://www.metafor-project.org/ ) has been totally revamped (and is starting to become actually useful), and a bit of grant money is soon trickling in my direction that involves certain developments in the package. The updated version of the package still does not include that aforementioned function, but I may consider putting a pre-alpha version on the website so that the adventurous are able to try it out. Alternatively, you could try taking a look at MCMCglmm (http://cran.r-project.org/web/packages/MCMCglmm/index.html), which should be able to fit the model that you want. Can't give you any details on how, but if you get stuck, try posting to R-sig-mixed-models and Jarrod Hadfield (the MCMCglmm package author) is very likely to help you further. Best, Wolfgang -- Wolfgang Viechtbauer, Ph.D., Statistician Department of Psychiatry and Psychology School for Mental Health and Neuroscience Faculty of Health, Medicine, and Life Sciences Maastricht University, P.O. Box 616 (VIJV1) 6200 MD Maastricht, The Netherlands +31 (43) 388-4170 | http://www.wvbauer.com -Original Message- From: Christian Röver [mailto:christian.roe...@med.uni-goettingen.de] Sent: Wednesday, January 23, 2013 11:10 To: r-help@r-project.org Cc: Wolfgang Viechtbauer Subject: mixed effects meta-regression: nlme vs. metafor Hi, I would like to do a meta-analysis, i.e., a mixed-effects regression, but I don't seem to get what I want using both the nlme or metafor packages. My question: is there indeed no way to do it? And if so, is there another package I could use? Here are the details: In my meta-analysis I'm comparing different studies that report a measure at time zero and after a certain followup time. Each reported measurement comes with standard error, and each study uses one (or several) of a few treatment categories. I want to fit a random effect for each study (the study effect) and a treatment-dependent time effect. For the moment I use a linear model, i.e., twice the followup time will give you twice the effect, etc... I get /almost/ what I want using nlme via this command: lme01 - lme(effect ~ treatment + treatment*time - time - 1, random = ~ 1|study, weights = varFixed(~se2), data = dat) effect is the real-valued measurement, treatment is a factor, and time is the followup time in months. se2 is the squared standard error. Problem is: using the varFixed() option, lme() will fit an additional variance parameter scaling the provided standard errors by a certain factor to be estimated. According to some discussions on the web, you once
Re: [R] summarise subsets of a vector
Or maybe x-matrix(test,nrow=10) apply(x,2,mean) On 23.01.2013, at 00:09, Wim Kreinen wrote: Hello, I have vector called test. And now I wish to measure the mean of the first 10 number, the second 10 numbers etc How does it work? Thanks Wim dput (test) c(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.71, 0.21875, 0, 0.27375, 0.26125, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.84125, 0.0575, 0.92625, 0.12, 0, 0) [[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] importing data
On Wed, Jan 23, 2013 at 9:16 AM, Ray Cheung ray1...@gmail.com wrote: Dear All, Sorry for asking a newbie question. I want to ask how to import 1000 datasets whose file names are labelled from data1.dat to data1000.dat into R so that they are named M[1, , ] to M[1000, , ] accordingly. Thank you very much. , Hi Ray, I'm pretty sure you don't mean named M[1,,] etc. but rather that there's only one object M and that's how the slices come into existence: What you'll want to do is something like this: little_helpful_function(n){ file_name - paste(data, n, .dat, sep = ) read.dta(file_name, ##OTHER PARAMETERS) } list_of_datasets - lapply(1:1000, little_helpful_function) output - do.call(c, list_of_datasets) dim(output) - c(dim(list_of_datasets[[1]]), 1000) Or something like that. Note that I'm not quite sure what a dta file is, so I'll leave it to you to find an appropriate read.dta function. Feel free to write back (cc'ing the list) if you don't understand all of the above. Cheers, Michael Best Regards, Ray [[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] Dot plot of character and numeric matrix
As an example: chars-c(A,A,B) numbers-as.numeric(as.factor(chars)) #make this numerical plot(numbers,c(0.4,0.5,0.6),xaxt=n) #xaxt=n says to not plot the x-axis axis(side=1,at=numbers,labels=chars) #make the axis with labels On 23.01.2013, at 10:16, Ng Wee Kiat Jeremy wrote: Dear List, I have a set of data which looks like this (small set of sample) A A 0.431 A A 0.439 A A 0.507 A G 0.508 A A 0.514 I will like to use this data to plot a dot plot, with the X-axis being of type character, and my y axis of type numeric. When I try to use the dot chart function, I get the error message 'x' must be a numeric vector or matrix, which I can understand it to be a result of the fact that I have characters AA, AG etc as my x-values. Any idea how I can go about doing this? Thanks in advanced! Jeremy [[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] how to read a df like that and transform it?
Dear all I have a data.frame like that : father mother num_daughterdaughter 291 39060 NULL 275 42190 NULL 273 42361 49410 281 41631 49408 274 42261 49406 295 38692 49403 49404 287 41130 NULL 295 38711 49401 292 38954 49396 49397 49398 49399 291 39003 49392 How to read it into R and transform it like that: father mother num_daughter daughter1 daughter2 daughter3 daughter4 291 39060 NULL 275 42190 NULL 273 42361 49410 281 41631 49408 274 42261 49406 295 38692 49403 49404 287 41130 NULL 295 38711 49401 292 38954 49396 4939749398 49399 291 39003 49392 library (plyr) and library (reshape2) and other good packages are OK for me. Thanks a lot! Yao He — Master candidate in 2rd year Department of Animal genetics breeding Room 436,College of Animial ScienceTechnology, China Agriculture University,Beijing,100193 E-mail: yao.h.1...@gmail.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] how to read a df like that and transform it?
I don't really understand this data table, but maybe this modification will give you the idea: dat - read.table(text=father mother num_daughterdaughter 291 39060 NA 275 42190 NA 273 42361 49410 281 41631 49408 274 42261 49406 295 38692 49403 287 41130 NA 295 38711 49401 292 38954 49396 291 39003 49392, header=TRUE) library(reshape2) dat$num_daughter - paste0(daughter, dat$num_daughter) dcast(dat, ... ~ num_daughter, value.var=daughter) Best, Ista On Wed, Jan 23, 2013 at 7:42 AM, Yao He yao.h.1...@gmail.com wrote: Dear all I have a data.frame like that : father mother num_daughterdaughter 291 39060 NULL 275 42190 NULL 273 42361 49410 281 41631 49408 274 42261 49406 295 38692 49403 49404 287 41130 NULL 295 38711 49401 292 38954 49396 49397 49398 49399 291 39003 49392 How to read it into R and transform it like that: father mother num_daughter daughter1 daughter2 daughter3 daughter4 291 39060 NULL 275 42190 NULL 273 42361 49410 281 41631 49408 274 42261 49406 295 38692 49403 49404 287 41130 NULL 295 38711 49401 292 38954 49396 4939749398 49399 291 39003 49392 library (plyr) and library (reshape2) and other good packages are OK for me. Thanks a lot! Yao He — Master candidate in 2rd year Department of Animal genetics breeding Room 436,College of Animial ScienceTechnology, China Agriculture University,Beijing,100193 E-mail: yao.h.1...@gmail.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] Average calculations
Dear all, I have a matrix with two columns: Names and Values In names: there are 4 groups they are, CK113234, CK116296, CK116292 and CK114042 I want to *sort values* (decreasing order) based on each group and take average of the *top two numbers* in each of the groups. dput(x) structure(list(Names = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 5L, 5L, 5L, 5L, 2L, 2L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L), .Label = c(CK113234, CK113298, CK114042, CK116292, CK116296), class = factor), Values = c(208.3360, 223.29665, 221.63255, 211.29735, 217.75112, 210.97916, 222.67365, 216.0822, 189.83685, 194.1595, 210.66298, 223.63718333, 187.74864, 192.5964, 237.593625, 216.8277, 225.8966, 228.00374, 214.99454, 211.38114, 218.7659, 209.9958, 214.8041, 215.184489473684, 224.2446, 217.559878571429, 232.02229167, 214.02384, 236.393875, 228.73522)), .Names = c(Names, Values), class = data.frame, row.names = c(NA, 30L)) The out put will look like following: Names Values CK113234 222,98 CK116296 217,14 CK116292 232,79 CK114042 234,2 Your help is appreciated. Regards Nico [[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] Regression with 3 measurement points
Dear R Mailinglist, I want to understand how predictors are associated with a dependent variable in a regression. I have 3 measurement points. I'm not interested in understanding the associations of regressors and the predictor at each measurement separately, instead I would like to use the whole sample in one regression, pooling the measurement points. I cannot simply throw them together, because the observations are not independent. Therefore, I think I need to add time as a regressor. How do I do this in R? Google leads me to time-series analysis more often than not, but from in other statistical programs and longitudinal research, the word time-series is usually reserved for 5+ measurement points. Thank you T [[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] mixed effects meta-regression: nlme vs. metafor
Hi Wolfgang, thanks for the instant and comprehensive reply! On 01/23/2013 12:39 PM, Viechtbauer Wolfgang (STAT) wrote: [...] In fact, trying to disentangle that residual variance component from any random study effects is usually next to impossible. I mention this explicitly one more time, because I have seen some publications using lme() in exactly this way ... I'm not too surprised -- it was only after some double-checking that I noticed that variances are not actually fixed when using the varFixed option... [...] The updated version of the package still does not include that aforementioned function, but I may consider putting a pre-alpha version on the website so that the adventurous are able to try it out. I'm looking forward to it...! Alternatively, you could try taking a look at MCMCglmm (http://cran.r-project.org/web/packages/MCMCglmm/index.html), which should be able to fit the model that you want. Can't give you any details on how, but if you get stuck, try posting to R-sig-mixed-models and Jarrod Hadfield (the MCMCglmm package author) is very likely to help you further. Thanks; I was also thinking of switching to OpenBUGS + R2OpenBUGS, which should provide the necessary flexibility at the price of some extra complication... but having worked with it before, it should be doable... Cheers, Christian __ 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] Average calculations
Hi Nico, You can use tapply: tapply( x[[Values ]], x[[ Names ]], mean ) CK113234 CK113298 CK114042 CK116292 CK116296 216.5061 190.1725 222.8710 220.4324 204.5741 Alternatively, tapply( x$Values, x$Names, mean ) CK113234 CK113298 CK114042 CK116292 CK116296 216.5061 190.1725 222.8710 220.4324 204.5741 Hope it helps. José José Iparraguirre Chief Economist Age UK -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Nico Met Sent: 23 January 2013 13:04 To: R help Subject: [R] Average calculations Dear all, I have a matrix with two columns: Names and Values In names: there are 4 groups they are, CK113234, CK116296, CK116292 and CK114042 I want to *sort values* (decreasing order) based on each group and take average of the *top two numbers* in each of the groups. dput(x) structure(list(Names = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 5L, 5L, 5L, 5L, 2L, 2L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L), .Label = c(CK113234, CK113298, CK114042, CK116292, CK116296), class = factor), Values = c(208.3360, 223.29665, 221.63255, 211.29735, 217.75112, 210.97916, 222.67365, 216.0822, 189.83685, 194.1595, 210.66298, 223.63718333, 187.74864, 192.5964, 237.593625, 216.8277, 225.8966, 228.00374, 214.99454, 211.38114, 218.7659, 209.9958, 214.8041, 215.184489473684, 224.2446, 217.559878571429, 232.02229167, 214.02384, 236.393875, 228.73522)), .Names = c(Names, Values), class = data.frame, row.names = c(NA, 30L)) The out put will look like following: Names Values CK113234 222,98 CK116296 217,14 CK116292 232,79 CK114042 234,2 Your help is appreciated. Regards Nico [[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. Wrap Up and Run 10k is back! Also, new for 2013 – 2km intergenerational walks at selected venues. So recruit a buddy, dust off the trainers and beat the winter blues by signing up now: http://www.ageuk.org.uk/10k Milton Keynes | Oxford | Sheffield | Crystal Palace | Exeter | Harewood House, Leeds | Tatton Park, Cheshire | Southampton | Coventry Age UK Improving later life http://www.ageuk.org.uk --- Age UK is a registered charity and company limited by guarantee, (registered charity number 1128267, registered company number 6825798). Registered office: Tavis House, 1-6 Tavistock Square, London WC1H 9NA. For the purposes of promoting Age UK Insurance, Age UK is an Appointed Representative of Age UK Enterprises Limited, Age UK is an Introducer Appointed Representative of JLT Benefit Solutions Limited and Simplyhealth Access for the purposes of introducing potential annuity and health cash plans customers respectively. Age UK Enterprises Limited, JLT Benefit Solutions Limited and Simplyhealth Access are all authorised and regulated by the Financial Services Authority. -- This email and any files transmitted with it are confidential and intended solely for the use of the individual or entity to whom they are addressed. If you receive a message in error, please advise the sender and delete immediately. Except where this email is sent in the usual course of our business, any opinions expressed in this email are those of the author and do not necessarily reflect the opinions of Age UK or its subsidiaries and associated companies. Age UK monitors all e-mail transmissions passing through its network and may block or modify mails which are deemed to be unsuitable. Age Concern England (charity number 261794) and Help the Aged (charity number 272786) and their trading and other associated companies merged on 1st April 2009. Together they have formed the Age UK Group, dedicated to improving the lives of people in later life. The three national Age Concerns in Scotland, Northern Ireland and Wales have also merged with Help the Aged in these nations to form three registered charities: Age Scotland, Age NI, Age Cymru. __ 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] Percentiles with R for a big data.frame
I found a code: y.ts - ts(data, frequency=12) aggregate(y.ts, FUN=quantile, probs=0.10) Seems it works fine even for a big data.frame. Thanks for your help. 2013/1/22 David Winsemius dwinsem...@comcast.net On Jan 22, 2013, at 5:58 AM, Simonas Kecorius wrote: Hey Duncan, Neither me do imagine what formula OpenOffice uses for quantiles. I have checked a data string, 24 values, to calculate a quantiles with OpenOffice and R. The result is identical. The problem arises when I try to implement quantile calculation in this form: dat2-with(dat1,aggregate(**cbind(dat1[,1:71]),by=list(** newID),quantiles,0.1,type=4)) . This code does not generate an error, but I guess neither a right result. You guess? What result and what is right? So my question would be: How I could calculate quantiles for a big data.frame in R (71 columns and 288 rows). I need to take 24 rows, calculate quantiles, then take another 24 rows etc..for 71 columns. You have already been told that you are misspelling the name of the R function. The other open question in my mind is whether you were hoping for something other than a single quantile (in this case the 10th percentile, or perhaps wanted the quantiles that would divide your data into deciles? If you want to do the calculation within groups then the second argument to `aggregate` must specify the grouping. By design `aggregate` will apply the function on all columns. -- David. Thanks in advance. 2013/1/22 Duncan Murdoch murdoch.dun...@gmail.com On 13-01-21 6:41 PM, Simonas Kecorius wrote: Dear R users, I came up to a problem dealing with percentiles in R. From my previous questions: I do have a big data.frame, with lots of columns and rows. The following command enables me to calculate means for all data frame. dat1$newID-rep(1:(nrow(dat1)/12),each=12) #if nrow(dat1)/12 is integer dat2-with(dat1,aggregate(cbind(dat1[,1:71]),by=list( newID),mean)) What I need is to calculate percentiles for each group (there are 12 values in a group). I tried the following: duomenai-with(dat1,aggregate(cbind(dat1[,1:71]),by=list( newID),quantiles,0.1,type=4)) You didn't define quantiles, so that won't work. Assuming that's a typo, and you meant quantile... First, is the following syntax is right? Secondly, I tried to calculate percentiles using OpenOffice and there is disagreement between values. If I do calculation for some number row, than R and OpenOffice numbers coincide, but for a data.frame it seams that something goes wrong. There are lots of different formulas for empirical quantiles. The ones available in R are described in the ?quantile help topic. What formula does OpenOffice use? Duncan Murdoch -- Simonas Kecorius ** [[alternative HTML version deleted]] __** R-help@r-project.org mailing list https://stat.ethz.ch/mailman/**listinfo/r-helphttps://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/** posting-guide.html http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. David Winsemius, MD Alameda, CA, USA -- Simonas Kecorius ** [[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] CFA with lavaan or with SEM
Dear David, On Wed, 23 Jan 2013 11:19:09 + David Purves david.pur...@glasgow.ac.uk wrote: Hi Sorry for the rather long message. . . . I have tried the analysis using John Fox's SEM package / command. I calculate the correlation matrix with smoothing my.cor-hetcor(north.dat.sub,use=pairwise.complete.obs)$correlations This returns the warning indicating that the correlation matrix was adjusted to make it positive definite. However the following sem model does not run, with the error message that the matrix is non-invertible. mod1-sem::sem(sem .model.1, S=my.cor, 300) Should the smoothing not allow it to be inverted? If the input correlation matrix is really positive definite, then it has an inverse. You could check directly, e.g., by looking at the eignevalues of the tetrachoric correlation matrix. There's very little here to go on, not even the error message produced by sem(). By the way, I assume that you didn't really call sem in the sem package as sem::sem in a session in which lavann was loaded. I'm not sure what would happen if you did that. Best, John John Fox Sen. William McMaster Prof. of Social Statistics Department of Sociology McMaster University Hamilton, Ontario, Canada http://socserv.mcmaster.ca/jfox/ __ 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] Regression with 3 measurement points
Post elsewhere (e.g. stats.stackexchange.com). This is not a statistical tutorial site. -- Bert On Wed, Jan 23, 2013 at 5:28 AM, Torvon tor...@gmail.com wrote: Dear R Mailinglist, I want to understand how predictors are associated with a dependent variable in a regression. I have 3 measurement points. I'm not interested in understanding the associations of regressors and the predictor at each measurement separately, instead I would like to use the whole sample in one regression, pooling the measurement points. I cannot simply throw them together, because the observations are not independent. Therefore, I think I need to add time as a regressor. How do I do this in R? Google leads me to time-series analysis more often than not, but from in other statistical programs and longitudinal research, the word time-series is usually reserved for 5+ measurement points. Thank you T [[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. -- Bert Gunter Genentech Nonclinical Biostatistics Internal Contact Info: Phone: 467-7374 Website: http://pharmadevelopment.roche.com/index/pdb/pdb-functional-groups/pdb-biostatistics/pdb-ncb-home.htm __ 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] Evaluating the significance of the random effects in GLMM
Gabriela Agostini gabrielaagostini18 at gmail.com writes: [snip] I am working with GLMM using the binomial family I use the following codes I dropped no significant terms, refitting the model and comparing the changes with likelihood: G.1-lmer(data$Ymat~stu+spi+stu*sp1+(1|ber),data=data,family=binomial) G.1b-lmer(data$Ymat~stu+spi+(1|ber),data=data,family=binomial) anova (G.1,G.2) But, when I want to evaluate the significance of random effect (1|ber) I cannot use a likelihood-ratio test, probably because the link function of both models is different. A couple of minor comments: * you should probably use Ymat rather than data$Ymat as your response, it will make post-processing easier * in your first model do you really mean stu*sp1 rather than stu*spi? * since A*B is equivalent to A+B+A:B, your first model specification is equivalent (assuming you really meant stu*spi) to stu*spi OR stu+spi+stu:spi. This won't change your answers but will be clearer to experienced R users. I don't understand why anova() won't work in this case. At least for the example you've shown us, it should. The link functions aren't different. Please (1) follow up to r-sig-mixed-mod...@r-project.org and (2) try to provide a little more information: a reproducible example if possible (http://tinyurl.com/reproducible-000). PS the section in http://glmm.wikidot.com/faq may provide some useful background on testing random effects. __ 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] setting off-diagonals to zero
The following 1460 x 1460 matrix can be throught of as 16 distinct 365 x 365 matrices. I'm trying to set off-diaganol terms in the 16 sub-matrices with indices more than +/- 5 (days) from each other to zero using some for loops. This works well for some, but not all, of the for loops. The R code Im using follows. For some reason the third loop below zero's-out everything in the sub-quadrant it is targeting, which is readily observable when viewing the matrix (View(MAT)). library(Matrix) MAT-matrix(rnorm(1460*1460,mean=0,sd=1),nrow = 1460, ncol = 1460) #works great for (i in 1:365) { SEQ - (i - 5):(i + 5) SEQ - SEQ[SEQ 0 SEQ 366] MAT[(1:365)[-SEQ], i] - 0 } #works great for (i in 1:365) { SEQ - (i - 5):(i + 5) SEQ - SEQ[SEQ 0 SEQ 366] MAT[(1:365)[-SEQ], i + 365] - 0 } #zero's out everything, including main-diagonal and near-main-diagonal terms??? for (i in 731:1095) { SEQ - (i - 5):(i + 5) SEQ - SEQ[SEQ 730 SEQ 1096] MAT[(731:1095)[-SEQ], i + 365] - 0 } View(MAT) I'm not sure why the third FOR loop above is not leaving the main-diagonal and near-main-diagonal terms alone? -- View this message in context: http://r.789695.n4.nabble.com/setting-off-diagonals-to-zero-tp4656407.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] Dot plot of character and numeric matrix
I think you need to become more familiar with the factor data type. Reread the Introduction to R document that comes with R. --- Jeff NewmillerThe . . Go Live... DCN:jdnew...@dcn.davis.ca.usBasics: ##.#. ##.#. Live Go... Live: OO#.. Dead: OO#.. Playing Research Engineer (Solar/BatteriesO.O#. #.O#. with /Software/Embedded Controllers) .OO#. .OO#. rocks...1k --- Sent from my phone. Please excuse my brevity. Ng Wee Kiat Jeremy jeremy.ng.wk1...@gmail.com wrote: Dear List, I have a set of data which looks like this (small set of sample) A A0.431 A A0.439 A A0.507 A G0.508 A A0.514 I will like to use this data to plot a dot plot, with the X-axis being of type character, and my y axis of type numeric. When I try to use the dot chart function, I get the error message 'x' must be a numeric vector or matrix, which I can understand it to be a result of the fact that I have characters AA, AG etc as my x-values. Any idea how I can go about doing this? Thanks in advanced! Jeremy [[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] summarise subsets of a vector
You didn't indicate what you want to do with the 101st observation. Arun's solution creates an 11th group and divides by the number in the group(1), while Jessica's solution creates an 11th column and divides by 10. test[101] - 100 unlist(lapply(split(test,((seq_along(test)-1)%/% 10)+1),mean)) 1 2 3 4 5 6 7 0.00 0.00 0.00 0.00 0.00 0.00 0.00 8 9 10 11 0.146375 0.00 0.194500 100.00 x-matrix(test,nrow=10) Warning message: In matrix(test, nrow = 10) : data length [101] is not a sub-multiple or multiple of the number of rows [10] apply(x,2,mean) [1] 0.00 0.00 0.00 0.00 0.00 0.00 0.00 [8] 0.146375 0.00 0.194500 10.00 Another approach would be to use aggregate: Groups - gl(ceiling(length(test)/10), 10)[1:length(test)] aggregate(test, list(Groups), mean) Group.1 x 11 0.00 22 0.00 33 0.00 44 0.00 55 0.00 66 0.00 77 0.00 88 0.146375 99 0.00 10 10 0.194500 11 11 100.00 -- David L Carlson Associate Professor of Anthropology Texas AM University College Station, TX 77843-4352 -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-bounces@r- project.org] On Behalf Of Jessica Streicher Sent: Wednesday, January 23, 2013 6:13 AM To: Wim Kreinen Cc: r-help Subject: Re: [R] summarise subsets of a vector Or maybe x-matrix(test,nrow=10) apply(x,2,mean) On 23.01.2013, at 00:09, Wim Kreinen wrote: Hello, I have vector called test. And now I wish to measure the mean of the first 10 number, the second 10 numbers etc How does it work? Thanks Wim dput (test) c(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.71, 0.21875, 0, 0.27375, 0.26125, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.84125, 0.0575, 0.92625, 0.12, 0, 0) [[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] Average calculations
Hi, Try this: x1-x[rev(order(x$Names,x$Values)),] do.call(rbind,tapply(x1$Values,list(x1$Names),head,2)) # [,1] [,2] #CK113234 223.2966 222.6737 #CK113298 192.5964 187.7486 #CK114042 236.3939 232.0223 #CK116292 237.5936 228.0037 #CK116296 223.6372 210.6630 #The average tapply(x1$Values,list(x1$Names),function(x) mean(head(x,2))) #CK113234 CK113298 CK114042 CK116292 CK116296 #222.9852 190.1725 234.2081 232.7987 217.1501 A.K. - Original Message - From: Nico Met nicome...@gmail.com To: R help r-help@r-project.org Cc: Sent: Wednesday, January 23, 2013 8:03 AM Subject: [R] Average calculations Dear all, I have a matrix with two columns: Names and Values In names: there are 4 groups they are, CK113234, CK116296, CK116292 and CK114042 I want to *sort values* (decreasing order) based on each group and take average of the *top two numbers* in each of the groups. dput(x) structure(list(Names = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 5L, 5L, 5L, 5L, 2L, 2L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L), .Label = c(CK113234, CK113298, CK114042, CK116292, CK116296), class = factor), Values = c(208.3360, 223.29665, 221.63255, 211.29735, 217.75112, 210.97916, 222.67365, 216.0822, 189.83685, 194.1595, 210.66298, 223.63718333, 187.74864, 192.5964, 237.593625, 216.8277, 225.8966, 228.00374, 214.99454, 211.38114, 218.7659, 209.9958, 214.8041, 215.184489473684, 224.2446, 217.559878571429, 232.02229167, 214.02384, 236.393875, 228.73522)), .Names = c(Names, Values), class = data.frame, row.names = c(NA, 30L)) The out put will look like following: Names Values CK113234 222,98 CK116296 217,14 CK116292 232,79 CK114042 234,2 Your help is appreciated. Regards Nico [[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] CFA with lavaan or with SEM
Hi John Thanks for your quick reply. The full warning I got is ' Error in csem(model = model.description, start, opt.flag = 1, typsize = typsize, : The matrix is non-invertable.' The eigenvalues of the tetrachoric correlations are non negative. So it is must be how I am defining my model. I have also tried it without having lavaan in the session. A wee example of my error (whether it is sensible); library(sem) my.cor-matrix(c( 1.000 , 0.7600616 , 0.3653309 , 0.4377949 , 0.2917927 , 0.5133697, 0.7600616 , 1.000, 0.6335519 , 0.8288809 , 0.6223942 , 0.6355725, 0.3653309 , 0.6335519 , 1.000 , 0.9098309 , 0.9098309 , 0.7693395, 0.4377949 , 0.8288809 , 0.9098309 , 1.000 ,0.9136967 , 0.7829854, 0.2917927 ,0.6223942 , 0.9098309 , 0.9136967 ,1.000 , 0.7354562, 0.5133697 ,0.6355725 , 0.7693395 , 0.7829854 , 0.7354562 , 1.000), nrow=6,byrow=T) colnames(my.cor)-rownames(my.cor)-c(a,b,c,d,e,g) eigen(my.cor) solve(my.cor) #i tried defining the model in two ways model.1-matrix(c( # arrow #parameter #start f - a, g1, NA, f - b, g2, NA, f - c, g3, NA, f - d, g4, NA, f - e, g5, NA, f - g, g6, NA, f - f, NA, 1), ncol=3,byrow=T) out-sem(model.1,S=my.cor,200) model.1 - specifyEquations() f1 = gam11*a + gam12*b + gam13*c + gam14*d + gam15*e + gam16*g f1 = 1* f1 out-sem(model.1,S=my.cor,200) But the same error. I would be very grateful if you could indicate where the error in my code is please. thanks, david -Original Message- From: John Fox [mailto:j...@mcmaster.ca] Sent: 23 January 2013 14:00 To: David Purves Cc: r-help@R-project.org Subject: Re: [R] CFA with lavaan or with SEM Dear David, On Wed, 23 Jan 2013 11:19:09 + David Purves david.pur...@glasgow.ac.uk wrote: Hi Sorry for the rather long message. . . . I have tried the analysis using John Fox's SEM package / command. I calculate the correlation matrix with smoothing my.cor-hetcor(north.dat.sub,use=pairwise.complete.obs)$correlations This returns the warning indicating that the correlation matrix was adjusted to make it positive definite. However the following sem model does not run, with the error message that the matrix is non-invertible. mod1-sem::sem(sem .model.1, S=my.cor, 300) Should the smoothing not allow it to be inverted? If the input correlation matrix is really positive definite, then it has an inverse. You could check directly, e.g., by looking at the eignevalues of the tetrachoric correlation matrix. There's very little here to go on, not even the error message produced by sem(). By the way, I assume that you didn't really call sem in the sem package as sem::sem in a session in which lavann was loaded. I'm not sure what would happen if you did that. Best, John John Fox Sen. William McMaster Prof. of Social Statistics Department of Sociology McMaster University Hamilton, Ontario, Canada http://socserv.mcmaster.ca/jfox/ __ 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. The University of Glasgow, charity number SC004401 __ 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] how to read a df like that and transform it?
Hi, It's not clear regarding those blanks especially, the num_daughter. I guess the father and mother would be the same as the previous row. Deleting those rows: df1 - read.table(text=father mother num_daughter daughter 291 3906 0 NA 275 4219 0 NA 273 4236 1 49410 281 4163 1 49408 274 4226 1 49406 295 3869 2 49403 287 4113 0 NA 295 3871 1 49401 292 3895 4 49396 291 3900 3 49392, header=TRUE) reshape(df1,v.names=daughter,idvar=c(father,mother),timevar=num_daughter,direction=wide) A.K. - Original Message - From: Yao He yao.h.1...@gmail.com To: R help r-help@r-project.org Cc: Sent: Wednesday, January 23, 2013 7:42 AM Subject: [R] how to read a df like that and transform it? Dear all I have a data.frame like that : father mother num_daughter daughter 291 3906 0 NULL 275 4219 0 NULL 273 4236 1 49410 281 4163 1 49408 274 4226 1 49406 295 3869 2 49403 49404 287 4113 0 NULL 295 3871 1 49401 292 3895 4 49396 49397 49398 49399 291 3900 3 49392 How to read it into R and transform it like that: father mother num_daughter daughter1 daughter2 daughter3 daughter4 291 3906 0 NULL 275 4219 0 NULL 273 4236 1 49410 281 4163 1 49408 274 4226 1 49406 295 3869 2 49403 49404 287 4113 0 NULL 295 3871 1 49401 292 3895 4 49396 49397 49398 49399 291 3900 3 49392 library (plyr) and library (reshape2) and other good packages are OK for me. Thanks a lot! Yao He — Master candidate in 2rd year Department of Animal genetics breeding Room 436,College of Animial ScienceTechnology, China Agriculture University,Beijing,100193 E-mail: yao.h.1...@gmail.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.
Re: [R] how to read a df like that and transform it?
Hi, May be this helps: df1-read.table(text= father,mother,num_daughter,daughter 291,3906,0, 275,4219,0, 273, 4236,1,49410 281,4163,1,49408 274, 4226,1,49406 295, 3869,2,49403 295,3869,2,49404 287,4113,0, 295, 3871,1,49401 292, 3895,4,49396 292,3895,4, 49397 292,3895,4,49398 292,3895,4,49399 291, 3900,3,49392 291, 3900,3, 291, 3900,3, ,sep=,,header=TRUE,stringsAsFactors=F,na.strings=) df1$num_daughter[df1$num_daughter1]-ave(df1$num_daughter[df1$num_daughter1],df1$num_daughter[df1$num_daughter1],FUN=seq_along) reshape(df1,v.names=daughter,idvar=c(father,mother),timevar=num_daughter,direction=wide) # father mother daughter.0 daughter.1 daughter.2 daughter.3 daughter.4 #1 291 3906 NA NA NA NA NA #2 275 4219 NA NA NA NA NA #3 273 4236 NA 49410 NA NA NA #4 281 4163 NA 49408 NA NA NA #5 274 4226 NA 49406 NA NA NA #6 295 3869 NA 49403 49404 NA NA #8 287 4113 NA NA NA NA NA #9 295 3871 NA 49401 NA NA NA #10 292 3895 NA 49396 49397 49398 49399 #14 291 3900 NA 49392 NA NA NA A.K. - Original Message - From: Yao He yao.h.1...@gmail.com To: R help r-help@r-project.org Cc: Sent: Wednesday, January 23, 2013 7:42 AM Subject: [R] how to read a df like that and transform it? Dear all I have a data.frame like that : father mother num_daughter daughter 291 3906 0 NULL 275 4219 0 NULL 273 4236 1 49410 281 4163 1 49408 274 4226 1 49406 295 3869 2 49403 49404 287 4113 0 NULL 295 3871 1 49401 292 3895 4 49396 49397 49398 49399 291 3900 3 49392 How to read it into R and transform it like that: father mother num_daughter daughter1 daughter2 daughter3 daughter4 291 3906 0 NULL 275 4219 0 NULL 273 4236 1 49410 281 4163 1 49408 274 4226 1 49406 295 3869 2 49403 49404 287 4113 0 NULL 295 3871 1 49401 292 3895 4 49396 49397 49398 49399 291 3900 3 49392 library (plyr) and library (reshape2) and other good packages are OK for me. Thanks a lot! Yao He — Master candidate in 2rd year Department of Animal genetics breeding Room 436,College of Animial ScienceTechnology, China Agriculture University,Beijing,100193 E-mail: yao.h.1...@gmail.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] to check if a character string is in a group of character strings
Hello, How can I judge if a string is in a group of string? For example, I would like to have if (subpool in pool){ }else{ } Where pool = c(s1,s2) subpool = c(s1) How can I write the subpool in pool right in R? Thanks very much! Cheers, Rebecca -- This message, and any attachments, is for the intended r...{{dropped:5}} __ 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] CFA with lavaan or with SEM
Dear David, It certainly helps to have a reproducible example. You've left out the error variances (uniquenesses) for the observed variables. You're also making the specification *much* harder than it needs to be: -- snip --- cfa.mod.1 - cfa() 1: F: a, b, c, d, e, g 2: Read 1 item NOTE: adding 6 variances to the model cfa.mod.1 PathParameter StartValue 1 F - a fixed 1 2 F - b lam[b:F] 3 F - c lam[c:F] 4 F - d lam[d:F] 5 F - e lam[e:F] 6 F - g lam[g:F] 7 F - F V[F] 8 a - a V[a] 9 b - b V[b] 10 c - c V[c] 11 d - d V[d] 12 e - e V[e] 13 g - g V[g] cfa.sem.1 - sem(cfa.mod.1, S=my.cor, N=200) summary(cfa.sem.1) Model Chisquare = 543.6442 Df = 9 Pr(Chisq) = 2.565155e-111 AIC = 567.6442 BIC = 495.9594 Normalized Residuals Min. 1st Qu.Median Mean 3rd Qu. Max. -1.536000 -0.135500 0.002829 0.294500 0.353400 5.337000 R-square for Endogenous Variables a b c d e g 0.1841 0.6969 0.8172 1.0084 0.8269 0.6007 Parameter Estimates Estimate Std Error z value Pr(|z|) lam[b:F] 1.945376727 0.302785547 6.424933 1.319280e-10 b --- F lam[c:F] 2.106647980 0.320689035 6.569130 5.061006e-11 c --- F lam[d:F] 2.340103148 0.347900207 6.726363 1.739560e-11 d --- F lam[e:F] 2.119171567 0.322095480 6.579327 4.725816e-11 e --- F lam[g:F] 1.806192591 0.287680436 6.278469 3.419240e-10 g --- F V[F] 0.184137740 0.057758730 3.188050 1.432356e-03 F -- F V[a] 0.815862342 0.081641551 9.993224 1.631854e-23 a -- a V[b] 0.303132223 0.030545714 9.923887 3.277381e-23 b -- b V[c] 0.182802929 0.019248279 9.497105 2.158058e-21 c -- c V[d] -0.008353614 0.008298643 -1.006624 3.141154e-01 d -- d V[e] 0.173057855 0.018375461 9.417878 4.602950e-21 e -- e V[g] 0.399281457 0.039935977 9.998039 1.554445e-23 g -- g Iterations = 59 -- snip --- Note that the default in cfa() is to use a reference indicator, and that the solution is improper -- there's a negative estimated error variance, V[d]. An alternative specification sets the variance of the factor to 1, but then cfa() fails to converge: -- snip --- cfa.mod.2 - cfa(reference.indicators=FALSE) 1: F: a, b, c, d, e, g 2: Read 1 item NOTE: adding 6 variances to the model cfa.mod.2 PathParameter StartValue 1 F - a lam[a:F] 2 F - b lam[b:F] 3 F - c lam[c:F] 4 F - d lam[d:F] 5 F - e lam[e:F] 6 F - g lam[g:F] 7 F - F fixed 1 8 a - a V[a] 9 b - b V[b] 10 c - c V[c] 11 d - d V[d] 12 e - e V[e] 13 g - g V[g] cfa.sem.2 - sem(cfa.mod.2, S=my.cor, N=200, debug=TRUE) . . . Start values: lam[a:F] lam[b:F] lam[c:F] lam[d:F] lam[e:F] lam[g:F] V[a] V[b] V[c] V[d] V[e] V[g] 0.65781335 0.87500031 0.89597921 0.95169707 0.87357655 0.86645865 0.56728160 0.23437445 0.19722125 0.09427268 0.23686401 0.24924941 iteration = 0 Step: [1] 0 0 0 0 0 0 0 0 0 0 0 0 Parameter: [1] 0.65781335 0.87500031 0.89597921 0.95169707 0.87357655 0.86645865 0.56728160 0.23437445 0.19722125 0.09427268 0.23686401 0.24924941 Function Value [1] 3.346898 Gradient: [1] 0.4583916 0.3957443 -0.2067868 -0.4369468 -0.2629929 0.2431501 -0.5501220 -1.672 0.6543088 3.0031327 0.7820309 -1.0122023 . . . iteration = 21 Parameter: [1] 0.4428 0.68987016 0.99055402 1.15651371 0.99812990 0.75293242 0.82441291 1.01174284 0.01185904 -1.30253783 -0.01183159 [12] 0.71942353 Function Value [1] -316143 Gradient: [1] 83431722 105921661 12975044375-137927630 -13105242109 162575760 -22404848 -36111801 -541872735153 [10] -61232522 -552802111412 -85072888 Successive iterates within tolerance. Current iterate is probably solution. Warning message: In eval(expr, envir, enclos) : Could not compute QR decomposition of Hessian. Optimization probably did not converge. -- snip --- The problem seems ill-conditioned, and in any event the standard errors that you get using tetrachoric correlations won't be right (I expect you know that). I hope this helps, John -Original Message- From: David Purves [mailto:david.pur...@glasgow.ac.uk] Sent: Wednesday, January 23, 2013 10:23 AM To: John Fox Cc: r-help@R-project.org Subject: RE: [R] CFA with lavaan or with SEM Hi John Thanks for your quick reply. The full warning I got is ' Error in csem(model = model.description, start, opt.flag = 1, typsize = typsize, : The matrix is non-invertable.' The eigenvalues of the tetrachoric correlations are non negative. So it is
Re: [R] to check if a character string is in a group of character strings
On 13-01-23 11:14 AM, Yuan, Rebecca wrote: Hello, How can I judge if a string is in a group of string? For example, I would like to have if (subpool in pool){ }else{ } if (subpool %in% pool) Duncan Murdoch Where pool = c(s1,s2) subpool = c(s1) How can I write the subpool in pool right in R? Thanks very much! Cheers, Rebecca -- This message, and any attachments, is for the intended r...{{dropped:5}} __ 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] to check if a character string is in a group of character strings
Not sure what you want this for, but work along the following: pool = c(s1,s2) subpool = c(s1) ifelse(pool==subpool,1,0) [1] 1 0 Notice: pool2 = c(s2,s1) ifelse(pool2==subpool,1,0) [1] 0 1 Etc. Hope this helps. José José Iparraguirre Chief Economist Age UK -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Yuan, Rebecca Sent: 23 January 2013 16:15 To: R help Subject: [R] to check if a character string is in a group of character strings Hello, How can I judge if a string is in a group of string? For example, I would like to have if (subpool in pool){ }else{ } Where pool = c(s1,s2) subpool = c(s1) How can I write the subpool in pool right in R? Thanks very much! Cheers, Rebecca -- This message, and any attachments, is for the intended r...{{dropped:5}} __ 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. Wrap Up and Run 10k is back! Also, new for 2013 – 2km intergenerational walks at selected venues. So recruit a buddy, dust off the trainers and beat the winter blues by signing up now: http://www.ageuk.org.uk/10k Milton Keynes | Oxford | Sheffield | Crystal Palace | Exeter | Harewood House, Leeds | Tatton Park, Cheshire | Southampton | Coventry Age UK Improving later life http://www.ageuk.org.uk --- Age UK is a registered charity and company limited by guarantee, (registered charity number 1128267, registered company number 6825798). Registered office: Tavis House, 1-6 Tavistock Square, London WC1H 9NA. For the purposes of promoting Age UK Insurance, Age UK is an Appointed Representative of Age UK Enterprises Limited, Age UK is an Introducer Appointed Representative of JLT Benefit Solutions Limited and Simplyhealth Access for the purposes of introducing potential annuity and health cash plans customers respectively. Age UK Enterprises Limited, JLT Benefit Solutions Limited and Simplyhealth Access are all authorised and regulated by the Financial Services Authority. -- This email and any files transmitted with it are confidential and intended solely for the use of the individual or entity to whom they are addressed. If you receive a message in error, please advise the sender and delete immediately. Except where this email is sent in the usual course of our business, any opinions expressed in this email are those of the author and do not necessarily reflect the opinions of Age UK or its subsidiaries and associated companies. Age UK monitors all e-mail transmissions passing through its network and may block or modify mails which are deemed to be unsuitable. Age Concern England (charity number 261794) and Help the Aged (charity number 272786) and their trading and other associated companies merged on 1st April 2009. Together they have formed the Age UK Group, dedicated to improving the lives of people in later life. The three national Age Concerns in Scotland, Northern Ireland and Wales have also merged with Help the Aged in these nations to form three registered charities: Age Scotland, Age NI, Age Cymru. __ 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] FactoMineR
Dear Daniel, Eventually, FactoMineR (and other Rcmdr plug-ins) really should be updated to conform to R 3.0.0 requirements, but I've modified the development version 1.9-4 of the Rcmdr on R-Forge to allow a new option to accommodate some of these plug-ins. If you set options(Rcmdr=list(RcmdrEnv.on.path=TRUE)), then plug-in packages like FactoMineR that rely on the RcmdrEnv environment being on the search path *may* again work properly. A quick check suggests that this is the case with FactoMineR. Normally, the development version of the Rcmdr should be installable for the current version of R from R-Forge via the command install.packages(Rcmdr, repos=http://R-Forge.R-project.org;), but packages on R-Forge are often built on an irregular basis, and so if you want to try it, you may have to download the Rcmdr source package via svn and build the package yourself; see http://r-forge.r-project.org/scm/?group_id=255. Of course, version 1.9-4 of the Rcmdr will eventually be moved to CRAN, but I have to correspond some more with plug-in package authors and do more testing before that happens. I hope this helps, John -Original Message- From: Dániel Kehl [mailto:ke...@ktk.pte.hu] Sent: Tuesday, January 22, 2013 8:02 AM To: John Fox Cc: R-help Subject: RE: [R] FactoMineR Dear John, great news, thank you for your kind answer and quick response. I am sure that the author is going to do his best as well. An other good experience why I love R! :) Have a nice day, daniel Feladó: John Fox [j...@mcmaster.ca] Küldve: 2013. január 22. 13:39 To: Dániel Kehl Cc: R-help Tárgy: Re: [R] FactoMineR Dear Daniel, There were changes to the new version 1.9-3 of the Rcmdr so that it conforms to CRAN policies. These changes can break plug-ins that haven't been modified for compatibility. One change is that the environment in which the Rcmdr stores state information is no longer put on the search path. That's apparently preventing the FactoMineR plug-in from finding the active data set. The solution is for the author to replace get(.activeDataSet) with something like get(getRcmdr(.activeDataSet)). I'll correspond with the package author to suggest this. I apologize for the difficulties introduced by these changes. John John Fox Sen. William McMaster Prof. of Social Statistics Department of Sociology McMaster University Hamilton, Ontario, Canada http://socserv.mcmaster.ca/jfox/ On Tue, 22 Jan 2013 10:34:28 + Dániel Kehl ke...@ktk.pte.hu wrote: Dear Users, I installed R Commander and the FactoMineR plug-in. Everything is fine, I can see the new menu, I can import datasets, but if I want to use any of the items in the FactoMineR menu, i get the following error: Error in get(.activeDataSet) : object '.activeDataSet' not found even if there is an active dataset (if there is none, all the menu items are grey of course). I have R version 2.15.2 using Windows 7 but experienced the same on other machines. Please let me know if you have any idea! Thanks a lot daniel __ 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] to check if a character string is in a group of character strings
Hello Duncan, Thanks for this! This works! Best, Rebecca -Original Message- From: Duncan Murdoch [mailto:murdoch.dun...@gmail.com] Sent: Wednesday, January 23, 2013 11:23 AM To: Yuan, Rebecca Cc: R help Subject: Re: [R] to check if a character string is in a group of character strings On 13-01-23 11:14 AM, Yuan, Rebecca wrote: Hello, How can I judge if a string is in a group of string? For example, I would like to have if (subpool in pool){ }else{ } if (subpool %in% pool) Duncan Murdoch Where pool = c(s1,s2) subpool = c(s1) How can I write the subpool in pool right in R? Thanks very much! Cheers, Rebecca -- This message, and any attachments, is for the intended...{{dropped:12}} __ 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] setting off-diagonals to zero
On 23-01-2013, at 16:13, emorway emor...@usgs.gov wrote: The following 1460 x 1460 matrix can be throught of as 16 distinct 365 x 365 matrices. I'm trying to set off-diaganol terms in the 16 sub-matrices with indices more than +/- 5 (days) from each other to zero using some for loops. This works well for some, but not all, of the for loops. The R code Im using follows. For some reason the third loop below zero's-out everything in the sub-quadrant it is targeting, which is readily observable when viewing the matrix (View(MAT)). library(Matrix) MAT-matrix(rnorm(1460*1460,mean=0,sd=1),nrow = 1460, ncol = 1460) #works great for (i in 1:365) { SEQ - (i - 5):(i + 5) SEQ - SEQ[SEQ 0 SEQ 366] MAT[(1:365)[-SEQ], i] - 0 } #works great for (i in 1:365) { SEQ - (i - 5):(i + 5) SEQ - SEQ[SEQ 0 SEQ 366] MAT[(1:365)[-SEQ], i + 365] - 0 } #zero's out everything, including main-diagonal and near-main-diagonal terms??? for (i in 731:1095) { SEQ - (i - 5):(i + 5) SEQ - SEQ[SEQ 730 SEQ 1096] MAT[(731:1095)[-SEQ], i + 365] - 0 } View(MAT) I'm not sure why the third FOR loop above is not leaving the main-diagonal and near-main-diagonal terms alone? Because -SEQ in the last expression is not referencing the correct elements. The first element of (731:1009) has index 1 and not 731. So as far as I can see the last expression should be something like MAT[(731:1095)[-(-730+SEQ)], i + 365] - 0 Berend __ 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] CFA with lavaan or with SEM
Dear Daniel, Oh, I see I forgot to comment on your second specification in my last reply: -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of David Purves Sent: Wednesday, January 23, 2013 10:23 AM To: John Fox Cc: r-help@R-project.org Subject: Re: [R] CFA with lavaan or with SEM . . . model.1 - specifyEquations() f1 = gam11*a + gam12*b + gam13*c + gam14*d + gam15*e + gam16*g f1 = 1* f1 First, this is backwards: the observed variables depend on the factor, and not vice-versa; e.g., a = gam11*f1. Second, the factor has an error-variance parameter; it doesn't depend on itself: V(f1) = 1. As I mentioned in my previous message, it's easier to use cfa() for this kind of model. Best, John __ 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] Create a Data Frame from an XML
Hello Gentlemen, I mistakenly sent the message twice, because the first time I didn't receive a notification message so I was unsure if it went through properly. Your solutions worked great. Thank you! I felt like I was fairly close just couldn't quite get the final step. Now, I'm trying to reverse the process and account for my header. In other words I have my data frame in R: BRANDNUMYEARVALUE GMC1 1999 1 FORD 2 2000 12000 GMC1 2001 12500 etc and I make some edits. BRANDNUMYEARVALUE DODGE 3 1999 1 TOYOTA 4 2000 12000 DODGE3 2001 12500 So now I would need to ouput an XML file in the same format accounting for my header (essentially, add z: in front of row). (What I want to output) data z:row BRAND=DODGE NUM=3 YEAR=1999 VALUE=1 / z:row BRAND=TOYOTA NUM=4 YEAR=2000 VALUE=12000 / z:row BRAND=DODGE NUM=3 YEAR=2001 VALUE=12500 / z:row BRAND=TOYOTA NUM=4 YEAR=2002 VALUE=13000 / z:row BRAND=DODGE NUM=3 YEAR=2003 VALUE=14000 / z:row BRAND=TOYOTA NUM=4 YEAR=2004 VALUE=17000 / z:row BRAND=DODGE NUM=3 YEAR=2005 VALUE=15000 / z:row BRAND=DODGE NUM=3 YEAR=1967 VALUE=PRICELESS / z:row BRAND=TOYOTA NUM=4 YEAR=2007 VALUE=17500 / z:row BRAND=DODGE NUM=3 YEAR=2008 VALUE=22000 / /data Thus far from the help I've found online I was trying to set up an xmlTree xml - xmlTree() and use xml$addTag to create nodes and put in the data from my data frame. I feel like I'm not really even close to a solution so I'm starting to believe that this might not be the best path to go down. Once again, any help is much appreciated. AG On Tue, Jan 22, 2013 at 6:04 PM, Duncan Temple Lang dtemplel...@ucdavis.edu wrote: Hi Adam [You seem to have sent the same message twice to the mailing list.] There are various strategies/approaches to creating the data frame from the XML. Perhaps the approach that most closely follows your approach is xmlRoot(doc)[ row ] which returns a list of XML nodes whose node name is row that are children of the root node data. So sapply(xmlRoot(doc) [ row ], xmlAttrs) yields a matrix with as many columns as there are row nodes and with 3 rows - one for each of the BRAND, YEAR and VALUE attributes. So d = t( sapply(xmlRoot(doc) [ row ], xmlAttrs) ) gives you a matrix with the correct rows and column orientation and now you can turn that into a data frame, converting the columns into numbers, etc. as you want with regular R commands (i.e. independently of the XML). D. On 1/22/13 1:43 PM, Adam Gabbert wrote: Hello, I'm attempting to read information from an XML into a data frame in R using the XML package. I am unable to get the data into a data frame as I would like. I have some sample code below. *XML Code:* Header... Data I want in a data frame: data row BRAND=GMC NUM=1 YEAR=1999 VALUE=1 / row BRAND=FORD NUM=1 YEAR=2000 VALUE=12000 / row BRAND=GMC NUM=1 YEAR=2001 VALUE=12500 / row BRAND=FORD NUM=1 YEAR=2002 VALUE=13000 / row BRAND=GMC NUM=1 YEAR=2003 VALUE=14000 / row BRAND=FORD NUM=1 YEAR=2004 VALUE=17000 / row BRAND=GMC NUM=1 YEAR=2005 VALUE=15000 / row BRAND=GMC NUM=1 YEAR=1967 VALUE=PRICLESS / row BRAND=FORD NUM=1 YEAR=2007 VALUE=17500 / row BRAND=GMC NUM=1 YEAR=2008 VALUE=22000 / /data *R Code:* doc -xmlInternalTreeParse (Sample2.xml) top - xmlRoot (doc) xmlName (top) names (top) art - top [[row]] art ** *Output:* artrow BRAND=GMC NUM=1 YEAR=1999 VALUE=1/ * * This is where I am having difficulties. I am unable to access additional rows; ( i.e. row BRAND=GMC NUM=1 YEAR=1967 VALUE=PRICLESS / ) and I am unable to access the individual entries to actually create the data frame. The data frame I would like is as follows: BRANDNUMYEARVALUE GMC1 1999 1 FORD 2 2000 12000 GMC1 2001 12500 etc Any help or suggestions would be appreciated. Conversly, my eventual goal would be to take a data frame and write it into an XML in the previously shown format. Thank you AG [[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.htmlhttp://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.htmlhttp://www.r-project.org/posting-guide.html and provide commented,
Re: [R] to check if a character string is in a group of character strings
I think you want %in% subpool %in% pool pool %in% subpool ir. Thierry Onkelinx Instituut voor natuur- en bosonderzoek / Research Institute for Nature and Forest team Biometrie Kwaliteitszorg / team Biometrics Quality Assurance Kliniekstraat 25 1070 Anderlecht Belgium + 32 2 525 02 51 + 32 54 43 61 85 thierry.onkel...@inbo.be www.inbo.be To call in the statistician after the experiment is done may be no more than asking him to perform a post-mortem examination: he may be able to say what the experiment died of. ~ Sir Ronald Aylmer Fisher The plural of anecdote is not data. ~ Roger Brinner The combination of some data and an aching desire for an answer does not ensure that a reasonable answer can be extracted from a given body of data. ~ John Tukey -Oorspronkelijk bericht- Van: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] Namens Yuan, Rebecca Verzonden: woensdag 23 januari 2013 17:15 Aan: R help Onderwerp: [R] to check if a character string is in a group of character strings Hello, How can I judge if a string is in a group of string? For example, I would like to have if (subpool in pool){ }else{ } Where pool = c(s1,s2) subpool = c(s1) How can I write the subpool in pool right in R? Thanks very much! Cheers, Rebecca -- This message, and any attachments, is for the intended r...{{dropped:5}} __ 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. * * * * * * * * * * * * * D I S C L A I M E R * * * * * * * * * * * * * Dit bericht en eventuele bijlagen geven enkel de visie van de schrijver weer en binden het INBO onder geen enkel beding, zolang dit bericht niet bevestigd is door een geldig ondertekend document. The views expressed in this message and any annex are purely those of the writer and may not be regarded as stating an official position of INBO, as long as the message is not confirmed by a duly signed document. __ 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] summarise subsets of a vector
Or... fs-rep(1:ceiling(length(test)/10),each=10)[1:length(test)] result-by(test,fs,mean) which will get you the version with the 101st as a single datapoint so many possibilities.. On 23.01.2013, at 16:43, David L Carlson wrote: You didn't indicate what you want to do with the 101st observation. Arun's solution creates an 11th group and divides by the number in the group(1), while Jessica's solution creates an 11th column and divides by 10. test[101] - 100 unlist(lapply(split(test,((seq_along(test)-1)%/% 10)+1),mean)) 1 2 3 4 5 6 7 0.00 0.00 0.00 0.00 0.00 0.00 0.00 8 9 10 11 0.146375 0.00 0.194500 100.00 x-matrix(test,nrow=10) Warning message: In matrix(test, nrow = 10) : data length [101] is not a sub-multiple or multiple of the number of rows [10] apply(x,2,mean) [1] 0.00 0.00 0.00 0.00 0.00 0.00 0.00 [8] 0.146375 0.00 0.194500 10.00 Another approach would be to use aggregate: Groups - gl(ceiling(length(test)/10), 10)[1:length(test)] aggregate(test, list(Groups), mean) Group.1 x 11 0.00 22 0.00 33 0.00 44 0.00 55 0.00 66 0.00 77 0.00 88 0.146375 99 0.00 10 10 0.194500 11 11 100.00 -- David L Carlson Associate Professor of Anthropology Texas AM University College Station, TX 77843-4352 -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-bounces@r- project.org] On Behalf Of Jessica Streicher Sent: Wednesday, January 23, 2013 6:13 AM To: Wim Kreinen Cc: r-help Subject: Re: [R] summarise subsets of a vector Or maybe x-matrix(test,nrow=10) apply(x,2,mean) On 23.01.2013, at 00:09, Wim Kreinen wrote: Hello, I have vector called test. And now I wish to measure the mean of the first 10 number, the second 10 numbers etc How does it work? Thanks Wim dput (test) c(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.71, 0.21875, 0, 0.27375, 0.26125, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.84125, 0.0575, 0.92625, 0.12, 0, 0) [[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] Adding a line to barchart
Great! This really helped! One quick follow-up -- is there a trick to placing a label wherever the line intersects the x-axis (either above or below the plot)? On Tue, Jan 22, 2013 at 11:49 PM, PIKAL Petr petr.pi...@precheza.cz wrote: Hi This function adds line to each panel addLine - function (a = NULL, b = NULL, v = NULL, h = NULL, ..., once = F) { tcL - trellis.currentLayout() k - 0 for (i in 1:nrow(tcL)) for (j in 1:ncol(tcL)) if (tcL[i, j] 0) { k - k + 1 trellis.focus(panel, j, i, highlight = FALSE) if (once) panel.abline(a = a[k], b = b[k], v = v[k], h = h[k], ...) else panel.abline(a = a, b = b, v = v, h = h, ...) trellis.unfocus() } } addLine(v=2, col=2, lty=3) Petr -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-bounces@r- project.org] On Behalf Of Jonathan Greenberg Sent: Tuesday, January 22, 2013 11:42 PM To: r-help Subject: [R] Adding a line to barchart R-helpers: I need a quick help with the following graph (I'm a lattice newbie): require(lattice) npp=1:5 names(npp)=c(A,B,C,D,E) barchart(npp,origin=0,box.width=1) # What I want to do, is add a single vertical line positioned at x = 2 that lays over the bars (say, using a dotted line). How do I go about doing this? --j -- Jonathan A. Greenberg, PhD Assistant Professor Global Environmental Analysis and Remote Sensing (GEARS) Laboratory Department of Geography and Geographic Information Science University of Illinois at Urbana-Champaign 607 South Mathews Avenue, MC 150 Urbana, IL 61801 Phone: 217-300-1924 http://www.geog.illinois.edu/~jgrn/ AIM: jgrn307, MSN: jgrn...@hotmail.com, Gchat: jgrn307, Skype: jgrn3007 [[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. -- Jonathan A. Greenberg, PhD Assistant Professor Global Environmental Analysis and Remote Sensing (GEARS) Laboratory Department of Geography and Geographic Information Science University of Illinois at Urbana-Champaign 607 South Mathews Avenue, MC 150 Urbana, IL 61801 Phone: 217-300-1924 http://www.geog.illinois.edu/~jgrn/ AIM: jgrn307, MSN: jgrn...@hotmail.com, Gchat: jgrn307, Skype: jgrn3007 [[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] italic font for legend text when using expression function for symbols
Hello, I'm trying to add a symbol (Delta) to plot legend with text using expression(paste()) but this disables the text.font that allows to use bold or italic text. as follows: x=c(1:10) y=c(1:10) plot(x,y) legend(1,10,legend=c(A,B,C,expression(paste(Delta, D))), pch=c(24,18,17,16),cex=2,text.font=3,bty=n) Any suggestion to how I can add the Delta symbol and have a italic font? Thanks -- \m/ [[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] problems with coercing a factor to be numeric
On Jan 23, 2013, at 1:58 AM, Francesco Sarracino wrote: Thanks, this works! but I am surprised that R has such a strange behavior and that there is no way to control it. BTW, also as.integer(pp)-1 works! Still, it doesn't look to me as a first best. At any rate, thanks a lot for your help. I think it is rather strange that you are criticising R because the mean or sum functions won't coerce factors to numeric class. R is already very loosely typed. It has a fairly limited number of object classes and there is widespread class coercion when it is appropriate. Can you explain why you believed factors or by logical extension character classed variables should get implicitly coerced by all mathematical functions? -- David. f. On 23 January 2013 10:53, D. Rizopoulos d.rizopou...@erasmusmc.nl wrote: check also pp - rep(0:1, 10) pp - factor(pp, levels=(0:1), labels=c(no,yes)) unclass(pp) unclass(pp) - 1 Best, Dimitris On 1/23/2013 10:48 AM, Francesco Sarracino wrote: Dear Dimitris, thanks for your quick reply. I've tried the solutions proposed in 7.10 How do I convert factors to numeric? as.numeric(as.character(pp)) and as.numeric(levels(pp))[as.integer(pp)] However, whatever I do, I get Warning message: NAs introduced by coercion and the output is a vector of NA. Any ideas? f. On 23 January 2013 10:39, D. Rizopoulos d.rizopou...@erasmusmc.nl mailto:d.rizopou...@erasmusmc.nl wrote: Check R FAQ 7.10: How do I convert factors to numeric? I hope it helps. Best, Dimitris On 1/23/2013 10:33 AM, Francesco Sarracino wrote: Dear R listers, I am trying to compute the mean of a dummy variable that is encoded as a factor. However, even though the levels of my factor are 0 - 1, when I compute the mean (after coercing the factor to be numeric), R changes 0 into 1 and 1 into yes, thus altering my expected result. Please, consider the following working example: pp - rep(0:1, 10) pp - factor(pp, levels=(0:1), labels=c(no,yes)) mean(pp) #this won't work because the argument is not numeric or logical mean(as.integer(pp)) # this computes the average, but not on the range 0-1, but 1-2. Indeed, the result is 1.5 and not 0.5 as expected. What am I doing wrong? Thanks in advance for your kind support, f. -- Dimitris Rizopoulos Assistant Professor Department of Biostatistics Erasmus University Medical Center Address: PO Box 2040, 3000 CA Rotterdam, the Netherlands Tel: +31/(0)10/7043478 tel:%2B31%2F%280%2910%2F7043478 Fax: +31/(0)10/7043014 tel:%2B31%2F%280%2910%2F7043014 Web: http://www.erasmusmc.nl/biostatistiek/ -- Francesco Sarracino, Ph.D. https://sites.google.com/site/fsarracino/ -- Dimitris Rizopoulos Assistant Professor Department of Biostatistics Erasmus University Medical Center Address: PO Box 2040, 3000 CA Rotterdam, the Netherlands Tel: +31/(0)10/7043478 Fax: +31/(0)10/7043014 Web: http://www.erasmusmc.nl/biostatistiek/ -- Francesco Sarracino, Ph.D. https://sites.google.com/site/fsarracino/ [[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 Alameda, CA, USA __ 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] density of hist(freq = FALSE) inversely affected by data magnitude
I think it is a fair bit of work to interpret the freq=TRUE (prob=FALSE) version of hist() when the bins have unequal sizes. E.g., in the following the bins are sized so that each contains an equal number of observations. The resulting flat frequency plot is hard for me to interpret. The density plot is easy. x - rnorm(1000, sd=50) hist(x, breaks=quantile(x,(0:10)/10), prob=TRUE) hist(x, breaks=quantile(x,(0:10)/10), prob=FALSE) Warning message: In plot.histogram(r, freq = freq1, col = col, border = border, angle = angle, : the AREAS in the plot are wrong -- rather use freq=FALSE Bill Dunlap Spotfire, TIBCO Software wdunlap tibco.com -Original Message- From: J Toll [mailto:jct...@gmail.com] Sent: Tuesday, January 22, 2013 5:32 PM To: William Dunlap Cc: r-help Subject: Re: [R] density of hist(freq = FALSE) inversely affected by data magnitude Bill, Thank you. I got it. That can require a fair amount of work to interpret the density, especially with odd or irregular bin sizes. Thanks again, James On Tue, Jan 22, 2013 at 5:33 PM, William Dunlap wdun...@tibco.com wrote: The probability density function is not unitless - it is the derivative of the [cumulative] probability distribution function so it has units delta-probability-mass over delta-x. It must integrate to 1 (over the all possible x). hist(freq=FALSE,x) or hist(prob=TRUE,x) displays an estimate of the density function and the following example shows how the scale matches what you get from the presumed population density function. f function (n, sd) { x - rnorm(n, sd = sd) hist(x, freq = FALSE) # estimated density s - seq(min(x), max(x), len = 129) lines(s, dnorm(s, sd = sd), col = red) # overlay expected density for this sample } f(1e6, sd=1) f(100, sd=1) f(100, sd=0.0001) f(1e6, sd=0.0001) Bill Dunlap Spotfire, TIBCO Software wdunlap tibco.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] problems with coercing a factor to be numeric
To find the proportion of yess in pp you can use mean(pp == yes) and avoid the conversion of a factor to integer (and subtracting 1). The above works for character and factor pp. Bill Dunlap Spotfire, TIBCO Software wdunlap tibco.com -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Francesco Sarracino Sent: Wednesday, January 23, 2013 1:59 AM To: D. Rizopoulos Cc: R help Subject: Re: [R] problems with coercing a factor to be numeric Thanks, this works! but I am surprised that R has such a strange behavior and that there is no way to control it. BTW, also as.integer(pp)-1 works! Still, it doesn't look to me as a first best. At any rate, thanks a lot for your help. f. On 23 January 2013 10:53, D. Rizopoulos d.rizopou...@erasmusmc.nl wrote: check also pp - rep(0:1, 10) pp - factor(pp, levels=(0:1), labels=c(no,yes)) unclass(pp) unclass(pp) - 1 Best, Dimitris On 1/23/2013 10:48 AM, Francesco Sarracino wrote: Dear Dimitris, thanks for your quick reply. I've tried the solutions proposed in 7.10 How do I convert factors to numeric? as.numeric(as.character(pp)) and as.numeric(levels(pp))[as.integer(pp)] However, whatever I do, I get Warning message: NAs introduced by coercion and the output is a vector of NA. Any ideas? f. On 23 January 2013 10:39, D. Rizopoulos d.rizopou...@erasmusmc.nl mailto:d.rizopou...@erasmusmc.nl wrote: Check R FAQ 7.10: How do I convert factors to numeric? I hope it helps. Best, Dimitris On 1/23/2013 10:33 AM, Francesco Sarracino wrote: Dear R listers, I am trying to compute the mean of a dummy variable that is encoded as a factor. However, even though the levels of my factor are 0 - 1, when I compute the mean (after coercing the factor to be numeric), R changes 0 into 1 and 1 into yes, thus altering my expected result. Please, consider the following working example: pp - rep(0:1, 10) pp - factor(pp, levels=(0:1), labels=c(no,yes)) mean(pp) #this won't work because the argument is not numeric or logical mean(as.integer(pp)) # this computes the average, but not on the range 0-1, but 1-2. Indeed, the result is 1.5 and not 0.5 as expected. What am I doing wrong? Thanks in advance for your kind support, f. -- Dimitris Rizopoulos Assistant Professor Department of Biostatistics Erasmus University Medical Center Address: PO Box 2040, 3000 CA Rotterdam, the Netherlands Tel: +31/(0)10/7043478 tel:%2B31%2F%280%2910%2F7043478 Fax: +31/(0)10/7043014 tel:%2B31%2F%280%2910%2F7043014 Web: http://www.erasmusmc.nl/biostatistiek/ -- Francesco Sarracino, Ph.D. https://sites.google.com/site/fsarracino/ -- Dimitris Rizopoulos Assistant Professor Department of Biostatistics Erasmus University Medical Center Address: PO Box 2040, 3000 CA Rotterdam, the Netherlands Tel: +31/(0)10/7043478 Fax: +31/(0)10/7043014 Web: http://www.erasmusmc.nl/biostatistiek/ -- Francesco Sarracino, Ph.D. https://sites.google.com/site/fsarracino/ [[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] Adding a line to barchart
I need a quick help with the following graph (I'm a lattice newbie): require(lattice) npp=1:5 names(npp)=c(A,B,C,D,E) barchart(npp,origin=0,box.width=1) # What I want to do, is add a single vertical line positioned at x = 2 that lays over the bars (say, using a dotted line). How do I go about doing this? In a lattice call, you can use panel= to provide a panel function that does more than one thing per panel. In this case: npp=1:5 names(npp)=c(A,B,C,D,E) barchart(npp,origin=0,box.width=1, panel=function(x, y, ...) { panel.barchart(x, y, ...) panel.abline(v=2, lty=2) } ) This gets more useful with grouped data because the panel function picks up the grouping factor: g - gl(5,5) h - factor(rep(LETTERS[1:5], 5)) barchart(h~ppn|g,origin=0,box.width=1, panel=function(x, y, ...) { panel.barchart(x, y, ...) panel.abline(v=2, lty=2.5) } ) *** This email and any attachments are confidential. Any use...{{dropped:8}} __ 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] extracting characters from a string
Dear All, I have a data frame of vectors of publication names such as 'pub': pub1 - c('Brown DK, Santos R, Rome DF, Don Juan X') pub2 - c('Benigni D') pub3 - c('Arstra SD, Van den Hoops DD, lamarque D') pub - rbind(pub1, pub2, pub3) I would like to construct a dataframe with only author's last name and each last name in columns and the publication in rows. Basically I want to get rid of the initials (max 2, always before a comma) and spaces surounding last name. I would like to avoid a loop. ps: If I could have even a short explanation of the code that extract the values of the character string that would also be great! David [[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] Evaluating the significance of the random effects in GLMM
Thanks! The comments and the information provided were extremely helpful to me. According to DRAFT r-sig-mixed-models FAQ, do not compare lmer models with the corresponding lm fits, or glmer/glm; the log-likelihoods are not commensurate. The problem is not the link function but rather the different additive terms. Maybe, I made a mistake in explaining my problem I want to compare Model A whit model B in order to evaluate the significance of the random effects. A-lmer(Ymat~stu+spi+(1|ber),data=data,family=binomial) B-glm(Ymat~stu+spi,family=binomial,data=data) I'm looking for an alternative way. I made these questions to r-sig-mixed-mod...@r-project.org as you recommended. Thanks again for your time! Gabriela __ 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] extracting characters from a string
1. Study a regular expression tutorial on the web to learn how to do this. 2. ?regex in R summarizes (tersely! -- but clearly) R's regex's. 3. ?grep tells you about R's regular expression manipulation functions. -- Bert On Wed, Jan 23, 2013 at 9:38 AM, Biau David djmb...@yahoo.fr wrote: Dear All, I have a data frame of vectors of publication names such as 'pub': pub1 - c('Brown DK, Santos R, Rome DF, Don Juan X') pub2 - c('Benigni D') pub3 - c('Arstra SD, Van den Hoops DD, lamarque D') pub - rbind(pub1, pub2, pub3) I would like to construct a dataframe with only author's last name and each last name in columns and the publication in rows. Basically I want to get rid of the initials (max 2, always before a comma) and spaces surounding last name. I would like to avoid a loop. ps: If I could have even a short explanation of the code that extract the values of the character string that would also be great! David [[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. -- Bert Gunter Genentech Nonclinical Biostatistics Internal Contact Info: Phone: 467-7374 Website: http://pharmadevelopment.roche.com/index/pdb/pdb-functional-groups/pdb-biostatistics/pdb-ncb-home.htm __ 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] extracting characters from a string
Hello, Try the following. fun - function(x, sep = , ){ s - unlist(strsplit(x, sep)) regmatches(s, regexpr([[:alpha:]]*, s)) } fun(pub) Hope this helps, Rui Barradas Em 23-01-2013 17:38, Biau David escreveu: Dear All, I have a data frame of vectors of publication names such as 'pub': pub1 - c('Brown DK, Santos R, Rome DF, Don Juan X') pub2 - c('Benigni D') pub3 - c('Arstra SD, Van den Hoops DD, lamarque D') pub - rbind(pub1, pub2, pub3) I would like to construct a dataframe with only author's last name and each last name in columns and the publication in rows. Basically I want to get rid of the initials (max 2, always before a comma) and spaces surounding last name. I would like to avoid a loop. ps: If I could have even a short explanation of the code that extract the values of the character string that would also be great! David [[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] italic font for legend text when using expression function for symbols
plot(1) legend('topleft',legend=expression(A,italic(A),bolditalic(A),Delta*italic(D))) On Wed, Jan 23, 2013 at 9:45 AM, raz barvazd...@gmail.com wrote: Hello, I'm trying to add a symbol (Delta) to plot legend with text using expression(paste()) but this disables the text.font that allows to use bold or italic text. as follows: x=c(1:10) y=c(1:10) plot(x,y) legend(1,10,legend=c(A,B,C,expression(paste(Delta, D))), pch=c(24,18,17,16),cex=2,text.font=3,bty=n) Any suggestion to how I can add the Delta symbol and have a italic font? Thanks -- \m/ [[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.
Re: [R] extracting characters from a string
Hello, I've just noticed that my first solution would only return the first set of alphabetic characters, such as Van, not Van den Hoops. The following will solve that problem. fun2 - function(x, sep = , ){ x - strsplit(x, sep) m - lapply(x, function(y) gregexpr( [[:alpha:]]*$, y)) res - lapply(seq_along(x), function(i) regmatches(x[[i]], m[[i]], invert = TRUE)) res - lapply(res, unlist) lapply(res, function(y) y[nchar(y) 0]) } fun2(pub) Hope this helps, Rui Barradas Em 23-01-2013 18:33, Rui Barradas escreveu: Hello, Try the following. fun - function(x, sep = , ){ s - unlist(strsplit(x, sep)) regmatches(s, regexpr([[:alpha:]]*, s)) } fun(pub) Hope this helps, Rui Barradas Em 23-01-2013 17:38, Biau David escreveu: Dear All, I have a data frame of vectors of publication names such as 'pub': pub1 - c('Brown DK, Santos R, Rome DF, Don Juan X') pub2 - c('Benigni D') pub3 - c('Arstra SD, Van den Hoops DD, lamarque D') pub - rbind(pub1, pub2, pub3) I would like to construct a dataframe with only author's last name and each last name in columns and the publication in rows. Basically I want to get rid of the initials (max 2, always before a comma) and spaces surounding last name. I would like to avoid a loop. ps: If I could have even a short explanation of the code that extract the values of the character string that would also be great! David [[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.
[R] hyphen replaced by period in header when using read.table
To Whom It May Concern: I have noticed that all of the hyphens (-) are changed to periods (.) when I try to read.table() and the headers contain - I am using R 2.13 on a RedHat system. Here is the situation: I have the following a tab-delimited text file saved as test.txt File1-a.txt File1-b.txt File2-a.txt File2-b.txt 1 1 2 1 1 2 3 2 1 1 2 3 1 2 3 4 When I use: example - read.table(test.txt, header = TRUE, sep = \t) example File1.a.txt File1.b.txt File2.a.txt File2.b.txt 1 1 2 1 1 2 3 2 1 1 2 3 1 2 3 4 Notice that all of the - are changed to . I read the help(read.table) along with a google search, but I can't find why this is happening. Is there a way to prevent this from happening? Thanks in advance, Mike [[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] extracting characters from a string
Hi, You could try this: dat1-read.table(text=pub,sep=,,fill=TRUE,stringsAsFactors=F) dat2- as.data.frame(do.call(cbind,lapply(dat1,function(x) gsub( $,,gsub(^ |\\w+$,,x,stringsAsFactors=F) dat2 # V1 V2 V3 V4 #1 Brown Santos Rome Don Juan #2 Benigni #3 Arstra Van den Hoops lamarque A.K. - Original Message - From: Biau David djmb...@yahoo.fr To: r help list r-help@r-project.org Cc: Sent: Wednesday, January 23, 2013 12:38 PM Subject: [R] extracting characters from a string Dear All, I have a data frame of vectors of publication names such as 'pub': pub1 - c('Brown DK, Santos R, Rome DF, Don Juan X') pub2 - c('Benigni D') pub3 - c('Arstra SD, Van den Hoops DD, lamarque D') pub - rbind(pub1, pub2, pub3) I would like to construct a dataframe with only author's last name and each last name in columns and the publication in rows. Basically I want to get rid of the initials (max 2, always before a comma) and spaces surounding last name. I would like to avoid a loop. ps: If I could have even a short explanation of the code that extract the values of the character string that would also be great! David [[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] nesting in CoxPH with survival package
Thank you for the suggestions. Just to clarify, my first question was more on what actual coding I should be using to indicate a nested variable when using the coxph() function. I asked this after consulting several times with a local statistician, but unfortunately neither of us are very familiar with R. After further consultation, I have changed the design to a 2*2 design (2 levels of ExpTemp and Stability each) with blocking (Period). I am still getting the x matrix deemed to be singular error. LOEmod3alt=coxph(LOE.fit~ExpTemp+Stability+Period,data=goodexp) Warning message: In coxph(LOE.fit ~ ExpTemp + Stability + Period, data = goodexp) : X matrix deemed to be singular; variable 5 summary(LOEmod3alt) Call: coxph(formula = LOE.fit ~ ExpTemp + Stability + Period, data = goodexp) n= 184, number of events= 105 coef exp(coef) se(coef) z Pr(|z|) ExpTemp -3.17825 0.04166 0.53105 -5.985 2.17e-09 *** StabilityStatic -0.84129 0.43115 0.20470 -4.110 3.96e-05 *** PeriodB 1.06794 2.90937 0.22859 4.672 2.98e-06 *** PeriodC 1.23853 3.45054 0.58457 2.119 0.0341 * PeriodD NANA 0.0 NA NA --- Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 exp(coef) exp(-coef) lower .95 upper .95 ExpTemp 0.0416624.0047 0.01471 0.118 StabilityStatic 0.43115 2.3194 0.28866 0.644 PeriodB 2.90937 0.3437 1.85877 4.554 PeriodC 3.45054 0.2898 1.0972310.851 PeriodDNA NANANA Concordance= 0.833 (se = 0.03 ) Rsquare= 0.591 (max possible= 0.995 ) Likelihood ratio test= 164.4 on 4 df, p=0 Wald test= 111.1 on 4 df, p=0 Score (logrank) test = 179.9 on 4 df, p=0 with(redo, table(LOEStatusfull, Period,ExpTemp)) , , ExpTemp = FIVE Period LOEStatusfull A B C D 0 42 0 35 0 1 4 0 11 0 , , ExpTemp = FOUR Period LOEStatusfull A B C D 0 0 0 0 2 1 0 46 0 44 As best as I can tell, none of my variables are collinear. Are there any other suggestions of how to deal with this error, or any more information I can provide to help understand why I would be getting this? Thank you for your time and your help, Katie On Sat, Jan 12, 2013 at 4:54 PM, Bert Gunter gunter.ber...@gene.com wrote: Katie: You need to get local statistical help. What you are doing makes no sense. See inline below. -- Bert On Sat, Jan 12, 2013 at 1:03 PM, David Winsemius dwinsem...@comcast.net wrote: On Jan 11, 2013, at 5:35 PM, Katie Anweiler wrote: Hello all, I am trying to understand how to specify nested factors when using coxph(), and if it is appropriate to nest these factors in my situation. In the simplest form, I am testing two different temperatures, with each temperature being performed twice in different experimental periods (e.g. Temp5 performed in Period A and C, Temp4 performed in Period B and D) Period is confounded with temperature. That is the source of the singularity. in the message received below. You can estimate the C-A and the D-B differences. As I said, get statistical help. These are not R questions. -- Bert I am trying to see if survival time is affected by the treatment temperature. To do this I am using temperature and experimental period nested within temperature as factors. LOEtempmod.5days=coxph(LOE.stable.5days~Temp+Temp/Period,data=goodstable) Warning message: In coxph(LOE.stable.5days ~ Temp + Temp/Period, : X matrix deemed to be singular; variable 2 5 6 7 1. Is this an appropriate way of nesting? Have you looked at the coxme package? http://cran.r-project.org/web/packages/coxme/index.html 2. Can this error message be ignored? Sometimes R packages correctly drop variables that are exactly collinear: other times the correct solution is not clear. I would think the answer in this case would be no, but do not have a lot to go on at this point. -- David Winsemius, MD Alameda, CA, USA __ 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. -- Bert Gunter Genentech Nonclinical Biostatistics Internal Contact Info: Phone: 467-7374 Website: http://pharmadevelopment.roche.com/index/pdb/pdb-functional-groups/pdb-biostatistics/pdb-ncb-home.htm __ 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] hyphen replaced by period in header when using read.table
Please read ?read.table again, and pay special attention to the check.names argument. A - is not allowed in a column name because it would lead to problems like: mydata$a-b vs mydata$a - b where mydata$a.b has no such confusion. If you must have - instead of ., you can use check.names=FALSE and make sure that you always access the columns using: mydata[, a-b] or mydata[a-b] instead of with the $ shortcut. mydata - data.frame(col1 = 1:3, a-b = 4:6, check.names=FALSE) mydata col1 a-b 11 4 22 5 33 6 Sarah On Wed, Jan 23, 2013 at 1:50 PM, michael.dufa...@genzyme.com wrote: To Whom It May Concern: I have noticed that all of the hyphens (-) are changed to periods (.) when I try to read.table() and the headers contain - I am using R 2.13 on a RedHat system. Here is the situation: I have the following a tab-delimited text file saved as test.txt File1-a.txt File1-b.txt File2-a.txt File2-b.txt 1 1 2 1 1 2 3 2 1 1 2 3 1 2 3 4 When I use: example - read.table(test.txt, header = TRUE, sep = \t) example File1.a.txt File1.b.txt File2.a.txt File2.b.txt 1 1 2 1 1 2 3 2 1 1 2 3 1 2 3 4 Notice that all of the - are changed to . I read the help(read.table) along with a google search, but I can't find why this is happening. Is there a way to prevent this from happening? Thanks in advance, Mike -- Sarah Goslee http://www.functionaldiversity.org __ 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] how to read a df like that and transform it?
Hi, If the `spaces` in father, mother, num_daughter columns needs to be replaced by the values in the previous row, dat1-read.table(text= father, mother, num_daughter, daughter 291, 3906, 0, 275, 4219, 0, 273, 4236, 1, 49410 281, 4163, 1, 49408 274, 4226, 1, 49406 295, 3869, 2, 49403 , ,, 49404 287, 4113, 0 295, 3871, 1, 49401 292, 3895, 4, 49396 ,,, 49397 ,,, 49398 ,,, 49399 291, 3900, 3, 49392 ,sep=,,header=T,fill=TRUE) library(zoo) dat2-data.frame(na.locf(dat1[,1:3]),daughter=dat1[,4]) dat2Sub-dat2[rep(which(dat2[,3]==3),2),1:3] dat2Sub$daughter-NA dat3-rbind(dat2,dat2Sub) dat3$num_daughter[dat3$num_daughter1]-ave(dat3$num_daughter[dat3$num_daughter1],dat3$num_daughter[dat3$num_daughter1],FUN=seq_along) reshape(dat3,v.names=daughter,idvar=c(father,mother),timevar=num_daughter,direction=wide) # father mother daughter.0 daughter.1 daughter.2 daughter.3 daughter.4 #1 291 3906 NA NA NA NA NA #2 275 4219 NA NA NA NA NA #3 273 4236 NA 49410 NA NA NA #4 281 4163 NA 49408 NA NA NA #5 274 4226 NA 49406 NA NA NA #6 295 3869 NA 49403 49404 NA NA #8 287 4113 NA NA NA NA NA #9 295 3871 NA 49401 NA NA NA #10 292 3895 NA 49396 49397 49398 49399 #14 291 3900 NA 49392 NA NA NA A.K. - Original Message - From: Yao He yao.h.1...@gmail.com To: R help r-help@r-project.org Cc: Sent: Wednesday, January 23, 2013 7:42 AM Subject: [R] how to read a df like that and transform it? Dear all I have a data.frame like that : father mother num_daughter daughter 291 3906 0 NULL 275 4219 0 NULL 273 4236 1 49410 281 4163 1 49408 274 4226 1 49406 295 3869 2 49403 49404 287 4113 0 NULL 295 3871 1 49401 292 3895 4 49396 49397 49398 49399 291 3900 3 49392 How to read it into R and transform it like that: father mother num_daughter daughter1 daughter2 daughter3 daughter4 291 3906 0 NULL 275 4219 0 NULL 273 4236 1 49410 281 4163 1 49408 274 4226 1 49406 295 3869 2 49403 49404 287 4113 0 NULL 295 3871 1 49401 292 3895 4 49396 49397 49398 49399 291 3900 3 49392 library (plyr) and library (reshape2) and other good packages are OK for me. Thanks a lot! Yao He — Master candidate in 2rd year Department of Animal genetics breeding Room 436,College of Animial ScienceTechnology, China Agriculture University,Beijing,100193 E-mail: yao.h.1...@gmail.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] Pasting a list of parameters into a function
I need to repeat a function many times, with differing parameters held constant across iterations. To accomplish this, I would like to create a list (or vector) of parameters, and then insert that list into the function. For example: q-(l,a,b,s) genericfunction-function(q){ } ## The equivalent code would of course be genericfunction-function(l,a,b,s){ } Any help or suggestions would be much appreciated. -- View this message in context: http://r.789695.n4.nabble.com/Pasting-a-list-of-parameters-into-a-function-tp4656445.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] How to extract values of results in gamlss.tr
Dear R helpers, I have following loss data and I need to fit LEFT truncated Log Normal distribution to this data which is Truncated at 100. dat = c(1333834,5710254,9987567,7809469,6940935,3473671,1270209,1102523,1124002, 5830159,4302300,3925242,2638409,2324421,7238436,9088709,7439250,4976551,4864319, 8741334,1863770,7098310,4942288,4971829,4986372) library(gamlss.tr) gen.trun(5, LOGNO) result - gamlss(dat~1, family=LOGNOtr) # THIS GIVES result Family: c(LOGNOtr, left truncated Log Normal) Fitting method: RS() Call: gamlss(formula = dat ~ 1, family = LOGNOtr) Mu Coefficients: (Intercept) 15.23 Sigma Coefficients: (Intercept) -0.3977 Degrees of Freedom for the fit: 2 Residual Deg. of Freedom 23 Global Deviance: 812.568 AIC: 816.568 SBC: 819.006 My problem is how do I extract these values of Mu Coefficients and Sigma Coefficients, if I want to use these values for further analyses? Kindly guide Katherine Gobin [[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] How to extract values of results in gamlss.tr
On Jan 23, 2013, at 12:14 PM, Katherine Gobin wrote: Dear R helpers, I have following loss data and I need to fit LEFT truncated Log Normal distribution to this data which is Truncated at 100. dat = c(1333834,5710254,9987567,7809469,6940935,3473671,1270209,1102523,1124002, 5830159,4302300,3925242,2638409,2324421,7238436,9088709,7439250,4976551,4864319, 8741334,1863770,7098310,4942288,4971829,4986372) library(gamlss.tr) gen.trun(5, LOGNO) result - gamlss(dat~1, family=LOGNOtr) # THIS GIVES result Family: c(LOGNOtr, left truncated Log Normal) Fitting method: RS() Call: gamlss(formula = dat ~ 1, family = LOGNOtr) Mu Coefficients: (Intercept) 15.23 Sigma Coefficients: (Intercept) -0.3977 Degrees of Freedom for the fit: 2 Residual Deg. of Freedom 23 Global Deviance: 812.568 AIC: 816.568 SBC: 819.006 My problem is how do I extract these values of Mu Coefficients and Sigma Coefficients, if I want to use these values for further analyses? After looking at names(result) result$mu.coefficients (Intercept) 15.23012 result$sigma.coefficients (Intercept) -0.3976947 help(gamlss.tr) I looked for an extractor function in hte Index for htat package but didn't find one. Since this is a suite of packages you should probably do your own more extensive search in the documents. -- David David Winsemius Alameda, CA, USA __ 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] problems with coercing a factor to be numeric
Given that your labels are no and yes, what do you expect R to do? To quote a well-known fortune, R is lacking a mind_read() function! cheers, Rolf Turner On 01/23/2013 10:58 PM, Francesco Sarracino wrote: Thanks, this works! but I am surprised that R has such a strange behavior and that there is no way to control it. BTW, also as.integer(pp)-1 works! Still, it doesn't look to me as a first best. At any rate, thanks a lot for your help. f. On 23 January 2013 10:53, D. Rizopoulos d.rizopou...@erasmusmc.nl wrote: check also pp - rep(0:1, 10) pp - factor(pp, levels=(0:1), labels=c(no,yes)) unclass(pp) unclass(pp) - 1 Best, Dimitris On 1/23/2013 10:48 AM, Francesco Sarracino wrote: Dear Dimitris, thanks for your quick reply. I've tried the solutions proposed in 7.10 How do I convert factors to numeric? as.numeric(as.character(pp)) and as.numeric(levels(pp))[as.integer(pp)] However, whatever I do, I get Warning message: NAs introduced by coercion and the output is a vector of NA. Any ideas? f. On 23 January 2013 10:39, D. Rizopoulos d.rizopou...@erasmusmc.nl mailto:d.rizopou...@erasmusmc.nl wrote: Check R FAQ 7.10: How do I convert factors to numeric? I hope it helps. Best, Dimitris On 1/23/2013 10:33 AM, Francesco Sarracino wrote: Dear R listers, I am trying to compute the mean of a dummy variable that is encoded as a factor. However, even though the levels of my factor are 0 - 1, when I compute the mean (after coercing the factor to be numeric), R changes 0 into 1 and 1 into yes, thus altering my expected result. Please, consider the following working example: pp - rep(0:1, 10) pp - factor(pp, levels=(0:1), labels=c(no,yes)) mean(pp) #this won't work because the argument is not numeric or logical mean(as.integer(pp)) # this computes the average, but not on the range 0-1, but 1-2. Indeed, the result is 1.5 and not 0.5 as expected. What am I doing wrong? Thanks in advance for your kind support, f. -- Dimitris Rizopoulos Assistant Professor Department of Biostatistics Erasmus University Medical Center Address: PO Box 2040, 3000 CA Rotterdam, the Netherlands Tel: +31/(0)10/7043478 tel:%2B31%2F%280%2910%2F7043478 Fax: +31/(0)10/7043014 tel:%2B31%2F%280%2910%2F7043014 Web: http://www.erasmusmc.nl/biostatistiek/ -- Francesco Sarracino, Ph.D. https://sites.google.com/site/fsarracino/ -- Dimitris Rizopoulos Assistant Professor Department of Biostatistics Erasmus University Medical Center Address: PO Box 2040, 3000 CA Rotterdam, the Netherlands Tel: +31/(0)10/7043478 Fax: +31/(0)10/7043014 Web: http://www.erasmusmc.nl/biostatistiek/ __ 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] problems with coercing a factor to be numeric
Thank you all for your replies. Let me try to explain my point: first of all, let me clarify that I didn't mean to criticize anyone (or anything). Secondly, what I meant refers to the fact that I've read on an R and S-plus companion to applied regression about methods to alter the encoding of factors when using contrasts in regressions. These are options (for contrasts) that can be easily set as option('contrasts'). This command changes the way R creates the dummies out of a factor and various methods are available. I was expecting that R might have had something similar that applied to my case, thus changing the way R attaches numeric values to my dummy variable. I am just surprised that such option doesn't exist. I was having wrong expectations. Thank you all for helping me clarifying this point. f. On 23 January 2013 21:55, Rolf Turner rolf.tur...@xtra.co.nz wrote: Given that your labels are no and yes, what do you expect R to do? To quote a well-known fortune, R is lacking a mind_read() function! cheers, Rolf Turner On 01/23/2013 10:58 PM, Francesco Sarracino wrote: Thanks, this works! but I am surprised that R has such a strange behavior and that there is no way to control it. BTW, also as.integer(pp)-1 works! Still, it doesn't look to me as a first best. At any rate, thanks a lot for your help. f. On 23 January 2013 10:53, D. Rizopoulos d.rizopou...@erasmusmc.nl wrote: check also pp - rep(0:1, 10) pp - factor(pp, levels=(0:1), labels=c(no,yes)) unclass(pp) unclass(pp) - 1 Best, Dimitris On 1/23/2013 10:48 AM, Francesco Sarracino wrote: Dear Dimitris, thanks for your quick reply. I've tried the solutions proposed in 7.10 How do I convert factors to numeric? as.numeric(as.character(pp)) and as.numeric(levels(pp))[as.**integer(pp)] However, whatever I do, I get Warning message: NAs introduced by coercion and the output is a vector of NA. Any ideas? f. On 23 January 2013 10:39, D. Rizopoulos d.rizopou...@erasmusmc.nl mailto:d.rizopoulos@**erasmusmc.nl d.rizopou...@erasmusmc.nl wrote: Check R FAQ 7.10: How do I convert factors to numeric? I hope it helps. Best, Dimitris On 1/23/2013 10:33 AM, Francesco Sarracino wrote: Dear R listers, I am trying to compute the mean of a dummy variable that is encoded as a factor. However, even though the levels of my factor are 0 - 1, when I compute the mean (after coercing the factor to be numeric), R changes 0 into 1 and 1 into yes, thus altering my expected result. Please, consider the following working example: pp - rep(0:1, 10) pp - factor(pp, levels=(0:1), labels=c(no,yes)) mean(pp) #this won't work because the argument is not numeric or logical mean(as.integer(pp)) # this computes the average, but not on the range 0-1, but 1-2. Indeed, the result is 1.5 and not 0.5 as expected. What am I doing wrong? Thanks in advance for your kind support, f. -- Dimitris Rizopoulos Assistant Professor Department of Biostatistics Erasmus University Medical Center Address: PO Box 2040, 3000 CA Rotterdam, the Netherlands Tel: +31/(0)10/7043478 tel:%2B31%2F%280%2910%**2F7043478 Fax: +31/(0)10/7043014 tel:%2B31%2F%280%2910%**2F7043014 Web: http://www.erasmusmc.nl/**biostatistiek/http://www.erasmusmc.nl/biostatistiek/ -- Francesco Sarracino, Ph.D. https://sites.google.com/site/**fsarracino/https://sites.google.com/site/fsarracino/ -- Dimitris Rizopoulos Assistant Professor Department of Biostatistics Erasmus University Medical Center Address: PO Box 2040, 3000 CA Rotterdam, the Netherlands Tel: +31/(0)10/7043478 Fax: +31/(0)10/7043014 Web: http://www.erasmusmc.nl/**biostatistiek/http://www.erasmusmc.nl/biostatistiek/ -- Francesco Sarracino, Ph.D. https://sites.google.com/site/fsarracino/ [[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] dummy encoding in metafor
Hi Michael, The supervisorfor my Master'sThesis told me that my means are the effect size and cause of this I have to take figure 1 for all standard deviations. So I hope that was the right information. From: Michael Dewey i...@aghmed.fsnet.co.uk lfgang.viechtba...@maastrichtuniversity.nl; Michael Dewey i...@aghmed.fsnet.co.uk; r-help@r-project.org r-help@r-project.org Sent: Wednesday, January 23, 2013 10:22 AM Subject: Re: [R] dummy encoding in metafor At 08:30 23/01/2013, Alma Wilflinger wrote: Dear Wolfgang and Michael, [[elided Yahoo spam]] Concerning the Variance: I took the variance I used for CMA (which is always 1), so I think it should be the right one. It seems unlikely to me that the variance from each study would be the same although I suppose it could be possible. Are you sure you are supplying the right values to CMA? Thank you for noticing and mentioning though :) I really appreciate how helpful you both are. best, Alma From: Viechtbauer Wolfgang (STAT) wolfgang.viechtba...@maastrichtuniversity.nl To: Michael Dewey i...@aghmed.fsnet.co.uk; Alma Wilflinger alma_an...@yahoo.com; r-help@r-project.org r-help@r-project.org Sent: Monday, January 21, 2013 11:10 AM Subject: RE: [R] dummy encoding in metafor As Michael already mentioned, the error: Error in qr.solve(wX, diag(k)) : singular matrix 'a' in solve indeed indicates that your design matrix is not of full rank (i.e., there are linear dependencies among your predictors). With this many factors in the same model, this is not surprising if k is only 94 (which is actually quite large for a meta-analysis). One options is to leave out some of the predictors. You can also try collapsing some of the levels of the factors. Of course, you lose some details that way, but apparently you don't have enough data in the first place to carry out such a detailed analysis. One other thing I noticed. You wrote: rma(yi=Mean, vi=Variance, ni=N.1, ...) I suspect that your variable Variance is actually the variance of the raw scores. However, the vi argument is used to pass the sampling variances of the yi values to the function -- not the variance of raw scores. The (estimated) sampling variance of a mean is s^2 / n, so if I am not mistaken, you really want to use: rma(yi=Mean, vi=Variance/N.1, ...) Best, Wolfgang -- Wolfgang Viechtbauer, Ph.D., Statistician Department of Psychiatry and Psychology School for Mental Health and Neuroscience Faculty of Health, Medicine, and Life Sciences Maastricht University, P.O. Box 616 (VIJV1) 6200 MD Maastricht, The Netherlands +31 (43) 388-4170 | http://www.wvbauer.com -Original Message- From: mailto:r-help-boun...@r-project.orgr-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Michael Dewey Sent: Monday, January 21, 2013 10:40 To: Alma Wilflinger; Michael Dewey; mailto:r-help@r-project.orgr-help@r-project.org Subject: Re: [R] dummy encoding in metafor At 14:48 20/01/2013, Alma Wilflinger wrote: Hi, thank you very much for your kind answer. If you look a bit further down the manual page you will see ### using a model formula to specify the same model rma(yi, vi, mods=~factor(alloc)+year+ablat, data=dat, method=REML, btt=c(2,3)) which is much easier. I have seen the possibility of using a model formula for dummy encoding and you are right it is much easier than doing it by hand. Thing is that if I include some moderator variables into the parameters I get the error: Error in qr.solve(wX, diag(k)) : singular matrix 'a' in solve I suspect that you have a linear dependence between your moderator variables. Depending on how many levels there are for country, sample, and so on you do have a lot of predictors (you presumably know that a factor counts as levels-1 for this purpose?) For example this call works: result = rma(yi=Mean, vi=Variance, ni=N.1, mods=~factor(Country) + relevel(factor(Sample), ref=Students) + Gender + Age + factor(Category) + relevel(factor(Block), ref=c)+ relevel(factor(order), ref=x), data=csvDataCmaAll, method=REML) If I add the trials which is of type INT: result = rma(yi=Mean, vi=Variance, ni=N.1, mods=~factor(Country) + relevel(factor(Sample), ref=Students) + Gender + Age + factor(Category) + relevel(factor(Block), ref=c)+ relevel(factor(order), ref=x) + trials, data=csvDataCmaAll, method=REML) I get the error and I was not able to find a definite reason for this error or how to solve it I wanted to try it by doing it manually. I think I have found out that it somehow relates to the If you code them yourself R does not know. You know. Regarding this I think my question was not clear enough. If R does the dummy encoding automatically via a model formula it leaves out one of the factors and uses it as a
Re: [R] How to construct a valid seed for l'Ecuyer's method with given .Random.seed?
Dear Hana, Thanks for helping. I am still wondering, why m1 (which should be 2^32-209 [see line 34 in ./src/RngStream.c]) is -767742437 in my case and why the minimal example you gave was working for you but isn't for me. Apart from that, ?.Random.seed - L'Ecuyer-CMRG says: , | The 6 elements of the seed are internally regarded as 32-bit | unsigned integers. Neither the first three nor the last | three should be all zero, and they are limited to less than | ‘4294967087’ and ‘429493’ respectively. ` = .Random.seed provides a *signed* integer. I tried to convert it to an unsigned integer: RNGkind() set.seed(1) .Random.seed[-1] RNGkind(L'Ecuyer-CMRG) .Random.seed[-1] # = unsigned seed - .Random.seed[-1] + 2^32 # = shifting require(rlecuyer) .lec.SetPackageSeed(seed) ... but it fails with , | Error in .lec.SetPackageSeed(seed) : Seed[1] = 14, Seed is not set. ` = so there seem to be the requirement that the second element of the seed is 14 (???). I might have done the conversion to a signed integer incorrectly, though. It would be great if the seed was checked *precisely* (not just basic length checks) in R, maybe in .lec.CheckSeed(). That would rule out further problems and strange error messages from C, which are harder to debug. What are the precise conditions for the seed in 'rlecuyer'? Judging from the above error, the second element must be 14. But, additionally,... ? I hope there is a solution to the problem of how to convert .Random.seed to get a valid seed for 'rlecuyer'... we need that in a package. Cheers, Marius Hana Sevcikova ha...@uw.edu writes: Marius, I looked it up in the original L'Ecuyer's paper: The seed must be larger than 0. Thus, the function defines the seed variable as unsigned long integer. You're passing a negative number, so I think there is some overflow going on. The internal L'Ecuyer RNG is a modification of the original one (and I'm not familiar with it), but they seem to relax that restriction. Hana pgphE0xoQvbRe.pgp Description: PGP signature __ 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] How to construct a valid seed for l'Ecuyer's method withgiven .Random.seed?
-Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Marius Hofert Sent: Wednesday, January 23, 2013 2:24 PM To: Hana Sevcikova Cc: R-help Subject: Re: [R] How to construct a valid seed for l'Ecuyer's method withgiven .Random.seed? Dear Hana, Thanks for helping. I am still wondering, why m1 (which should be 2^32-209 [see line 34 in ./src/RngStream.c]) is -767742437 in my case and why the minimal example you gave was working for you but isn't for me. Apart from that, ?.Random.seed - L'Ecuyer-CMRG says: , | The 6 elements of the seed are internally regarded as 32-bit | unsigned integers. Neither the first three nor the last | three should be all zero, and they are limited to less than | ‘4294967087’ and ‘429493’ respectively. ` = .Random.seed provides a *signed* integer. I tried to convert it to an unsigned integer: RNGkind() set.seed(1) .Random.seed[-1] RNGkind(L'Ecuyer-CMRG) .Random.seed[-1] # = unsigned seed - .Random.seed[-1] + 2^32 # = shifting require(rlecuyer) .lec.SetPackageSeed(seed) ... but it fails with , | Error in .lec.SetPackageSeed(seed) : Seed[1] = 14, Seed is not set. ` = so there seem to be the requirement that the second element of the seed is 14 (???). I might have done the conversion to a signed integer incorrectly, though. It would be great if the seed was checked *precisely* (not just basic length checks) in R, maybe in .lec.CheckSeed(). That would rule out further problems and strange error messages from C, which are harder to debug. What are the precise conditions for the seed in 'rlecuyer'? Judging from the above error, the second element must be 14. But, additionally,... ? I hope there is a solution to the problem of how to convert .Random.seed to get a valid seed for 'rlecuyer'... we need that in a package. Cheers, Marius Hana Sevcikova ha...@uw.edu writes: Marius, I looked it up in the original L'Ecuyer's paper: The seed must be larger than 0. Thus, the function defines the seed variable as unsigned long integer. You're passing a negative number, so I think there is some overflow going on. The internal L'Ecuyer RNG is a modification of the original one (and I'm not familiar with it), but they seem to relax that restriction. Hana I apologize if this message is posted twice. I am having email problems. I think the confusion about negative numbers is that R represents the seed values as signed integers, but the underlying C code interprets those values as unsigned integers. At least that is how I read the documentation on .Random.seed Hope this is helpful, Dan Daniel Nordlund Bothell, WA USA __ 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] How to construct a valid seed for l'Ecuyer's method with given .Random.seed?
Marius, I looked it up in the original L'Ecuyer's paper: The seed must be larger than 0. Thus, the function defines the seed variable as unsigned long integer. You're passing a negative number, so I think there is some overflow going on. The internal L'Ecuyer RNG is a modification of the original one (and I'm not familiar with it), but they seem to relax that restriction. Hana On 1/23/13 1:01 AM, Marius Hofert wrote: Since clusterSetupRNG() calls clusterSetupRNGstream() and this calls .lec.SetPackageSeed(), I could further minimalize the problem: set.seed(1) RNGkind(L'Ecuyer-CMRG) # = .Random.seed is of length 7 (first number encodes the rng kind) (seed - .Random.seed[2:7]) # should give a valid seed for l'Ecuyer's RNG require(rlecuyer) # latest version 0.3-3 .lec.SetPackageSeed(seed) The last line fails with: , | Error in .lec.SetPackageSeed(seed) : | Seed[0] = -767742437, Seed is not set. ` Looking at .lec.SetPackageSeed, seed seems to pass .lec.CheckSeed() [the check could probably be improved here (but further checking is done in the C code; see below)]: , | .lec.SetPackageSeed | function (seed = rep(12345, 6)) | { | if (!exists(.lec.Random.seed.table, envir = .GlobalEnv)) | .lec.init() | seed - .lec.CheckSeed(seed) # = bad check since it's passed | .Call(r_set_package_seed, as.double(seed), PACKAGE = rlecuyer) # = this fails! | return(seed) | } | environment: namespace:rlecuyer ` Going into the C code, r_set_package_seed calls RngStream_SetPackageSeed which in turn calls CheckSeed(seed). The relevant part of CheckSeed is this: , | for (i = 0; i 3; ++i) { | if (seed[i] = m1) { | /* HS 01-25-2012 */ | error(Seed[%1d] = %d, Seed is not set.\n, i,m1); |/* original code | fprintf (stderr, \n |ERROR: Seed[%1d] = m1, Seed is not set.\n |\n\n, i); | return (-1); |*/ | } | } ` Note that seed[0] in this (C-)code corresponds to the first element of my variable seed, which is -1535484873. This should definitely be smaller than m1 since m1 is defined as 4294967087.0 on line 34 in ./src/RngStream.c of the package 'rlecuyer'. Why is seed[i] then = m1??? This is strange. Indeed, as you can see from the error message above, m1 is taken as -767742437 in my case (why?). Still (and even more confusing), -1535484873 = -767742437 is FALSE (!) but the if(){} is entered anyways... Cheers, Marius __ 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] SNPRelate package error
I had the same problem but it now works if you remove some of the #info lines at the top of the file so that the number of lines is the same as the example sequence.vcf file before the data starts -- View this message in context: http://r.789695.n4.nabble.com/SNPRelate-package-error-tp4656236p4656452.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] cannot allocate memory block of size 2.7 Gb
Hello R-users I am getting error messagens when I require some packages or execute some procedures, like these below: require(tseries) Loading required package: tseries Error in get(Info[i, 1], envir = env) : cannot allocate memory block of size 2.7 Gb require (TSA) Loading required package: TSA Loading required package: locfit Error in get(Info[i, 1], envir = env) : cannot allocate memory block of size 2.7 Gb Failed with error: package locfit could not be loaded I used the commands memory.limit() and memory.size() to check memory limitation, but I could not see any problem. I send also sessionInfo() data. I have run the same script and different computers with less memory capacity, so it seems to me that it is not a real memory problem. memory.limit() [1] 6004 memory.size() [1] 1361.88 sessionInfo() R version 2.15.2 (2012-10-26) Platform: x86_64-w64-mingw32/x64 (64-bit) locale: [1] LC_COLLATE=Portuguese_Brazil.1252 LC_CTYPE=Portuguese_Brazil.1252 [3] LC_MONETARY=Portuguese_Brazil.1252 LC_NUMERIC=C [5] LC_TIME=Portuguese_Brazil.1252 loaded via a namespace (and not attached): [1] grid_2.15.2 quadprog_1.5-4 stabledist_0.6-5 tools_2.15.2 [5] xtable_1.7-0 Please, someone can help me understand that is happening and what should I do to fix it? Regards, Cláudio Brisolara Postgraduate student University of São Paulo [[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] setting off-diagonals to zero
I'm not following. Printing SEQ to the screen at the intermediate steps using the following modified R code suggests that 'i' is fine and is not getting reset to 1 as you suggest? My understanding, or rather my desired output if someone else is able to weight-in, is that the values in the second line of output (731 732 733 etc.) should not be appearing in the 3rd line of output. The third line of output should be missing 731 thru 736. Any suggestions on how to modify the R code are certainly welcome. Suggested revisions will be substituted back into the third FOR loop in my original post on this thread to prevent the main- and near-main-diagonal terms from being set equal to zero. for (i in 731:732) { SEQ - (i - 5):(i + 5) print(SEQ) SEQ - SEQ[SEQ 730 SEQ 1096] print(SEQ) print((731:1095)[-SEQ]) } # [1] 726 727 728 729 730 731 732 733 734 735 736 # [1] 731 732 733 734 735 736 # [1] 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756... -- View this message in context: http://r.789695.n4.nabble.com/setting-off-diagonals-to-zero-tp4656407p4656461.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] how to read a website with Chinese Character
Hi all, I am planning to parse some information on a website which includes lots of Chinese characters. Does someone know how to read/display Chinese in R? Thanks. url = http://www.teec.org.cn/html/renwujieshao/; x = readLines(url) I tried encoding = 'UTF-8' already but it didn't help. My R version is $platform [1] i386-pc-mingw32 $arch [1] i386 $os [1] mingw32 $system [1] i386, mingw32 $status [1] $major [1] 2 $minor [1] 15.0 HXD [[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] setting off-diagonals to zero
On Jan 23, 2013, at 7:13 AM, emorway wrote: The following 1460 x 1460 matrix can be throught of as 16 distinct 365 x 365 matrices. I'm trying to set off-diaganol terms in the 16 sub-matrices with indices more than +/- 5 (days) from each other to zero using some for loops. This works well for some, but not all, of the for loops. The R code Im using follows. For some reason the third loop below zero's-out everything in the sub-quadrant it is targeting, which is readily observable when viewing the matrix (View(MAT)). library(Matrix) MAT-matrix(rnorm(1460*1460,mean=0,sd=1),nrow = 1460, ncol = 1460) The way to do that in a single 365 x 365 matrix is: Mat - matrix( 1:(365*365), 365, 365) Mat[ abs( col(Mat)-row(Mat) ) 5 ] - 0 Mat The way to propagate that pattern is to use rep(), so here is a one-liner for the task: MAT[ rep( abs( col(Mat)-row(Mat) ) 5, 16) ] - 0 Didn't test on you gigantuan matrix; used smaller example: Mat - matrix( 1:(16*16), 16, 16) test - rbind(Mat, Mat) test[rep( abs( col(Mat)-row(Mat) ) 2 , 2)] - 0 test -- David. #works great for (i in 1:365) { SEQ - (i - 5):(i + 5) SEQ - SEQ[SEQ 0 SEQ 366] MAT[(1:365)[-SEQ], i] - 0 } #works great for (i in 1:365) { SEQ - (i - 5):(i + 5) SEQ - SEQ[SEQ 0 SEQ 366] MAT[(1:365)[-SEQ], i + 365] - 0 } #zero's out everything, including main-diagonal and near-main-diagonal terms??? for (i in 731:1095) { SEQ - (i - 5):(i + 5) SEQ - SEQ[SEQ 730 SEQ 1096] MAT[(731:1095)[-SEQ], i + 365] - 0 } View(MAT) I'm not sure why the third FOR loop above is not leaving the main-diagonal and near-main-diagonal terms alone? -- View this message in context: http://r.789695.n4.nabble.com/setting-off-diagonals-to-zero-tp4656407.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 Alameda, CA, USA __ 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] how to read a website with Chinese Character
On 13-01-23 8:19 PM, Hui Du wrote: Hi all, I am planning to parse some information on a website which includes lots of Chinese characters. Does someone know how to read/display Chinese in R? Thanks. url = http://www.teec.org.cn/html/renwujieshao/; x = readLines(url) If you look at the first few lines of x you'll see this: head(x) [1] !DOCTYPE html PUBLIC \-//W3C//DTD XHTML 1.0 Transitional//EN\\t\http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\; [2] html xmlns=\http://www.w3.org/1999/xhtml\; [3] head [4] meta http-equiv=\Content-Type\ content=\text/html; charset=gb2312\ / At the end of line 4 it shows charset=gb2312. I didn't think that was an encoding, but this seems to do the conversion: y - iconv(x, gb2312, utf-8) y (I don't know if that will display properly on your Windows machine; it doesn't work on mine, because I don't have the fonts installed. But it does work on my Mac.) Duncan Murdoch I tried encoding = 'UTF-8' already but it didn't help. My R version is $platform [1] i386-pc-mingw32 $arch [1] i386 $os [1] mingw32 $system [1] i386, mingw32 $status [1] $major [1] 2 $minor [1] 15.0 HXD [[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] setting off-diagonals to zero
-Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of emorway Sent: Wednesday, January 23, 2013 4:59 PM To: r-help@r-project.org Subject: Re: [R] setting off-diagonals to zero I'm not following. Printing SEQ to the screen at the intermediate steps using the following modified R code suggests that 'i' is fine and is not getting reset to 1 as you suggest? My understanding, or rather my desired output if someone else is able to weight-in, is that the values in the second line of output (731 732 733 etc.) should not be appearing in the 3rd line of output. The third line of output should be missing 731 thru 736. Any suggestions on how to modify the R code are certainly welcome. Suggested revisions will be substituted back into the third FOR loop in my original post on this thread to prevent the main- and near-main-diagonal terms from being set equal to zero. for (i in 731:732) { SEQ - (i - 5):(i + 5) print(SEQ) SEQ - SEQ[SEQ 730 SEQ 1096] print(SEQ) print((731:1095)[-SEQ]) } # [1] 726 727 728 729 730 731 732 733 734 735 736 # [1] 731 732 733 734 735 736 # [1] 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756... The statement print((731:1095)[-SEQ]) does not remove the values of SEQ (i.e. 731 732 733 734 735 736) from the printed sequence, but instead uses SEQ to index into the vector created by 731:1095. But the vector 731:1095 has length 365, so no elements are removed because the smallest value in SEQ is 731 and there are not many elements in the vector. Hope this is helpful, Dan Daniel Nordlund Bothell, WA USA __ 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] Recommendation for website to format R code
Hi list, Could anyone recommend some good website for formatting R code? For example, when you copy paste R code to gmail and back to R, it loses its format, the dash symbol causes errors. I've had someone used it to format my code here on the list, but can't find it anymore. Mike [[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] Recommendation for website to format R code
Are you only interested in formatting code from copy and pasting to/from email? If you are interested in formatting your code in Latex/PDF/HTML take a look at the knitr package: http://yihui.name/knitr/ Also, you could check out the formatR package: http://cran.r-project.org/web/packages/formatR/formatR.pdf --Mark Lamias From: C W tmrs...@gmail.com To: r-help r-help@r-project.org Sent: Wednesday, January 23, 2013 9:27 PM Subject: [R] Recommendation for website to format R code Hi list, Could anyone recommend some good website for formatting R code? For example, when you copy paste R code to gmail and back to R, it loses its format, the dash symbol causes errors. I've had someone used it to format my code here on the list, but can't find it anymore. Mike [[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.
Re: [R] Recommendation for website to format R code
Hey Mark, I am aware of this package. The situation is, 1. I am emailing my code from my machine to a public machine. Installation is a hassle. 2. Copy pasting for a website. I know there are websites for formatting Java and C code. So, I am looking for a website in particular, and I have seen it before but don't remember the site. Mike On Wed, Jan 23, 2013 at 9:34 PM, Mark Lamias mlam...@yahoo.com wrote: Are you only interested in formatting code from copy and pasting to/from email? If you are interested in formatting your code in Latex/PDF/HTML take a look at the knitr package: http://yihui.name/knitr/ Also, you could check out the formatR package: http://cran.r-project.org/web/packages/formatR/formatR.pdf --Mark Lamias -- *From:* C W tmrs...@gmail.com *To:* r-help r-help@r-project.org *Sent:* Wednesday, January 23, 2013 9:27 PM *Subject:* [R] Recommendation for website to format R code Hi list, Could anyone recommend some good website for formatting R code? For example, when you copy paste R code to gmail and back to R, it loses its format, the dash symbol causes errors. I've had someone used it to format my code here on the list, but can't find it anymore. Mike [[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.
Re: [R] setting off-diagonals to zero
HI, Not sure this is what you wanted. for (i in 731:732) { SEQ - (i - 5):(i + 5) print(SEQ) SEQ - SEQ[SEQ 730 SEQ 1096] print(SEQ) vec1-731:741 print(vec1[!vec1%in%SEQ]) } #[1] 726 727 728 729 730 731 732 733 734 735 736 #[1] 731 732 733 734 735 736 #[1] 737 738 739 740 741 # [1] 727 728 729 730 731 732 733 734 735 736 737 #[1] 731 732 733 734 735 736 737 #[1] 738 739 740 741 A.K. - Original Message - From: emorway emor...@usgs.gov To: r-help@r-project.org Cc: Sent: Wednesday, January 23, 2013 7:58 PM Subject: Re: [R] setting off-diagonals to zero I'm not following. Printing SEQ to the screen at the intermediate steps using the following modified R code suggests that 'i' is fine and is not getting reset to 1 as you suggest? My understanding, or rather my desired output if someone else is able to weight-in, is that the values in the second line of output (731 732 733 etc.) should not be appearing in the 3rd line of output. The third line of output should be missing 731 thru 736. Any suggestions on how to modify the R code are certainly welcome. Suggested revisions will be substituted back into the third FOR loop in my original post on this thread to prevent the main- and near-main-diagonal terms from being set equal to zero. for (i in 731:732) { SEQ - (i - 5):(i + 5) print(SEQ) SEQ - SEQ[SEQ 730 SEQ 1096] print(SEQ) print((731:1095)[-SEQ]) } # [1] 726 727 728 729 730 731 732 733 734 735 736 # [1] 731 732 733 734 735 736 # [1] 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756... -- View this message in context: http://r.789695.n4.nabble.com/setting-off-diagonals-to-zero-tp4656407p4656461.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.
Re: [R] Create a Data Frame from an XML
Hi Adam, On Jan 23, 2013, at 11:36 AM, Adam Gabbert wrote: Hello Gentlemen, I mistakenly sent the message twice, because the first time I didn't receive a notification message so I was unsure if it went through properly. Your solutions worked great. Thank you! I felt like I was fairly close just couldn't quite get the final step. Now, I'm trying to reverse the process and account for my header. In other words I have my data frame in R: BRANDNUMYEARVALUE GMC1 1999 1 FORD 2 2000 12000 GMC1 2001 12500 etc and I make some edits. BRANDNUMYEARVALUE DODGE 3 1999 1 TOYOTA 4 2000 12000 DODGE3 2001 12500 You needn't transform to a data frame if all you need to do is tweak the values of some of the attributes. You can always set the attributes of each row node directly. s - c( data, row BRAND=\GMC\ NUM=\1\ YEAR=\1999\ VALUE=\1\ /, row BRAND=\FORD\ NUM=\1\ YEAR=\2000\ VALUE=\12000\ /, row BRAND=\GMC\ NUM=\1\ YEAR=\2001\ VALUE=\12500\ /, row BRAND=\GMC\ NUM=\1\ YEAR=\2008\ VALUE=\22000\ /, /data) x - xmlRoot(xmlTreeParse(s, asText = TRUE, useInternalNodes = TRUE)) node - x[row][[1]] node xmlAttrs(node) - c(BRAND = BUICK, NUM = 3, YEAR = 2000, VALUE = 0) node x So now I would need to ouput an XML file in the same format accounting for my header (essentially, add z: in front of row). I think that what you're describing is a namespace identifier. Check the XML package help for ?xmlNamespace In particular check this example on the help page. node - xmlNode(arg, xmlNode(name, foo), namespace=R) xmlNamespace(node) Cheers, Ben (What I want to output) data z:row BRAND=DODGE NUM=3 YEAR=1999 VALUE=1 / z:row BRAND=TOYOTA NUM=4 YEAR=2000 VALUE=12000 / z:row BRAND=DODGE NUM=3 YEAR=2001 VALUE=12500 / z:row BRAND=TOYOTA NUM=4 YEAR=2002 VALUE=13000 / z:row BRAND=DODGE NUM=3 YEAR=2003 VALUE=14000 / z:row BRAND=TOYOTA NUM=4 YEAR=2004 VALUE=17000 / z:row BRAND=DODGE NUM=3 YEAR=2005 VALUE=15000 / z:row BRAND=DODGE NUM=3 YEAR=1967 VALUE=PRICELESS / z:row BRAND=TOYOTA NUM=4 YEAR=2007 VALUE=17500 / z:row BRAND=DODGE NUM=3 YEAR=2008 VALUE=22000 / /data Thus far from the help I've found online I was trying to set up an xmlTree xml - xmlTree() and use xml$addTag to create nodes and put in the data from my data frame. I feel like I'm not really even close to a solution so I'm starting to believe that this might not be the best path to go down. Once again, any help is much appreciated. AG On Tue, Jan 22, 2013 at 6:04 PM, Duncan Temple Lang dtemplel...@ucdavis.edu wrote: Hi Adam [You seem to have sent the same message twice to the mailing list.] There are various strategies/approaches to creating the data frame from the XML. Perhaps the approach that most closely follows your approach is xmlRoot(doc)[ row ] which returns a list of XML nodes whose node name is row that are children of the root node data. So sapply(xmlRoot(doc) [ row ], xmlAttrs) yields a matrix with as many columns as there are row nodes and with 3 rows - one for each of the BRAND, YEAR and VALUE attributes. So d = t( sapply(xmlRoot(doc) [ row ], xmlAttrs) ) gives you a matrix with the correct rows and column orientation and now you can turn that into a data frame, converting the columns into numbers, etc. as you want with regular R commands (i.e. independently of the XML). D. On 1/22/13 1:43 PM, Adam Gabbert wrote: Hello, I'm attempting to read information from an XML into a data frame in R using the XML package. I am unable to get the data into a data frame as I would like. I have some sample code below. *XML Code:* Header... Data I want in a data frame: data row BRAND=GMC NUM=1 YEAR=1999 VALUE=1 / row BRAND=FORD NUM=1 YEAR=2000 VALUE=12000 / row BRAND=GMC NUM=1 YEAR=2001 VALUE=12500 / row BRAND=FORD NUM=1 YEAR=2002 VALUE=13000 / row BRAND=GMC NUM=1 YEAR=2003 VALUE=14000 / row BRAND=FORD NUM=1 YEAR=2004 VALUE=17000 / row BRAND=GMC NUM=1 YEAR=2005 VALUE=15000 / row BRAND=GMC NUM=1 YEAR=1967 VALUE=PRICLESS / row BRAND=FORD NUM=1 YEAR=2007 VALUE=17500 / row BRAND=GMC NUM=1 YEAR=2008 VALUE=22000 / /data *R Code:* doc -xmlInternalTreeParse (Sample2.xml) top - xmlRoot (doc) xmlName (top) names (top) art - top [[row]] art ** *Output:* artrow BRAND=GMC NUM=1 YEAR=1999 VALUE=1/ * * This is where I am having difficulties. I am unable to access additional rows; ( i.e. row BRAND=GMC NUM=1 YEAR=1967 VALUE=PRICLESS / ) and I am unable to access the individual entries to actually create the data frame. The data frame I would like is as follows: BRANDNUMYEARVALUE
Re: [R] how to read a website with Chinese Character
Thanks a lot. y - iconv(x, gb2312, utf-8) does not work but y - iconv(x, gb2312, UTF8) works on my machine. Thank you for pointing to the right direction. -Original Message- From: Duncan Murdoch [mailto:murdoch.dun...@gmail.com] Sent: Wednesday, January 23, 2013 6:16 PM To: Hui Du Cc: r-help@r-project.org Subject: Re: [R] how to read a website with Chinese Character On 13-01-23 8:19 PM, Hui Du wrote: Hi all, I am planning to parse some information on a website which includes lots of Chinese characters. Does someone know how to read/display Chinese in R? Thanks. url = http://www.teec.org.cn/html/renwujieshao/; x = readLines(url) If you look at the first few lines of x you'll see this: head(x) [1] !DOCTYPE html PUBLIC \-//W3C//DTD XHTML 1.0 Transitional//EN\\t\http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\; [2] html xmlns=\http://www.w3.org/1999/xhtml\; [3] head [4] meta http-equiv=\Content-Type\ content=\text/html; charset=gb2312\ / At the end of line 4 it shows charset=gb2312. I didn't think that was an encoding, but this seems to do the conversion: y - iconv(x, gb2312, utf-8) y (I don't know if that will display properly on your Windows machine; it doesn't work on mine, because I don't have the fonts installed. But it does work on my Mac.) Duncan Murdoch I tried encoding = 'UTF-8' already but it didn't help. My R version is $platform [1] i386-pc-mingw32 $arch [1] i386 $os [1] mingw32 $system [1] i386, mingw32 $status [1] $major [1] 2 $minor [1] 15.0 HXD [[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] Copy on assignment and .Internal(inspect())
Here's another approach using the sampling profiler: prof - function() { Rprof(memory.profiling=T, interval=0.001) replicate(100, f()) Rprof(NULL) summaryRprof(memory = stats) } f - function() { x = seq(1000) for(i in seq(1000)) { x[i] - x[i] + 1 } } prof() = index: prof:replicate vsize.small max.vsize.small vsize.large max.vsize.large 1938 285003 1629 210990 nodesmax.nodes duplications tot.duplications 265805 139493487 1703 samples 251 Average duplications are just 9 for 1000 executions of x[i] - x[i] + 1. A lot of optimization seems to be going on! How do I make sense of the output listed in my previous post, then? Best regards -- Carlos On Thu, Jan 24, 2013 at 12:38 AM, Carlos Pita carlosjosep...@gmail.com wrote: Hi, I would like to know if it's ok to use .Internal(inspect(x)) in order to detect vector copying. Take for example the following silly code: f - function() { x = seq(10) print(.Internal(inspect(x))) for(i in seq(10)) { x[i] - x[i] + 1 print(.Internal(inspect(x))) } } The output of f() was: @bd7acf0 13 INTSXP g0c4 [NAM(1)] (len=10, tl=0) 1,2,3,4,5,... [1] 1 2 3 4 5 6 7 8 9 10 @bdd6f80 14 REALSXP g0c6 [NAM(1)] (len=10, tl=0) 2,2,3,4,5,... [1] 2 2 3 4 5 6 7 8 9 10 @ba66278 14 REALSXP g0c6 [NAM(1)] (len=10, tl=0) 2,3,3,4,5,... [1] 2 3 3 4 5 6 7 8 9 10 @ba661e0 14 REALSXP g0c6 [NAM(1)] (len=10, tl=0) 2,3,4,4,5,... [1] 2 3 4 4 5 6 7 8 9 10 @ba65ee8 14 REALSXP g0c6 [NAM(1)] (len=10, tl=0) 2,3,4,5,5,... [1] 2 3 4 5 5 6 7 8 9 10 @ba65e50 14 REALSXP g0c6 [NAM(1)] (len=10, tl=0) 2,3,4,5,6,... [1] 2 3 4 5 6 6 7 8 9 10 @ba65db8 14 REALSXP g0c6 [NAM(1)] (len=10, tl=0) 2,3,4,5,6,... [1] 2 3 4 5 6 7 7 8 9 10 @ba65c88 14 REALSXP g0c6 [NAM(1)] (len=10, tl=0) 2,3,4,5,6,... [1] 2 3 4 5 6 7 8 8 9 10 @ba6a228 14 REALSXP g0c6 [NAM(1)] (len=10, tl=0) 2,3,4,5,6,... [1] 2 3 4 5 6 7 8 9 9 10 @ba6a190 14 REALSXP g0c6 [NAM(1)] (len=10, tl=0) 2,3,4,5,6,... [1] 2 3 4 5 6 7 8 9 10 10 @ba6a0f8 14 REALSXP g0c6 [NAM(1)] (len=10, tl=0) 2,3,4,5,6,... [1] 2 3 4 5 6 7 8 9 10 11 Notice that the memory reference is different each time. But according to http://r.789695.n4.nabble.com/full-copy-on-assignment-td1750555.html I (possibly a mistake on my part) understand that some optimization should be taking place. Is right to conclude from the output above that the entire vector is being copied each time or is just some kind of shallow copy (maybe some kind of view of the vector but not the vector itself is being copied). Obviously I'm not familiarized with r internals. Best regards -- Carlos __ 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] problems with coercing a factor to be numeric
On 23 Jan 2013, at 21:36, Francesco Sarracino f.sarrac...@gmail.com wrote: what I meant refers to the fact that I've read on an R and S-plus companion to applied regression about methods to alter the encoding of factors when using contrasts in regressions. These are options (for contrasts) that can be easily set as option('contrasts'). This command changes the way R creates the dummies out of a factor and various methods are available. I was expecting that R might have had something similar that applied to my case, thus changing the way R attaches numeric values to my dummy variable. I am just surprised that such option doesn't exist. I was having wrong expectations. Such options do exist, but at modelling time, not factor creation/conversion time. When created, by calls to 'factor' or in functions like 'read.table', factors are stored internally as integers with a list of labels (what you see as factor levels) that go with each integer. Those internal integers start at 1 and go up. You can set the ordering of those labels (by specifying the levels argument in factor()) so that, for example, yes and no can be associated with (numeric) factor levels 1 and 2 respectively instead of the default ordering which would put 'no' alphabetically before 'yes'. (I find this choice particularly useful for orderings like high, medium, low for which the alphabetic ordering is not exactly intuitive; similarly alphabetic ordering puts '1', '2', '10' in the order '1', '10', '2' and so on, so that often needs specifying manually. It's also useful to specify levels if you want things like boxplots to come out in a particular order, as boxplots by default use the order of the factor levels). The internal integer values are returned by 'as numeric'. If your factor level labels - which are always character - are also interpretable as numbers, you need 'as.character' to return the character strings and then 'as.numeric' to convert those. Now, up to this point you just have more or less arbitrary integers asociated with the original factor levels (the degree of arbitrariness depends on whether you specified the level order or let R use its default). These integers are not the contrasts used in model fitting. Contrasts are set at model matrix building time; they are not a fixed attribute of the factor. The internal numbering of levels affects contrasts only to the extent that the numerical values used in setting contrasts are usually in the same order as the factor levels. You can inspect the functions used to associate contrasts with factor levels by using options(contrasts). You can inspect the numerical values that would currently be used for a given factor with a call to contrasts(). You can change the contrast asignments globally using options() or explicitly in some model calls (lm, for example, has a contrasts argument) and if you like you can write your own contrast functions to set any values you! like. The most common are probably treatment contrasts, which set the first factor level as intercept and the rest as (unit) differences from that, and sum to zero contrasts which do what they say, setting contrasts that sum to zero by choosing a set like (-1, 0, 1). So you actually have a great deal of control over both the order in which labels are associated with factor levels and the (separate) values of contrasts associated with those factor levels at modelling time. The cost of that control is some complexity, and the time needed to learn what's going on to use it all properly. Hope that helps ... S Ellison *** This email and any attachments are confidential. Any use...{{dropped:8}} __ 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] extracting characters from a string
thanks, it works well. I have to work on Arun's previous answer to make it work too. David De : Rui Barradas ruipbarra...@sapo.pt À : Biau David djmb...@yahoo.fr Cc : r help list r-help@r-project.org Envoyé le : Mercredi 23 janvier 2013 19h57 Objet : Re: [R] extracting characters from a string Hello, I've just noticed that my first solution would only return the first set of alphabetic characters, such as Van, not Van den Hoops. The following will solve that problem. fun2 - function(x, sep = , ){ x - strsplit(x, sep) m - lapply(x, function(y) gregexpr( [[:alpha:]]*$, y)) res - lapply(seq_along(x), function(i) regmatches(x[[i]], m[[i]], invert = TRUE)) res - lapply(res, unlist) lapply(res, function(y) y[nchar(y) 0]) } fun2(pub) Hope this helps, Rui Barradas Em 23-01-2013 18:33, Rui Barradas escreveu: Hello, Try the following. fun - function(x, sep = , ){ s - unlist(strsplit(x, sep)) regmatches(s, regexpr([[:alpha:]]*, s)) } fun(pub) Hope this helps, Rui Barradas Em 23-01-2013 17:38, Biau David escreveu: Dear All, I have a data frame of vectors of publication names such as 'pub': pub1 - c('Brown DK, Santos R, Rome DF, Don Juan X') pub2 - c('Benigni D') pub3 - c('Arstra SD, Van den Hoops DD, lamarque D') pub - rbind(pub1, pub2, pub3) I would like to construct a dataframe with only author's last name and each last name in columns and the publication in rows. Basically I want to get rid of the initials (max 2, always before a comma) and spaces surounding last name. I would like to avoid a loop. ps: If I could have even a short explanation of the code that extract the values of the character string that would also be great! David [[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. [[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] setting off-diagonals to zero
On 24-01-2013, at 01:58, emorway emor...@usgs.gov wrote: I'm not following. Printing SEQ to the screen at the intermediate steps using the following modified R code suggests that 'i' is fine and is not getting reset to 1 as you suggest? You misread. I did not say anything about 'i'. My understanding, or rather my desired output if someone else is able to weight-in, is that the values in the second line of output (731 732 733 etc.) should not be appearing in the 3rd line of output. The third line of output should be missing 731 thru 736. Well then look at this for (i in 731:732) { SEQ - (i - 5):(i + 5) print(SEQ) SEQ - SEQ[SEQ 730 SEQ 1096] print(SEQ) print((731:1095)[-(-730+SEQ)]) # my modification } # [1] 726 727 728 729 730 731 732 733 734 735 736 # [1] 731 732 733 734 735 736 # [1] 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 which seems to give the desired output Any suggestions on how to modify the R code are certainly welcome. Suggested revisions will be substituted back into the third FOR loop in my original post on this thread to prevent the main- and near-main-diagonal terms from being set equal to zero. for (i in 731:732) { SEQ - (i - 5):(i + 5) print(SEQ) SEQ - SEQ[SEQ 730 SEQ 1096] print(SEQ) print((731:1095)[-SEQ]) } # [1] 726 727 728 729 730 731 732 733 734 735 736 # [1] 731 732 733 734 735 736 # [1] 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756... -- View this message in context: http://r.789695.n4.nabble.com/setting-off-diagonals-to-zero-tp4656407p4656461.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] Rcpp wrap and as
Hi, I'm curious about the ability of these two methods to really wrap (I mean as in delegate) the target object instead of deep copying and transforming it to a new structure. First, specifically for vectors. Second, in general (my hunch is that -say- map-env are transformed copies but it's just a guess). Regards, Carlos. [[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] extracting characters from a string
HI David, It could be related to spaces in the data or something else. Suppose, if the data has some spaces at the end or the beginning. pub1 - c('Brown DK, Santos R, Rome DF, Don Juan X') pub2 - c('Benigni D') pub3 - c('Arstra SD, Van den Hoops DD, lamarque D ') pubnew-rbind(pub1, pub2, pub3) res-as.data.frame(do.call(cbind,lapply(dat1,function(x) gsub(^ | $,,gsub([A-Za-z]+$,,gsub( $,,x),stringsAsFactors=F) str(res) #'data.frame': 3 obs. of 4 variables: # $ V1: chr Brown Benigni Arstra # $ V2: chr Santos Van den Hoops # $ V3: chr Rome lamarque # $ V4: chr Don Juan #If I used the previous solution: as.data.frame(do.call(cbind,lapply(dat1,function(x) gsub( $,,gsub(^ |\\w+$,,x,stringsAsFactors=F) V1 V2 V3 V4 1 Brown Santos Rome Don Juan 2 Benigni 3 Arstra Van den Hoops lamarque D # initial present. I tried this case with Rui's solution: fun2(pubnew) #[[1]] #[1] Brown Santos Rome Don Juan #[[2]] #[1] Benigni # #[[3]] #[1] Arstra Van den Hoops lamarque D # tinitials present. As Rui's solution works for you, the problem might be something else. A.K. From: Biau David djmb...@yahoo.fr To: arun smartpink...@yahoo.com Sent: Thursday, January 24, 2013 12:40 AM Subject: Re: [R] extracting characters from a string thanks a lot. it doesn't entirely work well yet; poabably because of the format of the data I import. I have to look into it and thanks to your explanation, I should be able to find the problem in the data. David De : arun smartpink...@yahoo.com À : Biau David djmb...@yahoo.fr Envoyé le : Mercredi 23 janvier 2013 19h06 Objet : Re: [R] extracting characters from a string Hi David, I forgot about the explanation part. dat1-read.table(text=pub,sep=,,fill=TRUE,stringsAsFactors=F) # here, I converted it to dataframe, delimited by ,, Used fill=TRUE because you have unequal number of publications in each line as.data.frame(do.call(cbind,lapply(dat1,function(x) gsub( $,,gsub(^ |\\w+$,,x,stringsAsFactors=F) #splitting codes into smaller pieces; lapply(dat1,function(x) gsub(^ |\\w+$,,x)) #lapply() will ensure that the columns in dataframe are split to list elements. Here, the gsub command within first double quotes matches if there are any empty spaces at the start of the string and also the last word characters in each string and removes them ( 2nd set of double quotes are empty). $V1 [1] Brown Benigni Arstra $V2 [1] Santos Van den Hoops $V3 [1] Rome lamarque $V4 [1] Don Juan lapply(dat1,function(x) gsub( $,,gsub(^ |\\w+$,,x))) # I used a second gsub because there are some spaces at the end e.g. Brown $V1 [1] Brown Benigni Arstra $V2 [1] Santos Van den Hoops $V3 [1] Rome lamarque $V4 [1] Don Juan do.call(cbind,lapply(dat1,function(x) gsub( $,,gsub(^ |\\w+$,,x #bind by columns V1 V2 V3 V4 [1,] Brown Santos Rome Don Juan [2,] Benigni [3,] Arstra Van den Hoops lamarque Hope it helps. A.K. - Original Message - From: Biau David djmb...@yahoo.fr To: r help list r-help@r-project.org Cc: Sent: Wednesday, January 23, 2013 12:38 PM Subject: [R] extracting characters from a string Dear All, I have a data frame of vectors of publication names such as 'pub': pub1 - c('Brown DK, Santos R, Rome DF, Don Juan X') pub2 - c('Benigni D') pub3 - c('Arstra SD, Van den Hoops DD, lamarque D') pub - rbind(pub1, pub2, pub3) I would like to construct a dataframe with only author's last name and each last name in columns and the publication in rows. Basically I want to get rid of the initials (max 2, always before a comma) and spaces surounding last name. I would like to avoid a loop. ps: If I could have even a short explanation of the code that extract the values of the character string that would also be great! David [[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] hologram
Guangzhou Lidun Hologram Co., Ltd. Home|Product|company Profile |Contacts|more DearFriends, Best Wishes For You! Wish you have a good day!We are the major manufacturer and exporter of silicone bracelets and holographic stickers with more than ten years experience in China. Also, custom bracelet and custom packing box are welcomed. Any questions or more information, please let me know. Sincerely hope to find a way to cooperate with your esteemed company. The following are our Products: Hot Product more flag silicone bands bracelet US $ 1.5-2.2/ Piece sports silicone watch US $ 1.3-2/ Piece silicon hologram bracelet US $ 1.4-2/ Piece energy wristband US $ 1.3-2.2/ Piece sport silicone bands/bangles US $ 1.5-2.2/ Piece sport energy bracelet US $ 1.7-2.2/ Piece energy balance bracelets US $ 1.5-2.2/ Piece fashion health bracelet US $ 1.5-2.3/ Piece silicon pet tags US $ 1.5-2.2/ Piece paw shape silicon pet tags US $ 0.4-0.6/ Piece Silicone Dog Tags US $ 0.4-0.6/ Piece fashion pet tags US $ 1.5-2.2/ Piece waterproof hologram sticker US $ 0.001-0.8/ Piece custom hologram Label US $ 0.001-0.08/ Piece hologram stickers US $ 0.001-0.8/ Piece hologram energy bracelet US $ 0.001-0.08/ Piece security barcode labels US $ 0.001-0.008/ Piece water-proof silicone case US $ 1.2-2/ Piece watermark fiber paper US $ 0.11-0.18/ Piece 3D printing paper US $ 0.001-0.08/ Piece Phone No. :020-36199009 WebSite:www.hologramid.cn Email:hologra...@yahoo.cn Address: Room313, Yun Quan Coomerece Centre,No.38,Beizhan Road,Sanyuanli,Baiyun District,Guangzhou,China. [[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.