Presentation is loading. Please wait.

Presentation is loading. Please wait.

SIMPLE AND MULTIPLE REGRESSION. Relació entre variables Entre variables discretes (exemple: veure Titanic)Titanic Entre continues (Regressió !) Entre.

Similar presentations


Presentation on theme: "SIMPLE AND MULTIPLE REGRESSION. Relació entre variables Entre variables discretes (exemple: veure Titanic)Titanic Entre continues (Regressió !) Entre."— Presentation transcript:

1 SIMPLE AND MULTIPLE REGRESSION

2 Relació entre variables Entre variables discretes (exemple: veure Titanic)Titanic Entre continues (Regressió !) Entre discretes i continues (Regressió!)

3 >Rendiment en Matemàtiques, >Nombre de llibres a casa Pisa 2003

4 >Rendiment en Matemàtiques, >Nombre de llibres a casa Pisa 2003

5 Regressió Lineal ?

6 Pisa 2003 Regressió Lineal ?

7 Pisa 2003 Regressió Lineal ?

8 Regressió Lineal 

9 * We first load the PISAespanya.sav file and then * this is the sintaxis file for SPSS analysis *Q38 How often do these things happen in your math class *Student dont't listen to what the teacher says CROSSTABS /TABLES=subnatio BY st38q02 /FORMAT= AVALUE TABLES /STATISTIC=CHISQ /CELLS= COUNT ROW. FACTOR /VARIABLES pv1math pv2math pv3math pv4math pv5math pv1math1 pv2math1 pv3math1 pv4math1 pv5math1 pv1math2 pv2math2 pv3math2 pv4math2 pv5math2 pv1math3 pv2math3 pv3math3 pv4math3 pv5math3 pv1math4 pv2math4 pv3math4 pv4math4 pv5math4 /MISSING LISTWISE /ANALYSIS pv1math pv2math pv3math pv4math pv5math pv1math1 pv2math1 pv3math1 pv4math1 pv5math1 pv1math2 pv2math2 pv3math2 pv4math2 pv5math2 pv1math3 pv2math3 pv3math3 pv4math3 pv5math3 pv1math4 pv2math4 pv3math4 pv4math4 pv5math4 /PRINT INITIAL EXTRACTION FSCORE /PLOT EIGEN ROTATION /CRITERIA FACTORS(1) ITERATE(25) /EXTRACTION ML /ROTATION NOROTATE /SAVE REG(ALL). GRAPH /SCATTERPLOT(BIVAR)=st19q01 WITH fac1_1 /MISSING=LISTWISE. REGRESSION /MISSING LISTWISE /STATISTICS COEFF OUTS R ANOVA /CRITERIA=PIN(.05) POUT(.10) /NOORIGIN /DEPENDENT fac1_1 /METHOD=ENTER st19q01 /PARTIALPLOT ALL /SCATTERPLOT=(*ZRESID,*ZPRED ) /RESIDUALS HIST(ZRESID) NORM(ZRESID).

10 library(foreign) help(read.spss) data=read.spss("G:/DATA/PISAdata2003/ReducedDataSpain.sav", use.value.labels=TRUE,to.data.fram=TRUE) names(data) [1] "SUBNATIO" "SCHOOLID" "ST03Q01" "ST19Q01" "ST26Q04" "ST26Q05" [7] "ST27Q01" "ST27Q02" "ST27Q03" "ST30Q02" "EC07Q01" "EC07Q02" [13] "EC07Q03" "EC08Q01" "IC01Q01" "IC01Q02" "IC01Q03" "IC02Q01" [19] "IC03Q01" "MISCED" "FISCED" "HISCED" "PARED" "PCMATH" [25] "RMHMWK" "CULTPOSS" "HEDRES" "HOMEPOS" "ATSCHL" "STUREL" [31] "BELONG" "INTMAT" "INSTMOT" "MATHEFF" "ANXMAT" "MEMOR" [37] "COMPLRN" "COOPLRN" "TEACHSUP" "ESCS" "W.FSTUWT" "OECD" [43] "UH" "FAC1.1" attach(data) mean(FAC1.1) [1] -8.95814e-16 tabulate(ST19Q01) [1] 106 0 15 1266 1927 2372 3575 1155 375 > table(ST19Q01) ST19Q01 Miss Invalid N/A More than 500 books 106 0 15 1266 201-500 books 101-200 books 26-100 books 11-25 books 1927 2372 3575 1155 0-10 books 375

