Can't run the "rDEA" package, in R - r

I'm terrible when it comes to run models with R. I'm trying to run the following command, that can be found here:
## load data on Japanese hospitals (Besstremyannaya 2013, 2011)
data("hospitals", package="rDEA")
## inputs and outputs for analysis
Y = hospitals[c('inpatients', 'outpatients')]
X = hospitals[c('labor', 'capital')]
W = hospitals[c('labor_price', 'capital_price')]
## Naive input-oriented DEA score for the first 20 firms under variable returns-to-scale
firms=1:20
di_naive = dea(XREF=X, YREF=Y, X=X[firms,], Y=Y[firms,], model="input", RTS="variable")
di_naive$thetaOpt
## Naive DEA score in cost-minimization model for the first 20 firms under variable returns-to-scale
ci_naive = dea(XREF=X, YREF=Y, X=X[firms,], Y=Y[firms,], W=W[firms,],
model="costmin", RTS="variable")
ci_naive$XOpt
ci_naive$gammaOpt
The command works very well, but, when I try to run the command applied to my data, I get the this stuff here:
> ## inputs and outputs for analysis
> Y = data[c('V7', 'V8')]
Error in data[c("V7", "V8")] :
object of type 'closure' is not subsettable
> X = data[c('V3', 'V4','V5','V6')]
Error in data[c("V3", "V4", "V5", "V6")] :
object of type 'closure' is not subsettable
> W = data[c('V2')]
Error in data[c("V2")] : object of type 'closure' is not subsettable
> ## Naive input-oriented DEA score for the first 20 firms under variable returns-to-scale
> firms=1:19
> di_naive = dea(XREF=X, YREF=Y, X=X[firms,], Y=Y[firms,], model="input", RTS="variable")
Error in dea.input(XREF = XREF, YREF = YREF, X = X, Y = Y, RTS = RTS) :
object 'X' not found
> di_naive$thetaOpt
Error: object 'di_naive' not found
> ## Naive DEA score in cost-minimization model for the first 20 firms under variable returns-to-scale
> ci_naive = dea(XREF=X, YREF=Y, X=X[firms,], Y=Y[firms,], W=W[firms,],
+ model="costmin", RTS="variable")
Error in dea.costmin(XREF = XREF, YREF = YREF, X = X, Y = Y, W = W, RTS = RTS) :
object 'X' not found
> ci_naive$XOpt
Error: object 'ci_naive' not found
> ci_naive$gammaOpt
Error: object 'ci_naive' not found
>
Someone can give me a hand?

Related

getting an error in decision tree model (R)

