text:
# How to find how independent variables affect dependent variables

I'm a bit of a novice at maths and am trying to get my head around a problem.

I have 3 independent variables which affect 1 dependent variable. I want to create a 4D model which will give me the 4th dimension when I give it an (x, y, z) triplet.

I am programming in Java and already have a regression function which will take a set of independent variables and give me coefficients of those independent variables which best fit the data supplied.

What I am trying to figure out is which independent variables to use.

I have tried various cubic functions, with independent variables something like: {1 + x + y + z + xx + xy + xz + yy + yz + zz + xxx + xxy + xxz + yyy + yyx + yyz + zzz + zzy + zzx + xyz}

Then when the resulting model looked a bit wrong I thought, ah maybe the x and y values don't mean anything when multiplied, so took out the variables where x and y were together. Now it still isn't right and I'm worried I'm just going about it in entirely the wrong way. Maybe there's an exponential in there somewhere?

Is there some mathematical method to finding exactly which variables I should be using?

Cheers!

The data I already have is like this. It's to do with calculating final scores in a cricket game based on which batsmen are in and how far through the game we are, the final score is the dependent variable:

X axis ranges from 0 to 10 inclusive (the order of the first batsman in). Y axis ranges from 0 to 10 inclusive (the order of the second batsman in). Z axis ranges from 0 to 19 inclusive (the over we are in, basically means how far through the game we are).

The lower x and y are, the higher the final score will be, as the team have better batsmen still in. The higher the over (when x and y are the same), the higher the final score will be, because the batsmen have lasted longer and so should have their eye in.

I guess it's "what I expect the dependent variable to be" which is the question. How does each parameter effect the final score. I can post some sample data if you want.

I have calculated a data point for each (X, Y, Z) combination, so can't get more. I have data from all the cricket games, and each data point is the average final score of games where this situation has occurred. Some situations ((x, y, z) triples) are far more likely to occur (in more average games) and have been weighted in the regression function accordingly.

-

## migrated from math.stackexchange.comMar 8 '13 at 20:54

This question came from our site for people studying math at any level and professionals in related fields.

There is no exact science behind including or omitting explanatory variables, as adding additional variables changes the meaning of your model. By adding additional variables, what you basically say is: How does x affect y, keeping all other explanatory variables constant?

Apart from paying attention to the p-values, you should also have a look at the $R^2$, which measures which portion of the variance in the population is explained by your model.

Unless you are interested in coding the regression algorithm yourself, you might want to have a look at the excellent Weka Java Library or R, an open source statistics software.

-

It is very hard to determine the relationship between variables without having an underlying, prior assumption on how their relationship works. I am not sure about the problem at hand, but seeing that you assume a linear relationship of data points (be it variables or their products) I take it we are looking at a linear relationship.

Indeed there are several problems which may make your regression and forecast downright invalid. Another issue is your small sample size. The result of this is that you have to be even more careful in selecting the right technique.

First, your regression model must be correct for your regression to be correct. This seems tautological, but it entails that no variable should be missing in the equation, if it also has an impact (more correctly, is correlated) with the other variables.
You can immediately see the issue here: It is almost certain that there are more things to winning a cricket game than just the order of batters. For example if the breakfast of the second batter influences the game outcome AND his standing on the batting list, it technically must be in your equation. Otherwise your estimate of the influence of the batting order on the game outcome will be biased, ie wrong.
On the other hand if you have a variable, like weather (maybe), which does not influence the batting order but does influence the game outcome, then your estimate of the influence of the batting order will still be correct. However your forecast of the game outcome BASED on these estimates will be off and should be considered more of a indication than a concrete fact.

You will probably say, well damn, how we ever gonna get a good model then? Good point, almost never will we be exact in this. However there are ways to mitigate the problem or at least diagnose it. We somewhat get around missing variable bias if the missing part is somehow more or less random. In fact we concede anyway that we can not correctly model reality, but as long as the "wrongness" has certain properties, we are still somewhat "right".

The key is that we add the error term in this, a random factor which is normally assumed to be, well, "normal" distributed and centered around zero, though this is already achieved by including a constant variable.
But if we have such an error term in our model, ie. our understanding of reality, then the residuals, which is the difference between the real data and our estimation, should be only created by these error terms and therefore also appear random.
On the other hand if we have a biased estimate because we are missing variables, we can still be confident about our results if the residuals appear to be random around zero.