11 Efecto de Cultural Possession of the family

12 Data Variables Y and X observed on a sample of size n: y i, x i i =1,2,..., n

13 Covariance and correlation

14 Scatterplot for various values of correlation

15 Coeficient de correlació r = 0, tot i que hi ha una relació funcional exacta (no lineal!) > cbind(x,y) x y [1,] -10 100 [2,] -9 81 [3,] -8 64 [4,] -7 49 [5,] -6 36 [6,] -5 25 [7,] -4 16 [8,] -3 9 [9,] -2 4 [10,] -1 1 [11,] 0 0 [12,] 1 1 [13,] 2 4 [14,] 3 9 [15,] 4 16 [16,] 5 25 [17,] 6 36 [18,] 7 49 [19,] 8 64 [20,] 9 81 [21,] 10 100 >

16 Regressió Lineal Simple Variables Y X E Y | X =  +  X Var (Y | X ) =  

17 Linear relation: y = 1 +.6 X

18 Linear relation and sample data

19 Regression Model Y i =  +  X i +  i  i : mean zero variance  2 n  rmally distributed

20 Sample Data: Scatterplot

21 Fitted regression line a= 0.5789 b=0.6270

22 Fitted and true regression lines: a= 0.5789 b=0.6270  =1,  =.6

23 Fitted and true regression lines in repeated (20) sampling  =1,  =.6

24 OLS estimate of beta (under repeated sampling)  =1,  =.6 Estimate of beta for different samples (100): 0.619 0.575 0.636 0.543 0.555 0.594 0.611 0.584 0.576...... > > mean(bs) [1] 0.6042086 > sd(bs) [1] 0.03599894 >

25 REGRESSION Analysis of the Simulated Data (with R and other software )

26 Fitted regression line: a= 1.0232203, b= 0.6436286  =1,  =.6

27 Regression Analysis regression = lm(Y ~X) summary(regression) Call: lm(formula = Y ~ X) Residuals: Min 1Q Median 3Q Max -6.0860 -2.1429 -0.1863 1.9695 9.4817 Coefficients: Estimate Std. Error t value Pr(>|t|) (Intercept) 1.0232 0.3188 3.21 0.00180 ** X 0.6436 0.0377 17.07 < 2e-16 *** --- Signif. codes: 0 `***' 0.001 `**' 0.01 `*' 0.05 `.' 0.1 ` ' 1 Residual standard error: 3.182 on 98 degrees of freedom Multiple R-Squared: 0.7483, Adjusted R-squared: 0.7458 F-statistic: 291.4 on 1 and 98 DF, p-value: < 2.2e-16 >>

28 Regression Analysis with Stata. use "E:\Albert\COURSES\cursDAS\AS2003\data\MONT.dta", clear. regress y x Source | SS df MS Number of obs = 100 ---------+------------------------------ F( 1, 98) = 291.42 Model | 2950.73479 1 2950.73479 Prob > F = 0.0000 Residual | 992.280727 98 10.1253135 R-squared = 0.7483 ---------+------------------------------ Adj R-squared = 0.7458 Total | 3943.01551 99 39.8284395 Root MSE = 3.182 ------------------------------------------------------------------------------ y | Coef. Std. Err. t P>|t| [95% Conf. Interval] ---------+-------------------------------------------------------------------- x |.6436286.0377029 17.071 0.000.5688085.7184488 _cons | 1.02322.3187931 3.210 0.002.3905858 1.655855 ------------------------------------------------------------------------------. predict yh. graph yh y x, c(s.) s(io)

29 Regression analysis with SPSS

30 Estimación

31 Gráfico de dispersión

32 Fitted Regression FY i = 1.02  +.64 X i, R 2 =.74 s.e.: (.037) t-value: 17.07  Regression coeficient of X is significant (5% significance level), with the expected value of Y icreasing.64 for each unit increase of X. The 95% confidence interval for the regression coefficient is [.64-1.96*.037,..64+1.96*.037]=[.57,.71] 74% of the variation of Y is explained by the variation of X

33 Fitted regression line

