# Binomial test in R

I need to do a Bernoulli test in R.

Lets say i have a set of data specified to insert (10 random samples of 40). From this there are four possible options, and i wish to assign the likelihood of which is chosen based on their means and sd? the randomly generated samples come from a normal distribution with mean of 25 and sd of 4.

I'm just unsure exactly how to code this in R. Thanks for any help.

-
Could you please clarify this question? What kind of data do you have? What are you trying to learn about them? Where do the 0.3 and 0.7 come from? –  whuber Jul 28 '12 at 19:01
I don't get it, are you asking a new question here? Do you want to know how to do a one sample t-test in R? How are normal data w/ mean=25 & SD=4 related to a Bernoulli? If this is a totally different question, it would be best to start a new question, instead of deleting most of your old one. If the older phrasing let to a misunderstanding & answers that aren't really what you need, we prefer you edit below the original text. –  gung Jul 28 '12 at 20:10

If you want to test that your sample is sampled from a Bernoulli distribution with parameter $p=0.3$ you need to count the number of successes (the 1s) and the size of the sample. Here is an example

# Simulate a random sample of size 17 with p=.3
set.seed(123)
simulated_sample <- runif(17) < 0.3
x <- sum(simulated_sample == TRUE)    # (number of successes)
n <- length(simulated_sample) # (sample size)
# Do the test.
binom.test(x, n, p=0.3)
#   Exact binomial test
#
# data:  x and n
# number of successes = 4, number of trials = 17, p-value = 0.7919
# alternative hypothesis: true probability of success is not equal to 0.3
# 95 percent confidence interval:
#  0.06810774 0.49899327
# sample estimates:
# probability of success
#              0.2352941

-
+1, clear & to the point. One question out of curiosity, any reason you didn't generate data w/ rbinom()? Seems like it would have been the default choice for me (although, I recognize there is nothing wrong w/ the way you did it). –  gung Jul 28 '12 at 19:28
@gung thanks! There is no special reason, it is just a programming habit (because I sometimes like to have series of success available). rbinom is probably more pedagogical, I will use it instead. –  gui11aume Jul 28 '12 at 19:33
@gung, thinking about it I will actually leave it as is for the demo. You usually have a real sample, from which you have to compute the number of successes and the length. Even if these are trivial operations in R I prefer to show them. –  gui11aume Jul 28 '12 at 19:37
Thanks for that. Lets say i have a set of data specified to insert in place of the random generated 17 (10 random samples of 40). From this there are four possible options, and i wish to assign the likelihood of which is chosen based on their means and sd? is this possible in R? –  YesSure Jul 28 '12 at 19:53
Yes of course. I suggest you follow @whuber's advice and edit your post to explain exactly what you want to do. You'll get more appropriate answers then. –  gui11aume Jul 28 '12 at 19:57