plotmplier in NARDL package - r

I have a problem with running plotmplier command in NARDL package. I keep receiving the same error:
error in plot.window(…) :need finite ylim
erd22 <- nardl(ef~lwr,efo,ic="bic",maxlags = TRUE,graph = FALSE,case=3) summary(erd22)
plotmplier(erd22,2,2,10)

Result through NARDL in R Prog is contradicted with Stata and Eviews. F Bound test is not a correct one. Better to use Stata or eviews 9/10.

Related

Error in eval(parse()) - r unable to find argument input

I am very new to R, and this is my first time of encountering the eval() function. So I am trying to use the med and boot.med function from the following package: mma. I am using it to conduct mediation analysis. med and boot.med take in models such as linear models, and dataframes that specify mediators and predictors and then estimate the mediation effect of each mediator.
The author of the package gives the flexible option of specifying one's own custom.function. From the source code of med, it can be seen that the custom.function is passed to the eval(). So I tried insert the gbmt function as the custom function. However, R kept giving me error message: Error during wrapup: Number of trees to be used in prediction must be provided. I have been searching online for days and tried many ways of specifying the number of trees parameter n.trees, but nothing works (I believe others have raised similar issues: post 1, post 2).
The following codes are part of the source code of the med function:
cf1 = gsub("responseY", "y[,j]", custom.function[j])
cf1 = gsub("dataset123", "x2", cf1)
cf1 = gsub("weights123", "w", cf1)
full.model[[j]] <- eval(parse(text = cf1))
One custom function example the author gives in the package documentation is as follows:
temp1<-med(data=data.bin,n=2,custom.function = 'glm(responseY~.,data=dataset123,family="quasibinomial",
weights=weights123)')
Here the glm is the custom function. This example code works and you can replicate it easily (if you have mma installed and loaded). However when I am trying to use the gbmt function on a survival object, I got errors and here is what my code looks like:
temp1 <- med(data = data.surv,n=2,type = "link",
custom.function = 'gbmt(responseY ~.,
data = dataset123,
distribution = dist,
train_params = start_stop,
cv_folds=10,
keep_gbm_data = TRUE,
)')
Anyone has any idea how the argument about number of trees n.trees can be added somewhere in the above code?
Many thanks in advance!
Update: in order to replicate the example code, please install mma and try the following:
library("mma")
data("weight_behavior") ##binary x #binary y
x=weight_behavior[,c(2,4:14)]
pred=weight_behavior[,3]
y=weight_behavior[,15]
data.bin<-data.org(x,y,pred=pred,contmed=c(7:9,11:12),binmed=c(6,10), binref=c(1,1),catmed=5,catref=1,predref="M",alpha=0.4,alpha2=0.4)
temp1<-med(data=data.bin,n=2) #or use self-defined final function
temp1<-med(data=data.bin,n=2, custom.function = 'glm(responseY~.,data=dataset123,family="quasibinomial",
weights=weights123)')
I changed the custom.function to gbmt and used a survival object as responseY and the error occurs. When I use the gbmt function on my data outside the med function, there is no error.

Error from logistic regression Zelig R

