Re: [R] Spline Question

2012-02-15 Thread Michael Bedward
On 15 February 2012 19:00, Jeff Newmiller wrote: > What part of "read the posting guide" did you not understand? The "provide > commented, minimal, self-contained, reproducible code" part? Off topic: why is there so much unfriendliness on this thread ? Both the above and DW's post seem unnecessa

Re: [R] an unusual use for R

2012-02-02 Thread Michael Bedward
Brilliant Sarah ! I love seeing such unexpected and creative applications. I'm not a weaver but am a knitter (and a knotter actually) and have mused about using R to help design elements of textured knitting patterns e.g. as seen in single-colour, traditional fisherman's jumpers from England and

Re: [R] Regression type 2, x measured with error

2011-02-01 Thread Michael Bedward
Another search term is "geometric mean regression". For simple models you can try the lmodel2 package. Michael On 2 February 2011 04:31, David Winsemius wrote: > > On Feb 1, 2011, at 10:41 AM, misil wrote: > >> >> I wanna to do a Regression type 2 or Regression with X measured with >> error

Re: [R] how to calculate the consistency of different clusterings

2011-01-16 Thread Michael Bedward
Hello, I've been waiting to see if anyone else would answer this. I've previously used random reallocation of objects to groups (clusters) as a monte-carlo test of the informativeness of groups, as described here: http://lastresortsoftware.blogspot.com/2010/09/monte-carlo-testing-of-classificati

Re: [R] RSQLite - How to express(or save) a dataframe as an output?

2011-01-15 Thread Michael Bedward
Hi Amelia, You statement... dbGetPreparedQuery(con, "INSERT INTO output(df) VALUES (?)", data.frame(output)) ...is the problem. To insert an entire data.frame into the database use dbWriteTable. To insert with debSendPreparedQuery or dbGetPreparedQuery, the number of "?" in the VALUES specifie

Re: [R] gennerating skewed random numbers

2011-01-11 Thread Michael Bedward
Hi Ed, The sn package can generate random values from skewed Normal and t distributions. Also see here: http://azzalini.stat.unipd.it/SN/faq-r.html Michael On 11 January 2011 23:37, Ed Keith wrote: > This is not exactly an R specific question, but I think the people on this > list can probabl

Re: [R] how to coerce part of each column of a matrix to a vector and merge them

2011-01-11 Thread Michael Bedward
Hello, The answer to this one drops out of the answer to your previous question... m <- matrix(1:16, nrow=4) end <- c(2,3,1,3) ii <- cbind(sequence(end), rep(1:length(end), end)) x <- m[ ii ] Hope this helps, Michael 2011/1/11 zhaoxing731 : > Hello > > Suppose I have a matrix mat=(1:16,2) >

Re: [R] Generation of Normal Random Numbers