So now you have a pretty good understanding of the problems with the model. You should now go ahead and look at your residuals. Calculate those and look at the plot. Does it look normal? Does it have a systematic error? How are the residuals and the independent variables correlated?
You want to make sure that there is no relation between an independent variable and a residual (at the same datapoint, that is). So plot the correlation of this!
Next you want to make sure your residuals look normal, ie literally normal (distributed). If not, you are probably missing some influence which may make your estimate problematic.
At this point it might be that you have to give up because you just can not make the model work.
However in general you start to add and remove variables, keeping in mind how they correlate with each other. You look at p-values and R-Squared to find a model which explains the influence best. But keep in mind that the p-values only make sense if your residuals are correctly distributed.

I wrote this as a general understanding of some problems. You will have additional issues because of your small sample size, though these are more about accuracy of your forecast (depends). I didn't explain the math or how to technically do this because honestly, that's gonna take quite a bit of research and more than I can or should write here. But now you know what dangers lie along the way!

-

Well, you may run simple OLS regression with your independent variables and then look at p-values and drop out these which are statistically not significant. But if you don't have too many data points, I would suggest playing with the variable specification.

-
Ah, now what are the p-values, are they to do with partial residual plots? and what makes them significant or not? –  Duane Allman Mar 8 '13 at 22:00
Duane, although there's a kernel of good advice in this reply, I suggest you not follow it. The first part advocates a simplified form of model building akin to "backward stepwise regression." This is known to have problems. The second part--"playing"--does not seem to provide any actionable advice at all. –  whuber Mar 8 '13 at 22:20
Ok, I imagine the problems backward stepwise has is that you could easily remove a criteria which looks bad, but is actually good when correlating with something else (or however you say it)? If I did an exhaustive search of all combinations of independent variables (up to order 3), and pick the combination which gave me smallest "fisher f" value, would that be a decent result? –  Duane Allman Mar 8 '13 at 22:42
@DuaneAllman, unfortunately no. What you have suggested is a simplified for of model building akin to "best subsets regression". If these comments don't make much sense / you want to understand why, it may help to read my answer here: algorithms-for-automatic-model-selection. –  gung Mar 9 '13 at 0:45
@DuaneAllman, my position is No. You should read the post that I linked to. –  gung Mar 10 '13 at 17:22


text:
# Day 4: Magrittr is a series of tubes

### by Danielle Navarro, 30 Apr 2018

Yesterday was supposed to be laundry day. I had a massive backlog of clothes that needed to be washed, another pile that needed folding, and several free hours in which I could put several loads through the washing machine. It didn’t quite go to plan: our neighbour has been doing some construction work and the drainage pipes haven’t been all that reliable. The first load I tried to put through caused water to back up through the drains, and suddenly half of the house is a wading pool. The kids were very pleased. My partner and I, less so.

Anyway, while bailing water out of the laundry and thinking about pipes, it occurs to me that I really ought to be using magrittr. It’s not that I don’t know how to use %>%, it’s just that I haven’t spent enough time thinking about what it means for my workflow. It’s a little shameful that I’ve never even bothered to look at the documentation for magrittr. Maybe I should do something about that…

## A simple pipe

Writing your own pipe is really easy, as long as you don’t want it to be very good. Here I define my own pipe %-->% and use it to draw a barplot that counts the number of characters in every line to Greg! The stop sign! (as discussed in the emo-tism post from a couple of days ago). First we define the pipe function as a custom operator:

%-->% <- function(x,f) { f(x) }

Now I an use it the same way I would do with the %>% operator in the magrittr package:

greg <- "https://djnavarro.net/files/gregthestopsign.txt"
greg %-->% readLines %-->% nchar %-->% barplot

The thing that I – and just about everyone else in #Rstats land it seems – love about this way of coding in R is the fact that it’s a nice metaphor for data analysis. You have a data source (greg) that gets “piped” through several steps (in this case it’s a read > process > plot sequence) and then out “pops” the result. Writing the same code in a more conventional way is rather less visually satisfying:

greg <- "https://djnavarro.net/files/gregthestopsign.txt"
gregSummary <- nchar(gregData)
barplot(gregSummary)

In the piped example, you get an intuitive feeling of the greg data flowing through each of the steps in a straight line, whereas in the traditional example it feels more like greg is zigzagging through the code, jumping from left to right as you move down the code! To my mind there’s nothing “right” or “wrong” about either version, but the more I use pipes in my own code the happier I feel about it.

## My pipe is broken

The thing about plumbing, I mused to myself while scowling at my daughter who is gleefully splashing water all over the cupboards, is that it looks easier than it really is. Any fool can duct tape some PVC together and call it plumbing, but if it leaks then tree roots will get in and then it’s a whole thing and, well…

