Re: [R] Maximum likelihood estimate ofbivariatevonmises-weibulldistribut
r-help@stat.math.ethz.ch on Saturday, May 13, 2006 at 6:00 AM -0500 wrote: One of my friends recently wrote his PhD thesis from University of Leeds under Kanti Mardia's direction. I bet your friend was really angling for that. -- Alan B. Cobo-Lewis, Ph.D. (207) 581-3840 tel Department of Psychology(207) 581-6128 fax University of Maine Orono, ME 04469-5742[EMAIL PROTECTED] http://www.umaine.edu/visualperception __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] Simulating scalar-valued stationary Gaussian processes
Mikael Anderson mikael.anderson at gmail.com writes: Hi, I have a sample of size 100 from a function in interval [0,1] which can be assumed to come from a scalar-valued stationary Gaussian process. There are about 500 observation points in the interval. I need an effective and fast way to simulate from the Gaussian process conditioned on the available data. I can of course estimate the mean and 500x500 covariance matrix from data. I have searched both the Rsite and Internet in general but have not found any function or program which could work directly for this type of data. There are some packages in R to simulate from Gaussian processes(e.g. geoR, waveslim and spectralGP) but I couldn't figure out if any function in these packages could work in my framework. Given the size of covariance matrix I was thinking about using SVD to reduce the size but I would like to hear from the list members if there are more effective ways of doing this. One option would be to Fourier transform, randomize the phase, and back-transform: something like function (x, covar = NULL, argtype = even, intype = cov) { l - length(x) if (!is.null(covar)) x - x * sqrt(covar/var(x)) y - fft(x) if (argtype == even) { if (l%%2 != 0) { cat(length must be even, for now\n) return(NA) } arg0 - runif(l/2 - 1, -pi, pi) arg1 - c(0, arg0, 0, -rev(arg0)) } else if (argtype == zero) arg1 - rep(0, length(y)) else if (argtype == random) arg1 - runif(l, -pi, pi) z - complex(modulus = Mod(y), argument = arg1) y - fft(z, inverse = TRUE)/l chop(y) } of course this also depends exactly what you mean by conditioned on the available data -- and how do you feel about parametric models? RandomFields has lots of tools for conditional simulation, if you don't mind fitting a parametric covariance model to your data ... Ben Bolker __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] .Rprofile file and .First function
On May 12, 2006, at 4:06 PM, MARK LEEDS wrote: would someone mind to send me an example of a .Rprofile file and a .First function just so I can get an idea. Thanks a lot. I don't have a .First function, but here's my .Rprofile: # options for the interactive environment options(prompt=\nR ) ; options(width=1000) ; quit - To quit, type q() ; exit - To exit, type q() ; q - Almost there. To quit, type q() ; # familiar aliases / functions h - function() { history(max.show = Inf) } ; printf - function (...) { cat(sprintf(...)) ; } ; Regards, - Robert http://www.cwelug.org/downloads Help others get OpenSource software. Distribute FLOSS for Windows, Linux, *BSD, and MacOS X with BitTorrent __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] R-help Digest, Vol 39, Issue 13
r-help@stat.math.ethz.ch on Saturday, May 13, 2006 at 6:00 AM -0500 wrote: lme(biomass~age, random=~woods/age)? Jörn Consult Pinheiro and Bates (2000, Mixed-effects models in S and S-Plus, Springer, ISBN 0-387-98957-0 ref 7 at http://www.r-project.org/doc/bib/R-books.html ) for how to fit more elaborate models, but two straightforward ones that might be adequate are lme( biomass~age, random=~1|woods ) and lme( biomass~age, random=~age|woods ) In the lme4 library corresponding syntax is lmer( biomass~age+(1|woods) ) and lmer( biomass~age+(age|woods) ) For vignettes on the lme4 library see the mlmRev library and @ARTICLE{Rnews:Bates:2005, AUTHOR = {Douglas Bates}, TITLE = {Fitting Linear Mixed Models in {R}}, JOURNAL = {R News}, YEAR = 2005, VOLUME = 5, NUMBER = 1, PAGES = {27--30}, MONTH = {May}, URL = {[ http://CRAN.R-project.org/doc/Rnews/ ]http://CRAN.R-project.org/doc/Rnews/} } alan -- Alan B. Cobo-Lewis, Ph.D. (207) 581-3840 tel Department of Psychology(207) 581-6128 fax University of Maine Orono, ME 04469-5742[EMAIL PROTECTED] http://www.umaine.edu/visualperception __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] [R-pkgs] New CRAN package DPpackage
Dear List, I am pleased to announce the release of version 1.0.0 of DPpackage on CRAN. DPpackage covers some important models using Dirichlet process priors. The package includes: Semiparametric Bernoulli regression Semiparametric Density estimation Semiparametric Linear mixed models Semiparametric Generalized linear mixed models Semiparametric AFT model for interval-censored data I would very much appreciate any comments/errors/suggestions for future development. Best regards, Alejandro Jara. Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm ___ R-packages mailing list [EMAIL PROTECTED] https://stat.ethz.ch/mailman/listinfo/r-packages __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] Contour plot overlayed with line plot
It seems you have figured out a solution; for another example, you could look here: http://addictedtor.free.fr/graphiques/RGraphGallery.php?graph=90 Mike Jonathan Greenberg wrote on 5/10/2006 7:46 PM: I apologize for what may be a newbie question: I have two sets of data, one is X,Y,Z data that I'd like to make a contour plot of (Z defining the contours), and a second set of X,Y data (Y as a function of X) which I would like made into a line plot OVERLAYED on the contour plot (X and Y from both plots are in the same units and will have overlapping values). Any suggestions on how to do this in R? Thanks! --j -- Michael H. Prager, Ph.D. Population Dynamics Team NOAA Center for Coastal Habitat and Fisheries Research NMFS Southeast Fisheries Science Center Beaufort, North Carolina 28516 USA http://shrimp.ccfhrb.noaa.gov/~mprager/ __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] What does it mean to be masked from data when attaching? (Newbie question)
the problem you get comes from the fact that you attach the data.frame, e.g., it can be re-produced by: x1 - rnorm(30) dat - data.frame(x1 = rnorm(30)) attach(dat) look at ?attach for more details; you could consider with() as an alternative. I hope it helps. Best, Dimitris -- Dimitris Rizopoulos Ph.D. Student Biostatistical Centre School of Public Health Catholic University of Leuven Address: Kapucijnenvoer 35, Leuven, Belgium Tel: +32/(0)16/336899 Fax: +32/(0)16/337015 Web: http://med.kuleuven.be/biostat/ http://www.student.kuleuven.be/~m0390867/dimitris.htm Quoting Ben Fairbank [EMAIL PROTECTED]: I have several data frames, each with six variables and several hundred cases broken out from a larger dataframe by eleven values of a factor called Division. I have to perform the same analysis on each one. I would like to do it by creating a data frame called data2 eleven times, once with data corresponding to each value of the factor, and performing the same analysis on each of the eleven values of data2. However, when I assign to data2 the value of one of my data frames, e.g. data2 - Florida, and then attach data2, I get the warning The following object(s) are masked from data2 ( position 3 ) : Day Division SchedNo Spent TimeEnter TimeInStr The following object(s) are masked from Alb3 : Day Division SchedNo Spent TimeEnter TimeInStr The following object(s) are masked from data2 ( position 5 ) : Day Division SchedNo Spent TimeEnter TimeInStr I am having trouble finding an explanation of these messages, what the position refers to, and what it means to be masked. Can someone steer me to an online explanation? And by the way, one of the analyses I have to perform is simply to tabulate the days of the week that occur in variable Day by using table(Day) which gives, for example, Day Fri Mon Sat Sun Thur Tue Wed 173 191 111 92 188 218 187 What is the proper syntax for doing that by levels of a factor within the large data frame containing all eleven factors? I have unsuccessfully tried to use by. Thanks, Ben F. [[alternative HTML version deleted]] __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] bitwise addition
On Fri, 2006-05-12 at 15:35 -0500, Nameeta Lobo wrote: Hi again Sorry I should have been more specific the first time. I am not actually trying to generate this matrix but what am trying to do is to write a loop which takes an input of , does a bitwise addition, then checks to see if the new number generated has two 1s(I just summed the values to get 2) and if it does outputs that to a matrix. It goes on doing it till it reaches . So my final output for the above would read 0011 0101 0110 1001 1010 1100 For 2^6, I was looking for three 1s and so on. I wrote this in a for loop etc. Created the original matrix with expand.grid command that you guys helped me out with before. My only concern was that for e.g. 2^25 or higher, not much space can be allocated to the creation of the original matrix and then also because of the loops there is the problem of computer time. So was just wondering if it was easier to do it via bitwise addition. thanks a lot for your help everyone. any more suggestion nameeta Nameeta, This approach is still heavily time bound due to the process of comparing the resultant binary representations against the desired number of 1's. It is probably O(n^3) or worse. To improve on this, I suspect you will need to go to a compiled language such as C, where you can engage in more efficient bit level manipulations. Though perhaps somebody else here will have some further thoughts. My premise is that you are not just adding any number to 0, but are going in integer sequence from 0:((2^x) - 1) looking for a fixed number of 1's. Here is the code. It requires the use of Martin's digitsBase() function from package sfsmisc to create the binary representations of the integers. FindOnes - function(exp, ones) { checkDigits - function(x) { n - digitsBase(x, ndigits = exp) if (sum(n) == ones) paste(n, collapse = ) } L - sapply(1:((2^exp) - 1), checkDigits) do.call(rbind, L) } To use it: exp: The exponent desired, as in (2 ^ exp) ones: The number of 1's desired in the binary representation So for example: # Use 2^4 and get results with 2 1's # Took 0.004 seconds FindOnes(4, 2) [,1] [1,] 0011 [2,] 0101 [3,] 0110 [4,] 1001 [5,] 1010 [6,] 1100 # 2^6 with 3 1's # Took 0.02 seconds FindOnes(6, 3) [,1] [1,] 000111 [2,] 001011 [3,] 001101 [4,] 001110 [5,] 010011 [6,] 010101 [7,] 010110 [8,] 011001 [9,] 011010 [10,] 011100 [11,] 100011 [12,] 100101 [13,] 100110 [14,] 101001 [15,] 101010 [16,] 101100 [17,] 110001 [18,] 110010 [19,] 110100 [20,] 111000 Testing with 2^18 looking for 9 1's: system.time(x - FindOnes(18, 9)) [1] 76.089 0.664 86.535 0.000 0.000 str(x) chr [1:48620, 1] 01 10 ... object.size(x) [1] 2722840 I am curious as to your application here. HTH, Marc Schwartz __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] apply
Dear Sir, Iam a new user of R Software. I thank you very much for this Software. By running the R 2.3.0 software I have encountred aproblem: I have downloaded the tseriesChaos package from CRAN. When I try to run any function of the the tseriesChaos package for example, the c2 function the R software diplays on the screen error, impossible to find the c2 function). Please help me! What shall I do to add on this package and run it correctly? Why the Software displays error, impossible to find the c2 function? Is it caused by a damaged version of the R 2.3.0? I thank you in advance and I am waiting forward your e-mail This is my e-mail: [EMAIL PROTECTED] Accédez au courrier électronique de La Poste : www.laposte.net ; 3615 LAPOSTENET (0,34 /mn) ; tél : 08 92 68 13 50 (0,34/mn) [[alternative HTML version deleted]] __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] apply
On Sat, 2006-05-13 at 23:02 +0200, karim.regh wrote: Dear Sir, Iam a new user of R Software. I thank you very much for this Software. By running the R 2.3.0 software I have encountred aproblem: I have downloaded the tseriesChaos package from CRAN. When I try to run any function of the the tseriesChaos package for example, the c2 function the R software diplays on the screen error, impossible to find the c2 function). Please help me! What shall I do to add on this package and run it correctly? Why the Software displays error, impossible to find the c2 function? Is it caused by a damaged version of the R 2.3.0? I thank you in advance and I am waiting forward your e-mail Did you use: library(tseriesChaos) before trying to use the functions that are contained in it? See R FAQ: 7.30 I installed a package but the functions are not there Reading the Posting Guide as noted at the bottom of each e-mail coming through the list would enable you to solve many basic problems such as this. HTH, Marc Schwartz __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] Fwd: Newbie to R: would like to solve a problem
I forgot to forward the message to the group :-/ And I have one more question, but it pertains somewhat to this last post (which is why I attached the last message) What is the name of the distribution that takes skewness and kurtosis as a factor? I figure, if I can find a distribution that better models the damage done in this game, it would be better off period. A normal curve estimates the data pretty darn well already, maybe adding in skewness and kurtosis will make the model close to exact. I tried searching for skewness and kertosis on google, and found some information on a Weibull distribution, but it only seems to model skewness and not as much kurtosis. Is there a specific distribution that can model data based on both skewness and kurtosis? -- Forwarded message -- From: percy tiglao [EMAIL PROTECTED] Date: May 12, 2006 5:16 PM Subject: Re: [R] Newbie to R: would like to solve a problem To: McGehee, Robert [EMAIL PROTECTED] On 5/12/06, McGehee, Robert [EMAIL PROTECTED] wrote: Not sure I completely followed (especially what a Knockback is), but I'll give this a try. Lol :-) Video game stuff. Unimportant. You got the main gist of what I want though. If you want to precisely define the convolution of multiple attacks, you would want to use a language that utilizes symbolic integration, which R currently does not support (e.g. see Mathematica). That said, it sounds like you don't actually want a precise answer, but you want to have a polynomial function estimate the true distribution. If this is the case, then it seems like doing a simulation may be precisely what you want. That is, model a polynomial approximation of the total damage from multiple attacks as a function of the number of attacks. Ah. So to get the precise formula, I need Mathematica? Gosh... I'll just do it by hand then, Lol. I'm so cheap :-/ Well, a simulation was the 2nd thing I was going to ask for if there was no way for this to work out. For instance the function below will plot what the distribution of N multiple attacks would look like: distributionFun - function(N, min, max, skill, num_attacks) { hist(replicate(1000, sum(replicate(N, total_damage(min, max, skill, num_attacks) } and sum(replicate(N, total_damage(min, max, skill, num_attacks))) will give you a sample from this distribution. Thus, distributionFun(1, 10, 20, 1, 1) will show the piecewise constant distribution that you would expect from a single attack, and setting N to a large number produces a Gaussian distribution (CLT). [NB: Here the N and num_attacks arguments may be redundant, but it's not clear to me how these multiple attacks work (i.e. are there multiple attacks multiple times, etc.)] If I'm reading this code correctly, You got 100% what I was looking for, in terms of simulation anyway :) Once you have the simulated distribution, you can either create a polynomial model as a function of N and use these values as inputs into your web simulation, or you can use the code above to grab a single sample from the distribution. Also, I imagine you would get better results modeling the moments of the distribution (mean, variance, skew, kurtosis, etc.) rather than using a polynomial function, but up to you. Wow... there is so much more math I need to learn before I attempt this problem again... Kurtosis? Thank god for Wikipedia + googleing tutorials. And since when was skewness represented as a number? o.O Also, if you're only doing this for the first 8 attacks, then integrating a piecewise constant function by hand (if Mathematica is unavailable) is not too difficult, and running simulations may be going overboard. Not with high-school level Math knowledge it is. Lol. *note to self, start buying math books* Lastly, just as an FYI, your functions can be rewritten a bit more concisely as such: sdmg - function(min, max, skill) { runif(1, min, max) * ifelse(runif(1) 0.4, skill, skill + 1) } total_damage - function(min, max, skill, num_attacks) { sum(replicate(num_attacks, sdmg(min, max, skill)) } Good luck, Robert Thanks so much for all your help. I'll be looking into other languages (like Yacas) to see if they can do this precisely (Idealy, I need it as a function of min, max, and skill. That way, It will be easy enough for Javascript to calculate.) __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] What does it mean to be masked from data when attaching? (Newbie question)
On 5/13/2006 2:52 PM, Ben Fairbank wrote: I have several data frames, each with six variables and several hundred cases broken out from a larger dataframe by eleven values of a factor called Division. I have to perform the same analysis on each one. I would like to do it by creating a data frame called data2 eleven times, once with data corresponding to each value of the factor, and performing the same analysis on each of the eleven values of data2. However, when I assign to data2 the value of one of my data frames, e.g. data2 - Florida, and then attach data2, I get the warning The following object(s) are masked from data2 ( position 3 ) : Day Division SchedNo Spent TimeEnter TimeInStr The following object(s) are masked from Alb3 : Day Division SchedNo Spent TimeEnter TimeInStr The following object(s) are masked from data2 ( position 5 ) : Day Division SchedNo Spent TimeEnter TimeInStr I am having trouble finding an explanation of these messages, what the position refers to, and what it means to be masked. Can someone steer me to an online explanation? It is the position in the search list. See search() for the complete list. It sounds as though you are attaching things, but not detaching them: and R is warning that the new attach is hiding something from the previous one. The Introduction to R manual discusses this in the Data frames section of the Lists and data frames chapter. Duncan Murdoch And by the way, one of the analyses I have to perform is simply to tabulate the days of the week that occur in variable Day by using table(Day) which gives, for example, Day Fri Mon Sat Sun Thur Tue Wed 173 191 111 92 188 218 187 What is the proper syntax for doing that by levels of a factor within the large data frame containing all eleven factors? I have unsuccessfully tried to use by. Thanks, Ben F. [[alternative HTML version deleted]] __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] Adding error bars to a trellis barchart display
Hi all -- I'm using trellis to generate bar charts, but there's no built-in function to generate error bars or confidence intervals, as far as I can tell. I assumed I could just write my own panel function to add them, so I searched the archive, and found a posting from the author of the package stating ... placing multiple bars side by side needs specialized calculations, which are done within panel.barchart. To add bars to these, you will need to reproduce those calculations. Just so I'm clear on this -- there's no capacity to add bars to the plot, nor to find out the coordinates of the bars in the graphs themselves. If you want them, you have to completely rewrite panel.barchart. Is this correct? Are there really so few people using error bars with bar charts? -- Chris __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] Adding error bars to a trellis barchart display
Chris Bergstresser wrote: Hi all -- I'm using trellis to generate bar charts, but there's no built-in function to generate error bars or confidence intervals, as far as I can tell. I assumed I could just write my own panel function to add them, so I searched the archive, and found a posting from the author of the package stating ... placing multiple bars side by side needs specialized calculations, which are done within panel.barchart. To add bars to these, you will need to reproduce those calculations. Just so I'm clear on this -- there's no capacity to add bars to the plot, nor to find out the coordinates of the bars in the graphs themselves. If you want them, you have to completely rewrite panel.barchart. Is this correct? Are there really so few people using error bars with bar charts? One of our projects does confidence intervals on bar cahrts produced using teh lattice library. It is quite feasible without too much effort - see: http://members.optusnet.com.au/tchur/NetEpi-Analysis-0-8-Screenshot-5.png Sorry I don't have time to extract the code which does this right now, but you can dissect it out yourself from the NetEpi-Analysis-0.8 tarball at http://sourceforge.net/project/showfiles.php?group_id=123700 - although the R code is embedded in Python classes, which might make extrication a bit more difficult (and which is why I don't have time to do it right now). But from memory the chunk of R code which overrides the default panel function is fairly self-contained and you should be able to identify it fairly easily - just grep the source code for likely strings such as panel.barchart to discover where it is. Other screenshots can be downloaded from http://sourceforge.net/project/showfiles.php?group_id=123700 if anyone is interested. Tim C __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] Adding error bars to a trellis barchart display
On 5/13/06, Chris Bergstresser [EMAIL PROTECTED] wrote: Hi all -- I'm using trellis to generate bar charts, but there's no built-in function to generate error bars or confidence intervals, as far as I can tell. I assumed I could just write my own panel function to add them, so I searched the archive, and found a posting from the author of the package stating ... placing multiple bars side by side needs specialized calculations, which are done within panel.barchart. To add bars to these, you will need to reproduce those calculations. Just so I'm clear on this -- there's no capacity to add bars to the plot, nor to find out the coordinates of the bars in the graphs themselves. If you want them, you have to completely rewrite panel.barchart. Is this correct? Are there really so few people using error bars with bar charts? I would hope so, since bar charts with error bars are horrible things, in my opinion. Lattice comes with an example of (standard) confidence intervals (new in R 2.3.0) that can be accessed by running library(lattice) demo(intervals) The Hmisc package also has high level interfaces that support confidence intervals (I'm not familiar with the details). -Deepayan __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] Bioconductor AND Genetics Library
I am aware of the R Genetics Project that developed the R library and software called Bioconductor (http://www.bioconductor.org/ ) . How do the two relate to each other? What is the one that the other is not and vice versa? Can anybody link me to something that answers the question? -- Farrel Buchinsky, MD Pediatric Otolaryngologist Allegheny General Hospital Pittsburgh, PA __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] bitwise addition
Using the algorithm in the reference www.everything2.com/index.pl?node_id=449702 and the 'bitops' package, here is some code that will select the numeric values with a specified number of bits. It takes less than 12 seconds to select from 21-bit numbers. If I had more memory, I would expect that for 25-bit numbers it would take about 200 seconds to compute the indices. mask1 - 0x mask2 - 0x mask4 - 0x0f0f0f0f mask8 - 0x00ff00ff mask16 - 0x require(bitops) [1] TRUE x - 0:(2^21 - 1) # test all number with 21 bits system.time({ + x - bitAnd(x, mask1) + bitAnd(bitShiftR(x, 1), mask1) + x - bitAnd(x, mask2) + bitAnd(bitShiftR(x, 2), mask2) + x - bitAnd(x, mask4) + bitAnd(bitShiftR(x, 4), mask4) + x - bitAnd(x, mask8) + bitAnd(bitShiftR(x, 8), mask8) + x - bitAnd(x, mask16) + bitAnd(bitShiftR(x, 16), mask16) + }) [1] 10.40 0.87 11.82NANA # print the first 10 numbers which(x == 9)[1:10] - 1 # account for sequence starting at zero [1] 511 767 895 959 991 1007 1015 1019 1021 1022 On 5/13/06, Marc Schwartz [EMAIL PROTECTED] wrote: On Fri, 2006-05-12 at 15:35 -0500, Nameeta Lobo wrote: Hi again Sorry I should have been more specific the first time. I am not actually trying to generate this matrix but what am trying to do is to write a loop which takes an input of , does a bitwise addition, then checks to see if the new number generated has two 1s(I just summed the values to get 2) and if it does outputs that to a matrix. It goes on doing it till it reaches . So my final output for the above would read 0011 0101 0110 1001 1010 1100 For 2^6, I was looking for three 1s and so on. I wrote this in a for loop etc. Created the original matrix with expand.grid command that you guys helped me out with before. My only concern was that for e.g. 2^25 or higher, not much space can be allocated to the creation of the original matrix and then also because of the loops there is the problem of computer time. So was just wondering if it was easier to do it via bitwise addition. thanks a lot for your help everyone. any more suggestion nameeta Nameeta, This approach is still heavily time bound due to the process of comparing the resultant binary representations against the desired number of 1's. It is probably O(n^3) or worse. To improve on this, I suspect you will need to go to a compiled language such as C, where you can engage in more efficient bit level manipulations. Though perhaps somebody else here will have some further thoughts. My premise is that you are not just adding any number to 0, but are going in integer sequence from 0:((2^x) - 1) looking for a fixed number of 1's. Here is the code. It requires the use of Martin's digitsBase() function from package sfsmisc to create the binary representations of the integers. FindOnes - function(exp, ones) { checkDigits - function(x) { n - digitsBase(x, ndigits = exp) if (sum(n) == ones) paste(n, collapse = ) } L - sapply(1:((2^exp) - 1), checkDigits) do.call(rbind, L) } To use it: exp: The exponent desired, as in (2 ^ exp) ones: The number of 1's desired in the binary representation So for example: # Use 2^4 and get results with 2 1's # Took 0.004 seconds FindOnes(4, 2) [,1] [1,] 0011 [2,] 0101 [3,] 0110 [4,] 1001 [5,] 1010 [6,] 1100 # 2^6 with 3 1's # Took 0.02 seconds FindOnes(6, 3) [,1] [1,] 000111 [2,] 001011 [3,] 001101 [4,] 001110 [5,] 010011 [6,] 010101 [7,] 010110 [8,] 011001 [9,] 011010 [10,] 011100 [11,] 100011 [12,] 100101 [13,] 100110 [14,] 101001 [15,] 101010 [16,] 101100 [17,] 110001 [18,] 110010 [19,] 110100 [20,] 111000 Testing with 2^18 looking for 9 1's: system.time(x - FindOnes(18, 9)) [1] 76.089 0.664 86.535 0.000 0.000 str(x) chr [1:48620, 1] 01 10 ... object.size(x) [1] 2722840 I am curious as to your application here. HTH, Marc Schwartz __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html -- Jim Holtman Cincinnati, OH +1 513 646 9390 (Cell) +1 513 247 0281 (Home) What is the problem you are trying to solve? [[alternative HTML version deleted]] __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] .Rprofile file and .First function
On May 13, 2006, at 9:22 AM, MARK LEEDS wrote: thanks robert. You're welcome, Mark. if tyou don't ind me asking, what do those statements quit, exit and q do in the .Rprofile function ? Thanks. I tend to work in a lot of different environments, each with their own way of exiting. If I type any of those three variables, they remind me of the correct way to exit the R environment. Regards, - Robert http://www.cwelug.org/downloads Help others get OpenSource software. Distribute FLOSS for Windows, Linux, *BSD, and MacOS X with BitTorrent __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html