MCAR (Multivariate Conditional Autoregressive) model in R - r

I am performing a spatial analysis of student grades according to their city of origin using R. I have several covariates such as poverty, education and socio-cultural indices. So far I have fitted univariate models such as: linear regression, weighted linear regression and CAR (conditional autoregressive).
Now, I am reading "Hierarchical Modeling and Analysis for Spatial Data" from Banerjee, Carlin and Gelfand. I am interested in applying multivariate models, in particular a MCAR (Multivariate Conditional Autoregressive) model.
However, I have not found any code in R (or Python) that has it implemented. The most possible has been the "spatialreg" library that includes univariate CAR and SAR models.
Is there any library that you know of that includes them? Thanks in advance

I have found "CARBayes" package. This works perfectly for fitting MCAR model.

Related

estimating heteroskedastic logit model

Suppose (following Train, Discrete Choice Analysis with Simulation, chapter 3.2) you have a discrete choice model, observations from several cities, and you suspect that the variances of the unobserved factors differ over cities. The suggested appropriate
model is heteroskedastic logit (or probit). Can this setup be estimated in R? As far as I can see, the mlogit package doesn't do this
(it doesn't allow you to specify that the source of the heterogeneity is the cities). Is that correct, or am I missing
something? If it is right, any suggestions for an R package?

How to use Brant test with survey ordinal logistic reg (svyolr) to test PO assumption in complex survey data?

I am using the R survey package to estimate an ordinal logistic regression on complex survey data using the function svyolr(). I would like to test the proportional odds assumption with this weighted data, but brant::brant() only seems to work with unweighted models generated using MASS::polr(). Is anyone aware of how to test the PO assumption with a svyolr model?
Brant test reference using brant::brant() on a MASS:polr() model:
https://cran.r-project.org/web/packages/brant/brant.pdf
https://conservancy.umn.edu/bitstream/handle/11299/166205/ThomasA_TheProportionalOddsModel.pdf?sequence=1
Thanks so much!

Generalized linear model for HTS microbiome data

I attempt to conduct generalized linear model in a microbiome dataset (16S HTS).
Given that microbiome dataset is compositional, I am wondering if there are any resources that compatible for doing the analysis.
I am using R package mvabund (doi: 10.1111/j.2041-210X.2012.00190.x), but the examples and documentation did not provide clues on compositional data.
It seems that it is not appropriate to treat the count data as abundance data, would converting the dataset into relative abundance or performing clr-transformation solve the problem?

How to calculate X-year survival probability from a cox regression of random survival forest in R

I want to build a survival model then calculate the X-year (e.g. 10-year) risk of survival.
Is there a way to do this using coxph or survreg? Is this possible using random survival forest (e.g. ranger)?
P.S. not sure if important but data is wide (~100 features - mostly continuous) and 17k samples.
For anyone else trying to do the same. If you build a cox-model with survival::coxph or rms::cph you can use the function pec::predictSurvProb.

Consider autocorrelation in a Linear Quantile mixed models (LQMM)

(I am using R and the lqmm package)
I was wondering how to consider autocorrelation in a Linear Quantile mixed models (LQMM).
I have a data frame that looks like this:
df1<-data.frame( Time=seq(as.POSIXct("2017-11-13 00:00:00",tz="UTC"),
as.POSIXct("2017-11-13 00:1:59",tz="UTC"),"sec"),
HeartRate=rnorm(120, mean=60, sd=10),
Treatment=rep("TreatmentA",120),
AnimalID=rep("ID01",120),
Experiment=rep("Exp01",120))
df2<-data.frame( Time=seq(as.POSIXct("2017-08-11 00:00:00",tz="UTC"),
as.POSIXct("2017-08-11 00:1:59",tz="UTC"),"sec"),
HeartRate=rnorm(120, mean=62, sd=14),
Treatment=rep("TreatmentB",120),
AnimalID=rep("ID02",120),
Experiment=rep("Exp02",120))
df<-rbind(df1,df2)
head(df)
With:
The heart rates (HeartRate) that are measured every second on some animals (AnimalID). These measures are carried during an experiment (Experiment) with different treatment possible (Treatment). Each animal (AnimalID) was observed for multiple experiments with different treatments. I wish to look at the effect of the variable Treatment on the 90th percentile of the Heart Rates but including Experiment as a random effect and consider the autocorrelation (as heart rates are taken every second). (If there is a way to include AnimalID as random effect as well it would be even better)
Model for now:
library(lqmm)
model<-lqmm(fixed= HeartRate ~ Treatment, random= ~1| Exp01, data=df, tau=0.9)
Thank you very much in advance for your help.
Let me know if you need more information.
For resources on thinking about this type of problem you might look at chapters 17 and 19 of Koenker et al. 2018 Handbook of Quantile Regression from CRC Press. Neither chapter has nice R code to go from, but they discuss different approaches to the kind of data you're working with. lqmm does use nlme machinery, so there may be a way to customize the covariance matrices for the random effects, but I suspect it would be easiest to either ask for help from the package author or to do a deep dive into the package code to figure out how to do that.
Another resource is the quantile regression model for mixed effects models accounting for autocorrelation in 'Quantile regression for mixed models with an application to examine blood pressure trends in China' by Smith et al. (2015). They model a bivariate response with a copula, but you could do the simplified version with univariate response. I think their model only at this points incorporates lag-1 correlation structure within subjects/clusters. The code for that model does not seem to be available online either though.

Resources