Clunky metaphors notwithstanding, the problem with my %-->% function is that it only works when the object on the right hand side of the pipe is a function. If I want to customise the barplot that gets drawn at the end – say, by drawing it in R-Ladies purple – it’s not sufficient to pipe my data to the barplot function. I need to tell R to call barplot with the col="#88398A" argument. Intuitively it feels like I what I want to do is this…

greg %-->% readLines %-->% nchar %-->% barplot(col="#88398A")
## Error in barplot.default(col = "#88398A"): argument "height" is missing, with no default

… but of course my stupid, stupid pipe doesn’t know how to handle that! The code I wrote for %-->% works in the original example because barplot is a function, but barplot(col="#8839A") describes a call to the barplot function. I could of course redefine my pipe to be a bit more sophisticated so that it can handle arbitrary calls as input, but then I’d have to try to remember how quote and eval and substitute and all those vile low-level functions work… and seriously, why bother reinventing the pipe? The %>% operator in the magrittr package already does everything I could ever want. So thanks to the joy that is %>% I can seamlessly mix functions like readLines with calls like barplot(col="#88398A") in my code, and magrittr is smart enought to handle it:

greg %>% readLines %>% nchar %>% barplot(col="#88398A")

If I’ve learned anything from the pool of water spreading across my laundry floor, it’s really important to know that you can trust your pipes.

## There are several pipes in magrittr

Being a very lazy person, I’ve never really looked at the package documentation for magrittr. I should have. There are four operators in the package:

• %>% is the forward-pipe operator.
• %T>% is the tee operator.
• %<>%is the compound assignment pipe-operator.
• %$% is the exposition pipe-operator. The %>% is the one that everyone uses all the time… but what are these other magical looking glyphs? What do they mean? Are they also gang signs? Turns out they’re all kinds of awesomeness, and I am embarrassed not to have known about them before! ### %T> Suppose I want to have two outputs to flow out of my pipe: for instance, suppose I want to read the first 15 lines of the song, print them on screen, and then graph the length in characters in each line? Intuitively, what I want to do is split my pipe in two, kind of like having a T-junction in a road or pipe. That’s what the %T>% operator does. It passes the input “down” into one function, but that function is a dead end; the original value gets passed onto the next function. Example: greg %>% readLines(n = 15) %T>% # the URL is passed to readLines... cat(sep = "\n") %>% # ... take a little detour to print the lyrics nchar %>% # the output from *readLines* is passed to nchar... barplot(col = "#88398A") # now we draw the barplot  ## [Intro] ## Ba-ba-ba, ba-ba, ba-ba-ba-ba ## Ba-ba-ba, ba-ba, ba-ba-ba-ba ## Ba-ba-ba, ba-ba, ba-ba-ba-ba ## Ba-ba-ba, ba-ba, ba-ba-ba-ba ## ## [Verse 1: Ron] ## The guy who slagged the football team, those yobs were not for him ## He turns into a real estate agent who believes in discipline ## The guy who's first to use cocaine, the wild boy breaking free ## He'll end up in a court of law as a prosecuting QC ## Remember the school captain? Success was a matter of time ## I can hear him now as she screams, "Greg, you missed the stop sign!" ## ## [Verse 2: Ron] Cool! We now have two outputs from our pipe… the actual lyrics (first output, at the top) and the plot (second output at the bottom). Pretty neat! ### %<>% I am viscerally annoyed 😠 😁 that %<>% is referred to in the documentation as the compound assignment pipe-operator when it is so obviously the Ouroboros operator. The %<>% operator is what happens when you take a variable, feed it into a pipe, and then take the output from the end of the pipe and assign it back to the original variable. Clearly a snake eating its own tail. me <- "snake" me %<>% (emo::ji) %>% rep.int(times=10) cat(me) ## <U+0001F40D> <U+0001F40D> <U+0001F40D> <U+0001F40D> <U+0001F40D> <U+0001F40D> <U+0001F40D> <U+0001F40D> <U+0001F40D> <U+0001F40D> ### %$%

When the input (left hand side) to this pipe is a data frame (or list or environment), the %$% operator “exposes” the names of the variables inside the data frame to the function on the right hand side. I can imagine this being very handy in all kinds of situations. Plotting data in the traditional graphics system is much nicer, for one thing! iris %$% plot(Sepal.Length, Sepal.Width, pch=19)

Soooo many plots that I could have drawn in a cleaner way if I’d known about %\$%.

## Epilogue

Okay, so magrittr is awesome 💯 and I love it. It’s done nothing to help me with my underwater laundry though.

format: plain


text:
# Surface integral

• Apr 17th 2010, 10:35 PM
Bruno J.
Surface integral
Let $\vec F(x,y,z)=(P(x,y,z),Q(x,y,z),R(x,y,z))$ be a vector field on $\mathbb R^3$ with continuous partial derivatives, and $S$ a smooth orientable surface. Show that

