Quantile Mapping in R - r

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)
}
}

Related

SuperLearner Error in R - Object 'All' not found

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)

Error in "getCovariate.corSpatial" with gamm function

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!

Exponential smoothing not recognizing my data as time series

I have a data set that includes t(time) which ranges from 1-243 and 5 other variables which are separate company stock prices each also containing 243 data points. I want to run exponential smoothing on my variable "HD". I am trying to run the following command:
library(smooth)
smoothhd <- es(mydata$HD, h=10, holdout=TRUE, silent=FALSE, cfTYPE=MSE)
However, when I do I receive the following error:
The provided data is not ts object. Only non-seasonal models are available.
Forming the pool of models based on... ANN, AAN, Estimation progress: 100%... Done!
Error in .External.graphics(C_layout, num.rows, num.cols, mat, as.integer(num.figures), :
invalid graphics state.
Does anyone have any insight as to what is wrong with my command or what might need to be changed with my data file in order for this command to give me the smoothed data?
It just seems that your mydata$HD is not a time series object.
Try run is.ts(mydata$HD) and if it is not just coerce it to it with as.ts(mydata$HD).

Issue with LCMM Plot Code (invalid subscript type 'list')

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.

plotfit.fd is upset about my names. Cannot plot and cannot understand error

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.

Resources