34 Residual plot

35 OLS analysis

36 Variance decomposition

37 Properties of OLS estimation

38 Sampling distributions

39 Inferences

40 Student-t distribution

41 Significance tests

42 F-test

43 Prediction of Y

44 Multiple Regression:

45 t-test and CI

46 F-test

47 Confidence bounds for Y

48 Interpreting multiple regression by means of simple regression

49 Adjusted R 2

50 Exemple de l’Anàlisi de Regressió Dades de paisos.sav

51 Variables

52 Matrix Plot Necessitat de transformar les variables !

53 Transformació de variables

54 Matrix Plot Relacions (aproximadament) lineals entre variables transformades !

55 Anàlisi de Regressió REGRESSION /MISSING LISTWISE /STATISTICS COEFF OUTS R ANOVA /CRITERIA=PIN(.05) POUT(.10) /NOORIGIN /DEPENDENT espvida /METHOD=ENTER calories logpib logmetg /PARTIALPLOT ALL /SCATTERPLOT=(*ZRESID,*ZPRED ) /SAVE RESID.

56 Residus vs y ajustada:

57 Regressió parcial:

58

59 Regressió parcial

60 Anàlisi de Regressió REGRESSION /MISSING LISTWISE /STATISTICS COEFF OUTS R ANOVA /CRITERIA=PIN(.05) POUT(.10) /NOORIGIN /DEPENDENT espvida /METHOD=ENTER calories logpib logmetg cal2 /PARTIALPLOT ALL /SCATTERPLOT=(*ZRESID,*ZPRED ) /SAVE RESID.

61 Residus vs y ajustada

62 Case statistics Case missfit Potential for influence: Leverage Influence

63 Residuals

64 Hat matrix

65 Influence Analysis

66 Diagnostic case statistics After fitting regression, use the instruction Fpredict namevar predicted value of y, cooksd Cook’s D influence measure, dfbeta(x1) DFBETAS for regression coefficient on var x1, dfits DFFITS influence measures, hat Diagonal elements of hat matrix (leverage), leverage (same as hat), residuals, rstandard standardized residuals,.rstudent Studentized residuals, stdf standard erros of predicte individual y, standard error of forecast, stdp standard errors of predicted mean y, stdr standard errors of residuals, welsch Welsch’s distance influence measure.... display tprob(47, 2.337) Sort namevar list x1 x2 –5/1

67 Leverages after fit …. fpredict lev, leverage. gsort -lev. list nombre lev in 1/5 nombre lev 1. RECAGUREN SOCIEDAD LIMITADA,.0803928 2. EL MARQUES DEL AMPURDAN S,L,.0767692 3. ADOBOS Y DERIVADOS S,L,.0572497 4. CONSERVAS GARAVILLA SA.0549707 5. PLANTA DE ELABORADOS ALIMENTICIOS MA.0531497.

68 Box plot of leverage values. predict lev, leverage. graph lev, box s([_n]) Cases with extreme leverages

69 Leverage versus residual square plot. lvr2plot, s([_n])

70 Dfbeta’s:. fpredict beta, dfbeta(nt_paau). graph beta, box s([_n])

71 Regression: Outliers, basic idea Outlier

72 Regression: Outliers, indicators IndicatorDescriptionRule of thumb (when “wrong”) ResidResidual: actual – predicted- ZResidStandardized residual: residual divided by standarddeviation residual > 3 (in absolute value) SResidStudentized Residu: residual divided by standarddeviation residual at that particular datapoint of X values > 3 (in absolute value) DResidDifference residual and residual when datapoint deleted - SDResidSee DResid, standardized by standard deviation at that particular datapoint of X values > 3 (in absolute value)

73 Regression: Outliers, in SPSS

74 Regression: Influential Points, Basic Idea Influential Point (no outlier!)

75 Regression: Influential Points, Indicators IndicatorDescriptionRule of thumb LeverAfstand tussen punt en overige punten NB: potentieel invloedrijk > 2 (p+1) / n CookVerandering in residuen van overige cases als een bepaalde case niet in de regressie meedoet > 1 DfBetaVerschil tussen beta’s wanneer de case wel meedoet en wanneer die niet meedoet in het model NB: voor elke beta krijgen we deze - SdfBetaDfBeta / Standaardfout DfBeta NB: voor elke beta > 2/√n DfFitVerschil tussen voorspelde waarde als case wel versus niet meedoet in model - SDfFitDfFit / standaarddeviatie SdFit> 2 /√(p/n) CovRatioVerandering in Varianties/Covarianties als punt niet meedoet Abs (CovRatio – 1)> 3 p / n

