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.
Related
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)
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 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?
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!
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.