Hi I was wondering if anyone could help me as I'm new to R and struggling to work out how to write in equations or to find a function that is already ingrained in R.
So I am currently trying to create a probability density function that generates a random sample of 50,000 draws from the U(0,1) distribution by alternating the values of beta and micro in my formula, naturally as long as beta > 0
I think I should be starting with
m=50000 #where m is the number of draws
runif(m,0,1)
And here's where I get into a bit of a rut and hence I am wondering if anyone could help me out on how to do this.
Thanks in advance for the help.
Related
Sorry if this is a really basic question, but I just couldn't figure it out on my own.
I'm currently learning R for college and I'm trying to figure out how to loop over a range of numbers and input them into a distribution function, like so:
for (i in 0:3) {
dpois(i,2/3)
}
All I'm trying to accomplish here is for R to calculate a Poisson distribution for 0-3, with a lambda of 2/3.
R expects some additional input which I haven't quite figured out.
If I replace dpois with some other function (like print()), the loop works.
Any tips would be greatly appreciated.
Thanks!
R is already vectorized, and as such no for-loop is necessary.
dpois(0:3, 2/3) should do the trick.
Currently I'm interested in learning how to obtain information from the American Community Survey PUMS files. I have read some of the the ACS documentation and found that to replicate weights I must use the following formula:
And thanks to google I also found that there's the SURVEY package and the svrepdesign function to help me get this done
https://www.rdocumentation.org/packages/survey/versions/3.33-2/topics/svrepdesign
Now, even though I'm getting into R and learning statistics and have a SQL background, there are two BIG problems:
1 - I have no idea what that formula means and I would really like to understand it before going any further
2 - I don't understand how the SVREPDESIGN function works nor how to use it.
I'm not looking for someone to solve my life/problems, but I would really appreciate if someone points me in the right direction and gives a jump start.
Thank you for your time.
When you are using svyrepdesign, you are specifying that it is a design with replicated weights, and it uses the formula you provided to calculate the standard errors.
The American Community Survey has 80 replicate weights, so it first calculates the statistic you are interested in with the full sample weights (X), then it calculates the same statistic with all 80 replicate weights (X_r).
You should read this: https://usa.ipums.org/usa/repwt.shtml
I'm trying to simulate two random variables: One with a Normal Dist. and one with an Exp dist. I've run into issues as I cannot seem to find a good way to specify a different distribution for each variable. The column "row.names" is created everytime I run this, and I would like this not to happen. Also, the correlations at the end of the script are not what I was aiming for at the beginning. The code is rough (newish to R) so any advice would be appreciated.
m= matrix(c(1,.8,.8,1),nrow=2)
l=t(chol(m))
normal=matrix(rnorm(100,mean=10,sd=5),nrow=1,ncol=100)
exp=matrix(rexp(100,2), nrow=1,ncol=100)
data=rbind(normal,exp)
data2=t(as.data.frame(t(l)%*%data))
fix(data2)
cor(data2)
Thanks
I want to estimate the forward looking version of the Taylor rule equation using the iterative nonlinear GMM:
I have the data for all the variables in the model, namely (inflation rate), (unemployment gap) and (effective federal funds rate) and what I am trying to estimate is the set of parameters , and .
Where I need help is in the usage of the gmm() function in the {gmm} R package. I 'think' that the parameters of the function that I need are the parameters:
gmm(g, x, type = "iterative",...)
where g is the formula (so, the model stated above), x is the data vector (or matrix) and type is the type of GMM to use.
My problem is with the data matrix parameter. I do not know the way in which to construct it (not that I don't know of matrices in R and all the examples I have seen on the internet are not similar to what I am attempting to do here. Also, this is my first time using the gmm() function in R. Is there anything else I need to know?
Your help will be much appreciated. Thank you :)
Just a warning, I started using R a day ago...my apologies if anything seems idiotically simple.
Right now im trying to have R take in a .txt file with acelerometer data of an impact and calculate a Head injury criterion test for it. The HIC test requires that curve from the data be integrated on a certain interval.
The equation is at the link below...i tried to insert it here as an image but it would not let me. Apparently i need some reputation points before it'll let me do that.
a(t) is the aceleration curve.
So far i have not had an issue generating a suitable curve in R to match the data. The loess function worked quite well, and is exactly the kind of thing i was looking for...i just have no idea how to integrate it. As far as i can tell, loess is a non-parametric regression so there is no way to determine the equation of the curve iteslf. Is there a way to integrate it though?
If not, is there another way to acomplish this task using a different function?
Any help or insighful comments would be very much appreciated.
Thanks in advance,
Wes
One more question though James, how can i just get the number without the text and error when using the integrate() function?
You can use the predict function on your loess model to create a function to use with integrate.
# using the inbuilt dataset "pressure"
plot(pressure,type="l")
# create loess object and prediction function
l <- loess(pressure~temperature,pressure)
f <- function(x) predict(l,newdata=x)
# perform integration
integrate(f,0,360)
40176.5 with absolute error < 4.6
And to extract the value alone:
integrate(f,0,360)$value
[1] 40176.5