Re: [R] Unable to pass Object Arguments to UniRoot()
yeah I found the error pls feel free to delete post! -- View this message in context: http://r.789695.n4.nabble.com/Unable-to-pass-Object-Arguments-to-UniRoot-tp4710938p4711015.html Sent from the R help mailing list archive at Nabble.com. __ 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.
[R] Unable to pass Object Arguments to UniRoot()
Hi there, I'd like to be able to pass an entire object to uniroot() as one of the arguments. Unfortunately to recreate my precise error would be rather involved. So I present a simplified version below: To create a structured object let the output from the lm() function use this simple code: year - c(2000 , 2001 , 2002 , 2003 , 2004) rate - c(9.34 , 8.50 , 7.62 , 6.93 , 6.60) fit - lm(rate ~ year) When I try to pass this to uniroot: OptLam-uniroot(f=LamOpt, interval=c(0.0001,120), tol=0.0001, MLEObj=fit ) I get the following error Error in f(lower, ...) : unused argument(s) (MLEObj = list(coefficients = c(1419.207999, -0.7049952), residuals = This seems to be specific to uniroot I have tested my own functions and they happily accept objects like fit. The function LamOpt is not supposed to work with a object created by lm() I've just used lm() as a simple example so don't worry about the results that LamOpt produces, if I can pass one object like fit to uniroot then I assume I can pass any object. It seems that uniroot must be expecting an object of a certain size, would it therefore be possible to use something analogous to pointers in c/c++ and pass the object by reference so only a pointer to the object is passed rather than the object itself? LamOpt-function(lambda,MLEobj){ x - c(3,6,9,12,15,18,21,24,30,36,48,60,72,84,96,108,120) #MLEObj-kemfit ## Cross-sectional model (Nelson and Siegel) #lambda - 0.0609 h2 - function(x){(1-exp(-lambda*x))/(lambda*x)} h3 - function(x){((1-exp(-lambda*x))/(lambda*x)) - exp(-lambda*x)} X=cbind(rep(1,m), h2(x), h3(x)) #obs Z - matrix(as.list(X), ncol = 3) MLEObj$par$Z=Z kf_iter = MARSSkf(MLEobj) return(-kf_iter$logLik) } Thanks Baz -- View this message in context: http://r.789695.n4.nabble.com/Unable-to-pass-Object-Arguments-to-UniRoot-tp4710938.html Sent from the R help mailing list archive at Nabble.com. __ 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] Unable to pass Object Arguments to UniRoot()
Thanks Krishna! You are correct, but even when I manually add m-17 just after x I still get the same error? Uniroot falls over when it tries to take in the argument MLEobj=fit, thus I think the error is occurring before LamOpt() gets called by uniroot(). Which is why the error you mentioned didn't show up before and thus unfortunately the original error still persists. Baz -- View this message in context: http://r.789695.n4.nabble.com/Unable-to-pass-Object-Arguments-to-UniRoot-tp4710938p4710943.html Sent from the R help mailing list archive at Nabble.com. __ 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] Confused by code?
Thanks Rui Barrudas and Peter Alspach, I understand better now: x-matrix(c(1,0,0,0,2,0,0,0,2),nrow=3) y-matrix(c(7,8,9,1,5,10,1,1,0),nrow=3) z-matrix(c(0,1,0,0,0,0,6,0,0),nrow=3) x[z]-y[z] viewData(x) produces an x matrix 7 0 0 0 2 0 0 10 2 which makes sense the first element of y 7 is inserted into z in slot x[1] and the and 6th element of y 10 is slotted into the x[6]. However the original code runs like this: mI- mRU(de.d, de.nP)de.CR mPV[mI]mP[mI] where mPv and MP are both (de.d, de.nP) matrices. and mRUlt;-function(m,n){ return(array(runif(m*n), dim=c(m,n))) } i.e. it returns an array of m*n random numbers uniformly distributed between 0 and 1. de.CR is a fixed value say 0.8. So mIlt;- mRU(de.d, de.NP)de.CR returns a de.d*de.nP array where each element is 1 is its more than 0.8 and zero otherwise. So in this case element mPv[1] will be repeatedly filled with the value of mP[1] and all other elements will remain unaffected? Is this correct? If so I am still confused as this is not what I thought was supposed to by happening but I know that the code overall does its job correctly? -- View this message in context: http://r.789695.n4.nabble.com/Confused-by-code-tp4643946p4644010.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] Confused by code?
x-matrix(c(1,0,0,0,1,0,0,0,1),nrow=3) y-matrix(c(0,0,0,1,0,0,1,1,0),nrow=3) z-matrix(c(0,1,0,0,1,0,1,0,0),nrow=3) x[z]-y[z] The resultant matrix x is all zeros except for the last two diagonal cells which are 1's. While y is lower triangualr 0's with the remaining cells all ones. I really don't understand how this deceptively simple looking piece of code is giving that result can someone explain please. I'm obviously missing something pretty basic so please keep your answer suitably basic. -- View this message in context: http://r.789695.n4.nabble.com/Confused-by-code-tp4643946.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] Server R
Thanks Michael, I presume that the command sudo apt-get updatewill do the trick but am emailing the appropriate group to get more background on what packages are included in the latest ubuntu version of R.Date: Mon, 17 Sep 2012 05:43:56 -0700 From: ml-node+s789695n4643369...@n4.nabble.com To: h_a_patie...@hotmail.com Subject: Re: Server R On Sun, Sep 16, 2012 at 9:42 PM, Bazman76 [hidden email] wrote: Hi there, I used the command sudo apt-get install r-base to install R on an EC2 server as shown below: http://www.r-bloggers.com/ec2-micro-instance-of-rstudio/ It works but the version of R installed is: R.version.string [1] R version 2.12.1 (2010-12-16) I want to the latest version with package parallel included. How can I change the commend to ensure the latest version of R is installed? I presume EC2 runs Ubuntu: http://cran.r-project.org/bin/linux/ubuntu/README Cheers, Michael -- View this message in context: http://r.789695.n4.nabble.com/Server-R-tp4643319.html Sent from the R help mailing list archive at Nabble.com. __ [hidden email] 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. __ [hidden email] 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. If you reply to this email, your message will be added to the discussion below: http://r.789695.n4.nabble.com/Server-R-tp4643319p4643369.html To unsubscribe from Server R, click here. NAML -- View this message in context: http://r.789695.n4.nabble.com/Server-R-tp4643319p4643390.html Sent from the R help mailing list archive at Nabble.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] Server R
Hi there, I used the command sudo apt-get install r-base to install R on an EC2 server as shown below: http://www.r-bloggers.com/ec2-micro-instance-of-rstudio/ It works but the version of R installed is: R.version.string [1] R version 2.12.1 (2010-12-16) I want to the latest version with package parallel included. How can I change the commend to ensure the latest version of R is installed? -- View this message in context: http://r.789695.n4.nabble.com/Server-R-tp4643319.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] Parallel R
Hi there, I have a largish optimisation problem (10 years of daily observations). I want to optimise between 4 and 6 parameters. I'd like to utilise parallel computing if I can as I will have to run it with different starting values etc. I have a quad core PC with 16GB ram running windows 7. Having done a little reading it seems the two best options for me are: 1.) Use the academic version of REvolution R enterprise which will let me run the code in parallel on my own PC. 2.) Or install Unubtu and use Segue and Amazon EC2 (or some equivalent). Just to get an idea how much faster is option 2 liable to be (given that its slightly more difficult to set up). Is it realistic to have a dual boot on my PC? Thanks Baz -- View this message in context: http://r.789695.n4.nabble.com/Parallel-R-tp4643175.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] Parallel R
Thanks for that I hadn't realised parallel could run on windows Pc's. The code is differential evolution but its not part of a package. Still I would like to be able to use cloud computing if possible, any thoughts on the easiest way to achieve that using a windows based PC? Found this blog which seems to give pretty clear instructions: http://travisnelson.net/2011/05/05/ec2-micro-instance-of-rstudio/ and was also recommended cloudRmpi package. Have you experience with either of these? -- View this message in context: http://r.789695.n4.nabble.com/Parallel-R-tp4643175p4643186.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] Difference between spec.pgram spec.ar
OK so I neeed to understan better what it it they are trying to measure. I understood (incorrectly it seems) that they were simply different methods to get the same result? -- View this message in context: http://r.789695.n4.nabble.com/Difference-between-spec-pgram-spec-ar-tp4541358p4542985.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] Difference between spec.pgram spec.ar
oops sorry n 08.04.2012 20:39, Bazman76 wrote: Hi there, Can someone explain what the difference between spec.pgram and spec.ar is? I understand that they attempt to do the same thing one using an AR estimation of the underlying series to estimate teh sensity the other using the FFT. However when applied to teh same data set they seem to be giving quite different results? http://r.789695.n4.nabble.com/file/n4541358/R_example.jpg Clearly the spec.ar() result seems to be smoothed but the results are also generally very different only really sharing the peak as the frequencies go towards zero. Can someone please explain why these two functions produce such different results on the same data set? « [hide part of quote] *Because they really measure different things? Why do you expect to get the same output in time as well as in frequency domain? * Uwe Ligges code shown below: library(waveslim) vols=read.csv(file=C:/Users/ocuk/My Documents/Abs Vol.csv, header=TRUE, sep=,) x-ts(vols[,1]) #x ## LA(8) vol.la8- mra(x, la8, 4, modwt) names(vol.la8)- c(d1, d2, d3, d4, s4) ## plot multiresolution analysis of IBM data #par(mfcol=c(6,1), pty=m, mar=c(5-2,4,4-2,2)) par(mfcol=c(3,1), pty=m, mar=c(5-2,4,4-2,2)) plot.ts(x, axes=F, ylab=, main=(abs rtns)) #for(i in 1:5) # plot.ts(vol.la8[[i]], axes=F, ylab=names(vol.la8)[i]) #axis(side=1, at=seq(0,1600,by=100), # labels=c(0,,200,,400,,600,,800,,1000,,1200,,1400,,1600)) spectrum(vol.la8[[1]]) specx- spec.ar(x) -- [hidden email] 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. « [hide part of quote] *OK so I neeed to understan better what it it they are trying to measure. I understood (incorrectly it seems) that they were simply different methods to get the same result? * -- View this message in context: http://r.789695.n4.nabble.com/Difference-between-spec-pgram-spec-ar-tp4541358p4543140.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] Difference between spec.pgram spec.ar
Yes I agree, there may be something pathalogical in the way at least one of the models handles the data. That's why I was trying to get a better handle on how the two functions spec.prgm() and spec.ar() work. The data has been processed by a wavelet analysis, so what you are seeing as the raw data is in fact the level1 details from the wavelet anlaysis. In theory this should only have high frequency components, that was why I am so surpirsed to see such strong components at low frequencies. That is not a R quesiton per se, but surely how spec.prgm() and spec.ar() work is? -- View this message in context: http://r.789695.n4.nabble.com/Difference-between-spec-pgram-spec-ar-tp4541358p4543191.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] Error in xy.coords(x, NULL, log = log) : (list) object cannot be coerced to type 'double'
that's it! Thank you. -- View this message in context: http://r.789695.n4.nabble.com/Error-in-xy-coords-x-NULL-log-log-list-object-cannot-be-coerced-to-type-double-tp4524046p4541340.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] Difference between spec.pgram spec.ar
Hi there, Can someone explain what the difference between spec.pgram and spec.ar is? I understand that they attempt to do the same thing one using an AR estimation of the underlying series to estimate teh sensity the other using the FFT. However when applied to teh same data set they seem to be giving quite different results? http://r.789695.n4.nabble.com/file/n4541358/R_example.jpg Clearly the spec.ar() result seems to be smoothed but the results are also generally very different only really sharing the peak as the frequencies go towards zero. Can someone please explain why these two functions produce such different results on the same data set? code shown below: library(waveslim) vols=read.csv(file=C:/Users/ocuk/My Documents/Abs Vol.csv, header=TRUE, sep=,) x-ts(vols[,1]) #x ## LA(8) vol.la8 - mra(x, la8, 4, modwt) names(vol.la8) - c(d1, d2, d3, d4, s4) ## plot multiresolution analysis of IBM data #par(mfcol=c(6,1), pty=m, mar=c(5-2,4,4-2,2)) par(mfcol=c(3,1), pty=m, mar=c(5-2,4,4-2,2)) plot.ts(x, axes=F, ylab=, main=(abs rtns)) #for(i in 1:5) # plot.ts(vol.la8[[i]], axes=F, ylab=names(vol.la8)[i]) #axis(side=1, at=seq(0,1600,by=100), # labels=c(0,,200,,400,,600,,800,,1000,,1200,,1400,,1600)) spectrum(vol.la8[[1]]) specx - spec.ar(x) -- View this message in context: http://r.789695.n4.nabble.com/Difference-between-spec-pgram-spec-ar-tp4541358p4541358.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] Error in xy.coords(x, NULL, log = log) : (list) object cannot be coerced to type 'double'
Hi there, When I run the code below I get the error Error in xy.coords(x, NULL, log = log) :(list) object cannot be coerced to type 'double' Any tips how I can resolve this? library(waveslim) vols=read.csv(file=C:/Users/ocuk/My Documents/Abs Vol.csv, header=TRUE, sep=,) x-c(vols[,1]) #x #data(ibm) av.la8 - mra(x, la8, 4, modwt) #names(av.la8) - c(d1, d2, d3, d4,d5,d6, d7, d8,s8) names(av.la8) - c(d1, d2, d3, d4,s4) #par(mfcol=c(10,1), pty=m, mar=c(5-2,4,4-2,2)) par(mfcol=c(6,1), pty=m, mar=c(5-2,4,4-2,2)) plot.ts(av.la8, axes=F, ylab=, main=abs vol) *Error in xy.coords(x, NULL, log = log) : (list) object cannot be coerced to type 'double'* #for(i in 1:9) for(i in 1:5) + plot.ts(av.la8[[i]], axes=F, ylab=names(av.la8)[i]) axis(side=1, at=seq(0,1541,by=100), + labels=c(0,,200,,400,,600,,800,,1000,,1200,,1400,)) -- View this message in context: http://r.789695.n4.nabble.com/Error-in-xy-coords-x-NULL-log-log-list-object-cannot-be-coerced-to-type-double-tp4524046p4524046.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] a question on autocorrelation acf
http://r.789695.n4.nabble.com/file/n4164630/R_example.xlsx R_example.xlsx Hi there, I attach an excel file which I use to produce the data. It simulates a simple AR(1) process y_t=0.5y_{t-1}+z_t. In column E I have cut and paste values so that we can compare like with like. When I run the acf() on these values, it shows 3 significant lags. When I run the pacf() it shows one very strong correlation of 0.3 at lag 1, and a smaller one at lag 2 of around 0.05. Now according to the theory the pacf() results should give the correct exponents for the lags. This is a pure AR(1) process so the results should be 0.5 on lag 1 and statistically insignificant else where? I have tried if for several realisations of the white noise term and the results are qualatively similar and is disagreement with the theory. Kind Regards Baz -- View this message in context: http://r.789695.n4.nabble.com/a-question-on-autocorrelation-acf-tp2076280p4164630.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] a question on autocorrelation acf
Hi there, I am wondering how R calculates the acf too? I have a data set of approx 1500 returns when I calculate the lag 1 autocorrelation in excel I get a value of -0.4 but in R its approximately -0.18? I have cross checked with PC give and PC give agrees with excel? I'm sure its just some kind of scaling but it would be nice to resolve this discrepency! Baz -- View this message in context: http://r.789695.n4.nabble.com/a-question-on-autocorrelation-acf-tp2076280p4161818.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] a question on autocorrelation acf
Hi there, I have now cheked the results against pc give and the excel add-in poptools. Poptools and pc give get the same answer but R is quite different especially for the acf and pacf()? I looked at the book you recommended on p390 itshows the formulas and they look pretty standard. However looking at the code that you sent the acf function does not seem to be being calculated as shown in the book? At no point is the series mean calculated? unless the variable x is already demeaned in some way ie. there is some preprocessing that I need to see to fully understand? -- View this message in context: http://r.789695.n4.nabble.com/a-question-on-autocorrelation-acf-tp2076280p4163021.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] Split an array into arbirtary sizes
sorry! vols=read.csv(file=C:/Documents and Settings/Hugh/My Documents/PhD/QuickDirtyVols.csv + , header=TRUE, sep=,) x-ts(vols[,2]) x so I have an ts object of 500 elements. I want to be able to split the array into say two parts of 250? How can I do it? I want to keep the elements in the same order -- View this message in context: http://r.789695.n4.nabble.com/Split-an-array-into-arbirtary-sizes-tp3948938p3949426.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] Split an array into arbirtary sizes
Hi there, I have a ts object that I would like wo split into arbirary sizes. Can'tfind how to do this? I realise its probaly very simple buy I can't sem to find the right function? -- View this message in context: http://r.789695.n4.nabble.com/Split-an-array-into-arbirtary-sizes-tp3948938p3948938.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] Correllogram of Daily Time Series
Hi there, What is the best way to get a time series of daily stock price observations into R (from excel). The time series are daily but there are spaces for w/e's and holidays etc. So I am not sure a ts object will be suitable but I am not sure what I should use? What ever package you recemmned i need to be able to run a corrolelagram. Thanks Hugh -- View this message in context: http://r.789695.n4.nabble.com/Correllogram-of-Daily-Time-Series-tp3944094p3944094.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] Correllogram of Daily Time Series
I did it using the code below thank you. Will the fact I have used a ts object but the observations are not really equally spaced invalidate the results? vols=read.csv(file=C:/Documents and Settings/Hugh/My Documents/PhD/Swaption vols.csv + , header=TRUE, sep=,) x-ts(vols[,2]) x acf(x) -- View this message in context: http://r.789695.n4.nabble.com/Correllogram-of-Daily-Time-Series-tp3944094p3945927.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] Confusing piece of R code
m0-epxression((4*theta1*theta2-theta3^2)/(2*x*theta3^2)-0.5*theta1*x) params-all.vars(m0) this reads all the params from m0 so theta1,2 and 3 correct? params-params[-which(params==x)] checks which params are multiplied by x? np-length(params) for(i in 1:6){ esp-get(sprintf(m%d,i-1))what does get do? sprinf formats strings? so what is it doinf here? assign(sprintf(m%d,i),D(esp,x)) what doeas assign so what in sprintf doing and what does D do? } really really confused? -- View this message in context: http://r.789695.n4.nabble.com/Confusing-piece-of-R-code-tp3656660p3656660.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] Confusing piece of R code
thanks sarah -- View this message in context: http://r.789695.n4.nabble.com/Confusing-piece-of-R-code-tp3656660p3656898.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] Reading Data from mle into excel?
Can I use sink() to transfer the MLE results which are a S4 type object to a text file? Can someone show me how to do this? -- View this message in context: http://r.789695.n4.nabble.com/Reading-Data-from-mle-into-excel-tp3545569p3563385.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] Reading Data from mle into excel?
Hi Greg, I have about 40 time series each of which I have to run a seperate MLE on. I will be experimenting with different starting values for the parameters etc, so some way to automate the process will be useful. I think I can just about do this part (if you see the code above) but as I can't do the second part I can't check it properly. The second part I simply want to take the results of all the MLE calculation: the parameter estimates, there standard errors and the actual value of the likilihood ratio so that I can compare them and present them to my supervisor. The last part must be done in excel as my supervisor has not been converted to R yet. Kind Regards Hugh Date: Tue, 31 May 2011 08:24:08 -0700 From: ml-node+3563453-1045326083-236...@n4.nabble.com To: h_a_patie...@hotmail.com Subject: Re: Reading Data from mle into excel? The sink function will write to a file what normally shows up on the screen after running some code. So while it is possible to use it to capture the output of the mle command and read the results into excel, I don't see anything useful that you could then do with it in excel. If you can tell us more about what your ultimate goal is, what you want to do with the results, then we can give better advice on either how to get the pieces you want into excel, or probably better, how do accomplish what you want in R without needing to involve excel at all. -- Gregory (Greg) L. Snow Ph.D. Statistical Data Center Intermountain Healthcare [hidden email] 801.408.8111 -Original Message- From: [hidden email] [mailto:r-help-bounces@r- project.org] On Behalf Of Bazman76 Sent: Tuesday, May 31, 2011 9:04 AM To: [hidden email] Subject: Re: [R] Reading Data from mle into excel? Can I use sink() to transfer the MLE results which are a S4 type object to a text file? Can someone show me how to do this? -- View this message in context: http://r.789695.n4.nabble.com/Reading- Data-from-mle-into-excel-tp3545569p3563385.html Sent from the R help mailing list archive at Nabble.com. __ [hidden email] 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. __ [hidden email] 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. If you reply to this email, your message will be added to the discussion below:http://r.789695.n4.nabble.com/Reading-Data-from-mle-into-excel-tp3545569p3563453.html To unsubscribe from Reading Data from mle into excel?, click here. -- View this message in context: http://r.789695.n4.nabble.com/Reading-Data-from-mle-into-excel-tp3545569p3563495.html Sent from the R help mailing list archive at Nabble.com. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Reading Data from mle into excel?
thanks for all your help I have taken a slightly different route but I think I am getting there library(plyr) #setwd(C:/Documents and Settings/Hugh/My Documents/PhD) #files-list.files(C:/Documents and Settings/Hugh/My Documents/PhD/,pattern=Swaption Vols.csv) #vols - lapply(files, read.csv, header = TRUE) vols=read.csv(file=C:/Documents and Settings/Hugh/My Documents/PhD/Swaption vols.csv + , header=TRUE, sep=,) dcOU-function(x,t,x0,theta,log=FALSE){ Ex-theta[1]/theta[2]+(x0-theta[1]/theta[2])*exp(-theta[2]*t) Vx-theta[3]^2*(1-exp(-2*theta[2]*t))/(2*theta[2]) dnorm(x,mean=Ex,sd=sqrt(Vx),log=log) } OU.lik-function(theta1,theta2,theta3){ n-length(X) dt-deltat(X) -sum(dcOU(X[2:n],dt,X[1:(n-1)],c(theta1,theta2,theta3),log=TRUE)) } require(stats4) require(sde) nc=ncol(vols) for(i in 2:nc){ X-ts(vols[,i]) mle(OU.lik,start=list(theta1=1,theta2=1,theta3=1), method=L-BFGS-B,lower=c(-Inf,-Inf,-Inf),upper=c(Inf,Inf,Inf))-fit summary(fit) } right now the summary(fit) gives the summary results for the 53rd column so the code is working correctly. How can I save these summary results in an array or datatable on each loop? -- View this message in context: http://r.789695.n4.nabble.com/Reading-Data-from-mle-into-excel-tp3545569p3547236.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] Reading Data from mle into excel?
Hi there, I ran the following code: vols=read.csv(file=C:/Documents and Settings/Hugh/My Documents/PhD/Swaption vols.csv , header=TRUE, sep=,) X-ts(vols[,2]) #X dcOU-function(x,t,x0,theta,log=FALSE){ Ex-theta[1]/theta[2]+(x0-theta[1]/theta[2])*exp(-theta[2]*t) Vx-theta[3]^2*(1-exp(-2*theta[2]*t))/(2*theta[2]) dnorm(x,mean=Ex,sd=sqrt(Vx),log=log) } OU.lik-function(theta1,theta2,theta3){ n-length(X) dt-deltat(X) -sum(dcOU(X[2:n],dt,X[1:(n-1)],c(theta1,theta2,theta3),log=TRUE)) } require(stats4) require(sde) set.seed(1) #X-sde.sim(model=OU,theta=c(3,1,2),N=1,delta=1) mle(OU.lik,start=list(theta1=1,theta2=1,theta3=1), method=L-BFGS-B,lower=c(-Inf,-Inf,-Inf),upper=c(Inf,Inf,Inf))-fit summary(fit) #ex3.01 R prof-profile(fit) par(mfrow=c(1,3)) plot(prof) par(mfrow=c(1,1)) vcov(fit) I run the code above and I get: summary(fit) Maximum likelihood estimation Call: mle(minuslogl = OU.lik, start = list(theta1 = 1, theta2 = 1, theta3 = 1), method = L-BFGS-B, lower = c(-Inf, -Inf, -Inf), upper = c(Inf, Inf, Inf)) Coefficients: Estimate Std. Error theta1 0.03595581 0.013929892 theta2 4.30910365 1.663781710 theta3 0.02120220 0.004067477 -2 log L: -5136.327 I need to run the same analysis for 40 different time series. I want to be able to collate all the estimates of theta and the associated stadard errors and then transfer them into excel? Can someone please point me to some R code that will allow me to do this? Thanks -- View this message in context: http://r.789695.n4.nabble.com/Reading-Data-from-mle-into-excel-tp3545569p3545569.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] Error in backSpline.npolySpline(sp) : spline must be monotone
I get the following error: Error in backSpline.npolySpline(sp) : spline must be monotone Has anyone had this error before? any ideas on a workaround? vols=read.csv(file=C:/Documents and Settings/Hugh/My Documents/PhD/Swaption vols.csv + , header=TRUE, sep=,) X-ts(vols[,2]) #X dcOU-function(x,t,x0,theta,log=FALSE){ + Ex-theta[1]/theta[2]+(x0-theta[1]/theta[2])*exp(-theta[2]*t) + Vx-theta[3]^2*(1-exp(-2*theta[2]*t))/(2*theta[2]) + dnorm(x,mean=Ex,sd=sqrt(Vx),log=log) + } OU.lik-function(theta1,theta2,theta3){ + n-length(X) + dt-deltat(X) + -sum(dcOU(X[2:n],dt,X[1:(n-1)],c(theta1,theta2,theta3),log=TRUE)) + } require(stats4) Loading required package: stats4 require(sde) Loading required package: sde Loading required package: MASS Loading required package: fda Loading required package: splines Loading required package: zoo To check the errata corrige of the book, type vignette(sde.errata) Attaching package: 'sde' The following object(s) are masked _by_ '.GlobalEnv': dcOU set.seed(1) #X-sde.sim(model=OU,theta=c(3,1,2),N=1,delta=1) mle(OU.lik,start=list(theta1=1,theta2=1,theta3=1), + method=L-BFGS-B,lower=c(-Inf,-Inf,-Inf),upper=c(Inf,Inf,Inf))-fit summary(fit) Maximum likelihood estimation Call: mle(minuslogl = OU.lik, start = list(theta1 = 1, theta2 = 1, theta3 = 1), method = L-BFGS-B, lower = c(-Inf, -Inf, -Inf), upper = c(Inf, Inf, Inf)) Coefficients: Estimate Std. Error theta1 0.03595581 0.013929892 theta2 4.30910365 1.663781710 theta3 0.02120220 0.004067477 -2 log L: -5136.327 #ex3.01 R prof-profile(fit) par(mfrow=c(1,3)) plot(prof) Error in backSpline.npolySpline(sp) : spline must be monotone -- View this message in context: http://r.789695.n4.nabble.com/Error-in-backSpline-npolySpline-sp-spline-must-be-monotone-tp3545579p3545579.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] Problem with MLE
Hi there, I am trying to run the following code: dcOU-function(x,t,x0,theta,log=FALSE){ + Ex-theta[1]/theta[2]+(x0-theta[1]/theta[2])*exp(-theta[2]*t) + Vx-theta[3]^2*(1-exp(-2*theta[2]*t))/(2*theta[2]) + dnorm(x,mean=Ex,sd=sqrt(Vx),log=log) + } OU.lik-function(theta1,theta2,theta3){ + n-length(X) + dt-deltat(X) + ~sum(dcOU(X[2:n],dt,X[1:(n-1)],c(theta1,theta2,theta3),log=TRUE)) + } #ex3.01.R require(stats4) Loading required package: stats4 require(sde) Loading required package: sde Loading required package: MASS Loading required package: fda Loading required package: splines Loading required package: zoo To check the errata corrige of the book, type vignette(sde.errata) Attaching package: 'sde' The following object(s) are masked _by_ '.GlobalEnv': dcOU set.seed(123) X-sde.sim(model=OU,theta=c(3,1,2),N=1000,delta=1) T set to = 1000.00 mle(OU.lik,start=list(theta1=1,theta2=0.5,theta3=1), + method=L-BFGS-B,lower=c(-Inf,0,0))-fit Error in optim(start, f, method = method, hessian = TRUE, ...) : 'pairlist' object cannot be coerced to type 'double' but there appears to be a problem with the optimisation process? Unfortunately it's not clear to me from the error message what is going wrong? Can someone please advise. -- View this message in context: http://r.789695.n4.nabble.com/Problem-with-MLE-tp3529445p3529445.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] Problem with MLE
sorry I solved it, was a typo on my part!! -- View this message in context: http://r.789695.n4.nabble.com/Problem-with-MLE-tp3529445p3529597.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] Adding dates to time series
Hi there, I have a spreadsheet in excel which consists of first column of dates and then subsequent columns that refer to prices of different securities on those dates. (the first row contains each series name) I saved the excel file as type csv and then imported to excel using prices=read.csv(file=C:/Documents and Settings/Hugh/My Documents/PhD/Option prices.csv,header = TRUE, sep = ,) This creates the correct time series data x-ts(prices[,2]) but does not have the dates attached. However the dates refer to working days. So although in general they represent Monday-Friday this is not always the case because of holidays etc. How then can I create a time series where the dates are read in from the first column of the csv file? I can not find an example in R documentation where this is done? Thanks -- View this message in context: http://r.789695.n4.nabble.com/Adding-dates-to-time-series-tp3524679p3524679.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] Adding dates to time series
OK I got it to work thanks to your example plot(ser) however, ultiamtely a I need a stype ts object. So I used xts - as.ts(ser) xts Time Series: Start = 1 End = 732 Frequency = 1 which just gets me back to where I started with the correct raw data but no attached dates? It is possible to have a time series ts() object with irregular dates? -- View this message in context: http://r.789695.n4.nabble.com/Adding-dates-to-time-series-tp3524679p3525001.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] Adding dates to time series
additional!! I now realise that the time series created below is in the wrong order! clearly the column of dates are not being interpreted as dates by the R. Is is possible for R to read column one as dates? how can I do this? dd-data.frame(prices[,1],prices[,2]) head(dd,3) prices...1. prices...2. 1 16/12/2004 0.13675654 2 17/12/2004 0.22967560 3 20/12/2004 0.01841611 ser-with(dd,zoo(prices[,2],prices[,1])) plot(ser) xts - as.ts(xzoo) Error in as.ts(xzoo) : object 'xzoo' not found xts - as.ts(ser) xts Time Series: Start = 1 End = 732 Frequency = 1 -- View this message in context: http://r.789695.n4.nabble.com/Adding-dates-to-time-series-tp3524679p3525011.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] R won't start keeps crashing
Hi there, I am reletively new user I only dowloaded is about a week ago. I was getting along fine but last night I tried to selected save workspace. Since then R will not work And I really really need it. There are two eror massages: The first if a pop up box is Fatal error: unable to resolve data in .RData. The second is a message in the GUI: Error in loadNamespace(name) there is no package called vars. When I click to dismiss the message box the whole thing just shuts down!! I have tried reinstalling but it has made no difference. Please Help -- View this message in context: http://r.789695.n4.nabble.com/R-won-t-start-keeps-crashing-tp3516829p3516829.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] R won't start keeps crashing
OK I did a seach for the files and got: .Rdata which is 206KB Canada.Rdata which is 3kB If I click on .Rdata I get the crash. If I click on Canada.Rdata the system starts? also they are stored in different places? .Rdata is in My documents Canada.RData is in My Documents\vars\vars\data I assume I should delete .Rdata, should I also delete the other file? Where should these files be stored? I think the .RData was a result of my trying to save the workspace. Are there files being saved to the correct location? Thanks for your help -- View this message in context: http://r.789695.n4.nabble.com/R-won-t-start-keeps-crashing-tp3516829p3517115.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] R won't start keeps crashing
http://r.789695.n4.nabble.com/file/n3517669/R_crash.jpg OK when I click on the .RData file I get the screen above. Also when I start R from the desktop icon or from select if from programs I get the same result. The warning message is in focus and I can not move the focus to the GUI. When I either click to dismiss the message of click to close it the whole session shuts down. So I can not enter the commands you sugested into this corrupt version. However, when I click on the Canada.Rdata the R session starts and seems to function normally. Here are the results of the functions you requested. Not sure if they will help given that this version is workfing? sessionInfo() R version 2.13.0 (2011-04-13) Platform: i386-pc-mingw32/i386 (32-bit) locale: [1] LC_COLLATE=English_United Kingdom.1252 [2] LC_CTYPE=English_United Kingdom.1252 [3] LC_MONETARY=English_United Kingdom.1252 [4] LC_NUMERIC=C [5] LC_TIME=English_United Kingdom.1252 attached base packages: [1] stats graphics grDevices utils datasets methods base load(C:/path/to/file) Error in readChar(con, 5L, useBytes = TRUE) : cannot open the connection In addition: Warning message: In readChar(con, 5L, useBytes = TRUE) : cannot open compressed file 'C:/path/to/file', probable reason 'No such file or directory' Sorry if I gave you the wrong information previously, just let me know what you want. -- View this message in context: http://r.789695.n4.nabble.com/R-won-t-start-keeps-crashing-tp3516829p3517669.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] R won't start keeps crashing
I will read the intor to R. When closing I got a pop up asking me if I wanted to save the workspace I just clicked yes? here is what I got load(C:/Documents and Settings/Hugh/My Documents/vars/vars/data) Error in readChar(con, 5L, useBytes = TRUE) : cannot open the connection In addition: Warning message: In readChar(con, 5L, useBytes = TRUE) : cannot open compressed file 'C:/Documents and Settings/Hugh/My Documents/vars/vars/data', probable reason 'Permission denied' -- View this message in context: http://r.789695.n4.nabble.com/R-won-t-start-keeps-crashing-tp3516829p3518035.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] R won't start keeps crashing
will delete it, just wanted to try and sort out the bug -- View this message in context: http://r.789695.n4.nabble.com/R-won-t-start-keeps-crashing-tp3516829p3518036.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.