4 views

Uploaded by muralidharan

g

- EC212 Course Outline 2015
- Correlation_and_Simple_Linear_Regression
- Regression in R Software
- Becker and Toutkoushian - Measuring Gender Bias in the Salaries (1)
- ETC1000 Topic 2
- Chapter 17
- HPLC Analysis
- - Forecasting S
- 54199223 a Report on Comparative Study of Home Loan Amp Customer Satisfaction
- The General Linear Model
- ACCG200_SolutionCh_03.pdf
- Regression
- Econometrics I July 2015
- EVIEWS_programming.pdf
- Monetary Policy Indicators Analysis Based on Regression Function
- basman paper (1) (1).docx
- Chapter 14
- Arias y Mader, 2011. Environmental Factors Affecting Daily Water
- A.I
- Does Teacher Training Pupil Learning

You are on page 1of 2

example of the basic commands. It is assumed that you know how to enter data or read data files

which is covered in the first chapter, and it is assumed that you are familiar with the different data

types.

DATA

X: 15.5,23.75,8,17,5.5,19,24,2.5,7.5,11,13,3.75,25,9.75,22,18,6,12.5,2,21.5

Y:

2158.7,1678.15,2316,2061.3,2207.5,1708.3,1784.7,2575,2357.9,2256.7,2165.2,2399.55,1779.8,2336

.75,1765.3,2053.5,2414.4,2200.5,2654.2,1753.7

The next thing we do is take a look at the data. We first plot the data using a scatter plot and notice

that it looks linear. To confirm our suspicions we then find the correlation between X&Y

Command Plot(x,y)

Cor(x,y)

The next question is what straight line comes closest to the data? In this case we will use least

squares regression as one way to determine the line. Before we can find the least square regression

line we have to make some decisions. First we have to decide which is the explanatory and which is

the response variable. Here, we arbitrarily pick the explanatory variable to be the X, and the

response variable is Y. This was chosen because it seems like the variable y might change in x rather

than time changing as the y changes.

The command to perform the least square regression is the lm command. The command has many

options, but we will keep it simple and not explore them here. If you are interested use the help(lm)

command to learn more. Instead the only option we examine is the one necessary argument which

specifies the relationship.

Since we specified that the variable y is the response variable and the x is the explanatory variable

this means that the regression line can be written in slope-intercept form

= () + ()

The way that this relationship is defined in the lm command is that you write the vector containing

the response variable, a tilde (~), and a vector containing the explanatory variable:

> fit

When you make the call to lm it returns a variable with a lot of information in it. If you are just

learning about least squares regression you are probably only interested in two things at this point,

the slope and the y-intercept. If you just type the name of the variable returned by lm it will print

out this minimal information to the screen.

If you would like to know what else is stored in the variable you can use the attributes command:

> attributes(fit)

One of the things you should notice is the coefficients variable within fit. You can print out the y-

intercept and slope by accessing this part of the variable:

> fit$coefficients[1]

> fit$coefficients[[1]]

> fit$coefficients[2]

> fit$coefficients[[2]]

Note that if you just want to get the number you should use two square braces. So if you want to get

an estimate of the x= 20 you can use the formula for a line

> fit$coefficients[[2]]*20+fit$coefficients[[1]]

A better use for this formula would be to calculate the residuals and plot them:

> res <- Y - (fit$coefficients[[2]]*year+fit$coefficients[[1]])

> res

> plot(X,Y)

There are easier ways to get the residuals. Two other ways are shown below:

> residuals(fit)

> fit$residuals

> plot(X,fit$residuals)

If you want to plot the regression line on the same plot as your scatter plot you can use the abline

function along with your variable fit:

> plot(X,Y)

> abline(fit)

Finally, as a teaser for the kinds of analyses you might see later, you can get the results of an F-test

by asking R for a summary of the fit variable:

> summary(fit)

