天天看点

Regression, 回归问题

a simple linear regression model that describes the relationship between two variables x and y can be expressed by the following equation. the numbers α and β are called parameters, and ϵ is the error term.

线性回归是利用数理统计中的回归分析,来确定两种或两种以上变量间相互依赖的定量关系的一种统计分析方法之一,运用十分广泛。分析按照自变量和因变量之间的关系类型,可分为线性回归分析和非线性回归分析。

if we choose the parameters α and β in the simple linear regression model so as to minimize the sum of squares of the error term ϵ, we will have the so called estimated simple regression equation. it allows us to compute fitted values(拟合值) of y based on values of x.

problem 根据已有的样本, 来预测下次喷发的时间 we apply the lm function to a formula that describes the variable eruptions by the variable waiting, andsave the linear regression model in a new variable eruption.lm. then we extract the parameters of the estimated regression equation with the coefficients function. we now fit the eruption duration using the estimated regression equation. based on the simple linear regression model, if the waiting time since the last eruption has been 80 minutes, we expect the next one to last 4.1762 minutes.

the coefficient of determination of a linear regression model is the quotient of the variances of the fitted values and observed values of the dependent variable. if we denote yi as the observed values of the dependent variable,  as its mean, and  as the fitted value, then the coefficient of determination is:

用来衡量, 拟合值(预测值)和观测值(真值)之间的差异, 说白了, 就是看看线性回归假设准不准...

we apply the lm function to a formula that describes the variable eruptions by the variable waiting, and save the linear regression model in a new variable eruption.lm. then we extract the coefficient of determination from the r.squared attribute of its summary. the coefficient of determination of the simple linear regression model for the data set faithful is 0.81146.

assume that the error term ϵ in the linear regression model is independent of x, and is normally distributed, with zero mean and constant variance. we can decide whether there is any significant relationship between x and y by testing the null hypothesis that β = 0.

什么叫显著性测试, 说白了, 你假设的这个线性关系是否是真实存在的, 是否是牵强的,是否压根就没关系.

对于x = a+ by,  如果b可能为0, 那么x就是个常量, 和y就没啥关系.

所以对于这个线性回归, b为0一定是个小概率事件, 否则这个线性回归假设就不成立.

note, 显著性检验的基本思想可以用小概率原理来解释. 小概率原理, 小概率事件在一次试验中是几乎不可能发生的, 假若在一次试验中事件事实上发生了. 那只能认为我们对总体所做的假设不正确.

所以这儿是个假设检验问题, testing the null hypothesis that β = 0, 如果这个假设不成立, 则此线性回归为显著的.

decide whether there is a significant relationship between the variables in the linear regression model of the data set faithful at .05 significance level. then we print out the f-statistics of the significance test with the summary function. <a></a> as the p-value is much less than 0.05, we reject the null hypothesis that β = 0. hence there is a significant relationship between the variables in the linear regression model of the data set faithful.

我没看懂过程, 总之结果是reject null hypothesis

assume that the error term ϵ in the linear regression model is independent of x, and is normally distributed, with zero mean and constant variance. for a given value of x, the interval estimate for the mean of the dependent variable,  , is called the confidence interval.

看例子就知道了, 回归是预测, 所以不可能完全精准, 所以给出一个置信区间比给一个单值更为合理. 之所以叫置信区间, 因为区间的范围是基于置信度的.

then we create a new data frame that set the waiting time value. we now apply the predict function and set the predictor variable in the newdata argument. we also set the interval type as "confidence", and use the default 0.95 confidence level. the 95% confidence interval of the mean eruption duration for the waiting time of 80 minutes is between 4.1048 and 4.2476 minutes.

我觉得这个例子用了predict这样的highlevel函数, 不利于大家理解这个问题.

assume that the error term ϵ in the simple linear regression model is independent of x, and is normally distributed, with zero mean and constant variance. for a given value of x, the interval estimate of the dependent variable y is called the prediction interval.

不同是上面那个是预估y平均值的区间, 而这里是预估y的区间.

predict(eruption.lm, newdata, interval="predict")

代码和上面的唯一不同是interval类型变为predict

we apply the lm function to a formula that describes the variable eruptions by the variable waiting, and save the linear regression model in a new variable eruption.lm. then we compute the residual with the resid function. we now plot the residual against the observed values of the variable waiting.

用图形化来表示观测值和预估值的差值.

a multiple linear regression (mlr) model that describes a dependent variable y by independent variables x1, x2, ..., xp (p &gt; 1) is expressed by the equation as follows, where the numbers α and βk (k = 1, 2, ..., p) are the parameters, and ϵ is the error term.

for example, in the built-in data set stackloss from observations of a chemical plant operation, if we assign stackloss as the dependent variable, and assign air.flow (cooling air flow), water.temp (inlet water temperature) and acid.conc. (acid concentration) as independent variables, the multiple linear regression model is:

多个自变量的线性回归, 现实世界比较复杂, 往往是由多种因素影响决定的, 这个比简单线性回归更实用一些.

内容基本和slr相同, 这儿就不详细说明了.

if we choose the parameters α and βk (k = 1, 2, ..., p) in the multiple linear regression model so as to minimize the sum of squares of the error term ϵ, we will have the so called estimated multiple regression equation. it allows us to compute fitted values of y based on a set of values of xk (k = 1, 2, ..., p) .

we apply the lm function to a formula that describes the variable stack.loss by the variables air.flow, water.temp and acid.conc. and we save the linear regression model in a new variable stackloss.lm. lastly, we apply the predict function to stackloss.lm and newdata.

为啥需要调整的...?

是否y和任意一个自变量x是显著相关的, 和前面slr差不多

we use the logistic regression equation to predict the probability of a dependent variable taking the dichotomy values 0 or 1. suppose x1, x2, ..., xp (p &gt; 1) are the independent variables, α and βk (k = 1, 2, ..., p) are the parameters, and e(y) is the expected value of the dependent variable y, then the logistic regression equation is:

非线性回归, 世间事务的关系不可能都是线性的, 所以要来研究非线性回归

using the generalized linear model, an estimated logistic regression equation can be formulated as below. the coefficients a and bk (k = 1, 2, ..., p) are determined according to a maximum likelihood approach, and it allows us to estimate the probability of the dependent variable y taking on the value 1 for given values of xk (k = 1, 2, ..., p).

we apply the function glm to a formula that describes the transmission type (am) by the horsepower (hp) and weight (wt). this creates a generalized linear model (glm) in the binomial family. now we apply the function predict to the generalized linear model am.glm along with newdata. we will have to select response prediction type in order to obtain the predicted probability.

本文章摘自博客园,原文发布日期:2012-03-02