I am trying to eliminate spatial autocorrelation using the gamm function using the following code:
model.data.cp.gamm.exp<-gamm(CP~s(YEAR), random=list(Ambience=~1), corSpatial(form=~Lat+Lon, type="exp", metric="euc"), data=data)
Sometimes I change the type to lin, rat, sph and gau.
However, for all cases, I keep getting the error:
Error in getCovariate.corSpatial(object, data = data) : cannot have zero distances in "corSpatial"
Although I have removed all duplicate coordinates within each year from my data, some are repeated over time and there is no way for me to change that. Does anyone know how to fix this error?
Thank you!
Related
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)
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 am trying to bias correct PRECIS data for precipitation and temperature using different techniques for selecting the best one out of all.
I am stuck up with an error while using 'qmap' package in R. It helped in giving results for an area averaged (2D Netcdf) dataset in the form of a 2D plot which also showed improved correlation when validated with the observation dataset.
I am facing a problem when I am trying to run the same function over the entire 3D dataset.
On running the following:
test=fitQmap(Observation_data,Model_data, method =
"PTF",transfun="scale",cost="RSS",wett.day=TRUE)
I am encountered with this error:
"Error in x[!nas] : object of type 'S4' is not subsettable"
Kindly help me out in getting rid of the error as I am a beginner in handling climate datests in R. Any help would be appreciated.
You have to use the same command, just run a loop over all the latitude and longitude dimension.
Am assuming your time dimension is 3rd.
First create an empty matrix with Nan values
OUTPUT<-array(NA,c(length(lon),length(lat),length(time)))
for (i in 1:length(lat))
{
for (j in 1:length(lon))
{
Observation<-Observation_data[i,j,]
Model<-Model_data[i,j,]
test=fitQmap(Observation,Model, method = "PTF",transfun="scale",cost="RSS",wett.day=TRUE)
OUTPUT[i,j,]<- doQmapDIST(Test_data$Model[i,j,],test)
rm(test)
}
}
I'm using R's coxph function to fit a survival regression model, and I'm trying to model time dependent covariates (see this vignette). When fitting the model, I get the following error:
Error in aeqSurv(Y) :
aeqSurv exception, an interval has effective length 0
Other than the source code, I couldn't find any references to this error online. Would appreciate any ideas about how to handle this exception.
I found the same error. Probably the cause is the aeqSurv routine that treats time values such that tiny differences are treated as a tie. This is actually useful and the error is potentially pointing an issue with the data.
However, if we need to force a solution you can use the coxph.options.
Just setting timefix = FALSE in the call to coxph should make the trick!
Source:
https://rdrr.io/cran/survival/src/R/aeqSurv.R
I had this error after I used the survSplit function to make time intervals, prior to fitting with coxph. I noticed that survSplit introduced trailing digits (i.e., 20 days turned into 20.0 days). So I removed those digits with the round function and it worked.
Like the above answer, adding the control variable in the coxph function should solve the problem. Please see the reference: https://github.com/therneau/survival/issues/76
model <- coxph(formula = Surv(time1, time2, event) ~ cluster(cluster),
data = dataframe,
control = coxph.control(timefix = FALSE)) # add the control variable
I am using vegan::rarecurve on community data.
lac.com.data<-wisconsin(lac.com.data)
rarecurve(lac.com.data)
Unfortunately, I am getting an error and cannot figure out how to fix it.
Error in seq.default(1, tot[i], by = step) : wrong sign in 'by' argument
I tried
rarecurve(lac.com.data,step=1)
to no avail.
I already generated a tabasco() graph and performed a Wisconsin standardization on the data frame without any problem.
There is no reproducible example. However, your usage is wrong. Function rarecurve needs input data of counts: it samples individuals from each sampling unit (row), and therefore you must have data on individuals. The error is caused by the use of wisconsin(lac.com.data): after that all rowSums(lac.com.data) will be 1, and your data are non-integers. You cannot use rarecurve for wisconsin() transformed data or any other non-integer data. Here the error manifests because the estimated numbers of individuals (rowSums of transformed data which are all 1) are lower than the number of species (>1).
Obviously we need to check input in rarecurve. We assumed that people would know what kind input is needed, but we were wrong.