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...
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 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...
Write Powershell Script Verifies System Environment Variable Lmlicensefile Exists Exists S Q42980878 write a PowerShell script...
Write Powershell Script Verifies System Environment Variable Lmlicensefile Exists Exists S Q42980878 write a PowerShell script that verifies the 'System' environmentvariable, 'LM_LICENSE_FILE', exists. If it exists, the scriptshould also verify that the variable [email protected] (which represents the port and server theLM points to) as one of the values in the variable. Values (if anyare present) are separated by commas "," in this variable. Finally,if the value does not exist, this script should also performremediation (add the desired value to the...
Use the R script to finish the following operations: (1) Generate 60 normally distributed random variables...
Use the R script to finish the following operations: (1) Generate 60 normally distributed random variables with the mean 30 and the variance 16, and store them in the vector ‘rand.vec’. (2) Turn the vector ‘rand.vec’ into a 6X10 matrix, and assign the name ‘rand.mat’ to the matrix. (3) Given a normal distribution with the mean 30 and the variance 16, find the two values of x that contain the middle 50% of the normal curve area.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT