Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
Generating a Random Walk in R is pretty easy. It's done by the following code:
x <- rnorm(100)
y <- cumsum(x)
But how do I generate/simulate a Random Walk with Trend and / or Drift?
A slightly more compact/efficient version of the code from here:
cumsum(rnorm(n=100, mean=drift, sd=sqrt(variance)))
should give you a realization of a random walk with variance t*variance and mean t*drift, where t is the index (starting from 1; prepend a zero or add a constant to the whole series if you like).
Related
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 6 days ago.
Improve this question
Code:
data(tips)
tips%>%
group_by(sex)%>%
summarize(variance=var(tip))
Output:
variance
1 1.914455
The output isn't the desired one. The result should be a tibble with variance computed against each group (in this case, sex). The summarize function is computing the variance of the entire tip column, rather than calculating the variance of each group.
Tried executing the code and restarting RStudio several times, but it didn't work.
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 4 years ago.
Improve this question
I am doing an exercise to create a function. One of the questions is:
"We can estimate the cumulative risk of an certain event using the
exponential formula
1-exp(-1/10000*t) where t is the time to the event. Create a function ans(t), which returns the risk at time t.
and I am using this command:
function(t){ans(t)<-1-exp(-1/10000*t)return(ans(t))}
but it is giving wrong answer. Can someone help me to understand this please?
The proper format to define a function is this:
ans<-function(t){
answer<-1-exp(-1/10000*t)
return(answer)
}
ans(1)
#[1] 9.9995e-05
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 4 years ago.
Improve this question
I would like to calculate Mann Attached imageKendall statistics in R. i have an excel sheet with rainfall and years. how would i best get it
Looking at the attached image you should not put Book1$Mean in quotes. Try using:
MannKendall(Book1$Mean)
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 5 years ago.
Improve this question
(USING R)
So I imported a data set by using
xcars <- read.csv(file.choose())
and then I chose my data set which was originally an excel file.
So, I have a column named dist (short for displacement) and I want to choose the first 25 entries underneath that column and then plot it on a histogram, so I attempted the following.
carsUpTo25 <- xcars(1:25,)
hist(carsUpTo25$dist)
Of course this didn't work. However, any help on how I would do this would be helpful.
Try this-
hist(xcars[,dist[1:10]])
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 6 years ago.
Improve this question
This is the R command I used to create a decision tree,
k <- C5.0(data1[1:16000,-32],as.factor(data2{1:16000,32])
but this output I get for error:
Error: unexpected '{' in "k <- C5.0(data1[1:16000,-32],as.factor(data2{"
Did I forget a bracket? I couldn't figure out why
Try
k <- C5.0(data1[1:16000,-32],as.factor(data2[1:16000,32]))
You used { instead of [ at the end and you also forgot to include another ) to wrap up your C5.0 function.