Debugging lmer function - r

I am trying to feed a hierarchical model with the lmer function from the lme4 package but lattely while trying new dataset for my code I encountered an error that occurs when the chol function is called from the monadicbase function:
"Debug location is approximate because source code is not available"
chol.default <- function(x, pivot = FALSE, LINPACK = FALSE, tol = -1, ...)
{
if (is.complex(x))
stop("complex matrices not permitted at present")
.Internal(La_chol(as.matrix(x), pivot, tol))
}
By searching within the lmer code on Github, I figured out that the chol function is called from the checkConv function within the package lme4.
My problem is that I do not understand why I get this message all the time with a specific dataset. Clearly, when I get the result at the end, it is incorrect and I don't know how to step inside the lmer code to start debugging that issue since I do not find the same arborescence at all inside my downloaded package and can't find where the used code is.
I sadly do not have a reproducible example for you but if you could give me some tips as to how to start to step in the R code of the lme4 package in debug mode that would be great !
UPDATE: showing the info I have on the error
The traceback is the following:
eval(expr, envir, enclos)
eval(substitute(browser(skipCalls = pos), list(pos = (length(sys.frames()) -
chol.default(Hessian)
chol(Hessian)

Related

forecast() function doesn't work with ETS- or STL-model

I am trying to use the forecast() function in R on different ETS- or STL-objects. I get the same error message everytime.
For example, if I try to run the code from RDocumentation.org about the forecast() function (https://www.rdocumentation.org/packages/forecast/versions/8.13/topics/forecast)
fit <- ets(window(WWWusage, end=60))
fc <- forecast(WWWusage, model=fit)
I get the following error message:
Error in forecast(fit_ets) :
'object' should be 'Arima' or 'estimate' class estimated
from arima() or estimate()
I am using RStudio and have updated to version 4.0.4.
Any ideas are much appreaciated! Thanks :-)

When using the function boxCox in R I keep getting this error "Error in as.data.frame.default(

I have the correct package alr4 which contains cars so it shouldn't be a problem with the function itself
box <- lm(Distance~Speed, data = stop)
boxCox(box)
This is the error
Error in as.data.frame.default(data, optional = TRUE) : cannot coerce class ‘"function"’ to a data.frame
The lm function runs just fine on its own, and I have used it in other analysis just fine, so it isn't an issue there. I am mostly just confused about the error and how to fix it. If you have suggestions or know why it happens that would be appreciated! Thanks

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.

Looking into the predict function in R

I am trying to understand how the SVM predict function works when using command ksvm from R package kernlab.
I tried the look into the predict function using the following commands:
methods(class="ksvm")
getAnywhere(ksvm:::predict)
However, I get the following output and not the complete predict function:
A single object matching ‘:::’ ‘ksvm’ ‘predict’ was found
It was found in the following places
package:base
namespace:base
with value
function (pkg, name)
{
pkg <- as.character(substitute(pkg))
name <- as.character(substitute(name))
get(name, envir = asNamespace(pkg), inherits = FALSE)
}
<bytecode: 0x00000000088be4f8>
<environment: namespace:base>
Warning message:
In find(x, numeric = TRUE) :
elements of 'what' after the first will be ignored
Can someone help with how to obtain the complete predict function?
Update 1:
Suggestion from misspelled worked fine on predict function for ksvm in kernlab package but doesn't seem to work on svm in e1071 package.
It throws the following error:
> getMethod("predict", "svm")
Error in getMethod("predict", "svm") :
no generic function found for 'predict'
In general, how to know which get method to use?
You were close. I was able to get the function code with getMethod("predict", "ksvm"). This answer describing S4 method dispatch was helpful. View source code for function
Per your updated question, I can get the source code for predict.svm using the ::: function. Specifically with e1071:::predict.svm. The link above also describes this in the section on S3 method dispatch.
There are at least a couple of things going on here. First is that in the former case you are dealing with S4 objects and S3 objects in the latter. The two systems have different method dispatches and different ways to view the source code. Another wrinkle is that the predict.svm function is an invisible function and can only be viewed either with ::: or getAnywhere().

R programming language mmedist The moment function must be defined. fdistrplus package

I'm trying to fit a distribution to some data using the function fdist from the package fdistrplus.
I've started learning R recently and got a hold of this package that I thought could do everything I needed.
When trying to use it to fit to a pareto distribution, I had to input my definitions of the pareto distribution like so:
ppareto = function(x,alpha,theta){
(1-(theta/(x+theta))^alpha)*(x>=0)
}
dpareto = function(x,alpha,theta){
(alpha*theta^alpha*(x+theta)^(-alpha-1))*(x>=0)
}
rpareto = function(n,alpha,theta){
l = array(as.numeric(NA),n)
ltmp = runif(n,0,1)
l = teta/ltmp^(1/alpha)-theta
return(l)
}
When calling
fitdist(data,"pareto",method = "mme")
It said it could not find the "dpareto" function. That is resolved by the code above.
Afterwards it said it needed an order parameter and a empirical moment parameter.
It's my understanding that the order parameter is the vector of orders that I want the routine to use as it's basis for the calculation.
So I tried:
fitdist(data,"pareto",method="mme",order=c(1,2))
As I saw in the examples of the package pdf.
Then it complained that:
Error in mmedist(data, distname, start = start, fix.arg = fix.arg, ...) :
The moment function must be defined.
Okay, next step:
momentfunc = function(x,order){mean(x^order)}
To define the function.
Then I tried
fitdist(data,"pareto",method="mme",order=c(1,2),memp=momentfunc)
Error in mmedist(data, distname, start = start, fix.arg = fix.arg, ...) :
The moment function must be defined.
Then I tried:
fitdist(data,"pareto",method="mme",order=c(1,2),memp="momentfunc")
Error in mmedist(data, distname, start = start, fix.arg = fix.arg, ...) :
The moment function must be defined.
I've searched the web, found examples of the pareto dist and followed them step by step all to no avail...
I've searched stackoverflow and found nothing.
So here I am. If anyone could help me I would be much obliged.
Is it my dumb mistake? Is it a bug in the package?
I've tried this on Windows 7, R 3.1.0
and on MacOS, R 3.0.1 (where I get a warning that the package was built under R 3.0.2)
Thanks in advance
you have to install and load the 'actuar' package

Resources