r

forecast and fable return different outputs on same dataset for forecasting in R

泄露秘密 提交于 2021-02-10 05:36:06
问题 I am trying to understand the different between two forecasting package forecast and fable , as the two editions of the same book (second edition and third edition seems to imply that the two packages are equivalent. library(dplyr) raw <- c(44.4082519001086, 47.1074380165289, 43.5633367662204, 43.1003584229391, 42.5828970331588, 38.3217993079585, 38.5751520417029) # raw <- c(raw,rev(raw)) forecast.df <- ts(raw) forecast::autoplot(forecast.df) + forecast::autolayer(forecast::holt(forecast.df

R error “object 'required_pkgs' not found whilst loading namespace 'timetk'”

五迷三道 提交于 2021-02-10 05:34:49
问题 I am using R 4.0.3 with RStudio 1.2.5033 on macOS 11.1. I have successfully installed the package using install.packages("timetk") . When trying to load the package with library(timetk) , I get the following error: Error: package or namespace load failed for ‘timetk’: object 'required_pkgs' not found whilst loading namespace 'timetk' I do not know how to solve this. Can anyone please offer help or advice? Thank you, C 回答1: This seems to be an error with the package, an is a known issue on

R error “object 'required_pkgs' not found whilst loading namespace 'timetk'”

生来就可爱ヽ(ⅴ<●) 提交于 2021-02-10 05:33:39
问题 I am using R 4.0.3 with RStudio 1.2.5033 on macOS 11.1. I have successfully installed the package using install.packages("timetk") . When trying to load the package with library(timetk) , I get the following error: Error: package or namespace load failed for ‘timetk’: object 'required_pkgs' not found whilst loading namespace 'timetk' I do not know how to solve this. Can anyone please offer help or advice? Thank you, C 回答1: This seems to be an error with the package, an is a known issue on

How can I rotate labels in ggplot2? [duplicate]

做~自己de王妃 提交于 2021-02-10 05:33:09
问题 This question already has an answer here : How to use angle in geom_label? (1 answer) Closed 7 hours ago . I have a scatter graph with lables. I want to rotate lables - instead of horizontal position I want to see them vertically. I only saw q-s about rotating axis lables on Stackoverflow. Sample: mtdata <- mtcars %>% rownames_to_column(var = "name") ggplot(mtdata, aes(x = mpg, y = wt)) + geom_point() + geom_label(data = mtdata %>% filter(mpg > 20 & wt >3), aes(label = name)) 回答1: You can use

r - copy missing values from other variables

风流意气都作罢 提交于 2021-02-10 05:31:35
问题 Simple question, but I can't figure out how to do the following. This is my data: ID Time1 Time2 Time3 Time4 01 23 23 NA NA 02 21 21 21 NA 03 22 22 25 NA 04 29 29 20 NA 05 NA NA 15 22 06 NA NA 11 NA Now, I want to replace missing values (NA) with the data that is available in other variables. Importantly, I need r to take the value that is 'closest' to the missing data point. E.g., for ID 5, Time1 and Time2 should be "15" (not "22"). Like this: ID Time1 Time2 Time3 Time4 01 23 23 23 23 02 21

Alternative for sample

Deadly 提交于 2021-02-10 05:29:05
问题 I have the following sample code that uses sapply which takes long to process (since executed many times): samples = sapply(rowIndices, function(idx){ sample(vectorToDrawFrom, 1, TRUE, weights[idx, ]) }) The issue is that I have to draw from the weights which are in the matrix, dependent on the indices in rowIndices . Does somebody have a better idea in mind to draw from the rows of the matrix? Reproducable example: rowIndices = floor(runif(1000, 1, 100)) vectorToDrawFrom = runif(5000, 0.0, 2

Scrape tables by passing multiple search requests using R

馋奶兔 提交于 2021-02-10 05:27:08
问题 I'm trying to search for multiple times on a website using First and last name (https://npiregistry.cms.hhs.gov/registry/) and then create a dataframe of the output I figured out that this is similar to what has been described in How to automate multiple requests to a web search form using R, but for some reasons I've been getting the error "Error: failed to load external entity"` Below is the code that I'm using to pull records fn = rep(c('HARVEY','HARVEY')); ln = rep(c('BIDWELL','ADELSON'))

How to calculate p-values from cross-correlation function in R

风流意气都作罢 提交于 2021-02-10 05:20:40
问题 I calculated a cross-correlation of two time series using ccf() in R. I know how to derive the confidence limits as: ccf1 <- ccf(x=x,y=y,lag.max=5,na.action=na.pass, plot=F) upperCI <- qnorm((1+0.95)/2)/sqrt(ccf1$n.used) lowerCI <- -qnorm((1+0.95)/2)/sqrt(ccf1$n.used) But what I really need is the p-value of the maximum correlation. ind.max <- which(abs(ccf1$acf[1:11])==max(abs(ccf1$acf[1:11]))) max.cor <- ccf1$acf[ind.max] lag.opt <- ccf1$lag[ind.max] How do I calculate this p-value? I have

Error with using the mlogit R function: the two indexes don't define unique observations

落爺英雄遲暮 提交于 2021-02-10 05:14:06
问题 I've got a problem with the mlogit funtion in R. My dataset looks like this: personID caseID altID choice a1 a2 a3 a4 1 1 1 1 3 0 3 1 1 1 2 0 1 3 0 1 1 1 3 0 4 4 4 4 1 2 1 0 2 2 1 3 1 2 2 1 2 3 1 3 etc.... I've tried running the following code, performing the model. setV2 <- mlogit.data(data = setV2, choice = "choice", shape = "long", alt.var = "altID", chid.var = "personID") m <- mlogit(choice ~ a1 + a2 + a3 + a4 | -1, rpar = c(a1 = "n", a2 = "n", a3 = "n", a4 = "n"), correlation = FALSE,

creating pairs for network analysis

ⅰ亾dé卋堺 提交于 2021-02-10 05:13:25
问题 From my dataset I'm trying to make pairs based on a ranking. my data looks like ID grp rank 1 grp1 1 1 grp2 1 1 grp3 2 2 grp1 1 2 grp2 2 2 grp2 2 2 grp2 2 2 grp3 2 2 grp1 3 The output I am aiming for is the following: for each ID if rank = 1 then grp in source and destination are the same = grp If rank is different from 1 then source = take grp from previous rank destination = take group from current rank If more then one group exist for the same ranking then an additional line needs to be