library(tree)
set.seed(1)
train=1:80
sum(is.na(sobija1))
hist(sobija1$CCSI)
sss=ifelse(sobija1$CCSI<=100, "negative","positive" )
sss=as.factor(sss)
sobija1=data.frame(sobija1,sss)
Tree_Class=tree(sss~sobija1$unemployment_rate+sobija1$house_pirce_index,sobija1,subset=train)
print(summary(Tree_Class))
plot(Tree_Class)
text(Tree_Class, pretty=0, cex=0.75)
cat("\n Confusion table for classification trees \n")
print(table(predict(Tree_Class,newdata = sobija1[-train,],type = "class"), sss[-train]))
> print(table(predict(Tree_Class,newdata = sobija1[-train,],type = "class"), sss[-train]))
Error in table(predict(Tree_Class, newdata = sobija1[-train, ], type = "class"), :
all arguments must have the same length
In addition: Warning message:
'newdata' had 41 rows but variables found have 121 rows
I tried to make a decision tree model, and was trying to make a matrix to check the error rate, but this error came up and now I have no idea how fix it.

GARCH modeling in R and error message "Error in .extractdata(data) : 'list' object cannot be coerced to type 'double'"

I am trying to model the amount of revenues with GARCH using the rugarch package. Whenever I try and run the GARCH code, I always get the same error message, with it being
"Error in .extractdata(data) :
'list' object cannot be coerced to type 'double'"
I will include all of my code below, as well as the various things I have tried to use to get rid of this error message. If I need to include more code/specify more things in the future, I am open to suggestions (relatively still new with R). Any help is appreciated!
imtired <- read_excel("C:\\Users\\zacha\\OneDrive\\Desktop\\Research for roadmap\\imtired.xlsx")
New names:
* `` -> ...1
> netrevenues = subset(imtired, select = -c(...1, Price, SalesVolume, GrowthRate ) )
> names(netrevenues)[names(netrevenues)=="NetRevenues"]<-"Revenue"
> head(netrevenues)
# A tibble: 6 x 1
Revenue
<dbl>
1 25366503.
2 25073396.
3 22637624.
4 16729842.
5 19797980.
6 18226119.
str(netrevenues)
tibble [638 x 1] (S3: tbl_df/tbl/data.frame)
$ Revenue: num [1:638] 25366503 25073396 22637624 16729842 19797980 ...
#build first GARCH model
netrevenues1 <- ugarchspec(variance.model = list(model = "sGARCH", garchOrder = c(1,1)),
mean.model = list(armaOrder = c(1,1)), distribution.model = "std")
netrevenuesGarch1 <- ugarchfit(spec = netrevenues1, data = netrevenues)
I suspect that the problem lies in passing a tibble instead of numeric values into the ugarch-function.
When I had a similar problem, as.numeric(unlist(netrevenues))did the job.
I found this solution and a related discussion here
https://www.programmingr.com/r-error-messages/list-object-cannot-be-coerced-to-type-double/ and here
How to coerce a list object to type 'double' .

R-error: object cannot be coerced to type 'double' & non-conformable arrays

I'm just trying to built a very easy Naive and SNaive forecasting model in RStudio, but somehow I keep bumping to an error when I'm trying to plot the accuracy metrics.
Amtrak.data = read_excel("Amtrak.xlsx")
Data.ts = ts(Amtrak.data$column1, start = c(1991,1), end = c(2004, 3), freq = 12)
nValid = 36
nTrain = length(Data.ts) - nValid
train.ts = window(Data.ts, start = c(1991,1), end = c(1991, nTrain))
valid.ts = window(Data.ts, start = c(1991, nTrain +1), end = c(1991, nTrain + nValid))
naive.pred = naive(train.ts, h = nValid)
snaive.pred = snaive(train.ts, h = nValid)
accuracy(naive.pred, valid.ts)
accuracy(snaive.pred, valid.ts)
Error that occurs:
Error in NextMethod(.Generic) :
(list) object cannot be coerced to type 'double'
In addition: Warning message:
In !=.default(actual, predicted) :
longer object length is not a multiple of shorter object length
I already tried adjusting the values in matrices, like this:
naive.pred = as.matrix(naive.pred)
snaive.pred = as.matrix(snaive.pred)
valid.ts = as.matrix(valid.ts)
But that only partly fixes the error:
Error in actual != predicted : non-conformable arrays
I'm getting very frustrated, as this is supposed to be really easy.. Somebody know how to fix this?

Ldahist(0 function Object not found

I am learning LDA using Wine data.
The dependent variable is called "Type" with 13 predictors.
wine.lda<-lda(Type ~., data = wine)
wine.lda$svd
wine.lda.values <- predict(wine.lda)
ldahist(data = wine.lda.values$x[,1], g=Type)
######OUTPUTS#########
> wine.lda<-lda(Type ~., data = wine)
> wine.lda$svd
[1] 28.18958 19.00634
> wine.lda.values <- predict(wine.lda)
> ldahist(data = wine.lda.values$x[,1], g=Type)
Error in ldahist(data = wine.lda.values$x[, 1], g = Type) :
object 'Type' not found
Everything was just fine. But when I tried to plot histogram. It gave me this error "object not found". I checked my code several times, but i couldnt find the reason.
Any help would be appreciated. Thanks!

Error when plotting HoltWinters graph

The following R code is giving me an error when trying to plot the HoltWinters graph as done here:
# init X
X11()
# get data
mydata = read.csv("lookup.csv", header=TRUE, stringsAsFactors=FALSE)
# data post-proc
mydata = as.data.frame(mydata)
mydata$Time = as.POSIXlt(mydata$Time, format='%d.%m.%Y %H:%M:%S')
# create time series - hourly data -> 8765 hours/year
dataTimeSeries <- ts(mydata$Close, frequency=8765)
dataForecasts = HoltWinters(dataTimeSeries, beta=FALSE, gamma=FALSE)
# output
plot.ts(dataForecasts)
message("Press Return To Continue")
invisible(readLines("stdin", n=1))
The error I'm getting is:
$ Rscript simple_forecast.R
Error in xy.coords(x, NULL, log = log) :
(list) object cannot be coerced to type 'double'
Calls: plot.ts -> plotts -> xy.coords
Execution halted
I'm quite perplexed, since print(dataForecasts) prints the correct data. I can also plot dataTimeSeries without a problem.
lookup.csv (pastebin)
Generally one should rely upon R to do the dispatch of class-dependent functions, and do notice that the example you cited at Avril Coghlan's page only used plot, not plot.ts.
(m <- HoltWinters(co2))
plot.ts(m)
Error in xy.coords(x, NULL, log = log) :
(list) object cannot be coerced to type 'double'
plot(m) # success

Resources