error in base backsolve with quantile regression, how do I solve? - r

If I run the library for 'quantreg', I get a warning that backsolve is masked from base. Then I try to run a quantile regression and I get an error involving backsolve. How can I solve this?
library(quantreg)
Loading required package: SparseM
Attaching package: ‘SparseM’
The following object is masked from ‘package:base’: backsolve
quantile_mod1<- rq(X ~ Y, tau=0.3,data=mydata)
Warning message:
In rq.fit.br(x, y, tau = tau, ...) : Solution may be nonunique
summary(quantile_mod1)
Error in base::backsolve(r, x, k = k, upper.tri = upper.tri, transpose = transpose, :
singular matrix in 'backsolve'. First zero in diagonal [41]
In addition: Warning message:
In summary.rq(quantile_mod1) : 12506 non-positive fis

Related

Using MCMC on evolutionary traits with Evomap

Here is what I'm running. I'm wondering why I'm getting an error and what the error means/how I could fix it. Is it something to with getting a null value for CDdat? Anyone have an idea? thanks.
library(phytools)
Loading required package: ape
Loading required package: maps
library(adephylo)
Loading required package: ade4
library(geiger)
library(nlme)
library(evomap)
library(caper)
Loading required package: MASS
Loading required package: mvtnorm
library(scales)
Attaching package: ‘scales’
The following object is masked from ‘package:geiger’:
rescale
library(coda)
library(ggplot2); theme_set(theme_light())
library(HDInterval)
Frogtree<-read.nexus("C:/Users/WiensDell3/Desktop/TwilliamsRfiles_AdvertisementCalls/frog_contree")
Call.duration. <- read.csv("C:/Users/WiensDell3/Desktop/TwilliamsRfiles_AdvertisementCalls/Call duration .csv")
CD <- Call.duration.
mydata<-comparative.data(data= CD,phy= Frogtree, names.col= "Species")
FrogTree<- mydata$phy
mydata2 <-mydata$data
x <- mydata2$CD
BMsigma2 <- ace(x, FrogTree, method = "REML")$sigma2[1]
mvBMresults <- mvBM(x, FrogTree, BMsigma2)
tree_mvBMCD <- FrogTree; tree_mvBMCD$edge.length<-mvBMresults$rBL
CDdat<- mydata2$CD; names(CDdat <-rownames(mydata2)
+ )
NULL
Iterations <- 500000
Model_mvBMCD<-anc.Bayes(tree_mvBMCD,CDdat,ngen=Iterations)
Error in invC %*% X : requires numeric/complex matrix/vector arguments
Model_mvBMCD<-anc.Bayes(tree_mvBMCD,CDdat,ngen=Iterations)
Error in invC %*% X : requires numeric/complex matrix/vector arguments

IDI.INF function to compare the performance of two Cox regression models

I would like to use the IDI.INF function from the survIDINRI package to the performance of two Cox regression models.
For this purpose, I have used the following script:
> D=subset(Dataset, select=c("time","status","Var1","Var2","Var3", "Var4", "Var5", "Var6", "Var7", "Var8"))
> D$status=as.numeric(D$status==2)
> D=D[!is.na(apply(D,1,mean)),] ; dim(D)
[1] 800 10
> head(D)
> outcome=D[,c(1,2)]
> covs1<-as.matrix(D[,c(-1,-2)])
> covs0<-as.matrix(D[,c(-1,-2, -10)])
> head(outcome)
> head(covs0)
> head(covs1)
> x <-IDI.INF(outcome, covs0, covs1, t0, npert=300,npert.rand = NULL, seed1 = NULL, alpha = 0.05)
At the end, I get the following message:
Error in fitter(X, Y, strats, offset, init, control, weights = weights, :
NA/NaN/Inf in foreign function call (arg 6)
In addition: Warning message:
In fitter(X, Y, strats, offset, init, control, weights = weights, :
Ran out of iterations and did not converge
Are there people who have experience with this IDI.INF function? Are there ways to tackle this problem?
This error message could be encountered because of weak predictive value of one variable (might be 6th variable in data.frame). You can fix this problem by removing that variable or including more number of study subjects if possible to make the prediction models stable.

polycor package - hetcor error in optim

I'm trying to run a factor analysis on a set of 80 dichotomous variables (1440 cases) using the hector function from the polycor package and the instructions I found here: http://researchsupport.unt.edu/class/Jon/Benchmarks/BinaryFA_L_JDS_Sep2014.pdf
Sadly, after I select just the variables interest from the rest of my dataset and run the factor analysis on them, I seem to consistently get the following error and warnings
Error in optim(0, f, control = control, hessian = TRUE, method = "BFGS") :
non-finite finite-difference value [1]
In addition: Warning messages:
1: In log(P) : NaNs produced
2: In log(P) : NaNs produced
This is with the command/when I hit the step described in the above PDF:
testMat <- hetcor(data)$cor
No idea what this means or how to proceed... Your thoughts are appreciated. Thank you!

fitdistr from MASS library gives warnings when fitting t-distribution

I'm trying to reproduce the following example from David Ruppert's "Statistics and Data Analysis for Financial Engineering", which fits Students t-distribution to historical risk free rate:
library(MASS)
data(Capm, package = "Ecdat")
x <- Capm$rf
fitt <- fitdistr(x,"t", start = list(m=mean(x),s=sd(x)), df=3)
as.numeric(fitt$estimate)
0.437310595161651 0.152205764779349
The output is accompanied by the following Warnings message:
Warning message:
In log(s): NaNs producedWarning message:
In log(s): NaNs producedWarning message:
In log(s): NaNs producedWarning message:
In log(s): NaNs producedWarning message:
In log(s): NaNs producedWarning message:
In log(s): NaNs producedWarning message:
In log(s): NaNs producedWarning message:
In log(s): NaNs producedWarning message:
In log(s): NaNs produced
It appears from the R's help file that MASS::fitdistr uses maximum-likelihood for finding optimal parameters. However, when I do optimization manually (same book), all goes smoothly and there is no warnings:
library(fGarch)
loglik_t <- function(beta) {sum( - dt((x - beta[1]) / beta[2],
beta[3], log = TRUE) + log(beta[2]) )}
start <- c(mean(x), sd(x), 5)
lower <- c(-1, 0.001, 1)
fit_t <- optim(start, loglik_t, hessian = T, method = "L-BFGS-B", lower = lower)
fit_t$par
0.44232633269102 0.163306955396773 4.12343777572566
The fitted parameters are within acceptable standard errors, and, in addition to mean and sd I have gotten df.
Can somebody advise me please:
Why MASS::fitdistr produces warnings whereas optimization via fGarch::optim succeeds without a warning?
Why there is no df in MASS::fitdistr output?
Is there a way to run MASS:fitdistr on this data without a warning and get df?
Disclaimer:
a similar question was asked couple of times without an answer here and here
You are not passing the lower argument to the function fitdistr which leads it to make a search in positive and negative domain. By passing the lower argument to function
fitt <- fitdistr(x,"t", start = list(m=mean(x),s=sd(x)), df=3, lower=c(-1, 0.001))
you get no NaNs -as you did in your manual optimisation.
EDIT:
fitt <- fitdistr(x,"t", start = list(m=mean(x),s=sd(x),df=3),lower=c(-1, 0.001,1))
returns non-integer degrees of freedom result. However, I guess, the rounded value of it, which is round(fitt$estimate['df'],0) can be used for fitted degrees of freedom parameter.

Difficulty to construct profile confidence interval in lmer model

When I fit lmer model with my data , there is no warning message. But when I tried to construct confidence interval by confint , it shows the following warning message :
Warning messages:
1: In FUN(X[[i]], ...) : non-monotonic profile
2: In nextpar(mat, cc, i, delta, lowcut, upcut) :
Last two rows have identical or NA .zeta values: using minstep
3: In FUN(X[[i]], ...) : non-monotonic profile
Is there any way to overcome the warning message , that is, is there any argument(option) which can remove the problem ? I have used the argument control=lmerControl(optCtrl=list(maxfun=20000)) :
fit <- lmer(Y~X+Z+X:Z+(X||group),data=dat,control=lmerControl(optCtrl=list(maxfun=20000)))

Resources