I'm running a logit model using the zelig package in R.
m3 <- zelig (newdata$bes.Turnout ~ civicduty + newdata$bes.CivicDuty2+newdata$bes.Age, model="logit", data=newdata)
newdata$bes.Turnout is binary, the rest are numerical.
I try to set the values of x.
mcos<- median(newdata$bes.CivicDuty2)
civicmean<-mean(civicduty)
mage<-mean(newdata$bes.Age)
test<-setx(m3, civicduty=civicmean, newdata$bes.CivicDuty2=mcos, newdata$bes.Age=mage)
I get the following error message:
Error: unexpected '=' in "test<-setx(m3, civicduty=civicmean, newdata$bes.CivicDuty2="
I have tried the same code for the survival data in Zelig, and here the setx worked.
Any ideas what I am doing wrong and how to fix it?
That call to setx doesn't make sense to me. My best guess is that you want something like
test<-setx(m3,
civicduty = mean(newdata$civicduty),
bes.CivicDuty2 = mean(newdata$bes.CivicDuty2,
bes.Age = mean(newdata$bes.Age))

R Leaps Package: Regsubsets - coef "Reordr" Fortran error

I'm using the R leaps package to obtain a fit to some data:
(My dataframe df contains a Y variable and 41 predictor variables)
require(leaps)
N=3
regsubsets(Y ~ ., data = df, nbest=1, nvmax=N+1,force.in="X", method = 'exhaustive')-> regfit
coef(regfit,id = N)
When I run the code more than once (the first time works fine) I get the following error when I run the coef command:
Error in .Fortran("REORDR", np = as.integer(object$np), nrbar = as.integer(object$nrbar), :
"reordr" not resolved from current namespace (leaps)
Any help with why this is happening would be much appreciated.
A.
I had to build the package from source inserting the (PACKAGE = 'leaps') argument into the REORDR function in the leaps.R file. It now works fine every time.
The solution is related to:
R: error message --- package error: "functionName" not resolved from current namespace

Error with gamsel R Package

I'm trying to use the gamsel R package to fit a sparse generalized additive model, and I can't seem to get it to work on real data. When I run on synthetic data as described in the package documentation, everything works well:
library(gamsel)
data=gendata(n=500,p=12,k.lin=3,k.nonlin=3,deg=8,sigma=0.5)
attach(data)
bases=pseudo.bases(X,degree=10,df=6)
gamsel.out=gamsel(X,y,bases=bases)
But when I run on real data, I get the following error:
library(gamsel)
X = as.matrix(read.csv("X.csv"),header=FALSE)
y = as.matrix(read.csv("y.csv"),header=FALSE)
gam_fit = gamsel(X,y)
Error in if (abs((df - current.df)/df) < 1e-04 | iterations == 1)
return(list(lambda = lambda, : missing value where TRUE/FALSE
needed
You can access sample data files that will reproduce this result here. Any thoughts about how to fix this error?

Error in mgcv R package, depending of the R version

The following program works perfectly with R\2.15.3 with the mgcv packages:
foo<-c(0.08901294, 0.04221170, 0.01608613, 0.04389676, 0.04102295, 0.03552413, 0.06571099, 0.11004966, 0.08380553, 0.09181121, 0.07422538,
0.11494897, 0.18523257, 0.13809043, 0.13569868, 0.13433534, 0.16056145, 0.15559133, 0.22381149, 0.13998797, 0.02831030)
infant.gamfit<-gam(foo~s(c(1:21)), family=gaussian(link = "logit"))
But with R\3.1.1 and 3.1.2, it produces the following error:
Error in reformulate(pav) : 'termlabels' must be a character vector
of length at least one
Which is an error I don't understand.
Of course the values in foo is an example among others, but I have the same problem with other values. Fixing k in the spline doesn't change anything.
That wouldn't be a problem if I wouldn't need to use it on a large scale with a supercomputer where all the versions of R create the same error...
(for the sake of the discussion, the R versions I tested on the supercomputer were:
R/2.15.3-foss-2014a-default;
R/2.15.3-foss-2014a-st;
R/2.15.3-intel-2014a-default;
R/3.0.2-foss-2014a-default)
So that's not a supercomputer problem, but more a problem related to the use of mgcv in different version of R.
I didn't find any answer on the internet.
Thank you in advance for your help.
Guillaume
It looks like recent versions of mgcv::gam can be a bit fragile when your predictor is an expression, as opposed to a named variable. This works:
x <- 1:21
gam(foo~s(x), family=gaussian(link = "logit"))
As does this:
x <- 1:21
gam(foo~s(x + 0), ...)
But this doesn't:
x <- rep(0, 21)
gam(foo~s(x + 1:21), ...)
In general, I'd suggest you should precompute your predictors when using gam.
PS. Gaussian family with logit link isn't very sensible, but that's another issue.

Resources