R error "attempt to select less than one element in get1index" - r

I need to estimate some parameters in gp model so I install "kergp" package in R to generate a customized kernel. When I use "mle" function to estimate parameters, I get the error as below:
Error in fitList[[bestIndex]] : attempt to select less than one element in get1index
Here is the code:(where initial_data is a dataframe.)
q4<-q1CompSymm(af, input = "af", cov = "corr", intAsChar = TRUE)
quan<-covTP(k1Fun1 = k1Fun1PowExp,d = 4,cov = "homo",
iso1 = 0,parLower = c(rep(0,9)), parUpper = c(2,2,2,2,Inf,Inf,Inf,Inf,Inf))
inputNames(quan)<-c("hl","hn1","hn2","hn3")
kernel<-covComp(formula = ~quan()*q4())
mle(kernel,
parCovIni = c(rep(0.5,10)),
initial_data$y,select(initial_data,-c('index','y','iw','rts')), F = NULL,
parCovLower = c(rep(0,10)),
parCovUpper = c(2,2,2,2,Inf,Inf,Inf,Inf,Inf,1),
noise = TRUE, varNoiseIni = var(initial_data$y) / 10,
optimFun = "stats::optim",
optimMethod = "BFGS")
I had seen the related document from github(https://github.com/cran/kergp/blob/master/R/methodMLE.R) but still couldn't figure out how this situation happen...
Besides, this error occurred after some iterations if there are any help. Any help would be appreciated. Thanks

Related

Consistent error message while running grouping analysis in 'plspm' package

I am looking for some help in resolving an error using the partial least squares path modeling package ('plspm').
I can get results running a basic PLS-PM analysis but run into issues when using the grouping function, receiving the error message:
Error in if (w_dif < specs$tol || iter == specs$maxiter) break : missing value where TRUE/FALSE needed
I have no missing values and all variables have the proper classification. Elsewhere I read that there is a problem with processing observations with the exact same values across all variables, I have deleted those and still face this issue. I seem to be facing the issue only when I run the groups using the "bootstrap" method as well.
farmwood = read.csv("farmwood_groups(distance).csv", header = TRUE) %>%
slice(-c(119:123))
Control = c(0,0,0,0,0,0)
Normative = c(0,0,0,0,0,0)
B_beliefs = c(0,0,0,0,0,0)
P_control = c(1,0,0,0,0,0)
S_norm = c(0,1,0,0,0,0)
Behavior = c(0,0,1,1,1,0)
farmwood_path = rbind(Control, Normative, B_beliefs, P_control, S_norm, Behavior)
colnames(farmwood_path) = rownames(farmwood_path)
farmwood_blocks = list(14:18,20:23,8:13,24:27,19,4:7)
farmwood_modes = rep("A", 6)
farmwood_pls = plspm(farmwood, farmwood_path, farmwood_blocks, modes = farmwood_modes)
ames(farmwood)[names(farmwood) == "QB3"] <- "Distance"
farmwood$Distance <- as.factor(farmwood$Distance)
distance_boot = plspm.groups(farmwood_pls, farmwood$Distance, method = "bootstrap")
distance_perm = plspm.groups(farmwood_pls, farmwood$Distance, method = "permutation")
The data is contained here:
https://www.dropbox.com/s/8vewuupywpi1jkt/farmwood_groups%28distance%29.csv?dl=0
Any help would be appreciated. Thank you in advance

ME function and margin Function from twopm package rstudio

I ran my twopart model and I have tried following the but the margins and the AME commands to get the marginal effects on all the variables, but I am running into a really weird issue with the data frame for some reason.
> margin(tpmodel1)
Error in `[.data.frame`(newdata, , term) : undefined columns selected
But when looking at the guide for the twopm package, it says that all I need to do is just AME(tpmodel1) or margin(tpmodel1) to get all the marginal effects and it is still giving that error. so then i did
> margin(tpmodel1, newdata = NULL, term = NULL, se=TRUE)
Error in `[.data.frame`(newdata, , term) : undefined columns selected
And
> margin(tpmodel1, newdata = dfasthma, term = NULL, se=TRUE)
Error in margin(tpmodel1, newdata = dfasthma, term = NULL, se = TRUE) :
some of independent variables of the two-part model are not available in the newdata set
of which doesnt make sense cause The data set i created for the variables I am using is dfasthma.
the code from the package:
margin(object, newdata = NULL, term = NULL, value = NULL,
se = TRUE, se.method = c("delta","bootstrap"), CI = TRUE, CI.boots = FALSE,
level = 0.95,eps = 1e-7,na.action = na.pass, iter = 50)
The image attached is a guide to the margin command from the package

Error calling rCBA::fpgrowth: method fpgrowth with signature (DDI)[[Ljava/lang/String; not found

I wrote the R code below to mine with the FP-Growth algorithm:
fpgabdata <- read.csv('../Agen Biasa.csv', header = FALSE)
train <- sapply(fpgabdata, as.factor)
train <- data.frame(train, check.names = TRUE)
txns <- as(train,"transactions")
abrulesfpg = rCBA::fpgrowth(txns, support = 0.25, confidence = 0.5, maxLength = 10, consequent = NULL, verbose = TRUE, parallel = TRUE)
But I get the following error:
Error in .jcall(jPruning, "[[Ljava/lang/String;", "fpgrowth", support, :
method fpgrowth with signature (DDI)[[Ljava/lang/String; not found
These are my data:
The reason you are seeing this error is that the current implementation of the FP-growth algorithm in rCBA requires that you specify a value for the consequent (right hand side).
For example, the following should work, assuming you have sensible thresholds for support and confidence:
abrulesfpg = rCBA::fpgrowth(
txns,
support = 0.25,
confidence = 0.5,
maxLength = 10,
consequent = "SPIRULINA",
verbose = TRUE,
parallel = TRUE
)
I know the OP is likely to have discovered this by now, but I've answered this just in case anyone else encounters the same error.

Getting error while using "predict" method for Markov chain implemenattion in R using clickstream package

I have data set for user wise, clicks pattern for each session for one online site.I would like to predict next clicks using Markov chain & its probability.
Following is the my Code:
library(clickstream);
cls2<-readClickstreams(file.choose(),sep = ',',header = TRUE);
mc2<-fitMarkovChain(clickstreamList = cls2,order = 2,control = list(optimizer= "linear"));
pattern <- new("Pattern", sequence = c("/clsisGre/PersonalDetailForm.jsp","/clsisGre/PersonalDetail.jsp"), absorbingProbabilities = data.frame(NULL = 0.9, Success = 0.1));
> resultPattern <- predict(mc2, startPattern = pattern, dist = 1);
Error Message is :
Error in if (nextState %in% object#absorbingStates) { :
argument is of length zero
In addition: Warning message:
In max(cp, na.rm = T) : no non-missing arguments to max; returning -Inf
Need help to handle this error/exception.
Thanks in advance.
Sorry for late update but I am able to crack this problem, So I m posting the same solution which might be helpful for others.
In code (a,b,c,d,e,f,g,h,l,m) is the sequence input for which I would like to build Markov chain.Below code will help to handle the error mentioned in above post.
pattern <- new("Pattern", sequence = c(a,b,c,d,e,f,g,h,l,m),
absorbingProbabilities = data.frame(NULL = 0.9, Success = 0.1));
possibleError <- tryCatch(
suppressWarnings( predict(mc2, startPattern = pattern, dist = 1)),
error=function(e) e
);
if(inherits(possibleError, "error")) next
resultPattern <- predict(mc2, startPattern = pattern, dist = 1);
aa<-attributes(resultPattern)$absorbingProbabilities;
success_mat10[i,2]<-aa$Success;
success_mat10[i,1]<-as.vector(url_mat10[i,1]);

theta.sparse error with lorDIF

I was wondering whether anyone can help me out.
I am trying to run a dif analysis on my data but keep getting a theta.sparse error, which I am unsure of how to fix. I would really appreciate any that you can give me.
library(lordif)
dat<- read.csv2("OPSO.csv",header=TRUE)
datgender <- read.csv2("DATA.csv",header=TRUE)
group<-datgender$Gender
sink("outputDIFopso.txt")
gender.difopso <- lordif(dat, group, selection = NULL,
criterion = c("Chisqr", "R2", "Beta"),
pseudo.R2 = c("McFadden", "Nagelkerke", "CoxSnell"), alpha = 0.01,
beta.change = 0.1, R2.change = 0.02, maxIter = 10, minCell = 5,
minTheta = -4, maxTheta = 4, inc = 0.1, control = list(), model = "GRM",
anchor = NULL, MonteCarlo = FALSE, nr = 100)
print(gender.difopso)
summary(gender.difopso)
sink()
pdf("graphtestop.pdf")
plot(gender.difopso)
dev.off()
dev.off()
Error in lordif(dat, group, selection = NULL, criterion = c("Chisqr", :
object 'theta.sparse' not found
Thank you :)
You should check the error line before then. The output will probably say you have no items flagged for DIF. When that's the case you should just run the mirt function and extract theta and ipar objects as necessary.
The author could add some case handling for when compare(flags, flags.matrix) is true. At the very least, it seems a warning is omitted when there are no items with DIF the same way it says
if (ndif == ni) {
warning("all items got flagged for DIF - stopping\n")
}
and there is no case handling when (ndif == 0) although compare(flags, flag.matrix) evaluates to TRUE.
The implications when all or none of the items have DIF is that you would get the same results (generating the same ICC plots, same inference etc) by fitting mirt in the combined sample (no DIF) or two or more mirt models for each group (all DIF). So it's a correct time saving procedure to just bypass when all that breaks down.

Resources