Re: [R] Code to construct table with paired data
Thank you Peter! Great solutions! That's exactly what I was looking for. Maurício Cardeal Em 08/04/2017 09:11, peter dalgaard escreveu: > Here's one way: > >> ddw <- reshape(dd, direction="wide", idvar="pair", timevar="treatfac") >> names(ddw) > [1] "pair" "imprfac.A" "imprfac.B" >> xtabs(~ imprfac.A + imprfac.B, ddw) > imprfac.B > imprfac.A + - > + 1 3 > - 2 1 > > (reshape() is a bit of a pain to wrap one's mind around; possibly, the > tidyversalists can come up with something easier.) > > With a bit stronger assumptions on the data set (all pairs complete and in > same order for both treatments), there is also > >> table(A=imprfac[treatfac=="A"], B=imprfac[treatfac=="B"]) > B > A + - >+ 1 3 >- 2 1 > > > >> On 08 Apr 2017, at 13:16 , Mauricio Cardeal wrote: >> >> Hi! >> >> Is it possible to automatically construct a table like this: >> >> #treat B >> # improvement >> # + - >> #treat A improvement + 1 3 >> # - 2 1 >> >> From these data: >> >> pair <- c(1,1,2,2,3,3,4,4,5,5,6,6,7,7) # identification >> treat <- c(1,0,1,0,1,0,1,0,1,0,1,0,1,0) # treatament 1 (A) or 0 (B) >> impr <- c(1,0,1,0,1,0,0,1,0,1,0,0,1,1) # improvement 1 (yes) 0 (no) >> >> treatfac <- factor(treat) >> levels(treatfac)<-list("A"=1,"B"=0 ) >> imprfac <- factor(impr) >> levels(imprfac)<-list("+"=1,"-"=0) >> >> data.frame(pair,treatfac,imprfac) >> >> pair treatfac imprfac >> >> 1 1 A + >> 2 1 B - >> 3 2 A + >> 4 2 B - >> 5 3 A + >> 6 3 B - >> 7 4 A - >> 8 4 B + >> 9 5 A - >> 105 B + >> 116 A - >> 126 B - >> 137 A + >> 147 B + >> >> I tried some functions like table or even xtabs, but the results doesn't >> show the pairs combinations. >> >> >> Thanks in advance, >> >> >> Maurício Cardeal >> >> Federal University of Bahia, Brazil >> >> >> >> >> [[alternative HTML version deleted]] >> >> __ >> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see >> 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 -- To UNSUBSCRIBE and more, see 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] change the R home directory
Change to the desired directory before starting R. -- Sent from my phone. Please excuse my brevity. On April 8, 2017 10:40:13 AM PDT, Da Zheng wrote: >Hello, > >By default, the home directory of R is "/usr/lib/R" in Ubuntu. >Everything works fine. > >However, when I installed Jupyter notebook and the R kernel with >anaconda2, it seems the R home directory is changed to some directory >in anaconda2. This messes up compilation and linking. I wonder how I >change the R home directory back to the default directory. > >I tried to set R_HOME directly, When I start R, I see a warning >message: >WARNING: ignoring environment value of R_HOME > >I don't understand why R wants to ignore the environment value. >Of course, the R home directory isn't changed. >> R.home() >[1] "/home/zhengda/anaconda2/lib/R" > >What is the right way of changing the R home directory? > >Thanks, >Da > >__ >R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see >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 -- To UNSUBSCRIBE and more, see 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] change the R home directory
Hello, By default, the home directory of R is "/usr/lib/R" in Ubuntu. Everything works fine. However, when I installed Jupyter notebook and the R kernel with anaconda2, it seems the R home directory is changed to some directory in anaconda2. This messes up compilation and linking. I wonder how I change the R home directory back to the default directory. I tried to set R_HOME directly, When I start R, I see a warning message: WARNING: ignoring environment value of R_HOME I don't understand why R wants to ignore the environment value. Of course, the R home directory isn't changed. > R.home() [1] "/home/zhengda/anaconda2/lib/R" What is the right way of changing the R home directory? Thanks, Da __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see 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] difference metric info of same font on different device
On 2017/4/7 23:13, Jeff Newmiller wrote: I think it is a fundamental characteristic of graphics drivers that output will look different in the details... you are on a wild goose chase. Postscript in particular has a huge advantage in font presentation over other graphics output mechanisms. I agreed with your opinion on Postscript. However, as shown in the attached plots in previous post, the glyph metric info for any CID-keyed font is based on assumption in R. In fact, it's not possible to get the metric info of a CID-keyed font without accessing the actual font which may be in truetype or opentype/CFF format. And, I don't think R could find the actual font. Best, Jinsong __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see 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] difference metric info of same font on different device
On 2017/4/7 23:13, Jeff Newmiller wrote: I think it is a fundamental characteristic of graphics drivers that output will look different in the details... you are on a wild goose chase. Postscript in particular has a huge advantage in font presentation over other graphics output mechanisms. Well, the problem stems from the MetricInfo of CID-keyed fonts, which are intended only for use for the glyphs of East Asian languages, which are all monospaced and are all treated as filling the same bounding box. (from the help page of CIDFont) However, is it possible to use the same MetricInfo of CID-keyed fonts as that for png() or windows()? Best, Jinsong __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see 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] Paired sample t-test with mi.t.test
Dear Dr. Eichner and Dr. Kohl, First, thank you for your response. I tried your code and R it worked perfectly I just had to add: mi.t.test(implist*$imputation,* "pre_test", "post_test", alternative = "greater", paired = TRUE, var.equal = TRUE, conf.level = 0.95) for the code to run. Thank you very much again for taking the time. Best, Joel On Fri, Apr 7, 2017 at 3:26 PM, Prof. Dr. Matthias Kohl < matthias.k...@stamats.de> wrote: > Dear Joel, > > are you trying to apply function mi.t.test from my package MKmisc? > > Could you please try: > mi.t.test(implist, "pre_test", "post_test", alternative = > "greater", paired = TRUE, var.equal = TRUE, conf.level = 0.95) > > x and y are the names of the variables, not the variables themselves. > > Best > Matthias > > Am 06.04.2017 um 18:32 schrieb Joel Gagnon: > >> Dear all, >> >> It is my first time posting on this list so forgive me for any rookie >> mistakes I could make. >> >> I want to conduct t-tests on a dataset that has been imputed using the >> mice >> package: >> imput_pps <- mice(pps, m=20, maxit=20, meth='pmm') # pps is my dataset. It >> contains items from an 11-item questionnaire gather at pre and post test. >> So the data set has 22 columns. >> >> I then proceed to compute the total scores for the pre and post test on my >> imputed datasets: >> >> long_pps <- complete(imput_pps, action ="long", include = TRUE) >> long_pps$pre_test <- rowSums(long_pps[ ,c(3:13)]) >> long_pps$post_test <- rowSums(long_pps[ , c(14:24)]) >> >> I then used as.mids to convert back to mids object: >> mids_pps <- as.mids(long_pps) >> >> Next, I created an imputation list object using mitools: >> implist <- lapply(seq(mids_pps$m), function(im) complete(mids_pps, im)) >> implist <- imputationList(implist) >> >> Now, I want to conduct t-tests using the mi.t.test package. I tried the >> following code: >> mi.t.test(implist, implist$pre_test, implist$post_test, alternative = >> "greater", paired = TRUE, var.equal = TRUE, conf.level = 0.95) >> >> When I run this code, R tells me that Y is missing. I know this may sound >> stupid, but I thought that I specified Y with this line: implist$pre_test, >> implist$post_test - with implist$pre_test being X and implist$post_test >> being Y - like I usually do for a normal t-test using the t.test function. >> >> It seems I don't quite understand what the Y variable is supposed to >> represent. Could someone help me figure out what I am doing wrong? You >> help would be very much appreciated. >> >> Best regards, >> >> Joel Gagnon, Ph.D(c), >> Department of Psychology, >> Université du Québec à Trois-Rivières >> Québec, Canada >> >> [[alternative HTML version deleted]] >> >> __ >> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see >> https://stat.ethz.ch/mailman/listinfo/r-help >> PLEASE do read the posting guide http://www.R-project.org/posti >> ng-guide.html >> and provide commented, minimal, self-contained, reproducible code. >> >> > -- > Prof. Dr. Matthias Kohl > www.stamats.de > [[alternative HTML version deleted]] __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see 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] mgcv gam/bam model selection with random effects and AR terms
Would be grateful for advice on gam/bam model selection incorporating random effects and autoregressive terms. I have a multivariate time series recorded on ~500 subjects at ~100 time points. One of the variables (A) is the dependent and four others (B to E) are predictors. My basic formula is: [model 1]: bam(A ~ s(time)+s(B)+s(C)+s(D)+s(E)) I've then included a random intercept and a random effect for time as the pattern of A over time is highly variable across subjects. [model 2]: bam(A ~ s(time)+s(B)+s(C)+s(D)+s(E)+s(id, bs='re')+s(id,time, bs='re')) I expect there is also potential for autocorrelation within the time series. So: [model 3]: bam(A ~ s(time)+s(B)+s(C)+s(D)+s(E)+s(id, bs='re')+s(id,time, bs='re'), AR.start = startindex, rho = 0.52) The rho value of 0.52 was settled on by trial-and-error minimising fREML/ML (side question: am I correct in understanding that bam can only use a fixed rho rather than taking this as a value to optimise as in gamm?) The lowest fREML or ML values are obtained by model 3 (71674 vs 72099) for model 2) but the highest adjusted R2/deviance explained is with model 2 (37.7 vs 42.1%). Model 1 is inferior to both the others on all measures. Is it better to select the model including the AR term given the lower ML or is it legitimate to go with the 'simpler' model 2 that has higher R2/deviance explained? I am unable to provide a fully reproducible example as I don't know how to generate sample data with these specific characteristics. Many thanks __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see 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] Code to construct table with paired data
Here's one way: > ddw <- reshape(dd, direction="wide", idvar="pair", timevar="treatfac") > names(ddw) [1] "pair" "imprfac.A" "imprfac.B" > xtabs(~ imprfac.A + imprfac.B, ddw) imprfac.B imprfac.A + - + 1 3 - 2 1 (reshape() is a bit of a pain to wrap one's mind around; possibly, the tidyversalists can come up with something easier.) With a bit stronger assumptions on the data set (all pairs complete and in same order for both treatments), there is also > table(A=imprfac[treatfac=="A"], B=imprfac[treatfac=="B"]) B A + - + 1 3 - 2 1 > On 08 Apr 2017, at 13:16 , Mauricio Cardeal wrote: > > Hi! > > Is it possible to automatically construct a table like this: > > #treat B > # improvement > # + - > #treat A improvement + 1 3 > # - 2 1 > > From these data: > > pair <- c(1,1,2,2,3,3,4,4,5,5,6,6,7,7) # identification > treat <- c(1,0,1,0,1,0,1,0,1,0,1,0,1,0) # treatament 1 (A) or 0 (B) > impr <- c(1,0,1,0,1,0,0,1,0,1,0,0,1,1) # improvement 1 (yes) 0 (no) > > treatfac <- factor(treat) > levels(treatfac)<-list("A"=1,"B"=0 ) > imprfac <- factor(impr) > levels(imprfac)<-list("+"=1,"-"=0) > > data.frame(pair,treatfac,imprfac) > >pair treatfac imprfac > > 1 1 A + > 2 1 B - > 3 2 A + > 4 2 B - > 5 3 A + > 6 3 B - > 7 4 A - > 8 4 B + > 9 5 A - > 105 B + > 116 A - > 126 B - > 137 A + > 147 B + > > I tried some functions like table or even xtabs, but the results doesn't > show the pairs combinations. > > > Thanks in advance, > > > Maurício Cardeal > > Federal University of Bahia, Brazil > > > > > [[alternative HTML version deleted]] > > __ > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see > 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. -- Peter Dalgaard, Professor, Center for Statistics, Copenhagen Business School Solbjerg Plads 3, 2000 Frederiksberg, Denmark Phone: (+45)38153501 Office: A 4.23 Email: pd@cbs.dk Priv: pda...@gmail.com __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see 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] Code to construct table with paired data
Hi! Is it possible to automatically construct a table like this: #treat B # improvement # + - #treat A improvement + 1 3 # - 2 1 From these data: pair <- c(1,1,2,2,3,3,4,4,5,5,6,6,7,7) # identification treat <- c(1,0,1,0,1,0,1,0,1,0,1,0,1,0) # treatament 1 (A) or 0 (B) impr <- c(1,0,1,0,1,0,0,1,0,1,0,0,1,1) # improvement 1 (yes) 0 (no) treatfac <- factor(treat) levels(treatfac)<-list("A"=1,"B"=0 ) imprfac <- factor(impr) levels(imprfac)<-list("+"=1,"-"=0) data.frame(pair,treatfac,imprfac) pair treatfac imprfac 1 1 A + 2 1 B - 3 2 A + 4 2 B - 5 3 A + 6 3 B - 7 4 A - 8 4 B + 9 5 A - 105 B + 116 A - 126 B - 137 A + 147 B + I tried some functions like table or even xtabs, but the results doesn't show the pairs combinations. Thanks in advance, Maurício Cardeal Federal University of Bahia, Brazil [[alternative HTML version deleted]] __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see 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] Archive format
Hi Joe, I have read your question with great interest. I am a little bit astonished to read about your project. There is a big national institute in Germany called GESIS (https://de.wikipedia.org/wiki/GESIS_%E2%80%93_Leibniz-Institut_f%C3%BCr_Sozialwissenschaften) which does the same job you are trying to set-up since 1986 now. You could try to exchange ideas with them. Your subject is very complex with regard to reproducible research. You might want to have a look at (1) https://cran.r-project.org/web/views/ReproducibleResearch.html (2) Gandrud, Christopher: Reproducible Research with R and R Studio (https://www.amazon.com/Reproducible-Research-Studio-Second-Chapman/dp/1498715370) Kind regards Georg > Gesendet: Mittwoch, 29. März 2017 um 10:44 Uhr > Von: "Joe Gain" > An: R-help@r-project.org > Cc: bwfdm-i...@lists.kit.edu > Betreff: [R] Archive format > > Hello, > > we are collecting information on the subject of research data management > in German on the webplatform: > > www.forschungsdaten.info > > One of the topics, which we are writing about, is how to *archive* data. > Unfortunately, none of us in the project is an expert with respect to R > and so I would like to ask the list, what they recommend? A related > question is to do with the sharing of data. We have already asked some > academics, who have basically replied that they don't really know other > than to strongly recommend a plain text format. > > We would also like to know, if members of the list recommend converting > formats from commercial software such as S-Plus, Terr, SPSS etc. to an > R-compatible format for long term archivation? Are there any general > rules and best practices, when it comes to archiving (and sharing) > statistical data and statistical programs? > > Any comments would be much appreciated! > Joe > > -- > B 1003 > Kommunikations-, Informations-, Medienzentrum (KIM) > Universitaet Konstanz > > t: ++49-7531-883234 > e: joe.g...@uni-konstanz.de > > __ > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see > 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 -- To UNSUBSCRIBE and more, see 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.