y ~ x1 + x2 + x3 + x4or in SAS by
model y = x1-x4;If all independent variables are held constant except for x3 and x3 increases by 5, how much does y increase in terms of the regression coefficient β3?
1700 9 .These are the desired settings for the independent variables with the dependent variable value set to missing ( . ).
newdata = data.frame(pressure=1700, angle=9)If more than one setting is needed, pass in a vector for each column:
newdata = data.frame(pressure=c(1700, 1400), angle=c(9, 15)).Then obtain the predicted values for these settings with
p = predict(model, newdata=newdata)
# R script. Assume that the full dataframe is df. # Suppose that you want to select one fourth of the # to be the test set. n = nrow(df) size = n / 4 set.seed(49143) s = sample(n, size) test = df[s, ] training = df[-s, ] * SAS source code. Assume that the full dataset is full_ds. Suppose that you want to select one third of the to be the test set; proc surveyselect data=full_ds method=srs seed=49143 outall samprate=0.25 out=subsets;
# Crime Example converted to work with propval.txt datafile. library(leaps) cat("PropVal dataset:\n") propval = read.table("c:/datasets/propval.txt", header=T) print(propval) depvar = as.vector(propval$y) predictors = as.matrix(propval[, c(-1, -2)]) out = leaps(x=predictors, y=depvar, wt=rep(1, NROW(predictors)), int=TRUE, method=c("adjr2"), nbest=10, names=c("x2", "x3", "x4", "x5", "x6", "x7", "x8", "x9")) print(cbind(out$which, out$adjr2))
# Install DAAG package if not installed. install.packages("DAAG") libary(DAAG) model = lm(y ~ x1 + x2 + x3, data=mydata) # Perform 3-fold cross-validation. # Use seed to get the same result on every run. cv.lm(mydata, model, m=3, seed=997)
Model | Independent Variable | Parameter Estimates |
Standard Error | 95% Confidence Interval |
---|---|---|---|---|
Linear | Intercept | 0.42081 | 0.02494 | (0.36842, 0.47320) |
len | 2.12796 | 0.08195 | (1.95578, 2.30014) | |
Quadratic | Intercept | 0.29426 | 0.01204 | (0.26886, 0.31965) |
len | 3.48676 | 0.10392 | (3.26751, 3.70601) | |
lenlen | -2.54743 | 0.18924 | (-2.94670, -2.14816) | |
Square Root | Intercept | 0.01165 | 0.00621 | (-0.00141, 0.02471) |
sqrtlen | 1.98756 | 0.01203 | (1.96228, 2.01285) | |
Log-Log | Intercept | 0.68005 | 0.00702 | (0.66530, 0.69480) |
loglen | 0.48618 | 0.00402 | (0.47773, 0.49463) |