Could not find the "DouglasPeuckerEpsilon" in R language - r

I'm trying to use Douglas Peucker's algorithm in R.
By executing the following code, I get the following error:
Px <- (1:100)/10
Py <- dnorm(Px,3,1)+dnorm(Px,7,1)+Px/10
### Example 1
### Simplification using epsilon
par(mfrow=c(2,2))
plot(Px,Py,type="l")
plot(DouglasPeuckerEpsilon(Px,Py,0.01),type="b",col=4)
Could not find the "DouglasPeuckerEpsilon" in R language.
This is because I do not have the DP package installed?

Perform the following Steps:
Install the package (kmlShape)
Then load the Library (kmlShape)
install.packages("kmlShape")
library("kmlShape")
Then run plot(DouglasPeuckerEpsilon(Px,Py,0.01),type="b",col=4) for Ramer-Douglas-Peucker algorithm (RDP)

Related

R Studio installing packages and functions

I'm trying to use copula on Rmd but am coming across a lot of issues with the formula:
Error: could not find function "pobs"
For example, I have already installed the packages before by typing this:
install.packages("VineCopula")
u <- pobs(as.matrix(cbind(cree,yahoo)))[,1]
v <- pobs(as.matrix(cbind(cree,yahoo)))[,2]
selectedCopula <- BiCopSelect(u,v,familyset=NA)
selectedCopula
Code based off this link: https://www.r-bloggers.com/modelling-dependence-with-copulas-in-r/
It seems you didn't load the VineCopula package before using it. install.packages is used to install packages, library is used to load them into your R session. This is what you should run:
library(VineCopula)
u <- pobs(as.matrix(cbind(cree,yahoo)))[,1]
v <- pobs(as.matrix(cbind(cree,yahoo)))[,2]
selectedCopula <- BiCopSelect(u,v,familyset=NA)
selectedCopula
You have installed the library in your code but haven't referenced it hence the functions are not available.
An example of this for reference would be installing an application on your phone; it gets installed but you need to open it in order to use it.
By using install.packages, the package was downloaded in your default home folder. You can change that using install.packages('package_name',lib.loc='path_on_your_system').
It is also a good practice to specify the library path before loading it.
.libPaths('path_on_your_system')
library(VineCopula)
u <- pobs(as.matrix(cbind(cree,yahoo)))[,1]
v <- pobs(as.matrix(cbind(cree,yahoo)))[,2]
selectedCopula <- BiCopSelect(u,v,familyset=NA)
selectedCopula
Let me know if this explanation helps.

Error in `freeParam` in fitting of normal copula [R]

