Re: [R] how to transform a data file
Hi option 3 library(reshape) melt(d, id.vars=id) Regards Petr Hi PJ, Try # some data id - 1:20 m - matrix(sample(0:1, 200, TRUE), ncol = 10) colnames(m) - paste('V', 1:10, sep = ) d - data.frame(id, m) d # option 1 cbind(rep(d$id, each = ncol(d)-1), matrix(unlist(t(d[,-1])), ncol = 1)) # option 2 cbind(rep(d$id, each = ncol(d) - 1), stack(d[,-1])[,-2]) HTH, Jorge.- On Mon, Nov 28, 2011 at 10:19 PM, pat j wrote: Hello R people, I have a data file with 101 numeric variables: one variable called IDN (the individual's unique id number, which I need to retain, and which ranges from 1000 to 1320; some numbers are obviously skipped), and V1 to V100 (each has a value of 0 or 1; these 100 variables represent sequentially ordered days and whether a characteristic was present or absent--e.g., v1 is day 1 and a 1 means the characteristic is present; v10 is day 10 and 0 means the characteristic is absent). This may be child's play for many on this list, but how do I transform this data file to two columns, one called id and another column named c with 100 rows? I think it will end up being a 1000 row file. I've read some and think that I'm trying to melt my existing data. I can transpose the v1 to v100 with t(v1 to v100) but then I'm unclear on how to automatically generate 100 identical IDN's for each case and variable and then put them together. This may be redundant, but for the sake of clarity, what I'm trying to do is get from this: IDN V1 V2 V3 … V100 1 0 1 0 . . . 1 2 1 1 1 . . . 0 40 1 0 . . . 1 . . 100 0 1 0 . . . 1 To this: id c 10 11 10 . . .[continue 96 more times for c4 - c100] 1 1 2 1 2 1 2 1 . . . [continue 96 more times for c4 - c100] 2 0 . . . [then repeat this for the next 98 cases] 1000 1 0 1 Thank you very much. PJ [[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-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Transforming a string into a command
On Nov 29, 2011, at 2:00 AM, Xu Wang wrote: Why don't the following two commands work? eval(parse(text=s)) eval(as.expression(s)) Hm, try to set an object s before calling. Regards Petr __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] cumsum in 3d arrays
Yes exactly what I want! Thank you very much for your help. -- View this message in context: http://r.789695.n4.nabble.com/cumsum-in-3d-arrays-tp4110470p4118432.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] Inlcudung classes in de contigency table + dataoverflow
Hello Everybody, I'm making a contigency table with a dataset which looks like: ClassSizeMember1 Members2 Members3 etc. 1 2 A B 0 2 3 C D A 3 3 B A D 4 3 D AB etc. I make the contigency table with the ftab() function I already found that I can 'export' the table when I use the is.table() function. However I would also want to inlcude which class is with which frequency. So the result I would like to have: size Var1Var2 Var3 freq clas 2 A B 01 1 3C D A1 2 3 B A D2 3,4 Is this possible? Another question: I've got a dataset with about 40 collums and about 2 rows. Whenever I try to make a contigency table with all my data I get the next error: Error in vector(integer, length) : vector size cannot be NA In addition: Warning messages: 1: In pd * (as.integer(cat) - 1L) : NAs produced by integer overflow 2: In pd * nl : NAs produced by integer overflow Could anyone help me with this? Thank you -- View this message in context: http://r.789695.n4.nabble.com/Inlcudung-classes-in-de-contigency-table-dataoverflow-tp4118302p4118302.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] Sum matrix by rows, conditional on value
Yes, that worked for me. Thank you. On Mon, Nov 28, 2011 at 10:16 PM, David Winsemius dwinsem...@comcast.netwrote: On Nov 29, 2011, at 1:08 AM, Katrina Bennett wrote: I'd like to sum a matrix only where the matrix meets a specific condition. The matrix has 365 rows and about 50,000 columns. If you describe the meaning attached to the data if might help readers understand what the acceptable options might be. (Please read the Posting Guide.) str(cdem.mat.yr) num [1:365, 1:41772] -43.5 -48.4 -45.9 -38.4 -32 ... I'm having trouble replicating this because it is not working out for me, so I'm unsure I can provide an solid working example (apologies). I would like to subset my matrix where the values are greater than zero. I can do this easily using the following command to generate a matrix of TRUE/FALSE conditions. thaw.index - subset(cdem.mat.yr 0) Are you hoping to subset particular rows? If not, then you can make a copy and then set the negative values to NA thaw.mat -cdem.mat.yr is.na(thaw.mat)- thaw.mat 0 and ... rowSums(thaw.mat, na.rm=TRUE) However, every time I then try to run apply, or rowSums to sum the matrix rows using this index, I get back errors messages or the wrong answer. I am guessing that your subset operation produced a vector and that apply or rowSums no longer makes any sense. There is a lot of values that meet this condition, so I know this issue is with my formatting of the argument. i.e. rowSums(cdem.mat.yr == thaw.index) [1] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 [66] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 [131] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 [196] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 [261] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 [326] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 thaw.index.sum - apply(cdem.mat.yr[which(cdem.**mat.yr 0)], 1, sum) Error in apply(cdem.mat.yr[which(cdem.**mat.yr 0)], 1, sum) : dim(X) must have a positive length This just provides me with one single value (I want the sum of all the rows individually) sum(apply(cdem.mat.yr, 1, function(x) x0)) If I only run the apply over the entire matrix, this works but I can't subset it according to my condition. apply(cdem.mat.yr, 1, sum) [1] -1834000.521 -2038684.652 -1932676.585 -1619369.113 -1353598.426 -1190377.640 -1263541.796 -1438280.178 -1472440.385 -1714465.774 [11] -1945920.377 -2163888.712 -1836656.208 -1772994.790 -1864650.604 -1633144.043 -1580619.187 -1684046.620 -1769963.843 -1787676.116 [21] -1643345.342 -1497455.795 -1580307.433 -1483559.628 -1531067.546 -1557093.271 -1363626.528 -1160882.203 -1118893.494 -1352922.958 [31] -1441715.250 -1539084.024 -1717835.433 -1806727.136 -1887120.912 -1645721.673 -1310700.520 -1531408.644 -1582011.715 -1460538.996 [41] -1192880.165 -121.092 -1190390.732 -1241594.368 -1180704.394 -1025346.594 -1073581.060 -889662.991 -798735.050 -784632.707 [51] -874676.120 -957186.890 -1054610.980 -1067208.121 -1222859.353 -1477327.599 -1635653.310 -1696308.770 -1473630.951 -1283105.867 [61] -1061390.704 -811017.224 -875804.422 -851608.811 -948160.325 -1440351.359 -1206523.958 -1143659.246 -1405071.144 -1421438.254 [71] -1374929.105 -1336184.952 -1237185.588 -1082307.120 -1019742.616 -958257.706 -888078.311 -790481.841 -821010.686 -907205.025 [81] -966761.676 -926937.928 -908394.310 -976085.444 -971934.490 -703952.655 -521541.649 -625973.624 -743458.875 -631452.421 [91] -584709.631 -565843.210 -604252.152 -616885.977 -522011.655 -576824.263 -726170.003 -822902.735 -897385.940 -668897.194 [101] -525227.323 -493291.723 -559480.809 -627790.133 -607923.974 -535240.664 -346627.878 -343257.607 -287171.179 -324723.615 [111] -389052.208 -420393.385 -498589.819 -542040.688 -394442.745 -183163.637 -126540.029 -186213.012 -179799.971 -364410.639 [121] -309555.880 -357052.251 -321362.137 -394878.460 -498785.071 -309942.686 -276417.534 -337700.381 -304804.510 -238100.600 [131] -261210.843 -201821.616 -299377.673 -232015.614 -121752.676 -154925.661 -145809.72915840.738 145755.754 -33601.212 [141] -24323.63035036.73155156.44148603.82487203.646 139653.449 111722.558 101036.307 153884.464 153151.263 [151] 112680.914 108730.812 110198.055 127087.03377174.238 -67632.638 -35129.97656801.006 6712.631 8838.200 [161]40086.874 -29691.225 -55861.564
Re: [R] Transforming a string into a command
David, Did my reply get orphaned or are you trying to help me realize that asking why something does not work is not a straightforward question? I'll try to cover both bases. I'll focus just on the first case that I don't understand. Suppose we have s- ln(a+b) a-1 b-2 eval(parse(text=s)) Error in eval(expr, envir, enclos) : could not find function ln Perhaps it's because I don't understand eval well (any good references for reading up on eval, parse, substitute, etc.?). But I expected it to produce the same as the following line: eval(parse(text=ln(a+b))) Xu David Winsemius wrote On Nov 29, 2011, at 2:00 AM, Xu Wang wrote: Why don't the following two commands work? eval(parse(text=s)) eval(as.expression(s)) Can you think of anything else we might need to know in order to answer that question? -- David Winsemius, MD West Hartford, CT __ R-help@ mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- View this message in context: http://r.789695.n4.nabble.com/Transforming-a-string-into-a-command-tp4112183p4118294.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] window manager interface commands for linux
On Mon, 28-Nov-2011 at 12:07PM +0100, Ana wrote: | How can i replicate this in Linux: | source(file.choose()) | As the Mac people used to say ungrammatically: Think Different. There are many ways of using Linux that can't be done in Windows and we know nothing of your setup, so it's not obvious what's most appropriate for you. Maybe something like the following: Start R from the directory you wish to use, preferably using ESS which will give you a separate Emacs window where you run your R commands. Otherwise open a second tab in your terminal window (which will automatically be the same directory). A Terminal window will thus be available where you can list your files, say with ls or ll. Paste the file name (using only the mouse) into your R command window. Takes lots of words to describe, but very easy to do. There are many variations on that idea. HTH -- ~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~. ___Patrick Connolly {~._.~} Great minds discuss ideas _( Y )_ Average minds discuss events (:_~*~_:) Small minds discuss people (_)-(_) . Eleanor Roosevelt ~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] md.pattern ('mice') failure with more than 31 variables
Hello How come that the function md.pattern() from package 'mice' delivers a warning when run over data sets with more than 31 variables? library( 'mice' ) x - as.data.frame( matrix( sample( c(1:3, 1:3, 1:3, NA), 7000, repl=TRUE ), ncol=35, dimnames=list(NULL, paste('V', 11:45, sep=) ) ) ) md.pattern(x) # Warning message: In md.pattern(x) : NAs introduced by coercion md.pattern(x[, 1:31]) # fine Thanks, *S* -- Sascha Vieweg, saschav...@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] window manager interface commands for linux
Le lundi 28 novembre 2011 à 12:07 +0100, Ana a écrit : How can i replicate this in Linux: source(file.choose()) I've tried source(tkgetOpenFile()) but with no luck Try this instead (it works here): source(tclvalue(tkgetOpenFile())) Cheers __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Transforming a string into a command
Hi Did my reply get orphaned or are you trying to help me realize that asking why something does not work is not a straightforward question? I'll try to cover both bases. I'll focus just on the first case that I don't understand. Suppose we have s- ln(a+b) a-1 b-2 eval(parse(text=s)) Error in eval(expr, envir, enclos) : could not find function ln What is function ln supposed to do and to what package it belongs. I get ?ln No documentation for ‘ln’ in specified packages and libraries: you could try ‘??ln’ but it does not mean that ln is not used elsewhere. Regards Petr Perhaps it's because I don't understand eval well (any good references for reading up on eval, parse, substitute, etc.?). But I expected it to produce the same as the following line: eval(parse(text=ln(a+b))) Xu David Winsemius wrote On Nov 29, 2011, at 2:00 AM, Xu Wang wrote: Why don't the following two commands work? eval(parse(text=s)) eval(as.expression(s)) Can you think of anything else we might need to know in order to answer that question? -- David Winsemius, MD West Hartford, CT __ R-help@ mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- View this message in context: http://r.789695.n4.nabble.com/Transforming- a-string-into-a-command-tp4112183p4118294.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] Combining histograms and distribution curve
Dear Sir, I am reviewing a group of patients who had a surgical procedure. The histogram of the age frequency has a bimodal distribution. I am trying to emphasise this by adding a distribution curve on the histogram. Let's say the ages are 8, 9, 7, 6, 7, 8, 5, 4, 16, 12, 11, 10, 8, 7, 9 for example. How can I plot a histogram with a distribution curve on it? Your help is highly appreciated. Ivo [[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] Transforming a string into a command
On 11/29/2011 06:30 PM, Xu Wang wrote: David, Did my reply get orphaned or are you trying to help me realize that asking why something does not work is not a straightforward question? I'll try to cover both bases. I'll focus just on the first case that I don't understand. Suppose we have s- ln(a+b) a-1 b-2 eval(parse(text=s)) Error in eval(expr, envir, enclos) : could not find function ln Perhaps it's because I don't understand eval well (any good references for reading up on eval, parse, substitute, etc.?). But I expected it to produce the same as the following line: eval(parse(text=ln(a+b))) Hi Xu, Try: s-log(a+b) a-1 b-2 eval(parse(text=s)) [1] 1.098612 There is no ln function in the base package. 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.
Re: [R] md.pattern ('mice') failure with more than 31 variables
On Tue, Nov 29, 2011 at 1:58 AM, saschav...@gmail.com wrote: Hello How come that the function md.pattern() from package 'mice' delivers a warning when run over data sets with more than 31 variables? Because 2^31 is too large of a value to be represented as an integer. The 15th line of md.pattern has the code: mdp - as.integer((r %*% (2^((1:ncol(x)) - 1))) + 1) when ncol(x) 31, 32+ - 1 = 31+, and as.integer(2^31) returns NA and gives the warning you see. Technically, the warning does not occur at the 2^... part, it is when the results are converted to integer, so if there were no missing values, r (a 0/1 matrix indicating whether a particular cell is missing) would be all zeros, and thus r %*% potentially larger value than 2^30 = 0, and you do not get any warnings. Aside from some storage inefficiency for 31 columns, I do not see any harm from from simply removing the conversion to integer. For 31 columns, the function appears to give equal results with or without the conversion, but for 31 columns, some patterns are not included when as.integer is used. Cheers, Josh library( 'mice' ) x - as.data.frame( matrix( sample( c(1:3, 1:3, 1:3, NA), 7000, repl=TRUE ), ncol=35, dimnames=list(NULL, paste('V', 11:45, sep=) ) ) ) md.pattern(x) # Warning message: In md.pattern(x) : NAs introduced by coercion md.pattern(x[, 1:31]) # fine Thanks, *S* -- Sascha Vieweg, saschav...@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. -- Joshua Wiley Ph.D. Student, Health Psychology Programmer Analyst II, ATS Statistical Consulting Group University of California, Los Angeles https://joshuawiley.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] Combining histograms and distribution curve
Hi, Try lines function to get a distribution cruve: X-c(8, 9, 7, 6, 7, 8, 5, 4, 16, 12, 11, 10, 8, 7, 9 ) hist(X, prob=TRUE) lines(density(X)) Regrads ML Le 29/11/11 11:04, gwanme...@aol.com a écrit : Dear Sir, I am reviewing a group of patients who had a surgical procedure. The histogram of the age frequency has a bimodal distribution. I am trying to emphasise this by adding a distribution curve on the histogram. Let's say the ages are 8, 9, 7, 6, 7, 8, 5, 4, 16, 12, 11, 10, 8, 7, 9 for example. How can I plot a histogram with a distribution curve on it? Your help is highly appreciated. Ivo [[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. -- Mohamed Lajnef,IE INSERM U955 eq 15# P?le de Psychiatrie# H?pital CHENEVIER # 40, rue Mesly # 94010 CRETEIL Cedex FRANCE # mohamed.laj...@inserm.fr # tel : 01 49 81 32 79 # Sec : 01 49 81 32 90 # fax : 01 49 81 30 99 # [[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] quick ANOVA question
Hello, imagine the following experimental design: Group - Value control - 5 control - 6 control - 5 treated1 - 8 treated1 - 9 treated1 - 9 treated2 - 15 treated2 - 16 treated2 - 15 treated3 - 25 treated3 - 30 treated3 - 28 What I like to know is if I apply an ANOVA to this data and choose the control group as the reference group (using the relevel function) what groups exactly are compared? Are only all treated groups 1, 2, 3 tested against the control group or are all possible combinations tested? What is compared? A) Testing: control vs treated1; control vs treated2; control vs treated3; or B) Testing: control vs treated1; control vs treated2; control vs treated3; treated1 vs treated2; treated1 vs treated3; treated2 vs treated3; Cheers -- View this message in context: http://r.789695.n4.nabble.com/quick-ANOVA-question-tp4118724p4118724.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] window manager interface commands for linux
Ana wrote: How can i replicate this in Linux: source(file.choose()) Hi Ana, There is probably some way to do this with a shell script, but I am unaware of it. If you have the marvelous Tcl-Tk scripting language on your Linux box, you could write something like this: #!/usr/bin/wish # sourceRfile a script to run an R command file # SelectFile - A module for selecting a filename from a directory # call SelectFile mask where 'mask' contains a mask or filename # default mask = * proc GetFileList filemask { set filelist [ glob -nocomplain $filemask ] return $filelist } proc StringElement cmplist { if { [ llength $cmplist ] 1 } { set cmpstring [ lindex $cmplist 0 ] set cmpchar [ lindex $cmplist 1 ] set stringlength [ string length $cmpstring ] set charlength [ string length $cmpchar ] set stringindex 0 while { $stringindex $stringlength } { set charindex 0 while { $charindex $charlength } { if { [ string index $cmpstring $stringindex ] ==\ [ string index $cmpchar $charindex ] } { return 1 } incr charindex } incr stringindex } } return 0 } proc SelectFile mask { global filename global done global rindex if { [ string length $mask ] == 0 } { set mask * } set path [ pwd ] set done 0 set filename set rindex 0 while { !$done } { frame .sff -bd 3 -relief raised label .sff.path -text $path entry .sff.name label .sff.filelabel -text Directories frame .sff.fileframe label .sff.dirlabel -text Files frame .sff.dirframe frame .sff.buttonframe listbox .sff.fileframe.flist -selectmode single \ -yscroll .sff.fileframe.yscroll set scrollbar .sff.fileframe.yscroll -relief sunken \ -command .sff.fileframe.flist yview listbox .sff.dirframe.dlist -selectmode single \ -yscroll .sff.dirframe.yscroll set scrollbar .sff.dirframe.yscroll -relief sunken \ -command .sff.dirframe.dlist yview set filelist [ GetFileList $mask ] lsort filelist set fileindex 0 foreach filein $filelist { if { [ file isfile $filein ] } { .sff.fileframe.flist insert $fileindex $filein incr fileindex } } set dirlist [ GetFileList * ] lsort dirlist set dlist [ list ] set dirindex 0 if { $path != / } { .sff.dirframe.dlist insert $dirindex .. incr dirindex } foreach dirin $dirlist { if { [ file isdirectory $dirin ] } { .sff.dirframe.dlist insert $dirindex $dirin incr dirindex } } bind .sff.fileframe.flist ButtonRelease-1 { .sff.name delete 0 end .sff.name insert 0 [ .sff.fileframe.flist get\ [ .sff.fileframe.flist curselection ] ] } button .sff.buttonframe.ok -text OK -command { if { [ llength [ .sff.dirframe.dlist curselection ] ] } { set filename [ .sff.dirframe.dlist get [ .sff.dirframe.dlist curselection ] ] } else { if { [ llength [ .sff.fileframe.flist curselection ] ] } { set filename [ .sff.fileframe.flist get [ .sff.fileframe.flist curselection ] ] } else { if { [ llength [ .sff.name get ] ] } { set filename [ .sff.name get ] } } } destroy .sff } button .sff.buttonframe.cancel -text Cancel -command { set rindex -1 set done 1 set filename destroy .sff } bind .sff.name Return { set filename [ .sff.name get ] destroy .sff } place .sff -relx 0.5 -rely 0.5 -anchor center -width 400\ -height 300 place .sff.path -relx 0.5 -rely 0.02 -anchor n place .sff.name -relx 0.5 -rely 0.12 -anchor n place .sff.filelabel -relx 0.05 -rely 0.22 place .sff.dirlabel -relx 0.55 -rely 0.22 place .sff.dirframe -relx 0.05 -rely 0.3 -relwidth 0.43\ -relheight 0.5 place .sff.fileframe -relx 0.55 -rely 0.3 -relwidth 0.43\ -relheight 0.5 place .sff.fileframe.flist -relx 0 -relwidth 0.85 -relheight 1 place .sff.fileframe.yscroll -relx 0.9 -rely 0.5\ -anchor center -relheight 1 place .sff.dirframe.dlist -relx 0 -relwidth 0.85 -relheight 1 place .sff.dirframe.yscroll -relx 0.9 -rely 0.5\ -anchor center -relheight 1 place .sff.buttonframe -relx 0.5 -rely 0.9 -anchor center pack .sff.buttonframe.ok -side left pack .sff.buttonframe.cancel -side right .sff.name insert 0 $mask focus .sff.name tkwait window .sff if { [ file isdirectory $filename ] } { cd $filename set path [ pwd ] } elseif { [ StringElement [ list $filename *?\[\] ] ] } { set mask $filename } else { set done 1 } } return $filename } wm geometry . 400x400 set Rfile [ SelectFile *.R ] exec R CMD BATCH $Rfile exit Then simply create the following file named helloR.R in the same directory: sink(helloR.out) cat(Hello, R\n) sink() chmod +x sourceRfile.tk ./sourceRfile.tk Select the file helloR.R from the resulting menu, and that file will be sourced by R. However, this is a bloody roundabout way to source a file in R. Jim __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide
[R] Read TXT file with variable separation
Hi! I have to import some TXT files into R, but the separation between the columns are made with different blank spaces, but each file use the same separation. Example: 31 104 5 0 11RUA SAO SEBASTIAO 25 BAIRRO FILETO 01 0020033854 The pattern is the same on each file. There is two sample files attached to this message. I would like to figure out how to import a single file, and the use some code to import several files (like this http://www.ats.ucla.edu/stat/r/code/read_multiple.htm) When I try read.table, I receive this: cnefe - read.table(sample1.txt, header=FALSE) Erro em scan(file, what, nmax, sep, dec, quote, skip, nlines, na.strings, : linha 1 não tinha 17 elementos Information about my session: sessionInfo()R version 2.12.1 (2010-12-16)Platform: i386-pc-mingw32/i386 (32-bit) locale:[1] LC_COLLATE=Portuguese_Brazil.1252 LC_CTYPE=Portuguese_Brazil.1252 [3] LC_MONETARY=Portuguese_Brazil.1252 LC_NUMERIC=C [5] LC_TIME=Portuguese_Brazil.1252 attached base packages:[1] stats graphics grDevices utils datasets methods base -- Atenciosamente, Raphael Saldanha saldanha.plan...@gmail.com 31 104 5 0 11AVENIDA JOSE ESTEVES BORGES 375 BAIRRO FILETO 06OLARIA 1 0010023854 31 104 5 0 11AVENIDA JOSE ESTEVES BORGES 241 BAIRRO FILETO 04CRECHE ENSINO LETRAMENTO INFANIL1 0010023854 31 104 5 0 11AVENIDA JOSE ESTEVES BORGES 225 BAIRRO FILETO 01 0010023854 31 104 5 0 11AVENIDA JOSE ESTEVES BORGES 219 BAIRRO FILETO 01 0010023854 31 104 5 0 11RUA EZEQUIEL C DOS SANTOS 10 BAIRRO FILETO 01 0010053854 31 104 5 0 11RUA JOSE TOMAZ DA CUNHA 20 BAIRRO FILETO 01 0010063854 31 104 5 0 11RUA JOSE TOMAZ DA CUNHA 26
Re: [R] how to keep row name if there is only one row selected from a data frame
Dear Community: Thank you Michael, I did it as you said. However I still have a little problem with this staff. I try my lm's in my df1's variables. Let's say: lm1 - lm( df1$vi) ~ df1$v1 + df1$v2) Then I usally type: plot(lm1, 1:4) I'd like to see in the plots obtained the name of the rownames of df1 instead of the id that R automatically assign (I see 1, 2, 3, instead of the rownames of my dataframe) How can I see the rownames in the plots? u...@host.com -- View this message in context: http://r.789695.n4.nabble.com/how-to-keep-row-name-if-there-is-only-one-row-selected-from-a-data-frame-tp895594p4118563.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] quick ANOVA question
Hi, Anova compare the means of more than two groups, in your case anova test H0 hypothisis H0: means(control)=mean(tread1)=mean(tread2)=mean(tread3), if there is at least one différence, you can identify the mean difference between groups by using post hoc test to testing your B suggestion. Regrads ML Le 29/11/11 11:49, syrvn a écrit : Hello, imagine the following experimental design: Group - Value control - 5 control - 6 control - 5 treated1 - 8 treated1 - 9 treated1 - 9 treated2 - 15 treated2 - 16 treated2 - 15 treated3 - 25 treated3 - 30 treated3 - 28 What I like to know is if I apply an ANOVA to this data and choose the control group as the reference group (using the relevel function) what groups exactly are compared? Are only all treated groups 1, 2, 3 tested against the control group or are all possible combinations tested? What is compared? A) Testing: control vs treated1; control vs treated2; control vs treated3; or B) Testing: control vs treated1; control vs treated2; control vs treated3; treated1 vs treated2; treated1 vs treated3; treated2 vs treated3; Cheers -- View this message in context: http://r.789695.n4.nabble.com/quick-ANOVA-question-tp4118724p4118724.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. -- Mohamed Lajnef,IE INSERM U955 eq 15# P?le de Psychiatrie# H?pital CHENEVIER # 40, rue Mesly # 94010 CRETEIL Cedex FRANCE # mohamed.laj...@inserm.fr # tel : 01 49 81 32 79 # Sec : 01 49 81 32 90 # fax : 01 49 81 30 99 # [[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 the lower triangle of a matrix to a symmetricmatrix
@Olivier ETERRADOSSI : I tried gdata to convert a (1x1) lower triangular matrix to full matrix and got memory problems. Especially at this step : upperTriangle(a) - lowerTrangle(a) it consumes more than 3 GB . Any ideas on how to create full matrix with efficient memory management ? -- View this message in context: http://r.789695.n4.nabble.com/how-to-convert-the-lower-triangle-of-a-matrix-to-a-symmetric-matrix-tp823271p4118621.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] problem during installing bayesQR package for R 2.14 version
I typed the following command *install.packages('bayesQR')'* to install bayesQR(my R version is 2.14) i am encountered the following error. Installing package(s) into ‘C:/Users/knreddy.IDRBTVM/Documents/R/win-library/2.14’ (as ‘lib’ is unspecified) Warning: unable to access index for repository http://essrc.hyogo-u.ac.jp/cran/bin/windows/contrib/2.14 Warning: unable to access index for repository http://www.stats.ox.ac.uk/pub/RWin/bin/windows/contrib/2.14 Warning message: In getDependencies(pkgs, dependencies, available, lib) : package ‘bayesQR’ is not available (for R version 2.14.0) pls reply me as early as possible. and also can i know i amable to access the bayesQR code.tell me the link to access the same.. THANKS IN ADVANCE. With regards Kalam Narendar Reddy Masters in Technology, University Of hyderabad. -- View this message in context: http://r.789695.n4.nabble.com/problem-during-installing-bayesQR-package-for-R-2-14-version-tp4118755p4118755.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] Read TXT file with variable separation
Raphael, This looks like fixed width format which you can read with read.fwf. In fixed width format the columns are not separated by white space (or other characters), but are identified by the positition in the file. So in your file, for example the first field looks to contained in the first 2 columns of your file (the first 2 characters of every line), the second field in the next five columns, etc. Regards, Jan Citeren Raphael Saldanha saldanha.plan...@gmail.com: Hi! I have to import some TXT files into R, but the separation between the columns are made with different blank spaces, but each file use the same separation. Example: 31 104 5 0 11RUA SAO SEBASTIAO 25 BAIRRO FILETO 01 0020033854 The pattern is the same on each file. There is two sample files attached to this message. I would like to figure out how to import a single file, and the use some code to import several files (like this http://www.ats.ucla.edu/stat/r/code/read_multiple.htm) When I try read.table, I receive this: cnefe - read.table(sample1.txt, header=FALSE) Erro em scan(file, what, nmax, sep, dec, quote, skip, nlines, na.strings, : linha 1 não tinha 17 elementos Information about my session: sessionInfo()R version 2.12.1 (2010-12-16)Platform: i386-pc-mingw32/i386 (32-bit) locale:[1] LC_COLLATE=Portuguese_Brazil.1252 LC_CTYPE=Portuguese_Brazil.1252 [3] LC_MONETARY=Portuguese_Brazil.1252 LC_NUMERIC=C [5] LC_TIME=Portuguese_Brazil.1252 attached base packages:[1] stats graphics grDevices utils datasets methods base -- Atenciosamente, Raphael Saldanha saldanha.plan...@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] problem during installing bayesQR package for R 2.14 version
You can try downloading from the CRAN master (either a pre-packaged binary or source code). There's fortran code you might need to compile if you can't get the binary to work but it should be ok. http://cran.r-project.org/web/packages/bayesQR/index.html Michael On Tue, Nov 29, 2011 at 6:03 AM, narendarreddy kalam narendarcse...@gmail.com wrote: I typed the following command *install.packages('bayesQR')'* to install bayesQR(my R version is 2.14) i am encountered the following error. Installing package(s) into ‘C:/Users/knreddy.IDRBTVM/Documents/R/win-library/2.14’ (as ‘lib’ is unspecified) Warning: unable to access index for repository http://essrc.hyogo-u.ac.jp/cran/bin/windows/contrib/2.14 Warning: unable to access index for repository http://www.stats.ox.ac.uk/pub/RWin/bin/windows/contrib/2.14 Warning message: In getDependencies(pkgs, dependencies, available, lib) : package ‘bayesQR’ is not available (for R version 2.14.0) pls reply me as early as possible. and also can i know i amable to access the bayesQR code.tell me the link to access the same.. THANKS IN ADVANCE. With regards Kalam Narendar Reddy Masters in Technology, University Of hyderabad. -- View this message in context: http://r.789695.n4.nabble.com/problem-during-installing-bayesQR-package-for-R-2-14-version-tp4118755p4118755.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] simplify source code
Hi Dennis, thank you very much. That works fine. Is there a possibility that R continue even if one of the models is not solvable? R currently terminates with an error message. greetings Christof Am 27-11-2011 01:34, schrieb Dennis Murphy: vars- c('y1', 'y2', 'y3') # Function to create the model formula by plugging in the # response y and run the model mfun- function(y) { form- as.formula(paste(y, 'cbind(1, exp(x/th))', sep = ' ~ ')) nls(form, data = dg, start = list(th = 0.3), algorithm = 'plinear') } # Generate a list of model objects: mlist- lapply(vars, mfun) __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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 to PDF file
Hi Jim, Hi Ken Am 27-11-2011 00:00, schrieb jim holtman: There is the 'pdftk' (PDF tool kit) that you will find on the web that will do the job. I have used it to both combine and split out the pages in the PDF file. yes, thx. GUI tools like www.pdfsam.org do the job too. But is there a possibility to append files directly in R. That is to invoke pdftk inside R with a shellandwait? perhaps something like for (i in ...) { ... savePlot(filename=temp.pdf, type=pdf) exec pdftk temp.pdf final.pdf cat output final.pdf } greetings Christof __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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 during installing bayesQR package for R 2.14 version
Please cc the general list in your replies. I'm not a Windows expert and there are many on this list who know far more about that OS than I and can handle your question far more ably. As I said I'm not a Windows expert so you may wish to consult the R-Windows FAQ and the R Admin Installation Manuals (both easily google-able) and take the following with a grain of salt, but you can usually install a binary directly with the install.packages() command setting repos = NULL and putting the file-path as the primary argument. E.g., on my Mac this works to install xts remove.packages(xts) library(xts) # Throws error as desired setwd(~/Downloads) install.packages(xts_0.8-2.tgz, repos = NULL) library(xts) # Success! If you downloaded a binary don't worry about compiling the Fortran code: it comes pre-compiled. Michael On Tue, Nov 29, 2011 at 6:46 AM, kalam narendar reddy narendarcse...@gmail.com wrote: thnak u sir for revert back quickly. sir what i have to do now i have downloaded the windows Binary file. what is the next step i have to follow. please help me in this regard. if fortran code is there for bayesian quantile rgression in which directory it is. My os is windows07 Thanks In advance With Regards Kalam Narendar Reddy __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] simplify source code
Look into tryCatch() for error handling. Michael On Tue, Nov 29, 2011 at 7:01 AM, Christof Kluß ckl...@email.uni-kiel.de wrote: Hi Dennis, thank you very much. That works fine. Is there a possibility that R continue even if one of the models is not solvable? R currently terminates with an error message. greetings Christof Am 27-11-2011 01:34, schrieb Dennis Murphy: vars- c('y1', 'y2', 'y3') # Function to create the model formula by plugging in the # response y and run the model mfun- function(y) { form- as.formula(paste(y, 'cbind(1, exp(x/th))', sep = ' ~ ')) nls(form, data = dg, start = list(th = 0.3), algorithm = 'plinear') } # Generate a list of model objects: mlist- lapply(vars, mfun) __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] append to PDF file
I think you are looking for the system() command. Michael On Tue, Nov 29, 2011 at 7:11 AM, Christof Kluß ckl...@email.uni-kiel.de wrote: Hi Jim, Hi Ken Am 27-11-2011 00:00, schrieb jim holtman: There is the 'pdftk' (PDF tool kit) that you will find on the web that will do the job. I have used it to both combine and split out the pages in the PDF file. yes, thx. GUI tools like www.pdfsam.org do the job too. But is there a possibility to append files directly in R. That is to invoke pdftk inside R with a shellandwait? perhaps something like for (i in ...) { ... savePlot(filename=temp.pdf, type=pdf) exec pdftk temp.pdf final.pdf cat output final.pdf } greetings Christof __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Read TXT file with variable separation
Jan, This is what I'm looking for! Very thanks! On Tue, Nov 29, 2011 at 9:24 AM, Jan van der Laan rh...@eoos.dds.nl wrote: Raphael, This looks like fixed width format which you can read with read.fwf. In fixed width format the columns are not separated by white space (or other characters), but are identified by the positition in the file. So in your file, for example the first field looks to contained in the first 2 columns of your file (the first 2 characters of every line), the second field in the next five columns, etc. Regards, Jan Citeren Raphael Saldanha saldanha.plan...@gmail.com: Hi! I have to import some TXT files into R, but the separation between the columns are made with different blank spaces, but each file use the same separation. Example: 31 104 5 0 11RUA SAO SEBASTIAO 25 BAIRRO FILETO 01 0020033854 The pattern is the same on each file. There is two sample files attached to this message. I would like to figure out how to import a single file, and the use some code to import several files (like this http://www.ats.ucla.edu/stat/r/code/read_multiple.htm) When I try read.table, I receive this: cnefe - read.table(sample1.txt, header=FALSE) Erro em scan(file, what, nmax, sep, dec, quote, skip, nlines, na.strings, : linha 1 não tinha 17 elementos Information about my session: sessionInfo()R version 2.12.1 (2010-12-16)Platform: i386-pc-mingw32/i386 (32-bit) locale:[1] LC_COLLATE=Portuguese_Brazil.1252 LC_CTYPE=Portuguese_Brazil.1252 [3] LC_MONETARY=Portuguese_Brazil.1252 LC_NUMERIC=C [5] LC_TIME=Portuguese_Brazil.1252 attached base packages:[1] stats graphics grDevices utils datasets methods base -- Atenciosamente, Raphael Saldanha saldanha.plan...@gmail.com -- Atenciosamente, Raphael Saldanha saldanha.plan...@gmail.com __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Bayesian Quantile regression installation
i have R 2.14 version.and i have downloaded bayesQR package from following link http://cran.r-project.org/web/packages/bayesQR/index.html my OS is Windows7.i have downloaded Windows binary: bayesQR_1.3.zip file from above link.I am new to R. So please tell me what is the next step i have to do inorder to install the bayesQR package.pls reply me as quickly as possible. thanks in advance with regards Kalam Narendar Reddy, Masters In technology, University Of HYderabad, -- View this message in context: http://r.789695.n4.nabble.com/Bayesian-Quantile-regression-installation-tp4118947p4118947.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] Non parametric, repeated-measures, factorial ANOVA
Hi I have data from an experiment that used a repeated-measures factorial 2x2 design (i.e. each participant contributed data to both levels of both factors). I need a non-parametric version of the repeated-measures factorial ANOVA to analyse the data. SPSS only has non-parametric tests for one-way ANOVAs but I have been told that the test I need can be implemented using the R software. Unfortunantly I haven't been able to work out how to do this test in R. I've got the Wilcox book 'Robust Estimation and Hypothesis testing' but to be honest I don't have enough of a background in stats to understand a great deal of it, and I wasn't able to work out how to do the test I want. Can anyone let me know how I can do such a test in R? I presume this is a test that people frequently need to use and that there will be some code already written that can implement the test. Thanks Rob -- View this message in context: http://r.789695.n4.nabble.com/Non-parametric-repeated-measures-factorial-ANOVA-tp4118816p4118816.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] regarding installation of bayesQR package
i have R 2.14 version.and i have downloaded bayesQR package from following link http:// http://cran.r-project.org/web/packages/bayesQR/index.ht ml my OS is Windows7.i have downloaded Windows binary:bayesQR_1.3.zip file from above link.I am new to R. So please tell me what is the next step i have to do inorder to install the bayesQR package.pls reply me as quickly as possible. thanks in advance with regards *Kalam Narendar Reddy,* Masters In technology, University Of HYderabad, -- View this message in context: http://r.789695.n4.nabble.com/regarding-installation-of-bayesQR-package-tp4118899p4118899.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] fill binary matrices with random 1s
Dear all, I am finding difficulty in the following, I would like to create an empty matrix e.g. 10x10 of 0s and sequentially fill this matrix with randomly placed a 1s until it is saturated. Producing 100 matrices of sequentially increasing density., This process needs to be randomized 1000 times., I assume i should run this along the following lines, 1) Create 1000 matrices all zeros, 2) add a random 1 to all matrices, 3) run function on all 1000 matrices and output results to a vector table (i.e. calculate density of matric at each step for all 100 matrices. )., 4) add another 1 to the previous 1000 matrices in a random position., repeat till all matrices saturated., I have looked through histories on random fill algorithms but all packages I can find nothing as simple as the random fill I am looking for., sorry for bothering, Thank you for any help in advance. Something that starts along the lines of the following? Sorry this example is atrocious. matrixfill - function(emptymatrix, K=fullmatrix, time=100, from=0, to=time) { N - numeric(time+1) N[1] - emptymatrix for (i in 1:time) N[i+1] - N[i]+place random 1 in a random xy position until K. Calculate Density of matrix [[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] Any function\method to use automatically Final Model after bootstrapping using boot.stepAIC()
Hi List, Being new to R, I am trying to apply boot.stepAIC() for Model selection by bootstrapping the stepAIC() procedure. I had gone through the discussion in various thread on the variable selection methods. Understood the pros and cons of various method, also going through the regression modelling strategies in rms. I want to read Final model or Formula or list of variables automatically after boot.stepAIC(). n - 200 x1 - runif(n, -3, 3) x2 - runif(n, -3, 3) x3 - runif(n, -3, 3) x4 - runif(n, -3, 3) x5 - factor(sample(letters[1:2], n, rep = TRUE)) eta - 0.1 + 1.6 * x1 - 2.5 * as.numeric(as.character(x5) == levels(x5)[1]) y1 - rbinom(n, 1, plogis(eta)) data - data.frame(y1,x1, x2, x3, x4, x5) glmFit1 - glm(y1 ~ x1 + x2 + x3 + x4 + x5, family = binomial, data = data) bglmfit - boot.stepAIC(glmFit1, data, B = 50) bglmfit In the summary of Bootstrapping the 'stepAIC()' procedure, Following information is listed: Initial Model: y1 ~ x1 + x2 + x3 + x4 + x5 Final Model: y1 ~ x1 + x5 Is there any function or method for using Final Model by Bootstrapping the 'stepAIC()' procedure, like OrigstepAIC model as shown below. n - 200 x1 - runif(n, -3, 3) x5 - factor(sample(letters[1:2], n, rep = TRUE)) eta - 0.1 + 1.6 * x1 - 2.5 * as.numeric(as.character(x5) == levels(x5)[1]) data1 - data.frame(x1, x5) data1$probscore - predict(bglmfit$OrigStepAIC , data1) Is there any way to read the variables or formula in the Final Model. Thanks in advance! Regards, ~Ajit -- View this message in context: http://r.789695.n4.nabble.com/Any-function-method-to-use-automatically-Final-Model-after-bootstrapping-using-boot-stepAIC-tp4119050p4119050.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] Extracting from zip, removing certain file extensions
Hi there, I'm running R on windows 7 with Rstudio. Everyday I receive a zip file where a bunch of half-hourly files are zipped together. I then use xx=unzip(ind) to get xx, which consists of : [1] ./2011/A20112961503.flx ./2011/A20112961503.log ./2011/A20113211730.slt ./2011/A20113211800.slt ./2011/A20113211830.slt ./2011/A20113211900.slt [7] ./2011/A20113211930.slt ./2011/A20113212000.slt ./2011/A20113212030.slt ./2011/A20113212100.slt ./2011/A20113212130.slt ./2011/A20113212200.slt [13] ./2011/A20113212230.slt ./2011/A20113212300.slt ./2011/A20113212330.slt ./2011/A2011322.slt ./2011/A20113220030.slt ./2011/A20113220100.slt [19] ./2011/A20113220130.slt ./2011/A20113220200.slt ./2011/A20113220230.slt ./2011/A20113220300.slt ./2011/A20113220330.slt ./2011/A20113220400.slt [25] ./2011/A20113220430.slt ./2011/A20113220500.slt ./2011/A20113220530.slt ./2011/A20113220600.slt ./2011/A20113220630.slt ./2011/A20113220700.slt [31] ./2011/A20113220730.slt ./2011/A20113220800.slt ./2011/A20113220830.slt ./2011/A20113220900.slt ./2011/A20113220930.slt ./2011/A20113221000.slt [37] ./2011/A20113221030.slt ./2011/A20113221100.slt ./2011/A20113221130.slt ./2011/A20113221200.slt ./2011/A20113221230.slt ./2011/A20113221300.slt [43] ./2011/A20113221330.slt ./2011/A20113221400.slt ./2011/A20113221430.slt ./2011/A20113221500.slt ./2011/A20113221530.slt ./2011/A20113221600.slt [49] ./2011/A20113221630.slt ./2011/A20113221700.slt ./2011/A20113221730.slt What I want is to keep all the slt files and remove the other file types. How do I remove all the non slt files from xx? I want this to be automated so I don't have to state the entire file name each time. Thanks [[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] heatmap.2 (blurred output heatmap)
Hi I used to make heatmaps using following commands but now some thing has changed as I get library(gplots) heatmap. 2(qtl.map,Rowv=F,dendrogram=column,col=colorRampPalette(c(blue,lightblue,black,black,yellow,red)),breaks=seq(-4.01,4.01,length.out=51), density.info=none, ) following error and also the ouput eatmap is also blurred so I can not see anything! I am just wondering something has changed in package or its just something I am getting. Warning messages: 1: In plot.window(...) : at is not a graphical parameter 2: In plot.xy(xy, type, ...) : at is not a graphical parameter 3: In title(...) : at is not a graphical parameter Any help would be much appreciated! Cheers __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Extracting from zip, removing certain file extensions
use pattern matching (regular expressions): e.g., myFileNames[grepl(slt$, myFileNames)] On Tue, Nov 29, 2011 at 8:36 AM, Mathew Brown mathew.br...@forst.uni-goettingen.de wrote: Hi there, I'm running R on windows 7 with Rstudio. Everyday I receive a zip file where a bunch of half-hourly files are zipped together. I then use xx=unzip(ind) to get xx, which consists of : [1] ./2011/A20112961503.flx ./2011/A20112961503.log ./2011/A20113211730.slt ./2011/A20113211800.slt ./2011/A20113211830.slt ./2011/A20113211900.slt [7] ./2011/A20113211930.slt ./2011/A20113212000.slt ./2011/A20113212030.slt ./2011/A20113212100.slt ./2011/A20113212130.slt ./2011/A20113212200.slt [13] ./2011/A20113212230.slt ./2011/A20113212300.slt ./2011/A20113212330.slt ./2011/A2011322.slt ./2011/A20113220030.slt ./2011/A20113220100.slt [19] ./2011/A20113220130.slt ./2011/A20113220200.slt ./2011/A20113220230.slt ./2011/A20113220300.slt ./2011/A20113220330.slt ./2011/A20113220400.slt [25] ./2011/A20113220430.slt ./2011/A20113220500.slt ./2011/A20113220530.slt ./2011/A20113220600.slt ./2011/A20113220630.slt ./2011/A20113220700.slt [31] ./2011/A20113220730.slt ./2011/A20113220800.slt ./2011/A20113220830.slt ./2011/A20113220900.slt ./2011/A20113220930.slt ./2011/A20113221000.slt [37] ./2011/A20113221030.slt ./2011/A20113221100.slt ./2011/A20113221130.slt ./2011/A20113221200.slt ./2011/A20113221230.slt ./2011/A20113221300.slt [43] ./2011/A20113221330.slt ./2011/A20113221400.slt ./2011/A20113221430.slt ./2011/A20113221500.slt ./2011/A20113221530.slt ./2011/A20113221600.slt [49] ./2011/A20113221630.slt ./2011/A20113221700.slt ./2011/A20113221730.slt What I want is to keep all the slt files and remove the other file types. How do I remove all the non slt files from xx? I want this to be automated so I don't have to state the entire file name each time. Thanks [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Jim Holtman Data Munger Guru What is the problem that you are trying to solve? Tell me what you want to do, not how you want to do it. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] append to PDF file
On 29.11.2011 13:15, R. Michael Weylandt wrote: I think you are looking for the system() command. ... and you certainly do not want to use savePlot but rather use the pdf() device directly. Uwe Ligges Michael On Tue, Nov 29, 2011 at 7:11 AM, Christof Klußckl...@email.uni-kiel.de wrote: Hi Jim, Hi Ken Am 27-11-2011 00:00, schrieb jim holtman: There is the 'pdftk' (PDF tool kit) that you will find on the web that will do the job. I have used it to both combine and split out the pages in the PDF file. yes, thx. GUI tools like www.pdfsam.org do the job too. But is there a possibility to append files directly in R. That is to invoke pdftk inside R with a shellandwait? perhaps something like for (i in ...) { ... savePlot(filename=temp.pdf, type=pdf) exec pdftk temp.pdf final.pdf cat output final.pdf } greetings Christof __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Negative exponential fit
On 29.11.2011 07:06, Indrajit Sengupta wrote: What have you tried so far - can you explain? fitdistrplus package is the default package for fitting distributions. It is a contributed packages, and perhaps it is a good one (I do not know), but calling it the *default* ... who defined that? Best, Uwe Ligges Regards, Indrajit From: rch4r...@geneseo.edu To: r-help@r-project.org Sent: Tuesday, November 29, 2011 8:39 AM Subject: [R] Negative exponential fit We need help We are doing a project for a statistical class in and we are looking at world record times in different running events over time. We are trying to fit the data with a negative exponential but we just cant seem to get a function that works properly. we have on our x-axis the date and on the y-axis the time(in seconds). So as you can imagine, the times have decreased and appear to be approaching a limit. Any ideas for a nls function that would work for us would be greatly appreciated. Rob -- View this message in context: http://r.789695.n4.nabble.com/Negative-exponential-fit-tp4117889p4117889.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. [[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] Extracting from zip, removing certain file extensions
On 29/11/2011 8:36 AM, Mathew Brown wrote: Hi there, I'm running R on windows 7 with Rstudio. Everyday I receive a zip file where a bunch of half-hourly files are zipped together. I then use xx=unzip(ind) to get xx, which consists of : [1] ./2011/A20112961503.flx ./2011/A20112961503.log ./2011/A20113211730.slt ./2011/A20113211800.slt ./2011/A20113211830.slt ./2011/A20113211900.slt [7] ./2011/A20113211930.slt ./2011/A20113212000.slt ./2011/A20113212030.slt ./2011/A20113212100.slt ./2011/A20113212130.slt ./2011/A20113212200.slt [13] ./2011/A20113212230.slt ./2011/A20113212300.slt ./2011/A20113212330.slt ./2011/A2011322.slt ./2011/A20113220030.slt ./2011/A20113220100.slt [19] ./2011/A20113220130.slt ./2011/A20113220200.slt ./2011/A20113220230.slt ./2011/A20113220300.slt ./2011/A20113220330.slt ./2011/A20113220400.slt [25] ./2011/A20113220430.slt ./2011/A20113220500.slt ./2011/A20113220530.slt ./2011/A20113220600.slt ./2011/A20113220630.slt ./2011/A20113220700.slt [31] ./2011/A20113220730.slt ./2011/A20113220800.slt ./2011/A20113220830.slt ./2011/A20113220900.slt ./2011/A20113220930.slt ./2011/A20113221000.slt [37] ./2011/A20113221030.slt ./2011/A20113221100.slt ./2011/A20113221130.slt ./2011/A20113221200.slt ./2011/A20113221230.slt ./2011/A20113221300.slt [43] ./2011/A20113221330.slt ./2011/A20113221400.slt ./2011/A20113221430.slt ./2011/A20113221500.slt ./2011/A20113221530.slt ./2011/A20113221600.slt [49] ./2011/A20113221630.slt ./2011/A20113221700.slt ./2011/A20113221730.slt What I want is to keep all the slt files and remove the other file types. How do I remove all the non slt files from xx? I want this to be automated so I don't have to state the entire file name each time. Use a regular expression: xx - grep(slt$, xx, value=TRUE) If you want to do more complicated matching, read ?glob2rx or ?regexp. 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] fill binary matrices with random 1s
I have to admit I'm not entirely sure what your question is. How to put a 1 in a random position in a matrix? mat - matrix(0, 10, 10) mat[sample(1:nrow(mat), 1), sample(1:ncol(mat), 1)] - 1 will do so, but if you need to fill a random position that is *currently zero* then you'll need to wrap it in a while loop and check the value of that cell. Or, more elegantly, create a random vector of positions in advance, then fill each: tofill - sample(1:100) for(i in 1:length(tofill)) { mat[tofill[i]] - 1 } But if you don't need sequential matrices, just random matrices of particular densities, there are nicer ways to create them. matdensity - 45 matsize - 10 mat45 - matrix(sample(c(rep(1, matdensity), rep(0, matsize*2 - matdensity))), matsize, matsize) On Tue, Nov 29, 2011 at 7:32 AM, Grant McDonald grantforacco...@hotmail.co.uk wrote: Dear all, I am finding difficulty in the following, I would like to create an empty matrix e.g. 10x10 of 0s and sequentially fill this matrix with randomly placed a 1s until it is saturated. Producing 100 matrices of sequentially increasing density., This process needs to be randomized 1000 times., I assume i should run this along the following lines, 1) Create 1000 matrices all zeros, 2) add a random 1 to all matrices, 3) run function on all 1000 matrices and output results to a vector table (i.e. calculate density of matric at each step for all 100 matrices. )., 4) add another 1 to the previous 1000 matrices in a random position., repeat till all matrices saturated., I have looked through histories on random fill algorithms but all packages I can find nothing as simple as the random fill I am looking for., sorry for bothering, Thank you for any help in advance. Something that starts along the lines of the following? Sorry this example is atrocious. matrixfill - function(emptymatrix, K=fullmatrix, time=100, from=0, to=time) { N - numeric(time+1) N[1] - emptymatrix for (i in 1:time) N[i+1] - N[i]+place random 1 in a random xy position until K. Calculate Density of matrix -- Sarah Goslee http://www.functionaldiversity.org __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Bayesian Quantile regression installation
Let's see... you could: - read the directions at http://cran.r-project.org or the longer ones here http://cran.r-project.org/doc/manuals/R-admin.pdf - look at the help for install.packages() - actually look at the menus for R, as there's an install from local file option there somewhere in the Windows version. Or you could abrogate all responsibility for your own problems and ask repeatedly for help. Personally, I'd try one of the first three options. On Tue, Nov 29, 2011 at 7:15 AM, narendarreddy kalam narendarcse...@gmail.com wrote: i have R 2.14 version.and i have downloaded bayesQR package from following link http://cran.r-project.org/web/packages/bayesQR/index.html my OS is Windows7.i have downloaded Windows binary: bayesQR_1.3.zip file from above link.I am new to R. So please tell me what is the next step i have to do inorder to install the bayesQR package.pls reply me as quickly as possible. thanks in advance with regards Kalam Narendar Reddy, Masters In technology, University Of HYderabad, -- View this message in context: http://r.789695.n4.nabble.com/Bayesian-Quantile-regression-installation-tp4118947p4118947.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. -- Sarah Goslee http://www.stringpage.com http://www.sarahgoslee.com http://www.functionaldiversity.org __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] heatmap.2 (blurred output heatmap)
example(heatmap.2) works for me, hence it is either your data, your version of some package or your version of R that causes the problems, we do not have information of any of these although the posting guide asks you to provide this for each posting. So we cannot help. Uwe Ligges On 29.11.2011 14:45, Stuart wrote: Hi I used to make heatmaps using following commands but now some thing has changed as I get library(gplots) heatmap. 2(qtl.map,Rowv=F,dendrogram=column,col=colorRampPalette(c(blue,lightblue,black,black,yellow,red)),breaks=seq(-4.01,4.01,length.out=51), density.info=none, ) following error and also the ouput eatmap is also blurred so I can not see anything! I am just wondering something has changed in package or its just something I am getting. Warning messages: 1: In plot.window(...) : at is not a graphical parameter 2: In plot.xy(xy, type, ...) : at is not a graphical parameter 3: In title(...) : at is not a graphical parameter Any help would be much appreciated! Cheers __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Transforming a string into a command
On Nov 29, 2011, at 2:30 AM, Xu Wang wrote: David, Did my reply get orphaned All replies are orphaned. You are asked to include context if your question relies on code that has previously been posted. or are you trying to help me realize that asking why something does not work is not a straightforward question? I'll try to cover both bases. I'll focus just on the first case that I don't understand. Suppose we have s- ln(a+b) a-1 b-2 eval(parse(text=s)) Error in eval(expr, envir, enclos) : could not find function ln Perhaps it's because I don't understand eval well (any good references for reading up on eval, parse, substitute, etc.?). It appears you need to review the help page for the `log` function. But I expected it to produce the same as the following line: eval(parse(text=ln(a+b))) It did. eval(parse(text=ln(a+b))) Error in eval(expr, envir, enclos) : could not find function ln Xu David Winsemius wrote On Nov 29, 2011, at 2:00 AM, Xu Wang wrote: Why don't the following two commands work? eval(parse(text=s)) eval(as.expression(s)) They both worked as expected. An error was appropriately reported. ln(a+b) Error: could not find function ln log(a+b) [1] 1.098612 Can you think of anything else we might need to know in order to answer that question? Some Nabble users seem to expect that the rest of Rhelp sees what they see. They are delusional when they do so. -- David. -- View this message in context: http://r.789695.n4.nabble.com/Transforming-a-string-into-a-command-tp4112183p4118294.html Sent from the R help mailing list archive at Nabble.com. __ David Winsemius, MD West Hartford, CT __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] regarding installation of bayesQR package
On 29.11.2011 13:09, narendarreddy kalam wrote: i have R 2.14 2.14.0 I guess. version.and i have downloaded bayesQR package from following link http:// http://cran.r-project.org/web/packages/bayesQR/index.ht ml my OS is Windows7.i have downloaded Windows binary:bayesQR_1.3.zip file from above link.I am new to R. Well, the R Installation and Administration manual says it. Easiest: Either install.packages(bayesQR) downloads and installs automatically, or for Windows, simply use the GUI to install the downloaded zip file. Uwe Ligges So please tell me what is the next step i have to do inorder to install the bayesQR package.pls reply me as quickly as possible. thanks in advance with regards *Kalam Narendar Reddy,* Masters In technology, University Of HYderabad, -- View this message in context: http://r.789695.n4.nabble.com/regarding-installation-of-bayesQR-package-tp4118899p4118899.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] x, y for point of intersection
Hi again, Working with my real data and not with the little example i sent to the list i discovered that segm_distance function from package pracma does not converge to 0 in all cases, even if i increase the number of iteration to 10,000 for example. It seems that it depends on the initialization point - most like a minimization function. So my thanks go to Don who's suggestion works for the real data as well without any problems - so far ;-) He suggested to use the function crossing.psp from package spatstat. Thanks again to all who have answered and helped to solve my problem. I certainly learned few new things. Monica From: macque...@llnl.gov To: pisican...@hotmail.com CC: r-help@r-project.org Date: Wed, 23 Nov 2011 14:03:42 -0800 Subject: Re: [R] x, y for point of intersection The function crossing.psp() in the spatstat package might be of use. Here's an excerpt from its help page: crossing.psp package:spatstat R Documentation Crossing Points of Two Line Segment PatternsDescription: Finds any crossing points between two line segment patterns. Usage: crossing.psp(A,B) -Don -- Don MacQueen Lawrence Livermore National Laboratory 7000 East Ave., L-627 Livermore, CA 94550 925-423-1062 On 11/22/11 12:48 PM, R. Michael Weylandt michael.weyla...@gmail.com michael.weyla...@gmail.com wrote: If it's a one off, the identify() function might be of help -- if you need something algorithmic it's harder due to floating point stuff and sampling frequencies. Let me know if that's the case. Michael On Nov 22, 2011, at 3:40 PM, Monica Pisica pisican...@hotmail.com wrote: Hi everyone, I am trying to get a point of intersection between a polyline and a straight line ©.. and get the x and y coordinates of this point. For exemplification consider this: set.seed(123) k1 -rnorm(100, mean=1.77, sd=3.33) k1 - sort(k1) q1 - rnorm(100, mean=2.37, sd=0.74) q1 - sort(q1, decreasing = TRUE) plot(k1, q1, xlim - c((min(k1)-5), (max(k1)+5)), type=l) ya - 2 xa = -5 yb=4 xb=12 lines(c(xa, xb), c(ya, yb), col = 2) # I want to get the x and y coordinates of the intersection of the 2 lines ©. m - (ya-yb)/(xa-xb) b - ya-m*xa ln - loess(q1~k1) lines(ln) It is clear that the x, y will satisfy both linear equations, y = m*x + b and the ln polyline ©.. but while I can visualize the equation of the straight line I have problems with the polyline. I will appreciate any ideas to solve this problem. I thought it a trivial solution but it seems I cannot see it. Thanks, Monica __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] fill binary matrices with random 1s
Folks: On Tue, Nov 29, 2011 at 6:24 AM, Sarah Goslee sarah.gos...@gmail.com wrote: I have to admit I'm not entirely sure what your question is. How to put a 1 in a random position in a matrix? mat - matrix(0, 10, 10) mat[sample(1:nrow(mat), 1), sample(1:ncol(mat), 1)] - 1 This is unnecessary. In R: matrices are simply vectors with a dim attribute, so you can treat them as vectors: mat[sample(nrow(mat)*ncol(mat),1] - 1 Moreover, this also suggests a simple way to do this sequentially: Simply create your vector of random indices at one go and use it for your loop -- no checking on what previously was sampled is necessary: ransamp - sample(100,100) ## assuming nrow = ncol = 10 for( i in 1:100) { mat[ransamp[i]] - 1 ## do whatever you want } HTH Cheers, Bert will do so, but if you need to fill a random position that is *currently zero* then you'll need to wrap it in a while loop and check the value of that cell. Or, more elegantly, create a random vector of positions in advance, then fill each: tofill - sample(1:100) for(i in 1:length(tofill)) { mat[tofill[i]] - 1 } But if you don't need sequential matrices, just random matrices of particular densities, there are nicer ways to create them. matdensity - 45 matsize - 10 mat45 - matrix(sample(c(rep(1, matdensity), rep(0, matsize*2 - matdensity))), matsize, matsize) On Tue, Nov 29, 2011 at 7:32 AM, Grant McDonald grantforacco...@hotmail.co.uk wrote: Dear all, I am finding difficulty in the following, I would like to create an empty matrix e.g. 10x10 of 0s and sequentially fill this matrix with randomly placed a 1s until it is saturated. Producing 100 matrices of sequentially increasing density., This process needs to be randomized 1000 times., I assume i should run this along the following lines, 1) Create 1000 matrices all zeros, 2) add a random 1 to all matrices, 3) run function on all 1000 matrices and output results to a vector table (i.e. calculate density of matric at each step for all 100 matrices. )., 4) add another 1 to the previous 1000 matrices in a random position., repeat till all matrices saturated., I have looked through histories on random fill algorithms but all packages I can find nothing as simple as the random fill I am looking for., sorry for bothering, Thank you for any help in advance. Something that starts along the lines of the following? Sorry this example is atrocious. matrixfill - function(emptymatrix, K=fullmatrix, time=100, from=0, to=time) { N - numeric(time+1) N[1] - emptymatrix for (i in 1:time) N[i+1] - N[i]+place random 1 in a random xy position until K. Calculate Density of matrix -- Sarah Goslee http://www.functionaldiversity.org __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- 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] fill binary matrices with random 1s
On Nov 29, 2011, at 7:32 AM, Grant McDonald wrote: Dear all, I am finding difficulty in the following, I would like to create an empty matrix e.g. 10x10 of 0s and sequentially fill this matrix with randomly placed a 1s until it is saturated. Producing 100 matrices of sequentially increasing density., This process needs to be randomized 1000 times., I assume i should run this along the following lines, 1) Create 1000 matrices all zeros, 2) add a random 1 to all matrices, 3) run function on all 1000 matrices and output results to a vector table (i.e. calculate density of matric at each step for all 100 matrices. )., 4) add another 1 to the previous 1000 matrices in a random position., repeat till all matrices saturated., I have looked through histories on random fill algorithms but all packages I can find nothing as simple as the random fill I am looking for., sorry for bothering, Thank you for any help in advance. Something that starts along the lines of the following? Sorry this example is atrocious. matrixfill - function(emptymatrix, K=fullmatrix, time=100, from=0, to=time) { N - numeric(time+1) N[1] - emptymatrix for (i in 1:time) N[i+1] - N[i]+place random 1 in a random xy position until K. Calculate Density of matrix Ewww. That looks painful. Consider this as an alternative to create a single such random matrix: rmat - matrix(rbinom(100, 1, prob=0.1), 10,10) rmat [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] [1,]000000001 0 [2,]100000000 0 [3,]000010000 0 [4,]100000000 0 [5,]000110000 0 [6,]000000100 0 [7,]000000001 0 [8,]010000000 0 [9,]000000001 0 [10,]000001000 0 -- David Winsemius, MD West Hartford, CT __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Help needed in reproducing a plot
Hello, can anybody tell me how to produce a plot like the one in http://cran.r-project.org/web/packages/lme4/vignettes/Implementation.pdf on page 13, Figure 6? The data is stored in: library(nlme) data(Oats) Cheers -- View this message in context: http://r.789695.n4.nabble.com/Help-needed-in-reproducing-a-plot-tp4119603p4119603.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] Problems with Raster and clim.pact packages with large netcdf files (2.7G) in x64 bit R
I normally use the raster or clim.pact pckages to read netcdf (.nc) files. This has always worked out for me until this weekend every time i try to read a .nc file i get the following error Program: C:\Program Files\RStudio\bin\x64\rsession.exe File: posixio.c, Line 417 Expression: offset = 0 This application has requested the Runtime to terminate it in an unusual way.Please contact the application's support team for more information. here is an example of my code library(raster) library(clim.pact) PET1-brick(cru_ts_3_10.1901.2009.pet.dat.nc) #will give error PET-retrieve.nc(cru_ts_3_10.1901.2009.pet.dat.nc,x.rng=c(20,50),y.rng=c(-15,40)) #will give error The files are CRU data downloaded from BADC. Smaller files work ok but these are bigger file 1. This is the link to the original data source for which a free user account is required. http://badc.nerc.ac.uk/browse/badc/cru/data/cru_ts_3.10) I get the error when I am using R.2.14.0 64 Bit. Using the 32 Bit version doesnt bring errors.I have tried installing and uninstalling both R and Rstudio several times without success 2. I have confirmed that the problem is with R x64 Bit regardless of whether using Rstudio or R GUI or any other GUI. I repeat: No problems with 32 bit which is strange given that 32 bit restricts my memory to 3583 !! and if i load more data in the workspace i will run out of memeory. My machine has 16GB of RAM -- You have to trust that the dots will somehow connect in your future. You have to trust in something your gut, destiny, life, karma, whatever. Steve Jobs http://business.blogs.cnn.com/2011/10/06/life-lessons-steve-jobs-on-steve-jobs/ [[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] fill binary matrices with random 1s
Hi: Here's one approach. I assume that your first 1000 matrices have a single 1 in each matrix, the next set of 1000 have two 1's, ..., and the last one has 99 1's. (No point in doing all 1's since they're all constant.) If that's the case, then try the following. # Each row represents a different 'density' of 1's # upper triangle of m is 0 m - matrix(0, 100, 100) m[lower.tri(m)] - 1 diag(m) - 1 m - m[-100, ] # remove row of all 1's # Functions to operate on a single matrix # Function to permute a vector of 0's and 1's # and reshape it into a 10 x 10 matrix randomMatrix - function(x) matrix(sample(x), 10, 10) # Generate a 10 x 10 x 1000 array marray - function(x) replicate(1000, randomMatrix(x)) # Create a vector of names to which to assign the results # of simulating from each row of m: arraynames - paste('array', 1:99, sep = '') # apply the marray() function to each row of m and assign # to the corresponding index of arraynames for(i in seq_along(arraynames)) assign(arraynames[i], marray(m[i, ])) HTH, Dennis On Tue, Nov 29, 2011 at 4:32 AM, Grant McDonald grantforacco...@hotmail.co.uk wrote: Dear all, I am finding difficulty in the following, I would like to create an empty matrix e.g. 10x10 of 0s and sequentially fill this matrix with randomly placed a 1s until it is saturated. Producing 100 matrices of sequentially increasing density., This process needs to be randomized 1000 times., I assume i should run this along the following lines, 1) Create 1000 matrices all zeros, 2) add a random 1 to all matrices, 3) run function on all 1000 matrices and output results to a vector table (i.e. calculate density of matric at each step for all 100 matrices. )., 4) add another 1 to the previous 1000 matrices in a random position., repeat till all matrices saturated., I have looked through histories on random fill algorithms but all packages I can find nothing as simple as the random fill I am looking for., sorry for bothering, Thank you for any help in advance. Something that starts along the lines of the following? Sorry this example is atrocious. matrixfill - function(emptymatrix, K=fullmatrix, time=100, from=0, to=time) { N - numeric(time+1) N[1] - emptymatrix for (i in 1:time) N[i+1] - N[i]+place random 1 in a random xy position until K. Calculate Density of matrix [[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] Extracting from zip, removing certain file extensions
Great, many thanks. On 11/29/2011 3:09 PM, Duncan Murdoch wrote: On 29/11/2011 8:36 AM, Mathew Brown wrote: Hi there, I'm running R on windows 7 with Rstudio. Everyday I receive a zip file where a bunch of half-hourly files are zipped together. I then use xx=unzip(ind) to get xx, which consists of : [1] ./2011/A20112961503.flx ./2011/A20112961503.log ./2011/A20113211730.slt ./2011/A20113211800.slt ./2011/A20113211830.slt ./2011/A20113211900.slt [7] ./2011/A20113211930.slt ./2011/A20113212000.slt ./2011/A20113212030.slt ./2011/A20113212100.slt ./2011/A20113212130.slt ./2011/A20113212200.slt [13] ./2011/A20113212230.slt ./2011/A20113212300.slt ./2011/A20113212330.slt ./2011/A2011322.slt ./2011/A20113220030.slt ./2011/A20113220100.slt [19] ./2011/A20113220130.slt ./2011/A20113220200.slt ./2011/A20113220230.slt ./2011/A20113220300.slt ./2011/A20113220330.slt ./2011/A20113220400.slt [25] ./2011/A20113220430.slt ./2011/A20113220500.slt ./2011/A20113220530.slt ./2011/A20113220600.slt ./2011/A20113220630.slt ./2011/A20113220700.slt [31] ./2011/A20113220730.slt ./2011/A20113220800.slt ./2011/A20113220830.slt ./2011/A20113220900.slt ./2011/A20113220930.slt ./2011/A20113221000.slt [37] ./2011/A20113221030.slt ./2011/A20113221100.slt ./2011/A20113221130.slt ./2011/A20113221200.slt ./2011/A20113221230.slt ./2011/A20113221300.slt [43] ./2011/A20113221330.slt ./2011/A20113221400.slt ./2011/A20113221430.slt ./2011/A20113221500.slt ./2011/A20113221530.slt ./2011/A20113221600.slt [49] ./2011/A20113221630.slt ./2011/A20113221700.slt ./2011/A20113221730.slt What I want is to keep all the slt files and remove the other file types. How do I remove all the non slt files from xx? I want this to be automated so I don't have to state the entire file name each time. Use a regular expression: xx - grep(slt$, xx, value=TRUE) If you want to do more complicated matching, read ?glob2rx or ?regexp. Duncan Murdoch __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Matrix for correlation
hi @ all, I have problem with creating a matrix for a cor() function. I try to use the cor() function on a matrix to test the correlation between each value in a column. Maybe like corr(x, method = xyz). My x has two columns maybe like this: MEDIA VALUE Car 23 Train26 Plane 25 Cab 22 Bike 15 and so on. Now I want to calculate the correlation between Car and Train, Car and Plane, Train and Plane and so on. Sorry but I don't have a clue and I hope there is an easy way to solve my problem. Thanks a lot for all answers. Greetz Geo -- View this message in context: http://r.789695.n4.nabble.com/Matrix-for-correlation-tp4119590p4119590.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] Help needed in reproducing a plot
Looks like a typical plot produced using the 'lattice' package. There is plenty of documentation on the use of the package. Run some of the examples. On Tue, Nov 29, 2011 at 10:43 AM, syrvn ment...@gmx.net wrote: Hello, can anybody tell me how to produce a plot like the one in http://cran.r-project.org/web/packages/lme4/vignettes/Implementation.pdf on page 13, Figure 6? The data is stored in: library(nlme) data(Oats) Cheers -- View this message in context: http://r.789695.n4.nabble.com/Help-needed-in-reproducing-a-plot-tp4119603p4119603.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. -- 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] Matrix for correlation
I'm not sure how you mean to calculate correlation if you have a single observation of each mediumcan you provide your data (or a subset thereof) so we can see what you are actually working with and if correlation makes sense. Michael On Tue, Nov 29, 2011 at 10:41 AM, Geophagus falk.hilli...@twain-systems.com wrote: hi @ all, I have problem with creating a matrix for a cor() function. I try to use the cor() function on a matrix to test the correlation between each value in a column. Maybe like corr(x, method = xyz). My x has two columns maybe like this: MEDIA VALUE Car 23 Train 26 Plane 25 Cab 22 Bike 15 and so on. Now I want to calculate the correlation between Car and Train, Car and Plane, Train and Plane and so on. Sorry but I don't have a clue and I hope there is an easy way to solve my problem. Thanks a lot for all answers. Greetz Geo -- View this message in context: http://r.789695.n4.nabble.com/Matrix-for-correlation-tp4119590p4119590.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] Matrix for correlation
On 29.11.2011 16:41, Geophagus wrote: hi @ all, I have problem with creating a matrix for a cor() function. I try to use the cor() function on a matrix to test the correlation between each value in a column. Maybe like corr(x, method = xyz). My x has two columns maybe like this: MEDIA VALUE Car 23 Train26 Plane 25 Cab 22 Bike 15 and so on. Now I want to calculate the correlation between Car and Train, Car and Plane, Train and Plane and so on. If the above is your data, then you have indeed no clue what the word correlation means. Please look it up in a textbook and find why you cannot calculate it for this kind of data. If you do not find, please ask a local statistician for help. Uwe Ligges Sorry but I don't have a clue and I hope there is an easy way to solve my problem. Thanks a lot for all answers. Greetz Geo -- View this message in context: http://r.789695.n4.nabble.com/Matrix-for-correlation-tp4119590p4119590.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] quick ANOVA question
-Original Message- What I like to know is if I apply an ANOVA to this data and choose the control group as the reference group (using the relevel function) what groups exactly are compared? Are only all treated groups 1, 2, 3 tested against the control group or are all possible combinations tested? ANOVA doesn't compare one level against another; it compares all levels against none. * lm() coefficients and associated p-values can be used to compare treatments to the 'control' if you use treatment contrasts with 'control' as the first or 'base' level and there are no other effects in the model. But see fortune(242). It may not apply to you, but it always applies to me at least to the extent that I am never quite sure that it doesn't. S Ellison *Ish. A more accurate description might be that anova in R compares a model with two or more levels specified for a factor to a model with no levels specified other than the default intercept. But that doesn't have as nice a ring to it, does it? *** 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] Decision Trees /Decision Analysis with R?
Hi, Unfortunately I do not have an answer to this question yet, but it is something I'm currently examining. We're hoping to construct a template for health economic evaluation using decision tree (eventually working up to more complex modelling methodologies). I'll keep you posted on our progress. Ian -- View this message in context: http://r.789695.n4.nabble.com/Decision-Trees-Decision-Analysis-with-R-tp3582184p4119677.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] Matrix for correlation
Do you have multiple data points for Car/Train etc? And do you want to see if there are differences between in mean/medians these modes of transport? If so explore anova, kruskal-wallis . Date: Tue, 29 Nov 2011 16:57:57 +0100 From: lig...@statistik.tu-dortmund.de To: falk.hilli...@twain-systems.com CC: r-help@r-project.org Subject: Re: [R] Matrix for correlation On 29.11.2011 16:41, Geophagus wrote: hi @ all, I have problem with creating a matrix for a cor() function. I try to use the cor() function on a matrix to test the correlation between each value in a column. Maybe like corr(x, method = xyz). My x has two columns maybe like this: MEDIA VALUE Car 23 Train26 Plane 25 Cab 22 Bike 15 and so on. Now I want to calculate the correlation between Car and Train, Car and Plane, Train and Plane and so on. If the above is your data, then you have indeed no clue what the word correlation means. Please look it up in a textbook and find why you cannot calculate it for this kind of data. If you do not find, please ask a local statistician for help. Uwe Ligges Sorry but I don't have a clue and I hope there is an easy way to solve my problem. Thanks a lot for all answers. Greetz Geo -- View this message in context: http://r.789695.n4.nabble.com/Matrix-for-correlation-tp4119590p4119590.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Help needed in reproducing a plot
Hi: This looks like the one: library('lattice') data(Oats, package = 'MEMSS') print(xyplot(yield ~ nitro | Block, Oats, groups = Variety, type = c(g, b), auto.key = list(lines = TRUE, space = 'top', columns = 3), xlab = Nitrogen concentration (cwt/acre), ylab = Yield (bushels/acre), aspect = 'xy')) Look at the source code of the implementation document in the same place that you found the pdf. I found it from the html help page for the lme4 package, but there are other places you could find it.) The code for the plots in the document are contained therein. Dennis On Tue, Nov 29, 2011 at 7:43 AM, syrvn ment...@gmx.net wrote: Hello, can anybody tell me how to produce a plot like the one in http://cran.r-project.org/web/packages/lme4/vignettes/Implementation.pdf on page 13, Figure 6? The data is stored in: library(nlme) data(Oats) Cheers -- View this message in context: http://r.789695.n4.nabble.com/Help-needed-in-reproducing-a-plot-tp4119603p4119603.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] Making the lines thicker in histogram
I'm using a histogram and want to overlay this onto a barplot. I need the histogram lines to be thicker in order for it to stand out more on top of the barplot. Is there a command in order to do this? Thanks in advance. -- View this message in context: http://r.789695.n4.nabble.com/Making-the-lines-thicker-in-histogram-tp4119639p4119639.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] Matrix for correlation
Hi Michael, thank you so much for your fast reply. On the image below there is an example of what I mean. I need the correlation between the values on the fields with ?. http://r.789695.n4.nabble.com/file/n4119734/corr_ex.png But my source data is not in a matrix. It looks like the table in my first post. Do you understand my problem? Thanks a lot! Geophagus -- View this message in context: http://r.789695.n4.nabble.com/Matrix-for-correlation-tp4119590p4119734.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] Matrix for correlation
I think everyone is worried about your data, not what a correlation matrix is. Now I think you may be even more turned around: you want a correlation between the values of the correlation matrix? Just dput() your data object and copy it into your email and we'll see if it's possible to calculate a correlation matrix. Michael On Tue, Nov 29, 2011 at 11:15 AM, Geophagus falk.hilli...@twain-systems.com wrote: Hi Michael, thank you so much for your fast reply. On the image below there is an example of what I mean. I need the correlation between the values on the fields with ?. http://r.789695.n4.nabble.com/file/n4119734/corr_ex.png But my source data is not in a matrix. It looks like the table in my first post. Do you understand my problem? Thanks a lot! Geophagus -- View this message in context: http://r.789695.n4.nabble.com/Matrix-for-correlation-tp4119590p4119734.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] Notation
Hi, what's mean / in command: betareg(inf~Grupo/Sexo, data=dados) it's a effect nested? -- Silvano Cesar da Costa Departamento de Estatística Universidade Estadual de Londrina Fone: 3371-4346 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Weird Excel Time Format
I have a 10-column XLS file, with 2 date fields. As far as I can tell, they were configured identically in Excel 2010. One of these fields resembles 39406.577662037, whilst in Excel, it is shown as 2007-11-20 13:42:20. Applying as.Date() with the default format doesn't do it. Any ideas as to what format this is? Many thanks! -- H -- Sent from my mobile device Envoyait de mon portable __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] format numbers without leading or trailing 0s
A simple question, but I can't find something to do what I want: Given: a vector of numbers, like lambda - c(0, 0.005, 0.01, 0.02, 0.04, 0.08) Desired: format them in minimal space for use as plot labels, ie, without leading or tailing 0s. For this example: lambdaf - c(0, .005, .01, .02, .04, .08) -- Michael Friendly Email: friendly AT yorku DOT ca Professor, Psychology Dept. York University Voice: 416 736-5115 x66249 Fax: 416 736-5814 4700 Keele StreetWeb: http://www.datavis.ca Toronto, ONT M3J 1P3 CANADA __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] format numbers without leading or trailing 0s
Here's one way to get rid of leading zeros before the decimal point: gsub(^0\\., \\., as.character(lambda)) [1] 0.005 .01 .02 .04 .08 Sarah On Tue, Nov 29, 2011 at 12:04 PM, Michael Friendly frien...@yorku.ca wrote: A simple question, but I can't find something to do what I want: Given: a vector of numbers, like lambda - c(0, 0.005, 0.01, 0.02, 0.04, 0.08) Desired: format them in minimal space for use as plot labels, ie, without leading or tailing 0s. For this example: lambdaf - c(0, .005, .01, .02, .04, .08) -- -- Sarah Goslee http://www.functionaldiversity.org __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Weird Excel Time Format
If all else fails, read the help page. There are examples on ?as.Date of reading Excel dates. But I don't believe the time you give. (0.577662037 is just before 13:51:50). On Tue, 29 Nov 2011, Hasan Diwan wrote: I have a 10-column XLS file, with 2 date fields. As far as I can tell, they were configured identically in Excel 2010. One of these fields resembles 39406.577662037, whilst in Excel, it is shown as 2007-11-20 13:42:20. Applying as.Date() with the default format doesn't do it. Any ideas as to what format this is? Many thanks! -- H -- 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] format numbers without leading or trailing 0s
.. and if you want to simultaneously handle possible multiple trailing zeros (not sure whether this could even happen) (somewhat but not completely tested) lambda - c(0, 0.005, 0.01, 0.02, 0.04, 0.08) gsub(^0(\\..*[^0])0*$,\\1,lambda) [1] 0.005 .01 .02 .04 .08 Note that the as.character() coercion is done automatically (and is documented to be). If you do much of this, it's worth going through one of the many web tutorials on regular expressions. And if you're a minimalist like me, you may even find R's man page, ?regexp), suffices. Cheers, Bert On Tue, Nov 29, 2011 at 9:09 AM, Sarah Goslee sarah.gos...@gmail.com wrote: Here's one way to get rid of leading zeros before the decimal point: gsub(^0\\., \\., as.character(lambda)) [1] 0 .005 .01 .02 .04 .08 Sarah On Tue, Nov 29, 2011 at 12:04 PM, Michael Friendly frien...@yorku.ca wrote: A simple question, but I can't find something to do what I want: Given: a vector of numbers, like lambda - c(0, 0.005, 0.01, 0.02, 0.04, 0.08) Desired: format them in minimal space for use as plot labels, ie, without leading or tailing 0s. For this example: lambdaf - c(0, .005, .01, .02, .04, .08) -- -- Sarah Goslee http://www.functionaldiversity.org __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- 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] Making the lines thicker in histogram
kerry1912 wrote on 11/29/2011 09:51:34 AM: I'm using a histogram and want to overlay this onto a barplot. I need the histogram lines to be thicker in order for it to stand out more on top of the barplot. Is there a command in order to do this? Thanks in advance. This topic has been discussed previously in r-help. See below ... Jean http://tolstoy.newcastle.edu.au/R/e10/help/10/06/8175.html From: Petr PIKAL Date: 11 Jun 2010 Hi Look at the source code. graphics:::plot.histogram You can find that boxes are actually drawn by rect So if you want to use standard graphics, you probably need to modify source code and set up your version of plot.histogram. Maybe with ggplot2 package you can find some way how to do what you want but you shall check yourself. Regards Petr [[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] Weird Excel Time Format
On 29 November 2011 09:32, Prof Brian Ripley rip...@stats.ox.ac.uk wrote: If all else fails, read the help page. There are examples on ?as.Date of reading Excel dates. I did, it seems there is either (a) a problem with my code, or (b) a problem with the documentation. See below: rawtimeColumn [1] 39406.577662037 39406.5862847222 39406.592361 39406.5972800926 39406.603819 39406.6445601852 39406.6478587963 39406.6619212963 39406.6634259259 39406.6643518519 [11] 39406.665162037 39406.6659143519 39406.666319 39406.668287037 39406.6702546296 39406.6722106481 39406.6728587963 39406.6731481481 39406.6049768518 39406.585417 [21] 39406.589583 39406.592361 39406.59375 39406.597222 39406.601389 39406.60625 39406.619444 39406.620139 39406.621528 14:5730 [31] 39406.626389 39406.627778 39406.629861 39406.629861 39406.634028 39406.636806 39406.640972 as.Date(as.numeric(rawtimeColumn), origin='1904-01-01') # per as.Date() help [1] 1904-01-04 1904-01-07 1904-01-13 1904-01-19 1904-01-23 1904-02-18 1904-02-21 1904-02-29 1904-03-01 1904-03-02 1904-03-03 1904-03-04 1904-03-05 1904-03-06 [15] 1904-03-07 1904-03-08 1904-03-09 1904-03-10 1904-01-25 1904-01-06 1904-01-11 1904-01-13 1904-01-16 1904-01-18 1904-01-20 1904-01-26 1904-01-31 1904-02-01 [29] 1904-02-03 1904-01-02 1904-02-06 1904-02-07 1904-02-10 1904-02-10 1904-02-12 1904-02-13 1904-02-15 These readings were taken at the 23rd of November in 2011. But I don't believe the time you give. (0.577662037 is just before 13:51:50). It was contrived, so probably was wrong and I should have made that explicit. -- Sent from my mobile device Envoyait de mon portable __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Weird Excel Time Format
You haven't indicated how you are accessing the Excel file, or whether it is an XLS or XLSX file. It sounds like you might be using rcom or a dependent package, in which case you may need to read the Excel COM interface documentation more carefully. In any event, you can't expect as.Date to understand the floating-point numbers as if they were formatted dates it they aren't. For my part, I highly recommend exporting to CSV before importing to R. --- Jeff NewmillerThe . . Go Live... DCN:jdnew...@dcn.davis.ca.usBasics: ##.#. ##.#. Live Go... Live: OO#.. Dead: OO#.. Playing Research Engineer (Solar/BatteriesO.O#. #.O#. with /Software/Embedded Controllers) .OO#. .OO#. rocks...1k --- Sent from my phone. Please excuse my brevity. Hasan Diwan hasan.di...@gmail.com wrote: I have a 10-column XLS file, with 2 date fields. As far as I can tell, they were configured identically in Excel 2010. One of these fields resembles 39406.577662037, whilst in Excel, it is shown as 2007-11-20 13:42:20. Applying as.Date() with the default format doesn't do it. Any ideas as to what format this is? Many thanks! -- H -- Sent from my mobile device Envoyait de mon portable __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] format numbers without leading or trailing 0s
You may also want to deal with a possible leading negative sign: lambda - c(0, 0.005, 0.01, 0.02, 0.04, 0.08, -0.005, -0.01, -0.02, -0.04, -0.08, 1000) gsub(^0(\\..*[^0])0*$,\\1, lambda) [1] 0 .005 .01.02.04.08 [7] -0.005 -0.01 -0.02 -0.04 -0.08 1000 gsub(^(-)?0(\\..*[^0])0*$,\\1\\2, lambda) # -0. - . [1] 0 .005 .01 .02 .04 .08 -.005 [8] -.01 -.02 -.04 -.08 1000 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 Bert Gunter Sent: Tuesday, November 29, 2011 9:57 AM To: Sarah Goslee Cc: R-help; Michael Friendly Subject: Re: [R] format numbers without leading or trailing 0s .. and if you want to simultaneously handle possible multiple trailing zeros (not sure whether this could even happen) (somewhat but not completely tested) lambda - c(0, 0.005, 0.01, 0.02, 0.04, 0.08) gsub(^0(\\..*[^0])0*$,\\1,lambda) [1] 0.005 .01 .02 .04 .08 Note that the as.character() coercion is done automatically (and is documented to be). If you do much of this, it's worth going through one of the many web tutorials on regular expressions. And if you're a minimalist like me, you may even find R's man page, ?regexp), suffices. Cheers, Bert On Tue, Nov 29, 2011 at 9:09 AM, Sarah Goslee sarah.gos...@gmail.com wrote: Here's one way to get rid of leading zeros before the decimal point: gsub(^0\\., \\., as.character(lambda)) [1] 0 .005 .01 .02 .04 .08 Sarah On Tue, Nov 29, 2011 at 12:04 PM, Michael Friendly frien...@yorku.ca wrote: A simple question, but I can't find something to do what I want: Given: a vector of numbers, like lambda - c(0, 0.005, 0.01, 0.02, 0.04, 0.08) Desired: format them in minimal space for use as plot labels, ie, without leading or tailing 0s. For this example: lambdaf - c(0, .005, .01, .02, .04, .08) -- -- Sarah Goslee http://www.functionaldiversity.org __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- 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. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] format numbers without leading or trailing 0s
Omitting the leading zero is dangerous, since the decimal point can disappear in a poor hardcopy leading to later misinterpretation. --- 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. Michael Friendly frien...@yorku.ca wrote: A simple question, but I can't find something to do what I want: Given: a vector of numbers, like lambda - c(0, 0.005, 0.01, 0.02, 0.04, 0.08) Desired: format them in minimal space for use as plot labels, ie, without leading or tailing 0s. For this example: lambdaf - c(0, .005, .01, .02, .04, .08) -- Michael Friendly Email: friendly AT yorku DOT ca Professor, Psychology Dept. York University Voice: 416 736-5115 x66249 Fax: 416 736-5814 4700 Keele StreetWeb: http://www.datavis.ca Toronto, ONT M3J 1P3 CANADA __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Weird Excel Time Format
On 29 November 2011 10:26, Jeff Newmiller jdnew...@dcn.davis.ca.us wrote: You haven't indicated how you are accessing the Excel file, or whether it is an XLS or XLSX file. It sounds like you might be using rcom or a dependent package, in which case you may need to read the Excel COM interface documentation more carefully. In any event, you can't expect as.Date to understand the floating-point numbers as if they were formatted dates it they aren't. I'm using the xlsx package to access this file. It is an XLS file. I think I got it sorted though. The column that has the problem has NA's, whereas the column that does not is complete. For my part, I highly recommend exporting to CSV before importing to R. Will look into doing so... -- Sent from my mobile device Envoyait de mon portable __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Weird Excel Time Format
On 11/29/2011 01:39 PM, Hasan Diwan wrote: On 29 November 2011 10:26, Jeff Newmillerjdnew...@dcn.davis.ca.us wrote: For my part, I highly recommend exporting to CSV before importing to R. Will look into doing so... I don't think this point can be stressed enough. I have had too many bad experiences with dates in excel, especially when multiple computers are involved. When someone has data in excel, I now require them to make the csv file on their system and manually verify the dates but opening the file in notepad. -- Kevin E. Thorpe Biostatistician/Trialist, Applied Health Research Centre (AHRC) Li Ka Shing Knowledge Institute of St. Michael's Assistant Professor, Dalla Lana School of Public Health University of Toronto email: kevin.tho...@utoronto.ca Tel: 416.864.5776 Fax: 416.864.3016 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Why Numeric Values Become Factors in Data Frame
I have a data frame with 1 factor, one date, and 37 numeric values: str(waterchem) 'data.frame': 3525 obs. of 39 variables: site : Factor w/ 64 levels D-1,D-2,D-3,..: 1 1 1 1 1 ... $ sampdate : Date, format: 2007-12-12 2008-03-15 ... $ CO3 : num 1 1 6.7 1 1 1 1 1 1 1 ... $ HCO3 : num 231 228 118 246 157 208 338 285 260 240 ... $ Ca: num 100 88.4 63.4 123 78.2 103 265 213 178 166 ... $ DO: num 4.96 9.91 4.32 2.58 1.81 5.09 3.98 5.46 1.9 2.52 ... ... $ SC: Factor w/ 841 levels 1.090,10.000,..: 635 638 363 All the numeric categories are read in as numbers except for some of those in column 'SC'. I have been looking in the source file for a couple of hours trying to learn why values such as 1.090 and 10.000 are seen as characters rather than numbers. I've not see the reason. The source file is 860K and looks like this: site|sampdate|'Ag'|'Al'|'CO3'|'HCO3'|'Alk-Tot'|'As'|'Ba'|'Be'|'Bi'|'Ca'|'Cd'|'Cl'|'Co'|'Cr'|'Cu'|'DO'|'Fe'|'Hg'|'K'|'Mg'|'Mn'|'Mo'|'Na'|'NH4'|'NO3-NO2'|'Oil-grease'|'Pb'|'pH'|'Sb'|'SC'|'Se'|'SO4'|'Sr'|'TDS'|'Tl'|'V'|'Zn' 'D-1'|'2007-12-12'|0.000|0.106|1.000|231.000|231.000|0.011|0.000|0.002|0.000|100.000|0.000|1.430|0.000|0.006|0.024|4.960|4.110|NA|0.000|9.560|0.035|0.000|0.970|0.010|0.293|NA|0.025|7.800|0.001|630.000|0.001|65.800|0.000|320.000|0.001|0.000|11.400 'D-1'|'2008-03-15'|0.000|0.080|1.000|228.000|228.000|0.001|0.000|0.002|0.000|88.400|0.000|1.340|0.000|0.006|0.014|9.910|0.309|0.000|0.000|9.150|0.047|0.000|0.820|0.224|0.020|NA|0.025|7.940|0.001|633.000|0.001|75.400|0.000|300.000|0.001|0.000|12.400 The R command used to create the data frame is: waterchem - read.table('wqR.txt', header = TRUE, sep = '|') Pointers on how to determine why this one variable has some values and characters rather than as numerics are needed. Rich __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Transforming a string into a command
Petr, thanks for pointing that out. Jim, you are exactly right! Thank you for catching that. I did not realize in the other replies that they were using log and not ln. David, thank you for the lessons. I will improve my question asking skills. Thanks to all, Xu On Tue, Nov 29, 2011 at 9:31 AM, David Winsemius dwinsem...@comcast.netwrote: On Nov 29, 2011, at 2:30 AM, Xu Wang wrote: David, Did my reply get orphaned All replies are orphaned. You are asked to include context if your question relies on code that has previously been posted. or are you trying to help me realize that asking why something does not work is not a straightforward question? I'll try to cover both bases. I'll focus just on the first case that I don't understand. Suppose we have s- ln(a+b) a-1 b-2 eval(parse(text=s)) Error in eval(expr, envir, enclos) : could not find function ln Perhaps it's because I don't understand eval well (any good references for reading up on eval, parse, substitute, etc.?). It appears you need to review the help page for the `log` function. But I expected it to produce the same as the following line: eval(parse(text=ln(a+b))) It did. eval(parse(text=ln(a+b))) Error in eval(expr, envir, enclos) : could not find function ln Xu David Winsemius wrote On Nov 29, 2011, at 2:00 AM, Xu Wang wrote: Why don't the following two commands work? eval(parse(text=s)) eval(as.expression(s)) They both worked as expected. An error was appropriately reported. ln(a+b) Error: could not find function ln log(a+b) [1] 1.098612 Can you think of anything else we might need to know in order to answer that question? Some Nabble users seem to expect that the rest of Rhelp sees what they see. They are delusional when they do so. -- David. -- View this message in context: http://r.789695.n4.nabble.com/** Transforming-a-string-into-a-**command-tp4112183p4118294.htmlhttp://r.789695.n4.nabble.com/Transforming-a-string-into-a-command-tp4112183p4118294.html Sent from the R help mailing list archive at Nabble.com. __** David Winsemius, MD West Hartford, CT [[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] hour in x-axis
Dear R useres, got the following problem. Given the AggData (listed below) I need to plot AggData[,2] vs time (AggData[,1]) for chosen 'rows'. Ive done already: plot(AggData[rows,2], xaxt='n') axis(1,at=seq(1,length(rows),1),sub(,, AggData[rows,1])) which works, but I need to list only chosen data points, say full hours or every 60th point, something like: axis(1,at=seq(1,seq(1,length(rows),60)),sub(, , AggData[day.rows[seq(1,length(rows),60)],2])) but does not work. Could be nice if time on the x-axis is in H:m format (no seconds). In the original data time bout is 1 minute, e.g. 17:19:35, 17:20:35, 17:21:35 . Taken every 100th for brevity yields (AggData[seq(1,length(rows),100),c(2,7)]) time value 117:19:3580.68327 101 18:59:3580.97230 201 20:39:3578.30810 301 22:19:3580.41558 401 23:59:3577.01051 501 01:39:3577.19687 601 03:19:3578.20762 701 04:59:3577.13315 801 06:39:3576.29110 901 08:19:3575.32090 1001 09:59:3585.32890 1101 11:39:3579.86978 1201 13:19:3583.32418 1301 14:59:3578.26018 1401 16:39:3579.06434 Thanks in advance. Best, robert -- View this message in context: http://r.789695.n4.nabble.com/hour-in-x-axis-tp4120142p4120142.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] Calculating the probability for a logistic regression
Hi All, When we run the command : summary ( newmod-gam(Dlq~ formula,family,,data) ) in R, the output would the effect of smoothness in R. As of now to calculate the probability I am following the below approach: 1) Run the plot of the GAM , interpret the curves 2) Re Run the Regression as a GLM after taking into account the non linear terms in step1 3) Calculate the probability from the coefficients obtained in step2, using the appropriate link function But I came across a paper by SAS ( http://support.sas.com/rnd/app/papers/gams.pdf ), Where the parameters outputs are also given when the program is run. So I was wondering if we have something similar in R also? I tried hard but could not find anything. -- View this message in context: http://r.789695.n4.nabble.com/Calculating-the-probability-for-a-logistic-regression-tp4119884p4119884.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] Parameters setting in functions optimization
Good afternoon everybody, I'm quite new in functions optimization on R and, whereas I've read lot's of function descriptions, I'm not sure of the correct settings for function like optimx and nlminb. I'd like to minimize my parameters and the loglikelihood result of the function. My parameters are a mean distance of dispersion and a proportion of individuals not assigned, coming from very far away. The function LikeGi reads external tables and it's working as I want (I've got a similar model on Mathematica). My final function is LogLiketot : LogLiketot- function(dist,ms) { res - NULL for(i in 1:nrow(pop5)){ for(l in 1:nrow(freqvar)){ res - c(res, pop5[i,l]*log(LikeGi(l,i,dist,ms))) } } return(-sum(res)) } dist is the mean dispersal distance (0, lots of meters) and ms the proportion of individuals (0-1). Of course, I want them to be as low as possible. I'd tried to enter the initials parameters as indicated in the tutorials : optim(c(40,0.5), fn=LogLiketot) Error in 1 - ms : 'ms' is missing But ms is 0.5 ... So I've tried this form : optimx(c(30,50),ms=c(0.4,0.5), fn=LogLiketot) with different values for the two parameters : par fvalues method fns grs itns conv KKT1 KKT2 xtimes 219.27583, 25.37964 2249.698BFGS 12 8 NULL0 TRUE TRUE 57.5 1 29.6787861, 0.1580298 2248.972 Nelder-Mead 51 NA NULL0 TRUE TRUE 66.3 The first line is not possible but as I've not constrained the optimization ... but the second line would be a very good result ! Then, searching for another similar cases, I've tried to change my function form: LogLiketot- function(par) { res - NULL for(i in 1:nrow(pop5)){ for(l in 1:nrow(freqvar)){ res - c(res, pop5[i,l]*log(LikeGi(l,i,par[1],par[2]))) } } return(-sum(res)) } where dist=par[1] and ms=par[2] And I've got : optimx(c(40,0.5), fn=LogLiketot) par fvalues method fns grs itns conv KKT1 KKT2 xtimes 2 39.9969607, 0.9777634 1064.083BFGS 29 10 NULL0 TRUE NA 92.03 1 39.7372199, 0.9778101 1064.083 Nelder-Mead 53 NA NULL0 TRUE NA 70.83 And I've got now a warning message : In log(LikeGi(l, i, par[1], par[2])) : NaNs produced (which are very bad results in that case) Anyone with previous experiences in optimization of several parameters could indicate me the right way to enter the initial parameters in this kind of functions ? Thanks a lot for helping me ! Diane -- Diane Bailleul Doctorante Université Paris-Sud 11 - Faculté des Sciences d'Orsay Unité Ecologie, Systématique et Evolution Département Biodiversité, Systématique et Evolution UMR 8079 - UPS CNRS AgroParisTech Porte 320, premier étage, Bâtiment 360 91405 ORSAY CEDEX FRANCE (0033) 01.69.15.56.64 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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 help
I have a model like this (Nelson and Siegel 1987) img src=http://r.789695.n4.nabble.com/file/n4120161/31f188c684764cd431619dbb59fed5ae.png; border=0/ where tau and y are the maturities and yields, respectively, given to me in my data file.. y-c(4.863,5.662,6.41,6.864,7.153,7.352,7.409,7.474,7.503,7.644,7.676,7.701,7.674,7.668,7.665,7.741,7.743,7.742) tau-c(1,3,6,9,12,15,18,21,24,30,36,48,60,72,84,96,108,120) I firstly need to find the MLE of m which maximises the likelihood function and then I can easily find the b1, b2 and b3 constants using this m value via least squares estimation.. But does anybody know how I can go abouts finding the MLE of m and if you could help with providing r code for it, I would appreciate that a lot. I have been pulling my hair out for the past week now trying to do it :) [[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 Numeric Values Become Factors in Data Frame
Hi Rich, Try looking at: levels(waterchem$SC) There must be something in that column that is triggering R to read it as character. Potential examples include using . to indicate missing values or anything else that is not itself directly numeric. You might also get some mileadge out of attempting to coerce the factor labels to numeric and seeing what errors/warnings arise and if any new values are missing. For instance: x - factor(c(1, 2, NA, 3e5, .)) levels(x) [1] . 1 2 3e5 NA as.numeric(levels(x)) [1]NA 1e+00 2e+00 3e+05NA Warning message: NAs introduced by coercion Nothing else comes to mind off the top of my head to try. Once you determine what is doing it, you can force the class in read.table using the colClasses argument. Cheers, Josh On Tue, Nov 29, 2011 at 11:18 AM, Rich Shepard rshep...@appl-ecosys.com wrote: I have a data frame with 1 factor, one date, and 37 numeric values: str(waterchem) 'data.frame': 3525 obs. of 39 variables: site : Factor w/ 64 levels D-1,D-2,D-3,..: 1 1 1 1 1 ... $ sampdate : Date, format: 2007-12-12 2008-03-15 ... $ CO3 : num 1 1 6.7 1 1 1 1 1 1 1 ... $ HCO3 : num 231 228 118 246 157 208 338 285 260 240 ... $ Ca : num 100 88.4 63.4 123 78.2 103 265 213 178 166 ... $ DO : num 4.96 9.91 4.32 2.58 1.81 5.09 3.98 5.46 1.9 2.52 ... ... $ SC : Factor w/ 841 levels 1.090,10.000,..: 635 638 363 All the numeric categories are read in as numbers except for some of those in column 'SC'. I have been looking in the source file for a couple of hours trying to learn why values such as 1.090 and 10.000 are seen as characters rather than numbers. I've not see the reason. The source file is 860K and looks like this: site|sampdate|'Ag'|'Al'|'CO3'|'HCO3'|'Alk-Tot'|'As'|'Ba'|'Be'|'Bi'|'Ca'|'Cd'|'Cl'|'Co'|'Cr'|'Cu'|'DO'|'Fe'|'Hg'|'K'|'Mg'|'Mn'|'Mo'|'Na'|'NH4'|'NO3-NO2'|'Oil-grease'|'Pb'|'pH'|'Sb'|'SC'|'Se'|'SO4'|'Sr'|'TDS'|'Tl'|'V'|'Zn' 'D-1'|'2007-12-12'|0.000|0.106|1.000|231.000|231.000|0.011|0.000|0.002|0.000|100.000|0.000|1.430|0.000|0.006|0.024|4.960|4.110|NA|0.000|9.560|0.035|0.000|0.970|0.010|0.293|NA|0.025|7.800|0.001|630.000|0.001|65.800|0.000|320.000|0.001|0.000|11.400 'D-1'|'2008-03-15'|0.000|0.080|1.000|228.000|228.000|0.001|0.000|0.002|0.000|88.400|0.000|1.340|0.000|0.006|0.014|9.910|0.309|0.000|0.000|9.150|0.047|0.000|0.820|0.224|0.020|NA|0.025|7.940|0.001|633.000|0.001|75.400|0.000|300.000|0.001|0.000|12.400 The R command used to create the data frame is: waterchem - read.table('wqR.txt', header = TRUE, sep = '|') Pointers on how to determine why this one variable has some values and characters rather than as numerics are needed. Rich __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Joshua Wiley Ph.D. Student, Health Psychology Programmer Analyst II, ATS Statistical Consulting Group University of California, Los Angeles https://joshuawiley.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] Why Numeric Values Become Factors in Data Frame
On Nov 29, 2011, at 2:18 PM, Rich Shepard wrote: I have a data frame with 1 factor, one date, and 37 numeric values: str(waterchem) 'data.frame': 3525 obs. of 39 variables: site : Factor w/ 64 levels D-1,D-2,D-3,..: 1 1 1 1 1 ... $ sampdate : Date, format: 2007-12-12 2008-03-15 ... $ CO3 : num 1 1 6.7 1 1 1 1 1 1 1 ... $ HCO3 : num 231 228 118 246 157 208 338 285 260 240 ... $ Ca: num 100 88.4 63.4 123 78.2 103 265 213 178 166 ... $ DO: num 4.96 9.91 4.32 2.58 1.81 5.09 3.98 5.46 1.9 2.52 ... ... $ SC: Factor w/ 841 levels 1.090,10.000,..: 635 638 363 All the numeric categories are read in as numbers except for some of those in column 'SC'. I have been looking in the source file for a couple of hours trying to learn why values such as 1.090 and 10.000 are seen as characters rather than numbers. I've not see the reason. The source file is 860K and looks like this: site|sampdate|'Ag'|'Al'|'CO3'|'HCO3'|'Alk- Tot '| 'As '| 'Ba '| 'Be '| 'Bi '| 'Ca '| 'Cd '| 'Cl '|'Co'|'Cr'|'Cu'|'DO'|'Fe'|'Hg'|'K'|'Mg'|'Mn'|'Mo'|'Na'|'NH4'|'NO3- NO2'|'Oil- grease'|'Pb'|'pH'|'Sb'|'SC'|'Se'|'SO4'|'Sr'|'TDS'|'Tl'|'V'|'Zn' 'D-1'|'2007-12-12'|0.000|0.106|1.000|231.000|231.000|0.011|0.000| 0.002|0.000|100.000|0.000|1.430|0.000|0.006|0.024|4.960|4.110|NA| 0.000|9.560|0.035|0.000|0.970|0.010|0.293|NA|0.025|7.800|0.001| 630.000|0.001|65.800|0.000|320.000|0.001|0.000|11.400 'D-1'|'2008-03-15'|0.000|0.080|1.000|228.000|228.000|0.001|0.000| 0.002|0.000|88.400|0.000|1.340|0.000|0.006|0.014|9.910|0.309|0.000| 0.000|9.150|0.047|0.000|0.820|0.224|0.020|NA|0.025|7.940|0.001| 633.000|0.001|75.400|0.000|300.000|0.001|0.000|12.400 The R command used to create the data frame is: waterchem - read.table('wqR.txt', header = TRUE, sep = '|') Pointers on how to determine why this one variable has some values and characters rather than as numerics are needed. So what does this show? grep([^0-9.], waterchem$SC) David Winsemius, MD West Hartford, CT __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Why Numeric Values Become Factors in Data Frame
On Nov 29, 2011, at 1:18 PM, Rich Shepard wrote: I have a data frame with 1 factor, one date, and 37 numeric values: str(waterchem) 'data.frame': 3525 obs. of 39 variables: site : Factor w/ 64 levels D-1,D-2,D-3,..: 1 1 1 1 1 ... $ sampdate : Date, format: 2007-12-12 2008-03-15 ... $ CO3 : num 1 1 6.7 1 1 1 1 1 1 1 ... $ HCO3 : num 231 228 118 246 157 208 338 285 260 240 ... $ Ca: num 100 88.4 63.4 123 78.2 103 265 213 178 166 ... $ DO: num 4.96 9.91 4.32 2.58 1.81 5.09 3.98 5.46 1.9 2.52 ... ... $ SC: Factor w/ 841 levels 1.090,10.000,..: 635 638 363 All the numeric categories are read in as numbers except for some of those in column 'SC'. I have been looking in the source file for a couple of hours trying to learn why values such as 1.090 and 10.000 are seen as characters rather than numbers. I've not see the reason. The source file is 860K and looks like this: site|sampdate|'Ag'|'Al'|'CO3'|'HCO3'|'Alk-Tot'|'As'|'Ba'|'Be'|'Bi'|'Ca'|'Cd'|'Cl'|'Co'|'Cr'|'Cu'|'DO'|'Fe'|'Hg'|'K'|'Mg'|'Mn'|'Mo'|'Na'|'NH4'|'NO3-NO2'|'Oil-grease'|'Pb'|'pH'|'Sb'|'SC'|'Se'|'SO4'|'Sr'|'TDS'|'Tl'|'V'|'Zn' 'D-1'|'2007-12-12'|0.000|0.106|1.000|231.000|231.000|0.011|0.000|0.002|0.000|100.000|0.000|1.430|0.000|0.006|0.024|4.960|4.110|NA|0.000|9.560|0.035|0.000|0.970|0.010|0.293|NA|0.025|7.800|0.001|630.000|0.001|65.800|0.000|320.000|0.001|0.000|11.400 'D-1'|'2008-03-15'|0.000|0.080|1.000|228.000|228.000|0.001|0.000|0.002|0.000|88.400|0.000|1.340|0.000|0.006|0.014|9.910|0.309|0.000|0.000|9.150|0.047|0.000|0.820|0.224|0.020|NA|0.025|7.940|0.001|633.000|0.001|75.400|0.000|300.000|0.001|0.000|12.400 The R command used to create the data frame is: waterchem - read.table('wqR.txt', header = TRUE, sep = '|') Pointers on how to determine why this one variable has some values and characters rather than as numerics are needed. Rich Rich, Somewhere in that column are non-numeric characters (other than 0 through 9 and a decimal point), resulting in the column being coerced to a factor. Not fully tested, but using grepl() along the lines of: Vec - c(1.09, 1.23, 1,23, A, 2.067) which(grepl([^0-9\\.], Vec)) [1] 3 4 Will give you the indices of the entries in the column that contain non-numeric characters. Vec[which(grepl([^0-9\\.], Vec))] [1] 1,23 A Will give you the entries themselves. The read.table() family of functions use type.convert() internally to do the data type coercions: type.convert(Vec) [1] 1.09 1.23 1,23 A 2.067 Levels: 1,23 1.09 1.23 2.067 A So 'Vec' is coerced to a factor due to the non-numeric characters contained in the entries. HTH, Marc Schwartz __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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 Numeric Values Become Factors in Data Frame
You can see what the offending strings are with with(waterchem, levels(SC)[is.na(as.numeric(levels(SC)))]) [1] - + Warning message: In eval(expr, envir, enclos) : NAs introduced by coercion but it may be easiest to use the colClasses argument to read.table to force that column to be numeric (with NA's for strings that could not be interpretted as numbers). 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 Rich Shepard Sent: Tuesday, November 29, 2011 11:19 AM To: r-help@r-project.org Subject: [R] Why Numeric Values Become Factors in Data Frame I have a data frame with 1 factor, one date, and 37 numeric values: str(waterchem) 'data.frame': 3525 obs. of 39 variables: site : Factor w/ 64 levels D-1,D-2,D-3,..: 1 1 1 1 1 ... $ sampdate : Date, format: 2007-12-12 2008-03-15 ... $ CO3 : num 1 1 6.7 1 1 1 1 1 1 1 ... $ HCO3 : num 231 228 118 246 157 208 338 285 260 240 ... $ Ca: num 100 88.4 63.4 123 78.2 103 265 213 178 166 ... $ DO: num 4.96 9.91 4.32 2.58 1.81 5.09 3.98 5.46 1.9 2.52 ... ... $ SC: Factor w/ 841 levels 1.090,10.000,..: 635 638 363 All the numeric categories are read in as numbers except for some of those in column 'SC'. I have been looking in the source file for a couple of hours trying to learn why values such as 1.090 and 10.000 are seen as characters rather than numbers. I've not see the reason. The source file is 860K and looks like this: site|sampdate|'Ag'|'Al'|'CO3'|'HCO3'|'Alk- Tot'|'As'|'Ba'|'Be'|'Bi'|'Ca'|'Cd'|'Cl'|'Co'|'Cr'|'Cu'|'DO'|'Fe'|'Hg'|'K'|'Mg'|'Mn'|'Mo'|'Na'|'NH4'|'N O3-NO2'|'Oil-grease'|'Pb'|'pH'|'Sb'|'SC'|'Se'|'SO4'|'Sr'|'TDS'|'Tl'|'V'|'Zn' 'D-1'|'2007-12- 12'|0.000|0.106|1.000|231.000|231.000|0.011|0.000|0.002|0.000|100.000|0.000|1.430|0.000|0.006|0.024|4. 960|4.110|NA|0.000|9.560|0.035|0.000|0.970|0.010|0.293|NA|0.025|7.800|0.001|630.000|0.001|65.800|0.000 |320.000|0.001|0.000|11.400 'D-1'|'2008-03- 15'|0.000|0.080|1.000|228.000|228.000|0.001|0.000|0.002|0.000|88.400|0.000|1.340|0.000|0.006|0.014|9.9 10|0.309|0.000|0.000|9.150|0.047|0.000|0.820|0.224|0.020|NA|0.025|7.940|0.001|633.000|0.001|75.400|0.0 00|300.000|0.001|0.000|12.400 The R command used to create the data frame is: waterchem - read.table('wqR.txt', header = TRUE, sep = '|') Pointers on how to determine why this one variable has some values and characters rather than as numerics are needed. Rich __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] hour in x-axis
without knowing much about your data or the base plotting... I'd use the library ggplot2. First, you'll need to format your dates to POSIXct AggData$time - as.POSIXct(AggData$time,format='%H:%M') Then plotting is trivial. ggplot(AggData,aes(x=time,y=value))+geom_points() or +geom_line() if you'd rather. Hope that helps, Justin On Tue, Nov 29, 2011 at 10:07 AM, threshold r.kozar...@gmail.com wrote: Dear R useres, got the following problem. Given the AggData (listed below) I need to plot AggData[,2] vs time (AggData[,1]) for chosen 'rows'. Ive done already: plot(AggData[rows,2], xaxt='n') axis(1,at=seq(1,length(rows),1),sub(,, AggData[rows,1])) which works, but I need to list only chosen data points, say full hours or every 60th point, something like: axis(1,at=seq(1,seq(1,length(rows),60)),sub(, , AggData[day.rows[seq(1,length(rows),60)],2])) but does not work. Could be nice if time on the x-axis is in H:m format (no seconds). In the original data time bout is 1 minute, e.g. 17:19:35, 17:20:35, 17:21:35 . Taken every 100th for brevity yields (AggData[seq(1,length(rows),100),c(2,7)]) time value 117:19:3580.68327 101 18:59:3580.97230 201 20:39:3578.30810 301 22:19:3580.41558 401 23:59:3577.01051 501 01:39:3577.19687 601 03:19:3578.20762 701 04:59:3577.13315 801 06:39:3576.29110 901 08:19:3575.32090 1001 09:59:3585.32890 1101 11:39:3579.86978 1201 13:19:3583.32418 1301 14:59:3578.26018 1401 16:39:3579.06434 Thanks in advance. Best, robert -- View this message in context: http://r.789695.n4.nabble.com/hour-in-x-axis-tp4120142p4120142.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. [[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] problem during installing bayesQR package for R 2.14 version
By any chance is Kalem accessing the Internet through a proxy server which requires a userid and password. There're are instructions in the Windows FAQ on how to deal with this. He may need to obtain some information from his IT department. Alternatively he could download the zip file and install it from a local directory. John On Tuesday, 29 November 2011, R. Michael Weylandt michael.weyla...@gmail.com wrote: Please cc the general list in your replies. I'm not a Windows expert and there are many on this list who know far more about that OS than I and can handle your question far more ably. As I said I'm not a Windows expert so you may wish to consult the R-Windows FAQ and the R Admin Installation Manuals (both easily google-able) and take the following with a grain of salt, but you can usually install a binary directly with the install.packages() command setting repos = NULL and putting the file-path as the primary argument. E.g., on my Mac this works to install xts remove.packages(xts) library(xts) # Throws error as desired setwd(~/Downloads) install.packages(xts_0.8-2.tgz, repos = NULL) library(xts) # Success! If you downloaded a binary don't worry about compiling the Fortran code: it comes pre-compiled. Michael On Tue, Nov 29, 2011 at 6:46 AM, kalam narendar reddy narendarcse...@gmail.com wrote: thnak u sir for revert back quickly. sir what i have to do now i have downloaded the windows Binary file. what is the next step i have to follow. please help me in this regard. if fortran code is there for bayesian quantile rgression in which directory it is. My os is windows07 Thanks In advance With Regards Kalam Narendar Reddy __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- John C Frain Economics Department Trinity College Dublin Dublin 2 Ireland www.tcd.ie/Economics/staff/frainj/home.html mailto:fra...@tcd.ie mailto:fra...@gmail.com [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] aggregate syntax for grouped column means
I am calculating the mean of each column grouped by the variable 'id'. I do this using aggregate, data.table, and plyr. My aggregate results do not match the other two, and I am trying to figure out what is incorrect with my syntax. Any suggestions? Thanks. Here is the data. myData - structure(list(var1 = c(31.59, 32.21, 31.78, 31.34, 31.61, 31.61, 30.59, 30.84, 30.98, 30.79, 30.79, 30.94, 31.08, 31.27, 31.11, 30.42, 30.37, 30.29, 30.06, 30.3, 30.43, 30.61, 30.64, 30.75, 30.39, 30.1, 30.25, 31.55, 31.96, 31.87, 30.29, 30.15, 30.37, 29.59, 29.52, 28.96, 29.69, 29.58, 29.52, 30.21, 30.3, 30.25, 30.23, 30.29, 30.39), var2 = c(33.78, 33.25, NA, 32.05, 32.59, NA, 32.24, NA, NA, 32.15, 32.39, NA, 32.4, 31.6, NA, 30.5, 30.66, NA, 30.6, 29.95, NA, 31.24, 30.73, NA, 30.51, 30.43, 31.17, 31.44, 31.17, 31.18, 31.01, 30.98, 31.25, 30.44, 30.47, NA, 30.47, 30.56, NA, 30.6, 30.57, NA, 31, 30.8, NA), id = c(0m4, 0m4, 0m4, 0m5, 0m5, 0m5, 0m6, 0m6, 0m6, 0m11, 0m11, 0m11, 0m12, 0m12, 0m12, 205m1, 205m1, 205m1, 205m4, 205m4, 205m4, 205m5, 205m5, 205m5, 205m6, 205m6, 205m6, 205m7, 205m7, 205m7, 600m1, 600m1, 600m1, 600m3, 600m3, 600m3, 600m4, 600m4, 600m4, 600m5, 600m5, 600m5, 600m7, 600m7, 600m7)), .Names = c(var1, var2, id), row.names = c(NA, -45L), class = data.frame) head(myData) var1 var2 id 1 31.59 33.78 0m4 2 32.21 33.25 0m4 3 31.78NA 0m4 4 31.34 32.05 0m5 5 31.61 32.59 0m5 6 31.61NA 0m5 results1 - aggregate(. ~ id ,data=myData,FUN=mean,na.rm=T) head(results1,1) #id var1 var2 # 1 0m11 30.79 32.27 library(data.table) mydt - data.table(myData) setkey(mydt,id) results2 - mydt[,lapply(.SD,mean,na.rm=TRUE),by=id] head(results2,1) # id var1 var2 # [1,] 0m11 30.84 32.27 library(plyr) results3 - ddply(myData,.(id),colwise(mean),na.rm=TRUE) head(results3,1) #id var1 var2 # 1 0m11 30.84 32.27 sessionInfo() R version 2.14.0 (2011-10-31) Platform: i386-pc-mingw32/i386 (32-bit) locale: [1] LC_COLLATE=English_United States.1252 LC_CTYPE=English_United States.1252LC_MONETARY=English_United States.1252 LC_NUMERIC=C [5] LC_TIME=English_United States.1252 attached base packages: [1] stats graphics grDevices utils datasets methods base other attached packages: [1] plyr_1.6 data.table_1.7.3 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] aggregate syntax for grouped column means
The semantics for na.rm are different for aggregate than for the other options. The former removes any rows that contain an NA prior to performing the computation, the latter methods work column-wise. You have to decide which is correct for your purposes. --- 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. Juliet Hannah juliet.han...@gmail.com wrote: I am calculating the mean of each column grouped by the variable 'id'. I do this using aggregate, data.table, and plyr. My aggregate results do not match the other two, and I am trying to figure out what is incorrect with my syntax. Any suggestions? Thanks. Here is the data. myData - structure(list(var1 = c(31.59, 32.21, 31.78, 31.34, 31.61, 31.61, 30.59, 30.84, 30.98, 30.79, 30.79, 30.94, 31.08, 31.27, 31.11, 30.42, 30.37, 30.29, 30.06, 30.3, 30.43, 30.61, 30.64, 30.75, 30.39, 30.1, 30.25, 31.55, 31.96, 31.87, 30.29, 30.15, 30.37, 29.59, 29.52, 28.96, 29.69, 29.58, 29.52, 30.21, 30.3, 30.25, 30.23, 30.29, 30.39), var2 = c(33.78, 33.25, NA, 32.05, 32.59, NA, 32.24, NA, NA, 32.15, 32.39, NA, 32.4, 31.6, NA, 30.5, 30.66, NA, 30.6, 29.95, NA, 31.24, 30.73, NA, 30.51, 30.43, 31.17, 31.44, 31.17, 31.18, 31.01, 30.98, 31.25, 30.44, 30.47, NA, 30.47, 30.56, NA, 30.6, 30.57, NA, 31, 30.8, NA), id = c(0m4, 0m4, 0m4, 0m5, 0m5, 0m5, 0m6, 0m6, 0m6, 0m11, 0m11, 0m11, 0m12, 0m12, 0m12, 205m1, 205m1, 205m1, 205m4, 205m4, 205m4, 205m5, 205m5, 205m5, 205m6, 205m6, 205m6, 205m7, 205m7, 205m7, 600m1, 600m1, 600m1, 600m3, 600m3, 600m3, 600m4, 600m4, 600m4, 600m5, 600m5, 600m5, 600m7, 600m7, 600m7)), .Names = c(var1, var2, id), row.names = c(NA, -45L), class = data.frame) head(myData) var1 var2 id 1 31.59 33.78 0m4 2 32.21 33.25 0m4 3 31.78NA 0m4 4 31.34 32.05 0m5 5 31.61 32.59 0m5 6 31.61NA 0m5 results1 - aggregate(. ~ id ,data=myData,FUN=mean,na.rm=T) head(results1,1) #id var1 var2 # 1 0m11 30.79 32.27 library(data.table) mydt - data.table(myData) setkey(mydt,id) results2 - mydt[,lapply(.SD,mean,na.rm=TRUE),by=id] head(results2,1) # id var1 var2 # [1,] 0m11 30.84 32.27 library(plyr) results3 - ddply(myData,.(id),colwise(mean),na.rm=TRUE) head(results3,1) #id var1 var2 # 1 0m11 30.84 32.27 sessionInfo() R version 2.14.0 (2011-10-31) Platform: i386-pc-mingw32/i386 (32-bit) locale: [1] LC_COLLATE=English_United States.1252 LC_CTYPE=English_United States.1252LC_MONETARY=English_United States.1252 LC_NUMERIC=C [5] LC_TIME=English_United States.1252 attached base packages: [1] stats graphics grDevices utils datasets methods base other attached packages: [1] plyr_1.6 data.table_1.7.3 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] aggregate syntax for grouped column means
look at just your data that is in that first id category and I bet you can figure it out! myData[myData$id=='0m11',] var1 var2 id 10 30.79 32.15 0m11 11 30.79 32.39 0m11 12 30.94NA 0m11 aggregate performs the na.rm step on the entire row thus, a mean of 30.79. data.table and plyr perform the na.rm on each column. Justin On Tue, Nov 29, 2011 at 12:21 PM, Juliet Hannah juliet.han...@gmail.comwrote: I am calculating the mean of each column grouped by the variable 'id'. I do this using aggregate, data.table, and plyr. My aggregate results do not match the other two, and I am trying to figure out what is incorrect with my syntax. Any suggestions? Thanks. Here is the data. myData - structure(list(var1 = c(31.59, 32.21, 31.78, 31.34, 31.61, 31.61, 30.59, 30.84, 30.98, 30.79, 30.79, 30.94, 31.08, 31.27, 31.11, 30.42, 30.37, 30.29, 30.06, 30.3, 30.43, 30.61, 30.64, 30.75, 30.39, 30.1, 30.25, 31.55, 31.96, 31.87, 30.29, 30.15, 30.37, 29.59, 29.52, 28.96, 29.69, 29.58, 29.52, 30.21, 30.3, 30.25, 30.23, 30.29, 30.39), var2 = c(33.78, 33.25, NA, 32.05, 32.59, NA, 32.24, NA, NA, 32.15, 32.39, NA, 32.4, 31.6, NA, 30.5, 30.66, NA, 30.6, 29.95, NA, 31.24, 30.73, NA, 30.51, 30.43, 31.17, 31.44, 31.17, 31.18, 31.01, 30.98, 31.25, 30.44, 30.47, NA, 30.47, 30.56, NA, 30.6, 30.57, NA, 31, 30.8, NA), id = c(0m4, 0m4, 0m4, 0m5, 0m5, 0m5, 0m6, 0m6, 0m6, 0m11, 0m11, 0m11, 0m12, 0m12, 0m12, 205m1, 205m1, 205m1, 205m4, 205m4, 205m4, 205m5, 205m5, 205m5, 205m6, 205m6, 205m6, 205m7, 205m7, 205m7, 600m1, 600m1, 600m1, 600m3, 600m3, 600m3, 600m4, 600m4, 600m4, 600m5, 600m5, 600m5, 600m7, 600m7, 600m7)), .Names = c(var1, var2, id), row.names = c(NA, -45L), class = data.frame) head(myData) var1 var2 id 1 31.59 33.78 0m4 2 32.21 33.25 0m4 3 31.78NA 0m4 4 31.34 32.05 0m5 5 31.61 32.59 0m5 6 31.61NA 0m5 results1 - aggregate(. ~ id ,data=myData,FUN=mean,na.rm=T) head(results1,1) #id var1 var2 # 1 0m11 30.79 32.27 library(data.table) mydt - data.table(myData) setkey(mydt,id) results2 - mydt[,lapply(.SD,mean,na.rm=TRUE),by=id] head(results2,1) # id var1 var2 # [1,] 0m11 30.84 32.27 library(plyr) results3 - ddply(myData,.(id),colwise(mean),na.rm=TRUE) head(results3,1) #id var1 var2 # 1 0m11 30.84 32.27 sessionInfo() R version 2.14.0 (2011-10-31) Platform: i386-pc-mingw32/i386 (32-bit) locale: [1] LC_COLLATE=English_United States.1252 LC_CTYPE=English_United States.1252LC_MONETARY=English_United States.1252 LC_NUMERIC=C [5] LC_TIME=English_United States.1252 attached base packages: [1] stats graphics grDevices utils datasets methods base other attached packages: [1] plyr_1.6 data.table_1.7.3 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Weird Excel Time Format
-Original Message- From: r-help-boun...@r-project.org [mailto:r-help-bounces@r- project.org] On Behalf Of Hasan Diwan Sent: Tuesday, November 29, 2011 10:16 AM To: Prof Brian Ripley Cc: R Project Help Subject: Re: [R] Weird Excel Time Format On 29 November 2011 09:32, Prof Brian Ripley rip...@stats.ox.ac.uk wrote: If all else fails, read the help page. There are examples on ?as.Date of reading Excel dates. I did, it seems there is either (a) a problem with my code, or (b) a problem with the documentation. See below: rawtimeColumn [1] 39406.577662037 39406.5862847222 39406.592361 39406.5972800926 39406.603819 39406.6445601852 39406.6478587963 39406.6619212963 39406.6634259259 39406.6643518519 [11] 39406.665162037 39406.6659143519 39406.666319 39406.668287037 39406.6702546296 39406.6722106481 39406.6728587963 39406.6731481481 39406.6049768518 39406.585417 [21] 39406.589583 39406.592361 39406.59375 39406.597222 39406.601389 39406.60625 39406.619444 39406.620139 39406.621528 14:5730 [31] 39406.626389 39406.627778 39406.629861 39406.629861 39406.634028 39406.636806 39406.640972 as.Date(as.numeric(rawtimeColumn), origin='1904-01-01') # per as.Date() help [1] 1904-01-04 1904-01-07 1904-01-13 1904-01-19 1904-01-23 1904-02-18 1904-02-21 1904-02-29 1904-03-01 1904-03-02 1904-03-03 1904-03-04 1904-03-05 1904-03-06 [15] 1904-03-07 1904-03-08 1904-03-09 1904-03-10 1904-01-25 1904-01-06 1904-01-11 1904-01-13 1904-01-16 1904-01-18 1904-01-20 1904-01-26 1904-01-31 1904-02-01 [29] 1904-02-03 1904-01-02 1904-02-06 1904-02-07 1904-02-10 1904-02-10 1904-02-12 1904-02-13 1904-02-15 These readings were taken at the 23rd of November in 2011. But I don't believe the time you give. (0.577662037 is just before 13:51:50). It was contrived, so probably was wrong and I should have made that explicit. The suggestions you have received about using CSV files to transfer data from Excel are useful, and in this case would have shown up a problem in the dates. If you look at item 30 in rawtimeColumn, i.e. rawtimeColumn[30] you will see the value 14:5730. This is not a valid numeric (nor date) value so rawtimeColumn was coerced to factor. By using as.numeric(rawtimeColumn), you were not converting the factor levels to dates, but the rather the underlying factor integer representation (i.e. 1,2,3 ...) to dates. Since, '14:5730' appears to be smallest value in lexical ordering, it has an underlying value of 1, and you can see it was converted to '1904-01-02', the day after the origin (which is day 0). Hope this is helpful, Dan Daniel J. Nordlund Washington State Department of Social and Health Services Planning, Performance, and Accountability Research and Data Analysis Division Olympia, WA 98504-5204 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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 in determining the formula for a mixed model analysis
Dear R and statistics experts: I have data of a behavioral experiment with the aim to investigate the effect of a memory task on motor learning. Question: I would appreciate help in figuring out a possible formula to determine whether motor learning across sessions differs between 2 groups. Design: - 2 Groups: group A: n=10 subjects, group B: n=10 - 6 motor learning sessions: baseline; immediately after memory task; 6h, 24h, 30d later, and 30d later with a different motor task - dependent variable: response time (RT) I tried the following: (lme4 package of R, I assumed that Subject is the random factor, and Session and Group the fixed factors.) fm1 - lmer(RT ~ Session + Group + (1|Subject) + (1|Subject:Session), table) I would appreciate any help on the formula or the choice of statistical approach. Thanks! Marianne,Columbia SC [[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] Vegan: Diversity Plot, label points
On Wed, 2011-11-23 at 16:02 -0300, Alejo C.S. wrote: Dear List, I can'f figure how to add point labels in the next plot (example from ?taxondive help page): library(vegan) data(dune) data(dune.taxon) taxdis - taxa2dist(dune.taxon, varstep=TRUE) mod - taxondive(dune, taxdis) plot(mod) The points in this plot are diversity values of single sites, and I'd like to add a label to each one. The plot command don't accept a label argument. Any tip? A couple of options: with(mod, text(Species, Dplus, label = rownames(dune), pos = 2, cex = 0.7)) fiddle with pos - see ?text for details. Another option is with(mod, identify(Species, Dplus, label = rownames(dune), cex = 0.9)) where you now click around the points you want to label. See ?identify for further details. HTH G Thanks in advance. Alejo __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- %~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~% Dr. Gavin Simpson [t] +44 (0)20 7679 0522 ECRC, UCL Geography, [f] +44 (0)20 7679 0565 Pearson Building, [e] gavin.simpsonATNOSPAMucl.ac.uk Gower Street, London [w] http://www.ucl.ac.uk/~ucfagls/ UK. WC1E 6BT. [w] http://www.freshwaters.org.uk %~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~% __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] I cannot get species scores to plot with site scores in MDS when I use a distance matrix as input. Problems with NA's?
On Thu, 2011-11-24 at 07:57 -0800, B77S wrote: Try the daisy() function from the package cluster, it seems to be able to handle NAs and non-dummy coded character variables metaMDS(daisy(df, metric=gower)) That won't help the OP as the species scores (the species data, i.e. the traits in this case) can not be computed from a site x site dissimilarity matrix. This is has the same problem as the OPs existing problem. G Edwin Lebrija Trejos wrote Hi, First I should note I am relatively new to R so I would appreciate answers that take this into account. I am trying to perform an MDS ordination using the function “metaMDS” of the “vegan” package. I want to ordinate species according to a set of functional traits. “Species” here refers to “sites” in traditional vegetation analyses while “traits” here correspond to “species” in such analyses. My data looks like this: Trait1 Trait2 Trait3 Trait4 Trait5 Trait… Species1 228.44 16.56 1.66 13.22 1 short Species2 150.55 28.07 0.41 0.60 1 mid Species3 NA 25.89 NA 0.55 0 large Species4 147.70 17.65 0.42 1.12 NA large Species… 132.68 NA 1.28 2.75 0 short Because the traits have different variable types, different measurement scales, and also missing values for some species, I have calculated the matrix of species distances using the Gower coefficient of similarity available in Package “FD” (which allows missing values). My problem comes when I create a bi-plot of species and traits. As I have used a distance matrix in function “metaMDS” there are no species scores available. This is given as a warning in R: NMDSgowdis- metaMDS(SpeciesGowdis) plot(NMDSgowdis, type = t) Warning message:In ordiplot(x, choices = choices, type = type, display = display, :Species scores not available” I have read from internet resources that in principle I could obtain the trait (species) scores to plot them in the ordination but my attempts have been unsuccessful. I have tried using the function “wascores” in package vegan and “add.spec.scores” in package BiodiversityR. For this purpuse I have created a new species x traits table where factor traits were coded into dummy variables and all integer variables (including binary) were coerced to numeric variables. Here are the codes used and the error messages I have got: “ NMDSgowdis- metaMDS(SpeciesGowdis) NMDSpoints-postMDS(NMDSgowdis$points,SpeciesGowdis) NMDSwasc-wascores(NMDSpoints,TraitsNMDSdummies) Error in if (any(w 0) || sum(w) == 0) stop(weights must be non-negative and not all zero) : missing value where TRUE/FALSE needed” I imagine the problem is with the NA’s in the data. Alternatively, I have used the “add.spec.scores” function, method=”cor.scores”, found in package BiodiversityR. This seemed to work, as I got no error message, but the species scores were not returned. Here the R code and results: “ A-add.spec.scores(ordi=NMDSgowdis,comm=TraitsNMDSdummies,method=cor.scores,multi=1, Rscale=F,scaling=1) plot(A) Warning message:In ordiplot(x, choices = choices, type = type, display = display, :Species scores not available“ Can anyone guide me to get the trait (“species”) scores to plot together with my species (“site”) scores? Thanks in advance, Edwin __ R-help@ mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- View this message in context: http://r.789695.n4.nabble.com/I-cannot-get-species-scores-to-plot-with-site-scores-in-MDS-when-I-use-a-distance-matrix-as-input-Pr-tp4103699p4104406.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. -- %~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~% Dr. Gavin Simpson [t] +44 (0)20 7679 0522 ECRC, UCL Geography, [f] +44 (0)20 7679 0565 Pearson Building, [e] gavin.simpsonATNOSPAMucl.ac.uk Gower Street, London [w] http://www.ucl.ac.uk/~ucfagls/ UK. WC1E 6BT. [w] http://www.freshwaters.org.uk %~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~% __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal,
Re: [R] I cannot get species scores to plot with site scores in MDS when I use a distance matrix as input. Problems with NA's?
On Thu, 2011-11-24 at 12:16 +, Edwin Lebrija Trejos wrote: Hi, First I should note I am relatively new to R so I would appreciate answers that take this into account. I am trying to perform an MDS ordination using the function “metaMDS” of the “vegan” package. I want to ordinate species according to a set of functional traits. “Species” here refers to “sites” in traditional vegetation analyses while “traits” here correspond to “species” in such analyses. My data looks like this: Trait1 Trait2 Trait3 Trait4 Trait5 Trait… Species1 228.44 16.56 1.66 13.22 1 short Species2 150.55 28.07 0.41 0.60 1 mid Species3 NA 25.89 NA 0.55 0 large Species4 147.70 17.65 0.42 1.12 NA large Species… 132.68 NA 1.28 2.75 0 short snip / Can anyone guide me to get the trait (“species”) scores to plot together with my species (“site”) scores? Thanks in advance, Edwin I think you should pass metaMDS the species trait matrix and then get it to use FD to compute the dissimilarities. Note from ?metaMDS there is a distfun argument for metaMDSdit. metaMDS passes the community data to metaMDSdist to compute the dissimilarities. The only snag is that gowdis doesn't accept a `method` argument so we need a wrapper: wrapper - function(x, method, ...) { gowdis(x, ...) } then do metaMDS(SpeciesGowdis, distfun = wrapper, X) where represents any other arguments you want to pass to gowdis via our wrapper. Essentially the wrapper ignores the method argument, we just need it as metaMDSdist wants to call the dissimilarity function with a method argument. This is not tested as there wasn't reproducible code, but hopefully you'll be able to work it out from the above. HTH G -- %~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~% Dr. Gavin Simpson [t] +44 (0)20 7679 0522 ECRC, UCL Geography, [f] +44 (0)20 7679 0565 Pearson Building, [e] gavin.simpsonATNOSPAMucl.ac.uk Gower Street, London [w] http://www.ucl.ac.uk/~ucfagls/ UK. WC1E 6BT. [w] http://www.freshwaters.org.uk %~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~% __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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 Numeric Values Become Factors in Data Frame
On Tue, 29 Nov 2011, Rich Shepard wrote: Pointers on how to determine why this one variable has some values and characters rather than as numerics are needed. Joshua, Marc, David, Bill, Sarah, Bert, et al.: Thank you all for the insights and ideas. It was a valuable lesson and it helped me fix the problem. Somehow my client had URLs in two data cells of the original Excel spreadsheet. I removed that in my LibreOffice copy and exported the file as a .csv. But, I was using a prior version with the cruft still in there when I read it into R. Now that I corrected the problem (and fixed mis-entered conductivity values 100) the R data frame is correct: str(waterchem) 'data.frame': 3524 obs. of 39 variables: $ site : Factor w/ 64 levels D-1,D-2,D-3,..: 1 1 1 1 1 1 ... $ sampdate : Date, format: 2007-12-12 2008-03-15 ... $ Ag: num 0 0 0 0 0 0 0 0 0 0 ... $ Al: num 0.106 0.08 0.116 0.08 0.08 0.08 0.08 0.08 0.08 0.08 ... $ CO3 : num 1 1 6.7 1 1 1 1 1 1 1 ... ... $ SC: num 630 633 386 503 83.2 538 1450 1130 1040 940 ... I knew there was a non-number in there but didn't see it. Your guidance not only taught me how to find it, but made me aware that while I was searching in the cleaned up text file R was fed the old version. Very much appreciated, Rich __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Problem in log
Hi all I have a function of log defined by y = log(1- exp(-a)), when exp(-a) is greater, 1, it produce NaN. How can I remove this in R? [[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] Problem in log
Do you mean remove the NaNs? Try na.omit() or complete.cases() or many other options. If you mean you want the complex log, try log(as.complex(1-exp(-a))) Michael On Tue, Nov 29, 2011 at 5:02 PM, Gyanendra Pokharel gyanendra.pokha...@gmail.com wrote: Hi all I have a function of log defined by y = log(1- exp(-a)), when exp(-a) is greater, 1, it produce NaN. How can I remove this in R? [[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] [SOLVED]looking for beta parameters
I managed to solve the problem myself without using this code. thx 2011-11-24 12:26 keltezéssel, Kehl Dániel írta: Dear Community, I am trying to write code for the following problem. Lets assume we have a beta distribution. I know one quantile, lets say, 10% of the mass lies above .8, that is between .8 and 1. In addition, I know that the average of this truncated tail is a given number, lets say .86. I have found the beta.select function in the LearnBayes package, which is as follows: function (quantile1, quantile2) { betaprior1 = function(K, x, p) { m.lo = 0 m.hi = 1 flag = 0 while (flag == 0) { m0 = (m.lo + m.hi)/2 p0 = pbeta(x, K * m0, K * (1 - m0)) if (p0 p) m.hi = m0 else m.lo = m0 if (abs(p0 - p) 1e-04) flag = 1 } return(m0) } p1 = quantile1$p x1 = quantile1$x p2 = quantile2$p x2 = quantile2$x logK = seq(-3, 8, length = 100) K = exp(logK) m = sapply(K, betaprior1, x1, p1) prob2 = pbeta(x2, K * m, K * (1 - m)) ind = ((prob2 0) (prob2 1)) app = approx(prob2[ind], logK[ind], p2) K0 = exp(app$y) m0 = betaprior1(K0, x1, p1) return(round(K0 * c(m0, (1 - m0)), 2)) } I assume one could change this code to get the results I need, but some parts of the function are not clear for me, any help would be greatly appreciated. Thanks a lot: Daniel [[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.