$\iint_S \vec F \cdot \vec{dS} = \iint_S Pdydz + Qdzdx+Rdxdy$.

• May 21st 2010, 01:51 PM
AllanCuz
Quote:

Originally Posted by Bruno J.
Let $\vec F(x,y,z)=(P(x,y,z),Q(x,y,z),R(x,y,z))$ be a vector field on $\mathbb R^3$ with continuous partial derivatives, and $S$ a smooth orientable surface. Show that

$\iint_S \vec F \cdot \vec{dS} = \iint_S Pdydz + Qdzdx+Rdxdy$.

I'd go to the definition of the divergence theorem.

$\iint_S \vec F \cdot \vec{dS} = \iiint_V div F dV$

$\iiint_V ( \frac{ \partial P }{ \partial x } + \frac{ \partial Q }{ \partial y } + \frac{ \partial R }{ \partial z })dxdydz$

Let's multiply through and examine the first component

$\iiint_V ( \frac{ \partial P }{ \partial x } ) dxdydz$

Note that,

$\int \frac{ \partial P }{ \partial x } dx$

Represents the integral of the derivative of P with respect to x. Which means, we take the derivative and then integrate back to our original function. This means,

$\int \frac{ \partial P }{ \partial x } dx = P$

Thus,

$\iiint_V ( \frac{ \partial P }{ \partial x } ) dxdydz = \iint Pdydz$
• May 23rd 2010, 08:57 AM
Bruno J.
The surface doesn't need to be closed, in which case you cannot use the divergence theorem!


text:
Looking for Algebra worksheets?
Check out our pre-made Algebra worksheets!
 Tweet

Browse Questions

You can create printable tests and worksheets from these Grade 9 Inequalities questions! Select one or more questions using the checkboxes above each question. Then click the add selected questions to a test button before moving to another page.

Previous Next
What is the solution to the inequality below?

12x > 5(x-2)
1. x > -2/7
2. x < -2/7
3. x > -10/7
4. x < -10/7
Solve the inequality: $4w-6>6w-20$
1. $w<7$
2. $w<2$
3. $w<-7$
4. $w<-2$
Which inequality is described by the statement: y is at most -8?
1. $y<=-8$
2. $y>=-8$
3. $y<-8$
4. $y> -8$
Give the equivalent inequality which results from multiplying both sides of the given inequality by -2: $-4x<=10$
1. $-8x>=20$
2. $-8x<=-20$
3. $8x>=-20$
4. $-8x> 20$
Solve the inequality: $|f-9|>=2$
1. $7< f <11$
2. $f<7 or f>11$
3. $7<=f<=11$
4. $f<=7 or f>=11$
Solve: $4y-1>=7 or 2y +5<17$
1. $y>=2 and y<6$
2. $y<=2 or y<6$
3. $y>=2 or y<6$
4. $y<2 or y>=6$
Give the equivalent inequality which results from multiplying both sides of the given inequality by -3: $w<=-2$
1. $-3w>=6$
2. $-3w<=-6$
3. $3w>=-6$
4. $-3w> 6$
Solve the inequality.
$-3x - 8 < 16$
1. $x < -8$
2. $x > -8$
3. $x > 8$
4. $x < 8$
Solve for the inequality for $w$.
$-2w<-10$
1. $w>20$
2. $w<-5$
3. $w<-2$
4. $w>5$
Which inequality is described by the statement: the difference of p and 7 is no less than 12?
1. $p/7 >=12$
2. $7-p> 12$
3. $p-7>=12$
4. $7/p<12$
What will the graph of $y<=-3x+2$ look like?
What will the graph of $y>2x+4$ look like?
The solution set of $3y-2<=3(y+2)$ is:
1. $RR$
2. $phi$
3. $y<=2$
4. $y>=2/3$
Solve: $4y-2>=6 or -3y +5<17$
1. $y>=2 and y<-4$
2. $y<=2 or y<-4$
3. $y>=2 or y> -4$
4. $y<1 or y>=22/3$
Find the answer for the inequality.
$9<1-x<=12$
1. $-8< x <=-11$
2. $-11<=x<-8$
3. $-13<=x<-10$
4. $-10< x <=-13$
The solution set of $3y-2<=3(y-2) is:$
1. $RR$
2. $phi$
3. $y<=2$
4. $y>=2/3$
The inequality $2y-4x<=24$ can be written in slope-intercept form as:
1. $y<=2x+12$
2. $y<=-2x+12$
3. $y<=13x+12$
4. $y<=10x+12$