76 Regression: Influential points, in SPSS Case 2 is an influential point

77

78

79

80

81 Regression: Influential Points, what to do? Nothing at all.. Check data Delete a-typical datapoints, then repeat regression without these datapoints “to delete a point or not is an issue statisticians disagree on”

82 MULTICOLLINEARITY Diagnostic tools

83 Regression: Multicollinearity If predictors correlate “high”, then we speak of multicollinearity Is this a problem? If you want to asess the influence of each predictor, yes it is, because: –Standarderrors blow up, making coefficients not- significant

84 Analyzing math data. use "G:\Albert\COURSES\cursDAS\AS2003b\data\mat.dta", clear. save "G:\Albert\COURSES\CursMetEstad\Curs2004\Metodes\mathdata.dta" file G:\Albert\COURSES\CursMetEstad\Curs2004\Metodes\mathdata.dta saved. edit - preserve. gen perform = (nt_m1+ nt_m2+ nt_m3)/3 (110 missing values generated). corr perform nt_paau nt_acces nt_exp (obs=189) | perform nt_paau nt_acces nt_exp ---------+------------------------------------ perform | 1.0000 nt_paau | 0.3535 1.0000 nt_acces | 0.5057 0.8637 1.0000 nt_exp | 0.5002 0.3533 0.7760 1.0000. outfile nt_exp nt_paau nt_acces perform using "G:\Albert\COURSES\CursMetEsta > d\Curs2004\Metodes\mathdata.dat".

85

86 Multiple regression: perform vs nt_acces nt_paau. regress perform nt_acces nt_paau Source | SS df MS Number of obs = 245 ---------+------------------------------ F( 2, 242) = 31.07 Model | 71.1787647 2 35.5893823 Prob > F = 0.0000 Residual | 277.237348 242 1.14560888 R-squared = 0.2043 ---------+------------------------------ Adj R-squared = 0.1977 Total | 348.416112 244 1.42793489 Root MSE = 1.0703 ------------------------------------------------------------------------------ perform | Coef. Std. Err. t P>|t| [95% Conf. Interval] ---------+-------------------------------------------------------------------- nt_acces | 1.272819.2427707 5.243 0.000.7946054 1.751032 nt_paau | -.2755092.1835091 -1.501 0.135 -.6369882.0859697 _cons | -1.513124.9729676 -1.555 0.121 -3.42969.4034425 ------------------------------------------------------------------------------. Perform = rendiment a mates I a III

87 Collinearity

88 Diagnostics for multicollinearity. corre nt_paau nt_exp nt_acces (obs=276) | nt_paau nt_exp nt_acces --------+--------------------------- nt_paau| 1.0000 nt_exp| 0.3435 1.0000 nt_acces| 0.8473 0.7890 1.0000. fit perform nt_paau nt_exp nt_access. vif Variable | VIF 1/VIF ---------+---------------------- nt_acces | 1201.85 0.000832 nt_paau | 514.27 0.001945 nt_exp | 384.26 0.002602 ---------+---------------------- Mean VIF | 700.13. Any explanatory variable with a VIF greater than 5 (or tolerance less than.2) show a degree of collinearity that may be Problematic This ratio is called Tolerance In the case of just nt_paau an nt_exp we Get. vif Variable | VIF 1/VIF ---------+---------------------- nt_exp | 1.14 0.875191 nt_paau | 1.14 0.875191 ---------+---------------------- Mean VIF | 1.14. VIF = 1/(1 – R j 2 )