2011-01-11 Thread Michael Bedward
Sagga K > > --- On *Tue, 11/1/11, Michael Bedward * wrote: > > > From: Michael Bedward > Subject: Re: [R] Generation of Normal Random Numbers > To: "saggak" > Cc: r-help@r-project.org > Received: Tuesday, 11 January, 2011, 7:24 AM > > m <- c(1004

Re: [R] how to use "apply" function partial to each vector of a matrix

2011-01-10 Thread Michael Bedward
Hello, Here is one way... m <- matrix(1:16, nrow=4) end <- c(2, 3, 1, 3) ii <- cbind(sequence(end), rep(1:length(end), end)) sums <- tapply(m[ ii ], ii[ , 2], sum) And here is another way... sums <- mapply(function(col, lastrow) sum(m[1:lastrow, col]), 1:ncol(m), end) Hope this helps, Michael

Re: [R] Generation of Normal Random Numbers

2011-01-10 Thread Michael Bedward
m <- c(1004.1, 1028.3, 1044.3, 861.4) s <- c(194.5899, 158.7052, 123.3000, 285.8695) x <- mapply(function(mi, si) rnorm(25, mi, si), m, s) Hope this helps, Michael On 11 January 2011 17:44, saggak wrote: > Dear R helpers > > I have a data frame as given below > > df = data.frame(A = c(776,827,

Re: [R] Global variables

2011-01-10 Thread Michael Bedward
Hi Sebastian, You might also find the proto package useful as a way of restricting the scope of variables. It provides a more intuitive (at least to me) way of packaging variables and functions up into environments that can be related in a hierarchy. Michael On 10 January 2011 23:48, Sebastien B

Re: [R] Normal Distribution Quantiles

2011-01-09 Thread Michael Bedward
Just to add to the silly solutions, here's how I would have done it... mu <- 40 sdev <- 10 days <- 100:120 # range to explore p <- 0.8 days[ match(TRUE, qnorm(0.2, mu*days, sqrt(sdev * sdev * days)) >= 4000) ] Michael On 9 January 2011 08:48, Bert Gunter wrote: > If I understand what you have

Re: [R] How to make a Cluster of Clusters

2011-01-07 Thread Michael Bedward
Hi Diego, It depends on your what your research questions are. You haven't told us :) For example, if you wanted to know whether (a) the environmental distance between lakes is correlated with spatial distance and (b) if the relationship changes over time you might do a series of Mantel tests. T

Re: [R] How to make a Cluster of Clusters

2011-01-06 Thread Michael Bedward
Hello Diego, This might not be relevant, but on reading your question the first idea that struck me was that ordination trajectories of your lakes over time might be more informative than clustering. Michael On 5 January 2011 01:31, Diego Pujoni wrote: > Dear R-help, > > In my Master thesis I m

Re: [R] RSQLite to input dataframe

2011-01-04 Thread Michael Bedward
Hi Amy, I'm not sure if I understand your question correctly so let me know if the following is off track. Starting with your example, here is how to create a data.frame and write it to a new table in a new database file... my.data = data.frame(X = c("US", "UK", "Canada", "Australia", "Newzealan

Re: [R] Bayesian Belief Networks

2010-12-23 Thread Michael Bedward
Hello Walt, Have a look at the bnlearn and deal packages. Michael On 24 December 2010 01:29, Data Analytics Corp. wrote: > Hi, > > Does anyone know of a package for or any implementation of a Bayesian Belief > Network in R? > > Thanks, > > Walt > > > > Walter R. Paczkow

Re: [R] regression

2010-12-22 Thread Michael Bedward
Hello Ufuk, Here is one way to do it... # make up some data for this example x <- matrix(runif(7 * 20), ncol=7) # a data.frame is most convenient for lm x <- as.data.frame(x) colnames(x) <- c("x1", "x2", "x3", "x4", "x5", "x6", "y") # a list to hold lm results x.lm <- list() # run regressions

Re: [R] Compare two dataframes

2010-12-16 Thread Michael Bedward
Hello Mark, This is how I do it but it's longer than your code :) unique.rows <- function (df1, df2) { # Returns any rows of df1 that are not in df2 out <- NULL for (i in 1:nrow(df1)) { found <- FALSE for (j in 1:nrow(df2)) { if (all(df1[i,] == df2[j,])) { found <- T

Re: [R] Is there a join() function in R ? OR: simulating "Combining ggplot2 and Google Maps" by David Kahle

2010-12-16 Thread Michael Bedward
Hi Christiaan, That looks like the join function in the plyr package. Michael On 16 December 2010 22:06, christiaan pauw wrote: > Hi everybody > > Im on R version 2.11.1  on Mac OS X > > I am working through David Kahle's example of using ggplot2 with Rgooglemaps > (found here: > https://github

Re: [R] predict.lm with new regressor names

2010-12-15 Thread Michael Bedward
Hi Anirban, You can do it like this... lm.foobar <- lm(foo ~ bar) some.data <- rnorm(200) predict(lm.foobar, newdata=list(bar=some.data)) Hope that helps. Michael On 16 December 2010 17:05, Anirban Mukherjee wrote: > Hi all, > > Suppose: > > y<-rnorm(100) > x1<-rnorm(100) > lm.yx<-lm(y~x1) >

Re: [R] Significance Help

2010-12-14 Thread Michael Bedward
Hello Samaire, I don't know much about eyesight measurements (other than that my own would probably be 0.1, 0.2) but I'll attempt some suggestions... For objective (1) you will have to define what you mean by significantly different. If you had data on left/right values from a larger population t

Re: [R] peak detection

2010-12-13 Thread Michael Bedward
Hi Joe, Just for info, I've done this in the past by applying lowess followed by diff to a vector, then identifying points with change of sign in the diffs. Michael On 14 December 2010 14:22, Joe Stuart wrote: > Never mind. I did find this package, which seems to do the trick. Thanks > > http:/

Re: [R] simple plotting question

2010-12-12 Thread Michael Bedward
Hello Erin, Try this... plot(x, y, type="b", pch=16) Michael On 13 December 2010 18:11, Erin Hodgess wrote: > Dear R People: > > When I plot using type="b", I have circles and lines, which is as it should > be. > > Is there a way to have filled in circles using the type argument, > please?  O

Re: [R] R Plots for Recurrent Events - Suggestions are needed

2010-12-12 Thread Michael Bedward
Hi Haoda, I couldn't find a package that implements this, although I'm not familiar with the field so there could be something but using different terminology. However, looking at the the Google preview of Nelson (2003) which is cited by the page that you linked to, the calculations seem very sim

Re: [R] Pure curiosity

2010-12-12 Thread Michael Bedward
Just to follow up on Robert's comment, If you do an ls() you'll see that you've created objects V1, V2 in your global environment. A very similar question was discussed last week (I think... it's all a blur) in the context of using "<-" instead of "=" with named function arguments. Michael On

Re: [R] help with RSQLite adding a new column

2010-12-11 Thread Michael Bedward
Hi Michael, Sorry if I'm being slow, but I've read your post three times and still can't quite work out what you're trying to do (the changing variables names are a bit confusing). I use RSQLite a lot and might be able to help if you could explain your inputs and desired output in simple terms.

Re: [R] subset with two factors

2010-12-10 Thread Michael Bedward
Hello Martin, You were almost there :) T1 <- subset(daten1, Geschlecht=="M" & GG=="A") Hope this helps. Michael On 10 December 2010 22:25, Martin Spindler wrote: > Dear all, > > I have a dataframe of the following strucutre > >  numacc_b coverage_b Geschlecht GG > 1        0          1      

Re: [R] Number of dimension in Multidimensional Scaling

2010-12-09 Thread Michael Bedward
Just to add to Michael F's comments: I've looked for that elbow many a time but never found it :) Admittedly, I typically deal with fairly noisy, ecological data, but I think it's a mistake to try to identify the "optimal" number of dimensions. Better instead to concentrate on a "useful" number, i

