Question

There is the 2-parameter linear model where e is the error vector of length n given...

There is the 2-parameter linear model where e is the error vector of length n given by e ~ N(0, 22 In) where In is the n by n identity matrix.

I want to use glm(y ~ x, family = gaussian(), data = ...) in R. Please advise how to specify the given error vector.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

# The required function is

n=30
## independent variable
x=rnorm(n, 4, 2)

## Error with mean zero and variance 22
e=rnorm(n, 0, sd=sqrt(22))

## Dependent variable with variance 22
y=x+e

data=cbind(y, x)
data=data.frame(data)

## Required model

model=glm(y~x, family = gaussian, data)
summary(model)

## For check the error variance

model=lm(y~x)
summary(model)

#########################

### Run the model

> n=30
> ## independent variable
> x=rnorm(n, 4, 2)
>
> ## Error with mean zero and variance 22
> e=rnorm(n, 0, sd=sqrt(22))
>
> ## Dependent variable with variance 22
> y=x+e
>
> data=cbind(y, x)
> data=data.frame(data)
>
> ## Required model
>
> model=glm(y~x, family = gaussian, data)
> summary(model)

Call:
glm(formula = y ~ x, family = gaussian, data = data)

Deviance Residuals:
Min 1Q Median 3Q Max
-9.0524 -1.4839 -0.0806 2.1880 11.1185

Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 0.03522 1.89826 0.019 0.9853
x 1.06081 0.45707 2.321 0.0278 *
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

(Dispersion parameter for gaussian family taken to be 17.304)

Null deviance: 577.72 on 29 degrees of freedom
Residual deviance: 484.51 on 28 degrees of freedom
AIC: 174.59

Number of Fisher Scoring iterations: 2

>
> model=lm(y~x)
> summary(model)

Call:
lm(formula = y ~ x)

Residuals:
Min 1Q Median 3Q Max
-9.0524 -1.4839 -0.0806 2.1880 11.1185

Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 0.03522 1.89826 0.019 0.9853
x 1.06081 0.45707 2.321 0.0278 *
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

Residual standard error: 4.16 on 28 degrees of freedom
Multiple R-squared: 0.1613, Adjusted R-squared: 0.1314
F-statistic: 5.387 on 1 and 28 DF, p-value: 0.0278

Add a comment
Know the answer?
Add Answer to:
There is the 2-parameter linear model where e is the error vector of length n given...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT