[R] Takagi-Sugeno fuzzy model
Dear R-help. I am learning fuzzy algorithm, at this moment about Takagi-Sugeno fuzzy model. I have been searching on mailing list r-help about this, but I didn't find any list about Takagi-Sugeno fuzzy model. I want to know, are there any R code (or library/package) for Takagi-Sugeno fuzzy model. Thanks for your help. Best wishes, Muhammad Subianto [[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] fitting a lognormal distribution using cumulative probabilities
Dear Prof Ripley and Dimitris (cc R-list), thank you very much for your very insightful responses. I've been checking how to use survreg{survival} to fit a left-censored lognormal distribution, and I was surprised to find that results are exactly the same as with fitdistr{MASS}. Here is an example with a larger dataset: # # data: data1 - data.frame(obs.time=c(30,31.98,35.95,37.2,46.4,50.5,54,56,60,62.95, 69.4,71.5,74,76,78,79.25,81.1,84.68,90,95.37,100), reps=c(5,47,80,18,20,32,29,8,29,2,7,8,1,4,3,2,3,3,1,2,1)) data2 - with(data1, data.frame(obs.time=rep(obs.time, reps), event=rep(1,sum(data1$reps # 1. using fitdistr to estimate lognormal parameters library(MASS) fit1 - fitdistr(data2$obs.time, lognormal); fit1 # meanlog sdlog # 3.80552970 0.29093294 # (0.01665877) (0.01177953) # 2. using survreg for left-censored estimation library(survival) fm - survreg(Surv(obs.time,event,type=left)~1, data=data2, dist=lognormal); summary(fm) fm$coefficients[[1]]; fm$scale # [1] 3.80553 # [1] 0.2909329 # results are the identical !! # plotting ecdf and the fitted curve = # parameters fit1.mean - fit1$estimate[[1]] fit1.sd - fit1$estimate[[2]] plot(ecdf(data2$obs.time), verticals=TRUE, do.p=FALSE, lwd=1.5, xlim=c(0,116), ylab=pb, xlab=time) curve(plnorm(x, meanlog=fit1.mean, sdlog=fit1.sd), add=TRUE, col='red', lwd=3) # the fit looks good to me #= end script = I guess this relates to the following sentences from Prof Ripley: ML fitting can be done for censored data. However, I don't think you have a valid description here: it seems you never recorded a time at which the event had not happened, and the most likely fit is a probability mass at zero (since this is a perfect explanation for your data). (which I don't fully understand) and If you have an ECDF, the jumps give you the data so you can just use fitdistr(). I have the ECDF and the number of observations is ~150-300. My final understanding is therefore that fitdistr can be used to fit distributions by ML over left-censored data, which is equivalent to fit the distribution using cumulative probabilities (to go back to my original terminology). Is this understanding correct? I would highly appreciate any feedback, especially if I am misunderstanding the way to estimate the function parameters for this type of data. Thank you very much! Ahimsa On Sat, Feb 23, 2008 at 2:35 AM, Prof Brian Ripley [EMAIL PROTECTED] wrote: On Sat, 23 Feb 2008, ahimsa campos-arceiz wrote: Dear all, I'm trying to estimate the parameters of a lognormal distribution fitted from some data. The tricky thing is that my data represent the time at which I recorded certain events. However, in many cases I don't really know when the event happened. I' only know the time at which I recorded it as already happened. So this is a rather extreme form of censoring. Therefore I want to fit the lognormal from the cumulative distribution function (cdf) rather than from the probability distribution function (pdf). My understanding is that methods based on Maximum Likelihood (e.g. fitdistr {MASS}) are based on the pdf. Nonlinear least-squares methods seem to be based on the cdf... however I was unable to use nls{stat} for lognormal. Not so: ML fitting can be done for censored data. However, I don't think you have a valid description here: it seems you never recorded a time at which the event had not happened, and the most likely fit is a probability mass at zero (since this is a perfect explanation for your data). To make any progress with censoring, you need to see both positive and negative events. If you told us that none of these events happened before t=15, it would be possible to fit the model (although you would need far more data to get a good fit). Generally code to handle censoring is in survival analysis: e.g. survreg() in package survival. In the terminiology of the latter, all your observations are left-censored. I found a website that explains how to fit univariate distribution functions based on cumulative probabilities, including a lognormal example, in Matlab: http://www.mathworks.com/products/statistics/demos.html?file=/products/demos/shipping/stats/cdffitdemo.html and other programs like TableCurve 2D seem to do this too. Maybe, but that is a different problem. If you have an ECDF, the jumps give you the data so you can just use fitdistr(). (And you will see comparing observed and fitted CDFs in MASS, the book.) There must be a straightforward method in R which I have overlooked. Any suggestion on how can I estimate these parameters in R or helpful references are very much appreciated. (not sure if it helps but) here is an example of my type of data: treat.1 - c(21.67, 21.67, 43.38, 35.50, 32.08, 32.08, 21.67, 21.67,
Re: [R] fitting a lognormal distribution using cumulative probabilities
Your example code is asserting that the events occurred at the times in 'obs.time', not before those times. Surv(event = 1) means uncensored. If you try event = 0, the fitter diverges towards an exact fit, as I said it should. Yes, you will get a good fit to the ECDF, but you are modelling the observation times, not the event times (and asserting that a continuous distribution fits discrete data). I suggest you seek local statistical help: these are conceptual rather than R issues. (BTW, using a .com address suggests you are a COMpany and in the absence of a signature block that will influence how much free help you are offered.) On Sat, 23 Feb 2008, ahimsa campos-arceiz wrote: Dear Prof Ripley and Dimitris (cc R-list), thank you very much for your very insightful responses. I've been checking how to use survreg{survival} to fit a left-censored lognormal distribution, and I was surprised to find that results are exactly the same as with fitdistr{MASS}. Here is an example with a larger dataset: # # data: data1 - data.frame(obs.time=c(30,31.98,35.95,37.2,46.4,50.5,54,56,60,62.95, 69.4,71.5,74,76,78,79.25,81.1,84.68,90,95.37,100), reps=c(5,47,80,18,20,32,29,8,29,2,7,8,1,4,3,2,3,3,1,2,1)) data2 - with(data1, data.frame(obs.time=rep(obs.time, reps), event=rep(1,sum(data1$reps # 1. using fitdistr to estimate lognormal parameters library(MASS) fit1 - fitdistr(data2$obs.time, lognormal); fit1 # meanlog sdlog # 3.80552970 0.29093294 # (0.01665877) (0.01177953) # 2. using survreg for left-censored estimation library(survival) fm - survreg(Surv(obs.time,event,type=left)~1, data=data2, dist=lognormal); summary(fm) fm$coefficients[[1]]; fm$scale # [1] 3.80553 # [1] 0.2909329 # results are the identical !! # plotting ecdf and the fitted curve = # parameters fit1.mean - fit1$estimate[[1]] fit1.sd - fit1$estimate[[2]] plot(ecdf(data2$obs.time), verticals=TRUE, do.p=FALSE, lwd=1.5, xlim=c(0,116), ylab=pb, xlab=time) curve(plnorm(x, meanlog=fit1.mean, sdlog=fit1.sd), add=TRUE, col='red', lwd=3) # the fit looks good to me #= end script = I guess this relates to the following sentences from Prof Ripley: ML fitting can be done for censored data. However, I don't think you have a valid description here: it seems you never recorded a time at which the event had not happened, and the most likely fit is a probability mass at zero (since this is a perfect explanation for your data). (which I don't fully understand) and If you have an ECDF, the jumps give you the data so you can just use fitdistr(). I have the ECDF and the number of observations is ~150-300. My final understanding is therefore that fitdistr can be used to fit distributions by ML over left-censored data, which is equivalent to fit the distribution using cumulative probabilities (to go back to my original terminology). Is this understanding correct? I would highly appreciate any feedback, especially if I am misunderstanding the way to estimate the function parameters for this type of data. Thank you very much! Ahimsa On Sat, Feb 23, 2008 at 2:35 AM, Prof Brian Ripley [EMAIL PROTECTED] wrote: On Sat, 23 Feb 2008, ahimsa campos-arceiz wrote: Dear all, I'm trying to estimate the parameters of a lognormal distribution fitted from some data. The tricky thing is that my data represent the time at which I recorded certain events. However, in many cases I don't really know when the event happened. I' only know the time at which I recorded it as already happened. So this is a rather extreme form of censoring. Therefore I want to fit the lognormal from the cumulative distribution function (cdf) rather than from the probability distribution function (pdf). My understanding is that methods based on Maximum Likelihood (e.g. fitdistr {MASS}) are based on the pdf. Nonlinear least-squares methods seem to be based on the cdf... however I was unable to use nls{stat} for lognormal. Not so: ML fitting can be done for censored data. However, I don't think you have a valid description here: it seems you never recorded a time at which the event had not happened, and the most likely fit is a probability mass at zero (since this is a perfect explanation for your data). To make any progress with censoring, you need to see both positive and negative events. If you told us that none of these events happened before t=15, it would be possible to fit the model (although you would need far more data to get a good fit). Generally code to handle censoring is in survival analysis: e.g. survreg() in package survival. In the terminiology of the latter, all your observations are left-censored. I found a website that explains how to fit univariate distribution functions based on cumulative probabilities, including a
[R] Newbie: Measuring distance between clusters.
Hi, I had 1 genes, and I clustered them using K-means clustering in R. kc-kmeans(data.sub,7) kc n cluster sum of squares by cluster: [1] 60631.76 135886.19 159049.71 101783.27 90040.72 183335.60 158867.81 Available components: [1] cluster centers withinss size I am very new to R. How do i measure the distance between those cluster? I tried I am trying to do a complete linkage z-hclust(kc,method=complete) Error in if (n 2) stop(must have n = 2 objects to cluster) : argument is of length zero thanks. -- View this message in context: http://www.nabble.com/Newbie%3A-Measuring-distance-between-clusters.-tp15650066p15650066.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] fitting a lognormal distribution using cumulative probabilities
Dear Professor Ripley, thanks again for your mail and useful comments. Surv(event = 1) means uncensored. If you try event = 0, the fitter diverges towards an exact fit, as I said it should. Sorry, I misunderstood this. (BTW, using a .com address suggests you are a COMpany and in the absence of a signature block that will influence how much free help you are offered.) Thank you very much for this comment. I'd never thought this way. (I'm not a company, btw) My best regards, Ahimsa -- ahimsa campos-arceiz PhD candidate Lab of Biodiversity Science The University of Tokyo www.camposarceiz.com [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Hiding a function
Hi the list Is it possible to 'hide' a function from the user ? I cut a big fonction in sub function and I would like to hide the sub function, just like if I declare them in the big function : -- a - function(x){ b - function(y){y^2} d - function(y){y^3} b(x)+d(x)+2 } a(2) # [1] 14 b(2) # Error : I would like the same, but with external declaration (for readability) : b - function(y){y^2} d - function(y){y^3} a - function(x){ b(x)+d(x)+2 } a(2) # [1] 14 b(2) # Error Is it possible ? Thanks Christophe __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] addtable2plot(plotrix)
Markus Didion wrote: Dear List adding a table to a plot using addtable2plot(plotrix) does not seem to work when using a logarithmic axis. The table is then reduced to one line. Is there an argument to indicate that a log-scale is used, or an alternative to add a bunch of information to a plot? I'm using R 2.6.1 on WinXP SP2. Hi Markus, Thanks for pointing that out - logarithmic axes had slipped under my radar (as the open source developer said to the actress). I'll got onto it. Jim __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Hiding a function
On 23/02/2008 5:15 AM, Christophe Genolini wrote: Hi the list Is it possible to 'hide' a function from the user ? I cut a big fonction in sub function and I would like to hide the sub function, just like if I declare them in the big function : -- a - function(x){ b - function(y){y^2} d - function(y){y^3} b(x)+d(x)+2 } a(2) # [1] 14 b(2) # Error : I would like the same, but with external declaration (for readability) : b - function(y){y^2} d - function(y){y^3} a - function(x){ b(x)+d(x)+2 } a(2) # [1] 14 b(2) # Error Is it possible ? Yes, as long as you're using a package with a NAMESPACE, just don't export b and d. There are other ways too, but they don't improve readability. Duncan Murdoch __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Hiding a function
Duncan Murdoch a écrit : On 23/02/2008 5:15 AM, Christophe Genolini wrote: Hi the list Is it possible to 'hide' a function from the user ? I cut a big fonction in sub function and I would like to hide the sub function, just like if I declare them in the big function : -- a - function(x){ b - function(y){y^2} d - function(y){y^3} b(x)+d(x)+2 } a(2) # [1] 14 b(2) # Error : I would like the same, but with external declaration (for readability) : b - function(y){y^2} d - function(y){y^3} a - function(x){ b(x)+d(x)+2 } a(2) # [1] 14 b(2) # Error Is it possible ? Yes, as long as you're using a package with a NAMESPACE, just don't export b and d. There are other ways too, but they don't improve readability. Duncan Murdoch If I understand, it is possible only in a package, not in a programme (unless the other ways), is that it ? Ok, thanks. Christophe __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Set without argument
Hi the list, I am defining S4 objet. Is it possbile to define a method that change the slot of an object without using - ? My object contain a numeric and a matrix. At some point, I would like to impute the missing value in the matrix. So I would like to use something like : - setClass(MyObj,representation(time=numeric,traj=matrix)) a - new(MyObj,time=3,traj=matrix(c(1:6,NA,8:12),ncol=3)) imputeMyObj(a) - I find 'setTime-' to change le slot time, but it can not work in the case of imputeMyObs since this mehod does not need a value... Any solution ? Thanks Christophe __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Hiding a function
On 23/02/2008 5:58 AM, Christophe Genolini wrote: Duncan Murdoch a écrit : On 23/02/2008 5:15 AM, Christophe Genolini wrote: Hi the list Is it possible to 'hide' a function from the user ? I cut a big fonction in sub function and I would like to hide the sub function, just like if I declare them in the big function : -- a - function(x){ b - function(y){y^2} d - function(y){y^3} b(x)+d(x)+2 } a(2) # [1] 14 b(2) # Error : I would like the same, but with external declaration (for readability) : b - function(y){y^2} d - function(y){y^3} a - function(x){ b(x)+d(x)+2 } a(2) # [1] 14 b(2) # Error Is it possible ? Yes, as long as you're using a package with a NAMESPACE, just don't export b and d. There are other ways too, but they don't improve readability. Duncan Murdoch If I understand, it is possible only in a package, not in a programme (unless the other ways), is that it ? Yes, that's right. Here's one of the other ways: a - local( { b - function(y){y^2} d - function(y){y^3} function(x){ b(x)+d(x)+2 } }) I don't find that more readable than if b and d had been defined locally within a. Duncan Murdoch __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] using subset() in data frame
On 2/22/2008 8:01 PM, Robert Walters wrote: R folks, As an R novice, I struggle with the mystery of subsetting. Textbook and online examples of this seem quite straightforward yet I cannot get my mind around it. For practice, I'm using the code in MASS Ch. 6, whiteside data to analyze a different data set with similar variables and structure. Here is my data frame: ###subset one of three cases for the variable 'position' data.b-data.a[data.a$position==inrow,] print(data.b) position porosityx y 1 inrow macro 1.40 16.5 2 inrow macro . . . .. . . . . . 7 inrow micro 8 inrow micro Now I want to do separate lm's for each case of porosity, macro and micro. The code as given in MASS, p.141, slightly modified would be: fit1 - lm(y ~ x, data=data.b, subset = porosity == macro) fit2 - update(fit1, subset = porosity == micro) ###simplest code with subscripting fit1 - lm(y ~ x, data.b[porosity==macro]) Assuming data.b has two dimensions, you need a comma after porosity==macro to indicate that you are selecting a subset of rows of the data frame: fit1 - lm(y ~ x, data.b[porosity==macro,]) ###following example in ?subset fit1 - lm(y ~ x, data.b, subset(data.b, porosity, select=macro)) The select argument to subset is meant to select variables (i.e., it indicates columns to select from a data frame) and you are misusing it by specifying the level of a factor. If you make your call to subset by itself (a good idea when you are learning how a function works), you should get an error like this: subset(whiteside, Insul, select=Before) Error in subset.data.frame(whiteside, Insul, select = Before) : 'subset' must evaluate to logical What I think you intended was this: subset(data.b, porosity == macro) Even with the correct call to subset, you also don't want both data.b and the subset piece, because subset returns a data frame. In other words, you would be passing lm() two different data frames. So try this instead: fit1 - lm(y ~ x, subset(data.b, porosity == macro)) None of th above, plus many permutations thereof, works. Can anyone educate me? Thanks, Robert Walters __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Chuck Cleland, Ph.D. NDRI, Inc. 71 West 23rd Street, 8th floor New York, NY 10010 tel: (212) 845-4495 (Tu, Th) tel: (732) 512-0171 (M, W, F) fax: (917) 438-0894 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Hiding a function
It depends what you mean by 'hiding', you can start the function names with a dot and then they are not listed by ls(), so this is kind of hiding. .a - function() TRUE ls() character(0) .a function() TRUE Personally i would not do this though. G. On Sat, Feb 23, 2008 at 11:58:57AM +0100, Christophe Genolini wrote: [...] If I understand, it is possible only in a package, not in a programme (unless the other ways), is that it ? Ok, thanks. [...] -- Csardi Gabor [EMAIL PROTECTED]UNIL DGM __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] using subset() in data frame
On 2/23/2008 6:09 AM, Chuck Cleland wrote: On 2/22/2008 8:01 PM, Robert Walters wrote: R folks, As an R novice, I struggle with the mystery of subsetting. Textbook and online examples of this seem quite straightforward yet I cannot get my mind around it. For practice, I'm using the code in MASS Ch. 6, whiteside data to analyze a different data set with similar variables and structure. Here is my data frame: ###subset one of three cases for the variable 'position' data.b-data.a[data.a$position==inrow,] print(data.b) position porosityx y 1 inrow macro 1.40 16.5 2 inrow macro . . . .. . . .. . 7 inrow micro 8 inrow micro Now I want to do separate lm's for each case of porosity, macro and micro. The code as given in MASS, p.141, slightly modified would be: fit1 - lm(y ~ x, data=data.b, subset = porosity == macro) fit2 - update(fit1, subset = porosity == micro) ###simplest code with subscripting fit1 - lm(y ~ x, data.b[porosity==macro]) Assuming data.b has two dimensions, you need a comma after porosity==macro to indicate that you are selecting a subset of rows of the data frame: fit1 - lm(y ~ x, data.b[porosity==macro,]) Actually, that should be: fit1 - lm(y ~ x, data.b[data.b$porosity==macro,]) because [.data.frame needs to know where to find porosity, and it won't know to look inside of data.b unless you direct it to look there. ###following example in ?subset fit1 - lm(y ~ x, data.b, subset(data.b, porosity, select=macro)) The select argument to subset is meant to select variables (i.e., it indicates columns to select from a data frame) and you are misusing it by specifying the level of a factor. If you make your call to subset by itself (a good idea when you are learning how a function works), you should get an error like this: subset(whiteside, Insul, select=Before) Error in subset.data.frame(whiteside, Insul, select = Before) : 'subset' must evaluate to logical What I think you intended was this: subset(data.b, porosity == macro) Even with the correct call to subset, you also don't want both data.b and the subset piece, because subset returns a data frame. In other words, you would be passing lm() two different data frames. So try this instead: fit1 - lm(y ~ x, subset(data.b, porosity == macro)) None of th above, plus many permutations thereof, works. Can anyone educate me? Thanks, Robert Walters __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Chuck Cleland, Ph.D. NDRI, Inc. 71 West 23rd Street, 8th floor New York, NY 10010 tel: (212) 845-4495 (Tu, Th) tel: (732) 512-0171 (M, W, F) fax: (917) 438-0894 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Hiding a function
Gabor Csardi a écrit : It depends what you mean by 'hiding', Well, the main idea was the to limit the existance of a function. a( ) need b( ) but no other function will need b(). So I would have like to let b( ) exists localy only when a( ) is called, not elsewhere. Christophe you can start the function names with a dot and then they are not listed by ls(), so this is kind of hiding. .a - function() TRUE ls() character(0) .a function() TRUE Personally i would not do this though. G. On Sat, Feb 23, 2008 at 11:58:57AM +0100, Christophe Genolini wrote: [...] If I understand, it is possible only in a package, not in a programme (unless the other ways), is that it ? Ok, thanks. [...] [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Hiding a function
Just to clarify, what Duncan was referring to as the alternative was nesting the definition of one function in another, e.g. look at FUNx in by.data.frame -- FUNx is available to by.data.frame but is not visible outside of by.data.frame . On Sat, Feb 23, 2008 at 6:09 AM, Duncan Murdoch [EMAIL PROTECTED] wrote: On 23/02/2008 5:58 AM, Christophe Genolini wrote: Duncan Murdoch a écrit : On 23/02/2008 5:15 AM, Christophe Genolini wrote: Hi the list Is it possible to 'hide' a function from the user ? I cut a big fonction in sub function and I would like to hide the sub function, just like if I declare them in the big function : -- a - function(x){ b - function(y){y^2} d - function(y){y^3} b(x)+d(x)+2 } a(2) # [1] 14 b(2) # Error : I would like the same, but with external declaration (for readability) : b - function(y){y^2} d - function(y){y^3} a - function(x){ b(x)+d(x)+2 } a(2) # [1] 14 b(2) # Error Is it possible ? Yes, as long as you're using a package with a NAMESPACE, just don't export b and d. There are other ways too, but they don't improve readability. Duncan Murdoch If I understand, it is possible only in a package, not in a programme (unless the other ways), is that it ? Yes, that's right. Here's one of the other ways: a - local( { b - function(y){y^2} d - function(y){y^3} function(x){ b(x)+d(x)+2 } }) I don't find that more readable than if b and d had been defined locally within a. 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-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Set without argument
Christophe Genolini [EMAIL PROTECTED] writes: Hi the list, I am defining S4 objet. Is it possbile to define a method that change the slot of an object without using - ? My object contain a numeric and a matrix. At some point, I would like to impute the missing value in the matrix. So I would like to use something like : - setClass(MyObj,representation(time=numeric,traj=matrix)) a - new(MyObj,time=3,traj=matrix(c(1:6,NA,8:12),ncol=3)) imputeMyObj(a) - Hi Christophe -- The 'usual' way to write the above code is a - imputeMyObj(a) with imputeMyObj designed to take a 'MyObj' as it's argument, and return a modified 'MyObj' (that the user can assign to 'a', if they like). Inside imputeMyObj, the developer would, in the end, write something like impuateMyObj - function(obj) { # calculate imputed values 'imp' slot(obj, traj) - imp obj } A better design would have a 'setter' method, minimally setGeneric(traj-, +function(object, ..., value) standardGeneric(traj-)) [1] traj- setReplaceMethod(traj, + signature=signature( +object=MyObj, +value=matrix), + function(object, ..., value) { + slot(object, traj) - value + object + }) [1] traj- and then the impute code would have impuateMyObj - function(obj) { # calculate imputed values 'imp' traj(obj) - imp obj } It's possible to design 'MyObj' so that it can be modified in-place (e.g., storing data in a slot of class 'environment', which has reference-like behavior) but this will probably surprise both you and the user. Martin I find 'setTime-' to change le slot time, but it can not work in the case of imputeMyObs since this mehod does not need a value... Any solution ? Thanks Christophe __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Martin Morgan Computational Biology / Fred Hutchinson Cancer Research Center 1100 Fairview Ave. N. PO Box 19024 Seattle, WA 98109 Location: Arnold Building M2 B169 Phone: (206) 667-2793 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Hiding a function
Ok, I saw FUNx So, I reformulate my question : is there a way, without nesting b( ) in a( ), to make b( ) available only in a( ) ? Just to clarify, what Duncan was referring to as the alternative was nesting the definition of one function in another, e.g. look at FUNx in by.data.frame -- FUNx is available to by.data.frame but is not visible outside of by.data.frame . On Sat, Feb 23, 2008 at 6:09 AM, Duncan Murdoch [EMAIL PROTECTED] wrote: On 23/02/2008 5:58 AM, Christophe Genolini wrote: Duncan Murdoch a écrit : On 23/02/2008 5:15 AM, Christophe Genolini wrote: Hi the list Is it possible to 'hide' a function from the user ? I cut a big fonction in sub function and I would like to hide the sub function, just like if I declare them in the big function : -- a - function(x){ b - function(y){y^2} d - function(y){y^3} b(x)+d(x)+2 } a(2) # [1] 14 b(2) # Error : I would like the same, but with external declaration (for readability) : b - function(y){y^2} d - function(y){y^3} a - function(x){ b(x)+d(x)+2 } a(2) # [1] 14 b(2) # Error Is it possible ? Yes, as long as you're using a package with a NAMESPACE, just don't export b and d. There are other ways too, but they don't improve readability. Duncan Murdoch If I understand, it is possible only in a package, not in a programme (unless the other ways), is that it ? Yes, that's right. Here's one of the other ways: a - local( { b - function(y){y^2} d - function(y){y^3} function(x){ b(x)+d(x)+2 } }) I don't find that more readable than if b and d had been defined locally within a. 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. [[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] using subset() in data frame
Erin Hodgess wrote: Hi Robert! Could you please check str(data.b) and see what you have for porosity? It needs to be a factor Thanks, Erin Erin, Yes, porosity is a factor. See output below. str(data.b) 'data.frame': 96 obs. of 7 variables: $ system : Factor w/ 6 levels ... $ block : int ... $ position: Factor w/ 3 levels inrow,interrow,.. $ depth : Factor w/ 2 levels 0-7.5cm,7-5-15cm: ... $ porosity: Factor w/ 2 levels macro ,micro:... $ x : num 1.41 1.5 1.3 1.53 ... $ y : num 12.10 14.60 23.30 ... Robert __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Hiding a function
On 23/02/2008 8:22 AM, Christophe Genolini wrote: Ok, I saw FUNx So, I reformulate my question : is there a way, without nesting b( ) in a( ), to make b( ) available only in a( ) ? Not that I know of. It will be available to anything using the same environment as a(), which in the case of a package with a NAMESPACE includes all other functions in the package, and in the case of my example below, includes everything else defined in the same local() environment (e.g. d()). Duncan Murdoch Just to clarify, what Duncan was referring to as the alternative was nesting the definition of one function in another, e.g. look at FUNx in by.data.frame -- FUNx is available to by.data.frame but is not visible outside of by.data.frame . On Sat, Feb 23, 2008 at 6:09 AM, Duncan Murdoch [EMAIL PROTECTED] wrote: On 23/02/2008 5:58 AM, Christophe Genolini wrote: Duncan Murdoch a écrit : On 23/02/2008 5:15 AM, Christophe Genolini wrote: Hi the list Is it possible to 'hide' a function from the user ? I cut a big fonction in sub function and I would like to hide the sub function, just like if I declare them in the big function : -- a - function(x){ b - function(y){y^2} d - function(y){y^3} b(x)+d(x)+2 } a(2) # [1] 14 b(2) # Error : I would like the same, but with external declaration (for readability) : b - function(y){y^2} d - function(y){y^3} a - function(x){ b(x)+d(x)+2 } a(2) # [1] 14 b(2) # Error Is it possible ? Yes, as long as you're using a package with a NAMESPACE, just don't export b and d. There are other ways too, but they don't improve readability. Duncan Murdoch If I understand, it is possible only in a package, not in a programme (unless the other ways), is that it ? Yes, that's right. Here's one of the other ways: a - local( { b - function(y){y^2} d - function(y){y^3} function(x){ b(x)+d(x)+2 } }) I don't find that more readable than if b and d had been defined locally within a. 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-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Standard method for S4 object
Hi the list, I am defining a new class MyClass. Shortly, I will submit a package with it. Before, I would like to know if there is a kind of non official list of what method a new S4 object have. More precisely, personnaly, I use 'print', 'summary' and 'plot' a lot. So for my new class, I define these 3 methods. Is there some other method that a R user can raisonnably expect ? Some minimum basic tools... Thanks Christophe __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] using subset() in data frame
Chuck Cleland wrote: On 2/23/2008 6:09 AM, Chuck Cleland wrote: On 2/22/2008 8:01 PM, Robert Walters wrote: Chuck, Thanks for the pointers on subset(). When I submit the two variants you suggested, below: fit1 - lm(y ~ x, subset(data.b, porosity == macro)) Error in eval(expr, envir, enclos) : object porosity not found fit1 - lm(pore.pct ~ Db, data.b[data.b$porosity==macro,]) Error in lm.fit(x, y, ...) : 0 (non-NA) cases So, the problem is there are no objects defined for data.b, as confirmed by the following query: objects() [1] data.a data.a0 data.b objects(data.b) Error in as.environment(pos) : invalid object for 'as.environment' However, when I submit the following queries: names(data.b) [1] system block position ... levels(data.b$porosity) [1] macro micro print(data.b$porosity) [1] macro... [26] micro... [51] macro... [76] micro... R returns values in each instance. Therein lies my confusion. Furthermore,I can plot data.b with xyplot(), a very nice coplot is produced. Any thoughts? Robert __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Set without argument
Thanks a lot The 'usual' way to write the above code is a - imputeMyObj(a) :-( I was hopping something like the use of the superassignator - inside imputeMyObj (I was hoping even if I did not find it myself)... To bad. But thanks for teaching me 'usual' pratice. It is something that is not so easy to find in toturial, and as medium level programmer, it is not always clear to pick the good way when we hesitate between two... Christophe __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Aranda-Ordaz
Hi all, Does anyone know R code or SAS code for Aranda-Ordaz link family? thanks, xiao yue - [[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] Standard method for S4 object
Christophe Genolini wrote: Hi the list, I am defining a new class MyClass. Shortly, I will submit a package with it. Before, I would like to know if there is a kind of non official list of what method a new S4 object have. More precisely, personnaly, I use 'print', 'summary' and 'plot' a lot. So for my new class, I define these 3 methods. Is there some other method that a R user can raisonnably expect ? Some minimum basic tools... Thanks Christophe Hi, /I think your question should be more relevant on Rdev./ I am not sure that 'print' is called when printing an S4 object. I think 'show' is used instead. You might find which methods are usual: http://wiki.r-project.org/rwiki/doku.php?id=tips:classes-s4 may help. Personnally I would find stuff like names, $, $-, or [ useful as these are usual operation with S3 objects. Regards, Thibaut. -- ## Thibaut JOMBART CNRS UMR 5558 - Laboratoire de Biométrie et Biologie Evolutive Universite Lyon 1 43 bd du 11 novembre 1918 69622 Villeurbanne Cedex Tél. : 04.72.43.29.35 Fax : 04.72.43.13.88 [EMAIL PROTECTED] http://lbbe.univ-lyon1.fr/-Jombart-Thibaut-.html?lang=en http://pbil.univ-lyon1.fr/software/adegenet/ __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Hiding a function
After some private email with some high level programmer (Gabor), I have the solution and I can answer to my own question :-) The problem was 1° to define a function B( ) available only in a function A( ) (for code safeness) and 2° to define B( ) elsewhere than in A( ) (for code readability) The solution is the following # Definition of an environment that will be use in A() (a list will work as well) envA - new.env() # Definition of B(), in environment envA : envA$b - function(x) x2 # Definition of A : A - function(x) with(envA, { B(3) }) Thanks Christophe On 23/02/2008 5:15 AM, Christophe Genolini wrote: Hi the list Is it possible to 'hide' a function from the user ? I cut a big fonction in sub function and I would like to hide the sub function, just like if I declare them in the big function : -- a - function(x){ b - function(y){y^2} d - function(y){y^3} b(x)+d(x)+2 } a(2) # [1] 14 b(2) # Error : I would like the same, but with external declaration (for readability) : b - function(y){y^2} d - function(y){y^3} a - function(x){ b(x)+d(x)+2 } a(2) # [1] 14 b(2) # Error Is it possible ? Yes, as long as you're using a package with a NAMESPACE, just don't export b and d. There are other ways too, but they don't improve readability. Duncan Murdoch __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Aranda-Ordaz
I have no idea if it is helpful, but a quick google search turned up: LINKINF # Two S-PLUS functions to compute influence diagnostics ...The assumed logit link is embedded within the Aranda-Ordaz parametric # family of link functions. # Written by John Yick and Andy H. Lee ... phase.hpcc.jp/mirrors/stat/S/linkinf - 5k - Cached - Similar pages - Note this On Sat, Feb 23, 2008 at 10:11 AM, o ha wang [EMAIL PROTECTED] wrote: Hi all, Does anyone know R code or SAS code for Aranda-Ordaz link family? thanks, xiao yue - [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Jim Holtman Cincinnati, OH +1 513 646 9390 What is the problem you are trying to solve? __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] exprs function download
I am supposed to use exprs as a function. Where can i download exprs function? I tried searching at bioconductor and seach engine but no luck. Is it located in one of the library in R? source(http://bioconductor.org/biocLite.R;) biocLite(Biobase) library(Biobase) ?exprs HTH, Tobias __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] overdrawing a plot
I had a similar problem, and Paul Murrell sent me a workaround: http://finzi.psych.upenn.edu/R/Rhelp02a/archive/104038.html You can capture the ggplot drawing as a grid grob (gTree), edit that (no drawing occurs to this point), and then draw it ... Hadley realized that this is a bit awkward, and it could be there is a better solution in the post-christmas revision. Not yet, unfortunately! I'm still thinking about it. Hadley -- http://had.co.nz/ __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] plotEst
On Tue, Feb 19, 2008 at 3:53 PM, sigalit mangut-leiba [EMAIL PROTECTED] wrote: Sorry to disturb, I managed to plot 2 together with 'layer' like this: qplot(se, or, min=lcl1, max=ucl1, data=df1, geom=pointrange)+layer(data = df2, mapping = *aes*(x = se, y = OR2,min=lcl2,max=ucl2), geom = pointrange)+geom_line() An easier way would be to do something like this: df1$id - 1 df2$id - 2 df - rbind(df1, df2) qplot(se, or, min=lcl1, max=ucl1, colour=factor(id), data=df, geom=pointrange) + geom_line() That way you get a nice legend too. Hadley -- http://had.co.nz/ __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Viable Approach to Parallel R?
Hi Dan, I've had pretty good luck using Snow with with Rpvm. It's definitely not what you'd call plug and play, but it does work. I'm using it on a single computer to just take advantage of multiple processors, and it does a pretty good job of keeping them busy. The main gotchas I've found with Snow are in data dissemination: You may have to clusterCall(cl, require(foo)) or clusterExport(cl,bar) more things than you would have expected. -Eric -- Eric W. Anderson University of Colorado [EMAIL PROTECTED] Dept. of Computer Science phone: +1-720-984-8864 Systems Research Lab - ECCR 1B54 PGP key fingerprints: personal: 1BD4 CFCE 8B59 8D6E EA3E EBD5 4DC9 3E61 656C 462B academic: D3C5 D6FF EDED 9F1F C36D 53A3 74B7 53A6 3C74 5F12 signature.asc Description: Digital signature __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Hiding a function
After some private email with some high level programmer (Gabor), I have shouldn't that rather be: high in knowledge but low in level? Best, Hans-Peter [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Viable Approach to Parallel R?
Similar experience, with snow MPI (LAM). Actually, plug and play. G. On Sat, Feb 23, 2008 at 10:57:22AM -0700, Eric W Anderson wrote: Hi Dan, I've had pretty good luck using Snow with with Rpvm. It's definitely not what you'd call plug and play, but it does work. I'm using it on a single computer to just take advantage of multiple processors, and it does a pretty good job of keeping them busy. The main gotchas I've found with Snow are in data dissemination: You may have to clusterCall(cl, require(foo)) or clusterExport(cl,bar) more things than you would have expected. -Eric -- Eric W. Anderson University of Colorado [EMAIL PROTECTED] Dept. of Computer Science phone: +1-720-984-8864 Systems Research Lab - ECCR 1B54 PGP key fingerprints: personal: 1BD4 CFCE 8B59 8D6E EA3E EBD5 4DC9 3E61 656C 462B academic: D3C5 D6FF EDED 9F1F C36D 53A3 74B7 53A6 3C74 5F12 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Csardi Gabor [EMAIL PROTECTED]UNIL DGM __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Error in ma.svd(X, 0, 0) : 0 extent dimensions
Hi, I run a maanova analysis and found this message error: Error in ma.svd(X, 0, 0) : 0 extent dimensions I did a google search and found this: \item ma.svd: function to compute the sigular-value decomposition of a rectangular matrix by using LAPACK routines DEGSVD AND ZGESVD. \item fdr: function to calculate the adjusted P values for FDR control. I did a search for LAPACK and not found a package. Could you help me on how I could solve this problem? I am try to do this: library(maanova) read the data file and design # Make the full model based on the design anova.full.mix - fitmaanova(data, formula=~ Var+ind+Trat+Time+ Var:ind+Var:Trat+Var:Time+ ind:Trat+ind:Time+ Trat:Time+ Var:ind:Trat+ Var:ind:Time+ Sample,random=~Sample) If I remove the Var:ind:Trat and Var:ind:Time from formula the script runs very well. Did is not possible to do that interactions (Var:ind:Trat and Var:ind:Time)? What you suggest me to do that? Thank you very much! Marcelo __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] using subset() in data frame
Greg Snow wrote: Look carefully at the output and commands below. The first level of porosity is macro (notice the space at the end) but you are asking for macro (without the space). Computers are very literal, so macro is not equal to macro. T Greg and Chuck, Thanks for your very generous help. As Greg perceptively noted above, there is indeed a space after macro . When I went back and changed porosity == macro to macro the program ran without a flaw. I think this error goes back to the .csv file which I read into R. For some reason it's propagating a space after macro that's not visible in the file, but R picks up. In future, I'll be careful to note how R expresses variables read from external files. Sincerely, Robert Walters __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Bimodal deconvolution
Hi Everyone- After searching through posts and my favorite R-help websites I'm still confused about a problem. I have data which is bimodal in nature, but there is no clearly obvious separation between the two peaks. In programs such as Origin, I can deconvolute the two distributions and have it generate a best guess as to what the two subpopulations are which make up my dataset. Below is a link to a figure which represents what I would like to accomplish here (it is the best I can do so far). http://nucleus.msae.wisc.edu/example.html Thanks, Seth Imhoff __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] using subset() in data frame
Chuck Cleland wrote: On 2/23/2008 9:13 AM, Robert Walters wrote: Chuck Cleland wrote: Chuck, For the record, I might add that that the following two variants for subsetting worked equally well: fit1 - lm(pore.pct ~ Db, subset(data.b, porosity == macro )) fit1 - lm(pore.pct ~ Db, data.b[data.b$porosity == macro ,]) So the problem was two-fold. I'll never know if any of the variations of subset I was typing were correct due to the macro error. Robert Walters __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Bimodal deconvolution
Seth Imhoff wrote: Hi Everyone- After searching through posts and my favorite R-help websites I'm still confused about a problem. I have data which is bimodal in nature, but there is no clearly obvious separation between the two peaks. In programs such as Origin, I can deconvolute the two distributions and have it generate a best guess as to what the two subpopulations are which make up my dataset. Below is a link to a figure which represents what I would like to accomplish here (it is the best I can do so far). http://nucleus.msae.wisc.edu/example.html That's not a well defined problem without further assumptions, so if you want to do what Origin does, you need to find out what Origin does (This is not easily fathomed by Googling.) The key concept is finite mixture model an there's a CRAN task view on the topic: http://cran.r-project.org/web/views/Cluster.html (Deconvolution is a somewhat different technique which is based on the assumption that there is an underlying signal which is blurred by some smoothing kernel. That doesn't really seem to apply here, but you could use the search facilities on www.r-project.org to investigate.) -- 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.
[R] clarification about glm
Hello, I have a question about glm: if i have a binary covariate (unit=1,0) the reference group would be 0? (prediction for unit=1) example: dat1-data.frame(y,unit,x1,x2) log_u - glm(y~.,family=binomial,data=dat1) summary(log_u) Estimate Std. Error z value Pr(|z|) (Intercept) -0.542470.24658 -2.200 0.0278 * unit1 -0.130520.22861 -0.571 0.5680 aps 0.030980.01433 2.162 0.0306 * tiss00.025220.01101 2.291 0.0219 * Thank you, Sigalit. [[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] clarification about glm
Hi Sigalit, yes, you can see this from the fact that the table says unit1 meaning that it compares 1 to 0 and not vice versa. Everytime you regress on dummies the label will have added this to the original variable name. Say you have gender male and female. Then gendermale in the label of your summary table would indicate that female is coded 0 and male 1 and that you therefore compare how much more or less of the dependent variable males have over females (and not vice versa). In case of a binomial regression it would of course be how much more or less likely they are on average (with the appropriate transformation) ... Does that help you? Cheers, Daniel - cuncta stricte discussurus - -Ursprüngliche Nachricht- Von: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Im Auftrag von sigalit mangut-leiba Gesendet: Saturday, February 23, 2008 3:05 PM An: r-help Betreff: [R] clarification about glm Hello, I have a question about glm: if i have a binary covariate (unit=1,0) the reference group would be 0? (prediction for unit=1) example: dat1-data.frame(y,unit,x1,x2) log_u - glm(y~.,family=binomial,data=dat1) summary(log_u) Estimate Std. Error z value Pr(|z|) (Intercept) -0.542470.24658 -2.200 0.0278 * unit1 -0.130520.22861 -0.571 0.5680 aps 0.030980.01433 2.162 0.0306 * tiss00.025220.01101 2.291 0.0219 * Thank you, Sigalit. [[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] How to Include greek symbol in axis label?
Thanks for your help. I tried par(family=serif) and it worked well. I'm running R 2.6.1, on windows XP machine. font=6 appears to be similar to times new roman or serif, they appear to be very similar (to my untrained eye). Serif seems to work fine for my needs! Thanks, Ken Kenneth Takagi MS Student Crop and Soil Sciences 412 ASI Building University Park, PA 16802 Ph: (814)-863-7638 -Original Message- From: Prof Brian Ripley [mailto:[EMAIL PROTECTED] Sent: Sat 2/23/2008 2:05 AM To: Kenneth Takagi Cc: r-help@r-project.org Subject: Re: [R] How to Include greek symbol in axis label? On Fri, 22 Feb 2008, Kenneth Takagi wrote: Hi, I'm fairly new to R, so hopefully this is an easy question... Sorry, no as you haven't given us the minimum information asked for in the posting guide and we are reduced to attempted mind reading. What is 'font=6'? R only has font = 1 to 5. There is an extension on the windows() device only (but you have not mentioned an OS): nowadays the use of par(family=) is preferred. So a likely answer is to use par(family=serif) BTW, this is not a 'greek character'. It is the mathematical symbol phi, and that is distinct from the Greek character, and not in whatever 'font=6' is. On a plot, I would like to have the y label read: Response(phi) with phi = the greek character. From old posts I've found this: title(ylab=expression(paste(Response (, phi, This displays nicely, but in the default font. I would like to use font=6 (which is the font of the other labels, title, etc.). Is there an way to display the y-label in font=6 and still include the greek character? Is there an easier way to do this? Thanks for your help! Ken [EMAIL PROTECTED] [[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 [[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] plotEst
Thank you for your suggestion, now I get 2 lines but confidence limits just for the first one.. do you know what I'm doing wrong?! Thanks again, Sigalit. On 2/23/08, hadley wickham [EMAIL PROTECTED] wrote: On Tue, Feb 19, 2008 at 3:53 PM, sigalit mangut-leiba [EMAIL PROTECTED] wrote: Sorry to disturb, I managed to plot 2 together with 'layer' like this: qplot(se, or, min=lcl1, max=ucl1, data=df1, geom=pointrange)+layer(data = df2, mapping = *aes*(x = se, y = OR2,min=lcl2,max=ucl2), geom = pointrange)+geom_line() An easier way would be to do something like this: df1$id - 1 df2$id - 2 df - rbind(df1, df2) qplot(se, or, min=lcl1, max=ucl1, colour=factor(id), data=df, geom=pointrange) + geom_line() That way you get a nice legend too. Hadley -- http://had.co.nz/ [[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 Include greek symbol in axis label?
On Sat, 23 Feb 2008, Kenneth Takagi wrote: Thanks for your help. I tried par(family=serif) and it worked well. I'm running R 2.6.1, on windows XP machine. font=6 appears to be similar to times new roman or serif, they appear to be very similar (to my untrained eye). Serif seems to work fine for my needs! It is 'Times New Roman' unless you altered it: see etc/Rdevga. And that is what 'serif' maps to Thanks, Ken Kenneth Takagi MS Student Crop and Soil Sciences 412 ASI Building University Park, PA 16802 Ph: (814)-863-7638 -Original Message- From: Prof Brian Ripley [mailto:[EMAIL PROTECTED] Sent: Sat 2/23/2008 2:05 AM To: Kenneth Takagi Cc: r-help@r-project.org Subject: Re: [R] How to Include greek symbol in axis label? On Fri, 22 Feb 2008, Kenneth Takagi wrote: Hi, I'm fairly new to R, so hopefully this is an easy question... Sorry, no as you haven't given us the minimum information asked for in the posting guide and we are reduced to attempted mind reading. What is 'font=6'? R only has font = 1 to 5. There is an extension on the windows() device only (but you have not mentioned an OS): nowadays the use of par(family=) is preferred. So a likely answer is to use par(family=serif) BTW, this is not a 'greek character'. It is the mathematical symbol phi, and that is distinct from the Greek character, and not in whatever 'font=6' is. On a plot, I would like to have the y label read: Response(phi) with phi = the greek character. From old posts I've found this: title(ylab=expression(paste(Response (, phi, This displays nicely, but in the default font. I would like to use font=6 (which is the font of the other labels, title, etc.). Is there an way to display the y-label in font=6 and still include the greek character? Is there an easier way to do this? Thanks for your help! Ken [EMAIL PROTECTED] [[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 -- 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.
[R] Calculate missing value using a correlation metric
Could someone please let me know how can I calculate missing values using a correlation metric? I know that the knn function is used for calculating missing values using Euclidean distance. Thanks -- View this message in context: http://www.nabble.com/Calculate-missing-value-using-a-correlation-metric-tp15658940p15658940.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] Newbie: Measuring distance between clusters.
One way to do it is to find the distances between ther centers (= centres in English) of the clusters. dist(kc$centers) It rather depends on how you define distances between clusters, though. There are many possibilities. -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Keizer_71 Sent: Saturday, 23 February 2008 7:40 PM To: r-help@r-project.org Subject: [R] Newbie: Measuring distance between clusters. Hi, I had 1 genes, and I clustered them using K-means clustering in R. kc-kmeans(data.sub,7) kc n cluster sum of squares by cluster: [1] 60631.76 135886.19 159049.71 101783.27 90040.72 183335.60 158867.81 Available components: [1] cluster centers withinss size I am very new to R. How do i measure the distance between those cluster? I tried I am trying to do a complete linkage z-hclust(kc,method=complete) Error in if (n 2) stop(must have n = 2 objects to cluster) : argument is of length zero thanks. -- View this message in context: http://www.nabble.com/Newbie%3A-Measuring-distance-between-clusters.-tp1 5650066p15650066.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] exprs function download
RSiteSearch(exprs) will start you off. If not, ask whoever is requiring you to use it. -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Keizer_71 Sent: Sunday, 24 February 2008 3:15 AM To: r-help@r-project.org Subject: [R] exprs function download Hi, I am supposed to use exprs as a function. Where can i download exprs function? I tried searching at bioconductor and seach engine but no luck. Is it located in one of the library in R? thanks. C -- View this message in context: http://www.nabble.com/exprs-function-download-tp15654560p15654560.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] where can I find source code for particle filters applied to stochastic volatilities?
Hi all, Could anybody point me to some overview/survey papers about using particle filters and sequential monte carlo methods to estimate stochastic volatilities? I couldn't find any such articles giving a big-picture view of the literature. How do these estimation methods compare to EMM and other Bayesian methods for estimating stochastic volatilities? Also, I am looking for some sample/source code that shows how to program particle filters and sequential monte carlo methods to estimate stochastic volatilities... Could anybody give me some pointers? Thanks a lot __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Corrected : Efficient writing of calculation involving each element of 2 data frames
Vikas, Please provide reproducible code when posting to this list (read the posting guide). You need to vectorise your code to make it run faster. Here are some timing results for 3 different vectorised methods. All 3 methods take under 30 seconds to run on a pair of 30,000-vectors. The results suggests that using rollapply (from the zoo package) will work well. You might get it to go a bit faster by working with embed, but as I understand it that requires explicitly forming a large matrix, which may cause problems with big datasets. Also it is not as intuitive as the zoo function. df.a - data.frame(Date=as.Date(1:3), Value=rnorm(3)) df.b - data.frame(Date=as.Date(1:3), Value=rnorm(3)) # METHOD 1: sapply starts - seq(1, nrow(df.a)-99) system.time( cors - sapply(starts, function(i) { if (i %% 1000 == 0) print(i) subset - i + 0:99 cor(df.a[subset, 2], df.b[subset, 2]) }) ) # user system elapsed # 29.970.31 31.22 # METHOD 2: zoo::rollapply library(zoo) z.ab - zoo(cbind(a=df.a$Value, b=df.b$Value), order.by=df.a$Date) system.time( zcors - unlist(rollapply(z.ab, width=100, FUN=function(z) cor(z[,1], z[,2]), by.column = FALSE, align=right) ) ) # user system elapsed # 14.860.39 16.02 all.equal(cors, coredata(zcors)) # TRUE # METHOD 3: embed / sapply mat.a - embed(df.a$Value, 100) mat.b - embed(df.b$Value, 100) system.time( ecors - sapply(1:nrow(mat.a), function(i) cor(mat.a[i,], mat.b[i,])) ) # user system elapsed # 12.300.04 12.73 all.equal(cors, ecors) # TRUE On Sat, Feb 23, 2008 at 8:15 AM, Vikas N Kumar [EMAIL PROTECTED] wrote: Hi I have 2 data.frames each of the same number of rows (approximately 3 or more entries). They also have the same number of columns, lets say 2. One column has the date, the other column has a double precision number. Let the column names be V1, V2. Now I want to calculate the correlation of the 2 sets of data, for the last 100 days for every day available in the data.frames. My code looks like this : # Let df1, and df2 be the 2 data frames with the required data ## begin code snippet my_corr - c(); for ( i_start in 100:nrow(df1)) my_corr[i_start-99] - cor(x=df1[(i_start-99):i_start,V2],y=df2[(i_start-99):i_start,V2]) ## end of code snippet This runs very slowly, and takes more than an hour to run if I have to calculate correlation between 10 data sets leaving me with 45 runs of this snippet or taking more than 30 minutes to run. Is there an efficient way to write this piece of code where I can get it to run faster ? If I do something similar in Excel, it is much faster. But I have to use R, since this is a part of a bigger program. Any help will be appreciated. Thanks and Regards Vikas -- http://www.vikaskumar.org/ [[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. -- Felix Andrews / 安福立 PhD candidate Integrated Catchment Assessment and Management Centre The Fenner School of Environment and Society The Australian National University (Building 48A), ACT 0200 Beijing Bag, Locked Bag 40, Kingston ACT 2604 http://www.neurofractal.org/felix/ 3358 543D AAC6 22C2 D336 80D9 360B 72DD 3E4C F5D8 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.