89 Multiple regression: perform vs nt_paau nt_exp. regress perform nt_paau nt_exp Source | SS df MS Number of obs = 189 ---------+------------------------------ F( 2, 186) = 37.24 Model | 75.2441994 2 37.6220997 Prob > F = 0.0000 Residual | 187.897174 186 1.01019986 R-squared = 0.2859 ---------+------------------------------ Adj R-squared = 0.2783 Total | 263.141373 188 1.39968815 Root MSE = 1.0051 ------------------------------------------------------------------------------ perform | Coef. Std. Err. t P>|t| [95% Conf. Interval] ---------+-------------------------------------------------------------------- nt_paau |.3382551.1109104 3.050 0.003.119451.5570593 nt_exp |.9040681.1396126 6.476 0.000.6286403 1.179496 _cons | -3.295308 1.104543 -2.983 0.003 -5.474351 -1.116266 ------------------------------------------------------------------------------. predict yh (option xb assumed; fitted values) (82 missing values generated). predict e, resid (169 missing values generated).. corr nt_exp nt_paau nt_acces (obs=276) | nt_exp nt_paau nt_acces ---------+--------------------------- nt_exp | 1.0000 nt_paau | 0.3435 1.0000 nt_acces | 0.7890 0.8473 1.0000

90 Regression: Multicollinearity, Indicators IndicatordescriptionRule of thumb (when “wrong”) Overall F_Test versus test coefficients Overall F-Test is significant, but individual coefficients are not - BetaStandardized coefficientOutside [-1, +1] ToleranceTolerance = unique variance of a predictor (not shared/explained by other predictors) … NB: Tolerance per coefficient < 0.01 Variantie Inflation Factor √ VIF indicates how much the standard error of a particular coefficient is inflated due to correlatation between this particular predictor and the other predictors NB: VIF per coefficient >10 Eigenvalues…rather technical…+/- 0 Condition Index…rather technical…> 30 Variance Proportion…rather technical…look tot “loadings” on the dimensions Loadings around 1

91 Regression: Multicollinearity, in SPSS diagnostics

92 Regression: Multicollineariteit, in SPSS Beta > 1Tolerance, VIF in orde

93 Regressie: Multicollineariteit, in SPSS 2 eigenwaarden rond 0 Deze variabelen zorgen voor multicoll. CI in orde

94 Regression: Multicollinearity, what to do? Nothing… (if there is no interest in the individual coefficients, only in good prediction) Leave one (or more) predictor(s) out Use PCA to reduce high correlated variables to smaller number of uncorrelated variables

95 Variables Categòriques Use: Survey_sample.sav, in i/.../data

96 Salari vs gènere | anys d’educació status de treball

97 Creació de variables dicotòmiques GET FILE='G:\Albert\Web\Metodes2005\Dades\survey_sample.sav'. COMPUTE D1 = wrkstat=1. EXECUTE. COMPUTE D2 = wrkstat=2. EXECUTE. COMPUTE D3 = wrkstat=3. EXECUTE. COMPUTE D4 = wrkstat=4. EXECUTE. COMPUTE D5 = wrkstat=5. EXECUTE. COMPUTE D6 = wrkstat=6. EXECUTE. COMPUTE D7 = wrkstat=7. EXECUTE. COMPUTE D8 = wrkstat=8. EXECUTE.

98 Regressió en blocks REGRESSION /MISSING LISTWISE /STATISTICS COEFF OUTS R ANOVA CHANGE /CRITERIA=PIN(.05) POUT(.10) /NOORIGIN /DEPENDENT rincome /METHOD=ENTER sex /METHOD=ENTER d2 d3 d4 d5 d6 d7 d8.

99

100 Regressió en blocks REGRESSION /MISSING LISTWISE /STATISTICS COEFF OUTS R ANOVA CHANGE /CRITERIA=PIN(.05) POUT(.10) /NOORIGIN /DEPENDENT rincome /METHOD=ENTER sex /METHOD=ENTER educ /METHOD=ENTER d2 d3 d4 d5 d6 d7 d8.

101 Categorical Predictors Is income dependent on years of age and religion ?

102 Categorical Predictors Compute dummy variable for each category, except last

103 Categorical Predictors And so on…

104 Categorical Predictors Block 1

105 Categorical Predictors Block 2

106 Categorical Predictors Ask for R 2 change

107 Categorical Predictors Look at R Square change for importance of categorical variable


Download ppt "SIMPLE AND MULTIPLE REGRESSION. Relació entre variables Entre variables discretes (exemple: veure Titanic)Titanic Entre continues (Regressió !) Entre."

Similar presentations


Ads by Google