Question

In: Statistics and Probability

Write an R Script that does the following for "sampleData1.dta"

Write an R Script that does the following for "sampleData1.dta"

a) Regress "earn," "adcc," and "tinc" on a constant.

b) Regress earnings on "higrade," "age," and "agesq." Display TSS, RSS, ESS and R Squared Value

c) Reestimate the regression from pt. b, this time omitting the constant term.

 

Solutions

Expert Solution

Before starting with the regression, you need to call the data in R.So, run the following code in the beginning.

CODE:

mydata=read.table("sampleData1.dta",header=T,sep=",")  

Here, in the code within quotes provide the path where your data is stored. For example, if it is in the Documents folder in the C drive, then provide the code as "C:/Documents". For sep argument, provide a space or comma accordingly with which your data is separated. To check if your data is correctly read in R, you just run the following code:

View(data)

This will give a new window in R, showing your data as we see normally in an excel sheet.

PART A

Here, you want to regress "earn","adcc" and "tinc" on a constant term.So, I am assuming that there are 3 predictor variables with no explanatory variable, so considering only the constant term. In R script, run the following code:

model1=lm(cbind(earn,adcc,tinc)~1,data=mydata)

model1 # this provides the coefficients or just the intercept term

Further, if you want the TSS, RSS, ESS and so on. Run the following code:

summary(model1)

PART B

CODE:

model2=lm(earnings~higrade+age+agesq,data=mydata)

model2 #gives the regression coefficients

summary(model2) $r.squared #returns the R squared value

anova(model2) # gives the RSS, ESS for all the x variables. Adding these gives the TSS

PART C

You can run the same codes here from part (b) with the only change being in the model as below.

model3=lm(earnings~-1+higrade+age+agesq,data=mydata)

For the TSS,ESS,RSS and R Squared value run the codes from (b) changing the model to model3.


Related Solutions

Use the R script to answer the following questions: (write down your answers in the R...
Use the R script to answer the following questions: (write down your answers in the R script with ##) (1). Import FarmSize.csv to Rstudio. Use the correct function to build a linear regression model predicting the average size of a farm by the number of farms; Give the model a name (e.g. FarmSize_Model). Call the model name to inspect the intercept and slope of the regression model. Verify the answers in your manual calculation. (2). Use the correct function to...
Use the R script to answer the following questions: (write down your answers in the R...
Use the R script to answer the following questions: (write down your answers in the R script with ##) (1). Import FarmSize.csv to Rstudio. Use the correct function to build a linear regression model predicting the average size of a farm by the number of farms; Give the model a name (e.g. FarmSize_Model). Call the model name to inspect the intercept and slope of the regression model. Verify the answers in your manual calculation. (2). Use the correct function to...
Write a R-script to (and show the outputs of your code) (a) Create a sequence of...
Write a R-script to (and show the outputs of your code) (a) Create a sequence of numbers starting at 3.5 and ending at 10.7 with increments of 0.79. Find the variance and mean of those numbers. And finally sort the vector in a decreasing manner (b) Create a 3 different 3 by 3 matrices such that each of the numbers 1,2,...,9 appear exactly once (Sudoku style) in each of the matrices.
Assignment Write a network diagnostics bash script that does the following: Finds the IPv4 address of...
Assignment Write a network diagnostics bash script that does the following: Finds the IPv4 address of the default gateway on your machine (one way to get this is the 'default' entry, also shown as 0.0.0.0, in the output of 'ip route') and runs a ping (with a count of 5 pings) to it. Runs another count of 5 pings to the site example.com. Outputs a 1-line summary of interfaces on your machine, not including the loopback address (lo). Outputs a...
Linux Sign into your lab account Write a bash shell script that does the following: Print...
Linux Sign into your lab account Write a bash shell script that does the following: Print out a friendly welcome message Ask the user for the name of their favorite animal Grep that animal from a text file noises.txt Tell the user what that animal says (i.e. what noise does it make) If the animal does not exist ask the user what noise the animal makes Store that new information in noises.txt
Write a script to display the following patterns on the screen. Number of rows and columns...
Write a script to display the following patterns on the screen. Number of rows and columns are taken from the command arguments; if they are missing, set default to 3 (rows) and 4 (columns). Hint: you will use a nested loop. **** **** **** a) Display the source code in an editor (#4-11) b) Execute your script in the terminal, and display the command and the result (#4-12)
Write a script in C that will do the following : 1. Create the directory ZHW3....
Write a script in C that will do the following : 1. Create the directory ZHW3. 2. Verify that the directory is created by display all information related to the directory and not just the name of the directory. 3. Assume that the input from the command is used to validate password strength. Here are a few assumptions for the password string. • Length – minimum of 8 characters. • Contain alphabets , numbers , and @ # $ %...
Write a complete shell script that first asks the user to enter a URL. The script...
Write a complete shell script that first asks the user to enter a URL. The script should read the URL into a variable named url. The shell script should then retrieve the file associated with the URL by using the curl command. The output of the curl command should be redirected to a file named html_file. The shell script should then use the grep command to search the file named html_file for the word manhattan. Finally, the shell script should...
Write a R script that calculates the mean and variance of two random variables X~F(m=2,n=5) and...
Write a R script that calculates the mean and variance of two random variables X~F(m=2,n=5) and Y~F(m=10,n=5) from their density functions.
Fully Functional Script written in BASH In this section, you will write a fully functional script...
Fully Functional Script written in BASH In this section, you will write a fully functional script to help your manager with an important project that will build upon what you learned from your script work in Milestone Four. After you have written the script, you will execute it to generate a report for all three users (once for Bob, once for Henry, and once for Frank). You should have three unique generated reports in your ~/scripts directory (or more if...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT