NotesWhat is notes.io?

Notes brand slogan

Notes - notes.io

---
title: 'Homework 5 - STAT 462: Applied Regression Analysis'
author: "Joshua Williams"
output: pdf_document
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```

``` {r warning=FALSE, message=FALSE}
library(lattice)
library(faraway)
```


```{r}
?read.table
data <-read.table("bears.txt",header=TRUE)
dim(data)
data[data$ID==41,]
bears = data[data$Obs.No==1,]
bears
dim(bears)
###
y = bears$Weight
x1 = bears$Neck.G

```


```{r}
lm1 = lm(y~x1)
lm1
summary(lm1)

#plot(lm1)
res1 = resid(lm1)
#res1
res1

X.design = cbind(1,x1)
X.design

```

The Regression slope is 20.59





```{r}
sigma2 = sum(res1^2)/(99-2)
sigma2

se.beta1 = sqrt(sigma2*solve(t(X.design) %*% X.design)[2,2])
se.beta1
```


The Variance is 1369.55


The Standard Error is 0.7148337






The Distribution of the test statistic is N(0,1)














The Test Statistic is equal to 28.80384
```{r}


betahat = solve(t(X.design)%*%X.design) %*% t(X.design) %*% y
betahat

beta1hat = betahat[2]
beta1hat

tvalue = beta1hat/se.beta1
tvalue
```







The P-value is equal to 0
```{r}
pvalue = 2*(1-pt(abs(tvalue),df=97))
pvalue


#pvalue = 2*(1-pt(abs(tvalue),df=97))
#pvalue
```

We reject the null hypothesis










```{r}

x1 = bears$Neck.G
x2 = bears$Head.W
y = bears$Weight
X = cbind(1, x1, x2)
lm_fit <- lm(y~x1+x2)
n = dim(X)[1]
p = dim(X)[2]

betahat2 = solve(t(X)%*%X, t(X)%*%y)
yhat = X%*%betahat2
eps_hat = y - yhat
sigma2 = sum(eps_hat^2)/(n-p)
sigma2
cv_mat = sigma2*solve(t(X)%*%X)
round(cv_mat,digits=5)

se = sqrt(diag(cv_mat))
mytable<-cbind(betahat2,se)
colnames(mytable)<-c("Est","se")
mytable

tvalue = betahat2/se
tvalue
pval = 2*pt(abs(tvalue), df=n-p, lower.tail = FALSE)

mytable<-cbind(mytable,tvalue,pval)
colnames(mytable)<-c("Est","se","t-stat","p-val")
mytable


#
# lm2 = lm(y~x1+x2)
# res2 = resid(lm2)
# RSS2 = sum(res2^2)
# RSS2
# TSS= sum((y-mean(y))^2)
# TSS
# SS_reg = TSS - RSS2
# SS_reg
# summary(lm2)





#summary(lm1)

#summary(lm1)$sigma^2
```



The RSS is equal to 132756.1
The TSS is equal to 1269109
The SS_reg is equal to 1136353









The Distribution of the test statistic is N(0,1)



```{r}


# res2 = resid(lm2)
#
# X.design = cbind(1,x2,x1)
# #X.design
#
#
# sigma2 = sum(res2^2)/(99-2)
# sigma2
#
# se.beta1 = sqrt(sigma2*solve(t(X.design) %*% X.design)[2,2])
# #se.beta1
#
#
#
# #betahatt = solve(t(X.design)%*%X.design) %*%t(X.design) %*% y
# #betahat
#
# beta1hat = betahatt[2]
# #beta1hat
#
# tvalue = beta1hat/se.beta1
# tvalue
```






```

     
 
what is notes.io
 

Notes.io is a web-based application for taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000 notes created and continuing...

With notes.io;

  • * You can take a note from anywhere and any device with internet connection.
  • * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
  • * You can quickly share your contents without website, blog and e-mail.
  • * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
  • * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.

Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.

Easy: Notes.io doesn’t require installation. Just write and share note!

Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )

Free: Notes.io works for 12 years and has been free since the day it was started.


You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;


Email: [email protected]

Twitter: http://twitter.com/notesio

Instagram: http://instagram.com/notes.io

Facebook: http://facebook.com/notesio



Regards;
Notes.io Team

     
 
Shortened Note Link
 
 
Looding Image
 
     
 
Long File
 
 

For written notes was greater than 18KB Unable to shorten.

To be smaller than 18KB, please organize your notes, or sign in.