I am trying to make boxcox transformation of a variable (i.e. sqrt.CR) with lambda value from -2 to 2. On running the below R code it gives a error of invalid atomic vectors. Later on checking earlier posts i saw few suggestions to transform the matrix into a data frame. Though the error continued to show up. Do anyone know to figure out this error ?
R code.
Matrix to data frame conversion
drivers.data<-as.data.frame(drivers)
Boxcox transfrom.
drivers$box_CR<-boxcox(drivers.data$sqrt.CR,lambda=seq(-2,2))
The input to boxcox must be the output of a lm or aov call, not a vector of numbers as yours appears to be. See ?boxcox.
boxcox(object, ...)
Arguments:
object: a formula or fitted model object. Currently only ‘lm’ and
‘aov’ objects are handled.
It could be because of package conflict, in MASS,boxcox requires a model object lm, whereas in bestNormalize it requires a vector.
Try
bestNormalize::boxcox(drivers.data)
Related
I am trying to fit a model with the SuperLearner package. However, I can't even get past the stage of playing with the package to get comfortable with it....
I use the following code:
superlearner<-SuperLearner::SuperLearner(Y=y, X=as.data.frame(data_train[1:30]), family =binomial(), SL.library = list("SL.glmnet"), obsWeights = weights)
y is a numeric vector of the same length as my dataframe "data_train", containing the correct labels with 9 different classes. The dataframe "data_train" contains 30 columns with numeric data.
When i run this, i get the Error:
Error in get(library$screenAlgorithm[s], envir = env) :
Objekt 'All' not found
I don't really know what the problem could be and i can't really wrap my head around the source code. Please note that the variable obsWeights in the function contains a numeric vector of the same length as my data with weights i calculated for the model. This shouldn't be the problem, as it doesn't work either way.
Unfortunately i can't really share my data on here, but maybe someone had this error before...
Thanks!
this seems to happen if you do not attach SuperLearner, you can fix via library(SuperLearner)
I'm attempting to follow a tutorial (link here: https://www.r-bloggers.com/latent-class-mixed-models-with-graphics/) for running a latent class mixture model. My model has run properly, but i'm having an issue plotting the latent classes.
Con2 < lcmm(ConT~AdminCount,random=~AdminCount,subject='PID',mixture=~AdminCount,ng=3,idiag=TRUE,data=datal,link="linear")
summary(Con2)
datal$CONid <- as.character(datal$PID)
people3 <- as.data.frame(Con2$pprob[1:2])
datal$CONgroup <- character(people3$class[sapply(datal$CONid, function(x) which(people3$CONid==x))])
When I try to run the last line of code, I get this error:
Error in people3$class[sapply(datal$CONid, function(x)
which(people3$CONid == : invalid subscript type 'list'
Any ideas what this error means/how I can address it?
Pictures here of all my code and output:
info about variables being used in model
Probability values from model
Model Summary
Graph Code and Error
We still can't recreate your error; I did find the original tutorial posting though as well as the full R code and the data.
So I need to guess your error. Note that the error statement is that the "subscript is a list". The subscript is the function call sapply(datal$CONid, function(x) which(people3$CONid==x). In the default setting, the sapply-function will return a list, if the return values of the function are of irregular length (otherwise a vector or a matrix). That is, the elements of datal$CONid occur with irregular frequency among the entries of people3$CONid.
Hope you can work from here on.
I get the following error when I try to improve the intensity estimate of a kppm object, if I include the argument vcov = TRUE in the function improve.kppm:
Error in improve.kppm(object, type = type, rmax = rmax, dimyx = dimyx, :
object 'gminus1' not found
If I don't include the argument, the function runs but I cannot use the summary() function on the improved kppm object. I get the same error message as above. The same thing happens when I use vcov().
The call that I used to create my kppm object was (number of covariates has been reduced for clarity):
a05 = kppm(a2005nests ~ nest + nest2, cluster = "Thomas", covariates = fitcov(2))
where fitcov(2) is a function that returns a list of im objects. Could this be the issue? I've noticed that some spatstat functions on kppm objects throw errors if I used this function in the original kppm call. Usually it says something along the lines of Error: Covariates ‘nest’ and ‘nest2’ were not found.
There is a bug in the logical flow of improve.kppm: if vcov=TRUE and type != "quasi", the variable gminus1 is not defined. We will fix this in the development version of spatstat as soon as possible.
Did you perhaps select type="clik1" or type="wclik1" in the original call to kppm?
For the moment, you should be able to avoid the bug by omitting the argument type, or explicitly selecting type="quasi", in calls to kppm and improve.kppm.
The second problem, in which kppm fails to find the covariates, appears to be a scoping problem, but I can't reproduce it here. It would help if you can supply a minimal working example.
I try to run multiple linear regressions on large data sets. Basically biglm works fine. Now I try to find a convenient way to create my formula automatically, using a vector, containing my dependent variables and a string, containing the rest of my formula. Both strings together are my formula.
This works fine for lm() but leads to an error using biglm()
reproduceable example:
library(biglm)
data<-data.frame(av=c(1,2,3,4,5,6,5,4,5,5),
uv1=c(1,2,5,5,4,56,3,4,5,6),
uv2=c(4,5,8,3,2,7,6,2,4,6),
weight=c(1.2,1,1,1,1,1,1,1,0,0))
dependent<-c('av')
independent<-'~ uv1 + uv2 -1'
formula<-paste(dependent[1],independent)
#this works fine
lm_standard<-lm(formula,data=data,weights=weight)
#and this works fine
lm_big1<-biglm(av~uv1+uv2-1,data=data,weights=~weight)
#and here comes the error
lm_big<-biglm(formula,data=data,weights=~weight)
Error: $ operator is invalid for atomic vectors
I don't use as.formula(), because I don't know how to add the -1 to the as.formula() object. My workaround for the as.formula() problem leads to the error message. Is it possible to a) use as.formula() with a missing intercept or b) paste the formula in a way, biglm() can understand?
lm automatically coerces suitable objects to a formula object, whilst biglm does not. Just do it yourself....
lm_big<-biglm( as.formula( formula ) ,data=data,weights=~weight)
I am using the following code getting the error message in R version 2.13.1. in mac.
cv.glmnet(dsgn.mat,resp,family="gaussian",nfolds=5)
Error in as.matrix(cbind2(1, newx) %*% nbeta) :
error in evaluating the argument 'x' in selecting a method for function 'as.matrix': Error in t(.Call(Csparse_dense_crossprod, y, t(x))) :
error in evaluating the argument 'x' in selecting a method for function 't': Error: invalid class 'NA' to dup_mMatrix_as_dgeMatrix
I should mention that there is no message if I use only glmnet then it is working fine.
Without any example data, all I can say is that, generally, most errors that pop up only during cross validation are because one of the random folds ends up "bad". This is obviously more common if you don't have many observations in your data set. For example, do you have any NAs in your data (might lead to an entire fold of NAs)?
You can get around this by preprocessing your data, but glmnet also will let you directly prescribe the folds via parameter foldid.