Efficient Bootstrapping and R Code for Computing M Times - 8,7,2,3,1,1000,10000

  • Thread starter Artusartos
  • Start date
In summary, there are a few issues with the provided code, including not defining the function "delta" before using it, not defining the necessary variables in the for loop, and defining the variable M twice. It would be helpful to define the function and variables beforehand, and to use different variable names for clarity.
  • #1
Artusartos
247
0

Homework Statement



I have the code:

>delta<-function(y,n,sigma,a,b,N){

+T<-rlogis(N,a,b)

+W<-sqrt(n)/(sqrt(2)*pi*sigma)*exp((-n*(y-T)^2)(S*sigma^2))

+d<-mean(T*W)/mean(T)

+return(d)

+}

And I want to compute this M times for y=8,n=7,sigma=2,a=3,b=1,N=1000,M=10000.


Homework Equations





The Attempt at a Solution




So this is what I wrote:

>my.sample<-delta(8, 7, 2,3,1,1000)

+M<-10000

+M;d<-numeric(M)

+for(i in 1:M)

+d=delta(y,n,sigma,a,b,N)

+{

>x<-sample(delta, 10000, replace=TRUE)

>M;d<-mean(x)}

But I keep getting errors, so I must be doing something wrong but I'm not sure what.

In other words, this is how it looks like in R:

> my.sample<-delta(8, 7, 2,3,1,1000)
Error in delta(8, 7, 2, 3, 1, 1000) : attempt to apply non-function
> M<-10000
> M;d<-numeric(M)
[1] 10000
> for(i in 1:M)
+ d=delta(y,n,sigma,a,b,N)
Error in rlogis(N, a, b) : object 'N' not found
> {
+ x<-sample(delta, 10000, replace=TRUE)
+ M;d<-mean(x)}
Error in x[.Internal(sample(length(x), size, replace, prob))] :
object of type 'closure' is not subsettable



I've been trying to fix this for a long time, and it's really frustrating...any help would be appreciated.

Thanks in advance
 
Physics news on Phys.org
  • #2
!

Hello,

It looks like there are a few issues with your code. First, in the line "my.sample<-delta(8, 7, 2,3,1,1000)", you are calling the function "delta" but you have not defined it yet. You need to define the function before you can use it.

Second, in the for loop, you are trying to use the variables y, n, sigma, a, b, and N, but these variables are not defined in the loop. You need to either define them within the loop or pass them as arguments to the function "delta".

Third, in the line "x<-sample(delta, 10000, replace=TRUE)", you are trying to sample from the function "delta", but you should be sampling from the output of the function. So it should be "x<-sample(my.sample, 10000, replace=TRUE)".

Finally, you are defining M twice in your code, which can cause confusion. It would be better to use a different variable name for the length of the vector, such as "n.simulations" or something similar.

I hope this helps! Let me know if you have any other questions.
 

1. What is "Efficient Bootstrapping"?

"Efficient Bootstrapping" is a statistical method used to estimate the uncertainty of a statistical model or study. It involves resampling the data multiple times to create new datasets and then analyzing these datasets to determine the variability of the results.

2. What is the significance of "M Times" in this context?

"M Times" refers to the number of times the data is resampled in the bootstrapping process. The more times the data is resampled, the more accurate the estimates of uncertainty will be.

3. How does R code contribute to efficient bootstrapping?

R code is a programming language commonly used in statistical analysis. It allows for the automation of the bootstrapping process, making it more efficient and accurate. Additionally, R has many built-in functions and packages that make it easier to perform bootstrapping and other statistical analyses.

4. Why are the specific values of "8,7,2,3,1,1000,10000" used in this context?

These values represent the data that is being bootstrapped. In this case, the data is a set of numbers, and the values are simply examples of possible data points. The specific values used may vary depending on the specific study or analysis being performed.

5. How does efficient bootstrapping benefit scientific research?

Efficient bootstrapping provides scientists with a way to estimate the uncertainty of their results and make more informed conclusions. It also allows for the comparison of different statistical models and the identification of potential flaws in the data or analysis. Overall, efficient bootstrapping helps to improve the accuracy and reliability of scientific research.

Similar threads

  • Calculus and Beyond Homework Help
Replies
1
Views
358
  • Calculus and Beyond Homework Help
Replies
7
Views
279
  • Calculus and Beyond Homework Help
Replies
8
Views
874
  • Calculus and Beyond Homework Help
Replies
20
Views
2K
  • Calculus and Beyond Homework Help
Replies
3
Views
269
  • Calculus and Beyond Homework Help
Replies
8
Views
231
Replies
1
Views
625
  • Calculus and Beyond Homework Help
Replies
1
Views
153
  • Calculus and Beyond Homework Help
Replies
3
Views
520
  • Calculus and Beyond Homework Help
Replies
3
Views
811
Back
Top