Error for create_slope_cs function in the leastcostpath package - r

guys! I encountered an error when creating a cost surface based on DEM data.
Adm1 <-
rgeoboundaries::geoboundaries(
country = "Austria",
adm_lvl = "adm0")
r <- get_elev_raster(Adm1,z=4)
cs <- create_slope_cs(dem = r, cost_function = 'tobler', neighbours = 16)
The error is like
Error in h(simpleError(msg, call)) :
error in evaluating the argument 'x' in selecting a method for function 'extent': ‘srs’ is not a slot in class “BasicRaster”
I can run this code on my other laptop. So I think there's nothing wrong with my code. But do you know how to fix this?

Related

R - Error in h(simpleError(msg, call)) : err in arg 'x' in selecting a mthd for fun 'as.matrix': not-yet-implemented mthd 4 <df> %*% <dgMatrix>

This one is a real headscratcher.
All of the code included in this question and the datasets loaded into my script can be found in my GitHub Repository for this applied predictive analytics (using R) project.
First thing is first, the actual full error message I got in the console without any abbreviations was the following:
Error in h(simpleError(msg, call)) : error in evaluating the argument 'x' in selecting a method for function 'as.matrix': not-yet-implemented method for <data.frame> %*% <dgCMatrix>
I have a 225 by 3808 dataframe called data2014 where I have already deliberately removed all non-numeric columns and interpolated all NAs in it initially. This error appears multiple times for me as I attempt to run/train a Ridge Regression on my stock data from 2014.
The first time it appears is when running the following lines of code:
library(Matrix)
library(glmnet)
#grid1 <-
ridge1.mod = glmnet(x = data2014, y = pr_var2014, alpha = 0,
standardize = TRUE)
dim(coef(ridge1.mod))
ridge1.mod
summary(ridge1.mod)
ridge1.pred = predict(ridge1.mod, newx = data2015)
> ridge1.pred = predict(ridge1.mod, newx = data2015)
Error in h(simpleError(msg, call)) :
error in evaluating the argument 'x' in selecting a method for function 'as.matrix': not-yet-implemented method for <data. Frame> %*% <dgCMatrix>
Note: I previously removed the column in data_2014 which had observed values for the percentage variation in the price of that stock the following year after assigning it to the object pr_var2014 (I misnamed it, it should be called pr_var2015) to avoid any potential multicollinearity issues when predicting that variable/column.
And the second time the identical error message appears in the Console is after running the two following lines of code directly below that, namely:
set.seed(11)
cv.out1 = cv.glmnet(data2014, pr_var2014, alpha = 0)
> cv.out1 = cv.glmnet(data2014, pr_var2014, alpha = 0)
Error in h(simpleError(msg, call)) :
error in evaluating the argument 'x' in selecting a method for function 'as.matrix': not-yet-implemented method for <data.frame> %*% <dgCMatrix>
These erros are especially perxlexing to me because I am going directly off of the directions for how to run a Ridge Regression in the well known and well respected textbook "An Introduction to Statistical Learning with Applications in R", so I don't understand what could be the problem here.

I am receiving 'Error in !toroidal : invalid argument type'

I am trying to run a supervised SOM model based on cross-validated values.
The issue seems is in the sup.som line. I receive this error: Error in !toroidal : invalid argument type.
This code has worked fine in the past (within past few days) and I have tried restarting RStudio. There was a very similar question here (Error in !toroidal : invalid argument type in R with som package) but the issue seemed to have resolved itself for the other person. Any help is appreciated!
My code is:
require(kohonen)
set.seed(123)
fitControl <- trainControl(method = "cv",number = 10)
tg <- expand.grid(xdim=c(3:10), ydim=c(3:10), user.weights=seq(0.1,0.9,by=0.1), topo="hexagonal")
somFit1 <- train(train[,1:6], as.factor(train$CORR), method="xyf", trControl=fitControl, tuneLength=20, tuneGrid=tg)
'''sup.som <- xyf(training.sc, classvec2classmat(corrupt.train), grid = somgrid(xdim=somFit1$bestTune$xdim, ydim=somFit1$bestTune$ydim, topo="hexagonal"), user.weights=somFit1$bestTune$user.weights, keep.data=TRUE)
I ended up trying my code in the R console to see if I could get more detailed error messages, and I got the following:
require(class)
Loading required package: class
Attaching package: ‘class’
The following object is masked from ‘package:kohonen’:
somgrid
The solution was to specify kohonen::somgrid before my code as follows:
sup.som <- xyf(training.sc, classvec2classmat(corrupt.train), grid = kohonen::somgrid(xdim=somFit1$bestTune$xdim, ydim=somFit1$bestTune$ydim, topo="hexagonal"), user.weights=somFit1$bestTune$user.weights, keep.data=TRUE)
Hope this helps someone else

Getting error using neuralnet function at R

I am getting an error, while running the below code:
library(neuralnet)
library(datasets.load)
Neural_Net = neuralnet(formula = dist ~ mag , data = attenu, hidden = C(1,3) )
I get the below error:
Error in C(1, 3) : object not interpretable as a factor
I couldn't solve the problem. Where am I doing wrong?
I will be very glad for any help. Thanks a lot.

invalid type (list) message in applying gmm method

The moment condition function is simply exp(-g/r)-1, where g is a known series of daily return on AAA-class bond index, and r is the rikiness measure to be derived through gmm. My codes are as follows:
View(Source)
library(gmm)
data(Source)
x <- Source[1:5200,"AAA"]
m <- function(r,x)
{m.1 <- exp(-x[,"AAA"]/r)-1}
summary(gmm(m,x,t0=1,method="BFGS",control=1e-12))
Which in term yields the following error message:
****Error in model.frame.default(formula = gmat ~ 1, drop.unused.levels = TRUE) :
invalid type (list) for variable 'gmat'****
Could anyone help me figure out what went wrong?
Thanks a lot!
For those kind people who would like to replicate the results, please find attached the source data as mentioned above.
The correct r is 1.590 , which can be solved through goal searching in excel, with target function :(average(exp(-g/r)-1) )^2 and target value: 0 (tolerance: 1e-12)
https://docs.google.com/spreadsheets/d/1AnTErQd2jm9ttKDZa7On3DLzEZUWaz5Km3nKaB7K18o/edit?usp=sharing

Error inmatrix : Non-numeric matrix Extent

I was trying to run GSA(Gene Set enrichment Analysis) function in R using the Biobase package: Expression Set.
I was using the resp.type to be "Two class unpaired" .But when i run the function :
gsa <- GSA(x=exprs(Eset), genesets=genesets, genenames=genenames, y = as.integer(factor), resp.type= "Two class unpaired", minsize=2,maxsize=500,nperms=500)
It gives me an error saying :
Error in matrix(1, nrow = n, ncol = 1) : non-numeric matrix extent
I dont know what this error means.I did mode(exprs(eset)),it gives me "numeric"
Can anybody tell me how to get rid of this problem?

Resources