# Linear regression of 32 amp data. Plot is stored in lm.png x <- c(0.3227232465, 0.2854859489, 0.3534587938, 0.4498566467, 0.4039529072, 0.4025835754) y <- c(13.7079374085, 19.5715418654, 11.3708216946, -0.3745108961, 6.6088012633, 2.4987437778) # Apply the lm() function. model <- lm(y~x) png(file = "lm.png") plot(x,y,xlab = "Baseline efficiency", ylab = "efficiency increase %") new.data <- data.frame(x = seq(min(x),max(x),len=6)) lines(new.data$x,predict(model,newdata=new.data)) dev.off() print(summary(model)) # Linear regression of 46 amp data. Plot is stored in lma.png x <- c(0.2854859489, 0.4181766012, 0.3534587938, 0.4498566467, 0.3650476068, 0.4039529072) y <- c(14.9666501473, 4.3357736667, 13.3628124346, -0.5383594131, 11.3240380881, 9.6677593611) # Apply the lm() function. model <- lm(y~x) png(file = "lma.png") plot(x,y,xlab = "Baseline efficiency", ylab = "efficiency increase %") new.data <- data.frame(x = seq(min(x),max(x),len=6)) lines(new.data$x,predict(model,newdata=new.data)) dev.off() print(summary(model)) # Non-linear regression of 46 amp data. Plot is stored in nls.png. xvalues <- c(0.2854859489, 0.4181766012, 0.3534587938, 0.4498566467, 0.3650476068, 0.4039529072) yvalues <- c(14.9666501473, 4.3357736667, 13.3628124346, -0.5383594131, 11.3240380881, 9.6677593611) # Give the chart file a name. png(file = "nls.png") plot(xvalues,yvalues,xlab = "Baseline efficiency", ylab = "efficiency increase %") # Take the assumed values and fit into the model. model <- nls(yvalues ~ b1*xvalues^2+b2,start = list(b1=1,b2=3)) # Plot the chart with new data by fitting it to a prediction from 100 data points. new.data <- data.frame(xvalues = seq(min(xvalues),max(xvalues),len=100)) lines(new.data$xvalues,predict(model,newdata=new.data)) # Save the file. dev.off() # Get the sum of the squared residuals. print(sum(resid(model)^2)) # Get the confidence intervals on the chosen values of the coefficients. print(confint(model)) # Linear regression of squared y values for 46 amps. Plot is stored in lm1.png x <- c(0.2854859489, 0.4181766012, 0.3534587938, 0.4498566467, 0.3650476068, 0.4039529072) y <- c(224.0006166317, 18.7989332888, 178.5647561623, -0.2898308577, 128.2338386207, 93.4655710641) # Apply the lm() function. model <- lm(y~x) png(file = "lm1.png") plot(x,y,xlab = "Baseline efficiency", ylab = "square of efficiency increase %") new.data <- data.frame(x = seq(min(x),max(x),len=6)) lines(new.data$x,predict(model,newdata=new.data)) dev.off() print(summary(model))