Re: [R] How to create a table with borders?
Thanks arun, But what is the alternative solution in windows. Please reply me. -- View this message in context: http://r.789695.n4.nabble.com/How-to-create-a-table-with-borders-tp4645470p4645527.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] car::linearHypothesis Sum of Sqaures Error?
I am working with a RCB 2x2x3 ANCOVA, and I have noticed a difference in the calculation of sum of squares in a Type III calculation. Anova output is a follows: Anova(aov(MSOIL~Forest+Burn*Thin*Moisture+ROCK,data=env3l),type=3) Anova Table (Type III tests) Response: MSOIL Sum Sq Df F valuePr(F) (Intercept)22.3682 1 53.2141 3.499e-07 *** Forest 1.0954 2 1.3029 0.29282 Burn2.6926 1 6.4058 0.01943 * Thin0.0494 1 0.1176 0.73503 Moisture1.2597 2 1.4984 0.24644 ROCK2.1908 1 5.2119 0.03296 * Burn:Thin 0.2002 1 0.4764 0.49763 Burn:Moisture 1.0612 2 1.2623 0.30360 Thin:Moisture 1.6590 2 1.9734 0.16392 Burn:Thin:Moisture 1.1175 2 1.3292 0.28605 Residuals 8.8272 21 However, I would like to calculate some a priori contrasts within the Moisture factor as follows: Transect_moisture_contrasts-matrix(c(-1,2,-1,1,0,-1),3,2) dimnames(Transect_moisture_contrasts)-list(levels(env$Moisture),c(I vs. XM,X vs. M)) contrasts(env$Moisture)-Transect_moisture_contrasts contrasts(env3l$Moisture) I vs. XM X vs. M X-1 1 I 2 0 M-1 -1 soilmodel-lm(MSOIL~Forest+Burn*Thin*Moisture+ROCK,data=env3l) linearHypothesis(soilmodel,MoistureI vs. XM) Linear hypothesis test Hypothesis: MoistureI vs. XM = 0 Model 1: restricted model Model 2: MSOIL ~ Forest + Burn * Thin * Moisture + ROCK Res.DfRSS Df Sum of Sq F Pr(F) 1 22 9.4106 2 21 8.8272 1 0.58333 1.3877 0.252 linearHypothesis(soilmodel,MoistureX vs. M) Linear hypothesis test Hypothesis: MoistureX vs. M = 0 Model 1: restricted model Model 2: MSOIL ~ Forest + Burn * Thin * Moisture + ROCK Res.DfRSS Df Sum of Sq F Pr(F) 1 22 9.6359 2 21 8.8272 1 0.80871 1.9239 0.18 The sum of squares for these two contrasts do not add up to the sum of squares of the main effect Moisture .80871+.58333 [1] 1.39204 1.39204-1.2596 [1] 0.13244 Checking them together produces the correct sum of squares for the main effect linearHypothesis(soilmodel,c(MoistureI vs. XM,MoistureX vs. M)) Linear hypothesis test Hypothesis: MoistureI vs. XM = 0 MoistureX vs. M = 0 Model 1: restricted model Model 2: MSOIL ~ Forest + Burn * Thin * Moisture + ROCK Res.Df RSS Df Sum of Sq F Pr(F) 1 23 10.0869 2 21 8.8272 21.2596 1.4984 0.2464 So my question is: Should the sum of squares for the two contrasts add to the main effect here? If they should, maybe we can figure out why mine do not. Thanks in advance for any assistance. Cheers, John John J. Wiley, Jr. PhD Candidate State University of New York College of Environmental Science and Forestry Department of Environmental and Forest Biology 460 Illick Hall Syracuse, NY 13210 315.470.4825 (office) 740.590.6121 (cell) [[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] simulating a toss of a coin
All, I've devised a way to toss a coin three times and record the number of heads, then use the table command to summarize the number of time 0, 1, 2, or 3 heads were obtained. n - 100 x - sample(c(H,T),3*n,replace=TRUE) dim(x) - c(3,n) num_heads - apply(x,2,function(x) sum(x==H)) table(num_heads)/n What I'd like to do next is run this code 10 times, and gather the results in a matrix with 10 rows and 4 columns, where the first row records the output of the first run of the above code, the second row records the second run of the above code, etc. Looking for some simple ideas on how to accomplish this. Thanks. David __ 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] Error in lmer: asMethod(object) : matrix is not symmetric [1, 2]
Yes, that was what I was trying to do. Thank you very much for your reply! Olivier -- View this message in context: http://r.789695.n4.nabble.com/Error-in-lmer-asMethod-object-matrix-is-not-symmetric-1-2-tp4645133p4645537.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] simulating a toss of a coin
On Tue, Oct 9, 2012 at 6:04 AM, David Arnold dwarnol...@suddenlink.net wrote: All, I've devised a way to toss a coin three times and record the number of heads, then use the table command to summarize the number of time 0, 1, 2, or 3 heads were obtained. n - 100 x - sample(c(H,T),3*n,replace=TRUE) dim(x) - c(3,n) num_heads - apply(x,2,function(x) sum(x==H)) table(num_heads)/n What I'd like to do next is run this code 10 times, and gather the results in a matrix with 10 rows and 4 columns, where the first row records the output of the first run of the above code, the second row records the second run of the above code, etc. Looking for some simple ideas on how to accomplish this. Thanks. David Hi David, This is that wonderful smell of homework in the morning, so I can't really say too much in good conscience, but I think you are looking for ?replicate Cheers, Michael __ 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 create a table with borders?
Hello, Why not use package xtable? I've just tried the following. #install.packages('xtable') library(xtable) x - 1:20 y - 0.5*x + rnorm(20) fit - aov(y ~ x) latex.tbl - xtable(fit) align(latex.tbl) - |lr| print(latex.tbl) The output was % latex table generated in R 2.15.1 by xtable 1.7-0 package % Tue Oct 09 08:12:33 2012 \begin{table}[ht] \begin{center} \begin{tabular}{|lr|} \hline Df Sum Sq Mean Sq F value Pr($$F) \\ \hline x 1 191.80 191.80 208.27 0. \\ Residuals 18 16.58 0.92 \\ \hline \end{tabular} \end{center} \end{table} Hope this helps, Rui Barradas Em 09-10-2012 04:47, killerkarthick escreveu: Thanks arun, But what is the alternative solution in windows. Please reply me. -- View this message in context: http://r.789695.n4.nabble.com/How-to-create-a-table-with-borders-tp4645470p4645527.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] simulating a toss of a coin
Hello, Try the following. fun - function(n = 100){ x - sample(c(H,T),3*n,replace=TRUE) dim(x) - c(3,n) num_heads - apply(x,2,function(x) sum(x==H)) table(num_heads)/n } Runs - 1e1 t(replicate(Runs, fun())) Hope this helps, Rui Barradas Em 09-10-2012 06:04, David Arnold escreveu: All, I've devised a way to toss a coin three times and record the number of heads, then use the table command to summarize the number of time 0, 1, 2, or 3 heads were obtained. n - 100 x - sample(c(H,T),3*n,replace=TRUE) dim(x) - c(3,n) num_heads - apply(x,2,function(x) sum(x==H)) table(num_heads)/n What I'd like to do next is run this code 10 times, and gather the results in a matrix with 10 rows and 4 columns, where the first row records the output of the first run of the above code, the second row records the second run of the above code, etc. Looking for some simple ideas on how to accomplish this. Thanks. David __ 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] Diagnostic testing in a VEC
Hello Laura, you convert your VEC model to its levl-VAR representation and employ the diagnostic tests you mentioned. This can be accomplished with the functions/methods contained in the package 'vars'. You might want to have a look at the vignette of the latter package. Best, Bernhard -Ursprüngliche Nachricht- Von: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] Im Auftrag von Laura Catalina Echeverri Guzmán Gesendet: Montag, 8. Oktober 2012 17:34 An: r-help@r-project.org Betreff: [R] Diagnostic testing in a VEC Hi everyone, I'm using the Johansen framework to determine a VEC using package urca. I have estimated the corresponding VEC using likelihood ratio test for restrictions on alpha, beta or both and I have generated objects of the class cajo.test. Now I want to diagnostic tests in the model, like heteroskedasticity test, residuals normality and serial autocorrelation, but I cannot find the way to do it in objects like the one I have. How can I do it? what packages/methods I may use? Do I have to transform this object in other object to do it easily? I would appreciate if someone could help me with this issue. Thank you! -- Laura Catalina Echeverri Guzmán [[alternative HTML version deleted]] * Confidentiality Note: The information contained in this ...{{dropped:10}} __ 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] Modern Symbolic debugger for R programmes?
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 On 09/10/12 06:12, Worik R wrote: I think I am whistling in the wind, but is there a modern symbolic debugger for R programmes? I am working through some one else's code, thousands of lines, that has the occasional bug in it, and a lot in my understanding of it. I cannot make setBreakpoint or findLineNum work. I get No source refs found.. I am starting to loose my mind! A debugger where I could set breakpoints with a little more granularity than the function level and a little more accessible than the trace function. What I ideally want is GDB for R. Does that exist? There is quite some debugging fuctionality available in ESS for emacs (http://ess.r-project.org/) and I rmrmber a presentation at useR in 2011 that there is as well in eclipse, but there you have to used,. as far as I remember, a patched version of R. So I would suggest to look into ESS for a debugger. Cheers, Rainer cheers Worik -BEGIN PGP SIGNATURE- Version: GnuPG v1.4.11 (GNU/Linux) Comment: Using GnuPG with Mozilla - http://www.enigmail.net/ iEYEARECAAYFAlBz1UwACgkQoYgNqgF2egokDwCeKd/87kM8P3YGRm/au783y1DX StwAn04wmEbH9P0FuaWHZ72fBK8BODJV =OMlj -END 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] Modern Symbolic debugger for R programmes?
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 On 09/10/12 09:42, Rainer M Krug wrote: On 09/10/12 06:12, Worik R wrote: I think I am whistling in the wind, but is there a modern symbolic debugger for R programmes? I am working through some one else's code, thousands of lines, that has the occasional bug in it, and a lot in my understanding of it. I cannot make setBreakpoint or findLineNum work. I get No source refs found.. I am starting to loose my mind! A debugger where I could set breakpoints with a little more granularity than the function level and a little more accessible than the trace function. What I ideally want is GDB for R. Does that exist? There is quite some debugging fuctionality available in ESS for emacs (http://ess.r-project.org/) and I rmrmber a presentation at useR in 2011 that there is as well in eclipse, but there you have to used,. as far as I remember, a patched version of R. So I would suggest to look into ESS for a debugger. Just found http://stackoverflow.com/questions/2854820/statet-debugging-tool and http://www.walware.de/?page=/it/downloads/statet.mframe Cheers, Rainer Cheers, Rainer cheers Worik - -- Rainer M. Krug, PhD (Conservation Ecology, SUN), MSc (Conservation Biology, UCT), Dipl. Phys. (Germany) Centre of Excellence for Invasion Biology Stellenbosch University South Africa Tel : +33 - (0)9 53 10 27 44 Cell: +33 - (0)6 85 62 59 98 Fax : +33 - (0)9 58 10 27 44 Fax (D):+49 - (0)3 21 21 25 22 44 email: rai...@krugs.de Skype: RMkrug -BEGIN PGP SIGNATURE- Version: GnuPG v1.4.11 (GNU/Linux) Comment: Using GnuPG with Mozilla - http://www.enigmail.net/ iEYEARECAAYFAlBz1hwACgkQoYgNqgF2egqqXwCfd1YhQTNywjJH96cvgzXoZ0Lx 6voAn33G6NuA7YBIOdypVgOKIY+peiA1 =NBYG -END 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.
[R] multinomial MCMCglmm
Dear all, I would like to add mixed effects in a multinomial model and I am trying to use MCMCglmm for that. The main problem I face: my data set is a trapping data set, where the observation at each trap (1 or 0 for several species) have been aggregated per trapline (i.e. 25 traps). Therefore we have a proportion of presence/absence for each species per trapline. ex: ID_line mesh habitat Apsy Mygl Crle Crru Miag Miar Mimi Mumu Misu Soar Somi 11 028S6A 28 copse200000000 00 12 028S6B 28 copse110000000 00 13 028S6C 28 hedge200400000 00 14 028S6D 28 hedge100700001 00 15 028S6E 28 hedge700100000 00 empty 1128 1228 1324 1421 1522 When I run the following: test1 - MCMCglmm(fixed=cbind(Apsy,Mygl,Crle,Crru,Miag,Miar,Mimi,Mumu,Misu,Soar,Somi,empty)~habitat,random=~mesh,family=multinomial12,data=metalSmA[,c(2,9,23:34)],rcov=~us(trait):units) I got some error concerning the variance structure: ill-conditioned G/R structure: use proper priors if you haven't or rescale data if you have I guess that the problem comes from the nature of my observations which are frequencies instead of 0/1 per unit Does someone know if a multinomial model fitted with MCMCglmm can handle those frequencies table and how to specify the good G/R variance structures? Regards Amélie Vaniscotte [[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] Update CSV file content
On 10/08/2012 08:20 PM, Rantony wrote: Hi, Here i have a csv file, it contain like this NAME UPDATED - -- ABCINDIA XYZ UK My requirement what is, i need to change the value inside the csv file (instead of INDIA i need to make it USA). NAME UPDATED - -- ABCUSA XYZ UK How can we update by writing into the csv file ? i dont want to delete entire data and write data from dataframe into csv - like that. I need direct file update ! Hi Antony, If it's a small CSV file, you can just alter it in a text editor. Otherwise, that's what spreadsheets are for. Jim __ 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] ylim with only one value specified
Dear R developers, I would like to have R choose the limits of the y-axis semi-automatically, e.g., zero should be included, but the maximum should be chosen depending on the data. Examples: plot(1:10, 1:10) # selects min and max automatically plot(1:10, 1:10, ylim=c(1, 10)) # manual definition plot(1:10, 1:10, ylim=c(0, Inf)) # this would be a nice feature, i.e. lower y limit = 0 defined manually, upper limit = 10 selected automatically The relevant code from plot.default would have to be modified: old: ylim - if (is.null(ylim)) range(xy$y[is.finite(xy$y)]) else ylim new: ylim - if (is.null(ylim)) range(xy$y[is.finite(xy$y)]) else if(length(ylim) == 2 ylim[2] == Inf) c(ylim[1], max(xy$y[is.finite(xy$y)]) else ylim and some more if-else statements if cases like ylim=c(0, -Inf), ylim=c(Inf, 0), ylim=c(-Inf, 0) and ylim=c(-Inf, Inf)[as a replacement for NULL/ autoselection] and ylim=c(Inf, -Inf)[autoselection, reversed y axis] should be handled correctly. I would find such a feature useful. Do you think it would interfere with other functions? Thank you for your consideration. Best wishes, Matthias Gondan __ 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] Modern Symbolic debugger for R programmes?
On 12-10-09 12:12 AM, Worik R wrote: I think I am whistling in the wind, but is there a modern symbolic debugger for R programmes? I am working through some one else's code, thousands of lines, that has the occasional bug in it, and a lot in my understanding of it. I cannot make setBreakpoint or findLineNum work. I get No source refs found.. I am starting to loose my mind! You need to source the code with source references. That is the default for source(), but not for package installation. Set env variable R_KEEP_PKG_SOURCE=yes for command line installs; option(keep.source.pkgs=TRUE) for installs from within R. Then you need to tell setBreakpoint where to look, through the envir arg. See the 2nd example in the help page. A debugger where I could set breakpoints with a little more granularity than the function level and a little more accessible than the trace function. What I ideally want is GDB for R. I thought you said you wanted a modern debugger :-). GDB is very 80ish. I'm unaware of any debuggers that I would consider modern, i.e. like the debuggers from the 90s, but there are a number of pre-modern choices that others have mentioned, and I don't think anyone has mentioned the debug package. Duncan Murdoch __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] ylim with only one value specified
On Tue, Oct 9, 2012 at 10:28 AM, Matthias Gondan matthias-gon...@gmx.de wrote: Dear R developers, I would like to have R choose the limits of the y-axis semi-automatically, e.g., zero should be included, but the maximum should be chosen depending on the data. Examples: plot(1:10, 1:10) # selects min and max automatically plot(1:10, 1:10, ylim=c(1, 10)) # manual definition plot(1:10, 1:10, ylim=c(0, Inf)) # this would be a nice feature, i.e. lower y limit = 0 defined manually, upper limit = 10 selected automatically The relevant code from plot.default would have to be modified: old: ylim - if (is.null(ylim)) range(xy$y[is.finite(xy$y)]) else ylim new: ylim - if (is.null(ylim)) range(xy$y[is.finite(xy$y)]) else if(length(ylim) == 2 ylim[2] == Inf) c(ylim[1], max(xy$y[is.finite(xy$y)]) else ylim and some more if-else statements if cases like ylim=c(0, -Inf), ylim=c(Inf, 0), ylim=c(-Inf, 0) and ylim=c(-Inf, Inf)[as a replacement for NULL/ autoselection] and ylim=c(Inf, -Inf)[autoselection, reversed y axis] should be handled correctly. I would find such a feature useful. Do you think it would interfere with other functions? Thank you for your consideration. Best wishes, I remember this being discussed not too long ago, but I don't remember the conclusion of that thread. My vote at the time (I might not have voiced it) would be to have NA rather than Inf for the 'magic' limits, but this doesn't allow your reversed-axis option. Cheers, Michael Matthias Gondan __ 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] car::linearHypothesis Sum of Sqaures Error?
Dear John On Tue, 9 Oct 2012 02:07:07 + John Jay Wiley Jr. jwile...@syr.edu wrote: I am working with a RCB 2x2x3 ANCOVA, and I have noticed a difference in the calculation of sum of squares in a Type III calculation. For type III tests, you should use contrasts that are orthogonal in the row basis of the design. Perhaps you've done that (by setting the contrasts for the factors directly), but I suspect not. Why not just use type II tests? They're hard to screw up. As well, I assume that the variables that enter additively are the covariates. If not, and a covariate is involved in the interaction, the type III tests aren't sensible unless the 0 point of the covariate is where you want to test a main effect or lower-order interaction. Anova output is a follows: Anova(aov(MSOIL~Forest+Burn*Thin*Moisture+ROCK,data=env3l),type=3) Anova Table (Type III tests) Response: MSOIL Sum Sq Df F valuePr(F) (Intercept)22.3682 1 53.2141 3.499e-07 *** Forest 1.0954 2 1.3029 0.29282 Burn2.6926 1 6.4058 0.01943 * Thin0.0494 1 0.1176 0.73503 Moisture1.2597 2 1.4984 0.24644 ROCK2.1908 1 5.2119 0.03296 * Burn:Thin 0.2002 1 0.4764 0.49763 Burn:Moisture 1.0612 2 1.2623 0.30360 Thin:Moisture 1.6590 2 1.9734 0.16392 Burn:Thin:Moisture 1.1175 2 1.3292 0.28605 Residuals 8.8272 21 However, I would like to calculate some a priori contrasts within the Moisture factor as follows: Transect_moisture_contrasts-matrix(c(-1,2,-1,1,0,-1),3,2) dimnames(Transect_moisture_contrasts)-list(levels(env$Moisture),c(I vs. XM,X vs. M)) contrasts(env$Moisture)-Transect_moisture_contrasts contrasts(env3l$Moisture) I vs. XM X vs. M X-1 1 I 2 0 M-1 -1 soilmodel-lm(MSOIL~Forest+Burn*Thin*Moisture+ROCK,data=env3l) linearHypothesis(soilmodel,MoistureI vs. XM) Linear hypothesis test Hypothesis: MoistureI vs. XM = 0 Model 1: restricted model Model 2: MSOIL ~ Forest + Burn * Thin * Moisture + ROCK Res.DfRSS Df Sum of Sq F Pr(F) 1 22 9.4106 2 21 8.8272 1 0.58333 1.3877 0.252 linearHypothesis(soilmodel,MoistureX vs. M) Linear hypothesis test Hypothesis: MoistureX vs. M = 0 Model 1: restricted model Model 2: MSOIL ~ Forest + Burn * Thin * Moisture + ROCK Res.DfRSS Df Sum of Sq F Pr(F) 1 22 9.6359 2 21 8.8272 1 0.80871 1.9239 0.18 The sum of squares for these two contrasts do not add up to the sum of squares of the main effect Moisture .80871+.58333 [1] 1.39204 1.39204-1.2596 [1] 0.13244 Checking them together produces the correct sum of squares for the main effect linearHypothesis(soilmodel,c(MoistureI vs. XM,MoistureX vs. M)) Linear hypothesis test Hypothesis: MoistureI vs. XM = 0 MoistureX vs. M = 0 Model 1: restricted model Model 2: MSOIL ~ Forest + Burn * Thin * Moisture + ROCK Res.Df RSS Df Sum of Sq F Pr(F) 1 23 10.0869 2 21 8.8272 21.2596 1.4984 0.2464 So my question is: Should the sum of squares for the two contrasts add to the main effect here? Only if the data are balanced. I hope this helps, John John Fox Sen. William McMaster Prof. of Social Statistics Department of Sociology McMaster University Hamilton, Ontario, Canada http://socserv.mcmaster.ca/jfox/ If they should, maybe we can figure out why mine do not. Thanks in advance for any assistance. Cheers, John John J. Wiley, Jr. PhD Candidate State University of New York College of Environmental Science and Forestry Department of Environmental and Forest Biology 460 Illick Hall Syracuse, NY 13210 315.470.4825 (office) 740.590.6121 (cell) [[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] Convert COLON separated format
If you want something that is fast, read the file in, strip off the colon/data, write it out to a temp and then read it back in. Here is a 355K line file: temp - tempfile() input - readLines('/temp/colon.txt') length(input) [1] 355212 system.time(input - gsub((:[0-9]+), , input)) user system elapsed 0.720.000.74 head(input) [1] 1 5 27 345 1 5 27 345 1 5 27 345 1 5 27 345 1 5 27 345 1 5 27 345 writeLines(input, temp) system.time(newInput - read.table(temp)) user system elapsed 1.080.021.13 dim(newInput) [1] 355212 4 head(newInput) V1 V2 V3 V4 1 1 5 27 345 2 1 5 27 345 3 1 5 27 345 4 1 5 27 345 5 1 5 27 345 6 1 5 27 345 On Tue, Oct 9, 2012 at 12:56 AM, Noah Silverman noahsilver...@ucla.edu wrote: I have a bunch of data sets that were created for the libsvm tool. They are in colon separated sparse format. i.e. 1 5:1 27:3 345:10 Is a row with the label of 1 and only has values in columns 5, 27, and 345. I want to read these into a data.frame in R. Is there a simple way to do this? -- Noah Silverman, M.S. UCLA Department of Statistics 8117 Math Sciences Building Los Angeles, CA 90095 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Jim Holtman Data Munger Guru What is the problem that you are trying to solve? Tell me what you want to do, not how you want to do it. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] other way of making a table?
I'm making tables for prediction results of classifiers (2 classes) that show the usual numbers, true positives, false positives, etc I used the command table(predictedLabels,realLabels) to make those. I just had a case though ,where one of the label vectors had only one class in it. This will result in only half a table. Compare: x-c(1,1,1,0,0) y-c(1,1,1,0,1) table(x,y) to x-c(1,1,1,0,0) y-c(1,1,1,1,1) table(x,y) I want the second one to still have all 4 cases (second column all zeros then). Any easy solutions? __ 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 create a table with borders?
HI Rui, Thanks for the alternate method. I guess OP had trouble with pdflatex processing (output of latex(tab)) to create the table. A.K. - Original Message - From: Rui Barradas ruipbarra...@sapo.pt To: killerkarthick karthick@gmail.com Cc: r-help@r-project.org Sent: Tuesday, October 9, 2012 3:15 AM Subject: Re: [R] How to create a table with borders? Hello, Why not use package xtable? I've just tried the following. #install.packages('xtable') library(xtable) x - 1:20 y - 0.5*x + rnorm(20) fit - aov(y ~ x) latex.tbl - xtable(fit) align(latex.tbl) - |lr| print(latex.tbl) The output was % latex table generated in R 2.15.1 by xtable 1.7-0 package % Tue Oct 09 08:12:33 2012 \begin{table}[ht] \begin{center} \begin{tabular}{|lr|} \hline Df Sum Sq Mean Sq F value Pr($$F) \\ \hline x 1 191.80 191.80 208.27 0. \\ Residuals 18 16.58 0.92 \\ \hline \end{tabular} \end{center} \end{table} Hope this helps, Rui Barradas Em 09-10-2012 04:47, killerkarthick escreveu: Thanks arun, But what is the alternative solution in windows. Please reply me. -- View this message in context: http://r.789695.n4.nabble.com/How-to-create-a-table-with-borders-tp4645470p4645527.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-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] Text file: multiple matrix
Hi there! I'm a newbie in R This is my problem: I have a txt file composed by 100 matrix (256x256) separated by a blank line! How can I save automatically the matrix in separated txt file (100)? e.g. 1° matrix from line 1 to line 256 257 blank line 2°matrix from line 258 to line 513 514 blank line 3° matrix from line 515 to line 770 771 blank line 4° matrix from line 772 to line 1027.. Thanks -- View this message in context: http://r.789695.n4.nabble.com/Text-file-multiple-matrix-tp4645551.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 create a column in dependence of another column
Hi there, I'm sorry for the bad subject decision. Couldn't describe it better... In my dataset called dataSet I want to create a new variable column called deal_category which depends on another column called trans_value. In column trans_value I have values in USDm. Now what I want to do is to give these values a category called low, medium or high. The classification depends on the size of the values. low, if value in trans_value is 200 USDm medium, if value x in trans_value is: 200 USDm = x 500 USDm high, if value in trans_value is: = 500 USDm Having defined these deals with low, medium, high I want to run a lm() with these categories as independent variable. deal_category2 - factor(deal_category) levels(deal_category2) - c(low, medium, high) reg_1 - lm(dep_var1 ~ indep_1 + indep_2 + deal_category2) summary(reg_1) Is this correct? Does R recognize my categories as variables? Thanks for all your support! Felix -- View this message in context: http://r.789695.n4.nabble.com/How-to-create-a-column-in-dependence-of-another-column-tp4645548.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 deal with thousands of seconds in R?
If I do: a [1] 2012_10_01_14_13_32.445 a2 [1] 2012_10_01_14_13_32.500 strptime(a,format=%Y_%M_%d_%H_%M_%S)-strptime(a2,format=%Y_%M_%d_%H_%M_%S) Time difference of 0 secs Is there any time object in R that would deal with thousands of seconds? Thanks Agus -- -- Dr. Agustin Lobo Institut de Ciencies de la Terra Jaume Almera (CSIC) Lluis Sole Sabaris s/n 08028 Barcelona Spain Tel. 34 934095410 Fax. 34 934110012 e-mail agustin.l...@ictja.csic.es https://sites.google.com/site/aloboaleu/ __ 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] Modern Symbolic debugger for R programmes?
Worik R wor...@gmail.com on Tue, 9 Oct 2012 17:12:51 +1300 wrote: WR I cannot make setBreakpoint or findLineNum work. I get No source WR refs found.. I am starting to loose my mind! Indeed, as Rainer suggested, check out ESS. The ess-tracebug (part of ESS) provides, among other things, source level debugging, breakpoints and versatile watch window. A bit old but still relevant documentation and screen-shots can be found here http://code.google.com/p/ess-tracebug/ Vitalie __ 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] turn list into dataframe
Hi Purna, From your reply, I guess you intend to email the OP (original poster), but somehow you got confused with the email ids. When you send reply, please cc: to r-help. The OP didn't gave much details about the dataset, but only the output generated from tapply(). Output shows that the list elements are unequal in length. If that is the case, then as.data.frame(output ) gives: list1-list(c(2.8546, 4.0778, 5.2983, 6.3863, 7.5141, 8.5498, 9.5839, 10.6933),c(7.6810, 8.7648, 9.8382, 10.8903, 11.9840, 13.0541, 14.1132, 15.1657),c(22.0840, 30.3001, 35.2505, 42.8085, 48.5220, 52.0604, 57.9428, 61.4930, + 64.4550, 67.3543, 69.8435, 72.9508, 74.4730, 76.3104)) names(list1)-c(SNRL1Core120,SNRL1Core230,VAL1.1.1NA.na30) as.data.frame(list1) #Error in data.frame(SNRL1Core120 = c(2.8546, 4.0778, 5.2983, 6.3863, 7.5141, : #arguments imply differing number of rows: 8, 14 That was the reason I used the function. A.K. - Original Message - From: Purna chander chander...@gmail.com To: arun smartpink...@yahoo.com Cc: Sent: Tuesday, October 9, 2012 1:52 AM Subject: Re: [R] turn list into dataframe Hi Ben, try this.. as.data.frame(tapply(myvector,myindex,cumsum)) Regards, Purna On 10/9/12, arun smartpink...@yahoo.com wrote: Hi, Your output suggests that the list elements have unequal lengths. The empty spaces will be occupied by NAs. I am using the first three list elements from the tapply() output: list1-list(c(2.8546, 4.0778, 5.2983, 6.3863, 7.5141, 8.5498, 9.5839, 10.6933),c(7.6810, 8.7648, 9.8382, 10.8903, 11.9840, 13.0541, 14.1132, 15.1657),c(22.0840, 30.3001, 35.2505, 42.8085, 48.5220, 52.0604, 57.9428, 61.4930, 64.4550, 67.3543, 69.8435, 72.9508, 74.4730, 76.3104)) names(list1)-c(SNRL1Core120,SNRL1Core230,VAL1.1.1NA.na30) fun1-function(x){ na.pad-function(y,len){ c(y,rep(NA,len-length(y))) } maxlen-max(sapply(x,length)) do.call(data.frame,lapply(x,na.pad,len=maxlen)) } fun1(list1) A.K. - Original Message - From: Benjamin Caldwell btcaldw...@berkeley.edu To: r-help r-help@r-project.org Cc: Sent: Monday, October 8, 2012 5:49 PM Subject: [R] turn list into dataframe Dear R users, I'm starting to use 'apply' functions rather than for loops in R, and sometimes the output is a bit different than what I want. In this case, the command was tapply(myvector,myindex,cumsum) And the output was something like this: $`SNRL1 Core 120` [1] 2.8546 4.0778 5.2983 6.3863 7.5141 8.5498 9.5839 10.6933 $`SNRL1 Core 230` [1] 7.6810 8.7648 9.8382 10.8903 11.9840 13.0541 14.1132 15.1657 $`VAL 1.1.NA.na30` [1] 22.0840 30.3001 35.2505 42.8085 48.5220 52.0604 57.9428 61.4930 64.4550 67.3543 69.8435 72.9508 74.4730 76.3104 $`VAL 1.2.NA.na15` [1] 33.8895 38.7440 41.0536 44.1581 46.4891 48.3130 51.0973 52.9241 54.6404 56.1265 57.5064 59.0745 $`VAL 1.2.NA.na30` [1] 6.6408 10.6838 13.8328 15.5435 18.3037 20.3315 22.8817 24.4481 26.4106 27.6658 29.6455 30.8490 31.8680 $`VAL 1.3.NA.na10` [1] 4.8198 7.1274 8.9536 11.5954 14.0845 15.5116 16.9462 18.1269 19.3453 20.5723 21.7122 22.8643 $`VAL 1.3.NA.na20` [1] 5.7382 8.2056 9.4489 10.8225 12.3497 13.6879 15.1077 16.3229 , That's fine, but I need the output as a dataframe. I'm not even sure what to call this list, but it has multiple entries for each item. Forgive the fact that I don't have the data for you to use, I'm wondering if anyone knows about a pre-existing function that will allow be to turn the above list form into a dataframe. Thanks *Ben Caldwell* [[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] How to deal with thousands of seconds in R?
On 09/10/2012 09:54, Agustin Lobo wrote: If I do: a [1] 2012_10_01_14_13_32.445 a2 [1] 2012_10_01_14_13_32.500 strptime(a,format=%Y_%M_%d_%H_%M_%S)-strptime(a2,format=%Y_%M_%d_%H_%M_%S) Time difference of 0 secs Is there any time object in R that would deal with thousands of seconds? Did you mean milliseconds, that is 1/1000th of a second? If so, see the help for the function you used: ‘%S’ Second as decimal number (00-61), allowing for up to two leap-seconds (but POSIX-compliant implementations will ignore leap seconds). Specific to R is ‘%OSn’, which for output gives the seconds truncated to ‘0 = n = 6’ decimal places (and if ‘%OS’ is not followed by a digit, it uses the setting of ‘getOption(digits.secs)’, or if that is unset, ‘n = 3’). Further, for ‘strptime’ ‘%OS’ will input seconds including fractional seconds. Note that ‘%S’ ignores (and not rounds) fractional parts on output. strptime(a,format=%Y_%M_%d_%H_%M_%OS)-strptime(a2,format=%Y_%M_%d_%H_%M_%OS) Time difference of -0.0557 secs (Note that a is not a binary fraction, so some representation error is expected.) -- Brian D. Ripley, rip...@stats.ox.ac.uk Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UKFax: +44 1865 272595 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] other way of making a table?
Use factors? --- 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. Jessica Streicher j.streic...@micromata.de wrote: I'm making tables for prediction results of classifiers (2 classes) that show the usual numbers, true positives, false positives, etc I used the command table(predictedLabels,realLabels) to make those. I just had a case though ,where one of the label vectors had only one class in it. This will result in only half a table. Compare: x-c(1,1,1,0,0) y-c(1,1,1,0,1) table(x,y) to x-c(1,1,1,0,0) y-c(1,1,1,1,1) table(x,y) I want the second one to still have all 4 cases (second column all zeros then). Any easy solutions? __ 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] car::linearHypothesis Sum of Sqaures Error?
John, Thank you for the reply. The data are balanced; I double-checked. I believe the contrasts are orthogonal. Sum of squares in summary(aov) with the contrasts split out add to the main effect. I am still unsure of where the error is for the sum of squares calculation. I have written some code with a parallel model structure that may help (see below). Can linearHypothesis return type II tests? It seems to only return type III with no option to set 'type'. Cheers, John y-runif(36,0,100) block-factor(rep(c(A,B,C),each=12)) a-factor(rep(c(A,B),times=3,each=6)) b-factor(rep(c(A,B),times=6,each=3)) c-factor(rep(c(A,B,C),times=12,each=1)) covar-0.6*y+rnorm(36,10,25) data-data.frame(y,block,a,b,c,covar) c_contrasts-matrix(c(-1,2,-1,1,0,-1),3,2) dimnames(c_contrasts)-list(levels(data$c),c(B vs. AC,A vs. C)) contrasts(data$c)-c_contrasts model-lm(y~block+a*b*c+covar,data=data) summary.aov(model,split=list(c=list(B vs. AC=1,A vs. C=2))) #Sum of squares add here, but factorial ANCOVA non-orthogonal in type I SS Anova(model,type=2) Anova(model,type=3) linearHypothesis(model,c(cB vs. AC,cA vs. C)) #Anova and linear hypothesis produce equal sum of squares for c main effect in type III linearHypothesis(model,cB vs. AC) linearHypothesis(model,cA vs. C) #Sum of squares of the individual contrasts do not add to the main effect of c John J. Wiley, Jr. PhD Candidate State University of New York College of Environmental Science and Forestry Department of Environmental and Forest Biology 460 Illick Hall Syracuse, NY 13210 315.470.4825 (office) 740.590.6121 (cell) From: John Fox [j...@mcmaster.ca] Sent: Tuesday, October 09, 2012 7:15 AM To: John Jay Wiley Jr. Cc: r-help@r-project.org Subject: Re: [R] car::linearHypothesis Sum of Sqaures Error? Dear John On Tue, 9 Oct 2012 02:07:07 + John Jay Wiley Jr. jwile...@syr.edu wrote: I am working with a RCB 2x2x3 ANCOVA, and I have noticed a difference in the calculation of sum of squares in a Type III calculation. For type III tests, you should use contrasts that are orthogonal in the row basis of the design. Perhaps you've done that (by setting the contrasts for the factors directly), but I suspect not. Why not just use type II tests? They're hard to screw up. As well, I assume that the variables that enter additively are the covariates. If not, and a covariate is involved in the interaction, the type III tests aren't sensible unless the 0 point of the covariate is where you want to test a main effect or lower-order interaction. Anova output is a follows: Anova(aov(MSOIL~Forest+Burn*Thin*Moisture+ROCK,data=env3l),type=3) Anova Table (Type III tests) Response: MSOIL Sum Sq Df F valuePr(F) (Intercept)22.3682 1 53.2141 3.499e-07 *** Forest 1.0954 2 1.3029 0.29282 Burn2.6926 1 6.4058 0.01943 * Thin0.0494 1 0.1176 0.73503 Moisture1.2597 2 1.4984 0.24644 ROCK2.1908 1 5.2119 0.03296 * Burn:Thin 0.2002 1 0.4764 0.49763 Burn:Moisture 1.0612 2 1.2623 0.30360 Thin:Moisture 1.6590 2 1.9734 0.16392 Burn:Thin:Moisture 1.1175 2 1.3292 0.28605 Residuals 8.8272 21 However, I would like to calculate some a priori contrasts within the Moisture factor as follows: Transect_moisture_contrasts-matrix(c(-1,2,-1,1,0,-1),3,2) dimnames(Transect_moisture_contrasts)-list(levels(env$Moisture),c(I vs. XM,X vs. M)) contrasts(env$Moisture)-Transect_moisture_contrasts contrasts(env3l$Moisture) I vs. XM X vs. M X-1 1 I 2 0 M-1 -1 soilmodel-lm(MSOIL~Forest+Burn*Thin*Moisture+ROCK,data=env3l) linearHypothesis(soilmodel,MoistureI vs. XM) Linear hypothesis test Hypothesis: MoistureI vs. XM = 0 Model 1: restricted model Model 2: MSOIL ~ Forest + Burn * Thin * Moisture + ROCK Res.DfRSS Df Sum of Sq F Pr(F) 1 22 9.4106 2 21 8.8272 1 0.58333 1.3877 0.252 linearHypothesis(soilmodel,MoistureX vs. M) Linear hypothesis test Hypothesis: MoistureX vs. M = 0 Model 1: restricted model Model 2: MSOIL ~ Forest + Burn * Thin * Moisture + ROCK Res.DfRSS Df Sum of Sq F Pr(F) 1 22 9.6359 2 21 8.8272 1 0.80871 1.9239 0.18 The sum of squares for these two contrasts do not add up to the sum of squares of the main effect Moisture .80871+.58333 [1] 1.39204 1.39204-1.2596 [1] 0.13244 Checking them together produces the correct sum of squares for the main effect linearHypothesis(soilmodel,c(MoistureI vs. XM,MoistureX vs. M)) Linear hypothesis test Hypothesis: MoistureI vs. XM = 0 MoistureX vs. M = 0 Model 1: restricted model Model 2: MSOIL ~ Forest + Burn * Thin * Moisture + ROCK Res.Df RSS Df Sum of Sq F Pr(F) 1 23 10.0869 2 21 8.8272 21.2596 1.4984 0.2464 So my question
Re: [R] other way of making a table?
So.. real=factor(realLabels) predicted=factor(predictedLabels) fl-unique(levels(real),levels(predicted)) real=factor(realLabels,fl) predicted=factor(pl,fl) table(real,predicted) ? i kinda dont like it :/ On 09.10.2012, at 15:00, Jeff Newmiller wrote: Use factors? --- 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. Jessica Streicher j.streic...@micromata.de wrote: I'm making tables for prediction results of classifiers (2 classes) that show the usual numbers, true positives, false positives, etc I used the command table(predictedLabels,realLabels) to make those. I just had a case though ,where one of the label vectors had only one class in it. This will result in only half a table. Compare: x-c(1,1,1,0,0) y-c(1,1,1,0,1) table(x,y) to x-c(1,1,1,0,0) y-c(1,1,1,1,1) table(x,y) I want the second one to still have all 4 cases (second column all zeros then). Any easy solutions? __ 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] other way of making a table?
Dear Jessica, Compare x-c(1,1,1,0,0) y-c(1,1,1,1,1) table(x, y) with table(factor(x, levels = 0:1), factor(y, levels = 0:1)) HTH, Jorge.- On Wed, Oct 10, 2012 at 12:24 AM, Jessica Streicher wrote: So.. real=factor(realLabels) predicted=factor(predictedLabels) fl-unique(levels(real),levels(predicted)) real=factor(realLabels,fl) predicted=factor(pl,fl) table(real,predicted) ? i kinda dont like it :/ On 09.10.2012, at 15:00, Jeff Newmiller wrote: Use factors? --- 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. Jessica Streicher j.streic...@micromata.de wrote: I'm making tables for prediction results of classifiers (2 classes) that show the usual numbers, true positives, false positives, etc I used the command table(predictedLabels,realLabels) to make those. I just had a case though ,where one of the label vectors had only one class in it. This will result in only half a table. Compare: x-c(1,1,1,0,0) y-c(1,1,1,0,1) table(x,y) to x-c(1,1,1,0,0) y-c(1,1,1,1,1) table(x,y) I want the second one to still have all 4 cases (second column all zeros then). Any easy solutions? __ 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] other way of making a table?
On 09/10/2012 9:24 AM, Jessica Streicher wrote: So.. real=factor(realLabels) predicted=factor(predictedLabels) fl-unique(levels(real),levels(predicted)) real=factor(realLabels,fl) predicted=factor(pl,fl) table(real,predicted) ? i kinda dont like it :/ Why make it so complicated? Don't you know the levels in advance? If so, it's much simpler: levels - c(0,1) x - factor( c(1,1,1,0,0), levels=levels) y - factor( c(1,1,1,1,1), levels=levels) table(x,y) Even if you don't know them, the levels calculation doesn't need to work on a factor, you could simply do x-c(1,1,1,0,0) y-c(1,1,1,1,1) levels - unique(c(x,y)) x - factor( x, levels=levels) y - factor( y, levels=levels) table(x,y) Duncan Murdoch On 09.10.2012, at 15:00, Jeff Newmiller wrote: Use factors? --- 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. Jessica Streicher j.streic...@micromata.de wrote: I'm making tables for prediction results of classifiers (2 classes) that show the usual numbers, true positives, false positives, etc I used the command table(predictedLabels,realLabels) to make those. I just had a case though ,where one of the label vectors had only one class in it. This will result in only half a table. Compare: x-c(1,1,1,0,0) y-c(1,1,1,0,1) table(x,y) to x-c(1,1,1,0,0) y-c(1,1,1,1,1) table(x,y) I want the second one to still have all 4 cases (second column all zeros then). Any easy solutions? __ 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] Reading labels for very large heatmaps
If you provide some example data in reproducible code, I might be able to help. Otherwise, not much I can do. Jean JIMonroe jim...@virginia.edu wrote on 10/08/2012 01:17:55 AM: Jean, It's definitely bigger now, but my axes are cut-off. As in your example, I had them drawn after generating the heatmap, but the image does not seem to be centered. I think even part of the heatmap is getting cut off, which wasn't happening until I explicitly set the width and height of the pdf. Here is my code pdf(Apo_Mut_Boot.pdf, width=200, height=200) heatmap(x=as.matrix((Apo_Mut)), col = colorRampPalette(c(white,black))(256), zlim=c(min(Apo_Mut),max(Apo_Mut)),add = FALSE, xaxs = i, yaxs = i,xaxt= n, yaxt = n, xlab=residue, ylab=residue, main=Apo-Mutant,revC=TRUE, Rowv = as.dendrogram(blah2), Colv = as.dendrogram(blah2), reorderfun = function(d,w) rev(reorder(d,w)), oldstyle = FALSE,cexRow=0.01,cexCol=0.01,symm=TRUE ) axis(1, at=1:919, labels=RowCol, las=2, cex=0.01) axis(4, at=1:919, labels=RowCol, las=2, cex=0.01) box() graphics.off() Jacob [[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] why does R stepAIC keep unsignificant variables?
will add() or drop() function work more similarly as SAS? I understand that there are not many observation points which might cause the problem, but why can the automated process run successfully in SAS instead? From: David Winsemius dwinsem...@comcast.net To: Liang Che/US/TLS/PwC@Americas-US Cc: r-help@r-project.org Date: 10/08/2012 09:10 PM Subject:Re: [R] why does R stepAIC keep unsignificant variables? On Oct 8, 2012, at 5:43 PM, liang@us.pwc.com wrote: Ran a bunch of variables in R and the final result of StepAIC is as below: Why are the first 5 variables kept in the stepwise result?? Are the last 4 variables finally chosen after Stepwise? Thanks Coefficients: Estimate Std. Error t value Pr(|t|) (Intercept) 1.315e-01 2.687e-01 0.490 0.63611 Core_CPI__ 1.290e-02 7.496e-03 1.721 0.11927 GDP_change -3.482e-03 2.075e-03 -1.678 0.12767 Unemployment 1.209e-02 6.970e-03 1.735 0.11685 interest -5.580e-03 3.923e-03 -1.422 0.18863 housing 6.692e-04 5.812e-04 1.151 0.27928 S_P 7.636e-05 3.967e-05 1.925 0.08641 . d1 2.087e-02 6.102e-03 3.421 0.00762 ** d2 -2.059e-02 7.331e-03 -2.808 0.02043 * d3 -2.769e-02 6.268e-03 -4.418 0.00168 ** --- Signif. codes: 0 ?***? 0.001 ?**? 0.01 ?*? 0.05 ?.? 0.1 ? ? 1 Residual standard error: 0.008362 on 9 degrees of freedom Multiple R-squared: 0.9534, Adjusted R-squared: 0.9069 F-statistic: 20.48 on 9 and 9 DF, p-value: 5.866e-05 install.package(fortunes) requie(fortune) fortune(182) -- David Winsemius, MD Alameda, CA, USA __ The information transmitted, including any attachments, is intended only for the person or entity to which it is addressed and may contain confidential and/or privileged material. Any review, retransmission, dissemination or other use of, or taking of any action in reliance upon, this information by persons or entities other than the intended recipient is prohibited, and all liability arising therefrom is disclaimed. If you received this in error, please contact the sender and delete the material from any computer. PricewaterhouseCoopers LLP is a Delaware limited liability partnership. This communication may come from PricewaterhouseCoopers LLP or one of its subsidiaries. [[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] other way of making a table?
Yepp, i do not necessarily know them beforehand. Or maybe i should rather say that they may differ from time to time but i want to be able to just copy the code. I can use your code that skips the first factor commands though, thanks. On 09.10.2012, at 15:00, Jeff Newmiller wrote: Use factors? --- 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. Jessica Streicher j.streic...@micromata.de wrote: I'm making tables for prediction results of classifiers (2 classes) that show the usual numbers, true positives, false positives, etc I used the command table(predictedLabels,realLabels) to make those. I just had a case though ,where one of the label vectors had only one class in it. This will result in only half a table. Compare: x-c(1,1,1,0,0) y-c(1,1,1,0,1) table(x,y) to x-c(1,1,1,0,0) y-c(1,1,1,1,1) table(x,y) I want the second one to still have all 4 cases (second column all zeros then). Any easy solutions? __ 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 write out this regression equation in R?
For example: How to make R write out: Balance = 2 + 3 * IntGDP + 5 * IntUnemployment + 0.3 * d1 from the table below: Balance Intercept IntGDP GDPNum IntUnemployment IntInflationd1 d2 d3 3 2 3 5 0.3 0 0 and if I have 20 rows, how to make it a batch process? thanks __ The information transmitted, including any attachments, is intended only for the person or entity to which it is addressed and may contain confidential and/or privileged material. Any review, retransmission, dissemination or other use of, or taking of any action in reliance upon, this information by persons or entities other than the intended recipient is prohibited, and all liability arising therefrom is disclaimed. If you received this in error, please contact the sender and delete the material from any computer. PricewaterhouseCoopers LLP is a Delaware limited liability partnership. This communication may come from PricewaterhouseCoopers LLP or one of its subsidiaries. [[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 write out this regression equation in R?
How to make R write out: Balance = 2 + 3 * IntGDP + 5 * IntUnemployment + 0.3 * d1 from the table below: Balance Intercept IntGDP GDPNum IntUnemployment IntInflationd1 d2 d3 3 2 3 5 0.3 0 0 Maybe ?sprintf would help? And if you wrap that in a function that takes a vector, using apply() on the table would give you one string per row, *** 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] Text file: multiple matrix
Hello, Try the following, substituting your filename for test.txt. fun - function(filenumber, con, n, sep = , prefix = RTest){ txt - readLines(con, n = n) tc - textConnection(txt) on.exit(close(tc)) tbl - read.table(tc, sep = sep)[-n, ] filename - sprintf(%s_%03d, prefix, filenumber) write.table(tbl, filename, row.names = FALSE) filename } NRows - 256 NMat - 100 fc - file(test.txt, open = rb) lapply(seq_len(NMat), fun, fc, n = NRows + 1) close(fc) Hope this helps, Rui Barradas Em 09-10-2012 11:15, ludovico escreveu: Hi there! I'm a newbie in R This is my problem: I have a txt file composed by 100 matrix (256x256) separated by a blank line! How can I save automatically the matrix in separated txt file (100)? e.g. 1° matrix from line 1 to line 256 257 blank line 2°matrix from line 258 to line 513 514 blank line 3° matrix from line 515 to line 770 771 blank line 4° matrix from line 772 to line 1027.. Thanks -- View this message in context: http://r.789695.n4.nabble.com/Text-file-multiple-matrix-tp4645551.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] Send Email from R
Hi, i wanted to send a mail from R (using Eclips). Currently i installed the following packages base64_1.1 sendmailR_1.1-1 mail_1.0.tar.gz Rmail_1.1.tar.gz But while installing package some error was occuring. Any other way to send a mail ? - Thanks in advance Antony -- View this message in context: http://r.789695.n4.nabble.com/Send-Email-from-R-tp4645565.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] How to deal with thousands of seconds in R?
Sorry for the typo, I meant thousandths, and thanks for pointing out the %OS format, which I had overlooked Agus On Tue, Oct 9, 2012 at 2:51 PM, Prof Brian Ripley rip...@stats.ox.ac.uk wrote: On 09/10/2012 09:54, Agustin Lobo wrote: If I do: a [1] 2012_10_01_14_13_32.445 a2 [1] 2012_10_01_14_13_32.500 strptime(a,format=%Y_%M_%d_%H_%M_%S)-strptime(a2,format=%Y_%M_%d_%H_%M_%S) Time difference of 0 secs Is there any time object in R that would deal with thousands of seconds? Did you mean milliseconds, that is 1/1000th of a second? If so, see the help for the function you used: ‘%S’ Second as decimal number (00-61), allowing for up to two leap-seconds (but POSIX-compliant implementations will ignore leap seconds). Specific to R is ‘%OSn’, which for output gives the seconds truncated to ‘0 = n = 6’ decimal places (and if ‘%OS’ is not followed by a digit, it uses the setting of ‘getOption(digits.secs)’, or if that is unset, ‘n = 3’). Further, for ‘strptime’ ‘%OS’ will input seconds including fractional seconds. Note that ‘%S’ ignores (and not rounds) fractional parts on output. strptime(a,format=%Y_%M_%d_%H_%M_%OS)-strptime(a2,format=%Y_%M_%d_%H_%M_%OS) Time difference of -0.0557 secs (Note that a is not a binary fraction, so some representation error is expected.) -- Brian D. Ripley, rip...@stats.ox.ac.uk Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UKFax: +44 1865 272595 -- -- Dr. Agustin Lobo Institut de Ciencies de la Terra Jaume Almera (CSIC) Lluis Sole Sabaris s/n 08028 Barcelona Spain Tel. 34 934095410 Fax. 34 934110012 e-mail agustin.l...@ictja.csic.es https://sites.google.com/site/aloboaleu/ __ 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] why does R stepAIC keep unsignificant variables?
Why are the first 5 variables kept in the stepwise result?? I don't know, for your data set. However, AIC is in my limited experience less likely to reject a term than rejection based on p-value at 95% confidence. It's not the same criterion, so there's no immediate reason it should give the same result. And it often - quite correctly - doesn't. 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.
[R] append for .Rdata?
Can i somehow append objects to an .Rdata file? I didn't see an option for it in the save() method. dump() won't work since i have s4 objects in there. __ 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] Convert COLON separated format
Matrix::spMatrix can help. Read your data file with lns - readLines(fileName) to get something like lns - c(1 5:15 7:17 9:19, 2 2:22 8:28, 4 6:46) Then use a function like the following that reformats the data to the i=row,j=col,x=value vectors that spMatrix can use. f - function(lns, nrow=NULL, ncol=NULL) { # expect lines of the form rowNumwhiteSpacecolNum:value[whiteSpacecolNum:value ...] triples - unlist(lapply(strsplit(lns, [ \t]+), function(ln)paste(sep=:,ln[1],ln[-1] triples - strsplit(triples, :) if (any(which - vapply(triples, length, 0) != 3)) stop(formatting error) ijx - matrix(as.numeric(unlist(triples)), ncol=3, byrow=TRUE) if (is.null(nrow)) nrow - max(ijx[,1]) if (is.null(ncol)) ncol - max(ijx[,2]) spMatrix(nrow=nrow, ncol=ncol, i=ijx[,1], j=ijx[,2], x=ijx[,3]) } Use it as f(lns) 4 x 9 sparse Matrix of class dgTMatrix [1,] . . . . 15 . 17 . 19 [2,] . 22 . . . . . 28 . [3,] . . . . . . . . . [4,] . . . . . 46 . . . or, if you know the number of rows and columns, tell it: f(lns, 10, 10) 10 x 10 sparse Matrix of class dgTMatrix [1,] . . . . 15 . 17 . 19 . [2,] . 22 . . . . . 28 . . [3,] . . . . . . . . . . [4,] . . . . . 46 . . . . [5,] . . . . . . . . . . [6,] . . . . . . . . . . [7,] . . . . . . . . . . [8,] . . . . . . . . . . [9,] . . . . . . . . . . [10,] . . . . . . . . . . Use as.matrix() on its output if you don't want to continue using the sparse matrix format. 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 Noah Silverman Sent: Monday, October 08, 2012 9:57 PM To: r-help Subject: [R] Convert COLON separated format I have a bunch of data sets that were created for the libsvm tool. They are in colon separated sparse format. i.e. 1 5:1 27:3 345:10 Is a row with the label of 1 and only has values in columns 5, 27, and 345. I want to read these into a data.frame in R. Is there a simple way to do this? -- Noah Silverman, M.S. UCLA Department of Statistics 8117 Math Sciences Building Los Angeles, CA 90095 __ 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] turn list into dataframe
Thanks Arun - the different lengths in the list elements was the sticking point. Does anyone have suggestions for packages or R books on indexing/ reshaping datasets for an intermediate user like myself? *Ben Caldwell* On Mon, Oct 8, 2012 at 3:26 PM, arun smartpink...@yahoo.com wrote: Hi, Your output suggests that the list elements have unequal lengths. The empty spaces will be occupied by NAs. I am using the first three list elements from the tapply() output: list1-list(c(2.8546, 4.0778, 5.2983, 6.3863, 7.5141, 8.5498, 9.5839, 10.6933),c(7.6810, 8.7648, 9.8382, 10.8903, 11.9840, 13.0541, 14.1132, 15.1657),c(22.0840, 30.3001, 35.2505, 42.8085, 48.5220, 52.0604, 57.9428, 61.4930, 64.4550, 67.3543, 69.8435, 72.9508, 74.4730, 76.3104)) names(list1)-c(SNRL1Core120,SNRL1Core230,VAL1.1.1NA.na30) fun1-function(x){ na.pad-function(y,len){ c(y,rep(NA,len-length(y))) } maxlen-max(sapply(x,length)) do.call(data.frame,lapply(x,na.pad,len=maxlen)) } fun1(list1) A.K. - Original Message - From: Benjamin Caldwell btcaldw...@berkeley.edu To: r-help r-help@r-project.org Cc: Sent: Monday, October 8, 2012 5:49 PM Subject: [R] turn list into dataframe Dear R users, I'm starting to use 'apply' functions rather than for loops in R, and sometimes the output is a bit different than what I want. In this case, the command was tapply(myvector,myindex,cumsum) And the output was something like this: $`SNRL1 Core 120` [1] 2.8546 4.0778 5.2983 6.3863 7.5141 8.5498 9.5839 10.6933 $`SNRL1 Core 230` [1] 7.6810 8.7648 9.8382 10.8903 11.9840 13.0541 14.1132 15.1657 $`VAL 1.1.NA.na30` [1] 22.0840 30.3001 35.2505 42.8085 48.5220 52.0604 57.9428 61.4930 64.4550 67.3543 69.8435 72.9508 74.4730 76.3104 $`VAL 1.2.NA.na15` [1] 33.8895 38.7440 41.0536 44.1581 46.4891 48.3130 51.0973 52.9241 54.6404 56.1265 57.5064 59.0745 $`VAL 1.2.NA.na30` [1] 6.6408 10.6838 13.8328 15.5435 18.3037 20.3315 22.8817 24.4481 26.4106 27.6658 29.6455 30.8490 31.8680 $`VAL 1.3.NA.na10` [1] 4.8198 7.1274 8.9536 11.5954 14.0845 15.5116 16.9462 18.1269 19.3453 20.5723 21.7122 22.8643 $`VAL 1.3.NA.na20` [1] 5.7382 8.2056 9.4489 10.8225 12.3497 13.6879 15.1077 16.3229 , That's fine, but I need the output as a dataframe. I'm not even sure what to call this list, but it has multiple entries for each item. Forgive the fact that I don't have the data for you to use, I'm wondering if anyone knows about a pre-existing function that will allow be to turn the above list form into a dataframe. Thanks *Ben Caldwell* [[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] append for .Rdata?
On 09/10/2012 16:35, Jessica Streicher wrote: Can i somehow append objects to an .Rdata file? No. See the 'R Internals' manual for the details. BTW, it is '.RData': R is case sensitive and so are many file systems. It sounds like you should be using a database of the results of saveRDS() for each object (which is what lazy-loading uses, BTW). -- Brian D. Ripley, rip...@stats.ox.ac.uk Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UKFax: +44 1865 272595 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] R stickers
Dear all, Perhaps this is not the place but... we are going to print some stickers to take them to a conference for a sticker exchange with other free software organisations. Last year I printed very simple stickers and this year I would like to take better stuff to the meeting. Does anyone have a nice design with the R logo that we could use? If you do and are willing to share it please contact me off-list. We may also print some of the for the useR! 2013 conference. :) Many thanks, -- Virgilio Gómez Rubio Departamento de Matemáticas Escuela de Ingenieros Industriales - Albacete Avda. España s/n - 02071 Albacete - SPAIN Tlf: (+34) 967 59 92 00 ext. 8250/8242 __ 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] R stickers
The R site has a number of them: http://developer.r-project.org/Logo/ On Tue, Oct 9, 2012 at 12:27 PM, Virgilio Gómez-Rubio virgilio.go...@uclm.es wrote: Dear all, Perhaps this is not the place but... we are going to print some stickers to take them to a conference for a sticker exchange with other free software organisations. Last year I printed very simple stickers and this year I would like to take better stuff to the meeting. Does anyone have a nice design with the R logo that we could use? If you do and are willing to share it please contact me off-list. We may also print some of the for the useR! 2013 conference. :) Many thanks, -- Virgilio Gómez Rubio Departamento de Matemáticas Escuela de Ingenieros Industriales - Albacete Avda. España s/n - 02071 Albacete - SPAIN Tlf: (+34) 967 59 92 00 ext. 8250/8242 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Jim Holtman Data Munger Guru What is the problem that you are trying to solve? Tell me what you want to do, not how you want to do it. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] How to create a column in dependence of another column
Hello, As for creating the new variable try dataSet - within(dataSet, deal_category - ifelse(trans_value 200, low, ifelse(trans_value 500, medium, high))) And the rest seems ok. Run the code and see if it is. Hope this helps, Rui Barradas Em 09-10-2012 10:25, fxen3k escreveu: Hi there, I'm sorry for the bad subject decision. Couldn't describe it better... In my dataset called dataSet I want to create a new variable column called deal_category which depends on another column called trans_value. In column trans_value I have values in USDm. Now what I want to do is to give these values a category called low, medium or high. The classification depends on the size of the values. low, if value in trans_value is 200 USDm medium, if value x in trans_value is: 200 USDm = x 500 USDm high, if value in trans_value is: = 500 USDm Having defined these deals with low, medium, high I want to run a lm() with these categories as independent variable. deal_category2 - factor(deal_category) levels(deal_category2) - c(low, medium, high) reg_1 - lm(dep_var1 ~ indep_1 + indep_2 + deal_category2) summary(reg_1) Is this correct? Does R recognize my categories as variables? Thanks for all your support! Felix -- View this message in context: http://r.789695.n4.nabble.com/How-to-create-a-column-in-dependence-of-another-column-tp4645548.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] R stickers
Hi Jim,El mar, 09-10-2012 a las 12:39 -0400, jim holtman escribió: The R site has a number of them: http://developer.r-project.org/Logo/ Many thanks. That was what I printed last year, but perhaps someone has a logo with some text on it, etc. Cheers, Virgilio __ 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 create a column in dependence of another column
It might be simpler to use cut(): trans_value - c(3000, 200, 400, 50, 2000) cut(trans_value, breaks=c(-Inf, 200, 500, Inf), labels=c(low,medium,high)) [1] high lowmedium lowhigh Levels: low medium high 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 Rui Barradas Sent: Tuesday, October 09, 2012 9:54 AM To: fxen3k Cc: r-help@r-project.org Subject: Re: [R] How to create a column in dependence of another column Hello, As for creating the new variable try dataSet - within(dataSet, deal_category - ifelse(trans_value 200, low, ifelse(trans_value 500, medium, high))) And the rest seems ok. Run the code and see if it is. Hope this helps, Rui Barradas Em 09-10-2012 10:25, fxen3k escreveu: Hi there, I'm sorry for the bad subject decision. Couldn't describe it better... In my dataset called dataSet I want to create a new variable column called deal_category which depends on another column called trans_value. In column trans_value I have values in USDm. Now what I want to do is to give these values a category called low, medium or high. The classification depends on the size of the values. low, if value in trans_value is 200 USDm medium, if value x in trans_value is: 200 USDm = x 500 USDm high, if value in trans_value is: = 500 USDm Having defined these deals with low, medium, high I want to run a lm() with these categories as independent variable. deal_category2 - factor(deal_category) levels(deal_category2) - c(low, medium, high) reg_1 - lm(dep_var1 ~ indep_1 + indep_2 + deal_category2) summary(reg_1) Is this correct? Does R recognize my categories as variables? Thanks for all your support! Felix -- View this message in context: http://r.789695.n4.nabble.com/How-to-create-a- column-in-dependence-of-another-column-tp4645548.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-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] converting dgCMatrix to regular matrix
Hi: I've looked around and I must be missing it because it's probably somewhere. Does someone know how to convert an object of class dgCmatrix to a regular matrix. I can send someone the data if they need it but it's too big to include here. I read the data in using temp-readMat(movielens.mat) where readMat is from the R.matlab package. But the resulting 2 matrices are S4 object of class dgCmatrix with 6 slots shown below. In the end, I'd actually want to put the 18000 elements of the second matrix into the appropriate locations of the first matrix ( first one has missings or zeros in those places. Not sure which yet ) but first things first ! Thanks a lot. #=== temp - readMat(movielens.mat) print(str(temp)) List of 2 $ x:Formal class 'dgCMatrix' [package Matrix] with 6 slots .. ..@ i : int [1:982089] 0 47 144 253 513 517 574 580 581 593 ... .. ..@ p : int [1:6041] 0 50 176 224 242 437 505 533 669 772 ... .. ..@ Dim : int [1:2] 3706 6040 .. ..@ Dimnames:List of 2 .. .. ..$ : NULL .. .. ..$ : NULL .. ..@ x : num [1:982089] 5 5 5 4 5 4 4 4 5 4 ... .. ..@ factors : list() $ v:Formal class 'dgCMatrix' [package Matrix] with 6 slots .. ..@ i : int [1:18120] 708 964 1782 466 2160 2512 1178 1483 2785 971 ... .. ..@ p : int [1:6041] 0 3 6 9 12 15 18 21 24 27 ... .. ..@ Dim : int [1:2] 3706 6040 .. ..@ Dimnames:List of 2 .. .. ..$ : NULL .. .. ..$ : NULL .. ..@ x : num [1:18120] 3 5 4 5 4 3 3 5 3 4 ... .. ..@ factors : list() - attr(*, header)=List of 3 ..$ description: chr MATLAB 5.0 MAT-file, Platform: GLNXA64, Created on: Tue Mar 18 18:21:21 2008 ..$ version: chr 5 ..$ endian : chr little NULL [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] how to convert by lists in data.frames
Dear R-helpers, Ive got a summary of results from a by() call that I am making with a list of more than two of factors not very different from the example in the by() help page require(stats) by(warpbreaks[, 1], warpbreaks[, -1], summary) The result of the command gives a list of the form wool: A tension: L Min. 1st Qu. MedianMean 3rd Qu.Max. 25.00 26.00 51.00 44.56 54.00 70.00 --- wool: B tension: L Min. 1st Qu. MedianMean 3rd Qu.Max. 14.00 20.00 29.00 28.22 31.00 44.00 --- . And so on. I would like to convert this result in to a flat data.frame with variable names: Wool, Tension, Min, 1stQ, Median, Mean, 3rdQ, Max A, L , 25.00 26.00 51.00 44.56 54.00 70.00 B, L, 14.00 20.00 29.00 28.22 31.00 44.00 . Although Ive tried the argument simplify=T I havent been able to get this converted. Is there a simple way to achieve this? Thanks in advance! Regards, Jesus Jesús María Frías Celayeta, PhD Ceann Cúntóir, Scoil Eolaíocht an Bhia agus Sláinte an Chomhshaoil Assistant Head, School of Food Science and Environmental Health, Coláiste Eolaíochtaí agus Sláinte/ College of Sciences and Health, Institiúid Teicneolaíochta Átha Cliath/ Dublin Institute of Technology, Sráid Chathal Brugha, Baile Átha Cliath 1, Éire/Cathal Brugha Street, Dublin 1, Ireland F: +353-1-4024459 E: mailto:james.cur...@dit.ie jesus.fr...@dit.ie W: http://fseh.dit.ie/o4/StaffListing/JesusFrias.html Tá an teachtaireacht seo scanta ó thaobh ábhar agus víreas ag Seirbhís Scanta Ríomhphost de chuid Seirbhísí Faisnéise, ITBÁC agus meastar í a bheith slán. http://www.dit.ie This message has been scanned for content and viruses by the DIT Information Services E-Mail Scanning Service, and is believed to be clean. http://www.dit.ie [[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] turn list into dataframe
On Tuesday, October 9, 2012, Benjamin Caldwell wrote: Thanks Arun - the different lengths in the list elements was the sticking point. Does anyone have suggestions for packages or R books on indexing/ reshaping datasets for an intermediate user like myself? Perhaps Spector on Data Manipulation in R Cheer cheers, rmw *Ben Caldwell* On Mon, Oct 8, 2012 at 3:26 PM, arun smartpink...@yahoo.comjavascript:; wrote: Hi, Your output suggests that the list elements have unequal lengths. The empty spaces will be occupied by NAs. I am using the first three list elements from the tapply() output: list1-list(c(2.8546, 4.0778, 5.2983, 6.3863, 7.5141, 8.5498, 9.5839, 10.6933),c(7.6810, 8.7648, 9.8382, 10.8903, 11.9840, 13.0541, 14.1132, 15.1657),c(22.0840, 30.3001, 35.2505, 42.8085, 48.5220, 52.0604, 57.9428, 61.4930, 64.4550, 67.3543, 69.8435, 72.9508, 74.4730, 76.3104)) names(list1)-c(SNRL1Core120,SNRL1Core230,VAL1.1.1NA.na30) fun1-function(x){ na.pad-function(y,len){ c(y,rep(NA,len-length(y))) } maxlen-max(sapply(x,length)) do.call(data.frame,lapply(x,na.pad,len=maxlen)) } fun1(list1) A.K. - Original Message - From: Benjamin Caldwell btcaldw...@berkeley.edu javascript:; To: r-help r-help@r-project.org javascript:; Cc: Sent: Monday, October 8, 2012 5:49 PM Subject: [R] turn list into dataframe Dear R users, I'm starting to use 'apply' functions rather than for loops in R, and sometimes the output is a bit different than what I want. In this case, the command was tapply(myvector,myindex,cumsum) And the output was something like this: $`SNRL1 Core 120` [1] 2.8546 4.0778 5.2983 6.3863 7.5141 8.5498 9.5839 10.6933 $`SNRL1 Core 230` [1] 7.6810 8.7648 9.8382 10.8903 11.9840 13.0541 14.1132 15.1657 $`VAL 1.1.NA.na30` [1] 22.0840 30.3001 35.2505 42.8085 48.5220 52.0604 57.9428 61.4930 64.4550 67.3543 69.8435 72.9508 74.4730 76.3104 $`VAL 1.2.NA.na15` [1] 33.8895 38.7440 41.0536 44.1581 46.4891 48.3130 51.0973 52.9241 54.6404 56.1265 57.5064 59.0745 $`VAL 1.2.NA.na30` [1] 6.6408 10.6838 13.8328 15.5435 18.3037 20.3315 22.8817 24.4481 26.4106 27.6658 29.6455 30.8490 31.8680 $`VAL 1.3.NA.na10` [1] 4.8198 7.1274 8.9536 11.5954 14.0845 15.5116 16.9462 18.1269 19.3453 20.5723 21.7122 22.8643 $`VAL 1.3.NA.na20` [1] 5.7382 8.2056 9.4489 10.8225 12.3497 13.6879 15.1077 16.3229 , That's fine, but I need the output as a dataframe. I'm not even sure what to call this list, but it has multiple entries for each item. Forgive the fact that I don't have the data for you to use, I'm wondering if anyone knows about a pre-existing function that will allow be to turn the above list form into a dataframe. Thanks *Ben Caldwell* [[alternative HTML version deleted]] __ R-help@r-project.org javascript:; 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 javascript:; 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] converting dgCMatrix to regular matrix
On 09-10-2012, at 19:04, Mark Leeds marklee...@gmail.com wrote: Hi: I've looked around and I must be missing it because it's probably somewhere. Does someone know how to convert an object of class dgCmatrix to a regular matrix. I can send someone the data if they need it but it's too big to include here. as.matrix as(x,matrix) 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] how to convert by lists in data.frames
Hello, Try do.call(data.frame, by.list) Hope this helps, Rui Barradas Em 09-10-2012 17:53, Jesus Frias escreveu: Dear R-helpers, I've got a summary of results from a by() call that I am making with a list of more than two of factors not very different from the example in the by() help page require(stats) by(warpbreaks[, 1], warpbreaks[, -1], summary) The result of the command gives a list of the form wool: A tension: L Min. 1st Qu. MedianMean 3rd Qu.Max. 25.00 26.00 51.00 44.56 54.00 70.00 --- wool: B tension: L Min. 1st Qu. MedianMean 3rd Qu.Max. 14.00 20.00 29.00 28.22 31.00 44.00 --- And so on. I would like to convert this result in to a flat data.frame with variable names: Wool, Tension, Min, 1stQ, Median, Mean, 3rdQ, Max A, L , 25.00 26.00 51.00 44.56 54.00 70.00 B, L, 14.00 20.00 29.00 28.22 31.00 44.00 Although I've tried the argument simplify=T I haven't been able to get this converted. Is there a simple way to achieve this? Thanks in advance! Regards, Jesus Jesús María Frías Celayeta, PhD Ceann Cúntóir, Scoil Eolaíocht an Bhia agus Sláinte an Chomhshaoil Assistant Head, School of Food Science and Environmental Health, Coláiste Eolaíochtaí agus Sláinte/ College of Sciences and Health, Institiúid Teicneolaíochta Átha Cliath/ Dublin Institute of Technology, Sráid Chathal Brugha, Baile Átha Cliath 1, Éire/Cathal Brugha Street, Dublin 1, Ireland F: +353-1-4024459 E: mailto:james.cur...@dit.ie jesus.fr...@dit.ie W: http://fseh.dit.ie/o4/StaffListing/JesusFrias.html Tá an teachtaireacht seo scanta ó thaobh ábhar agus víreas ag Seirbhís Scanta Ríomhphost de chuid Seirbhísí Faisnéise, ITBÁC agus meastar í a bheith slán. http://www.dit.ie This message has been scanned for content and viruses by the DIT Information Services E-Mail Scanning Service, and is believed to be clean. http://www.dit.ie [[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] how to convert by lists in data.frames
On Tue, Oct 9, 2012 at 11:42 AM, Rui Barradas ruipbarra...@sapo.pt wrote: Hello, Try do.call(data.frame, by.list) I don't think data.frame inside do.call works in this context. May need it on the outside to do the job (Only OK here since there is no mixture of numeric and character/factors in this summary). Something like by.list - by(warpbreaks[, 1], warpbreaks[, -1], summary) by.dtfrm - data.frame( do.call( rbind, by.list ) ) by.dtfrm - cbind( do.call( expand.grid, attr( by.list, 'dimnames' ) ), by.dtfrm ) Hope this helps, Rui Barradas Em 09-10-2012 17:53, Jesus Frias escreveu: Dear R-helpers, I've got a summary of results from a by() call that I am making with a list of more than two of factors not very different from the example in the by() help page require(stats) by(warpbreaks[, 1], warpbreaks[, -1], summary) The result of the command gives a list of the form wool: A tension: L Min. 1st Qu. MedianMean 3rd Qu.Max. 25.00 26.00 51.00 44.56 54.00 70.00 --- wool: B tension: L Min. 1st Qu. MedianMean 3rd Qu.Max. 14.00 20.00 29.00 28.22 31.00 44.00 --- And so on. I would like to convert this result in to a flat data.frame with variable names: Wool, Tension, Min, 1stQ, Median, Mean, 3rdQ, Max A, L , 25.00 26.00 51.00 44.56 54.00 70.00 B, L, 14.00 20.00 29.00 28.22 31.00 44.00 Although I've tried the argument simplify=T I haven't been able to get this converted. Is there a simple way to achieve this? Thanks in advance! Regards, Jesus Jesús María Frías Celayeta, PhD Ceann Cúntóir, Scoil Eolaíocht an Bhia agus Sláinte an Chomhshaoil Assistant Head, School of Food Science and Environmental Health, Coláiste Eolaíochtaí agus Sláinte/ College of Sciences and Health, Institiúid Teicneolaíochta Átha Cliath/ Dublin Institute of Technology, Sráid Chathal Brugha, Baile Átha Cliath 1, Éire/Cathal Brugha Street, Dublin 1, Ireland F: +353-1-4024459 E: mailto:james.cur...@dit.ie jesus.fr...@dit.ie W: http://fseh.dit.ie/o4/StaffListing/JesusFrias.html Tá an teachtaireacht seo scanta ó thaobh ábhar agus víreas ag Seirbhís Scanta Ríomhphost de chuid Seirbhísí Faisnéise, ITBÁC agus meastar í a bheith slán. http://www.dit.ie This message has been scanned for content and viruses by the DIT Information Services E-Mail Scanning Service, and is believed to be clean. http://www.dit.ie [[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. [[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 convert by lists in data.frames
Ilai, et. al: Yes. The OP might also look at the result of: t(simplify2array (by.list)) The only wrinkle here (with either rbind or simplify2array) is getting the labels correct if the design is not fully crossed -- i.e. if some groups are missing so that expand.grid() won't work. Then you might have to work harder to extract the information from by.list. str(by.list) might help here. -- Bert On Tue, Oct 9, 2012 at 11:14 AM, ilai ke...@math.montana.edu wrote: On Tue, Oct 9, 2012 at 11:42 AM, Rui Barradas ruipbarra...@sapo.pt wrote: Hello, Try do.call(data.frame, by.list) I don't think data.frame inside do.call works in this context. May need it on the outside to do the job (Only OK here since there is no mixture of numeric and character/factors in this summary). Something like by.list - by(warpbreaks[, 1], warpbreaks[, -1], summary) by.dtfrm - data.frame( do.call( rbind, by.list ) ) by.dtfrm - cbind( do.call( expand.grid, attr( by.list, 'dimnames' ) ), by.dtfrm ) Hope this helps, Rui Barradas Em 09-10-2012 17:53, Jesus Frias escreveu: Dear R-helpers, I've got a summary of results from a by() call that I am making with a list of more than two of factors not very different from the example in the by() help page require(stats) by(warpbreaks[, 1], warpbreaks[, -1], summary) The result of the command gives a list of the form wool: A tension: L Min. 1st Qu. MedianMean 3rd Qu.Max. 25.00 26.00 51.00 44.56 54.00 70.00 --- wool: B tension: L Min. 1st Qu. MedianMean 3rd Qu.Max. 14.00 20.00 29.00 28.22 31.00 44.00 --- And so on. I would like to convert this result in to a flat data.frame with variable names: Wool, Tension, Min, 1stQ, Median, Mean, 3rdQ, Max A, L , 25.00 26.00 51.00 44.56 54.00 70.00 B, L, 14.00 20.00 29.00 28.22 31.00 44.00 Although I've tried the argument simplify=T I haven't been able to get this converted. Is there a simple way to achieve this? Thanks in advance! Regards, Jesus Jesús María Frías Celayeta, PhD Ceann Cúntóir, Scoil Eolaíocht an Bhia agus Sláinte an Chomhshaoil Assistant Head, School of Food Science and Environmental Health, Coláiste Eolaíochtaí agus Sláinte/ College of Sciences and Health, Institiúid Teicneolaíochta Átha Cliath/ Dublin Institute of Technology, Sráid Chathal Brugha, Baile Átha Cliath 1, Éire/Cathal Brugha Street, Dublin 1, Ireland F: +353-1-4024459 E: mailto:james.cur...@dit.ie jesus.fr...@dit.ie W: http://fseh.dit.ie/o4/StaffListing/JesusFrias.html Tá an teachtaireacht seo scanta ó thaobh ábhar agus víreas ag Seirbhís Scanta Ríomhphost de chuid Seirbhísí Faisnéise, ITBÁC agus meastar í a bheith slán. http://www.dit.ie This message has been scanned for content and viruses by the DIT Information Services E-Mail Scanning Service, and is believed to be clean. http://www.dit.ie [[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. [[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] How can I write the square root symbol in an axes label?
And how can I write the units of my axis but outside the square root symbol I have plot(1:10, ylab=bquote(Log(sqrt(Total area (mm) but I need it as in the attached picture http://r.789695.n4.nabble.com/file/n4645602/square_root_mm1.jpg -- View this message in context: http://r.789695.n4.nabble.com/How-can-I-write-the-square-root-symbol-in-an-axes-label-tp4645497p4645602.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] How can I write the square root symbol in an axes label?
On Oct 9, 2012, at 11:13 AM, 21rosit wrote: And how can I write the units of my axis but outside the square root symbol I have plot(1:10, ylab=bquote(Log(sqrt(Total area (mm) but I need it as in the attached picture http://r.789695.n4.nabble.com/file/n4645602/square_root_mm1.jpg plot(1:10, ylab=bquote(Log(sqrt(Total area)~(mm The tilde generates a space, while no space would occur if you substituted * for the ~. -- 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] How can I write the square root symbol in an axes label?
Look at help(plotmath). plot(1:10, xlab=bquote(Log(sqrt(Total area) * (mm # small space before (mm) plot(1:10, xlab=bquote(Log(sqrt(Total area) ~ (mm # more space before (mm) For your next question: # now use .(var) to interpolate value of variable 'var' into a plot label. varName - Mean Acceleration # render as uninterpreted text units - bquote(m/s^2) # render in math notation plot(1:10, xlab=bquote(Log(sqrt(.(varName)) ~ (.(units) 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 21rosit Sent: Tuesday, October 09, 2012 11:14 AM To: r-help@r-project.org Subject: Re: [R] How can I write the square root symbol in an axes label? And how can I write the units of my axis but outside the square root symbol I have plot(1:10, ylab=bquote(Log(sqrt(Total area (mm) but I need it as in the attached picture http://r.789695.n4.nabble.com/file/n4645602/square_root_mm1.jpg -- View this message in context: http://r.789695.n4.nabble.com/How-can-I-write-the- square-root-symbol-in-an-axes-label-tp4645497p4645602.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] how to convert by lists in data.frames
On Tue, Oct 9, 2012 at 12:25 PM, Bert Gunter gunter.ber...@gene.com wrote: The only wrinkle here (with either rbind or simplify2array) is getting the labels correct if the design is not fully crossed -- i.e. if some groups are missing so that expand.grid() won't work. Then you might have to work harder to extract the information from by.list. Agreed. In such a case I might decide to let aggregate(breaks~wool+tension, subset(warpbreaks, wool != 'A' | tension != 'H' ), summary) sort through the headache for me, and overlook the annoying result is actually a matrix put in as a single variable in the data.frame. Personal preference maybe but that never made sense to me in the data frame construct (even if it is just a list). Cheers str(by.list) might help here. -- Bert On Tue, Oct 9, 2012 at 11:14 AM, ilai ke...@math.montana.edu wrote: On Tue, Oct 9, 2012 at 11:42 AM, Rui Barradas ruipbarra...@sapo.pt wrote: Hello, Try do.call(data.frame, by.list) I don't think data.frame inside do.call works in this context. May need it on the outside to do the job (Only OK here since there is no mixture of numeric and character/factors in this summary). Something like by.list - by(warpbreaks[, 1], warpbreaks[, -1], summary) by.dtfrm - data.frame( do.call( rbind, by.list ) ) by.dtfrm - cbind( do.call( expand.grid, attr( by.list, 'dimnames' ) ), by.dtfrm ) Hope this helps, Rui Barradas Em 09-10-2012 17:53, Jesus Frias escreveu: Dear R-helpers, I've got a summary of results from a by() call that I am making with a list of more than two of factors not very different from the example in the by() help page require(stats) by(warpbreaks[, 1], warpbreaks[, -1], summary) The result of the command gives a list of the form wool: A tension: L Min. 1st Qu. MedianMean 3rd Qu.Max. 25.00 26.00 51.00 44.56 54.00 70.00 --- wool: B tension: L Min. 1st Qu. MedianMean 3rd Qu.Max. 14.00 20.00 29.00 28.22 31.00 44.00 --- And so on. I would like to convert this result in to a flat data.frame with variable names: Wool, Tension, Min, 1stQ, Median, Mean, 3rdQ, Max A, L , 25.00 26.00 51.00 44.56 54.00 70.00 B, L, 14.00 20.00 29.00 28.22 31.00 44.00 Although I've tried the argument simplify=T I haven't been able to get this converted. Is there a simple way to achieve this? Thanks in advance! Regards, Jesus Jesús María Frías Celayeta, PhD Ceann Cúntóir, Scoil Eolaíocht an Bhia agus Sláinte an Chomhshaoil Assistant Head, School of Food Science and Environmental Health, Coláiste Eolaíochtaí agus Sláinte/ College of Sciences and Health, Institiúid Teicneolaíochta Átha Cliath/ Dublin Institute of Technology, Sráid Chathal Brugha, Baile Átha Cliath 1, Éire/Cathal Brugha Street, Dublin 1, Ireland F: +353-1-4024459 E: mailto:james.cur...@dit.ie jesus.fr...@dit.ie W: http://fseh.dit.ie/o4/StaffListing/JesusFrias.html Tá an teachtaireacht seo scanta ó thaobh ábhar agus víreas ag Seirbhís Scanta Ríomhphost de chuid Seirbhísí Faisnéise, ITBÁC agus meastar í a bheith slán. http://www.dit.ie This message has been scanned for content and viruses by the DIT Information Services E-Mail Scanning Service, and is believed to be clean. http://www.dit.ie [[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. [[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 [[alternative HTML
[R] NA When Setting Options to See Fractions of Seconds
Dear all, I just found a weird behavior of the timeDate related functions Sys.timeDate() and as.timeDate(). Both of them take place when showing fractions of seconds and I think they might have the same source. Do you know if it should be considered a bug of Sys.timeDate()? Also, what is a good way to generate timeDate with fractions of seconds from strings? I know I can just get the whole part of seconds and add fractions to it. That is a little bit unnecessarily awkward IMO. Thanks! - Alex Below is my whole session: R version 2.15.1 (2012-06-22) -- Roasted Marshmallows Platform: i386-pc-mingw32/i386 (32-bit) require(timeDate) Sys.timeDate() New_York [1] [2012-10-09 14:35:21] options(digits.secs=3) Sys.timeDate() New_York [1] [NA] Warning message Sys.time() [1] 2012-10-09 14:43:45.303 EDT as.timeDate(2012-10-09 14:43:45.303 EDT) New_York [1] [NA] Warning message as.timeDate(2012-10-09 14:43:45.303) New_York [1] [NA] Warning message [[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] car::linearHypothesis Sum of Sqaures Error?
Dear John, -Original Message- From: John Jay Wiley Jr. [mailto:jwile...@syr.edu] Sent: Tuesday, October 09, 2012 9:17 AM To: John Fox Cc: r-help@r-project.org Subject: RE: [R] car::linearHypothesis Sum of Sqaures Error? John, Thank you for the reply. The data are balanced; I double-checked. I believe the contrasts are orthogonal. Sum of squares in summary(aov) with the contrasts split out add to the main effect. I am still unsure of where the error is for the sum of squares calculation. I have written some code with a parallel model structure that may help (see below). Can linearHypothesis return type II tests? It seems to only return type III with no option to set 'type'. Cheers, John y-runif(36,0,100) block-factor(rep(c(A,B,C),each=12)) a-factor(rep(c(A,B),times=3,each=6)) b-factor(rep(c(A,B),times=6,each=3)) c-factor(rep(c(A,B,C),times=12,each=1)) covar-0.6*y+rnorm(36,10,25) data-data.frame(y,block,a,b,c,covar) c_contrasts-matrix(c(-1,2,-1,1,0,-1),3,2) dimnames(c_contrasts)-list(levels(data$c),c(B vs. AC,A vs. C)) contrasts(data$c)-c_contrasts model-lm(y~block+a*b*c+covar,data=data) summary.aov(model,split=list(c=list(B vs. AC=1,A vs. C=2))) #Sum of squares add here, but factorial ANCOVA non-orthogonal in type I SS Anova(model,type=2) Anova(model,type=3) linearHypothesis(model,c(cB vs. AC,cA vs. C)) There are two problems here: (1) the covariate isn't balanced; (2) you didn't pay attention to the contrasts for factors other than c. The default is contr.treatment, which produces terms whose contrasts are not orthogonal in the row basis of the design. So, the following two ANOVAs (not ANCOVAs) give the same result, but the third doesn't. For balanced data, types I (sequential), II, and III tests should all be the same. --- snip -- model.2 - lm(y~block+a*b*c, data=data) anova(model.2) Anova(model.2) Anova(model.2, type=3) # incorrect --- snip -- Here's one way to get correct type III tests: --- snip -- options(contrasts=c(contr.sum, contr.poly)) model.3 - update(model.2) anova(model.3) Anova(model.3) Anova(model.3, type=3) # now all the same --- snip -- #Anova and linear hypothesis produce equal sum of squares for c main effect in type III linearHypothesis(model,cB vs. AC) linearHypothesis(model,cA vs. C) #Sum of squares of the individual contrasts do not add to the main effect of c This is a manifestation of the same problem: --- snip -- linearHypothesis(model.3, c(cB vs. AC,cA vs. C)) # SS equal to the sum of the next two linearHypothesis(model.3, cB vs. AC) linearHypothesis(model.3, cA vs. C) --- snip -- It doesn't make sense to ask whether linearHypothesis() does type II or type III tests -- it just tests directly specified linear hypotheses concerning the parameters of the model as parametrized. Anova() can formulate sets of type II and III linear hypotheses (but for the latter, you do have to pay attention to the parametrization). Best, John John J. Wiley, Jr. PhD Candidate State University of New York College of Environmental Science and Forestry Department of Environmental and Forest Biology 460 Illick Hall Syracuse, NY 13210 315.470.4825 (office) 740.590.6121 (cell) From: John Fox [j...@mcmaster.ca] Sent: Tuesday, October 09, 2012 7:15 AM To: John Jay Wiley Jr. Cc: r-help@r-project.org Subject: Re: [R] car::linearHypothesis Sum of Sqaures Error? Dear John On Tue, 9 Oct 2012 02:07:07 + John Jay Wiley Jr. jwile...@syr.edu wrote: I am working with a RCB 2x2x3 ANCOVA, and I have noticed a difference in the calculation of sum of squares in a Type III calculation. For type III tests, you should use contrasts that are orthogonal in the row basis of the design. Perhaps you've done that (by setting the contrasts for the factors directly), but I suspect not. Why not just use type II tests? They're hard to screw up. As well, I assume that the variables that enter additively are the covariates. If not, and a covariate is involved in the interaction, the type III tests aren't sensible unless the 0 point of the covariate is where you want to test a main effect or lower-order interaction. Anova output is a follows: Anova(aov(MSOIL~Forest+Burn*Thin*Moisture+ROCK,data=env3l),type=3) Anova Table (Type III tests) Response: MSOIL Sum Sq Df F valuePr(F) (Intercept)22.3682 1 53.2141 3.499e-07 *** Forest 1.0954 2 1.3029 0.29282 Burn2.6926 1 6.4058 0.01943 * Thin0.0494 1 0.1176 0.73503 Moisture1.2597 2 1.4984 0.24644 ROCK2.1908 1 5.2119 0.03296 * Burn:Thin 0.2002 1 0.4764 0.49763 Burn:Moisture 1.0612 2 1.2623 0.30360 Thin:Moisture
[R] Qustion about Creating a sequence of vector
Hello R User, I have a data set where subject( Id) are frequently measured. For example, the size of the data set is 75 by 2 and has following frequency distribution. idfreq 1 30 2 20 3 25 I want to create a variable (say seq) containing sequential count for each id. I mean variable seq should be as ( 1,2,..,30, 1,2,...,20, 1,2,...,25) I use following code but did not work. Any suggestion is much appreciated.. sim-rep(NA, 90) for (i in 1:3){ d[i]-seq(1,a[i,2],by=1) sim[i]-as.vector(c(d[i]) } Thank you, Bibek __ 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] plot.new() and grid functions in multipage pdfs
Hi, when using the grid package, I've come across this weird behaviour where a call to plot.new() will start a new page for a multi-page pdf, but then the margins will somehow behave strangely for all but the first page: here is some code: pdf(test.pdf); plot.new(); grid.rect(gp = gpar(fill=blue)); plot.new(); grid.rect(gp = gpar(fill=blue)); dev.off() The first page is filled completely with a blue rectangle, but in the second page, the margins clip the rectangle. This is causing me considerable headache, as I rely on many grid functions for plotting. This seems like a bug to me, or is there something about the behaviour of plot.new() and/or grid functions that I don't understand? /Ali __ 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] Qustion about Creating a sequence of vector
sequence(c(4,2,0,10)) [1] 1 2 3 4 1 2 1 2 3 4 5 6 7 8 9 10 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 bibek sharma Sent: Tuesday, October 09, 2012 11:54 AM To: r-help@r-project.org Subject: [R] Qustion about Creating a sequence of vector Hello R User, I have a data set where subject( Id) are frequently measured. For example, the size of the data set is 75 by 2 and has following frequency distribution. idfreq 1 30 2 20 3 25 I want to create a variable (say seq) containing sequential count for each id. I mean variable seq should be as ( 1,2,..,30, 1,2,...,20, 1,2,...,25) I use following code but did not work. Any suggestion is much appreciated.. sim-rep(NA, 90) for (i in 1:3){ d[i]-seq(1,a[i,2],by=1) sim[i]-as.vector(c(d[i]) } Thank you, Bibek __ 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] car::linearHypothesis Sum of Sqaures Error?
John, Again, thank you for your reply. Unfortunately, I didn't specify that I had previously changed the contrast options to contr.sum. I was aware of that requirement, and I still found that the sum of squares didn't add up. It seems that you made the SS add up by removing the covariate. Ultimately, the reason I moved to Anova and linearHypothesis was to deal with the covariate since Type I sum of squares produce non-orthogonality in factorial ANCOVAs. I am interested to know how you assessed the covariate as unbalanced? It is equally replicated across the groups and the variances are similar. Is there another metric I am missing for a continuous covariate? Cheers, John From: John Fox [j...@mcmaster.ca] Sent: Tuesday, October 09, 2012 2:59 PM To: John Jay Wiley Jr. Cc: r-help@r-project.org Subject: RE: [R] car::linearHypothesis Sum of Sqaures Error? Dear John, -Original Message- From: John Jay Wiley Jr. [mailto:jwile...@syr.edu] Sent: Tuesday, October 09, 2012 9:17 AM To: John Fox Cc: r-help@r-project.org Subject: RE: [R] car::linearHypothesis Sum of Sqaures Error? John, Thank you for the reply. The data are balanced; I double-checked. I believe the contrasts are orthogonal. Sum of squares in summary(aov) with the contrasts split out add to the main effect. I am still unsure of where the error is for the sum of squares calculation. I have written some code with a parallel model structure that may help (see below). Can linearHypothesis return type II tests? It seems to only return type III with no option to set 'type'. Cheers, John y-runif(36,0,100) block-factor(rep(c(A,B,C),each=12)) a-factor(rep(c(A,B),times=3,each=6)) b-factor(rep(c(A,B),times=6,each=3)) c-factor(rep(c(A,B,C),times=12,each=1)) covar-0.6*y+rnorm(36,10,25) data-data.frame(y,block,a,b,c,covar) c_contrasts-matrix(c(-1,2,-1,1,0,-1),3,2) dimnames(c_contrasts)-list(levels(data$c),c(B vs. AC,A vs. C)) contrasts(data$c)-c_contrasts model-lm(y~block+a*b*c+covar,data=data) summary.aov(model,split=list(c=list(B vs. AC=1,A vs. C=2))) #Sum of squares add here, but factorial ANCOVA non-orthogonal in type I SS Anova(model,type=2) Anova(model,type=3) linearHypothesis(model,c(cB vs. AC,cA vs. C)) There are two problems here: (1) the covariate isn't balanced; (2) you didn't pay attention to the contrasts for factors other than c. The default is contr.treatment, which produces terms whose contrasts are not orthogonal in the row basis of the design. So, the following two ANOVAs (not ANCOVAs) give the same result, but the third doesn't. For balanced data, types I (sequential), II, and III tests should all be the same. --- snip -- model.2 - lm(y~block+a*b*c, data=data) anova(model.2) Anova(model.2) Anova(model.2, type=3) # incorrect --- snip -- Here's one way to get correct type III tests: --- snip -- options(contrasts=c(contr.sum, contr.poly)) model.3 - update(model.2) anova(model.3) Anova(model.3) Anova(model.3, type=3) # now all the same --- snip -- #Anova and linear hypothesis produce equal sum of squares for c main effect in type III linearHypothesis(model,cB vs. AC) linearHypothesis(model,cA vs. C) #Sum of squares of the individual contrasts do not add to the main effect of c This is a manifestation of the same problem: --- snip -- linearHypothesis(model.3, c(cB vs. AC,cA vs. C)) # SS equal to the sum of the next two linearHypothesis(model.3, cB vs. AC) linearHypothesis(model.3, cA vs. C) --- snip -- It doesn't make sense to ask whether linearHypothesis() does type II or type III tests -- it just tests directly specified linear hypotheses concerning the parameters of the model as parametrized. Anova() can formulate sets of type II and III linear hypotheses (but for the latter, you do have to pay attention to the parametrization). Best, John John J. Wiley, Jr. PhD Candidate State University of New York College of Environmental Science and Forestry Department of Environmental and Forest Biology 460 Illick Hall Syracuse, NY 13210 315.470.4825 (office) 740.590.6121 (cell) From: John Fox [j...@mcmaster.ca] Sent: Tuesday, October 09, 2012 7:15 AM To: John Jay Wiley Jr. Cc: r-help@r-project.org Subject: Re: [R] car::linearHypothesis Sum of Sqaures Error? Dear John On Tue, 9 Oct 2012 02:07:07 + John Jay Wiley Jr. jwile...@syr.edu wrote: I am working with a RCB 2x2x3 ANCOVA, and I have noticed a difference in the calculation of sum of squares in a Type III calculation. For type III tests, you should use contrasts that are orthogonal in the row basis of the design. Perhaps you've done that (by setting the contrasts for the factors directly), but I suspect not. Why not just use type II tests? They're hard to screw up. As
Re: [R] plot.new() and grid functions in multipage pdfs
On Tue, Oct 9, 2012 at 1:26 PM, Ali Tofigh alix.tof...@gmail.com wrote: Hi, when using the grid package, I've come across this weird behaviour pdf(test.pdf); plot.new(); grid.rect(gp = gpar(fill=blue)); plot.new(); grid.rect(gp = gpar(fill=blue)); dev.off() The first page is filled completely with a blue rectangle, but in the second page, the margins clip the rectangle. This is causing me considerable headache, as I rely on many grid functions for plotting. This seems like a bug to me, or is there something about the behaviour of plot.new() and/or grid functions that I don't understand? Why would you expect plot.new from base graphics to play nice with grid ? if you like/use grid graphics, stay in that world: pdf(test.pdf); grid.rect(gp = gpar(fill=blue)); grid.newpage(); grid.rect(gp = gpar(fill=blue)); dev.off() /Ali __ 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] plot.new() and grid functions in multipage pdfs
The plot.new function is for base graphics and base and grid graphics don't usually play well together. You probably want to use grid.newpage function instead. On Tue, Oct 9, 2012 at 1:26 PM, Ali Tofigh alix.tof...@gmail.com wrote: Hi, when using the grid package, I've come across this weird behaviour where a call to plot.new() will start a new page for a multi-page pdf, but then the margins will somehow behave strangely for all but the first page: here is some code: pdf(test.pdf); plot.new(); grid.rect(gp = gpar(fill=blue)); plot.new(); grid.rect(gp = gpar(fill=blue)); dev.off() The first page is filled completely with a blue rectangle, but in the second page, the margins clip the rectangle. This is causing me considerable headache, as I rely on many grid functions for plotting. This seems like a bug to me, or is there something about the behaviour of plot.new() and/or grid functions that I don't understand? /Ali __ 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. -- Gregory (Greg) L. Snow Ph.D. 538...@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] car::linearHypothesis Sum of Sqaures Error?
Dear John, -Original Message- From: John Jay Wiley Jr. [mailto:jwile...@syr.edu] Sent: Tuesday, October 09, 2012 3:37 PM To: John Fox Cc: r-help@r-project.org Subject: RE: [R] car::linearHypothesis Sum of Sqaures Error? John, Again, thank you for your reply. Unfortunately, I didn't specify that I had previously changed the contrast options to contr.sum. I was aware of that requirement, and I still found that the sum of squares didn't add up. It seems that you made the SS add up by removing the covariate. Ultimately, the reason I moved to Anova and linearHypothesis was to deal with the covariate since Type I sum of squares produce non-orthogonality in factorial ANCOVAs. I am interested to know how you assessed the covariate as unbalanced? It is equally replicated across the groups and the variances are similar. Is there another metric I am missing for a continuous covariate? Unless the covariate mean is identical in the groups (combinations of factor levels), it is unbalanced in the sense of being correlated with the contrasts for groups. You could easily have checked that by looking the covariance matrix of the coefficients. John Cheers, John From: John Fox [j...@mcmaster.ca] Sent: Tuesday, October 09, 2012 2:59 PM To: John Jay Wiley Jr. Cc: r-help@r-project.org Subject: RE: [R] car::linearHypothesis Sum of Sqaures Error? Dear John, -Original Message- From: John Jay Wiley Jr. [mailto:jwile...@syr.edu] Sent: Tuesday, October 09, 2012 9:17 AM To: John Fox Cc: r-help@r-project.org Subject: RE: [R] car::linearHypothesis Sum of Sqaures Error? John, Thank you for the reply. The data are balanced; I double-checked. I believe the contrasts are orthogonal. Sum of squares in summary(aov) with the contrasts split out add to the main effect. I am still unsure of where the error is for the sum of squares calculation. I have written some code with a parallel model structure that may help (see below). Can linearHypothesis return type II tests? It seems to only return type III with no option to set 'type'. Cheers, John y-runif(36,0,100) block-factor(rep(c(A,B,C),each=12)) a-factor(rep(c(A,B),times=3,each=6)) b-factor(rep(c(A,B),times=6,each=3)) c-factor(rep(c(A,B,C),times=12,each=1)) covar-0.6*y+rnorm(36,10,25) data-data.frame(y,block,a,b,c,covar) c_contrasts-matrix(c(-1,2,-1,1,0,-1),3,2) dimnames(c_contrasts)-list(levels(data$c),c(B vs. AC,A vs. C)) contrasts(data$c)-c_contrasts model-lm(y~block+a*b*c+covar,data=data) summary.aov(model,split=list(c=list(B vs. AC=1,A vs. C=2))) #Sum of squares add here, but factorial ANCOVA non-orthogonal in type I SS Anova(model,type=2) Anova(model,type=3) linearHypothesis(model,c(cB vs. AC,cA vs. C)) There are two problems here: (1) the covariate isn't balanced; (2) you didn't pay attention to the contrasts for factors other than c. The default is contr.treatment, which produces terms whose contrasts are not orthogonal in the row basis of the design. So, the following two ANOVAs (not ANCOVAs) give the same result, but the third doesn't. For balanced data, types I (sequential), II, and III tests should all be the same. --- snip -- model.2 - lm(y~block+a*b*c, data=data) anova(model.2) Anova(model.2) Anova(model.2, type=3) # incorrect --- snip -- Here's one way to get correct type III tests: --- snip -- options(contrasts=c(contr.sum, contr.poly)) model.3 - update(model.2) anova(model.3) Anova(model.3) Anova(model.3, type=3) # now all the same --- snip -- #Anova and linear hypothesis produce equal sum of squares for c main effect in type III linearHypothesis(model,cB vs. AC) linearHypothesis(model,cA vs. C) #Sum of squares of the individual contrasts do not add to the main effect of c This is a manifestation of the same problem: --- snip -- linearHypothesis(model.3, c(cB vs. AC,cA vs. C)) # SS equal to the sum of the next two linearHypothesis(model.3, cB vs. AC) linearHypothesis(model.3, cA vs. C) --- snip -- It doesn't make sense to ask whether linearHypothesis() does type II or type III tests -- it just tests directly specified linear hypotheses concerning the parameters of the model as parametrized. Anova() can formulate sets of type II and III linear hypotheses (but for the latter, you do have to pay attention to the parametrization). Best, John John J. Wiley, Jr. PhD Candidate State University of New York College of Environmental Science and Forestry Department of Environmental and Forest Biology 460 Illick Hall Syracuse, NY 13210 315.470.4825 (office) 740.590.6121 (cell) From: John Fox
Re: [R] variances of random effects in coxme
Dear R users, Terry Theneau, thank you very much for you answer. I'm running R 2.15.1 (32 bits) and coxme 2.2-3. Here is a small R code which reproduces the problem (I fitted a model with random effects whereas it is useless), it gives exactly the same estimations of the variances than on my real data. library(coxme) set.seed(1989) # parameters N=500 beta1=0.5 beta2=-0.5 beta3=0.5 nb.groups=10 # variables x=rbinom(N,1,0.5) # first covariate y=rbinom(N,1,0.5) # second covariate z=factor(rbinom(N,1,0.5)) # third covariate which will interacts with the groups id=factor(sample(1:nb.groups,N,T)) # groups time=-log(runif(N))/exp(beta1*x+beta2*y+beta3*I(z==1)) # time of event or censoring eps=sample(0:1,N,T,c(0.3,0.7)) # event or censoring data=data.frame(time,eps,x,y,z,id) # preparing the coxme model data$id_z=factor(paste(data$id,data$z,sep=-)) names=paste(rep(levels(data$id),each=2),rep(levels(data$z),nb.groups),sep=-) mat1=bdsmatrix(rep(c(1,0,0,0),nb.groups),blocksize=rep(2,nb.groups),dimnames=list(names,names)) mat2=bdsmatrix(rep(c(0,0,0,1),nb.groups),blocksize=rep(2,nb.groups),dimnames=list(names,names)) mat3=bdsmatrix(rep(c(0,1,1,0),nb.groups),blocksize=rep(2,nb.groups),dimnames=list(names,names)) varlist=coxmeMlist(list(mat1,mat2,mat3), rescale = F, pdcheck = F, positive=F) # models fit.me=coxme(Surv(time,eps) ~ x + y + z + (1 | id_z),varlist=varlist,data=data) fit.me fit.ph=coxph(Surv(time,eps) ~ x + y + z,data=data) fit.ph 1-pchisq(-2*(fit.ph$loglik[2]-fit.me$loglik[2]),3) # 0.9421373 1-pchisq(-2*(fit.ph$loglik[2]-fit.me$loglik[3]),3) # 0.5929387 If I'm not wrong, the likelihood ratio tests above indicate adding the random component is not necessary, which fits well with the way I simulated the data. Thank you again, Hugo 2012/10/8 Terry Therneau thern...@mayo.edu You are right, those look suspicious. What version of R and of the coxme package are you running? Later version of coxme use multiple starting estimates due to precisely this kind of problem. Also, when the true MLE is variance=0 the program purposely never quite gets there, in order to avoid log(0). Compare the log-lik to a fixed effects model with those covariates. I can't do more than guess without a reproducable example. Terry Therneau On 10/08/2012 05:00 AM, r-help-requ...@r-project.org wrote: Dear R users, I'm using the function coxme of the package coxme in order to build Cox models with complex random effects. Unfortunately, I sometimes get surprising estimations of the variances of the random effects. I ran models with different fixed covariates but always with the same 3 random effects defined by the argument varlist=coxmeMlist(list(mat1,**mat2,mat3), rescale = F, pdcheck = F, positive=F). I get a few times exactly the same estimations of the parameters of the random effects whereas the fixed effects of the models are different: Random effects Group Variable Std DevVariance idp Vmat.1 0.1000 0.0100 Vmat.2 0.02236068 0.0005 Vmat.3 0.02449490 0.0006 The variances are round figures, so I have the feeling that the algorithm didn't succeed in fitting the model. Has anyone ever faced to this problem? Thanks, Hugo [[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 convert by lists in data.frames
You're right, I was in a hurry. This one works. x - rnorm(100) a - sample(letters[1:4], 100, T) by.list - by(x, a, summary) do.call(rbind, as.list(by.list)) (I would also prefer aggregate.) Rui Barradas Em 09-10-2012 19:46, ilai escreveu: On Tue, Oct 9, 2012 at 12:25 PM, Bert Gunter gunter.ber...@gene.com wrote: The only wrinkle here (with either rbind or simplify2array) is getting the labels correct if the design is not fully crossed -- i.e. if some groups are missing so that expand.grid() won't work. Then you might have to work harder to extract the information from by.list. Agreed. In such a case I might decide to let aggregate(breaks~wool+tension, subset(warpbreaks, wool != 'A' | tension != 'H' ), summary) sort through the headache for me, and overlook the annoying result is actually a matrix put in as a single variable in the data.frame. Personal preference maybe but that never made sense to me in the data frame construct (even if it is just a list). Cheers str(by.list) might help here. -- Bert On Tue, Oct 9, 2012 at 11:14 AM, ilai ke...@math.montana.edu wrote: On Tue, Oct 9, 2012 at 11:42 AM, Rui Barradas ruipbarra...@sapo.pt wrote: Hello, Try do.call(data.frame, by.list) I don't think data.frame inside do.call works in this context. May need it on the outside to do the job (Only OK here since there is no mixture of numeric and character/factors in this summary). Something like by.list - by(warpbreaks[, 1], warpbreaks[, -1], summary) by.dtfrm - data.frame( do.call( rbind, by.list ) ) by.dtfrm - cbind( do.call( expand.grid, attr( by.list, 'dimnames' ) ), by.dtfrm ) Hope this helps, Rui Barradas Em 09-10-2012 17:53, Jesus Frias escreveu: Dear R-helpers, I've got a summary of results from a by() call that I am making with a list of more than two of factors not very different from the example in the by() help page require(stats) by(warpbreaks[, 1], warpbreaks[, -1], summary) The result of the command gives a list of the form wool: A tension: L Min. 1st Qu. MedianMean 3rd Qu.Max. 25.00 26.00 51.00 44.56 54.00 70.00 --- wool: B tension: L Min. 1st Qu. MedianMean 3rd Qu.Max. 14.00 20.00 29.00 28.22 31.00 44.00 --- And so on. I would like to convert this result in to a flat data.frame with variable names: Wool, Tension, Min, 1stQ, Median, Mean, 3rdQ, Max A, L , 25.00 26.00 51.00 44.56 54.00 70.00 B, L, 14.00 20.00 29.00 28.22 31.00 44.00 Although I've tried the argument simplify=T I haven't been able to get this converted. Is there a simple way to achieve this? Thanks in advance! Regards, Jesus Jesús María Frías Celayeta, PhD Ceann Cúntóir, Scoil Eolaíocht an Bhia agus Sláinte an Chomhshaoil Assistant Head, School of Food Science and Environmental Health, Coláiste Eolaíochtaí agus Sláinte/ College of Sciences and Health, Institiúid Teicneolaíochta Átha Cliath/ Dublin Institute of Technology, Sráid Chathal Brugha, Baile Átha Cliath 1, Éire/Cathal Brugha Street, Dublin 1, Ireland F: +353-1-4024459 E: mailto:james.cur...@dit.ie jesus.fr...@dit.ie W: http://fseh.dit.ie/o4/StaffListing/JesusFrias.html Tá an teachtaireacht seo scanta ó thaobh ábhar agus víreas ag Seirbhís Scanta Ríomhphost de chuid Seirbhísí Faisnéise, ITBÁC agus meastar í a bheith slán. http://www.dit.ie This message has been scanned for content and viruses by the DIT Information Services E-Mail Scanning Service, and is believed to be clean. http://www.dit.ie [[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. [[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
Re: [R] Up key is not the previous command
Le lundi 08 octobre 2012 à 20:33 -0700, Peter Langfelder a écrit : run capabilities(what=cledit) in your R terminal session. If you get FALSE, your R was compiled without command line editing support which you need for the up arrow action. FWIW, it works with the R version packaged in Fedora 17 here. My two cents __ 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] synthetic distribution built upon set of discrete values
Hello, I have a vector of double values between 0 and 100 I would like to draw a synthetic distribution of this vector to see graphically how the values are distributed between 0 and 100. How can I do that ? Thomas __ 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] synthetic distribution built upon set of discrete values
?? Perhaps: ?density ?plot.density -- Bert On Tue, Oct 9, 2012 at 1:06 PM, Thomas Carrié tho...@free.fr wrote: Hello, I have a vector of double values between 0 and 100 I would like to draw a synthetic distribution of this vector to see graphically how the values are distributed between 0 and 100. How can I do that ? Thomas __ 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] car::linearHypothesis Sum of Sqaures Error?
John, Thank you. There are different means of the covariate among the levels in my contrasts, which is producing the non-orthogonality and non-additivity of the sum of squares. Should be all set. Cheers, John From: John Fox [j...@mcmaster.ca] Sent: Tuesday, October 09, 2012 4:00 PM To: John Jay Wiley Jr. Cc: r-help@r-project.org Subject: RE: [R] car::linearHypothesis Sum of Sqaures Error? Dear John, -Original Message- From: John Jay Wiley Jr. [mailto:jwile...@syr.edu] Sent: Tuesday, October 09, 2012 3:37 PM To: John Fox Cc: r-help@r-project.org Subject: RE: [R] car::linearHypothesis Sum of Sqaures Error? John, Again, thank you for your reply. Unfortunately, I didn't specify that I had previously changed the contrast options to contr.sum. I was aware of that requirement, and I still found that the sum of squares didn't add up. It seems that you made the SS add up by removing the covariate. Ultimately, the reason I moved to Anova and linearHypothesis was to deal with the covariate since Type I sum of squares produce non-orthogonality in factorial ANCOVAs. I am interested to know how you assessed the covariate as unbalanced? It is equally replicated across the groups and the variances are similar. Is there another metric I am missing for a continuous covariate? Unless the covariate mean is identical in the groups (combinations of factor levels), it is unbalanced in the sense of being correlated with the contrasts for groups. You could easily have checked that by looking the covariance matrix of the coefficients. John Cheers, John From: John Fox [j...@mcmaster.ca] Sent: Tuesday, October 09, 2012 2:59 PM To: John Jay Wiley Jr. Cc: r-help@r-project.org Subject: RE: [R] car::linearHypothesis Sum of Sqaures Error? Dear John, -Original Message- From: John Jay Wiley Jr. [mailto:jwile...@syr.edu] Sent: Tuesday, October 09, 2012 9:17 AM To: John Fox Cc: r-help@r-project.org Subject: RE: [R] car::linearHypothesis Sum of Sqaures Error? John, Thank you for the reply. The data are balanced; I double-checked. I believe the contrasts are orthogonal. Sum of squares in summary(aov) with the contrasts split out add to the main effect. I am still unsure of where the error is for the sum of squares calculation. I have written some code with a parallel model structure that may help (see below). Can linearHypothesis return type II tests? It seems to only return type III with no option to set 'type'. Cheers, John y-runif(36,0,100) block-factor(rep(c(A,B,C),each=12)) a-factor(rep(c(A,B),times=3,each=6)) b-factor(rep(c(A,B),times=6,each=3)) c-factor(rep(c(A,B,C),times=12,each=1)) covar-0.6*y+rnorm(36,10,25) data-data.frame(y,block,a,b,c,covar) c_contrasts-matrix(c(-1,2,-1,1,0,-1),3,2) dimnames(c_contrasts)-list(levels(data$c),c(B vs. AC,A vs. C)) contrasts(data$c)-c_contrasts model-lm(y~block+a*b*c+covar,data=data) summary.aov(model,split=list(c=list(B vs. AC=1,A vs. C=2))) #Sum of squares add here, but factorial ANCOVA non-orthogonal in type I SS Anova(model,type=2) Anova(model,type=3) linearHypothesis(model,c(cB vs. AC,cA vs. C)) There are two problems here: (1) the covariate isn't balanced; (2) you didn't pay attention to the contrasts for factors other than c. The default is contr.treatment, which produces terms whose contrasts are not orthogonal in the row basis of the design. So, the following two ANOVAs (not ANCOVAs) give the same result, but the third doesn't. For balanced data, types I (sequential), II, and III tests should all be the same. --- snip -- model.2 - lm(y~block+a*b*c, data=data) anova(model.2) Anova(model.2) Anova(model.2, type=3) # incorrect --- snip -- Here's one way to get correct type III tests: --- snip -- options(contrasts=c(contr.sum, contr.poly)) model.3 - update(model.2) anova(model.3) Anova(model.3) Anova(model.3, type=3) # now all the same --- snip -- #Anova and linear hypothesis produce equal sum of squares for c main effect in type III linearHypothesis(model,cB vs. AC) linearHypothesis(model,cA vs. C) #Sum of squares of the individual contrasts do not add to the main effect of c This is a manifestation of the same problem: --- snip -- linearHypothesis(model.3, c(cB vs. AC,cA vs. C)) # SS equal to the sum of the next two linearHypothesis(model.3, cB vs. AC) linearHypothesis(model.3, cA vs. C) --- snip -- It doesn't make sense to ask whether linearHypothesis() does type II or type III tests -- it just tests directly specified linear hypotheses concerning the parameters of the model as parametrized. Anova() can formulate sets of type II and III linear hypotheses (but for
Re: [R] turn list into dataframe
Thanks! *Ben Caldwell* On Tue, Oct 9, 2012 at 10:18 AM, R. Michael Weylandt michael.weyla...@gmail.com wrote: On Tuesday, October 9, 2012, Benjamin Caldwell wrote: Thanks Arun - the different lengths in the list elements was the sticking point. Does anyone have suggestions for packages or R books on indexing/ reshaping datasets for an intermediate user like myself? Perhaps Spector on Data Manipulation in R Cheer cheers, rmw *Ben Caldwell* On Mon, Oct 8, 2012 at 3:26 PM, arun smartpink...@yahoo.com wrote: Hi, Your output suggests that the list elements have unequal lengths. The empty spaces will be occupied by NAs. I am using the first three list elements from the tapply() output: list1-list(c(2.8546, 4.0778, 5.2983, 6.3863, 7.5141, 8.5498, 9.5839, 10.6933),c(7.6810, 8.7648, 9.8382, 10.8903, 11.9840, 13.0541, 14.1132, 15.1657),c(22.0840, 30.3001, 35.2505, 42.8085, 48.5220, 52.0604, 57.9428, 61.4930, 64.4550, 67.3543, 69.8435, 72.9508, 74.4730, 76.3104)) names(list1)-c(SNRL1Core120,SNRL1Core230,VAL1.1.1NA.na30) fun1-function(x){ na.pad-function(y,len){ c(y,rep(NA,len-length(y))) } maxlen-max(sapply(x,length)) do.call(data.frame,lapply(x,na.pad,len=maxlen)) } fun1(list1) A.K. - Original Message - From: Benjamin Caldwell btcaldw...@berkeley.edu To: r-help r-help@r-project.org Cc: Sent: Monday, October 8, 2012 5:49 PM Subject: [R] turn list into dataframe Dear R users, I'm starting to use 'apply' functions rather than for loops in R, and sometimes the output is a bit different than what I want. In this case, the command was tapply(myvector,myindex,cumsum) And the output was something like this: $`SNRL1 Core 120` [1] 2.8546 4.0778 5.2983 6.3863 7.5141 8.5498 9.5839 10.6933 $`SNRL1 Core 230` [1] 7.6810 8.7648 9.8382 10.8903 11.9840 13.0541 14.1132 15.1657 $`VAL 1.1.NA.na30` [1] 22.0840 30.3001 35.2505 42.8085 48.5220 52.0604 57.9428 61.4930 64.4550 67.3543 69.8435 72.9508 74.4730 76.3104 $`VAL 1.2.NA.na15` [1] 33.8895 38.7440 41.0536 44.1581 46.4891 48.3130 51.0973 52.9241 54.6404 56.1265 57.5064 59.0745 $`VAL 1.2.NA.na30` [1] 6.6408 10.6838 13.8328 15.5435 18.3037 20.3315 22.8817 24.4481 26.4106 27.6658 29.6455 30.8490 31.8680 $`VAL 1.3.NA.na10` [1] 4.8198 7.1274 8.9536 11.5954 14.0845 15.5116 16.9462 18.1269 19.3453 20.5723 21.7122 22.8643 $`VAL 1.3.NA.na20` [1] 5.7382 8.2056 9.4489 10.8225 12.3497 13.6879 15.1077 16.3229 , That's fine, but I need the output as a dataframe. I'm not even sure what to call this list, but it has multiple entries for each item. Forgive the fact that I don't have the data for you to use, I'm wondering if anyone knows about a pre-existing function that will allow be to turn the above list form into a dataframe. Thanks *Ben Caldwell* [[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. [[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] RMySQL install on windows
I have been trying to install RMySQL on Windows 7 following the procedure at: http://biostat.mc.vanderbilt.edu/wiki/Main/RMySQL I think I have properly installed RTools and created a proper Renviron.site file saying: MYSQL_HOME=C:/Program Files/MySQL/MySQL Server 5.5 When I try to install the packages from source, I get warnings that suggest I'm still not quite with the program yet. There are comments about POSIX paths that I don't quite grasp. Can anyone give me additional hints? There seems to be a libmysql.dll in the /lib subdirectory although the install seems to be looking in the /bin directory for a file of similar name. Is this something that has changed with recent versions of MySQL that should be fixed in the RMySQL package or is it something I can work around by hand or by properly setting some environmental variable? Thanks, Rob The errors ... install.packages('RMySQL',type='source') trying URL 'http://cran.wustl.edu/src/contrib/RMySQL_0.9-3.tar.gz' Content type 'application/x-gzip' length 165363 bytes (161 Kb) opened URL downloaded 161 Kb * installing *source* package 'RMySQL' ... ** package 'RMySQL' successfully unpacked and MD5 sums checked checking for $MYSQL_HOME... C:/Program Files/MySQL/MySQL Server 5.5 cygwin warning: MS-DOS style path detected: C:/Program Preferred POSIX equivalent is: /cygdrive/c/Program CYGWIN environment variable option nodosfilewarning turns off this warning. Consult the user's guide for more details about POSIX paths: http://cygwin.com/cygwin-ug-net/using.html#using-pathnames test: Files/MySQL/MySQL: unknown operand ** libs Warning: this package has a non-empty 'configure.win' file, so building only the main architecture cygwin warning: MS-DOS style path detected: C:/PROGRA~1/R/R-215~1.1/etc/x64/Makeconf Preferred POSIX equivalent is: /cygdrive/c/PROGRA~1/R/R-215~1.1/etc/x64/Makeconf CYGWIN environment variable option nodosfilewarning turns off this warning. Consult the user's guide for more details about POSIX paths: http://cygwin.com/cygwin-ug-net/using.html#using-pathnames gcc -m64 -IC:/PROGRA~1/R/R-215~1.1/include -DNDEBUG -IC:/Program Files/MySQL/MySQL Server 5.5/include -Id:/RCompile/CRANpkg/extralibs64/local/include -O2 -Wall -std=gnu99 -mtune=core2 -c RS-DBI.c -o RS-DBI.o RS-DBI.c: In function 'RS_na_set': RS-DBI.c:1219:11: warning: variable 'c' set but not used [-Wunused-but-set-variable] gcc -m64 -IC:/PROGRA~1/R/R-215~1.1/include -DNDEBUG -IC:/Program Files/MySQL/MySQL Server 5.5/include -Id:/RCompile/CRANpkg/extralibs64/local/include -O2 -Wall -std=gnu99 -mtune=core2 -c RS-MySQL.c -o RS-MySQL.o RS-MySQL.c: In function 'RS_MySQL_fetch': RS-MySQL.c:657:13: warning: variable 'fld_nullOk' set but not used [-Wunused-but-set-variable] RS-MySQL.c: In function 'RS_DBI_invokeBeginGroup': RS-MySQL.c:1137:30: warning: variable 'val' set but not used [-Wunused-but-set-variable] RS-MySQL.c: In function 'RS_DBI_invokeNewRecord': RS-MySQL.c:1158:20: warning: variable 'val' set but not used [-Wunused-but-set-variable] RS-MySQL.c: In function 'RS_MySQL_dbApply': RS-MySQL.c:1219:38: warning: variable 'fld_nullOk' set but not used [-Wunused-but-set-variable] gcc -m64 -shared -s -static-libgcc -o RMySQL.dll tmp.def RS-DBI.o RS-MySQL.o C:/Program Files/MySQL/MySQL Server 5.5/bin/libmySQL.dll -Ld:/RCompile/CRANpkg/extralibs64/local/lib/x64 -Ld:/RCompile/CRANpkg/extralibs64/local/lib -LC:/PROGRA~1/R/R-215~1.1/bin/x64 -lR gcc.exe: error: C:/Program Files/MySQL/MySQL Server 5.5/bin/libmySQL.dll: No such file or directory ERROR: compilation failed for package 'RMySQL' * removing 'C:/Program Files/R/R-2.15.1/library/RMySQL' The downloaded source packages are in ‘C:\Users\rbaer\AppData\Local\Temp\Rtmps9adPQ\downloaded_packages’ Warning messages: 1: running command 'C:/PROGRA~1/R/R-215~1.1/bin/x64/R CMD INSTALL -l C:/Program Files/R/R-2.15.1/library C:\Users\rbaer\AppData\Local\Temp\Rtmps9adPQ/downloaded_packages/RMySQL_0.9-3.tar.gz' had status 1 2: In install.packages(RMySQL, type = source) : installation of package ‘RMySQL’ had non-zero exit status R.Version() $platform [1] x86_64-pc-mingw32 $arch [1] x86_64 $os [1] mingw32 $system [1] x86_64, mingw32 $status [1] $major [1] 2 $minor [1] 15.1 $year [1] 2012 $month [1] 06 $day [1] 22 $`svn rev` [1] 59607 $language [1] R $version.string [1] R version 2.15.1 (2012-06-22) $nickname [1] Roasted Marshmallows __ 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] Qustion about Creating a sequence of vector
Hi, You can also try this: set.seed(1) dat1-data.frame(id=rep(c(1,2,3),c(30,20,25)),value=rnorm(75,15)) dat2-data.frame(stack(lapply(split(dat1,dat1$id),FUN=function(x) 1:nrow(x))),value=dat1[,2]) colnames(dat2)[1:2]-c(seq1,id) dat2$seq1 # [1] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 #[26] 26 27 28 29 30 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 #[51] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 A.K. - Original Message - From: bibek sharma mbhpat...@gmail.com To: r-help@r-project.org Cc: Sent: Tuesday, October 9, 2012 2:54 PM Subject: [R] Qustion about Creating a sequence of vector Hello R User, I have a data set where subject( Id) are frequently measured. For example, the size of the data set is 75 by 2 and has following frequency distribution. id freq 1 30 2 20 3 25 I want to create a variable (say seq) containing sequential count for each id. I mean variable seq should be as ( 1,2,..,30, 1,2,...,20, 1,2,...,25) I use following code but did not work. Any suggestion is much appreciated.. sim-rep(NA, 90) for (i in 1:3){ d[i]-seq(1,a[i,2],by=1) sim[i]-as.vector(c(d[i]) } Thank you, Bibek __ 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] problem with convergence in mle2/optim function
Dear R help, Thanks again for the responses. I increased the lower constraint to: lower = list(p1 = 0.0001, p2 = 0.0001, mu1 = 0.0001, mu2 = 0.0001). I also included an upper box constraint of: upper = list(p1 = Inf, p2 = Inf, mu1 = p1t, mu2 = p2t). Making these changes improved the rate of convergence among stochastic simulation runs, but I still had convergence problems. I found success in switching from mle2/optim to spg (BB package). So far, spg has produced similarly precise estimates as L-BFGS-B and consistently provides parameter estimates. If anyone is interested, here is the new objective function and spg call, instead of my previous objective function and mle2 call. All other parts of my reproducible code are the same as I've previously supplied: ## library(BB) # Objective function for spg() NLL2 - function(par, y){ p1 - par[1] p2 - par[2] mu1 - par[3] mu2 - par[4] t - y$tv n1 - y$n1 n2 - y$n2 n3 - y$n3 P1 - (p1*((-1 + exp(sqrt((mu1 + mu2 + p1 + p2)^2 - 4*(mu2*p1 + mu1*(mu2 + p2)))*t))*((-mu2)*(mu2 - p1 + p2) + mu1*(mu2 + 2*p2)) - mu2*sqrt((mu1 + mu2 + p1 + p2)^2 - 4*(mu2*p1 + mu1*(mu2 + p2))) - exp(sqrt((mu1 + mu2 + p1 + p2)^2 - 4*(mu2*p1 + mu1*(mu2 + p2)))*t)* mu2*sqrt((mu1 + mu2 + p1 + p2)^2 - 4*(mu2*p1 + mu1*(mu2 + p2))) + 2*exp((1/2)*(mu1 + mu2 + p1 + p2 + sqrt((mu1 + mu2 + p1 + p2)^2 - 4*(mu2*p1 + mu1*(mu2 + p2*t)*mu2* sqrt((mu1 + mu2 + p1 + p2)^2 - 4*(mu2*p1 + mu1*(mu2 + p2)/ exp((1/2)*(mu1 + mu2 + p1 + p2 + sqrt((mu1 + mu2 + p1 + p2)^2 - 4*(mu2*p1 + mu1*(mu2 + p2*t)/(2*(mu2*p1 + mu1*(mu2 + p2))* sqrt((mu1 + mu2 + p1 + p2)^2 - 4*(mu2*p1 + mu1*(mu2 + p2 P2 - (p2*((-1 + exp(sqrt((mu1 + mu2 + p1 + p2)^2 - 4*(mu2*p1 + mu1*(mu2 + p2)))*t))*(-mu1^2 + 2*mu2*p1 + mu1*(mu2 - p1 + p2)) - mu1*sqrt((mu1 + mu2 + p1 + p2)^2 - 4*(mu2*p1 + mu1*(mu2 + p2))) - exp(sqrt((mu1 + mu2 + p1 + p2)^2 - 4*(mu2*p1 + mu1*(mu2 + p2)))*t)* mu1*sqrt((mu1 + mu2 + p1 + p2)^2 - 4*(mu2*p1 + mu1*(mu2 + p2))) + 2*exp((1/2)*(mu1 + mu2 + p1 + p2 + sqrt((mu1 + mu2 + p1 + p2)^2 - 4*(mu2*p1 + mu1*(mu2 + p2*t)*mu1* sqrt((mu1 + mu2 + p1 + p2)^2 - 4*(mu2*p1 + mu1*(mu2 + p2)/ exp((1/2)*(mu1 + mu2 + p1 + p2 + sqrt((mu1 + mu2 + p1 + p2)^2 - 4*(mu2*p1 + mu1*(mu2 + p2*t)/(2*(mu2*p1 + mu1*(mu2 + p2))* sqrt((mu1 + mu2 + p1 + p2)^2 - 4*(mu2*p1 + mu1*(mu2 + p2 P3 - 1 - P1 - P2 p.all - c(P1, P2, P3) #cat(NLL.free p.all {P1,P2,P3}\n) #print(matrix(p.all, ncol=3)) -sum(dmnom2(c(n1, n2, n3), prob = p.all, log = TRUE)) } par - c(p1t, p2t, mu1t, mu2t) spg.fit - spg(par = par, fn = NLL2, y = yt, lower = c(0.001, 0.001, 0.001, 0.001), control = list(maxit = 5000)) My next problem is that spg takes about twice as long as L-BFGS-B to converge. The spg help file strongly suggests the use of an exact gradient function to improve speed. But I am having trouble writing a gradient function. Here is what I have so far: I derived the gradient function by taking the derivative of my NLL equation with respect to each parameter. My NLL equation is the probability mass function of the trinomial distribution. Here is some reproducible code: # library(Ryacas) p1 - Sym(p1); p2 - Sym(p2); mu1 - Sym(mu1); mu2 - Sym(mu2) t - Sym(t); n1 - Sym(n1); n2 - Sym(n2); n3 - Sym(n3) P1.symb - ((p1*((-1 + exp(sqrt((mu1 + mu2 + p1 + p2)^2 - 4*(mu2*p1 + mu1*(mu2 + p2)))*t))*((-mu2)*(mu2 - p1 + p2) + mu1*(mu2 + 2*p2)) - mu2*sqrt((mu1 + mu2 + p1 + p2)^2 - 4*(mu2*p1 + mu1*(mu2 + p2))) - exp(sqrt((mu1 + mu2 + p1 + p2)^2 - 4*(mu2*p1 + mu1*(mu2 + p2)))*t)* mu2*sqrt((mu1 + mu2 + p1 + p2)^2 - 4*(mu2*p1 + mu1*(mu2 + p2))) + 2*exp((1/2)*(mu1 + mu2 + p1 + p2 + sqrt((mu1 + mu2 + p1 + p2)^2 - 4*(mu2*p1 + mu1*(mu2 + p2*t)*mu2* sqrt((mu1 + mu2 + p1 + p2)^2 - 4*(mu2*p1 + mu1*(mu2 + p2)/ exp((1/2)*(mu1 + mu2 + p1 + p2 + sqrt((mu1 + mu2 + p1 + p2)^2 - 4*(mu2*p1 + mu1*(mu2 + p2*t)/(2*(mu2*p1 + mu1*(mu2 + p2))* sqrt((mu1 + mu2 + p1 + p2)^2 - 4*(mu2*p1 + mu1*(mu2 + p2) P2.symb - ((p2*((-1 + exp(sqrt((mu1 + mu2 + p1 + p2)^2 - 4*(mu2*p1 + mu1*(mu2 + p2)))*t))*(-mu1^2 + 2*mu2*p1 + mu1*(mu2 - p1 + p2)) - mu1*sqrt((mu1 + mu2 + p1 + p2)^2 - 4*(mu2*p1 + mu1*(mu2 + p2))) - exp(sqrt((mu1 + mu2 + p1 + p2)^2 - 4*(mu2*p1 + mu1*(mu2 + p2)))*t)* mu1*sqrt((mu1 + mu2 + p1 + p2)^2 - 4*(mu2*p1 + mu1*(mu2 + p2))) + 2*exp((1/2)*(mu1 + mu2 + p1 + p2 + sqrt((mu1 + mu2 + p1 + p2)^2 - 4*(mu2*p1 + mu1*(mu2 + p2*t)*mu1* sqrt((mu1 + mu2 + p1 + p2)^2 - 4*(mu2*p1 + mu1*(mu2 + p2)/ exp((1/2)*(mu1 + mu2 + p1 + p2 + sqrt((mu1 + mu2 + p1 + p2)^2 - 4*(mu2*p1 + mu1*(mu2 + p2*t)/(2*(mu2*p1 + mu1*(mu2 + p2))* sqrt((mu1 + mu2 + p1 + p2)^2 -
[R] Error in if (is.na(n) || n 65536L) stop(size cannot be NA nor exceed 65536) : missing value where TRUE/FALSE needed
Dear useRs, i am using NbClust to determine appropriate number of cluster for hclustering. i am consistently getting the following error Error in if (is.na(n) || n 65536L) stop(size cannot be NA nor exceed 65536) : missing value where TRUE/FALSE needed Does any one know where i am wrong?? thanks in advance eliza [[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] Error in if (is.na(n) || n 65536L) stop(size cannot be NA nor exceed 65536) : missing value where TRUE/FALSE needed
On Tue, Oct 9, 2012 at 4:37 PM, eliza botto eliza_bo...@hotmail.com wrote: Dear useRs, i am using NbClust to determine appropriate number of cluster for hclustering. i am consistently getting the following error Error in if (is.na(n) || n 65536L) stop(size cannot be NA nor exceed 65536) : missing value where TRUE/FALSE needed It looks like your variable 'n' is NULL. I am not familiar with NbClust but if I had to guess, my guess would be that it expects a matrix with 2 dimensions (one of which is 'n'), and you are giving it an argument whose 'dim' is NULL (perhaps you think you have a data.frame but it is in fact a list? Or instead of a matrix you give a vector (or distance)?) If you give us more information (and reproducible code!), we can help you more. HTH Peter __ 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] Error in if (is.na(n) || n 65536L) stop(size cannot be NA nor exceed 65536) : missing value where TRUE/FALSE needed
Thankyou very much peter, here is the code filelist = list.files(pattern = .*.txt) datalist = lapply(filelist, function(x)read.table(x, header=T)) datafr = do.call(cbind, datalist) x-datafr colnames(x) - c(1: 38) m=matrix(x, nrow=365) mat1-mlist1-list() for(i in 1:ncol(mat1)){ list1[[i]]-t(apply(mat1,1,function(x) x[i]-x)) list1} x-list1 x-matrix(unlist(x),ncol=1444) x-abs(x) y-colSums(x, na.rm=FALSE) z-matrix(y, ncol=38) NbClust(m, diss=z, distance = NULL, min.nc=2, max.nc=15, method = ward, index = all, alphaBeale = 0.1) thanks once againeliza Date: Tue, 9 Oct 2012 16:47:18 -0700 Subject: Re: [R] Error in if (is.na(n) || n 65536L) stop(size cannot be NA nor exceed 65536) : missing value where TRUE/FALSE needed From: peter.langfel...@gmail.com To: eliza_bo...@hotmail.com CC: r-help@r-project.org On Tue, Oct 9, 2012 at 4:37 PM, eliza botto eliza_bo...@hotmail.com wrote: Dear useRs, i am using NbClust to determine appropriate number of cluster for hclustering. i am consistently getting the following error Error in if (is.na(n) || n 65536L) stop(size cannot be NA nor exceed 65536) : missing value where TRUE/FALSE needed It looks like your variable 'n' is NULL. I am not familiar with NbClust but if I had to guess, my guess would be that it expects a matrix with 2 dimensions (one of which is 'n'), and you are giving it an argument whose 'dim' is NULL (perhaps you think you have a data.frame but it is in fact a list? Or instead of a matrix you give a vector (or distance)?) If you give us more information (and reproducible code!), we can help you more. HTH Peter [[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] Constant Error in R
Hi good R folks, I am hoping that you could help me resolve this issue. I tried finding answers online but to no avail. I keep getting this Error in x^2 : non-numeric argument to binary operator using multiple different codes, ones which have been verified to work by my professor and other students. I tried reinstalling R completely and it still didn't fix the issue. I am using the latest version and Mac 10.8.2. Thank you! I am posting the code where the error occurred below: library(foreign) library(lmtest) library(car) x.1 - runif(1000,0,1) x.2 - rbinom(1000,1,.5) b.1 - 10 b.2 - 2 mu - 1+(x.1*b.1) + (x.2*b.2) Z - cbind(x.1) gamma - 10 sigma2 - exp(2+Z*gamma) y - mu +rnorm(1000) * sqrt(sigma2) lm.y-lm(y~x.1+x.2) Error in x^2 : non-numeric argument to binary operator summary(lm.y) -- View this message in context: http://r.789695.n4.nabble.com/Constant-Error-in-R-tp4645630.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] Error in matrix (unlist(value, recursive = FALSE, use.names = FALSE), nrow = nr, : attempt to set an attribute on NULL
I am using Donlp2 package to solve a non-linear problem, but there's an error I always meet: Error in matrix(unlist(value, recursive = FALSE, use.names = FALSE), nrow = nr, : attempt to set an attribute on NULL I have been suffering from this bug for a long time. I'll be very grateful if somebody could help me -_- -- View this message in context: http://r.789695.n4.nabble.com/Error-in-matrix-unlist-value-recursive-FALSE-use-names-FALSE-nrow-nr-attempt-to-set-an-attribute-on-L-tp4645633.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] Error in if (is.na(n) || n 65536L) stop(size cannot be NA nor exceed 65536) : missing value where TRUE/FALSE needed
Hi Eliza, this is not __reproducible__ code - how am I supposed to know what's wrong when I don't have the input files you use? Please read the help for NbClust carefully and check that all your input variables have the correct dimensions. Some of the input seems strange, for example the z matrix that contains column sums of x, and you say diss = z instead of dist = z, which would make more sense. But like I said, I am not familiar with NClust, so maybe I'm wrong. Peter On Tue, Oct 9, 2012 at 4:53 PM, eliza botto eliza_bo...@hotmail.com wrote: Thankyou very much peter, here is the code filelist = list.files(pattern = .*.txt) datalist = lapply(filelist, function(x)read.table(x, header=T)) datafr = do.call(cbind, datalist) x-datafr colnames(x) - c(1: 38) m=matrix(x, nrow=365) mat1-m list1-list() for(i in 1:ncol(mat1)){ list1[[i]]-t(apply(mat1,1,function(x) x[i]-x)) list1} x-list1 x-matrix(unlist(x),ncol=1444) x-abs(x) y-colSums(x, na.rm=FALSE) z-matrix(y, ncol=38) NbClust(m, diss=z, distance = NULL, min.nc=2, max.nc=15, method = ward, index = all, alphaBeale = 0.1) thanks once again eliza Date: Tue, 9 Oct 2012 16:47:18 -0700 Subject: Re: [R] Error in if (is.na(n) || n 65536L) stop(size cannot be NA nor exceed 65536) : missing value where TRUE/FALSE needed From: peter.langfel...@gmail.com To: eliza_bo...@hotmail.com CC: r-help@r-project.org On Tue, Oct 9, 2012 at 4:37 PM, eliza botto eliza_bo...@hotmail.com wrote: Dear useRs, i am using NbClust to determine appropriate number of cluster for hclustering. i am consistently getting the following error Error in if (is.na(n) || n 65536L) stop(size cannot be NA nor exceed 65536) : missing value where TRUE/FALSE needed It looks like your variable 'n' is NULL. I am not familiar with NbClust but if I had to guess, my guess would be that it expects a matrix with 2 dimensions (one of which is 'n'), and you are giving it an argument whose 'dim' is NULL (perhaps you think you have a data.frame but it is in fact a list? Or instead of a matrix you give a vector (or distance)?) If you give us more information (and reproducible code!), we can help you more. HTH Peter __ 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] Constant Error in R
On Oct 9, 2012, at 2:30 PM, bobo wrote: Hi good R folks, I am hoping that you could help me resolve this issue. I tried finding answers online but to no avail. I keep getting this Error in x^2 : non-numeric argument to binary operator using multiple different codes, ones which have been verified to work by my professor and other students. I tried reinstalling R completely and it still didn't fix the issue. I am using the latest version and Mac 10.8.2. Thank you! I am posting the code where the error occurred below: library(foreign) library(lmtest) library(car) x.1 - runif(1000,0,1) x.2 - rbinom(1000,1,.5) b.1 - 10 b.2 - 2 mu - 1+(x.1*b.1) + (x.2*b.2) Z - cbind(x.1) gamma - 10 sigma2 - exp(2+Z*gamma) y - mu +rnorm(1000) * sqrt(sigma2) lm.y-lm(y~x.1+x.2) Error in x^2 : non-numeric argument to binary operator Well, something is strange here. Your error message is stating that the interpreter was unable to find x^2, but you have no x^2 expression in your code. I ran the code (except for the library calls which were clearly not needed for those commands. No error. I then loaded the packages and re-ran the code. Again, no errors. summary(lm.y) You probably need to restart R with the --vanilla option or if you are using a GUI, locate and rename the .Rdata file and then restart. If the error persist, you should post sessionInfo() results. -- 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] RMySQL install on windows
On Tue, Oct 9, 2012 at 5:08 PM, Robert Baer rb...@atsu.edu wrote: I have been trying to install RMySQL on Windows 7 following the procedure at: http://biostat.mc.vanderbilt.edu/wiki/Main/RMySQL I think I have properly installed RTools and created a proper Renviron.site file saying: MYSQL_HOME=C:/Program Files/MySQL/MySQL Server 5.5 When I try to install the packages from source, I get warnings that suggest I'm still not quite with the program yet. There are comments about POSIX paths that I don't quite grasp. Can anyone give me additional hints? There seems to be a libmysql.dll in the /lib subdirectory although the install seems to be looking in the /bin directory for a file of similar name. Is this something that has changed with recent versions of MySQL that should be fixed in the RMySQL package or is it something I can work around by hand or by properly setting some environmental variable? Thanks, Rob The errors ... install.packages('RMySQL',type='source') trying URL 'http://cran.wustl.edu/src/contrib/RMySQL_0.9-3.tar.gz' Content type 'application/x-gzip' length 165363 bytes (161 Kb) opened URL downloaded 161 Kb * installing *source* package 'RMySQL' ... ** package 'RMySQL' successfully unpacked and MD5 sums checked checking for $MYSQL_HOME... C:/Program Files/MySQL/MySQL Server 5.5 cygwin warning: MS-DOS style path detected: C:/Program Preferred POSIX equivalent is: /cygdrive/c/Program CYGWIN environment variable option nodosfilewarning turns off this warning. Consult the user's guide for more details about POSIX paths: http://cygwin.com/cygwin-ug-net/using.html#using-pathnames test: Files/MySQL/MySQL: unknown operand ** libs Warning: this package has a non-empty 'configure.win' file, so building only the main architecture cygwin warning: MS-DOS style path detected: C:/PROGRA~1/R/R-215~1.1/etc/x64/Makeconf Preferred POSIX equivalent is: /cygdrive/c/PROGRA~1/R/R-215~1.1/etc/x64/Makeconf CYGWIN environment variable option nodosfilewarning turns off this warning. Consult the user's guide for more details about POSIX paths: http://cygwin.com/cygwin-ug-net/using.html#using-pathnames gcc -m64 -IC:/PROGRA~1/R/R-215~1.1/include -DNDEBUG -IC:/Program Files/MySQL/MySQL Server 5.5/include -Id:/RCompile/CRANpkg/extralibs64/local/include -O2 -Wall -std=gnu99 -mtune=core2 -c RS-DBI.c -o RS-DBI.o RS-DBI.c: In function 'RS_na_set': RS-DBI.c:1219:11: warning: variable 'c' set but not used [-Wunused-but-set-variable] gcc -m64 -IC:/PROGRA~1/R/R-215~1.1/include -DNDEBUG -IC:/Program Files/MySQL/MySQL Server 5.5/include -Id:/RCompile/CRANpkg/extralibs64/local/include -O2 -Wall -std=gnu99 -mtune=core2 -c RS-MySQL.c -o RS-MySQL.o RS-MySQL.c: In function 'RS_MySQL_fetch': RS-MySQL.c:657:13: warning: variable 'fld_nullOk' set but not used [-Wunused-but-set-variable] RS-MySQL.c: In function 'RS_DBI_invokeBeginGroup': RS-MySQL.c:1137:30: warning: variable 'val' set but not used [-Wunused-but-set-variable] RS-MySQL.c: In function 'RS_DBI_invokeNewRecord': RS-MySQL.c:1158:20: warning: variable 'val' set but not used [-Wunused-but-set-variable] RS-MySQL.c: In function 'RS_MySQL_dbApply': RS-MySQL.c:1219:38: warning: variable 'fld_nullOk' set but not used [-Wunused-but-set-variable] gcc -m64 -shared -s -static-libgcc -o RMySQL.dll tmp.def RS-DBI.o RS-MySQL.o C:/Program Files/MySQL/MySQL Server 5.5/bin/libmySQL.dll -Ld:/RCompile/CRANpkg/extralibs64/local/lib/x64 -Ld:/RCompile/CRANpkg/extralibs64/local/lib -LC:/PROGRA~1/R/R-215~1.1/bin/x64 -lR gcc.exe: error: C:/Program Files/MySQL/MySQL Server 5.5/bin/libmySQL.dll: No such file or directory ERROR: compilation failed for package 'RMySQL' * removing 'C:/Program Files/R/R-2.15.1/library/RMySQL' The downloaded source packages are in ‘C:\Users\rbaer\AppData\Local\Temp\Rtmps9adPQ\downloaded_packages’ Warning messages: 1: running command 'C:/PROGRA~1/R/R-215~1.1/bin/x64/R CMD INSTALL -l C:/Program Files/R/R-2.15.1/library C:\Users\rbaer\AppData\Local\Temp\Rtmps9adPQ/downloaded_packages/RMySQL_0.9-3.tar.gz' had status 1 2: In install.packages(RMySQL, type = source) : installation of package ‘RMySQL’ had non-zero exit status R.Version() $platform [1] x86_64-pc-mingw32 $arch [1] x86_64 $os [1] mingw32 $system [1] x86_64, mingw32 $status [1] $major [1] 2 $minor [1] 15.1 $year [1] 2012 $month [1] 06 $day [1] 22 $`svn rev` [1] 59607 $language [1] R $version.string [1] R version 2.15.1 (2012-06-22) $nickname [1] Roasted Marshmallows __ 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. Most people who have problems have them because they followed instructions on the internet rather than the ones that come with the package. Go to:
Re: [R] How to write out this regression equation in R?
But sprintf is itself vectorized. If you give it vectors, it returns vectors. So you could obtain that apply-result more efficiently by passing a bunch of column vectors of data. There happens to be a convenient object called a data frame that holds a bunch of similar-length vectors. DF - data.frame( m=c(1,2), b=c(-3,4) ) result - sprintf( y=(%d)*x+(%d), DF$m, DF$b) cat(paste(result, collapse=\n)) --- 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. S Ellison s.elli...@lgcgroup.com wrote: How to make R write out: Balance = 2 + 3 * IntGDP + 5 * IntUnemployment + 0.3 * d1 from the table below: Balance Intercept IntGDP GDPNum IntUnemployment IntInflationd1 d2 d3 3 2 3 5 0.3 0 0 Maybe ?sprintf would help? And if you wrap that in a function that takes a vector, using apply() on the table would give you one string per row, *** 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-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] RGL package surface plot
I'm completely new at R... I have sinkhole survey data (lat, long, and elevation) and have been trying to plot a rotatable 3d plot for several hours... cannot get it right. Examples I see tend to be grid data (one elevation value per grid cell); however, my data are more random (known elevations at known (but random) x-y positions). Data format is tab separated, i.e.: lat long elev 3443 2 36.832.54 6.2 ...etc... please help! arik -- View this message in context: http://r.789695.n4.nabble.com/RGL-package-surface-plot-tp4645642.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] Qustion about Creating a sequence of vector
HI,By customising sequence(), set.seed(1) dat1-data.frame(id=rep(c(1,2,3),c(30,20,25)),value=rnorm(75,15)) #Either dat1$seq1-unlist(sapply(table(dat1$id),FUN=function(x) 1:x),use.names=FALSE) #or dat1$seq1-unlist(sapply(count(dat1$id)$freq,FUN=function(x) seq_len(x))) #can be used. A.K. - Original Message - From: William Dunlap wdun...@tibco.com To: bibek sharma mbhpat...@gmail.com; r-help@r-project.org r-help@r-project.org Cc: Sent: Tuesday, October 9, 2012 3:27 PM Subject: Re: [R] Qustion about Creating a sequence of vector sequence(c(4,2,0,10)) [1] 1 2 3 4 1 2 1 2 3 4 5 6 7 8 9 10 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 bibek sharma Sent: Tuesday, October 09, 2012 11:54 AM To: r-help@r-project.org Subject: [R] Qustion about Creating a sequence of vector Hello R User, I have a data set where subject( Id) are frequently measured. For example, the size of the data set is 75 by 2 and has following frequency distribution. id freq 1 30 2 20 3 25 I want to create a variable (say seq) containing sequential count for each id. I mean variable seq should be as ( 1,2,..,30, 1,2,...,20, 1,2,...,25) I use following code but did not work. Any suggestion is much appreciated.. sim-rep(NA, 90) for (i in 1:3){ d[i]-seq(1,a[i,2],by=1) sim[i]-as.vector(c(d[i]) } Thank you, Bibek __ 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] RGL package surface plot
On Oct 9, 2012, at 5:41 PM, ariklee wrote: I'm completely new at R... I have sinkhole survey data (lat, long, and elevation) and have been trying to plot a rotatable 3d plot for several hours... cannot get it right. Examples I see tend to be grid data (one elevation value per grid cell); however, my data are more random (known elevations at known (but random) x-y positions). Data format is tab separated, i.e.: lat long elev 3443 2 36.832.54 6.2 ...etc... Sounds like you want to fit some sort of 2-D manifold best fit function to a set of points, but you have not provided enough information to construct a solution. please help! Cries of desperation are no substitute for complete data and problem description. -- David. 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] RGL package surface plot
You should help us per the posting guide reproducible sample data, code you have tried that you thought would work, why you think it did not, output of sessionInfo function... Note that you can learn a lot by doing this exercise, your problem may not be where you think it is (or where we might guess it is) See http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example --- 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. ariklee eric.kra...@respec.com wrote: I'm completely new at R... I have sinkhole survey data (lat, long, and elevation) and have been trying to plot a rotatable 3d plot for several hours... cannot get it right. Examples I see tend to be grid data (one elevation value per grid cell); however, my data are more random (known elevations at known (but random) x-y positions). Data format is tab separated, i.e.: lat long elev 3443 2 36.832.54 6.2 ...etc... please help! arik -- View this message in context: http://r.789695.n4.nabble.com/RGL-package-surface-plot-tp4645642.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] Finding the p value of the intercept in model 2 regression
Hello, Please excuse my ignorance; my statistical background is fairly poor. I am looking to do a model II regression in R, and determine if the intercept is significantly greater then 0. I have downloaded the package lmodel2, which gives me the 95% confidence interval of the intercept. Although this is sufficient to determine if my intercepts are greater then 0, I would really like to have the p value of my intercept. Is there a way to get the p value of the intercept in a model II regression using lmodel2, or is there a way I can calculate it? Any help would be greatly appreciated, -Dylan -- View this message in context: http://r.789695.n4.nabble.com/Finding-the-p-value-of-the-intercept-in-model-2-regression-tp4645651.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] Legend Truncated Using filled.contour
This worked perfectly, thank you! (Sorry for the delay, was traveling and didn't get a chance to test it until now.) Kirsten On Oct 4, 2012, at 1:30 PM, David Winsemius dwinsem...@comcast.net wrote: On Oct 3, 2012, at 12:58 PM, Kirsten wrote: Hey everyone, I'm working on a contour plot depicting asymptomatic prevalence at varying durations of infectiousness and force of infection. I've been able to work everything out except for this one - my legend title keeps getting cut off. Here's what I have: filled.contour(x=seq(2,30,length.out=nrow(asym_matrix)), y=seq(1,2,length.out=ncol(asym_matrix)), asym_matrix, color = function(x)rev(heat.colors(x)), plot.title = title(main=Asymptomatic Prevalence in 0-4 Year Olds with\n Increasing Duration of Infectiousness, xlab = Duration of Infectiousness, ylab = Relative Force of Infection), key.title = title(main = Asymptomatic\n Prevalence)) My first thought was to make the legend title text smaller using cex = 0.75 (or similar), but it doesn't change the text size at all. In fact, none of the modifiers that I've tried to add to the key.title line (size, color, font, etc) seems to be making a bit of difference. key.title = title(main = Asymptomatic\n Prevalence, cex = 0.75) I couldn't see it until now (that I got your csv file) but you should not be qusoting the cex parameter. Also it should be `cex.main` rather than just `cex`. As explained in the filled.contour help page (which you clearly have read) the legend is really a second plot and you should be using the title function(as you clearly have figured out.) But the details and examples are in ?title . Try: ..., key.title = title(main = Asymptomatic\n Prevalence, cex.main=0.70) ) # 0.75 still got cut off a bit. =, and I think we are both on Macs so this should be the same on a default quartz() window. I assume there's an override earlier in the code, but I have no idea what it is. Any suggestions? People who choose to go to Nabble , a distinctly smaller group, would have been able to find you data, but most people could not. You should have used a .txt extension so you mailer would not improperly label it as something other than MIME-text. Or you could have simply copied the output of dput() into your email. -- 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.