一些笔记分享
Chapter 1 - 3
R basics
getwd()
Change work directory:
Session -> Set Work directory
List the files in the working directory: dir()
ls()
source("mycode.r")
myfunction <- function() {
x<-rsnorm(100)
mean(x)
}
second <- function(x) {
x+rnorm(length(x))
}
second(4:10)
[1] 4.967679 5.615161 6.024537 6.176771 7.228145 9.256796
[7] 9.348702
> 2+2
[1] 4
> show(2+2)
[1] 4
> x=2
> x+x
[1] 4
>x=seq(from =-2, to =2 ,b=0.1)
> y=x^2
plot(x,y,type='l')
Chapter 3
Null Hypothesis Significance Testing
Making inferences from data to uncertain beliefs.
Model: mathematical description
Parameters: Variables that refer to underlying characteristics
Prior is the distribution of beliefs we hold by excluding a particular set of data, and the posterior is the distribution of beliefs we hold by including the set of data.
· Estimation of parameter values: the posterior beliefs typically increase the magnitude of belief in some parameter values, while lessening the degree of belief in other parameter values.
· Prediction of data values. Prediction: means inferring the values of some missing data based on some other included data, regardless of the actual temporal relationship of the included and missing data.
· Model Comparison
More complexà fit data better than simple models, due to more flexibility
- Fit random noise better than simpler model, we are interested in the model that best fits the real trends in the data, not just the model that best fits the noise
Learn about features of R on an as-needed basis, and usually that means you look for examples of the sort of thing you want to do and then imitate the examples
Chapter 3
The fairness of a coin might be hugely consequential for high stakes games, but it isn’t often in life that we flip coins. So why bother studying the statistics of coin flips? Because the coin flips are a surrogate for myriad other real-life events that we care about. ..talking about some domain in which you are actually interested. The coins are merely a generic representative of a universe of analogous applications.
The long-run relative frequency:
- Approximate it by actually sampling from the space many times and tallying the number of times each event happens
· In R, pseudo-random number generators
· Even this long run is still just a finite random sample, and there is no guarantee that the relative frequency of an event will match the true underlying probability of the event à approximating
- Deriving mathematically
Assumption of fairness
Inside the head: subjective belief
· It can be hard to pin down mushy intuitive beliefs
· Ways to calibrate subjective beliefs and mathematically describe degrees of belief
- By preference
· Snowstorm the closes the interstate highway
· Two comparison gambles: Mables in sack experiment
- Mathematically
· Average Height of American woman, but be open to the possibility that the average might be somewhat above or below that value à too tedious and maybe impossible to specify the degree on belief
· Bell-shaped curve , change the width and center of the curve until it seems best to capture your subjective belief
Probability distributions
· A list of all possible outcomes and their corresponding probabilities
· When the outcomes are continuous, like calories, then the notion of probability takes on some subtleties, as we will see.
- Discrete: probability mass
When sample space consists of discrete outcomes, then we can talk about the probability of each distinct outcome.
For continuous outcome spaces, we can discretize the space into a finite set of mutually exclusive and exhaustive “bins”.
- Continuous distributions: Rendezvous with density
Two-way distribution
· Tossing a coin three times in a row. Eight possible sequences, because the coin is assumed to be fair, each row is equally likely
· For each sequence of three tosses, we can count the number of heads in the sequence and the number of times that the outcome switched between heads or tails.
· Two-way table, shows the probability of getting a particular combination of number of head and number of switches
· The probability of two things happening together is called their conjoint probability.
- marginal probability
· What’s the probability of getting two heads in three flips?
o Sum across the conjoint probabilities we’ve already compiled à marginal probability
o Conjoint p(x,y)
- Conditional probability
· Find the probability of one event, given that we know another event is true.
· What’s the probability that it will rain in the next 24 hours given that there is a thunderstorm 400 miles due west of you?
· The probability that a sequence of three flips has one switch, gien that it has one head.
The marginal probability indicates the probability of getting one switch on average across all numbers of head, whereas the conditional probability restricts consideration to a particular number of heads.