Using the Yeo Johnson transformation in the car package - r

I think I must be doing something incorrectly with the Yeo-Johnson transformation, as other R users seem to be able to get it to work. Every time I execute the function, I get an error.
library(car)
mydata <- read.csv("R_import.csv", header=TRUE)
test <- yjPower(mydata,0.5,jacobian.adjusted=FALSE)
After I run this, I receive:
Error in if (abs(lambda) <= 1e-06) log(U) else ((U^lambda) - 1)/lambda :
missing value where TRUE/FALSE needed
I've tried different datasets and different starting lambda and nothing seems to change. Does anyone know what might be going on?

Related

SuperLearner Error in R - Object 'All' not found

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)

How to block bootstrap in R?

I'm trying to run a block bootstrapping function on some time series data (monthly interest rates for ~15 years).
My data is in a csv file with no header, all comprising one column and going down by row.
I installed the package bootstrap because tsboot wouldn't work for me.
Here is my code:
testFile = read.csv("\\Users\\unori/sample_data.csv")
theta <- function(x){mean(x)}
results = bootstrap(testFile,100,theta)
It tells me there are at least 50 errors. All of them say "In mean.default(x) : argument is not numeric or logical: returning NA"
What to do? It runs when I use the example in the documentation. I think it must be how my data is stored/imported?
Thanks in advance.
Try to supply a working, minimal example that reproduces your problem! Check here to see how to make a minimal reproducible example.
The error messages tells you that the thing you want to calculate the mean of, is not a number! So R will just return NA.
Suggestions for debugging:
Does the object 'testFile' exist?
What is the output of
str(testFile)
This works for me:
library(bootstrap)
testFile <- cars[,1]
theta <- function(x){mean(x)}
results = bootstrap(testFile,100,theta)

ImpulseDE2, matrix counts contains non-integer elements

Possibly it's a stupid question (but be patient, I'm a beginner in R's word)... I'm working with ImpulseDE2, a package designed to RNAseq data analysis along different times (see article for more information).
The running function (runImpulseDE2) requires a matrix counts and a annotation data frame. I've created both but it appears this error message:
Error in checkCounts(matCountData, "matCountData"): ERROR: matCountData contains non-integer elements. Requires count data.
I have tried some solutions and nothing seems to work (and I've not found any solution in the Internet)...
as.matrix(data)
(data + 1) > and there isn't NAs nor zero values that originate this error ($ which(is.na(data)) and $ which(data < 1), but both results are integer(0))
as.numeric(data) > and appears another error: ERROR: [Rownames of matCountData] was not given as input.
I think that's something I'm not realizing, but I'm totally locked. Every tip will be welcome!
And here is the (silly) solution! This function seems not to accept float numbers... so applying a simple round is enough to solve this error.
Thanks for your help!

plotfit.fd is upset about my names. Cannot plot and cannot understand error

Shot in the dark but I cannot get a plot function to work in the CollocInfer package. I am trying to execute the following code:
plotfit.fd(temps, times, DEfd1,nfine=N,
xlab="Time (hours)", ylab="Temperature level (metres)",title="")
I have my code working perfectly up until this point. When I execute I get the following error:
Error in checkDim3(x, y, xdim[id], ydim[id], dNi, subset, xName = xNmi, :
Can NOT subset subscript 1 of DEfd1$coef because some dimnames(subscript 1 of temps)[[xdim=2]] are not found in dimnames(y)[[ydim=2]]; the first one is temps
I've been trying to track down what this means for hours. I ran some pacjkage supplied code and tried to figure it out and couldn't. The documentation for the checkDim3 function is here: http://www.psych.mcgill.ca/misc/fda/downloads/FDAfuns/R/R/checkDims3.R
I looked at the data and the values are consistent, i.e. I solved the ODE I am trying to model and the parameter estimates are correct. Somewhere I made an error in the bookkeeping? Any help appreciated. Or a workaround.
Ha, lesson learned:
dimnames(temps) <- NULL
works. This particular plotting function has tests for the dimnames of inputs.

Issues with eigen.analysis in popbio

I've been trying to calculate demographic rates using the 'popbio' package in R. I was trying to get the sensitivity of the eigenvalues but keep getting the error "Error in Mod(z$values) : non-numeric argument to function". So, I tried to run the example from the 'popbio' package and got the same error. From the example in the package manual:
A<-matrix(c(0,0,2,.3,0,0,0,.6,0), nrow=3,byrow=TRUE) #matrix from example
ev <- eigen.analysis(A) # calculation of eigenvalues
Error in Mod(z$values) : non-numeric argument to function #error I get for example and my data
I know that the function needs a matrix. Since object "A" is a matrix, I'm confused on why I'm getting the error. Any help on why I'm getting this error would be greatly appreciated! I'm pretty new to using R for this stuff, so apologies if this is the wrong place for this question.
Cheers,
Kevin
If you run into problems with a function in an add-on package, I would run through each line of code and then ask a more general question. For example,
Type eigen.analysis and hit return to see the code below (and line 4 is the only call to Modulus used for damping ratio)
ev <- eigen(A)
lmax <- which.max(Re(ev$values))
lambda <- Re(ev$values[lmax])
dr <- rle(round(Mod(ev$values), 5))$values
...
If you get an error running
A <- matrix(c(0,0,2,.3,0,0,0,.6,0), nrow=3,byrow=TRUE)
ev <- eigen(A)
Mod(ev$values)
then ask that question on Stack Overflow instead.
Just a guess, but I'm not sure why you see Error in Mod(z$values) instead of Mod(ev$values) unless you have some updated eigen.analysis script.

Resources