找到你要的答案

Q:Subsetting a data.frame column to a vector for making a confint

Q:使用数据框列向量进行限制

I have a data.frame and I need to subset one column from the data.frame and make a vector from it in order to create a confint from the vector.

I am able to subset the column, but if I create the vector by vector<-as.vector(data.frame$column), then I am not able to do confint because there is an error:

Error: $ operator is invalid for atomic vectors.

Dataframe example:

origin MPG
1       20.5
1       18
2       15
2       25
3       31
etc.    etc.

I want to make a confidence interval for the miles per gallon variable according to the origin of the car (US=1, EU=2, JPN=3).

Thanks for advance for any help with this issue.

Cheers.

我有一个数据框和我需要的子集,一列从数据框,它为了创造从矢量进行矢量限制。

我能集的列,但是如果我用矢量& lt创建载体;作为。向量(数据。框架柱,然后美元)我不能做限制因为有错误:

错误:$运算符对于原子向量无效。

数据框的例子:

origin MPG
1       20.5
1       18
2       15
2       25
3       31
etc.    etc.

我想做一个置信区间变量的英里每加仑根据汽车的起源(美国为1,欧盟为2,日本为3)。

感谢您对这个问题的任何帮助。

干杯.

answer1: 回答1:

confint computes a confidence interval for a fitted model, not for a population parameter. (see help(confint) arguments section : object: a fitted model object.) You can compute the interval using its formula like this :

set.seed(50)
x <- rnorm(100)
mean(x)
[1] -0.1135271
sd(x)/sqrt(length(x))
[1] 0.09926079

限制计算出拟合模型的置信区间,而不是一个种群参数。(请参阅帮助(限制)的论据部分:对象:拟合模型对象。)你可以使用这样的公式计算区间:

set.seed(50)
x <- rnorm(100)
mean(x)
[1] -0.1135271
sd(x)/sqrt(length(x))
[1] 0.09926079
r  vector  dataframe