SHARE
TWEET

Untitled

a guest Jul 23rd, 2019 54 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. > set.seed(1)
  2. > training_pred <- data.frame(rbind(c(1,0),c(1,0),c(0,0),c(0,0),c(0,1),c(0,1)))
  3. > colnames(training_pred) <- paste0("V",1:2)
  4. > training_obs <- as.vector(cbind(1,as.matrix(training_pred))%*%c(1,-.7,-.8)+
  5. + rnorm(nrow(training_pred),0,0.2))
  6. > training_obs
  7. [1] 0.17470924 0.33672866 0.83287428 1.31905616 0.26590155 0.03590632
  8.      
  9. > model <- lm(training_obs~V1+V2,training_pred)
  10. > new_pred <- data.frame(matrix(c(1,1),nrow=1,dimnames=list(NULL,paste0("V",1:2))))
  11. > predict(model,newdata=new_pred)
  12.          1
  13. -0.6693423
  14.      
  15. > summary(training_pred)
  16.        V1               V2        
  17.  Min.   :0.0000   Min.   :0.0000  
  18.  1st Qu.:0.0000   1st Qu.:0.0000  
  19.  Median :0.0000   Median :0.0000  
  20.  Mean   :0.3333   Mean   :0.3333  
  21.  3rd Qu.:0.7500   3rd Qu.:0.7500  
  22.  Max.   :1.0000   Max.   :1.0000  
  23. > summary(new_pred)
  24.        V1          V2  
  25.  Min.   :1   Min.   :1  
  26.  1st Qu.:1   1st Qu.:1  
  27.  Median :1   Median :1  
  28.  Mean   :1   Mean   :1  
  29.  3rd Qu.:1   3rd Qu.:1  
  30.  Max.   :1   Max.   :1
  31.      
  32. > model
  33.  
  34. Call:
  35. lm(formula = training_obs ~ V1 + V2, data = training_pred)
  36.  
  37. Coefficients:
  38. (Intercept)           V1           V2  
  39.      1.0760      -0.8202      -0.9251
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top