Tossing 3 fair coins in R (2)Tossing 3 fair coins in RSolving statistics question using PythonSimulate coin toss for one week?Outcome of a simulated dice and coin toss in RCoin Toss game in RProbability - Coin TossingCalculating observed values from a coin-toss simulation in RDFA for expected coin tossesUnbiased coin toss of n coins with different success values for each coinImplementing Predictive Posterior Distribution Using StanTossing 3 fair coins in R
Does an advisor owe his/her student anything? Will an advisor keep a PhD student only out of pity?
What are the advantages of simplicial model categories over non-simplicial ones?
Picking the different solutions to the time independent Schrodinger eqaution
On a tidally locked planet, would time be quantized?
Open a doc from terminal, but not by its name
putting logo on same line but after title, latex
Is there a way to get `mathscr' with lower case letters in pdfLaTeX?
The IT department bottlenecks progress. How should I handle this?
Calculate sum of polynomial roots
Quoting Keynes in a lecture
What if a revenant (monster) gains fire resistance?
Why Shazam when there is already Superman?
What happens if you are holding an Iron Flask with a demon inside and walk into an Antimagic Field?
Limits and Infinite Integration by Parts
What does "Scientists rise up against statistical significance" mean? (Comment in Nature)
Lowest total scrabble score
Why does AES have exactly 10 rounds for a 128-bit key, 12 for 192 bits and 14 for a 256-bit key size?
Does IPv6 have similar concept of network mask?
Using substitution ciphers to generate new alphabets in a novel
Angel of Condemnation - Exile creature with second ability
Is aluminum electrical wire used on aircraft?
How does the math work for Perception checks?
Temporarily disable WLAN internet access for children, but allow it for adults
How do you make your own symbol when Detexify fails?
Tossing 3 fair coins in R (2)
Tossing 3 fair coins in RSolving statistics question using PythonSimulate coin toss for one week?Outcome of a simulated dice and coin toss in RCoin Toss game in RProbability - Coin TossingCalculating observed values from a coin-toss simulation in RDFA for expected coin tossesUnbiased coin toss of n coins with different success values for each coinImplementing Predictive Posterior Distribution Using StanTossing 3 fair coins in R
If X = # of heads showing when three coins are tossed, find P(X=1), and E(X).
The experiment has the following distribution:
According to my calculation,
P(X=1) = 0.375 ≈ 0.40
E(X) = 1.50
And,
where n = # of repetitions of the experiment.
Source Code
noOfExperiments = 10000;
mySample <- sample(c(0,1,2,3), noOfExperiments, replace = T)
outcomeCount <- length(which(mySample==1))
prob <- outcomeCount / noOfExperiments
eX <- sum(mySample)/noOfExperiments
According to the above code, I obtained
P(X=1) = 0.2518
E(X) = 1.4917 ≈ 1.50
It seems like the value of E(X) is coming well, but the value of P(X=1) is not coming correctly.
What is wrong with my code?
Edit:
I have written the following code on the basis of Edward Carney's comment.
noOfExperiments = 1000;
mySample <- replicate(noOfExperiments, sum(sample(c(0, 1), 3, replace=T)) )
outcomeCount <- length(which(mySample==1))
prob <- outcomeCount/noOfExperiments
eX <- sum(mySample)/noOfExperiments
Note: related question.
r statistics probability
add a comment |
If X = # of heads showing when three coins are tossed, find P(X=1), and E(X).
The experiment has the following distribution:
According to my calculation,
P(X=1) = 0.375 ≈ 0.40
E(X) = 1.50
And,
where n = # of repetitions of the experiment.
Source Code
noOfExperiments = 10000;
mySample <- sample(c(0,1,2,3), noOfExperiments, replace = T)
outcomeCount <- length(which(mySample==1))
prob <- outcomeCount / noOfExperiments
eX <- sum(mySample)/noOfExperiments
According to the above code, I obtained
P(X=1) = 0.2518
E(X) = 1.4917 ≈ 1.50
It seems like the value of E(X) is coming well, but the value of P(X=1) is not coming correctly.
What is wrong with my code?
Edit:
I have written the following code on the basis of Edward Carney's comment.
noOfExperiments = 1000;
mySample <- replicate(noOfExperiments, sum(sample(c(0, 1), 3, replace=T)) )
outcomeCount <- length(which(mySample==1))
prob <- outcomeCount/noOfExperiments
eX <- sum(mySample)/noOfExperiments
Note: related question.
r statistics probability
2
An experiment would not involve inserting the probabilities ahead of time. A more realistic simulation can be obtained usingmySample <- replicate(noOfExperiments, sum(sample(c(0, 1), 3, replace=T))
followed bytable(mySample)/noOfExperiments
`.
– Edward Carney
Mar 8 at 2:32
3
In your original code, you're not using the given probabilities at all - you could apply them usingsample(c(0,1,2,3), noOfExperiments, replace = T, prob = c(0.125, 0.375, 0.375, 0.125))
– Marius
Mar 8 at 3:18
add a comment |
If X = # of heads showing when three coins are tossed, find P(X=1), and E(X).
The experiment has the following distribution:
According to my calculation,
P(X=1) = 0.375 ≈ 0.40
E(X) = 1.50
And,
where n = # of repetitions of the experiment.
Source Code
noOfExperiments = 10000;
mySample <- sample(c(0,1,2,3), noOfExperiments, replace = T)
outcomeCount <- length(which(mySample==1))
prob <- outcomeCount / noOfExperiments
eX <- sum(mySample)/noOfExperiments
According to the above code, I obtained
P(X=1) = 0.2518
E(X) = 1.4917 ≈ 1.50
It seems like the value of E(X) is coming well, but the value of P(X=1) is not coming correctly.
What is wrong with my code?
Edit:
I have written the following code on the basis of Edward Carney's comment.
noOfExperiments = 1000;
mySample <- replicate(noOfExperiments, sum(sample(c(0, 1), 3, replace=T)) )
outcomeCount <- length(which(mySample==1))
prob <- outcomeCount/noOfExperiments
eX <- sum(mySample)/noOfExperiments
Note: related question.
r statistics probability
If X = # of heads showing when three coins are tossed, find P(X=1), and E(X).
The experiment has the following distribution:
According to my calculation,
P(X=1) = 0.375 ≈ 0.40
E(X) = 1.50
And,
where n = # of repetitions of the experiment.
Source Code
noOfExperiments = 10000;
mySample <- sample(c(0,1,2,3), noOfExperiments, replace = T)
outcomeCount <- length(which(mySample==1))
prob <- outcomeCount / noOfExperiments
eX <- sum(mySample)/noOfExperiments
According to the above code, I obtained
P(X=1) = 0.2518
E(X) = 1.4917 ≈ 1.50
It seems like the value of E(X) is coming well, but the value of P(X=1) is not coming correctly.
What is wrong with my code?
Edit:
I have written the following code on the basis of Edward Carney's comment.
noOfExperiments = 1000;
mySample <- replicate(noOfExperiments, sum(sample(c(0, 1), 3, replace=T)) )
outcomeCount <- length(which(mySample==1))
prob <- outcomeCount/noOfExperiments
eX <- sum(mySample)/noOfExperiments
Note: related question.
r statistics probability
r statistics probability
edited Mar 8 at 3:13
user366312
asked Mar 8 at 1:52
user366312user366312
3,80146159319
3,80146159319
2
An experiment would not involve inserting the probabilities ahead of time. A more realistic simulation can be obtained usingmySample <- replicate(noOfExperiments, sum(sample(c(0, 1), 3, replace=T))
followed bytable(mySample)/noOfExperiments
`.
– Edward Carney
Mar 8 at 2:32
3
In your original code, you're not using the given probabilities at all - you could apply them usingsample(c(0,1,2,3), noOfExperiments, replace = T, prob = c(0.125, 0.375, 0.375, 0.125))
– Marius
Mar 8 at 3:18
add a comment |
2
An experiment would not involve inserting the probabilities ahead of time. A more realistic simulation can be obtained usingmySample <- replicate(noOfExperiments, sum(sample(c(0, 1), 3, replace=T))
followed bytable(mySample)/noOfExperiments
`.
– Edward Carney
Mar 8 at 2:32
3
In your original code, you're not using the given probabilities at all - you could apply them usingsample(c(0,1,2,3), noOfExperiments, replace = T, prob = c(0.125, 0.375, 0.375, 0.125))
– Marius
Mar 8 at 3:18
2
2
An experiment would not involve inserting the probabilities ahead of time. A more realistic simulation can be obtained using
mySample <- replicate(noOfExperiments, sum(sample(c(0, 1), 3, replace=T))
followed by table(mySample)/noOfExperiments
`.– Edward Carney
Mar 8 at 2:32
An experiment would not involve inserting the probabilities ahead of time. A more realistic simulation can be obtained using
mySample <- replicate(noOfExperiments, sum(sample(c(0, 1), 3, replace=T))
followed by table(mySample)/noOfExperiments
`.– Edward Carney
Mar 8 at 2:32
3
3
In your original code, you're not using the given probabilities at all - you could apply them using
sample(c(0,1,2,3), noOfExperiments, replace = T, prob = c(0.125, 0.375, 0.375, 0.125))
– Marius
Mar 8 at 3:18
In your original code, you're not using the given probabilities at all - you could apply them using
sample(c(0,1,2,3), noOfExperiments, replace = T, prob = c(0.125, 0.375, 0.375, 0.125))
– Marius
Mar 8 at 3:18
add a comment |
0
active
oldest
votes
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55055625%2ftossing-3-fair-coins-in-r-2%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55055625%2ftossing-3-fair-coins-in-r-2%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
2
An experiment would not involve inserting the probabilities ahead of time. A more realistic simulation can be obtained using
mySample <- replicate(noOfExperiments, sum(sample(c(0, 1), 3, replace=T))
followed bytable(mySample)/noOfExperiments
`.– Edward Carney
Mar 8 at 2:32
3
In your original code, you're not using the given probabilities at all - you could apply them using
sample(c(0,1,2,3), noOfExperiments, replace = T, prob = c(0.125, 0.375, 0.375, 0.125))
– Marius
Mar 8 at 3:18