# Regression # Dennis E. Slice (c) 2012 # Income-Happiness # Fake data # Model parameters plotTitle = "Happiness v. Income" xLbl = "X (Income)" yLbl = "Y (Happiness)" n = 10 # Small n for illustrative purposes b0 = 3 # non-zero intercept b1 = 0.1 # one thousand in income increases happiness by 0.1 minX = 1 # minimum income maxX = 100 # maximum income rangeX = maxX - minX # X - independent variable (free to vary) income = seq(minX, maxX, rangeX/(n - 1)) # 1000 to 100000 in income # (n-1)? This gives the number of gaps so the number of points will equal n # Y - dependent variable, completely determined by x happiness = b0 + b1 * income # Generate some error = variation due to anything # NOT in the model. E.g. sickness, marital status, # lying about income, etc, etc, etc,...anything! # sd=2 chosen by trial-and-error for illustrative purposes error = rnorm(n, 0, 2) happiness = happiness + error # Make a data frame and save it df <- data.frame(income,happiness) write.table(df,paste("happiness",n,".RData",sep="")) plot(df$income,df$happiness)