I am using R version 3.3.2 and the package copula version 0.999-15 to evaluate the fitting of the normal copula to my data. My data and code are:
Data: https://www.dropbox.com/s/tdg8bfzmy4nd1dd/jumps.dat?dl=0
library(copula)
data <- read.csv(file="jumps.dat", head=F, sep="")
cop_model <- ellipCopula("normal", dim = 2)
m <- pobs(as.matrix(data))
fitCopula(cop_model, m, method = 'mpl')
After I run the code I receive the following error:
Error in `freeParam<-`(`*tmp*`, value = estimate) : the length of 'value' is not equal to the number of free parameters
Calls: fitCopula ... fitCopula.ml -> fitCopStart -> fitCopula.icor -> freeParam<-
Execution halted
I have no idea what is happening here. The fitting for Clayton and Gumbel is pretty fine. Searching for similar errors in the web, I have found nothing. Reading the documentation (https://www.rdocumentation.org/packages/copula/versions/0.999-15/topics/fitCopula?) for some specificity for ellipCopula, I have found an specific option for posDef, but it did not returns any solution at all.
Old question, but I found this, so will share my solution.
Try to run the following, this is a minimum working example:
library(copula)
print("-----------")
mycop <- ellipCopula("normal", dim=4)
data <- matrix(runif(400), nrow=4)
fitCopula(mycop, t(data))
print("-----------")
For me, this works fine if I open R and type in the lines one by one, but fails if I run as a script with Rscript. The solution is that you need library(methods) as well.
For some reason this worked with copula v0.999-v14, but was broken by v0.999-v16. Alas.

exponential matrix function definition?

I am running a machine that only has R 2.10 and cannot be updated (this is a fact: it cannot be changed).
I need to use the "expm" package's functionality for taking the kth power of a matrix (it is the function %^%) but I cannot figure out how to copy the source code, since the earliest version of this package was made for versions later than R 2.10. On R, after installing the expm package, running:
library(expm)
getAnywhere('%^%')
gives me the source code, but then when I copy this source code in the form %^% <- *source code*, I get the error
Error in stopifnot(is.numeric(x) || is(x, "dMatrix"), length(d <- dim(x)) == :
object 'x' not found
Can anyone help me figure out how to use the original implementation of %^% via source code?
Use backticks ` to denote a non-syntactic name.
`%^%` <- ....

Are there known compatibility issues with R package mgcv? Are there general rules for compatibility?

I use R version 2.15.1 (2012-06-22) and mgcv version 1.7-22
I load the following set of packages in R:
library(sqldf)
library(timeDate)
library(forecast)
library(xts)
library(tseries)
library(MASS)
library(mgcv)
It happens that I can not run a simple model (I omit the code). Even the sample code taken from the help pages:
dat = gamSim(1,n=400,dist="normal",scale=2)
b = gam(y~s(x0)+s(x1)+s(x2)+s(x3),data=dat)
gives an error:
Error in qr.qty(qrc, sm$S[[l]]) :
NA/NaN/Inf in foreign function call (arg 5)
In addition: Warning message:
In smoothCon(split$smooth.spec[[i]], data, knots, absorb.cons, scale.penalty = scale.penalty, :
number of items to replace is not a multiple of replacement length
Note that everything works fine, if I just load the package mgcv and then use the sample code right away. It also works if I just load all the packages and run the sample code. It just does not work if I
load all packages
do some file reading, sqldf statements, ts operations and some models from package forecast.
if I then apply GAM, it does not work anymore.
Apparently the variable definitions in the general environment mess up the functioning of the package.
Are there any known issues? Are there general rules that I have to obey if I load various packages? Can I write code that "disturbed" the package mgcv?
# Richard there are 2 GAM related packages: gam and mgcv. Loading both libraries at the same time usually causes a conflict.
Loading mgcv as the first package solved my problem ... strange but true.

Interface between Octave and R

Could anyone kindly update the status on the interface between Octave and R? ROctave package was developed in 2002, but no new updates after that. I like to call some functions from Octave in R such as "roots". How to do it?
Thanks for your help.
Expanding on chl's point of using R directly, you can also consider these CRAN packages which explicitly bring Octave functionality to R:
pracma
signal
And then there is the old but trusted R / Octave cheat sheet.
Edit in 2012 There is now also an emerging CRAN package RcppOctave which permits R to execute Octave code. The package is at a reasonably early stage, and works so far only on Unix.
I do not know of any active R/octave project, but if you're just after finding roots for a given polynomial you can use one of the polynom or PolynomF package:
Here is an example with P(x)= 6 + 5*x + 4*x^2 + 3*x^3 + 2*x^4 + x^5.
In octave,
octave[2] > p = 1:6;
octave[3] > roots(p)
ans =
0.55169 + 1.25335i
0.55169 - 1.25335i
-1.49180 + 0.00000i
-0.80579 + 1.22290i
-0.80579 - 1.22290i
In R,
> library(polynom)
> p <- polynomial(6:1)
> pz <- solve(p)
> pz
[1] -1.491798+0.000000i -0.805786-1.222905i -0.805786+1.222905i
[4] 0.551685-1.253349i 0.551685+1.253349i
I found this CRAN package called RcppOctave:
"Direct interface to Octave. The primary goal is to facilitate the port of Matlab/Octave scripts to R. The package enables to call any Octave functions from R and as well as browsing their documentation, passing variables between R and Octave, using R core RNGs in Octave, which ensure stochastic computations are also reproducible."
http://cran.r-project.org/web/packages/RcppOctave/index.html

Resources