I am using the R package ape to analyze some sequences stored in a DNAbin object:
library(ape)
my.seq <- read.dna("sequences.txt", format = "clustal")
my.dist <- dist.dna(my.seq)
my.tree <- nj(my.dist)
I want to find the bootstrap values, so I use boot.phylo:
boot <- boot.phylo(my.tree, my.seq, FUN = function(xx) nj(dist.dna(xx)), B = 100)
But I get an error message saying:
Error in if (drop[j]) next : missing value where TRUE/FALSE needed
Any idea what this means, and how to fix it? I tried googling the error message, and I could not find anything.
Your if condition resulted in an NA.
It must have either TRUE or FALSEresult.
Related
I have been trying to run the pcpr2 package using the following tutorial: https://github.com/JoeRothwell/pcpr2
The data for this package is available in this link: https://github.com/JoeRothwell/pcpr2/raw/master/data/PCPR2data.RData
My datamatrix file is: https://drive.google.com/file/d/1wzzw2Jcui-IKICYc_QmTCvXqeFZ_3teX/view?usp=share_link
My metadata file is: https://drive.google.com/file/d/1d52Cj4qNvjTJox7n5uZKlmF9d8YPpfAn/view?usp=share_link
My code:
transcripts <- read.csv("test_matrix.csv", row.names = 1)
Z_metadata <- read.csv("test_trait.csv")
output <- runPCPR2(transcripts , Z_metadata, pct.threshold = 0.8)
Each time I try to use my data to run the codes from the pcpr2 package, I get the following error:
Error in runPCPR2(transcripts, Z_metadata, pct.threshold = 0.8) :
is.numeric(X_DataMatrix) is not TRUE
I tried converting my datamatrix into a numeric format by the following command:
transcripts = lapply(transcripts , as.double)
transcripts = do.call("cbind", transcripts)
However, this didn't work also. I get another error message:
Error in solve.default(crossprod(model.matrix(mod))) :
Lapack routine dgesv: system is exactly singular: U[15,15] = 0
I can tell something is wrong with my datamatrix format as the datatype and the class ain't the same as the ones used in the tutorial. However, I don't understand how to fix this. Any sort of help will be greatly appriciated.
Be careful when importing the test_matrix dataset (there are rownames and it should be a matrix) :
transcripts=as.matrix(read.csv("https://raw.githubusercontent.com/dtonmoy/PCPR2-data/main/test_matrix.csv",row.names=1))
Z_metadata=read.csv("https://raw.githubusercontent.com/dtonmoy/PCPR2-data/main/test_trait.csv")
output <- runPCPR2(transcripts , Z_metadata, pct.threshold = 0.8)
I'm using Bert (R add on for Excel).
When I try to run the following:
sales <- sample(100:170, 4*10, replace = TRUE)
advertising <- sample(50:70, 4*10, replace = TRUE)
sales_ts <- ts(sales, frequency = 4, end = c(2017, 4))
fit <- forecast::auto.arima(sales_ts, xreg = advertising,d=1,ic=c("aic"))
The arima works.
But when I try to use auto.arima
fit.arima <- arima(sales_ts,xreg =advertising,order=c(3,1,1))
I get the following error:
Error in rbind(info, getNamespaceInfo(env, "S3methods")) : number of columns of matrices must match (see arg 2)
Please help!
I was able to run this in R itself, and faced no issues (it worked fine).
Based on your error message, it's possible there's a namespace/library clash causing this, or that one of your libraries/packages wasn't installed properly.
You can either:
remove the package(s)
Use find.package("insert package name here") to find its location, then remove.packages("insert package name here") to remove it. Re-install and proceed
add the package name itself when referencing the function, like you did with forecast, e.g.
# adding "stats" in front, if that's the package being used
fit.arima <- stats::arima(sales_ts,xreg =advertising,order=c(3,1,1))
I'm trying to read in two dataframes into a comparitive object so I can plot them using pgls.
I'm not sure what the error being returned means, and how to go about getting rid of it.
My code:
library(ape)
library(geiger)
library(caper)
taxatree <- read.nexus("taxonomyforzeldospecies.nex")
LWEVIYRcombodata <- read.csv("LWEVIYR.csv")
LWEVIYRcombodataPGLS <-data.frame(LWEVIYRcombodata$Sum.of.percentage,OGT=LWEVIYRcombodata$OGT, Species=LWEVIYRcombodata$Species)
comp.dat <- comparative.data(taxatree, LWEVIYRcombodataPGLS, "Species")
Returns error:
> comp.dat <- comparative.data(taxatree, LWEVIYRcombodataPGLS, 'Species')
Error in if (tabulate(phy$edge[, 1])[ntips + 1] > 2) FALSE else TRUE :
missing value where TRUE/FALSE needed
This might come from your data set and your phylogeny having some discrepancies that comparative.data struggles to handle (by the look of the error message).
You can try cleaning both the data set and the tree using dispRity::clean.data:
library(dispRity)
## Reading the data
taxatree <- read.nexus("taxonomyforzeldospecies.nex")
LWEVIYRcombodata <- read.csv("LWEVIYR.csv")
LWEVIYRcombodataPGLS <- data.frame(LWEVIYRcombodata$Sum.of.percentage,OGT=LWEVIYRcombodata$OGT, Species=LWEVIYRcombodata$Species)
## Cleaning the data
cleaned_data <- clean.data(LWEVIYRcombodataPGLS, taxatree)
## Preparing the comparative data object
comp.dat <- comparative.data(cleaned_data$tree, cleaned_data$data, "Species")
However, as #MrFlick suggests, it's hard to know if that solves the problem without a reproducible example.
The error here is that I was using a nexus file, although ?comparitive.data does not specify which phylo objects it should use, newick trees seem to work fine, whereas nexus files do not.
I am attempting to use R package RecordLinkage, and am using two articles by the package authors as usage guides, in addition to the package documentation.
I am using 2 large datasets (100k+ rows), which I hope to link, and so I am using those elements of the package which are built around S4 class RLBigDataLinkage.
I begin by running the following lines in R:
>library('RecordLinkage')
>data1 <- as.data.frame(#source)
>data2 <- as.data.frame(#source)
>rpairs <- RLBigDataLinkage(data1, data2, strcmp = 2:8, exclude = 9:10)
This works fine (though it takes some time), and writes the necessary .ff files to deal with the large data sets.
If I then try:
>rpairs <- epiWeights(rpairs)
Or:
>rpairs <- epiWeights(rpairs, e = 0.01, f = getFrequencies(rpairs))
Then when I run:
>summary(rpairs)
I get the error message:
Error in dbGetQuery(object#con, "select count(*) from data1") :
error in evaluating the argument 'conn' in selecting a method for function 'dbGetQuery': Error: no slot of name "con" for this object of class "RLBigDataLinkage"
If, on the other hand, I run:
>result <- epiClassify(rpairs, 0.5)
>getTable(result)
I get the error message:
Error in table.ff(object#data#pairs$is_match, object#prediction, useNA = "ifany") :
Only vmodes integer currently allowed - are you sure ... contains only factors or integers?
I'm clearly missing something about how these objects need to be handled. Does anyone have any experience with this package that sees my error? Thanks kindly.
when the type of 'rpairs' is 'RLBigDataLinkage' use print(rpairs) ,you will get the summary of rpairs.
I have some troubles using the function AdjustedSharpeRatio() from the package PerformanceAnalytics, the following code sample in R 3.0.0:
library(PerformanceAnalytics)
logrets = array(dim=c(3,2),c(1,2,3,4,5,6))
weights = c(0.4,0.6)
AdjustedSharpeRatio(rowSums(weights*logrets),0.01)
gives the following error:
Error in checkData(R) :
The data cannot be converted into a time series. If you are trying to pass in
names from a data object with one column, you should use the form 'data[rows,
columns, drop = FALSE]'. Rownames should have standard date formats, such as
'1985-03-15'.
Replacing the last line with zoo gives the same error:
AdjustedSharpeRatio(zoo(rowSums(weights*logrets)),0.01)
Am I missing something obvious ?
Hmm...not too sure what you are trying to achieve with the logrets and weights objects there....but if logrets are already in percentages. then maybe something like this...
AdjustedSharpeRatio(xts(rowSums(weights*logrets)/100,Sys.Date()-(c(3:1)*365)), Rf=0.01)
This might work:
a <- rowSums(weights*logrets)
names(a) <- c('1985-03-15', '1985-03-16', '1985-03-17')
AdjustedSharpeRatio(a,0.01)