1/26
Looks like no tags are added yet.
Name | Mastery | Learn | Test | Matching | Spaced | Call with Kai | Chat |
|---|
No analytics yet
Send a link to your students to track their progress
library(rethinking)
load the rethinking library in
data(Howell)
load data howell from a library
d ← Howell
put Howell data into a variable
str(d)
inspect structure of data d
d$height
extract data in data frame d for height
d2 <- d[d$age >= 18,]
extract data from data frame d where the age is greater than or equal to 18 and assign to variable d2
curve(dnorm( x, 178, 20), from=100, to=250)
make a prior for a normal distribution of x with mean 178 and 95% CI of 80, plot from 100 to 250
dunif(x, 0, 50)
make a prior with a uniform distribution from 0 to 50
sample <- rnorm(1e4, 178, 20)
take 10,000 samples from a normal distribution with mean 178 and standard deviation 20 and assign them to a sample variable
sample ← runif(1e4, 0, 50)
take 10,000 samples from a uniform distibution from 0 to 50
sum(sample) / 1e4
take the average of a sample variable with 10,000 entries
prior_h <- rnorm(1e4, sample_mu, sample_sigma)
sample 10,000 values from a set of sample_mu and sample_sigma
dens(sample)
create a density plot of sample values
sample a row then take samples from that row
how to sample a posterior that contains multiple values
alist (
height ~ dnorm(mu , sigma),
mu ~ dnorm(178 , 20),
sigma ~ dunif(0 , 50)
)
how to create a list with variable relations, height follows a normal distribution, mu follows normal distribution 178 average, with stdev 20, sigma follows uniform from 0 to 50
m4.1 <- map (flist , data=d2)
Create a maximum a posteri model from d2 onto a quadratic function using the variables described in flist and their
precis(m4.1)
find the mean and stdev, and 89% confidence interval of m4.1
vcov(m4.1)
how to find the covariance of MAP model m4.1
cov2cor(vcov(m4.1))
how to find the relationship between mu and sigma of MAP m4.1
extract.samples(m4.1, n=1e4)
how to sample 10,000 times multi-dimensional posterioir from a MAP value m4.1, output is a data frame
rm(list = ls())
how to clear environment in R
plot(d2$height ~ d2$weight)
plot height (y) over weight (x)
precis(m4.3, corr=TRUE)
find a precis model with correlation matrix for map m4.3
rethinking link function
take all values of x for the model, sample from the posterior
str(x)
how to find the structure (N rows and cols) for x
link functuon
creates a sample of dist values for 1000 values of mu
standardizing data
puts the mean at 0 and makes the points clump around it better, done by subtracting everything by the mean then dividing by a standard deviation