Trying to run following R code.
> sp_500 <- sp_500 %>%
+
+ mutate(
+ stock.prices = map(ticker.symbol,
+ function(.x) get_stock_prices(.x,
+ return_format = "tibble",
+ from = "2017-01-01",
+ to = "2017-09-21")
+ ),
+ log.returns = map(stock.prices,
+ function(.x) get_log_returns(.x, return_format = "tibble")),
+ mean.log.returns = map_dbl(log.returns, ~ mean(.$Log.Returns)),
+ sd.log.returns = map_dbl(log.returns, ~ sd(.$Log.Returns)),
+ n.trade.days = map_dbl(stock.prices, nrow)
But I keep getting this error:
Warning: BRK.B download failed; trying again.
Error in mutate_impl(.data, dots) :
Evaluation error: BRK.B download failed after two attempts. Error message:
HTTP error 404..
Does anyone have an idea what am I doing wrong?
Best Regards
AnSa
It seems to have a problem downloading specific tickers. I am not a developer but I had the same problem as you do and fixed it by removing these tickers (less than 10). The code for removing them can be found on the same page where this piece of code is taken from and its
sp_500 <- sp_500 %>%
filter(ticker.symbol != "BRK.B")
I hope it helped.
Basically there is something wrong with the BRK.B stock, I'm not sure what it is, but the way to solve it is by eliminating it/them.
There are other stocks that get stuck in the function, this is how I solve it:
sp_500 <- sp_500[c(-72,-86, -82, -163, -268, -460, -392),] %>%
mutate(
stock.prices = map(ticker.symbol,
function(.x) get_stock_prices(.x,
return_format = "tibble",
from = "2007-01-01",
to = "2018-10-23")
),
log.returns = map(stock.prices,
function(.x) get_log_returns(.x, return_format = "tibble")),
mean.log.returns = map_dbl(log.returns, ~ mean(.$Log.Returns)),
sd.log.returns = map_dbl(log.returns, ~ sd(.$Log.Returns)),
n.trade.days = map_dbl(stock.prices, nrow)
)
The [c(-72,-86, -82, -163, -268, -460, -392),] are the stocks that didn't work for me because it display and error, basically find the columns in which you get errors by looking at the stock name and see in which columns they are and eliminate them
Hope it helps
Related
I'm trying to run a path analysis using the piecewiseSEM package. When I try to run summary or coefs(), I get this error:
Error in cbind(ret, isSig(ret[, 5])) : object 'ret' not found
or:
Error in cbind(ret, isSig(ret[, 5])) : object 'ret' not found
I have no idea what "object ret is. There is nothing in my code named "ret". My spelling is correct. All I have is a model list I called "mod" with two mixed models. The codes I tried to use are below:
mod <- psem(modn, modm)
summary(mod, standardize = "scale", conserve = TRUE)
#####
coefs(mod)
I have to run this as soon as possible and there is no one else to help me. I would really appreciate any comments. Please remember I'm not a skilled programmer so, I'll quote Michael Scott: "Explain this to me like I'm five." lol
Thank you.
modn<-lmer(Nestedness ~ (Category+Prop_ex+Connectance+Assimetry+N_Pol+N_Pla+Dist_eq) + (1|Eco_code), data = sem)
modm<-lmer(Modularity ~ (Category+Connectance+Assimetry+Prop_ex+Dist_eq+N_Pla+N_Pol) + (1|Eco_code),data = sem)
#try 1
mod <- psem(
lmer(Nestedness ~ (Category+Prop_ex+Connectance+Assimetry+N_Pol+N_Pla+Dist_eq) + (1|Eco_code), data = sem),
lmer(Modularity ~ (Category+Connectance+Assimetry+Prop_ex+Dist_eq+N_Pla+N_Pol) + (1|Eco_code),data = sem),
data = sem)
coefs(mod)
#try2
mod <- psem(modn, modm)
summary(mod, standardize = "scale", conserve = TRUE)
Resulting error:
Error in cbind(ret, isSig(ret[, 5])) : object 'ret' not found
in cbind(ret, isSig(ret[, 5])) : object 'ret' not found
delta_gamma = 0.05
MRW.data <- MRW.data %>%
mutate(ln.gdp.85 = log(gdp.85),
ln.gdp.60 = log(gdp.60),
ln.gdp.growth = ln.gdp.85 - ln.gdp.60,
ln.inv.gdp = log(Inv.gdp/100),
Non.oil = factor(Non.oil),
intermediate = factor(intermediate),
OECD= factor(OECD),
ln.ndg = log(pop.growth /100 + delta_gamma)) %>%
select(country, ln.gdp.85, ln.gdp.60, ln.inv.gdp, Non.oil, intermediate, OECD, ln.ndg, ln.school, gdp.growth, ln.gdp.growth)
skim(MRW.data)
Show in New Window
Error in select():
! Must subset columns with a valid subscript vector.
x Can't convert from to due to loss of precision.
Backtrace:
... %>% ...
rlang::cnd_signal(x)
Error in select(., country, ln.gdp.85, ln.gdp.60, ln.inv.gdp, Non.oil, :
x Can't convert from to due to loss of precision.
#2개년(use: df_3 , MSE: 0.02313121)
#선형회귀모델
lm2 <- lm(data = df_3, formula = OPS_y1 ~ (OPS_y2+OPS_y3 + AVG_y2+AVG_y3 + G_y2+G_y3 + GW.RBI_y2+GW.RBI_y3 + H_y2+H_y3 + SAC_y2+SAC_y3)^2) %>% step(direction = "both")
Error in length(obj) : class name too long in 'length'
Once the code has been executed, it will be executed normally. However, if you change the data set and run it again, the same error occurs when you run the first code again. What's the problem? I went to the registry editing window and changed the value of 'LongPathsEnabled' to 1, but it was not resolved. Please solve the problem.
I had the sample problem when using stepwise regression with the step function. In my case there was some package conflict and all was fine after I specified stats::step(...) as follows:
lm2 <- lm(data = df_3, formula = OPS_y1 ~ (OPS_y2+OPS_y3 + AVG_y2+AVG_y3 + G_y2+G_y3 + GW.RBI_y2+GW.RBI_y3 + H_y2+H_y3 + SAC_y2+SAC_y3)^2) %>% stats::step(direction = "both")
As pointed out by user12282991, the problem may be due to package conflicts. The error most probably results from attaching the package recipes, which masks "step" from package:stats. Thus, stepAIC from package MASS or stats::step works.
library(recipes)
step(subclass = paste(rep("A",1000),collapse=""))
gives
Error in (function (x, ...) : class name too long in 'print'.
I am trying to construct rolling risk contributions by each security using the PerformanceAnalytics package. Once I can get past this error I would like to plot the results over time. I keep receiving the error that the subscript is out of bounds and i'm not sure where to start in terms of resolving it. This is the error specifically:
Error in `[.xts`(x, i, which.i = TRUE) : subscript out of bounds
Not very experienced with R. Thank you for any guidance! Here is the code.
library(PerformanceAnalytics)
symbols <- c("SPY","EEM","BND","BIL")
prices <-
getSymbols(symbols, src = 'yahoo', from = "2016-01-01",
auto.assign = TRUE, warnings = FALSE) %>%
map(~Cl(get(.))) %>%
reduce(merge) %>%
`colnames<-`(symbols)
portfolioComponentReturns <- na.omit(Return.calculate(prices, method = "log"))
w = c(.25,.25,.25,.25)
rollingvolpct <- na.omit(rollapply(portfolioComponentReturns,
width=252,
FUN = function(Z)
{
t = StdDev(portfolioComponentReturns,weights = w, portfolio_method = "components", data = as.data.frame(Z), na.rm=T);
return(t$pct_contrib)
},
by.column=FALSE, align="right"))
I cannot seem to get past or understand what is wrong with this error while trying to run the ADF (Augmented Dickey Fuller) test on R-Studio. Will appreciate comments.
library(AER)
library("dynlm", lib.loc="~/R/win-library/3.2")
x<-read.table("C://R Files/protein.csv", header=T, sep=",")
"adf" <- function(x,k = 0, int = TRUE, trend = FALSE){
require(dynlm)
dx <- diff(x)
formula <- paste("dx ~ L(x)")
if(k > 0)
formula <- paste(formula," L(dx,1:k)")
if(trend){
s <- time(x)
t <- ts(s - s[1],start = s[1],freq = frequency(x))
formula <- paste(formula," t")
}
if(!int) formula <- paste(formula," - 1")
summary(dynlm(as.formula(formula)))
}
a<-ts(x$a)
adf(a, k=1, int=T, trend=T)
The error message that I get after this is :
Error in parse(text = x, keep.source = FALSE) :
:1:13: unexpected symbol
1: dx ~ L(x) L
^
It might be this:
formula <- paste(formula," L(dx,1:k)")
You can't just add something to a model. Try doing:
formula <- paste(formula,"+ L(dx,1:k)")
and see if that helps. If not you might want to share the contents of protein.csv so I can try to reproduce your problem.