[R] Clustering for variable reduction
Hi, I have a regression model, where the explanatory variables are factors, and I want to include interaction terms, but some combinations occur in the data very infrequently. Hence, I'm using hclust and cutree to hierarchically cluster the levels, and get new combined levels to regress on. Ideally, I would like to be able to cut the tree to achieve clusters with at least k observations each. That is, cut the tree at an appropriate height for each branch (combine nodes only when they have fewer than k obs). AFAIK, cutree cuts at a uniform height and there's no easy way of extracting the number of observations per cluster from hclust (except by assigning the new levels to the data and then counting the occurrences). Does anyone know of code that does this already? Thanks, Gad -- Gad Abraham Dept. CSSE and NICTA The University of Melbourne Parkville 3010, Victoria, Australia email: [EMAIL PROTECTED] web: http://www.csse.unimelb.edu.au/~gabraham __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] summary(object, test=c(Roy, Wilks, Pillai, ....) AND ellipse(object, center=....)
Why do you keep posting something to which you have already received an answer? https://stat.ethz.ch/pipermail/r-help/2008-April/158662.html answered in https://stat.ethz.ch/pipermail/r-help/2008-April/158664.html and repeated at https://stat.ethz.ch/pipermail/r-help/2008-April/158787.html and https://stat.ethz.ch/pipermail/r-help/2008-April/158796.html (this message). All of these are with unwrapped lines (I wrapped the version below) and contain HTML which the posting guide asked you not to send. On Sat, 5 Apr 2008, Ray Haraf wrote: Dear All, I would be very appreciative of your help with the following But you then showed 0% appreciation of the help you were given! 1). I am running multivariate multiple regression through the manova() function (kindly suggested by Professor Venables) and getting two different answers for test=c(Wilks,Roy,Pillai) and tests=c(Wilks,Roy,'Pillai) as shown below. In the first case (test=c(list)) I got error message which probably means I can only call one test at a time. I thought I could get ride of this by adding s to test; in this case (tests=c(list)), I got Pillai test. Does this mean that Pillai would be the default test and summary(manova()) can only post one test at a time? summary(manova(cbind(y1, y2) ~ z1, data = + ex7.8),test=c(Wilks,Roy,Pillai)) Error in match.arg(test) : 'arg' must be of length 1 summary(manova(cbind(y1, y2) ~ z1, data = + ex7.8),tests=c(Wilks,Roy,Pillai)) Df Pillai approx F num Df den Df Pr(F) z1 1 0.9375 15. 2 2 0.0625 . Residuals 3 --- Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 2). My next struggle is to construct prediction ellipse. Both ellipse() and ellipse.lm() are not giving me the solution to Sampling from multivariate multiple regression prediction regions posted by Iain Pardoe, Mon May 9 18:43:46 2005. I am working on the same problem and performed all the steps he suggested ex7.10 - + data.frame(y1 = c(141.5, 168.9, 154.8, 146.5, 172.8, 160.1, 108.5), + y2 = c(301.8, 396.1, 328.2, 307.4, 362.4, 369.5, 229.1), + z1 = c(123.5, 146.1, 133.9, 128.5, 151.5, 136.2, 92), + z2 = c(2.108, 9.213, 1.905, .815, 1.061, 8.603, 1.125)) attach(ex7.10) f.mlm - lm(cbind(y1,y2)~z1+z2) y.hat - c(1, 130, 7.5) %*% coef(f.mlm) round(y.hat, 2) y1 y2 [1,] 151.84 349.63 qf.z - t(c(1, 130, 7.5)) %*% + solve(t(cbind(1,z1,z2)) %*% cbind(1,z1,z2)) %*% + c(1, 130, 7.5) round(qf.z, 5) [,1] [1,] 0.36995 n.sigma.hat - SSD(f.mlm)$SSD # same as t(resid(f.mlm)) %*%resid(f.mlm) round(n.sigma.hat, 2) y1 y2 y1 5.80 5.22 y2 5.22 12.57 F.quant - qf(.95,2,3) round(F.quant, 2) [1] 9.55 From here how could I calculate a 95% prediction ellipse for y=(y1,y2) at (z1,z2)=(130,7.5) using either ellipse or ellipse.lm? y1 would be the x-axis and y2, the y-axis. The center is different from (0,0) and I don't know what would be the appropriate x (the lm object). Should I used predicted values or residuals? In both cases I have vectors which is different from the example given with ellipse.lm 3). Lastly but not the least, would be too ambitious to draw the axes (i.e, the eigenvalues) to the ellipse? Thanks and very kind regards, Ray [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Brian D. Ripley, [EMAIL PROTECTED] 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] lme cant get parameter estimated correctly
Here is a demo you may like to consider. (I can see what you are trying to do with your loops, but I prefer to do it this way.) On 32 bit Windows, (which I am forced to use), your seed is not a valid integer, so I have changed it to something which is. set.seed(7658943) fph - 0.4 Sigh - sqrt(0.0002) Sigi - sqrt(0.04) reH - rnorm(90, fph, Sigh) ## hospid effects dta - within(expand.grid(hospid = 1:90, empid = 1:80), fpi1 - reH[hospid] + rnorm(7200, fph, Sigi)) require(nlme) Modl - lme(fpi1 ~ 1, data = dta, random = ~1|hospid) summary(Modl) Linear mixed-effects model fit by REML . Random effects: Formula: ~1 | hospid (Intercept) Residual StdDev: 0.01593939 0.2003148 . Compare this with what you started with, viz: c(Sigh, Sigi) [1] 0.01414214 0.2000 and it doesn't look too bad to me. You might like to see how well the effects themselves agree: plot(ranef(Modl)[[1]], reH-fph) abline(0,1) cor(ranef(Modl)[[1]], reH) [1] 0.6317546 Again, about what I would expect. Note that the summary to lme objects gives standard deviations, not variance components. If you want to see variance components, there is a function in the 'ape' package which does it: require(ape) varcomp(Modl) hospid Within 0.0002540641 0.0401260303 Look familiar? Bill Venables CSIRO Laboratories PO Box 120, Cleveland, 4163 AUSTRALIA Office Phone (email preferred): +61 7 3826 7251 Fax (if absolutely necessary): +61 7 3826 7304 Mobile: +61 4 8819 4402 Home Phone: +61 7 3286 7700 mailto:[EMAIL PROTECTED] http://www.cmis.csiro.au/bill.venables/ -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of toby909 Sent: Sunday, 6 April 2008 3:27 PM To: [EMAIL PROTECTED] Subject: [R] lme cant get parameter estimated correctly I am caught in a mental trap. Why isn't the between groups variance estimated (0.0038) to be around the value with which I generated the data (0.0002)? Thanks Toby set.seed(76589437887) fph = 0.4 Sigh = sqrt(0.0002) Sigi = sqrt(0.04) ci = 1 fpi = matrix(,7200,3) for (i in 1:90) { fph = rnorm(1, fph, Sigh) for (k in 1:80) { fpi[ci,1:3] = matrix(c(i, k, rnorm(1, fph, Sigi)),1) ci = ci+1 } } colnames(fpi) = c(hospid, empid, fpi1) dta = as.data.frame(fpi) lme = lme(fpi1 ~ 1, dta, ~1|hospid) summary(lme) lme = lme(fpi1 ~ 1, dta, ~1|hospid) summary(lme) Linear mixed-effects model fit by REML Data: dta AIC BIC logLik -2555.416 -2534.771 1280.708 Random effects: Formula: ~1 | hospid (Intercept) Residual StdDev: 0.06173257 0.1997302 Fixed effects: fpi1 ~ 1 Value Std.Error DF t-value p-value (Intercept) 0.368082 0.006919828 7110 53.19236 0 Standardized Within-Group Residuals: Min Q1Med Q3Max -3.4870696 -0.6747173 -0.0048658 0.6838012 4.2633384 Number of Observations: 7200 Number of Groups: 90 0.0617^2 [1] 0.00380689 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] What to use for assignment, = or - ?
I've noticed an increasing tendency for people to use '=' rather than the older '-' symbol. When '=' became available as an assignment operator in S-PLUS in the late '90s my first reaction was to switch to it as well. Brian Ripley warned me that it was not a good idea. As usual he was right, but it took a couple of pretty serious finger-burning episodes before I came fully around to his view. There are three left assignment operators in S, and it's a good idea to distinguish what they do. a - b assigns a value 'b' to an object 'a' in some parent environment a - b assigns a value 'b' to an object 'a' in the current environment a = b (inside the argument list of a function call) potentially assigns a value 'b' to an object 'a' in the child environment of the function. Lazy evaluation determines if it actually happens or not. You must use '=' for the third of these. If you choose to use it for the second as well, as is allowed, there is a danger that you will confuse the environment in which the assignment is actually made. It's not a great danger, of course, but it can happen. In any case, it is a good idea to use three separate operators for these three distinct purposes, if nothing else as a clear visual reminder of what kind of assignment is intended to take place. I suspect the push towards using '=' instead of '-' has two main drivers: 1. the world is full of lazy typists 2. right now there seems to be a big influx of Matlab people into R, and it makes them feel more at home. Neither of these is much of a reason, I reckon. Bill Venables CSIRO Laboratories PO Box 120, Cleveland, 4163 AUSTRALIA Office Phone (email preferred): +61 7 3826 7251 Fax (if absolutely necessary): +61 7 3826 7304 Mobile: +61 4 8819 4402 Home Phone: +61 7 3286 7700 mailto:[EMAIL PROTECTED] http://www.cmis.csiro.au/bill.venables/ __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] [R-SIG-Mac] sizing of quartz
Oops! Sorry! Accept my apologies. I've sent this message to the wrong list. Best regards, Ricardo [Ricardo Rodriguez] Your XEN ICT Team wrote: Those are good news. Prof Brian Ripley wrote: You didn't tell us the version of R. quartz() is different in 2.7.0 alpha, and there the function arguments do work (and the size is really as advertised and not at a notional 72dpi). In fact, it is a much more standard device and interface, so less to learn. I assumed that version provides most of the information required. Please, what information is lacking in my first post? I've looked at installed.packages() and it seems to me that quartz() is bundled with the main software more than installed with a given package. Is it possible to pass height and width in pixels more than in inches working with 2.7.0 alfa? As I read in http://developer.R-project.org/, R-alpha*.tar.gz packages are made automatically available, but I guess there is not *.dmg for these stages. Thanks for your help, Ricardo -- Ricardo Rodríguez Your XEN ICT Team __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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 improve the OPTIM results
Dear Spencer Graves, Thank you for your comments and suggestions. I knew that the true optimum values are about (0.69, 0.0, 0.0, -0.3, 0.3, 2.3, -3.0 ,-3.0). That's why I used these values as starting values. Nonetheless, the last three estimates are so bad. Regards, Kathryn Lord Spencer Graves wrote: Dear Katheryn: I'm confused by your claim that, Even though I used the true parameter values as initial values, the results are not very good. When I ran it, 'optim' quit with $value = -35835, substantially less than fr2(theta0) = -0.3. Could you please review your question, because I believe this will answer it. MORE GENERAL OPTIM ISSUES It is known that 'optim' has problems. Perhaps the simplest thing to do is to call 'optim' with each of the 'methods' in sequence, using the 'optim' found by each 'method' as the starting value for the next. When I do this, I often skip 'SANN', because it typically takes so much more time than the other methods. However, if there might be multiple local minima, then SANN may be the best way to find a global minimum, though you may want to call 'optim' again with another method, starting from optimal solution returned by 'SANN'. Another relatively simple thing to do is to call optim with hessian = TRUE and then compute eigen(optim(..., hessian=TRUE)$hessian, symmetric=TRUE). If optim found an honest local minimum, all the eigenvalues will be positive. For your example, the eigenvalues were as follows: 19000, 11000, 0.06, 0.008, 0.003, -0.0002, -0.06, -6000 This says that locally, the minimum identified was really a saddle point, being a parabola opening up in two dimensions (with curvatures of 19000 and 11000 respectively), a parabola opening down in one dimension (with curvature -6000), and relatively flat by comparison in the other 5 dimensions. In cases like this, it should be moderately easy and fast to explore the dimension with the largest negative eigenvalue with the other dimensions fixed until local minima in each direction were found. Then 'optim' could be restarted from both those local minima, and the minimum of those two solutions could be returned. If all eigenvalues were positive, it might then be wise to restart with parscale = the square roots of the diagonal of the hessian; I haven't tried this, but I believe it should work. Using 'parscale' can fix convergence problems -- or create some where they did not exist initially. I'm considering creating a package 'optimMLE' that would automate some of this and package it with common 'methods' that would assume that sum(fn(...)) was either a log(likelihood) or the negative of a log(likelihood), etc. However, before I do, I need to make more progress on some of my other commitments, review RSiteSearch(optim, fun) to make sure I'm not duplicating something that already exists, etc. If anyone is interested in collaborating on this, please contact me off-line. Hope this helps. Spencer kathie wrote: Dear R users, I used to OPTIM to minimize the obj. function below. Even though I used the true parameter values as initial values, the results are not very good. How could I improve my results? Any suggestion will be greatly appreciated. Regards, Kathryn Lord #-- x = c(0.35938587, 0.34889725, 0.20577608, 0.1529, -4.24741146, -1.32943326, 0.29082527, -2.38156942, -6.62584473, -0.22596237, 6.97893687, 0.22001081, -1.39729222, -5.17860124, 0.52456484, 0.46791660, 0.03065136, 0.32155177, -1.12530013, 0.02608057, -0.22323154, 3.30955460, 0.54653982, 0.29403011, 0.47769874, 2.42216260, 3.93518355, 0.23237890, 0.09647044, -0.48768933, 0.37736377, 0.43739341, -0.02416010, 4.02788119, 0.07320802, -0.29393054, 0.25184609, 0.7608, -3.34121918, 1.16028677, -0.60352008, -2.86454069, -0.84411691, 0.24841071, -0.11764954, 5.92662106, 1.03932953, -6.21987657, -0.54763352, 0.20263192) # data theta0= c(log(2),0,c(0,-.3,.3),log(c(10,.05,.05))) # initial value(In fact, true parameter value) n = length(x) fr2 = function(theta) { a1 = theta[1]; a2 = theta[2] mu1 = theta[3]; mu2 = theta[4]; mu3 = theta[5] g1 = theta[6]; g2 = theta[7]; g3 = theta[8] w1=exp(a1)/(1+exp(a1)+exp(a2)) w2=exp(a2)/(1+exp(a1)+exp(a2)) w3=1-w1-w2 obj =((w1^2)/(2*sqrt(exp(g1)*pi)) + (w2^2)/(2*sqrt(exp(g2)*pi)) + (w3^2)/(2*sqrt(exp(g2)*pi)) + 2*w1*w2*dnorm((mu1-mu2)/sqrt(exp(g1)+exp(g2)))/sqrt(exp(g1)+exp(g2)) + 2*w1*w3*dnorm((mu1-mu3)/sqrt(exp(g1)+exp(g3)))/sqrt(exp(g1)+exp(g3)) +
Re: [R] [R-SIG-Mac] sizing of quartz
Those are good news. Prof Brian Ripley wrote: You didn't tell us the version of R. quartz() is different in 2.7.0 alpha, and there the function arguments do work (and the size is really as advertised and not at a notional 72dpi). In fact, it is a much more standard device and interface, so less to learn. I assumed that version provides most of the information required. Please, what information is lacking in my first post? I've looked at installed.packages() and it seems to me that quartz() is bundled with the main software more than installed with a given package. Is it possible to pass height and width in pixels more than in inches working with 2.7.0 alfa? As I read in http://developer.R-project.org/, R-alpha*.tar.gz packages are made automatically available, but I guess there is not *.dmg for these stages. Thanks for your help, Ricardo -- Ricardo Rodríguez Your XEN ICT Team __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] how to manupute data frame with conditions fill cell with previous value if next cell is zero
Dear R Experts, This is the 2nd time in the chat room. Its a great place to get help from R experts. I have a data frame problem, it contains thousands of data. part of it, I am giving for explaining the problem date day x yz 82 1989-04-28 Fri 2118.0 2418.80 33713 83 1989-05-01 Mon0.0 2414.96 33793 84 1989-05-02 Tue 2103.12402.86 33955 85 1989-05-03 Wed 2105.7 2393.70 0 86 1989-05-04 Thu 2119.0 2384.90 0 87 1989-05-05 Fri2132.8 2381.96 0 103 1989-05-29 Mon0.00.00 34161 127 1989-06-30 Fri 2151.0 2440.06 32949 128 1989-07-03 Mon 2165.6 2452.77 33236 129 1989-07-04 Tue 2174.40 35376 130 1989-07-05 Wed 2162.9 2456.56 33310 167 1989-08-25 Fri 2397.4 2732.36 34740 168 1989-08-28 Mon0.02743.36 34607 169 1989-08-29 Tue 2380.8 2726.63 34688 170 1989-08-30 Wed 2381.3 2728.15 34472 171 1989-08-31 Thu 2387.9 2737.27 34431 172 1989-09-01 Fri 2407.5 2752.09 34348 173 1989-09-04 Mon 2419.20.00 34484 174 1989-09-05 Tue 2426.0 2744.68 34442 175 1989-09-06 Wed 2390.8 2719.79 34271 176 1989-09-07 Thu 2415.9 2706.88 34153 177 1989-09-08 Fri 2423.9 2709.54 34116 178 1989-09-11 Mon 2400.6 2704.41 34114 179 1989-09-12 Tue 2397.6 2707.26 34333 180 1989-09-13 Wed 2401.5 2679.52 34287 181 1989-09-14 Thu 2382.0 2664.89 34402 182 1989-09-15 Fri 2366.5 2674.58 0 183 1989-09-18 Mon 2373.8 2687.50 34473 195 1989-10-04 Wed 2312.1 2771.09 35383 196 1989-10-05 Thu 2281.6 2773.56 35523 197 1989-10-06 Fri 2277.5 2785.52 35209 198 1989-10-09 Mon 2247.0 2791.41 35376 199 1989-10-10 Tue 2218.8 2785.33 0 200 1989-10-11 Wed 2218.8 2773.36 35240 In this data frame, I need to replace cells which is zero with previous value. For example 82 1989-04-28 Fri 2118.0 2418.80 33713 83 1989-05-01 Mon0.0 2414.96 33793 in 2nd line 0.0 should be replaced by 2118.0 Another Example 84 1989-05-02 Tue 2103.1 2402.86 33955 85 1989-05-03 Wed 2105.7 2393.70 0 86 1989-05-04 Thu 2119.0 2384.90 0 87 1989-05-05 Fri 2132.8 2381.96 0 3 lines filled by 33955 value. Another example 198 1989-10-09 Mon 2247.0 2791.41 35376 199 1989-10-10 Tue 2218.8 2785.33 0 200 1989-10-11 Wed 2218.8 2773.36 35240 in 2nd line filled by zero should be replaced by value 35376 Please help me. Thanking you saikat -- View this message in context: http://www.nabble.com/how-to-manupute-data-frame-with-conditions-fill-cell-with-previous-value-if-next-cell-is-zero-tp16524107p16524107.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] how to manupute data frame with conditions fill cell with previous value if next cell is zero
Hi, It's more a vector question. Try this one: f function( x, test = is.na(x) | x == 0 ){ out - x[!test][ cumsum(!test) ] if(test[1]) out - c(NA,out) out } f( c(1,0,2,1,0) ) [1] 1 1 2 1 1 f( c(1,0,2,1,0, NA) ) # missing values are also replaced [1] 1 1 2 1 1 1 f( c(0,1,0,2,1,0) ) # if first is to be replaced, it is set to NA [1] NA 1 1 2 1 1 Cheers, Romain -Original Message- From: [EMAIL PROTECTED] on behalf of saikat sarkar Sent: Sun 06/04/2008 14:04 To: r-help@r-project.org Subject: [R] how to manupute data frame with conditions fill cell with previous value if next cell is zero Dear R Experts, This is the 2nd time in the chat room. Its a great place to get help from R experts. I have a data frame problem, it contains thousands of data. part of it, I am giving for explaining the problem date day x yz 82 1989-04-28 Fri 2118.0 2418.80 33713 83 1989-05-01 Mon0.0 2414.96 33793 84 1989-05-02 Tue 2103.12402.86 33955 85 1989-05-03 Wed 2105.7 2393.70 0 86 1989-05-04 Thu 2119.0 2384.90 0 87 1989-05-05 Fri2132.8 2381.96 0 103 1989-05-29 Mon0.00.00 34161 127 1989-06-30 Fri 2151.0 2440.06 32949 128 1989-07-03 Mon 2165.6 2452.77 33236 129 1989-07-04 Tue 2174.40 35376 130 1989-07-05 Wed 2162.9 2456.56 33310 167 1989-08-25 Fri 2397.4 2732.36 34740 168 1989-08-28 Mon0.02743.36 34607 169 1989-08-29 Tue 2380.8 2726.63 34688 170 1989-08-30 Wed 2381.3 2728.15 34472 171 1989-08-31 Thu 2387.9 2737.27 34431 172 1989-09-01 Fri 2407.5 2752.09 34348 173 1989-09-04 Mon 2419.20.00 34484 174 1989-09-05 Tue 2426.0 2744.68 34442 175 1989-09-06 Wed 2390.8 2719.79 34271 176 1989-09-07 Thu 2415.9 2706.88 34153 177 1989-09-08 Fri 2423.9 2709.54 34116 178 1989-09-11 Mon 2400.6 2704.41 34114 179 1989-09-12 Tue 2397.6 2707.26 34333 180 1989-09-13 Wed 2401.5 2679.52 34287 181 1989-09-14 Thu 2382.0 2664.89 34402 182 1989-09-15 Fri 2366.5 2674.58 0 183 1989-09-18 Mon 2373.8 2687.50 34473 195 1989-10-04 Wed 2312.1 2771.09 35383 196 1989-10-05 Thu 2281.6 2773.56 35523 197 1989-10-06 Fri 2277.5 2785.52 35209 198 1989-10-09 Mon 2247.0 2791.41 35376 199 1989-10-10 Tue 2218.8 2785.33 0 200 1989-10-11 Wed 2218.8 2773.36 35240 In this data frame, I need to replace cells which is zero with previous value. For example 82 1989-04-28 Fri 2118.0 2418.80 33713 83 1989-05-01 Mon0.0 2414.96 33793 in 2nd line 0.0 should be replaced by 2118.0 Another Example 84 1989-05-02 Tue 2103.1 2402.86 33955 85 1989-05-03 Wed 2105.7 2393.70 0 86 1989-05-04 Thu 2119.0 2384.90 0 87 1989-05-05 Fri 2132.8 2381.96 0 3 lines filled by 33955 value. Another example 198 1989-10-09 Mon 2247.0 2791.41 35376 199 1989-10-10 Tue 2218.8 2785.33 0 200 1989-10-11 Wed 2218.8 2773.36 35240 in 2nd line filled by zero should be replaced by value 35376 Please help me. Thanking you saikat -- View this message in context: http://www.nabble.com/how-to-manupute-data-frame-with-conditions-fill-cell-with-previous-value-if-next-cell-is-zero-tp16524107p16524107.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] How to improve the OPTIM results
MORE GENERAL OPTIM ISSUES I'm considering creating a package 'optimMLE' that would automate some of this and package it with common 'methods' that would assume that sum(fn(...)) was either a log(likelihood) or the negative of a log(likelihood), etc. However, before I do, I need to make more progress on some of my other commitments, review RSiteSearch(optim, fun) to make sure I'm not duplicating something that already exists, etc. If anyone is interested in collaborating on this, please contact me off-line. Hope this helps. Spencer Thanks for your tips on using `optim()'. I believe `optim' is a reasonable good implementation of numerical optimization techniques such as quasi-Newton BFGS or conjugate gradients. Maybe methods using modern line searches or trust regions can follow someday. Everybody applying `optim' should be aware that it is a *Local Optimization* (LO) approach. What you describe appears to be a step towards *Global Optimization* (GO) in R. And indeed more and more requests in to the R-help list are about `optim' as a tool for global optimization, not always being fully aware of the differences. I am wondering whether it would be more useful to provide one or two global optimization approaches to the R community. And as this is an active research area, there are many and with different advantages and drawbacks. I would like to propose IPOPT as one of he newer and more advanced methods for global optimization. This powerful software package is open source and available through the COIN-OR initiative and its Web pages: http://www.coin-or.org/Ipopt/documentation/ ``Ipopt (Interior Point OPTimizer, pronounced I-P-Opt) is a software package for large-scale nonlinear optimization. Ipopt is written in C++ and is released as open source code under the Common Public License (CPL). It is available from the COIN-OR initiative. The code has been written by Carl Laird (Carnegie Mellon University) and Andreas Wachter (IBM's T.J. Watson Research Center), who is the COIN project leader for Ipopt.'' PERHAPS the COIN project would agree for IPOPT to be integrated into the open source project R as a package. For testing it right now there is an AMPL-based interface to IPOPT at the NEOS solver: http://neos.mcs.anl.gov/neos/solvers/nco:Ipopt/AMPL.html There may be other rewarding projects in the COIN-OR initiative, such as `SYMPHONY' for solving mixed-integer linear programs (MILP, stronger than `glpk' and `lp-solve'), or the BONMIN open source *non-linear* mixed integer programming (MINLP) solver. I could imagine R to be a good platform for integrating some of these algorithms. Hans W. Borchers Control and Optimization Group ABB Corporate Research Germany [EMAIL PROTECTED] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] What to use for assignment, = or - ?
Bill.Venables at csiro.au writes: I've noticed an increasing tendency for people to use '=' rather than the older '-' symbol. When '=' became available as an assignment operator in S-PLUS in the late '90s my first reaction was to switch to it as well. Brian Ripley warned me that it was not a good idea. As usual he was right, but it took a couple of pretty serious finger-burning episodes before I came fully around to his view. [snip] I suspect the push towards using '=' instead of '-' has two main drivers: 1. the world is full of lazy typists 2. right now there seems to be a big influx of Matlab people into R, and it makes them feel more at home. Neither of these is much of a reason, I reckon. It may not be a good reason, but the reason I usually teach = rather than - to my students is that they are usually learning scripting/programming for the very first time, and the = syntax for assignment (which as I recall was called gozzinta, for goes into, in the FORTRAN coloring book) seems natural to most people (even though it's logically quite different). They are so overwhelmed by learning new things that I don't want to add one more. (This is admittedly a judgment call.) Ben Bolker __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] How to improve the OPTIM results
try to use method L-BFGS-B and give boudary condition to the parameters in use so that the algorithm search is limited to a particular region as it seems u have to many parameters. On Fri, 4 Apr 2008 22:10:20 -0700 (PDT) kathie wrote: Dear R users, I used to OPTIM to minimize the obj. function below. Even though I used the true parameter values as initial values, the results are not very good. How could I improve my results? Any suggestion will be greatly appreciated. Regards, Kathryn Lord #--- --- x = c(0.35938587, 0.34889725, 0.20577608, 0.1529, -4.24741146, -1.32943326, 0.29082527, -2.38156942, -6.62584473, -0.22596237, 6.97893687, ! ; 0.22001081, -1.39729222, -5.17860124, 0.52456484, 0.46791660, 0.03065136, 0.32155177, -1.12530013, 0.02608057, -0.22323154, 3.30955460, 0.54653982, 0.29403011, 0.47769874, 2.42216260, 3.93518355, 0.23237890, 0.09647044, -0.48768933, 0.37736377, 0.43739341, -0.02416010, 4.02788119, 0.07320802, -0.29393054, 0.25184609, 0.7608, -3.34121918, 1.16028677, -0.60352008, -2.86454069, -0.84411691, 0.24841071, -0.11764954, 5.92662106, 1.03932953, -6.21987657, -0.54763352, 0.20263192) # data theta0= c(log(2),0,c(0,-.3,.3),log(c(10,.05,.05))) # initial value(In fact, true parameter value) n = length(x) fr2 = function(theta) { a1 = theta[1]; a2 = theta[2] mu1 = theta[3]; mu2 = theta[4]; mu3 = theta[5] g1 = theta[6]; g2 = theta[7]; g3! = theta[8] w1=exp(a1)/(1+exp(a1)+exp(a2)) w2=exp(a2)/(1+exp(a1)+exp(a2)) w3=1-w1-w2 obj =((w1^2)/(2*sqrt(exp(g1)*pi)) + (w2^2)/(2*sqrt(exp(g2)*pi)) + (w3^2)/(2*sqrt(exp(g2)*pi)) + 2*w1*w2*dnorm((mu1-mu2)/sqrt(exp(g1)+exp(g2)))/sqrt(exp(g1)+exp(g2)) + 2*w1*w3*dnorm((mu1-mu3)/sqrt(exp(g1)+exp(g3)))/sqrt(exp(g1)+exp(g3)) + 2*w2*w3*dnorm((mu2-mu3)/sqrt(exp(g2)+exp(g3)))/sqrt(exp(g2)+exp(g3)) - (2/n)*(sum(w1*dnorm((x-mu1)/sqrt(exp(g1)))/sqrt(exp(g1)) + w2*dnorm((x-mu2)/sqrt(exp(g2)))/sqrt(exp(g2)) + w3*dnorm((x-mu3)/sqrt(exp(g3)))/sqrt(exp(g3)) ))) return(obj) } optim(theta0, fr2, method=BFGS, control = list (fnscale=10, parscale=c(.01,.01,.01,.01,.01,1,1,1), maxit=10)) -- View this message in context: http://www.nabble.com/How-to-impr! ove-the-%22OPTIM%22-results-tp16509144p16509144.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] [OT] Typesetting / highlighting R code in Latex
Using Latex and the beamer class, I would like to highlight code snippets. Does anybody know a suitable 'preprocessor' or 'filter' for R (and/or C/C++) code ? I have been including it in simple \begin{verbatim} ... \end{verbatim} and I know there is a better way -- in fact I saw it used a while back in some package I looked at. And I didn't write that down... What I am looking for is the basic equivalent of 'everything in verbatim' plus the ability to hightlight certain parts to stress the points I'd like to make. There must be something. Pointers would be greatly appreciated! Thanks, Dirk -- Three out of two people have difficulties with fractions. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Strange message when plot function used..
Hi! I am an R beginer, so perhaps this is a quite simple question... After using the lmer command (under the lme4 package) for fitting a mixed model, it was impossible to use de command plot(model) for checking model adequacy. R returns this message: Error in as.double(y) : cannot type '%s' coerce to vector. Could anyone be so kind to tell me what to do? How can I continue to use lme library instead of lmer? R does not recognize lme anymore. Thanks in advance! _ Confira vídeos com notícias do NY Times, gols direto do Lance, videocas[[elided Hotmail spam]] [[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] Mac install
Need idiot's guide to installing R on Mac 10.3.9. Thanks. BJ __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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 manupute data frame with conditions fill cell with previous value if next cell is zero
On Sun, Apr 6, 2008 at 9:04 AM, saikat sarkar [EMAIL PROTECTED] wrote: This is the 2nd time in the chat room. Its a great place to get help from R experts. I assume you are referring to this email list. I am not aware of a chat room but if it exists that is something different from this list. I have a data frame problem, it contains thousands of data. Actually you don't have a data frame problem. You have a time series problem and by representing it as a data frame instead of a time series you are running into one problem after another that would be trivially addressed with the correct representation. See ?na.locf in the zoo package. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Strange message when plot function used..
Cristian Carranza wrote: Hi! I am an R beginer, so perhaps this is a quite simple question... After using the lmer command (under the lme4 package) for fitting a mixed model, it was impossible to use de command plot(model) for checking model adequacy. R returns this message: Error in as.double(y) : cannot type '%s' coerce to vector. Because lme4 does not ship a plot method for th lmer class and plot.default cannot handle the object ... Could anyone be so kind to tell me what to do? Think about how your plot should look like and implement it yourself. How can I continue to use lme library instead of lmer? R does not recognize lme anymore. Thanks in advance! What is lme library? If you mean the function lme() from package nlme, you have to load nlme rather than lme4. Uwe Ligges _ Confira vídeos com notícias do NY Times, gols direto do Lance, videocas[[elided Hotmail spam]] [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] row by row similarity
Hello all and thanks in advance for any advice. I am very new to R and have searched my question but have not come up with anything quite like what I would like to do. My problem is: I have a data set for individuals (rows) and values for behaviours (columns). I would like to know the proportion of shared behaviours for all possible pairs of individuals. The sum of shared behaviours divided by the total. There are zeros in the data that I would like treated as the behaviour does not exist. example data format: indB1 B2 B3 B4 B5 B6 w 215344 x 123456 y 135276 z 232426 Desired output: w x 0 w y 0.17 w z 0 x y 0.3 x z 0.3 etc. Thanks Grant [[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] dots and substitute
Hi, is there an elegant way to use 'substitute' with '...' arguments? My first try was this: f1 - function(...) substitute(...) f1( 2+7, foo, 3+5 ) 2 + 7 As you can see, substitute acts only on the first argument. So I tried f2 - function(...) substitute(list(...)) f2( 2+7, foo, 3+5 ) list(2 + 7, foo, 3 + 5) This is now all the information I want, but it is not split into the individual arguments. I would like to get a character vector, i.e. something like c( 2 + 7, \foo\, 3 + 5 ) My third try seems to be wrong as well: f3 - function(...) lapply( list(...), substitute ) f3( 2+7, foo, 3+5 ) Error in lapply(list(...), substitute) : '...' used in an incorrect context Does anybody has a good hint for me as how to do it correctly? Thanks Simon +--- | Dr. Simon Anders, Dipl. Phys. | European Bioinformatics Institute, Hinxton, Cambridgeshire, UK | preferred (permanent) e-mail: [EMAIL PROTECTED] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] lme cant get parameter estimated correctly
Bill.Venables at csiro.au writes: Here is a demo you may like to consider. (I can see what you are trying to do with your loops, but I prefer to do it this way.) This is just for pedagogical purpose, so I like to keep the simple-minded 'for' loop. But what I really wonder is why do I not get the right estimate? It cant be because of how I loop-create the data? Thanks Toby On 32 bit Windows, (which I am forced to use), your seed is not a valid integer, so I have changed it to something which is. set.seed(7658943) __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] [OT] Typesetting / highlighting R code in Latex
On 6 April 2008 at 10:40, Dirk Eddelbuettel wrote: | Using Latex and the beamer class, I would like to highlight code snippets. | Does anybody know a suitable 'preprocessor' or 'filter' for R (and/or C/C++) | code ? | | I have been including it in simple \begin{verbatim} ... \end{verbatim} and I | know there is a better way -- in fact I saw it used a while back in some | package I looked at. And I didn't write that down... | | What I am looking for is the basic equivalent of 'everything in verbatim' | plus the ability to hightlight certain parts to stress the points I'd like to | make. | | There must be something. Pointers would be greatly appreciated! The listing class was what I was looking for -- thanks for the quick off-list reply. Basic synopis of listing is eg here http://en.wikibooks.org/wiki/LaTeX/Packages/Listings Dirk -- Three out of two people have difficulties with fractions. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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 code for eta
I would greatly appreciate if anybody can tell me if an R code is available for computing the eta measure of association in contingency tables. With regards - [[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] Hex Decimal Convert
Hello, I have a data with hexdecimal. But GNU R convert it to strange number. How can I get that hexdecimal showing in the R-table? --- -- My Data-Table: Sender_ID Receiver_ID Other_ID 6565 0x47780439 0x 0x 0 --- R-Table: 6565 1199047737 0 0 0 Kind Regards, Edwin __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] What to use for assignment, = or - ?
On Apr 6, 2008, at 10:35 AM, Ben Bolker wrote: Bill.Venables at csiro.au writes: I've noticed an increasing tendency for people to use '=' rather than the older '-' symbol. When '=' became available as an assignment operator in S-PLUS in the late '90s my first reaction was to switch to it as well. Brian Ripley warned me that it was not a good idea. As usual he was right, but it took a couple of pretty serious finger-burning episodes before I came fully around to his view. [snip] I suspect the push towards using '=' instead of '-' has two main drivers: 1. the world is full of lazy typists 2. right now there seems to be a big influx of Matlab people into R, and it makes them feel more at home. Neither of these is much of a reason, I reckon. It may not be a good reason, but the reason I usually teach = rather than - to my students is that they are usually learning scripting/programming for the very first time, and the = syntax for assignment (which as I recall was called gozzinta, for goes into, in the FORTRAN coloring book) seems natural to most people (even though it's logically quite different). They are so overwhelmed by learning new things that I don't want to add one more. (This is admittedly a judgment call.) I actually teach my students to use -, for a number of reasons, but in some sense for the same reason you choose to teach = instead: I feel that - expresses better the act of assigning. The problem really is that in mathematics we use = to denote both assignment and equality, and are forced to use words like let and define to indicate when an assignment is meant, which I suppose is not the norm. In other words, which one is meant is based on context. Context is perhaps a reasonable way to define things in mathematics, or most other non-programming settings really, but it is definitely not a very good way in programming settings, in my opinion. This is the problem with = in this case: It has different meanings depending on its context. This can lead to subtle errors, not easy to track down. On another level, - brings up the severity of the act of assignment more clearly. You are about to overwrite whatever meaning that symbol had in the past, and replace it with a brand new meaning, and this can have a number of quite unpredictable side-effects. So it is not something that should be done lightly. In my opinion assignments should be used sparingly. Now, you might argue that when students are first learning programming, we should make it as simple as possible for them. Though I do respect that view, I think it is also important to not teach them bad practices, and overdoing it on the assignments is such a bad practice, IMO. It's hard to change what one has learned early on and gotten used to. I've spent a lot of my teaching time trying to correct such bad habits on the part of my students, especially on the importance of making it clear, when writing down an equation, whether that equation is something we know, something we are trying to prove, or used as a definition for the LHS of it. That's my story anyway, and I'm sticking to it. Sorry if I strayed a bit off topic there Ben Bolker Haris Skiadas Department of Mathematics and Computer Science Hanover College __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] dots and substitute
On Sun, 6 Apr 2008, Simon Anders wrote: Hi, is there an elegant way to use 'substitute' with '...' arguments? My first try was this: f1 - function(...) substitute(...) f1( 2+7, foo, 3+5 ) 2 + 7 As you can see, substitute acts only on the first argument. So I tried f2 - function(...) substitute(list(...)) f2( 2+7, foo, 3+5 ) list(2 + 7, foo, 3 + 5) This is now all the information I want, but it is not split into the individual arguments. I would like to get a character vector, i.e. something like c( 2 + 7, \foo\, 3 + 5 ) Try this: f2 - function(...) sapply( substitute(list(...)), deparse )[-1] all.equal( c( 2 + 7, \foo\, 3 + 5 ), f2( 2+7, foo, 3+5 )) HTH, Chuck p.s. Why do you want this as mode character? Warning: fortune(106) If the answer is parse() you should usually rethink the question. -- Thomas Lumley R-help (February 2005) My third try seems to be wrong as well: f3 - function(...) lapply( list(...), substitute ) f3( 2+7, foo, 3+5 ) Error in lapply(list(...), substitute) : '...' used in an incorrect context Does anybody has a good hint for me as how to do it correctly? Thanks Simon +--- | Dr. Simon Anders, Dipl. Phys. | European Bioinformatics Institute, Hinxton, Cambridgeshire, UK | preferred (permanent) e-mail: [EMAIL PROTECTED] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Charles C. Berry(858) 534-2098 Dept of Family/Preventive Medicine E mailto:[EMAIL PROTECTED] UC San Diego http://famprevmed.ucsd.edu/faculty/cberry/ La Jolla, San Diego 92093-0901 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Hex Decimal Convert
Hello, I have a data with hexdecimal. But GNU R convert it to strange number. How can I get that hexdecimal showing in the R-table? - My Data-Table: Sender_ID Receiver_ID Other_ID 6565 0x47780439 0x 0x 0 R-Table: 6565 1199047737 0 0 0 Kind Regards, Edwin __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Hex Decimal Convert
Dear Edwin, There's a distinction between the way in which a number is stored internally and the way in which it's printed. R is reading the hex numbers correctly but is printing them in decimal. You can assign the class hexmode to the vector containing the data and then it will print in hex: data - c(6565, 0x47780439, 0x, 0x, 0) data [1] 6565 1199047737 0 0 0 class(data) - hexmode data [1] 19a5 47780439 Notice that the whole vector is printed in hex. If you don't want that, then you could put the data into a list with some members of class hexmode and others not. I hope this helps, John On Sun, 6 Apr 2008 20:52:20 +0100 Edwin Sendjaja [EMAIL PROTECTED] wrote: Hello, I have a data with hexdecimal. But GNU R convert it to strange number. How can I get that hexdecimal showing in the R-table? - My Data-Table: Sender_ID Receiver_ID Other_ID 6565 0x47780439 0x 0x 0 R-Table: 6565 1199047737 0 0 0 Kind Regards, Edwin __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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 Fox, Professor Department of Sociology McMaster University Hamilton, Ontario, Canada http://socserv.mcmaster.ca/jfox/ __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Multiset Permutations
Dear R users, I want to perform an exact permutation of multisets. I have looked at the coin package, but it doesn't seem to offer what I am looking for. I want to perform permutations (exact - without duplications) on multisets of scalars (e.g., the multiset 0,0,1,2,2). I want to output all the possible permutations into a data frame so that each multiset permutation occupies a row (or column). The output would look something like this: 00122 01220 01210 20201 10202 12200 etc... There seem to be numerous algorithms in the primary statistical literature for doing this, but they haven't been implemented in R. I've been searching for weeks online and in books for a way of doing this, but the only thing i've come across is a Java script posted anonymously on a forum. I don't know Java at all, so can't make enough sense of it to try a translation into R, but i thought i'd include it below in case someone can glean from this a way of doing it in R. Thanks in advance for any help on this, it is greatly appreciated. Here are the original (anonymous) poster's comments and code: We definitely need to use recursion. There can be up to n! permutations. For example we'll use recursion to generate a tree of n! leaves. Each node is a run of the recursive function. The root node has n children, the nodes at the second level have each n-1 children, the nodes at the third level have n-2 children, etc. Each leaf of this tree will be a permutation. The idea is to add an element to the permutation, remove it from the set, and call the recursive function on that set. Because it's a multiset i'm using a Hashtable to eliminate duplicate entries. A pointer to the Hashtable gets passed along with each recursive call. The recursive function will know that it's on a leaf when the size of the set is 0, at which point it will insert its permutation in the Hashtable. Since identical permutations map to the same bucket in the hashtable, they overwrite eachother to leave only unique permutations. Here's the algorithm in Java: - JAVA CODE import java.util.*; public class Test { public static void PermutationsRecursive(char[] s, String p, Hashtable perms){ for(int x=0; xs.length; x++){ String np = new String(p); char[] ns = new char[s.length-1]; int y = 0; for(int z=0; zs.length; z++){ if(z != x) ns[y++] = s[z]; } np = np + s[x]; if(ns.length == 0) perms.put(np, new Boolean(true)); else PermutationsRecursive(ns, np, perms); } } public static String[] GetPermutations(char[] in){ int fact = Factorial(in.length); Hashtable perms = new Hashtable(fact); PermutationsRecursive(in, , perms); Enumeration e = perms.keys(); String[] out = new String[perms.size()]; int i = 0; while(e.hasMoreElements()){ out[i++] = (String) e.nextElement(); } return out; } private static int Factorial(int n){ int fact = 1; for(int i=2; i=n; i++){ fact *= i; } return fact; } public static void main(String[] args){ char[] set = new char[]{'A', 'A', 'B', 'C'}; String[] perms = GetPermutations(set); Arrays.sort(perms, String.CASE_INSENSITIVE_ORDER); for(int i=0; iperms.length; i++){ System.out.println(perms[i]); } } } - END JAVA CODE - This code prints the following: AABC AACB ABAC ABCA ACAB ACBA BAAC BACA BCAA CAAB CABA CBAA -- View this message in context: http://www.nabble.com/Multiset-Permutations-tp16529735p16529735.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] Multiset Permutations
You can use the function permutation from the e1071 package, then library(e1071) multisetperm - function(multiset) { unique(apply(matrix(multiset[permutations(length(multiset))], ncol=length(multiset)), 1, paste, sep=, collapse=)) } multisetperm(c(0, 0, 1, 2, 2)) The output would look something like this: 00122 01220 01210 20201 10202 12200 etc... The Java algorithm you cited does not look any more clever or less wasteful than this. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] dots and substitute
Hi Charles, Charles C. Berry wrote: Try this: f2 - function(...) sapply( substitute(list(...)), deparse )[-1] Wow, this works. Thanks a lot! p.s. Why do you want this as mode character? For the usual purpose of 'substitute': to label something. The use case is that I have a function that takes an unspecified number of very large integer vectors which are visualized in some way. I first tried to pass all the vectors as one list, via '.Call', but that made R duplicate the vectors, when the list argument is built. So, I now use '...' and '.External', where duplication does not happen. I would like to conveniently label the vectors by the expression with which they have been passed (as 'plot' does, too), and with your construction, I can now extract the expressions as characters and pass them to make the labels. Warning: fortune(106) If the answer is parse() you should usually rethink the question. -- Thomas Lumley R-help (February 2005) Then, I am lucky that you offered a solution with 'deparse', not 'parse'. ;-) Still, I am (pleasently) surprised that the vectors within the '...' do not get duplicated (according to 'tracemem') by this construction. Thank you very much Simon __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] summary(object, test=c(Roy, Wilks, Pillai, ....) AND ellipse(object, center=....)
You may be interested in the heplots package for multivariate linear models. For a multivariate regression, it plots a data ellipse of the predicted values (H matrix) together with a data ellipse of the residuals (E ellipse). H is scaled so that it protrudes outside the E ellipse iff the hypothesis is significant by Roy's test. -Michael Ray Haraf wrote: 2). My next struggle is to construct prediction ellipse. Both ellipse() and ellipse.lm() are not giving me the solution to Sampling from multivariate multiple regression prediction regions posted by Iain Pardoe, Mon May 9 18:43:46 2005. I am working on the same problem and performed all the steps he suggested ex7.10 - + data.frame(y1 = c(141.5, 168.9, 154.8, 146.5, 172.8, 160.1, 108.5), + y2 = c(301.8, 396.1, 328.2, 307.4, 362.4, 369.5, 229.1), + z1 = c(123.5, 146.1, 133.9, 128.5, 151.5, 136.2, 92), + z2 = c(2.108, 9.213, 1.905, .815, 1.061, 8.603, 1.125)) attach(ex7.10) f.mlm - lm(cbind(y1,y2)~z1+z2) y.hat - c(1, 130, 7.5) %*% coef(f.mlm) round(y.hat, 2) y1 y2 [1,] 151.84 349.63 qf.z - t(c(1, 130, 7.5)) %*% + solve(t(cbind(1,z1,z2)) %*% cbind(1,z1,z2)) %*% + c(1, 130, 7.5) round(qf.z, 5) [,1] [1,] 0.36995 n.sigma.hat - SSD(f.mlm)$SSD # same as t(resid(f.mlm)) %*%resid(f.mlm) round(n.sigma.hat, 2) y1 y2 y1 5.80 5.22 y2 5.22 12.57 F.quant - qf(.95,2,3) round(F.quant, 2) [1] 9.55 From here how could I calculate a 95% prediction ellipse for y=(y1,y2) at (z1,z2)=(130,7.5) using either ellipse or ellipse.lm? y1 would be the x-axis and y2, the y-axis. The center is different from (0,0) and I don't know what would be the appropriate x (the lm object). Should I used predicted values or residuals? In both cases I have vectors which is different from the example given with ellipse.lm 3). Lastly but not the least, would be too ambitious to draw the axes (i.e, the eigenvalues) to the ellipse? Thanks and very kind regards, Ray [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] [OT] Typesetting / highlighting R code in Latex
Le dim. 6 avr. à 14:44, Dirk Eddelbuettel a écrit : On 6 April 2008 at 10:40, Dirk Eddelbuettel wrote: | Using Latex and the beamer class, I would like to highlight code snippets. | Does anybody know a suitable 'preprocessor' or 'filter' for R (and/ or C/C++) | code ? | | I have been including it in simple \begin{verbatim} ... \end{verbatim} and I | know there is a better way -- in fact I saw it used a while back in some | package I looked at. And I didn't write that down... | | What I am looking for is the basic equivalent of 'everything in verbatim' | plus the ability to hightlight certain parts to stress the points I'd like to | make. | | There must be something. Pointers would be greatly appreciated! The listing class was what I was looking for -- thanks for the quick off-list reply. Basic synopis of listing is eg here http://en.wikibooks.org/wiki/LaTeX/Packages/Listings The listing package is great. I used it for my Introduction à la programmation en S manual (on CRAN) to index the code sections automagically. That said, I had to add a few keywords to the list bundled with the package; you may want to have a look at my customizations in https://vgoulet.act.ulaval.ca/svn/documents/intro_S/trunk/introduction_programmation_S.tex [Lines 96--113] HTH Vincent Dirk -- Three out of two people have difficulties with fractions. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Multiset Permutations
Hi, If I understand you correctly, there is beta code within the development version of package 'vegan' on R forge to do this. install.packages(vegan, repos=http://R-Forge.R-project.org;) Then: numPerms(5) [1] 120 perms - allPerms(5, observed = TRUE) perms[1:10,] [,1] [,2] [,3] [,4] [,5] [1,]12354 [2,]12435 [3,]12453 [4,]12534 [5,]12543 [6,]13245 [7,]13254 [8,]13425 [9,]13452 [10,]13524 As you can see, it returns the ordering of 5 observations when permuted freely. perms is a matrix with some extra attributes. To use this, loop over the rows of perms. To get the actual permuted vector, use something like the following: dat - c(0,0,1,2,2) dat[perms[1,]] [1] 0 0 1 2 2 dat[perms[2,]] [1] 0 0 2 1 2 dat[perms[3,]] [1] 0 0 2 2 1 This assumes that the entries in dat are freely exchangeable, which is what I take your output example to be representing. Be careful to read the help page for allPerms, if n is large you'll need to increase argument 'max'. numPerms(n) where n is the number of entries in dat will tell you how big max needs to be. Note that you should be able to do: perms - allPerms(dat) but that isn't working at all (did I say this was beta code?) due to a silly bug I introduced by trying to be too clever for my own good. So you have to use allPerms(n) instead. If this isn't exactly what you wanted, email me back as there may be a way to use the more complicated restricted permutations available in vegan to do what you want. HTH G On Sun, 2008-04-06 at 13:57 -0700, Stropharia wrote: Dear R users, I want to perform an exact permutation of multisets. I have looked at the coin package, but it doesn't seem to offer what I am looking for. I want to perform permutations (exact - without duplications) on multisets of scalars (e.g., the multiset 0,0,1,2,2). I want to output all the possible permutations into a data frame so that each multiset permutation occupies a row (or column). The output would look something like this: 00122 01220 01210 20201 10202 12200 etc... There seem to be numerous algorithms in the primary statistical literature for doing this, but they haven't been implemented in R. I've been searching for weeks online and in books for a way of doing this, but the only thing i've come across is a Java script posted anonymously on a forum. I don't know Java at all, so can't make enough sense of it to try a translation into R, but i thought i'd include it below in case someone can glean from this a way of doing it in R. Thanks in advance for any help on this, it is greatly appreciated. Here are the original (anonymous) poster's comments and code: We definitely need to use recursion. There can be up to n! permutations. For example we'll use recursion to generate a tree of n! leaves. Each node is a run of the recursive function. The root node has n children, the nodes at the second level have each n-1 children, the nodes at the third level have n-2 children, etc. Each leaf of this tree will be a permutation. The idea is to add an element to the permutation, remove it from the set, and call the recursive function on that set. Because it's a multiset i'm using a Hashtable to eliminate duplicate entries. A pointer to the Hashtable gets passed along with each recursive call. The recursive function will know that it's on a leaf when the size of the set is 0, at which point it will insert its permutation in the Hashtable. Since identical permutations map to the same bucket in the hashtable, they overwrite eachother to leave only unique permutations. Here's the algorithm in Java: - JAVA CODE import java.util.*; public class Test { public static void PermutationsRecursive(char[] s, String p, Hashtable perms){ for(int x=0; xs.length; x++){ String np = new String(p); char[] ns = new char[s.length-1]; int y = 0; for(int z=0; zs.length; z++){ if(z != x) ns[y++] = s[z]; } np = np + s[x]; if(ns.length == 0) perms.put(np, new Boolean(true)); else PermutationsRecursive(ns, np, perms); } } public static String[] GetPermutations(char[] in){ int fact = Factorial(in.length); Hashtable perms = new Hashtable(fact); PermutationsRecursive(in, , perms); Enumeration e = perms.keys(); String[] out = new String[perms.size()]; int i = 0; while(e.hasMoreElements()){ out[i++] = (String)
[R] Error message got a real'
Hi all, I'm running the program sem on a Mac, but I'm getting a message that I think is quite general. The error reads Error in scan(file, what, nmax, sep, dec, quote, skip, nlines, na.strings, : scan() expected 'a real', got '10652)' The 10652 is the sample size coming from a .csv file where I have header = TRUE. Any thoughts would be appreciated. David -- === David Kaplan, Ph.D. Professor Department of Educational Psychology University of Wisconsin - Madison Educational Sciences, Room, 1061 1025 W. Johnson Street Madison, WI 53706 email: dkaplan at education dot wisc dot edu homepage: [1]http://www.education.wisc.edu/edpsych/facstaff/kaplan/kaplan.htm Phone: 608-262-0836 === References 1. http://www.education.wisc.edu/edpsych/facstaff/kaplan/kaplan.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] R, VR, and Debian
Hi Folks, A while ago (September 2007) I set up an experimental Debian 4.0 Etch installation, and installed R on it, along with several packages -- including e1071 and the Bundle VR -- by means of the Debian package manager. Most of the time, R works fine. But not always. Just now, I wanted to try the code suggested by Johannes Hüsing for Stroparia's Multiset Permutation question. The first line is library(e1071) -- this failed because: library(e1071) Loading required package: class Error: package 'class' could not be loaded In addition: Warning message: there is no package called 'class' in: library(pkg, character.only = TRUE, logical = TRUE, lib.loc = lib.loc) The Debian package manager tells me that r-cran-vr is fully installed, and that The VR package contains four individuals packages: MASS, class, nnet and spatial. Also, that the installed version of r-cran-vr is 7.2.29-1 and also that this is the latest version. However, the version on CRAN is 7.2-41. A search downwards from /usr/lib/R finds nothing that matches class, nnet, nor spatial, though MASS is there. 'locate class', 'locate nnet', 'locate spatial' all draw blanks (as far as anything to do with R is concerned). So these packages, allegedly part of VR, have not been installed. I thought of uninstalling VR and re-installing, but after I marked it for deletion I was told that lots of other packages would disappear as well, so I backed off. It would seem, therefore, that installing R via the Debian repositories can be a close approximation to a waste of time! Additionally, in the past I have encountered a block when trying to install R packages from source, on this system, because something is wrong with 'gfortran'. I do not want to have to fight Debian in order to get on with using R, and (once again) feel discouraged about continuing to use a Linux distribution which, in other respects, is of high repute. I would be grateful for comments on the above observations, and particularly grateful for suggestions about how to overcome these problems. With best wishes to all, Ted. E-Mail: (Ted Harding) [EMAIL PROTECTED] Fax-to-email: +44 (0)870 094 0861 Date: 06-Apr-08 Time: 23:58:27 -- XFMail -- __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Executing a telnet session from R
Colleagues I am working in a Linux OS with R 2.6.2. I need to execute a telnet session to another Linux machine from R, perform some operations, then return to the original computer. When I am in an R session, this is easy to accomplish by typing: system(telnet -l username machinename) I am then asked for my password; once that is entered, I am connected to the remote machine. I can then enter commands on the remote machine, then logout. I would like to automate this process within a function. Obviously, I can embed the 'system' command in the function. Questions: 1. How do I enter the password into the command? 2. How do I execute the commands on the other machine? 3. Finally, how do I execute the 'logout' command (this should not differ from #2)? Thanks in advance for any help on this. Dennis Dennis Fisher MD P (The P Less Than Company) Phone: 1-866-PLessThan (1-866-753-7784) Fax: 1-415-564-2220 www.PLessThan.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.
Re: [R] Multiset Permutations
Dear Steven, The prob package does this, too. (Please see the * fix below). x - c(0, 0, 1, 2, 2) library(prob) A - permsn(x, 5) # with repeated columns B - unique( data.frame( t(A) )) # no repeated rows The data frame B will have 56 rows and 5 columns. If you need the columns collapsed, then you can use the apply(B, 1, paste, sep = , collapse = ) command that Johannes suggested. Details are in the prob package vignette, vignette(prob) I hope that this helps, Jay * fix: As it happens, your particular question helped to identify a bug in the current CRAN version of prob. Thank you! :-) Below is a fix until the updated version appears. permsn - function (x, m) { require(combinat) if (is.numeric(x) length(x) == 1 x 0 trunc(x) == x) x - seq(x) temp - combn(x, m) if ( isTRUE(all.equal(m,1)) ) { P - temp } else if (isTRUE(all.equal(m, length(x { temp - matrix(x, ncol = 1) P - array(unlist(permn(temp[, 1])), dim = c(m, factorial(m))) } else { k - dim(temp)[1] n - dim(temp)[2] P - array(unlist(permn(temp[, 1])), dim = c(k, factorial(k))) for (i in 2:n) { a - temp[, i] perms - array(unlist(permn(a)), dim = c(k, factorial(k))) P - cbind(P, perms) } } return(P) } *** G. Jay Kerns, Ph.D. Assistant Professor / Statistics Coordinator Department of Mathematics Statistics Youngstown State University Youngstown, OH 44555-0002 USA Office: 1035 Cushwa Hall Phone: (330) 941-3310 Office (voice mail) -3302 Department -3170 FAX E-mail: [EMAIL PROTECTED] http://www.cc.ysu.edu/~gjkerns/ __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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 manupute data frame with conditions fill cell with previous value if next cell is zero
There may well be neater ways to do this, but if you have only a limited number of zeros in any run, this is probably as quick as any. Suppose your data frame is 'dat': fixCol - function(x) { y - x n - length(x) while(any(zx - x == 0)) { y - c(NA, y[-n]) x[zx] - y[zx] } x } dat - transform(dat, x = fixCol(x), y = fixCol(y), z = fixCol(z)) If you have a great number of columns to fix up like this, a more succinct way would be something like dat[, 3:5] - lapply(dat[, 3:5], fixCol) Bill Venables CSIRO Laboratories PO Box 120, Cleveland, 4163 AUSTRALIA Office Phone (email preferred): +61 7 3826 7251 Fax (if absolutely necessary): +61 7 3826 7304 Mobile: +61 4 8819 4402 Home Phone: +61 7 3286 7700 mailto:[EMAIL PROTECTED] http://www.cmis.csiro.au/bill.venables/ -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of saikat sarkar Sent: Sunday, 6 April 2008 11:05 PM To: r-help@r-project.org Subject: [R] how to manupute data frame with conditions fill cell with previous value if next cell is zero Dear R Experts, This is the 2nd time in the chat room. Its a great place to get help from R experts. I have a data frame problem, it contains thousands of data. part of it, I am giving for explaining the problem date day x yz 82 1989-04-28 Fri 2118.0 2418.80 33713 83 1989-05-01 Mon0.0 2414.96 33793 84 1989-05-02 Tue 2103.12402.86 33955 85 1989-05-03 Wed 2105.7 2393.70 0 86 1989-05-04 Thu 2119.0 2384.90 0 87 1989-05-05 Fri2132.8 2381.96 0 103 1989-05-29 Mon0.00.00 34161 127 1989-06-30 Fri 2151.0 2440.06 32949 128 1989-07-03 Mon 2165.6 2452.77 33236 129 1989-07-04 Tue 2174.40 35376 130 1989-07-05 Wed 2162.9 2456.56 33310 167 1989-08-25 Fri 2397.4 2732.36 34740 168 1989-08-28 Mon0.02743.36 34607 169 1989-08-29 Tue 2380.8 2726.63 34688 170 1989-08-30 Wed 2381.3 2728.15 34472 171 1989-08-31 Thu 2387.9 2737.27 34431 172 1989-09-01 Fri 2407.5 2752.09 34348 173 1989-09-04 Mon 2419.20.00 34484 174 1989-09-05 Tue 2426.0 2744.68 34442 175 1989-09-06 Wed 2390.8 2719.79 34271 176 1989-09-07 Thu 2415.9 2706.88 34153 177 1989-09-08 Fri 2423.9 2709.54 34116 178 1989-09-11 Mon 2400.6 2704.41 34114 179 1989-09-12 Tue 2397.6 2707.26 34333 180 1989-09-13 Wed 2401.5 2679.52 34287 181 1989-09-14 Thu 2382.0 2664.89 34402 182 1989-09-15 Fri 2366.5 2674.58 0 183 1989-09-18 Mon 2373.8 2687.50 34473 195 1989-10-04 Wed 2312.1 2771.09 35383 196 1989-10-05 Thu 2281.6 2773.56 35523 197 1989-10-06 Fri 2277.5 2785.52 35209 198 1989-10-09 Mon 2247.0 2791.41 35376 199 1989-10-10 Tue 2218.8 2785.33 0 200 1989-10-11 Wed 2218.8 2773.36 35240 In this data frame, I need to replace cells which is zero with previous value. For example 82 1989-04-28 Fri 2118.0 2418.80 33713 83 1989-05-01 Mon0.0 2414.96 33793 in 2nd line 0.0 should be replaced by 2118.0 Another Example 84 1989-05-02 Tue 2103.1 2402.86 33955 85 1989-05-03 Wed 2105.7 2393.70 0 86 1989-05-04 Thu 2119.0 2384.90 0 87 1989-05-05 Fri 2132.8 2381.96 0 3 lines filled by 33955 value. Another example 198 1989-10-09 Mon 2247.0 2791.41 35376 199 1989-10-10 Tue 2218.8 2785.33 0 200 1989-10-11 Wed 2218.8 2773.36 35240 in 2nd line filled by zero should be replaced by value 35376 Please help me. Thanking you saikat -- View this message in context: http://www.nabble.com/how-to-manupute-data-frame-with-conditions-fill-ce ll-with-previous-value-if-next-cell-is-zero-tp16524107p16524107.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] Error message got a real'
David Kaplan wrote: Hi all, I'm running the program sem on a Mac, but I'm getting a message that I think is quite general. The error reads Error in scan(file, what, nmax, sep, dec, quote, skip, nlines, na.strings, : scan() expected 'a real', got '10652)' The 10652 is the sample size coming from a .csv file where I have header = TRUE. It appears to be finding a parenthesis too. That's not a real. 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] 'URCA' is not a valid package Error
Thank you Matthieu for your helpful suggestions. Unfortunately I still have problems. I have tried to compile it via your suggestion. this is strange... you should have the usual summary... I have on my machine library(urca) test2-ur.df(nottem, type=none, lags=1) summary(test2) When I type in library(urca) I receive the following. Error in library(urca) : 'urca' is not a valid package -- installed 2.0.0? When I type in installed.packages() the ONLY package with NA entries is URCA. SuggestsBuilt tcltk NA 2.6.2 tools NA 2.6.2 urca NA NA utils NA 2.6.2 I have tried to kill the session and start again but to no avail. I have installed Package: r-cran-urca (1.1-6-1) [universe] from the ubuntu website for use in Windows. My R version is 2.6.2. Thanks in advance for your help, Leyla. [[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] Hex Decimal Convert
Dear John, Thank you. Is there any possibility to get original stored number printed. Because i have another coloum like: Protocol TCP This is gonna cause probleme (as you notice before). I dont really understand what you mean with a list. i am new with R. Thanks, Edwin Am Sonntag, 6. April 2008 21:38:19 schrieb John Fox: Dear Edwin, There's a distinction between the way in which a number is stored internally and the way in which it's printed. R is reading the hex numbers correctly but is printing them in decimal. You can assign the class hexmode to the vector containing the data and then it will print in hex: data - c(6565, 0x47780439, 0x, 0x, 0) data [1] 6565 1199047737 0 0 0 class(data) - hexmode data [1] 19a5 47780439 Notice that the whole vector is printed in hex. If you don't want that, then you could put the data into a list with some members of class hexmode and others not. I hope this helps, John On Sun, 6 Apr 2008 20:52:20 +0100 Edwin Sendjaja [EMAIL PROTECTED] wrote: Hello, I have a data with hexdecimal. But GNU R convert it to strange number. How can I get that hexdecimal showing in the R-table? --- -- My Data-Table: Sender_ID Receiver_ID Other_ID 6565 0x47780439 0x 0x 0 --- - R-Table: 6565 1199047737 0 0 0 Kind Regards, Edwin __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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 Fox, Professor Department of Sociology McMaster University Hamilton, Ontario, Canada http://socserv.mcmaster.ca/jfox/ __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] mgcv::gam prediction using lpmatrix
The documentation for predict.gam in library mgcv gives an example of using an lpmatrix to do approximate prediction via interpolation. However, the code is specific to the example wrt the number of smooth terms, df's for each,etc. (which is entirely appropriate for an example) Has anyone generalized this to directly generate code from a gam object (eg SAS or C code)? I wanted to check before I reinvent the wheel. Thanks. -- View this message in context: http://www.nabble.com/mgcv%3A%3Agam-prediction-using-lpmatrix-tp16531418p16531418.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] R, VR, and Debian
On 6 April 2008 at 23:58, (Ted Harding) wrote: | Hi Folks, | A while ago (September 2007) I set up an experimental | Debian 4.0 Etch installation, and installed R on it, | along with several packages -- including e1071 and | the Bundle VR -- by means of the Debian package | manager. Most of the time, R works fine. But not always. | | Just now, I wanted to try the code suggested by | Johannes Hüsing for Stroparia's Multiset Permutation | question. | | The first line is library(e1071) -- this failed | because: | | library(e1071) | Loading required package: class | Error: package 'class' could not be loaded | In addition: Warning message: | there is no package called 'class' in: library(pkg, | character.only = TRUE, logical = TRUE, lib.loc = lib.loc) Looks like you may want to file a bug report against the corresponding Debian package which be out of sync or requiring a rebuild. I'm CCing the maintainer of that pacage too. | | The Debian package manager tells me that r-cran-vr | is fully installed, and that | The VR package contains four individuals packages: | MASS, class, nnet and spatial. | | Also, that the installed version of r-cran-vr is | 7.2.29-1 and also that this is the latest version. | However, the version on CRAN is 7.2-41. You made a choice of picking Debian etch for stability. This means packages will not be updated _by design and your choice_. So you cannot turn around and say 'how come the VR version is behind CRAN?'. For Debian unstable and testing (sid and lenny, IIRC) we have current versions. | A search downwards from /usr/lib/R finds nothing that | matches class, nnet, nor spatial, though MASS | is there. 'locate class', 'locate nnet', 'locate spatial' | all draw blanks (as far as anything to do with R is | concerned). So these packages, allegedly part of VR, | have not been installed. I have them below /usr/lib/R as you'd expect, but I ran testing. Maybe something happened. I'd reinstall the package. | I thought of uninstalling VR and re-installing, but | after I marked it for deletion I was told that lots | of other packages would disappear as well, so I | backed off. Just re-install by hand to test. Download the ,deb to /tmp and do 'sudo dpkg --install r-cran-vr_*.deb' on it. | It would seem, therefore, that installing R via the | Debian repositories can be a close approximation to | a waste of time! | | Additionally, in the past I have encountered a block | when trying to install R packages from source, on this | system, because something is wrong with 'gfortran'. | | I do not want to have to fight Debian in order to get | on with using R, and (once again) feel discouraged | about continuing to use a Linux distribution which, | in other respects, is of high repute. Many people are happy users of R and Debian. Why don;t you bring your questions to the r-sig-debian list where they are most on-topic? Hth, Dirk | I would be grateful for comments on the above observations, | and particularly grateful for suggestions about how to | overcome these problems. | | With best wishes to all, | Ted. | | | E-Mail: (Ted Harding) [EMAIL PROTECTED] | Fax-to-email: +44 (0)870 094 0861 | Date: 06-Apr-08 Time: 23:58:27 | -- XFMail -- | | __ | R-help@r-project.org mailing list | https://stat.ethz.ch/mailman/listinfo/r-help | PLEASE do read the posting guide http://www.R-project.org/posting-guide.html | and provide commented, minimal, self-contained, reproducible code. -- Three out of two people have difficulties with fractions. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Hex Decimal Convert
Dear Edwin, On Mon, 7 Apr 2008 01:14:35 +0100 Edwin Sendjaja [EMAIL PROTECTED] wrote: Dear John, Thank you. Is there any possibility to get original stored number printed. R is a programming language, so you could in principle read an input line as character data, break it into its components, and output each component in whatever format you wished. That would require some work. There might be a simpler approach, but I'm not aware of it. Because i have another coloum like: Protocol TCP The previous example that you send consisted entirely of numeric data and had only one line. Assuming that there are several lines, you could read the data into a data frame via read.table() and exercise some control over how each column is read. See ?read.table. You could then deal separately with the columns. This is gonna cause probleme (as you notice before). I'm afraid that I didn't notice since there was no character data in your previous example. I dont really understand what you mean with a list. i am new with R. It's probably unreasonable to expect to be able to use a programming language without reading something about it. One place to start is with the introductory manual distributed with R, which discusses lists in Section 6.1. Alternatively, you could read one of a number of books on R; many are listed at http://www.r-project.org/doc/bib/R-books.html. Regards, John Thanks, Edwin Am Sonntag, 6. April 2008 21:38:19 schrieb John Fox: Dear Edwin, There's a distinction between the way in which a number is stored internally and the way in which it's printed. R is reading the hex numbers correctly but is printing them in decimal. You can assign the class hexmode to the vector containing the data and then it will print in hex: data - c(6565, 0x47780439, 0x, 0x, 0) data [1] 6565 1199047737 0 0 0 class(data) - hexmode data [1] 19a5 47780439 Notice that the whole vector is printed in hex. If you don't want that, then you could put the data into a list with some members of class hexmode and others not. I hope this helps, John On Sun, 6 Apr 2008 20:52:20 +0100 Edwin Sendjaja [EMAIL PROTECTED] wrote: Hello, I have a data with hexdecimal. But GNU R convert it to strange number. How can I get that hexdecimal showing in the R-table? --- -- My Data-Table: Sender_ID Receiver_ID Other_ID 6565 0x47780439 0x 0x 0 --- - R-Table: 6565 1199047737 0 0 0 Kind Regards, Edwin __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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 Fox, Professor Department of Sociology McMaster University Hamilton, Ontario, Canada http://socserv.mcmaster.ca/jfox/ __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. John Fox, Professor Department of Sociology McMaster University Hamilton, Ontario, Canada http://socserv.mcmaster.ca/jfox/ __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Executing a telnet session from R
Don't use telnet, use rsh or (better) ssh. You can set up your identity on the remote host so that ssh doesn't ask for your password (see ssh documentation), and you can give ssh the command(s) that should be executed on the remote host (again see ssh documentation). Claus On Sunday 06 April 2008, Dennis Fisher wrote: Colleagues I am working in a Linux OS with R 2.6.2. I need to execute a telnet session to another Linux machine from R, perform some operations, then return to the original computer. When I am in an R session, this is easy to accomplish by typing: system(telnet -l username machinename) I am then asked for my password; once that is entered, I am connected to the remote machine. I can then enter commands on the remote machine, then logout. I would like to automate this process within a function. Obviously, I can embed the 'system' command in the function. Questions: 1. How do I enter the password into the command? 2. How do I execute the commands on the other machine? 3. Finally, how do I execute the 'logout' command (this should not differ from #2)? Thanks in advance for any help on this. Dennis Dennis Fisher MD P (The P Less Than Company) Phone: 1-866-PLessThan (1-866-753-7784) Fax: 1-415-564-2220 www.PLessThan.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. -- Claus Wilke Section of Integrative Biology and Center for Computational Biology and Bioinformatics University of Texas at Austin 1 University Station C0930 Austin, TX 78712 [EMAIL PROTECTED] 512 471 6028 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Error message got a real'
David Kaplan wrote: Yea, I checked that, but that wasn't the problem. I'm sending the input and a much smaller file. It's in .csv format. The input is for the Mac, and I'm beginning to think it might be a Mac issue. The program input lines come from John Fox's program sem The test.csv file isn't a csv file (which is a text format, with comma separated columns). It looks like your spreadsheet let you name it with extension .csv, but didn't save it in that format. By the way, posting the same question 6 minutes apart on two mailing lists is quite inconsiderate; please don't do that. Duncan Murdoch David === David Kaplan, Ph.D. Professor Department of Educational Psychology University of Wisconsin - Madison Educational Sciences, Room, 1061 1025 W. Johnson Street Madison, WI 53706 email: dkaplan at education dot wisc dot edu homepage: [1]http://www.education.wisc.edu/edpsych/facstaff/kaplan/kaplan.htm Phone: 608-262-0836 === Duncan Murdoch wrote: David Kaplan wrote: Hi all, I'm running the program sem on a Mac, but I'm getting a message that I think is quite general. The error reads Error in scan(file, what, nmax, sep, dec, quote, skip, nlines, na.strings, : scan() expected 'a real', got '10652)' The 10652 is the sample size coming from a .csv file where I have header = TRUE. It appears to be finding a parenthesis too. That's not a real. Duncan Murdoch References 1. http://www.education.wisc.edu/edpsych/facstaff/kaplan/kaplan.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] Error message got a real'
Thanks, I'm not sure why it wasn't saved as a .csv. I posted it to the R Mac list and the general R list because in the past when I've posted to the R Mac list I was told it wasn't a R question. Because this problem didn't appear with the windows verson of R, I wasn't sure which list was appropriate. There was no intention to be inconsiderate. David === David Kaplan, Ph.D. Professor Department of Educational Psychology University of Wisconsin - Madison Educational Sciences, Room, 1061 1025 W. Johnson Street Madison, WI 53706 email: dkaplan at education dot wisc dot edu homepage: [1]http://www.education.wisc.edu/edpsych/facstaff/kaplan/kaplan.htm Phone: 608-262-0836 === Duncan Murdoch wrote: David Kaplan wrote: Yea, I checked that, but that wasn't the problem. I'm sending the input and a much smaller file. It's in .csv format. The input is for the Mac, and I'm beginning to think it might be a Mac issue. The program input lines come from John Fox's program sem The test.csv file isn't a csv file (which is a text format, with comma separated columns). It looks like your spreadsheet let you name it with extension .csv, but didn't save it in that format. By the way, posting the same question 6 minutes apart on two mailing lists is quite inconsiderate; please don't do that. Duncan Murdoch David === David Kaplan, Ph.D. Professor Department of Educational Psychology University of Wisconsin - Madison Educational Sciences, Room, 1061 1025 W. Johnson Street Madison, WI 53706 email: dkaplan at education dot wisc dot edu homepage: [1][2]http://www.education.wisc.edu/edpsych/facstaff/kaplan/kaplan.htm Phone: 608-262-0836 === Duncan Murdoch wrote: David Kaplan wrote: Hi all, I'm running the program sem on a Mac, but I'm getting a message that I think is quite general. The error reads Error in scan(file, what, nmax, sep, dec, quote, skip, nlines, na.strings, : scan() expected 'a real', got '10652)' The 10652 is the sample size coming from a .csv file where I have header = TRUE. It appears to be finding a parenthesis too. That's not a real. Duncan Murdoch References 1. [3]http://www.education.wisc.edu/edpsych/facstaff/kaplan/kaplan.htm __ [EMAIL PROTECTED] mailing list [5]https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide [6]http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. References 1. http://www.education.wisc.edu/edpsych/facstaff/kaplan/kaplan.htm 2. http://www.education.wisc.edu/edpsych/facstaff/kaplan/kaplan.htm 3. http://www.education.wisc.edu/edpsych/facstaff/kaplan/kaplan.htm 4. mailto:R-help@r-project.org 5. https://stat.ethz.ch/mailman/listinfo/r-help 6. http://www.R-project.org/posting-guide.html __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] How to include a vignette with my package?
I want to include a vignette with a package I wrote. I did follow the Writting R extentions document step by step, but went I run Rcmd build, an error occurs. It goes like this: * creating vignettes ... ERROR . . . . :7: Emergency stop L7L == Fatal error occurred, no output PDF file produced!texify: pdflatex failed for some reason see log file. buildVignettesdir ='. ' Error in texi2dvifil =bft,pdf =TRUE, clean =FALSE, quiet = quiest : running 'texi2dvi' on test.tex' failed Calls : buildVignettes - texi2dvi Execution halted Thank you for your help! Francois Aucoin [[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] 'URCA' is not a valid package Error
Leyla Biondini wrote: I have installed Package: r-cran-urca (1.1-6-1) [universe] from the ubuntu website for use in Windows. Whatever made you believe that that would work? If you are using Windows, just install urca via the Packages menu in the Rgui. -- O__ Peter Dalgaard Øster Farimagsgade 5, Entr.B c/ /'_ --- Dept. of Biostatistics PO Box 2099, 1014 Cph. K (*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918 ~~ - ([EMAIL PROTECTED]) FAX: (+45) 35327907 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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 include a vignette with my package?
François Aucoin wrote: I want to include a vignette with a package I wrote. I did follow the Writting R extentions document step by step, but went I run Rcmd build, an error occurs. It goes like this: * creating vignettes ... ERROR . . . . :7: Emergency stop L7L == Fatal error occurred, no output PDF file produced!texify: pdflatex failed for some reason see log file. buildVignettesdir ='. ' Error in texi2dvifil =bft,pdf =TRUE, clean =FALSE, quiet = quiest : running 'texi2dvi' on test.tex' failed Calls : buildVignettes - texi2dvi Execution halted I would guess that the script couldn't find LaTeX (more specifically, pdflatex). You may need to install it, or at least add it to your path. 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] getting numeric arrays from data frame
Currently I invoke: foo - read.table(foo.data, header=TRUE) to read a table into foo Then when I try to plot a histogram out of the 5th column of foo: hist(foo[5]) It fails and it says: Error in hist.default(foo[5]) : 'x' must be numeric Then I tried: typeof(foo[5]) [1] List So how can I get an numeric array out of one of the columns? Also suppose if the dataframe foo (above) has eight columns and I want to make an x-y scatter plot on two of the columns, how can I extract these two specific columns? Thanks Mark __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] getting numeric arrays from data frame
try hist(foo[,5]) plot(foo[,c(1,5)]) HTH Currently I invoke: foo - read.table(foo.data, header=TRUE) to read a table into foo Then when I try to plot a histogram out of the 5th column of foo: hist(foo[5]) It fails and it says: Error in hist.default(foo[5]) : 'x' must be numeric Then I tried: typeof(foo[5]) [1] List So how can I get an numeric array out of one of the columns? Also suppose if the dataframe foo (above) has eight columns and I want to make an x-y scatter plot on two of the columns, how can I extract these two specific columns? Thanks Mark __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] function for between-groups covariance matrix?
Hi Is anyone aware if there is a function already available that calculates the between-groups COvariance matrix, say in a discriminant analysis setting, or in a manova setting. Maybe as a helper function to some other major function. Otherwise I would have to program it myself (probably resulting in some awkward code performing horribly on this large dataset). Thanks Toby __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.