#Load the data set
x <- c(0.725,0.429,-0.372 ,0.863)
The value of mu that minimizes the sum((x - mu)ˆ2) is the mean of the data.
mu <- mean(x)
mu
## [1] 0.41125
Hence, the value that minimizes sum((x - mu)ˆ2) is 0.41125.
The value that minimizes sum(w * (x - mu) ˆ 2) is is the weighted mean. We can use the function weighted.mean().
w <- c(2, 2, 1, 1)
mu <- weighted.mean(x, w)
mu
## [1] 0.4665
Thus, the value of mu that minimizes sum(w * (x - mu) ˆ 2) is 0.4665.
First, we center the parent’s height by subtracting from it their mean.
library(HistData)
# Load the Galton dataset
data("Galton")
# Center the parental height
Galton$parent_centered <- Galton$parent - mean(Galton$parent)
# Fit the regression model through the origin
fit <- lm(parent_centered ~ child + 0, data = Galton)
# Obtain the slope estimate
slope_estimate <- coef(fit)
slope_estimate
## child
## 0.0004442533
Hence, the regression egression through the origin slope estimate where
the centered parental height is the outcome and the child’s height is
the predictor is 0.0004442533 .