[R] Bivariate ReLU Distribution
Hi, I would rather have a Statistics related question hope experts here can provide some suggestions. I have posted this request in some other forum but failed to generate meaningful response I am looking for some technical document on deriving the Distribution function for sum of 2 ReLU(𝑋)=max{0,𝑋} distributions i.e max{0,𝑋1} + max{0,𝑋2} where X1 and X2 jointly follow some bivariate Nomal distribution. There are few technical notes available for univariate ReLU distribution, however I failed to find any spec for bivariate/multivariate setup. Any pointer on above subject will be highly helpful. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Help with Regular expression
Hi Bogaso, I see your ultimate goal is to extract the Date-time part from your expression, then below should help : > as.POSIXlt(gsub("[^0-9a-zA-Z]", "", "\":\"03-JAN-2018 16:00:00\""), format = "%d%b%Y%H%M%OS") [1] "2018-01-03 16:00:00 GMT" _____ Arun Kumar Saha, FRM QUANTITATIVE RISK AND HEDGE CONSULTING SPECIALIST LinkedIn: http://in.linkedin.com/in/ArunFRM Personal : http://WWW.ARUNSAHA.IN <http://WWW.ARUNSAHA.IN> _ [[alternative HTML version deleted]] __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/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] Model selection in nonstationary VAR
which method in statistics is completely free from model misspecification? Thanks and regards, _ Arun Kumar Saha, FRM QUANTITATIVE RISK AND HEDGE CONSULTING SPECIALIST Visit me at: http://in.linkedin.com/in/ArunFRM _ [[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] Spammer radhi
Can the Statisticians here develop some good Statistical tool to stop this Spamming keeping Type-I error almost zero? Thanks and regards, _ Arun Kumar Saha, FRM QUANTITATIVE RISK AND HEDGE CONSULTING SPECIALIST Visit me at: http://in.linkedin.com/in/ArunFRM _ [[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 calculate seasonal component & cyclic component of time series?
I think you need to pass a time series object, as given in the help page of decompose() function. From your text file it seems that you are passing a numerical vector which is missing the key element of Index as date for any legitimate time series data. _ Arun Kumar Saha, FRM QUANTITATIVE RISK AND HEDGE CONSULTING SPECIALIST Visit me at: http://in.linkedin.com/in/ArunFRM __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] VECM simulation
Dear Mamush, you do not need to change the "VAR simulation codes to VECM"!!! What you really need to change is your VECM model itself to correaponding VAR representation. I guess there is some function vec2var() or something like that (or perhaps you can do it manually.) Once you are done you may then use VAR simulation code. HTH, Thanks and regards, _____ Arun Kumar Saha, FRM QUANTITATIVE RISK AND HEDGE CONSULTING SPECIALIST Visit me at: http://in.linkedin.com/in/ArunFRM _ [[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 generate heterosced​astic random numbers?
Answering http://r.789695.n4.nabble.com/How-to-generate-heteroscedastic-random-numbers-td3654534.html I think best way to generated Heterosced​astic data would be, first fix or assume some DGP of your choice, you may assume any arbitrary model parameter(s) provided forms of those parameters are legitimate under the model space. Then just simulate numbers starting from the Residual (the form of that residual you already must have assumed). Given some initial value(s), you would then get some Time series. You may chose to generate a lengthy TS as most of the parameters estimations happen within Asymptotic concept. Then apply your statistical test on that realized series. You may repeatedly generate TS and check the distribution of estimated model parameters etc. HTH _ Arun Kumar Saha, FRM QUANTITATIVE RISK AND HEDGE CONSULTING SPECIALIST Visit me at: http://in.linkedin.com/in/ArunFRM __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Running R from windows command prompt
Hi Siddharth, many experts already answered your query, however I would like to share how I run R in command prompt: 1. open command prompt 2. change working directory: cd C:\\R-2.13.0\bin\i386 (put the entire path here, however many people might find this step weird, you can have better management setting window's path variable appropriately) 3. type R.exe You can use R within command prompt with same efficiency. However most awkward thing I find in this process is you can never copy-paste any code. So everything you need to type there manually! HTH _____ Arun Kumar Saha, FRM QUANTITATIVE RISK AND HEDGE CONSULTING SPECIALIST Visit me at: http://in.linkedin.com/in/ArunFRM __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] strength of seasonal component
Answering question as in " http://r.789695.n4.nabble.com/strength-of-seasonal-component-td3517033.html ." Possibly your code "MASS::rlm(mean price ~ month)" will result in Spurious regression; you would make wrong impression of your estimated beta coef. as in presence of the spurious regression they no longer have t-distribution. May be you should try with "MASS::rlm(diff(log(mean price)) ~ month)?" And secondly decomposition using standard approach is some sort of **deterministic** act therefore, you would not get any measure of "strength" in Statistical inference sense. To get that, I think above regression approach would be handy. HTH Thanks and regards, _________ Arun Kumar Saha, FRM QUANTITATIVE RISK AND HEDGE CONSULTING SPECIALIST Visit me at: http://in.linkedin.com/in/ArunFRM _ [[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] using lapply
On reply to the post http://r.789695.n4.nabble.com/using-lapply-td3345268.html Dear Kushan, this may be a good start: ## assuming 'instr.list' is your list object and you are applying my.strat() function on each element of that list, you can use lapply function as lapply(instr.list, function(x) return(my.strat(x))) Here resulting element will again be another list with length is same as the length of your original list 'instr.list.' Instead if the returned object for my.strat() function is a single number then you might want to create a vector instead list, in that case just use 'sapply' HTH Arun, [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Help -normal distribution
I gave you hint only, however whatever you done is correct. On Mon, Aug 2, 2010 at 4:30 AM, n.a.s wrote: > Hi, > > But i didn't understand why you did it like this qnorm(40/200)?? > > I already found the answer qnorm(.20,181,7.3) and qnorm(.80,181,7.3) > > > Thanks. > > > On Mon, Aug 2, 2010 at 12:33 AM, Arun.stat > wrote: >> >> try >> qnorm(40/200) >> -- >> View this message in context: >> http://r.789695.n4.nabble.com/Help-normal-distribution-tp2309730p2309735.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] Best way to replace :SS with :00
probably : a <- rep("HH:MM:SS", 5) substring(a, 7) = "00" a Not sure if there is an R way to do this or a regular express way, but here is what I am trying to do. I've got lots of data where the format is HH:MM:SS, but I need to format it like HH:MM:00, i.e. round the second down to zero. What is the best way to do this? Thanks again. Jason [[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] Detecting "Break"
Hi all, say, I have following vector : x <- c(rep(5, 5), rep(3,4), rep(5,10)) Now I want to get the index numbers where elements of that vector changes i.e. in above example I want to get a vector with elements : 6, 10. Because at that indices, element of original vector changes value. Is there any R function to do that? Regards, [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Calling R from .net environment
Hi, Currently I am a .net programmer and would like to use R for my statistical computations engine. I already have installed RServer250.exe so that I could call R from my .net programming environment, however unfortunately, i could not be able to find RServer250.exe in the R-(D) COM Interface region. If someone guide me how to add these COM components and call the R-code through my application, it would be very good to me. Regards, [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Skewness
I would like to know about the skewness function bundled in fBasics package. Is it population measure of skewness or sample estimate? [[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] Package for financial options calculation
Hi all, Is there any R package on "European/American oprions pricing"? And on calculation of it's sensitivities? Regards, [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Weighted variance function?
oh now I got, R is taking unbiased estimator, anyways thanks On Sun, Jul 27, 2008 at 2:54 PM, Arun Kumar Saha <[EMAIL PROTECTED]>wrote: > I feel there is something wrong in definition in weighted variance. > > Say for a fair dice the variance of outcome should be : 2.92 ( > http://en.wikipedia.org/wiki/Variance) > > However if I use cov.wt() or weighted.var() by Gavin, I get : > > cov.wt(as.data.frame(1:6), rep(0.6, 6)) > $cov > 1:6 > 1:6 3.5 > > $center > 1:6 > 3.5 > > $n.obs > [1] 6 > > $wt > [1] 0.167 0.167 0.167 0.167 0.167 0.167 > > i.e. 3.5 > > Therefore if I want to calculate Variance for a r.v. with different prob > for different values then should not use those formulae. Is it the case? > > > On Sun, Jul 27, 2008 at 2:30 PM, Patrick Burns <[EMAIL PROTECTED]>wrote: > >> Have you seen 'cov.wt'? >> >> >> Patrick Burns >> [EMAIL PROTECTED] >> +44 (0)20 8525 0696 >> http://www.burns-stat.com >> (home of S Poetry and "A Guide for the Unwilling S User") >> >> Arun Kumar Saha wrote: >> >>> ur prog gives following result: >>> >>> weighted.var(c(1,-1), c(0.5,0.5)) >>> [1] 2 >>> >>> is it ok? >>> >>> On Thu, Jul 24, 2008 at 7:57 PM, Gavin Simpson <[EMAIL PROTECTED] >>> >wrote: >>> >>> >>> >>>> On Thu, 2008-07-24 at 02:25 +0530, Arun Kumar Saha wrote: >>>> >>>> >>>>> There is a R function to calculate weighted mean : weighted.mean() >>>>> under >>>>> stats package. Is there any direct R function for calculating weighted >>>>> variance as well? >>>>> >>>>> >>>> Here are two ways; weighted.var() is via the usual formula and >>>> weighted.var2() uses a running sums approach. The formulae for which are >>>> both on the weighted mean entry page on wikipedia for example. >>>> >>>> The removal of NA is as per weighted.mean, but I have not included any >>>> of the sanity checks that that functions contains. >>>> >>>> weighted.var <- function(x, w, na.rm = FALSE) { >>>> if (na.rm) { >>>> w <- w[i <- !is.na(x)] >>>> x <- x[i] >>>> } >>>> sum.w <- sum(w) >>>> sum.w2 <- sum(w^2) >>>> mean.w <- sum(x * w) / sum(w) >>>> (sum.w / (sum.w^2 - sum.w2)) * sum(w * (x - mean.w)^2, na.rm = >>>> na.rm) >>>> } >>>> >>>> weighted.var2 <- function(x, w, na.rm = FALSE) { >>>> if (na.rm) { >>>> w <- w[i <- !is.na(x)] >>>> x <- x[i] >>>> } >>>> sum.w <- sum(w) >>>> (sum(w*x^2) * sum.w - sum(w*x)^2) / (sum.w^2 - sum(w^2)) >>>> } >>>> >>>> ## from example section in ?weighted.mean >>>> ## GPA from Siegel 1994 >>>> wt <- c(5, 5, 4, 1)/15 >>>> x <- c(3.7,3.3,3.5,2.8) >>>> weighted.mean(x,wt) >>>> >>>> weighted.var(x, wt) >>>> >>>> weighted.var2(x, wt) >>>> >>>> And some timings: >>>> >>>> >>>> >>>>> system.time(replicate(10, weighted.var(x, wt))) >>>>> >>>>> >>>> user system elapsed >>>> 2.679 0.014 2.820 >>>> >>>> >>>>> system.time(replicate(10, weighted.var2(x, wt))) >>>>> >>>>> >>>> user system elapsed >>>> 2.224 0.010 2.315 >>>> >>>> HTH >>>> >>>> G >>>> -- >>>> %~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~% >>>> Dr. Gavin Simpson [t] +44 (0)20 7679 0522 >>>> ECRC, UCL Geography, [f] +44 (0)20 7679 0565 >>>> Pearson Building, [e] gavin.simpsonATNOSPAMucl.ac.uk >>>> Gower Street, London [w] >>>> http://www.ucl.ac.uk/~ucfagls/<http://www.ucl.ac.uk/%7Eucfagls/> >>>> <http://www.ucl.ac.uk/%7Eucfagls/> >>>> UK. WC1E 6BT. [w] http://www.freshwaters.org.uk >>>> %~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~% >>>> >>>> >>>> >>>> >>> >>>[[alternative HTML version deleted]] >>> >>> __ >>> R-help@r-project.org mailing list >>> https://stat.ethz.ch/mailman/listinfo/r-help >>> PLEASE do read the posting guide >>> http://www.R-project.org/posting-guide.html >>> and provide commented, minimal, self-contained, reproducible code. >>> >>> >>> >>> >> > > > -- > > -- [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Weighted variance function?
I feel there is something wrong in definition in weighted variance. Say for a fair dice the variance of outcome should be : 2.92 ( http://en.wikipedia.org/wiki/Variance) However if I use cov.wt() or weighted.var() by Gavin, I get : cov.wt(as.data.frame(1:6), rep(0.6, 6)) $cov 1:6 1:6 3.5 $center 1:6 3.5 $n.obs [1] 6 $wt [1] 0.167 0.167 0.167 0.167 0.167 0.167 i.e. 3.5 Therefore if I want to calculate Variance for a r.v. with different prob for different values then should not use those formulae. Is it the case? On Sun, Jul 27, 2008 at 2:30 PM, Patrick Burns <[EMAIL PROTECTED]>wrote: > Have you seen 'cov.wt'? > > > Patrick Burns > [EMAIL PROTECTED] > +44 (0)20 8525 0696 > http://www.burns-stat.com > (home of S Poetry and "A Guide for the Unwilling S User") > > Arun Kumar Saha wrote: > >> ur prog gives following result: >> >> weighted.var(c(1,-1), c(0.5,0.5)) >> [1] 2 >> >> is it ok? >> >> On Thu, Jul 24, 2008 at 7:57 PM, Gavin Simpson <[EMAIL PROTECTED] >> >wrote: >> >> >> >>> On Thu, 2008-07-24 at 02:25 +0530, Arun Kumar Saha wrote: >>> >>> >>>> There is a R function to calculate weighted mean : weighted.mean() under >>>> stats package. Is there any direct R function for calculating weighted >>>> variance as well? >>>> >>>> >>> Here are two ways; weighted.var() is via the usual formula and >>> weighted.var2() uses a running sums approach. The formulae for which are >>> both on the weighted mean entry page on wikipedia for example. >>> >>> The removal of NA is as per weighted.mean, but I have not included any >>> of the sanity checks that that functions contains. >>> >>> weighted.var <- function(x, w, na.rm = FALSE) { >>> if (na.rm) { >>> w <- w[i <- !is.na(x)] >>> x <- x[i] >>> } >>> sum.w <- sum(w) >>> sum.w2 <- sum(w^2) >>> mean.w <- sum(x * w) / sum(w) >>> (sum.w / (sum.w^2 - sum.w2)) * sum(w * (x - mean.w)^2, na.rm = >>> na.rm) >>> } >>> >>> weighted.var2 <- function(x, w, na.rm = FALSE) { >>> if (na.rm) { >>> w <- w[i <- !is.na(x)] >>> x <- x[i] >>> } >>> sum.w <- sum(w) >>> (sum(w*x^2) * sum.w - sum(w*x)^2) / (sum.w^2 - sum(w^2)) >>> } >>> >>> ## from example section in ?weighted.mean >>> ## GPA from Siegel 1994 >>> wt <- c(5, 5, 4, 1)/15 >>> x <- c(3.7,3.3,3.5,2.8) >>> weighted.mean(x,wt) >>> >>> weighted.var(x, wt) >>> >>> weighted.var2(x, wt) >>> >>> And some timings: >>> >>> >>> >>>> system.time(replicate(10, weighted.var(x, wt))) >>>> >>>> >>> user system elapsed >>> 2.679 0.014 2.820 >>> >>> >>>> system.time(replicate(10, weighted.var2(x, wt))) >>>> >>>> >>> user system elapsed >>> 2.224 0.010 2.315 >>> >>> HTH >>> >>> G >>> -- >>> %~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~% >>> Dr. Gavin Simpson [t] +44 (0)20 7679 0522 >>> ECRC, UCL Geography, [f] +44 (0)20 7679 0565 >>> Pearson Building, [e] gavin.simpsonATNOSPAMucl.ac.uk >>> Gower Street, London [w] >>> http://www.ucl.ac.uk/~ucfagls/<http://www.ucl.ac.uk/%7Eucfagls/> >>> <http://www.ucl.ac.uk/%7Eucfagls/> >>> UK. WC1E 6BT. [w] http://www.freshwaters.org.uk >>> %~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~% >>> >>> >>> >>> >> >>[[alternative HTML version deleted]] >> >> __ >> R-help@r-project.org mailing list >> https://stat.ethz.ch/mailman/listinfo/r-help >> PLEASE do read the posting guide >> http://www.R-project.org/posting-guide.html >> and provide commented, minimal, self-contained, reproducible code. >> >> >> >> > -- [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Weighted variance function?
ur prog gives following result: weighted.var(c(1,-1), c(0.5,0.5)) [1] 2 is it ok? On Thu, Jul 24, 2008 at 7:57 PM, Gavin Simpson <[EMAIL PROTECTED]>wrote: > On Thu, 2008-07-24 at 02:25 +0530, Arun Kumar Saha wrote: > > There is a R function to calculate weighted mean : weighted.mean() under > > stats package. Is there any direct R function for calculating weighted > > variance as well? > > Here are two ways; weighted.var() is via the usual formula and > weighted.var2() uses a running sums approach. The formulae for which are > both on the weighted mean entry page on wikipedia for example. > > The removal of NA is as per weighted.mean, but I have not included any > of the sanity checks that that functions contains. > > weighted.var <- function(x, w, na.rm = FALSE) { >if (na.rm) { >w <- w[i <- !is.na(x)] >x <- x[i] >} >sum.w <- sum(w) >sum.w2 <- sum(w^2) >mean.w <- sum(x * w) / sum(w) >(sum.w / (sum.w^2 - sum.w2)) * sum(w * (x - mean.w)^2, na.rm = > na.rm) > } > > weighted.var2 <- function(x, w, na.rm = FALSE) { >if (na.rm) { >w <- w[i <- !is.na(x)] >x <- x[i] >} >sum.w <- sum(w) >(sum(w*x^2) * sum.w - sum(w*x)^2) / (sum.w^2 - sum(w^2)) > } > > ## from example section in ?weighted.mean > ## GPA from Siegel 1994 > wt <- c(5, 5, 4, 1)/15 > x <- c(3.7,3.3,3.5,2.8) > weighted.mean(x,wt) > > weighted.var(x, wt) > > weighted.var2(x, wt) > > And some timings: > > > system.time(replicate(10, weighted.var(x, wt))) > user system elapsed > 2.679 0.014 2.820 > > system.time(replicate(10, weighted.var2(x, wt))) > user system elapsed > 2.224 0.010 2.315 > > HTH > > G > -- > %~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~% > Dr. Gavin Simpson [t] +44 (0)20 7679 0522 > ECRC, UCL Geography, [f] +44 (0)20 7679 0565 > Pearson Building, [e] gavin.simpsonATNOSPAMucl.ac.uk > Gower Street, London [w] > http://www.ucl.ac.uk/~ucfagls/<http://www.ucl.ac.uk/%7Eucfagls/> > UK. WC1E 6BT. [w] http://www.freshwaters.org.uk > %~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~% > > [[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] Weighted variance function?
There is a R function to calculate weighted mean : weighted.mean() under stats package. Is there any direct R function for calculating weighted variance as well? [[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] looking for alternative of 'if-else'
I am not sure whether I could understand all things. Here is my code : library(zoo) # an reproducible example SD <- 1 date1 <- seq(as.Date("2001-01-01"), as.Date("2002-12-1"), by = "day") len1 <- length(date1) set.seed(1) # to make it reproducible data1 <- zoo(rnorm(len1), date1) plot(data1) # calculation for monthly or quarterly mean calc = function(frequ = c("M S", "Q S")) { switch(frequ "M S" = aggregate(data1, as.yearmon, mean) "Q S" = aggregate(data1, as.yearqtr, mean)) } However I am getting lot of errors while executing. Any further suggestion? Regards, On Sun, Jul 6, 2008 at 3:38 PM, <[EMAIL PROTECTED]> wrote: > Why don't you try "switch" Let me assume that you want to calculate a=3 and > b =5 by using one of "MEAN", "SUM","MIN", and "MAX functions. Then you could > write your code: (If you want to calculate "MEAN") > > example<-function(fun=c("MEAN", "SUM", "MIN", "MAX")){ >> > + fun<-match.arg(fun);a=3;b=5 > + switch( fun, > + MEAN=(a+b)/2, > +SUM=a+b, > +MIN=min(a,b), > +MAX=max(a,b)) > +} > >>example("MEAN") >> > [1] 4 > >> >> Hope this is helpful, > Chunhao Tu > > > > > > > Quoting Arun Kumar Saha <[EMAIL PROTECTED]>: > > There is "if-else" loop if I have to choose 1 item from a 2-item list. >> However if I have a list of 4 items (let say) then how i can choose a >> single >> item without employing 'if-else' loop? I mean in VBA I can use >> "select-case", is there any equivalent in R as well? >> >> Regards, >> >>[[alternative HTML version deleted]] >> >> __ >> R-help@r-project.org mailing list >> https://stat.ethz.ch/mailman/listinfo/r-help >> PLEASE do read the posting guide >> http://www.R-project.org/posting-guide.html >> and provide commented, minimal, self-contained, reproducible code. >> >> > > > [[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] looking for alternative of 'if-else'
There is "if-else" loop if I have to choose 1 item from a 2-item list. However if I have a list of 4 items (let say) then how i can choose a single item without employing 'if-else' loop? I mean in VBA I can use "select-case", is there any equivalent in R as well? Regards, [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Converting variance covariance matrix to correlation matrix
Suppose I have a Variance-covariance matrix A. Is there any fast way to calculate correlation matrix from 'A' and vice-versa without emplying any 'for' loop? [[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] Simulation study in R
x, y are cont. variable, and f also have to be cont.. And your second suggestion is correct of course, it actually should be |f(x,y) - c| < epsilon Thanks On Tue, Apr 29, 2008 at 12:34 PM, Moshe Olshansky <[EMAIL PROTECTED]> wrote: > Are the pairs (x,y) belong to some lattice or can > change continuously? > Does f assume some discrete values (or is constant on > sets of positive measure)? If not then it will be hard > to randomly select x and y which satisfy the exact > equality (this still can happen since there are > finitely many computer numbers, but their number is > quite large!). So if f change continuously you may > need the condition |f(x,y) - c| < epsilon for some > epsilon > 0. > > Regards, > > Moshe. > > > --- Arun Kumar Saha <[EMAIL PROTECTED]> wrote: > > > Here I am in a simulation study where I want to find > > different values > > of x and y such that f(x,y)=c (some known constant) > > w.r.t. x, y >0, > > y<=x and x<=c1 (another known constant). Can anyone > > please tell me how > > to do it efficiently in R. One way I thought that I > > will draw > > different random numbers from uniform dist according > > to that > > constraints and pick those which satisfy f(x,y)=c. > > However it is not I > > think computationally efficient. Can anyone here > > suggest me any other > > efficient approach? > > > > Regards, > > > > __ > > R-help@r-project.org mailing list > > https://stat.ethz.ch/mailman/listinfo/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] Simulation study in R
Here I am in a simulation study where I want to find different values of x and y such that f(x,y)=c (some known constant) w.r.t. x, y >0, y<=x and x<=c1 (another known constant). Can anyone please tell me how to do it efficiently in R. One way I thought that I will draw different random numbers from uniform dist according to that constraints and pick those which satisfy f(x,y)=c. However it is not I think computationally efficient. Can anyone here suggest me any other efficient approach? Regards, __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Writing list object to a file
Previous question that I asked was originated from this problem : suppose I have following time series : library(zoo) date1 = seq(as.Date("01/01/01", format = "%m/%d/%y"), as.Date("12/31/08", format = "%m/%d/%y"), by = 1) len1 = length(date1); data1 = zoo(matrix(rnorm(len1, mean=0, sd=0.5), nrow = len1), date1) Now I group those time series observation month wise : data2 = split(as.data.frame(data1), format(index(data1), "%Y%m") Now I want to perform Levene test ( http://en.wikipedia.org/wiki/Levene's_test) to test whether the variance for each group (here month) is significantly different or not. Can anyone suggest me any easiest way how to construct the test statistic, described above? Thanks On Wed, Apr 23, 2008 at 12:21 PM, Arun Kumar Saha <[EMAIL PROTECTED]> wrote: > Hi all, > > I am wondering how to write a 'list' object to a file. I already gone > through some threads like > http://mail.python.org/pipermail/python-list/2001-April/080639.html, > however could not trace out any reliable solution. I tried following : > > > write.table(calc, file="c:/data.csv") > Error in data.frame("200501" = c(-0.000387071806652095, > -0.000387221689252648, : > arguments imply differing number of rows: 25, 24, 16, 17, 18, 26, 27, > 19, 23, 20, 11 > Anybody can help? > > Regards, > -- [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Writing list object to a file
Hi all, I am wondering how to write a 'list' object to a file. I already gone through some threads like http://mail.python.org/pipermail/python-list/2001-April/080639.html, however could not trace out any reliable solution. I tried following : > write.table(calc, file="c:/data.csv") Error in data.frame("200501" = c(-0.000387071806652095, -0.000387221689252648, : arguments imply differing number of rows: 25, 24, 16, 17, 18, 26, 27, 19, 23, 20, 11 Anybody can help? Regards, [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Loading user defined functions autometically each time I start R
I am using R 2.6.2. under windows On Wed, Feb 27, 2008 at 12:43 PM, <[EMAIL PROTECTED]> wrote: > >From: Arun Kumar Saha <[EMAIL PROTECTED]> > >Date: 2008/02/27 Wed AM 01:03:26 CST > >To: "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> > >Subject: [R] Loading user defined functions autometically each time I > start R > > i'm on linux so if you are not it's > probably slightly different on windows > but not much. I just put my .Rprofile > file ( you need the . in front but I had to take it > off when I sent you ) in my /opt/mark ( hiome > dorectory on linux ) directory. > > generally speaking, when you ask questions > like that, be sure to specify your OS or > people ( not me ) will get annoyed. > > i you start up R, the .Rprofile should > get called and the functions in your > arun.R file should be available to you. > good luck. > > > I';m no expert so hopefully someone else > will reply also ( that's why i emailed > privately ). > > > > >Hi all, > > > >I wrote some user defined function for my own. Now I want to get a > mechanism > >so that every time I start R, those function will automatically be loaded > in > >R without manually copying pasting. Can gurus here pls tell me how to do > >that? Or I have to build my own packages bundled with those functions. > >However I am not familiar in writing R package yet. > > > >Regards, > > > > [[alternative HTML version deleted]] > > > >__ > >R-help@r-project.org mailing list > >https://stat.ethz.ch/mailman/listinfo/r-help > >PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html<http://www.r-project.org/posting-guide.html> > >and provide commented, minimal, self-contained, reproducible code. > -- -- Arun Kumar Saha, M.Sc. Statistical Arbitrage Quant RISK MANAGEMENT DIVISION Transgraph Consulting [www.transgraph.com] Hyderabad, INDIA Contact # Home: (91-033) 25558038 [CALCUTTA] Home: (91-040) 40033010 [HYDERABAD] Office: (91-040) 30685012 Ext. 17 [email preferred] FAX: (91-040) 55755003 [if absolutely necessary] Mobile: 919989122010 E-Mail: [EMAIL PROTECTED] [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.
[R] Loading user defined functions autometically each time I start R
Hi all, I wrote some user defined function for my own. Now I want to get a mechanism so that every time I start R, those function will automatically be loaded in R without manually copying pasting. Can gurus here pls tell me how to do that? Or I have to build my own packages bundled with those functions. However I am not familiar in writing R package yet. Regards, [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Fetching datapoints from a Time Series
Hi all, I have a time series like that : DateValue 01/03/05 -0.008471364 01/04/05 -0.008153802 01/05/05 -0.000780031 01/06/05 -0.000130064 01/07/05 -0.000650576 01/08/05 -0.000130166 01/10/05 -0.004174282 01/11/05 0.01027384 01/12/05 -0.006099558 01/13/05 -0.009811054 01/14/05 0.000657073 I import this dataset as a zoo object. Now I want to fetch the dataset between two particular dates. For example if I want to get data point between 01/02/05 and 01/09/05 I should get : 01/03/05 -0.008471364 01/04/05 -0.008153802 01/05/05 -0.000780031 01/06/05 -0.000130064 01/07/05 -0.000650576 01/08/05 -0.000130166 Can anyone please tell me how to do that? Is there any function to do that? Regards, [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Need help on "date"
This mail is continuation of my previous one. i have some raw data from Excel which was carried to R: data = read.delim(file="clipboard", header=T) > data Date Price 1 09/01/05 365 2 09/02/05 360 3 09/03/05 360 4 09/05/05 370 5 09/06/05 370 6 09/08/05 365 7 09/09/05 365 8 09/10/05 365 9 09/12/05 365 10 09/13/05 360 11 09/14/05 360 12 09/15/05 360 and, using the input from R-help I exctracted day, month, and year, from "Date" year = as.numeric(format(as.Date(data[,1],"%m/%d/%y"),"%Y")) month = as.numeric(format(as.Date(data[,1],"%m/%d/%y"),"%m")) day = as.numeric(format(as.Date(data[,1],"%m/%d/%y"),"%d")) Now I want to create a date-variable and put it in actual data: library(date) data1 = cbind(mdy.date(month, day, year), data[,-1]) > data1 [,1] [,2] [1,] 16680 365 [2,] 16681 360 [3,] 16682 360 [4,] 16684 370 [5,] 16685 370 [6,] 16687 365 [7,] 16688 365 [8,] 16689 365 [9,] 16691 365 [10,] 16692 360 [11,] 16693 360 [12,] 16694 360 However this is not that thing what I wanted, first column has been jumbled, it is not in actual date format. Can anyone tell me what should i do here? Regards, On 9/18/07, Arun Kumar Saha <[EMAIL PROTECTED]> wrote: > > Dear all, > > I have a variable 'x' like that: > > > x > [1] "2005-09-01" > > Here, 2005 represents year, 09 month and 01 day. > > Now I want to create three variables naming: y, m, and d such that: > > y = 2005 > m = 09 > d = 01 > > can anyone tell me how to do that? > > Regards, > > [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Need help on "date"
Dear Jeffrey, Your syntax looks very extraordinary to me. I would be very happy if you can explain this notation. Regards, On 9/18/07, Jeffrey Robert Spies <[EMAIL PROTECTED]> wrote: > > And one using regular expressions: > > x <- "2005-09-01" > pattern <- '([[:digit:]]{4})-([[:digit:]]{2})-([[:digit:]]{2})' > y <- sub(pattern, '\\1', x) > m <- sub(pattern, '\\2', x) > d <- sub(pattern, '\\3', x) > > -- Jeff. > > On Sep 18, 2007, at 5:00 AM, Arun Kumar Saha wrote: > > > Dear all, > > > > I have a variable 'x' like that: > > > >> x > > [1] "2005-09-01" > > > > Here, 2005 represents year, 09 month and 01 day. > > > > Now I want to create three variables naming: y, m, and d such that: > > > > y = 2005 > > m = 09 > > d = 01 > > > > can anyone tell me how to do that? > > > > Regards, > > > > [[alternative HTML version deleted]] > > > > __ > > R-help@r-project.org mailing list > > https://stat.ethz.ch/mailman/listinfo/r-help > > PLEASE do read the posting guide http://www.R-project.org/posting- > > guide.html > > and provide commented, minimal, self-contained, reproducible code. > > [[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] Need help on "date"
Dear all, I have a variable 'x' like that: > x [1] "2005-09-01" Here, 2005 represents year, 09 month and 01 day. Now I want to create three variables naming: y, m, and d such that: y = 2005 m = 09 d = 01 can anyone tell me how to do that? Regards, [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Function to get a sequence of months
Hi all, I am looking for a function for following calculation. start.month = "July" end.month = "January" months = f(start.month, end.month, by=1) * f is the function that I am looking for. Actually I want to get months = c("July", "August",.."January") If start.month = 6 and end.month = 1 then I could use (not properly) seq() function and then I would get month as a vector with elements 6,5,4,3,2, and 1 by choosing "by=-1". Is there any function which can subsitute the seq() function in my case? Regards, [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.