Sobol Sensitivity Analysis I want to use Sobol SA with Sobol sampling to find the most influential parameters on the energy consumption of a pilot building. I have 40 input variables (building characteristics) that some have uniform and some normal distributions. 
For Sobol sampling I know the total cost for the first order and total order estimation is N(k+2), how can I choose the sampling size (N)? 
Is grouping actually helpful for 40 parameters?
So I also thought of first running a first order and second order SA and based on the results of second-order indices, I group my input variables. But I do not know if that is actually helpful cause my main intention is to simplify the simulation. 
 A: There are multiple questions in your post. Let's consider them one at a time:


*

*The value of N depends on the accuracy you want on your Sobol indices and on the run time of your model. My advice is to take as much as you can, as long as the total time taken by the model runs is acceptable for you.

*Grouping input variables together (if it is what you meant by grouping) is useful when you have dependent inputs: you group together each group of dependent variables, so that there is no dependence between groups. Because you cannot use Sobol SA with dependent inputs. (See Jacques et al., 2006, Sensitivity analysis
in presence of model uncertainty and correlated inputs)

*Second order indices are interesting. You could consider computing total Sobol indices (in addition or in replacement of second order ones). Total indices give you an insight on all interactions of a given input (but no complete knowledge of with which input it interacts nor at which orders). If your goal is model simplification (i.e. replacing your model with a linear model with second-order interactions), you might preferer doing a second-order SA. However, if your goal is input selection (i.e. selecting on a subset of the input variables and discarding the others), you'd better use total indices as they tell you the total importance of the inputs (considering all interactions). For more details on total indices, see this question and the reference therein (Saltelli et al., 2010): Difference between Sobol indices and total Sobol indices?.


Note also that there are multiple methods to estimate Sobol indices. See the R library sensitivity for a list of lots of them. In particular, sobolEff function implements a very effective one based on Janon et al. (2014).
Another bonus side note: Use (discrepancy-optimized) Latin Hypercube sampling for your computation! You probably have already heard of it but it is a very robust and powerful technique. Plus, if you begin with a certain number of points N and you realize you need more, you can easily augment your initial dataset so that it has still good properties and rerun you Sobol computation on it.