Re: [R] Time out for a R Function

2010-12-06 Thread Michael Bedward
Below is a toy function with one way of doing it. There are bound to be better ways :) function(niter = 10, time.out = 3) { pretend.task <- function() { Sys.sleep(0.5) } start <- proc.time() for (iter in 1:niter) { pretend.task() cur <- proc.time() - start if (c

Re: [R] How to specify a fixed intercept for linear model

2010-12-03 Thread Michael Bedward
The offset arg is your friend... x <- 1:10 y <- 42 + 2*x + rnorm(length(x), 0, 0.5) # we suspect the intercept might be 42 ! lm( y ~ 0 + x, offset=rep(42, length(x))) Michael On 4 December 2010 13:42, cborley87 wrote: > > Hi, > > Im fitting some simple linear models to data from the olympic r

Re: [R] testing and ploting t-distribution

2010-12-03 Thread Michael Bedward
Hello Bill, Have a look at the example at the bottom of the help page for ?qqplot Michael On 4 December 2010 11:19, <5...@queensu.ca> wrote: > Hi there, > > > I am doing a test to see the the residual is distributed in the form of > t-distribution and trying to plot the residuals and the t-di

Re: [R] Maximum Number of Rows in a Dataframe

2010-12-03 Thread Michael Bedward
Hello, Please post a sample of your code so people here can understand what you are trying to do. Michael On 4 December 2010 11:00, rushabhbm wrote: > > Guys, > I am new to R so please excuse if I am not very clear. > > My problem is: I have a 'for' loop in which I am defining a Dataframe df >

Re: [R] using ``<-'' in function argument

2010-12-03 Thread Michael Bedward
It's only obvious when someone points it out :) fubar is not created because, in the test x > 3 returned FALSE, which means the cat function doesn't get used, which means the y arg (fubar <- 6) is never required and therefore not evaluated. Evil isn't it ? Michael On 3 December 2010 20:18, Ivan

Re: [R] Querying a data frame or data.table

2010-12-03 Thread Michael Bedward
Sounds just like the subset function (?) x <- as.data.frame(matrix(sample(5, 100, rep=TRUE), ncol=10)) subset(x, V1 > 3 & V2 < 5) Michael On 3 December 2010 19:05, Santosh Srinivas wrote: > Hello Group, > > Is there an easy way to query a data.frame or data.table (this is > fast!) for multiple

Re: [R] Arrange elements on a matrix according to rowSums + short 'apply' Q

2010-12-02 Thread Michael Bedward
Hi Aaron, Following up on Ivan's suggestion, if you want the column order to mirror the row order... mo <- order(rowSums(MAT), decreasing=TRUE) MAT2 <- MAT[mo, mo] Also, you don't need all those extra c() calls when creating inputData, just the outermost one. Regarding your second question, you

Re: [R] missing values

2010-12-01 Thread Michael Bedward
And just to add to Ivan's comment, if you are using the rowSums or colSums functions with a matrix or data.frame they also have the na.rm argument. Michael On 1 December 2010 20:16, Ivan Calandra wrote: > Hi, > > (a) sum() and mean() have a na.rm argument that should be set to TRUE. > > (b) let'

Re: [R] Pass an operator to function

2010-11-30 Thread Michael Bedward
Here is one way... f <- function(a, b, op="==") {  call <- call(op, a, b)  result <- eval(call)  # possibly do other stuff  result } > f(1, 2) [1] FALSE > f(1, 2, "<") [1] TRUE Michael On 1 December 2010 13:54, randomcz wrote: > > Hi guys, > > How to pass an operator to a function. For examp

Re: [R] List of influential points?

2010-11-29 Thread Michael Bedward
Hi Bill, Have a look at the influence.measures function... my.lm <- lm( ... ) influence.measures( my.lm ) Hope this helps, Michael On 30 November 2010 00:13, Schwab,Wilhelm K wrote: > Hello all, > > I fit a linear model to some data and used plot() to create diagnostic plots > for the fit;

Re: [R] cross tabulate variables by subject id

2010-11-29 Thread Michael Bedward
Hi Marianne, How about this... ac.ad <- unstack(dat1, choice ~ cond1:cond2)[, c("A.C", "A.D")] acad.xtab <- with(ac.ad, table(A.C, A.D)) Michael On 29 November 2010 20:18, Marianne Promberger wrote: > Dear list, > > I have data like this: > > dat1 <- data.frame(subject=rep(1:10,2), >        

Re: [R] How do I subtract sequential values ?

2010-11-28 Thread Michael Bedward
On 29 November 2010 15:09, Joshua Wiley wrote: > (I hope I'm like wine and get better with age or) > Sigh, me too - but I suspect I'm heading more towards vinegar Michael __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r

Re: [R] weighted x variables with glm

2010-11-28 Thread Michael Bedward
Hello again Wendy, Actually, the simex package is probably a more useful suggestion... http://www.stat.uni-muenchen.de/~helmut/Texte/Simex_Rnews.pdf Michael On 29 November 2010 13:55, Michael Bedward wrote: >>> In case you haven't see it, the glm function accepts an option

Re: [R] weighted x variables with glm

2010-11-28 Thread Michael Bedward
>> In case you haven't see it, the glm function accepts an optional >> weights argument. >> > > Thanks for the reply. But the philosopy behind weighting is the assumption > of unequal variance in the y values. In normal regression one assumes that > the x values are known without error > > Wendy S

Re: [R] weighted x variables with glm

2010-11-28 Thread Michael Bedward
Hi Wendy, In case you haven't see it, the glm function accepts an optional weights argument. Michael On 29 November 2010 09:42, Wendy Anderson wrote: > I have a glm regression (quasi-poisson) of log(mu) on x but I have varying > degrees of confidence in the x values, and can attach a numerical

Re: [R] get list index

2010-11-25 Thread Michael Bedward
Hello Lorezo, Try this... order(sapply(mylist, min))[1] Michael On 26 November 2010 11:23, Lorenzo Cattarino wrote: > Hi R-users, > > > > I have a list > > > > mylist <- list(c(0.79, 0.92, 0.91, 0.86, 0.96, 0.96, 0.95, 0.94, 0.99), > c(0.28, 0.45, 0.59, 0.69, 0.80, 0.87, 0.95, 0.94, 0.98), c(

Re: [R] Print to the cmd line in a script

2010-11-24 Thread Michael Bedward
Is this what you want ? printCount <- function(N) { for (i in 1:N) { cat(i, "\n") } } Depending on your platform, output from the print function may not appear until after your function has finished. You can try using flush.console() to give it a nudge... printCount <- function(N) { fo

Re: [R] compare GLM coefficients

2010-11-22 Thread Michael Bedward
Hello Kayce, My (very basic) understanding is that you can't directly compare the coefficients across models that have different response variables, nor could you use AIC and similar metrics of model goodness of fit. Instead, I think you have to carefully define what you mean by "reveal similar po

Re: [R] Splitting 3D matrix from for loop to generate/save 2D matrices

2010-11-21 Thread Michael Bedward
Hi Hana, Use the paste function to create your file names. for ( i in 1:dim(M)[1] ) save( M[i,,], file=paste("M_", i, ".img", sep="") ) Alternatively, use the sprintf function to get names with leading zeroes for easier sorting of files: for (i in 1:dim(M)[1] ) save( M[i,,], file=sprintf("M_%03

Re: [R] R help

2010-11-21 Thread Michael Bedward
/1: http://cran.r-project.org/doc/Rnews/Rnews_2008-1.pdf Hope this helps. Michael On 22 November 2010 15:03, Ahmed Attia wrote: > Hi Dr Michael, > > Attached is an example for the linear plus plateua model but in SAS, this > exactly what I need to do in R. > > Ahmed > >

Re: [R] R help

2010-11-21 Thread Michael Bedward
Sorry, "chage-point" should be "change-point" On 22 November 2010 14:44, Michael Bedward wrote: > Hi Ahmed, > > Does 'quadratic plateau' model refer to a chage-point or bent-cable > regression with quadratic on one side and an asymptote on the othe

Re: [R] R help

2010-11-21 Thread Michael Bedward
Hi Ahmed, Does 'quadratic plateau' model refer to a chage-point or bent-cable regression with quadratic on one side and an asymptote on the other ? If so, you might like to look at the bentcableAR package. There is a background article here: http://faculty.washington.edu/gchiu/Articles/bentcable-

Re: [R] need smooth cdf lines

2010-11-21 Thread Michael Bedward
Ah, this looks like Australian data :) One simple way would be to use the lowess function and fiddle with the f parameter (like bandwidth). Michael On 22 November 2010 14:18, Roslina Zakaria wrote: > Hi, > > I would like to overlap the cdf curve for observed and generated data  Here is > my cod

Re: [R] (no subject)

2010-11-20 Thread Michael Bedward
On 20 November 2010 20:57, Stephen Liu wrote: > Hi Michael, > > Thanks for your advice. > > data() only displays a list of files.  Is there an easy to show the brief > summary of files rather than calling each file. What sort of summary do you want ? The data() command should display names and a

Re: [R] (no subject)

2010-11-20 Thread Michael Bedward
Type data() to list the numerous example data sets included with the standard R distribution. Michael On 20 November 2010 20:42, Stephen Liu wrote: > Hi folks, > > Please advise where can I down free data files for learning R?  Google search > brought me many, not easy for to screen.  TIA > > B.

Re: [R] How to catch warnings

2010-11-18 Thread Michael Bedward
e execution at the point it was and let your write commands in console > to check what was going on. > > Is that possible? > Regards > Alex > > --- On Thu, 11/18/10, Michael Bedward wrote: > > From: Michael Bedward > Subject: Re: [R] How to catch warnings > To: "

Re: [R] How to catch warnings

2010-11-18 Thread Michael Bedward
made things easier. One > more question what If I want to halt or pause the program when a warning > happens? Right now I get only a message printed but it would be nicer if the > execution is paused so to try to print more values. > > Best REgards > > Alex > > ---

Re: [R] How to catch warnings

2010-11-17 Thread Michael Bedward
Hi Alex, Something like this ? x <- 1:4 y <- list(good=2:5, bad=3:5) for (yy in y) { tryCatch( x <- cbind(x, yy), warning=function(w) cat("problem values: ", yy, "\n") ) } Michael On 18 November 2010 03:19, Alaios wrote: > Hello when my code executes I receive the message tha

Re: [R] Population abundance, change point

2010-11-16 Thread Michael Bedward
Hi Nick, I've used MCMC to fit change point regressions to a variety of ecological data and prefer this approach to strucchange and similar because I feel I have more control over the model, ie. I find it easier to tailor the form of the model to biological / demographic processes. I also find the

Re: [R] Partition of a set

2010-11-16 Thread Michael Bedward
t; If not, do not spend to much time, since I can solve the problem by > implementing list with all partitions of set {1,2} and {1}. (only two > partitions for {1,2} ...) > > Best wishes > Diana > > Am 12.11.2010 12:06, schrieb Michael Bedward: >> >> You're wel

Re: [R] simulate survival data using median survival time

2010-11-16 Thread Michael Bedward
Hi Kere, Step 1 is choose an appropriate distribution :) Do you have one in mind ? Or are you interested in examining the effects of survival times having the same mean but generated with alternative distributions ? One ready-rolled alternative is the SimSurv method in package prodlim. To find

Re: [R] Sampling problem

2010-11-16 Thread Michael Bedward
On 16 November 2010 16:10, wangwallace wrote: > > Michael, I really appreciate your help. > > but I got the following error message when I wan trying to run the function > written by you: > > Error in out[i, ] <- apply(help[, c(grp1 + 1, grp2 + 5)], 2, sample, 1) : >  number of items to replace is

Re: [R] Sampling problem

2010-11-15 Thread Michael Bedward
Hello, Is this what you want ? sampleX <- function(X, nGrp1, nsamples) # X is matrix or data.frame with cols for two groups of variables # with grp1 in cols 2:5 and grp2 in cols 6:9 # # nGrp1 <- number of variables to sample from group 1 # # nsamples <- number of rows in output matrix if (nGrp

Re: [R] How to set an argument such that a function treats it as missing?

2010-11-13 Thread Michael Bedward
("f", x) eval(fcall) } On 13 November 2010 20:24, Michael Bedward wrote: > Hello Marius, > > NULL is not the same as missing. You could something like this in > various ways. Here are a couple... > > g <- function(x) { >  if (missing(x)) { >    f() >  }

Re: [R] How to set an argument such that a function treats it as missing?

2010-11-13 Thread Michael Bedward
Hello Marius, NULL is not the same as missing. You could something like this in various ways. Here are a couple... g <- function(x) { if (missing(x)) { f() } else { f(x) } } or change f to detect null args g <- function(x) { if (missing(x)) { x <- NULL } f(x) } f <- fu

Re: [R] Vector

2010-11-12 Thread Michael Bedward
Fancy that... vector spam :) Michael On 12 November 2010 20:30, Jeff Musgrave wrote: > Now you and your Vector Team can make more money. > Offer your current client base a chance to buy and sell > a product in high demand.  An item that increases in value every day. > Are you ready for this no-i

Re: [R] Partition of a set

2010-11-12 Thread Michael Bedward
ere the first element contains the one-elemnt partion, the > second to fourth the three 2-element-partions and the fifth the 3-element > partition? > Do you know or is it my job to implement this by myself (o.k. but > time-consuming ..) > > Best wishes > Diana > > Am 12.11.201

Re: [R] Adding meta-data when creating objects. e.g: changing "<-" so to (for example) add "creation time" - how-to and pros/cons?

2010-11-12 Thread Michael Bedward
Hi Ivan, > I had already seen your solution (that does work). > If you're right about the issue in "my" function, then the error message is > confusing ('could not find the function "get<-" '). Moreover, I assign()ed > and get() "x" from the .GlobalEnv, so there shouldn't be a problem with > scopi

Re: [R] Partition of a set

2010-11-12 Thread Michael Bedward
Hi Diana, Have a look at the setparts function in the partitions package. Michael On 12 November 2010 20:03, Diana wrote: > > Hi > > I am new on this forum. I am searching for a function in R which provides > all partitions of a set, say for the set > {1,2,3} > you get > {{1,2,3}} > {1,{2,3}} >

Re: [R] Adding meta-data when creating objects. e.g: changing "<-" so to (for example) add "creation time" - how-to and pros/cons?

2010-11-11 Thread Michael Bedward
} > > assign2("y", 1:4) > Error in attr(get(x), "creation.time") <- Sys.time() : >  could not find function "get<-" > > Why doesn't it work? > If I remove the attr() part, > identical(y, get("y")) returns TRUE, so why attr() canno

Re: [R] create a pairwise coocurrence matrix

2010-11-11 Thread Michael Bedward
On 12 November 2010 02:21, David Winsemius wrote: > >> The fastest and easiest solution is >> >>  t(A) %*% A > > That is really elegant. (Wish I could remember my linear algebra lessons as > well from forty years ago.) I checked it against the specified output and > found that with one exception t

Re: [R] How to get a specific named element in a nested list

2010-11-11 Thread Michael Bedward
richt- >> Von: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] Im >> Auftrag von Michael Bedward >> Gesendet: Donnerstag, 11. November 2010 10:56 >> An: friedericksen.h...@gmail.com >> Cc: r-h...@stat.math.ethz.ch >> Betreff: Re: [R] How

Re: [R] Adding meta-data when creating objects. e.g: changing "<-" so to (for example) add "creation time" - how-to and pros/cons?

2010-11-11 Thread Michael Bedward
As a hack you could do this... assign("=", assign2) Michael On 11 November 2010 21:30, Barry Rowlingson wrote: > On Thu, Nov 11, 2010 at 9:37 AM, Tal Galili wrote: > >> 4) My real intention is to somehow change the "<-" operator (not simply the >> assign).  I am unsure as to how to do that. >

Re: [R] Adding meta-data when creating objects. e.g: changing "<-" so to (for example) add "creation time" - how-to and pros/cons?

2010-11-11 Thread Michael Bedward
Hi Tal, Here's a way of doing the first bit... assign2 <- function(x, ...) { xname <- deparse(substitute(x)) assign(xname, ...) x <- get(xname) attr(x, "creation.time") <- Sys.time() assign(xname, x, pos=.GlobalEnv) } Michael On 11 November 2010 20:37, Tal Galili wrote: > My objecti

Re: [R] Populating then sorting a matrix and/or data.frame

2010-11-11 Thread Michael Bedward
uentially as I iterate through > the data, how would you recommend it?? > > Thanks, > > -N > > On 11/11/10 12:03 AM, Michael Bedward wrote: >> >> All values in a matrix are the same type, so if you've set up a matrix >> with a character column then your nume

Re: [R] How to get a specific named element in a nested list

2010-11-11 Thread Michael Bedward
Hi Friedericksen, This function will do it. No doubt there are more elegant ways :) rmatch <- function(x, name) { pos <- match(name, names(x)) if (!is.na(pos)) return(x[[pos]]) for (el in x) { if (class(el) == "list") { out <- getEl(el, name) if (!is.null(out)) return(o

Re: [R] Populating then sorting a matrix and/or data.frame

2010-11-11 Thread Michael Bedward
factors. > > -N > > On 11/10/10 11:16 PM, Michael Bedward wrote: >> >> Hello Noah, >> >> If you set these names... >>> >>> names(results)<- c("one", "two", "three") >> >> this won't work... >>&g

Re: [R] Populating then sorting a matrix and/or data.frame

2010-11-10 Thread Michael Bedward
Hello Noah, If you set these names... > names(results) <- c("one", "two", "three") this won't work... > results[results$c < 100,] because you don't have a column called "c" (unless that's just a typo in your post). > I tried making it a data.frame with > foo <- data.frame(results) > > But that

Re: [R] Difficult doubt about choose distances randomly in a matrix with a probability of event

2010-11-10 Thread Michael Bedward
Hello Judit, The code below is a toy simulation function that takes as arguments a matrix representing the initial population, a dispersal kernel, global survival probability and max number of iterations to run. It doesn't implement exactly what you described in your post but if you study the cod

Re: [R] Simple Function

2010-11-09 Thread Michael Bedward
If you want to assign to a variable in your workspace, rather than a local variable in your function, you can use the <<- operator (double headed arrow) like this... mat <- function(i) { for (k in i:10) { y[k] <<- k+1 f[k] <<- y[k-1] / 2 } } Type ?"<<-" for the help page. Michael O

Re: [R] jags error message

2010-11-09 Thread Michael Bedward
Hi James, The following is probably more an expression of empathy than direct help :) I've used rjags quite a bit but have often found it to be very picky about the formulation of the model. Scripts that run without problem under WinBUGS (for instance) provoke errors with jags and more often than

Re: [R] arrays of arrays

2010-11-09 Thread Michael Bedward
Hi Sachin, That's OK - you don't need to know the dimensions up front and you can add new vectors, or elements to an existing vector, as required. # empty list to start with X <- list() # we get a vector v1 <- c(1, 2, 3, 4, 5) # add it to the ragged array X <- c(X, list(v1)) # get another coup

Re: [R] concatenating a string to a column

2010-11-09 Thread Michael Bedward
You want the paste command (cat is for printing to the console)... A$period <- paste(A$period, 0, sep="") Michael On 10 November 2010 16:09, wrote: > > Hi All, > > Suppose I want to concatenate a zero to all the values to a column called > period in data frame A. I want to do the following bu

Re: [R] arrays of arrays

2010-11-09 Thread Michael Bedward
Hello Sachin, You have a "ragged array" and you can easily store this as a list of vectors... x <- list(c(0,0,1,1), c(1,3,5), 4, c(7, -1, 8, 9, 10, 6)) The only gotcha with this is that you will then need to use double brackets for the first index when retrieving values (single brackets will ret

Re: [R] Question related to combination and the corresponding probability

2010-11-08 Thread Michael Bedward
Don't know if this is "efficient" but I think it works... yn <- c("Y", "N") X <- expand.grid(x1=yn, x2=yn, x3=yn, x4=yn) Yp <- c(0.6, 0.5, 0.8, 0.9) X$prob <- apply(X, 1, function(x) cumprod(ifelse(x == "Y", Yp, 1-Yp))[length(x)]) Michael On 9 November 2010 17:05, Kate Hsu wrote: > Dear r user

Re: [R] : unusual combinations of categorical data

2010-11-08 Thread Michael Bedward
Perhaps just use the ftable function to generate a flat contingency table and look for counts below some threshold. Michael On 9 November 2010 09:25, Alan Chalk wrote: > Regarding unusual combinations of factors in categorical data. > Are there any R packages that can be used to identify the ou

Re: [R] conditional probability

2010-11-08 Thread Michael Bedward
Hello Jumlong, For Normal distribution see the help page for pnorm. For dealing with unknown (empirical) distributions, look at ecdf. Hope this helps Michael On 8 November 2010 16:29, Jumlong Vongprasert wrote: > Dear all >          I have problem with calculate probability, I have data x1,...

Re: [R] (no subject)

2010-11-05 Thread Michael Bedward
Hello, One approach would be to fit your distribution using MCMC with, for example, the rjags package. Then you can use the "zeroes trick" or "ones trick" to implement your new distribution as described here... http://mathstat.helsinki.fi/openbugs/data/Docu/Tricks.html You will find a summary of

Re: [R] Closing unreferenced result sets in dbi / RSQLite

2010-11-04 Thread Michael Bedward
Hi Andreas, Try this... # forget to assign result set dbSendQuery(con, "select * from df") # retrieve the result set just created rs <- dbListResults(con)[[1]] Then you can do dbClearResult or whatever. Michael On 4 November 2010 19:56, Andreas Borg wrote: > Hello R-help members, > > I have

Re: [R] Bayesian constrained regression method?

2010-10-24 Thread Michael Bedward
rained in (0,1). > > OK so some addition info. I know each of the X2 is in (0,1). Is there any > method available? > Jim > > On Sat, Oct 23, 2010 at 8:31 AM, Michael Bedward > wrote: >> >> Hi Jim, >> >> You don't mention whether you have any prior

Re: [R] Bayesian constrained regression method?

2010-10-23 Thread Michael Bedward
Hi Jim, You don't mention whether you have any prior information regarding X2 that can be used to constrain values imputed for it. I think you will need some because without it values sampled for b and X2 respectively will just "see-saw" against each other. Michael On 22 October 2010 18:37, Jim

Re: [R] Two-Way Joining or Clustering

2010-10-21 Thread Michael Bedward
Hi Muhammad, Have a look at the biclust package... http://cran.r-project.org/web/packages/biclust/index.html Michael On 21 October 2010 18:00, Muhammad Yaseen wrote: > *Hi Folks,* > * > * > *I want to do two-way joining or clustering as described in STATISTICA > website *http://www.statsoft.com

Re: [R] Clustering with ordinal data

2010-10-19 Thread Michael Bedward
Hello Steve, > I've been asked to help evaluate a vegetation data set, specifically to > examine it for community similarity. The initial problem I see is that the > data is ordinal.   At best this only captures a relative ranking of > abundance and ordinal ranks are assigned after data collection

Re: [R] Random assignment

2010-10-15 Thread Michael Bedward
nally posted as your objective (?) Michael On 15 October 2010 22:49, Michael Bedward wrote: > Hi John, > > The word "species" attracted my attention :) > > Like Dennis, I'm not sure I understand your idea properly. In > particular, I don't see what you ne

Re: [R] Random assignment

2010-10-15 Thread Michael Bedward
ilies it will be the same as doing the > simulation experiment outline in the method above? > > Thanks > > John > > > > > On 15 Oct 2010, at 12:49, Michael Bedward wrote: > > Hi John, > > The word "species" attracted my attention :) > > Like Den

Re: [R] Random assignment

2010-10-15 Thread Michael Bedward
Hi John, The word "species" attracted my attention :) Like Dennis, I'm not sure I understand your idea properly. In particular, I don't see what you need the simulation for. If family F has Fn species, your random expectation is that p * Fn of them will be at risk (p = 0.0748). The variance on t

Re: [R] compare histograms

2010-10-14 Thread Michael Bedward
stalled I look forward to trying it out shortly. Thanks again. Michael On 15 October 2010 03:17, Rainer M Krug wrote: > > > On Thu, Oct 14, 2010 at 3:15 AM, Michael Bedward > wrote: >> >> Hi Juan, >> >> Yes, you can use EMD to quantify the difference bet

Re: [R] spatial partition

2010-10-14 Thread Michael Bedward
Some quick ideas... One very easy way would be to round them all to integer degrees and remove the duplicates - or even just let the duplicates overwrite each other in the plot. A step up from that would be to create a matrix at some resolution (e.g. 180 x 360 for a 1 degree global grid) and coun

Re: [R] (no subject)

2010-10-14 Thread Michael Bedward
Hello Julia, I'm afraid your code had multiple problems: variables declared but not used, incorrect or unnecessary use of the "c" function, out-of-bounds subscripts and overwriting of result objects. Rather than point them all out in detail I've modified your code so that it works (see below). Pl

Re: [R] compare histograms

2010-10-13 Thread Michael Bedward
; Juan > > > On Wed, Oct 13, 2010 at 4:39 AM, Michael Bedward > wrote: >> >> Just to add to Greg's comments: I've previously used 'Earth Movers >> Distance' to compare histograms. Note, this is a distance metric >> rather than a parametric

Re: [R] compare histograms

2010-10-13 Thread Michael Bedward
is available: > > http://r.789695.n4.nabble.com/Measure-Difference-Between-Two-Distributions-td2712281.html#a2713505 > > HTH, > Dennis > > On Tue, Oct 12, 2010 at 7:39 PM, Michael Bedward > wrote: >> >> Just to add to Greg's comments: I've previous

Re: [R] vertical kites in KiteChart (plotrix)

2010-10-13 Thread Michael Bedward
Super ! An option for vertical plotting would be very nice. Michael On 13 October 2010 22:19, Jim Lemon wrote: > On 10/13/2010 07:11 PM, elpape wrote: >> >> Dear everyone, >> >> I would like to create a kite chart in which I plot densities (width of >> the >> vertical kites) in relation to sedi

  1   2   3   >