- EC212 Course Outline 2015Uploaded byNibhrat Lohia
- Correlation_and_Simple_Linear_RegressionUploaded byal7abeeb
- Regression in R SoftwareUploaded byJoão Heitor De Avila
- Becker and Toutkoushian - Measuring Gender Bias in the Salaries (1)Uploaded byMohd Aizuddin
- ETC1000 Topic 2Uploaded byJacky3141
- Chapter 17Uploaded byfa2heem
- HPLC AnalysisUploaded byDiana Romero
- - Forecasting SUploaded bylathifullal
- 54199223 a Report on Comparative Study of Home Loan Amp Customer SatisfactionUploaded bySunil Soni
- The General Linear ModelUploaded byKőmivesTimea
- ACCG200_SolutionCh_03.pdfUploaded bylethiphuongdan
- RegressionUploaded byManish Rauniyar
- Econometrics I July 2015Uploaded byWonder Smiths
- EVIEWS_programming.pdfUploaded byAbdur Rehman
- Monetary Policy Indicators Analysis Based on Regression FunctionUploaded byAmi Popescu
- basman paper (1) (1).docxUploaded byAnasKhan
- Chapter 14Uploaded byRubvly Tan
- Arias y Mader, 2011. Environmental Factors Affecting Daily WaterUploaded byAnahi Medina
- A.IUploaded byASHUMENDRA YADAV
- Does Teacher Training Pupil LearningUploaded byahmeddanaf
- CORELATION ANALYSIS.docxUploaded byPRAGYAN PANDA
- 07 Relation AnalysisUploaded bypradeep
- aimms3om_linearprogrammingtricksUploaded bygjorhugull
- StatisticsUploaded byAhmed El-saadany
- Modeling Lowe's Sales - Simonoff(1)Uploaded bykillerboye
- a-study-of-english-reading-ability-based-on-multiple-linear-regression-analysis.pdfUploaded byWardiman M Sakir
- OUTPUT.docUploaded byDesy Annisa
- Math644 Chapter 1 Part5Uploaded bySKRSHAW
- Week3 HandoutTable of Selecting Proper Stat TestsUploaded byAndrei Corniciuc
- Grace&Bollen2005EcolSocBul.pdfUploaded byValarrmathi Srinivasan

- 1st Year MSc Schedule Sem IIUploaded bymuralidharan
- Regression BayesUploaded bymuralidharan
- Final AnswerUploaded bymuralidharan
- construction.docxUploaded bymuralidharan
- ConstructionUploaded bymuralidharan
- CH05Uploaded bymuralidharan
- AssgnUploaded bymuralidharan
- Best Principles Risk AssessmentUploaded bymuralidharan
- Decades AgoUploaded bymuralidharan
- Clinical Slides 6Uploaded bymuralidharan
- RandomizeDemo.mUploaded bymuralidharan
- Gibbs SamplingUploaded bymuralidharan
- 22Uploaded bymuralidharan
- 5_1_derivation_of_formulas_in_chapter5.pdfUploaded bymuralidharan
- Social Exclusion of Scheduled Caste Children From Primary Education in IndiaUploaded bymuralidharan
- sprtUploaded bymuralidharan
- Rplot01Uploaded bymuralidharan
- Indira Gandhi National Old Age Pension SchemeUploaded bymuralidharan
- gg.txtUploaded bymuralidharan
- cipUploaded bymuralidharan
- 04-randomUploaded bymuralidharan
- 22-Reg7Uploaded bymuralidharan
- si.docxUploaded bymuralidharan
- Regression Analysis Cover PageUploaded bymuralidharan
- cover regUploaded bymuralidharan
- C1Uploaded bymuralidharan

- (2) Prime-hrm Forum 2017_pmUploaded bysuzette
- AngelScript to Do'sUploaded byMz4f45
- SyllabusME535 fall 2016(1).docxUploaded byAnonymous EMAJZz90
- toc-dfaUploaded bypurankkoul
- Modified Cable Sizing Strategies - Egemin - Publication 2014 JanuaryUploaded bymirali74
- improved elcUploaded bySamundra Gurung
- Fortianalyzer 5.4.0 Beta 3 Release NotesUploaded byParvez MDavida
- Netec Ppt Product OwnerUploaded byTara Rasch
- InterimReport[Draft]Uploaded bysaurabh
- BSP1005 Lecture Notes 7 - Market Power and Economics of Monopoly [Compatibility Mode]Uploaded bykennerve123
- Algortimos de Sincronizacion aplicados a relojes en Sistemas DistribuidosUploaded byStefania Garzon Barrera
- Machine Learning Course Brochure (1)Uploaded byprashant18coffee
- Fathom_Examples_Fat_002.pdfUploaded bynorgrent
- graupdatabase3Uploaded byapi-245499419
- MALC_chapter_1.pdfUploaded byC Saha
- R7411206 Information SecurityUploaded bysivabharathamurthy
- Intel® System Identification Utility - Identify Your ProductUploaded byabhi_icis
- projectUploaded byKhushboo Raj
- 11 Create Netcdf PythonUploaded byAli Jalaly
- Or Question BankUploaded byshh
- redpxrefUploaded byPachigolla Srikant
- MCQs for TestUploaded byHikmat Agha
- Coding VBAUploaded byPurna Cliquer's
- Arcane DB GettingStartedUploaded bydovescry
- Crypto Key ManagementUploaded byFachrizal Rizky Ferdiansyah
- Lawrence s Leff m s Barron s Math Workbook for the New SatUploaded byAidar1 Amanov
- Research study proposalUploaded bymahirzukic2
- 7 Steps for Learning Data Mining and Data ScienceUploaded byJoaquín Borrego-Díaz
- SAER-5925Uploaded byrjsquebrar
- PowerPoint Practice TestUploaded bykingraaja