I'm trying to run the following code in R, but I'm getting an error.
I'm not sure what part of the formula is incorrect. Any help would be greatly appreciated.
loglik<-function(y,theta)
{
mu=theta[1]
sigma2=theta[2]
lambda=theta[3]
n=length(y)
-0.5*n*log(2*pi)-0.5*n*log(sigma2)-sum((y^lambda-1)/lambda-mu)^2/(2*sigma2)+(lambda-1)(sum(log(y)))
}
Error: attempt to apply non-function
The issue is in
(lambda-1)(sum(log(y))
If it needs to be multiplied, add the *
(lambda-1)*(sum(log(y))
You are missing a * in the final line of the function.. Should be
(lambda-1)*(sum(log(y)))
Related
I am unable to run the code for sort.score in R,
I get the following error:Error in sort.score(AIC(m000.avalon, m001.avalon, m101.avalon, m200.avalon) :
could not find function "sort.score".
can anyone advice, where I am going wrong . Thank you
The function is actually sortScore, not sort.score. Try this instead, it will work for sure.
I am trying to manually add the NPV formula but I am getting the error message Error: attempt to apply non-function
npv<- (2520/(1+0.10))+ (2520(1+0.10)^2)+ (2520(1+0.10)^3)
Please let me know why am I getting this error message and how can I fix this?
Probably, we need the *
(2520/(1+0.10))+ (2520*(1+0.10)^2)+ (2520*(1+0.10)^3)
[1] 8694.229
When trying to run this (or any other) command
xtabs(ugdata$response, ugdata$Equity, data=ugdata)
I keep receiving this error
Error in formula.default(object, env = baseenv()) : invalid formula
I have been looking around all day, including similar posts on this website, but I cannot find a solution to help me fix this.
Any help would be greatly appreciated
I believe the error is in the syntax. Please try:
xtabs(ugdata$response ~ ugdata$Equity, data = ugdata)
Hope you can give me a quick help:
I have a function that works perfect as run in the global envir. When I eval the function from my own package it gives me an error. I can't figure out what the problem is. Seem so random to me.
catTableFun(aaa,grouped_by = "varNameAsString",preview=T) #from global envir works as expected
elricoFuns::catTableFun(aaa,grouped_by = "varNameAsString",preview=T) # identical function run from package gives the following error
Error:
#Error in get(grouped_by) : object 'varNameAsString' not found
Its such a construct causing the error. But why?
setDT(x)
gnLevels <- x[,get(grouped_by),drop=F]
I'm sorry I cant give you some rep example and this is a broad question, but I hope someone has encountered a similar phenomenon or has an educated guess about it.
I'm trying to call the checkm function from within another function that accepts a formula as a parameter. I'm getting an object not found error. Here is the minimal implementation and error.
library(lrmest)
data(pcd)
form<-formula(Y~X1+X2+X3+X4)
checkm(form,data=pcd)
Wrap<-function(f){
checkm(f,data=pcd)
}
Wrap(form)
The error is:
Error in model.frame(formula = f, data = pcd, NULL) :
object 'f' not found
Called from: eval(expr, envir, enclos)
My guess from reading around is this has to do with my not understanding environments or promises but given that I don't understand them, I'm probably wrong.
Any quick fixes?
One quick fix is to change the name of your formula argument. It happens to conflict with the eval(cal) call within checkm. I suspect #joran is right that this isn't your fault. This works:
library(lrmest)
data(pcd)
form<-Y~X1+X2+X3+X4
checkm(form,data=pcd)
Wrap<-function(formula){
checkm(formula,data=pcd)
}
Wrap(form)
As #joran pointed out, there is a bug/error in the function caused from not using the correct frame to evaluate the command. If you swap out checkm for lm you'll see it runs just fine. You can create your own function that changes just that one line of code with
checkm2<-checkm
body(checkm2)[[6]]<-quote(cal <- eval(cal, parent.frame()))
And then run
library(lrmest)
data(pcd)
form<-formula(Y~X1+X2+X3+X4)
checkm2(form,data=pcd)
Wrap<-function(f){
checkm2(f,data=pcd)
}
Wrap(form)
and everything seems to run properly. So that just appears to be the fault of the people who wrote the code. You might consider contacting them to file a bug report.