全部版块 我的主页
论坛 数据科学与人工智能 数据分析与数据科学 R语言论坛
1059 3
2013-04-14
You are required to investigate the sampling distribution of the F-statistic for testing the overall significance of the regression (assuming the null hypothesis holds) in the following specific situation:

y-hat = b0 + b1*x1 + b2*x2 + b3*x3 + b4*x4
sigma = 2

Using this underlying model, you are required to write R code that will produce a histogram that illustrates the sampling distribution of the F-statistic. Your answer should include your R code and a histogram that illustrates the sampling distribution.

我作业的其中一题,我不会编程序。希望有好心人士帮帮忙。感激不尽!!!
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

全部回复
2013-4-14 10:46:27
x1=1:1000   
set.seed(99900)
x2=runif(length(x1),1,50000)
set.seed(1)
x3=runif(length(x1),2000,80000)
set.seed(500)
x4=runif(length(x1),3566,60000)
n=length(x1)
y=rep(0,n)
numsamp=1000
f=rep(0,numsamp)
for(i in 1:numsamp){errors=rnorm(n,0,2)
y=1+2*x1+3*x2+4*x3+5*x4+errors
slrfit=lm(y~x1+x2+x3+x4)
b=anova(slrfit)
f[i]=mean(b[1,2],b[2,2],b[3,2],b[4,2])/b[5,3]}
hist(f)

我的这个有什么问题?可是我就是解不到,因为我拿到的图是normal的,可是F distribution不应该是normal。
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2013-4-14 11:49:20
代码过程写的比较简单,希望对你有用
复制代码
附件列表
Rplot.jpeg

原图尺寸 41.32 KB

Rplot.jpeg

二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2013-4-14 11:57:20
simF <- function(N) {
        X <- matrix(rnorm(N*4), nrow=N, ncol=4)
        y <- 1 + rnorm(N, 0, 2)
        fit <- lm(y~X)
        summary(fit)$fstatistic[1]       
}

Fs <- sapply(1:10000, function(x) simF(100))

hist(Fs, breaks=50, freq=F)
x <- seq(0, 6, length.out=1000)
y <- df(x, 4, 95)
lines(x, y, col=2)
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

相关推荐
栏目导航
热门文章
推荐文章

说点什么

分享

扫码加好友,拉您进群
各岗位、行业、专业交流群